Skip to content

Commit 4c8b4c3

Browse files
Ondrej Jirmanmripard
authored andcommitted
drm: sun4i: Add support for enabling DDC I2C bus to sun8i_dw_hdmi glue
Orange Pi 3 board requires enabling a voltage shifting circuit via GPIO for the DDC bus to be usable. Add support for hdmi-connector node's optional ddc-en-gpios property to support this use case. Signed-off-by: Ondrej Jirman <megous@megous.com> Reviewed-by: Jernej Skrabec <jernej.skrabec@siol.net> Signed-off-by: Maxime Ripard <mripard@kernel.org> Link: https://patchwork.freedesktop.org/patch/msgid/20190806155744.10263-4-megous@megous.com
1 parent f670006 commit 4c8b4c3

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

‎drivers/gpu/drm/sun4i/sun8i_dw_hdmi.c‎

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,34 @@ static u32 sun8i_dw_hdmi_find_possible_crtcs(struct drm_device *drm,
9797
return crtcs;
9898
}
9999

100+
static int sun8i_dw_hdmi_find_connector_pdev(struct device *dev,
101+
struct platform_device **pdev_out)
102+
{
103+
struct platform_device *pdev;
104+
struct device_node *remote;
105+
106+
remote = of_graph_get_remote_node(dev->of_node, 1, -1);
107+
if (!remote)
108+
return -ENODEV;
109+
110+
if (!of_device_is_compatible(remote, "hdmi-connector")) {
111+
of_node_put(remote);
112+
return -ENODEV;
113+
}
114+
115+
pdev = of_find_device_by_node(remote);
116+
of_node_put(remote);
117+
if (!pdev)
118+
return -ENODEV;
119+
120+
*pdev_out = pdev;
121+
return 0;
122+
}
123+
100124
static int sun8i_dw_hdmi_bind(struct device *dev, struct device *master,
101125
void *data)
102126
{
103-
struct platform_device *pdev = to_platform_device(dev);
127+
struct platform_device *pdev = to_platform_device(dev), *connector_pdev;
104128
struct dw_hdmi_plat_data *plat_data;
105129
struct drm_device *drm = data;
106130
struct device_node *phy_node;
@@ -150,16 +174,30 @@ static int sun8i_dw_hdmi_bind(struct device *dev, struct device *master,
150174
return PTR_ERR(hdmi->regulator);
151175
}
152176

177+
ret = sun8i_dw_hdmi_find_connector_pdev(dev, &connector_pdev);
178+
if (!ret) {
179+
hdmi->ddc_en = gpiod_get_optional(&connector_pdev->dev,
180+
"ddc-en", GPIOD_OUT_HIGH);
181+
platform_device_put(connector_pdev);
182+
183+
if (IS_ERR(hdmi->ddc_en)) {
184+
dev_err(dev, "Couldn't get ddc-en gpio\n");
185+
return PTR_ERR(hdmi->ddc_en);
186+
}
187+
}
188+
153189
ret = regulator_enable(hdmi->regulator);
154190
if (ret) {
155191
dev_err(dev, "Failed to enable regulator\n");
156-
return ret;
192+
goto err_unref_ddc_en;
157193
}
158194

195+
gpiod_set_value(hdmi->ddc_en, 1);
196+
159197
ret = reset_control_deassert(hdmi->rst_ctrl);
160198
if (ret) {
161199
dev_err(dev, "Could not deassert ctrl reset control\n");
162-
goto err_disable_regulator;
200+
goto err_disable_ddc_en;
163201
}
164202

165203
ret = clk_prepare_enable(hdmi->clk_tmds);
@@ -212,8 +250,12 @@ static int sun8i_dw_hdmi_bind(struct device *dev, struct device *master,
212250
clk_disable_unprepare(hdmi->clk_tmds);
213251
err_assert_ctrl_reset:
214252
reset_control_assert(hdmi->rst_ctrl);
215-
err_disable_regulator:
253+
err_disable_ddc_en:
254+
gpiod_set_value(hdmi->ddc_en, 0);
216255
regulator_disable(hdmi->regulator);
256+
err_unref_ddc_en:
257+
if (hdmi->ddc_en)
258+
gpiod_put(hdmi->ddc_en);
217259

218260
return ret;
219261
}
@@ -227,7 +269,11 @@ static void sun8i_dw_hdmi_unbind(struct device *dev, struct device *master,
227269
sun8i_hdmi_phy_remove(hdmi);
228270
clk_disable_unprepare(hdmi->clk_tmds);
229271
reset_control_assert(hdmi->rst_ctrl);
272+
gpiod_set_value(hdmi->ddc_en, 0);
230273
regulator_disable(hdmi->regulator);
274+
275+
if (hdmi->ddc_en)
276+
gpiod_put(hdmi->ddc_en);
231277
}
232278

233279
static const struct component_ops sun8i_dw_hdmi_ops = {

‎drivers/gpu/drm/sun4i/sun8i_dw_hdmi.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <drm/bridge/dw_hdmi.h>
1010
#include <drm/drm_encoder.h>
1111
#include <linux/clk.h>
12+
#include <linux/gpio/consumer.h>
1213
#include <linux/regmap.h>
1314
#include <linux/regulator/consumer.h>
1415
#include <linux/reset.h>
@@ -190,6 +191,7 @@ struct sun8i_dw_hdmi {
190191
struct regulator *regulator;
191192
const struct sun8i_dw_hdmi_quirks *quirks;
192193
struct reset_control *rst_ctrl;
194+
struct gpio_desc *ddc_en;
193195
};
194196

195197
static inline struct sun8i_dw_hdmi *

0 commit comments

Comments
 (0)