[PATCH v3 05/12] drm/mediatek: hdmi: make the cec dev optional
Guillaume Ranquet
granquet at baylibre.com
Fri Nov 4 14:09:51 UTC 2022
Make cec device optional in order to support newer versions of the
hdmi IP which doesn't require it
Signed-off-by: Guillaume Ranquet <granquet at baylibre.com>
---
drivers/gpu/drm/mediatek/mtk_hdmi.c | 8 +++--
drivers/gpu/drm/mediatek/mtk_hdmi_common.c | 54 ++++++++++++++++++++----------
drivers/gpu/drm/mediatek/mtk_hdmi_common.h | 1 +
3 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c
index 73bda2849196..85c6ebca36dd 100644
--- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
+++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
@@ -927,10 +927,11 @@ void mtk_hdmi_clk_disable_audio_mt8183(struct mtk_hdmi *hdmi)
static enum drm_connector_status
mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi)
{
- bool connected;
+ bool connected = true;
mutex_lock(&hdmi->update_plugged_status_lock);
- connected = mtk_cec_hpd_high(hdmi->cec_dev);
+ if (hdmi->cec_dev)
+ connected = mtk_cec_hpd_high(hdmi->cec_dev);
if (hdmi->plugged_cb && hdmi->codec_dev)
hdmi->plugged_cb(hdmi->codec_dev, connected);
mutex_unlock(&hdmi->update_plugged_status_lock);
@@ -1025,7 +1026,8 @@ static int mtk_hdmi_bridge_attach(struct drm_bridge *bridge,
return ret;
}
- mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev);
+ if (hdmi->cec_dev)
+ mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev);
return 0;
}
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi_common.c b/drivers/gpu/drm/mediatek/mtk_hdmi_common.c
index 3f08d37b1af0..3635ca66817b 100644
--- a/drivers/gpu/drm/mediatek/mtk_hdmi_common.c
+++ b/drivers/gpu/drm/mediatek/mtk_hdmi_common.c
@@ -137,28 +137,18 @@ void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi, u8 *buffer_spd, size_t bufsz
mtk_hdmi_setup_spd_infoframe(hdmi, buffer_spd, bufsz_spd, "mediatek", "On-chip HDMI");
}
-int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, struct platform_device *pdev,
- const char *const *clk_names, size_t num_clocks)
+static int mtk_hdmi_get_cec_dev(struct mtk_hdmi *hdmi, struct device *dev, struct device_node *np)
{
- struct device *dev = &pdev->dev;
- struct device_node *np = dev->of_node;
- struct device_node *cec_np, *remote, *i2c_np;
+ int ret;
+ struct device_node *cec_np;
struct platform_device *cec_pdev;
struct regmap *regmap;
- struct resource *mem;
- int ret;
-
- ret = mtk_hdmi_get_all_clk(hdmi, np, clk_names, num_clocks);
- if (ret) {
- dev_err(dev, "Failed to get all clks\n");
- return ret;
- }
/* The CEC module handles HDMI hotplug detection */
cec_np = of_get_compatible_child(np->parent, "mediatek,mt8173-cec");
if (!cec_np) {
dev_err(dev, "Failed to find CEC node\n");
- return -EINVAL;
+ return -ENOTSUPP;
}
cec_pdev = of_find_device_by_node(cec_np);
@@ -168,7 +158,6 @@ int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, struct platform_device *pdev,
return -EPROBE_DEFER;
}
of_node_put(cec_np);
- hdmi->cec_dev = &cec_pdev->dev;
/*
* The mediatek,syscon-hdmi property contains a phandle link to the
* MMSYS_CONFIG device and the register offset of the HDMI_SYS_CFG
@@ -177,12 +166,41 @@ int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, struct platform_device *pdev,
regmap = syscon_regmap_lookup_by_phandle(np, "mediatek,syscon-hdmi");
ret = of_property_read_u32_index(np, "mediatek,syscon-hdmi", 1, &hdmi->sys_offset);
if (IS_ERR(regmap))
- ret = PTR_ERR(regmap);
+ return PTR_ERR(regmap);
if (ret) {
- dev_err(dev, "Failed to get system configuration registers: %d\n", ret);
- goto put_device;
+ dev_err(dev,
+ "Failed to get system configuration registers: %d\n", ret);
+ return ret;
}
+
hdmi->sys_regmap = regmap;
+ hdmi->cec_dev = &cec_pdev->dev;
+
+ return 0;
+}
+
+int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, struct platform_device *pdev,
+ const char *const *clk_names, size_t num_clocks)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ struct device_node *remote, *i2c_np;
+ struct resource *mem;
+ int ret;
+
+ ret = mtk_hdmi_get_all_clk(hdmi, np, clk_names, num_clocks);
+ if (ret) {
+ dev_err(dev, "Failed to get all clks\n");
+ return ret;
+ }
+
+ ret = mtk_hdmi_get_cec_dev(hdmi, dev, np);
+ if (ret) {
+ if (ret == -ENOTSUPP)
+ dev_info(dev, "No CEC node found, continuing without");
+ else
+ goto put_device;
+ }
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!mem) {
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi_common.h b/drivers/gpu/drm/mediatek/mtk_hdmi_common.h
index 7452bea91f9e..921bde150e11 100644
--- a/drivers/gpu/drm/mediatek/mtk_hdmi_common.h
+++ b/drivers/gpu/drm/mediatek/mtk_hdmi_common.h
@@ -31,6 +31,7 @@
struct mtk_hdmi_conf {
bool tz_disabled;
bool cea_modes_only;
+ bool has_cec;
unsigned long max_mode_clock;
const struct drm_bridge_funcs *bridge_funcs;
void (*mtk_hdmi_output_init)(struct mtk_hdmi *hdmi);
--
b4 0.11.0-dev
More information about the dri-devel
mailing list