2 * HDMI Connector driver
4 * Copyright (C) 2013 Texas Instruments
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
12 #include <linux/gpio/consumer.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
17 #include <linux/of_gpio.h>
18 #include <linux/mutex.h>
20 #include <drm/drm_edid.h>
22 #include "../dss/omapdss.h"
24 static const struct videomode hdmic_default_vm
= {
27 .pixelclock
= 25175000,
35 .flags
= DISPLAY_FLAGS_HSYNC_LOW
| DISPLAY_FLAGS_VSYNC_LOW
,
38 struct panel_drv_data
{
39 struct omap_dss_device dssdev
;
40 struct omap_dss_device
*in
;
41 void (*hpd_cb
)(void *cb_data
, enum drm_connector_status status
);
44 struct mutex hpd_lock
;
53 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
55 static int hdmic_connect(struct omap_dss_device
*dssdev
)
57 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
58 struct omap_dss_device
*in
= ddata
->in
;
61 dev_dbg(ddata
->dev
, "connect\n");
63 if (omapdss_device_is_connected(dssdev
))
66 r
= in
->ops
.hdmi
->connect(in
, dssdev
);
73 static void hdmic_disconnect(struct omap_dss_device
*dssdev
)
75 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
76 struct omap_dss_device
*in
= ddata
->in
;
78 dev_dbg(ddata
->dev
, "disconnect\n");
80 if (!omapdss_device_is_connected(dssdev
))
83 in
->ops
.hdmi
->disconnect(in
, dssdev
);
86 static int hdmic_enable(struct omap_dss_device
*dssdev
)
88 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
89 struct omap_dss_device
*in
= ddata
->in
;
92 dev_dbg(ddata
->dev
, "enable\n");
94 if (!omapdss_device_is_connected(dssdev
))
97 if (omapdss_device_is_enabled(dssdev
))
100 in
->ops
.hdmi
->set_timings(in
, &ddata
->vm
);
102 r
= in
->ops
.hdmi
->enable(in
);
106 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
111 static void hdmic_disable(struct omap_dss_device
*dssdev
)
113 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
114 struct omap_dss_device
*in
= ddata
->in
;
116 dev_dbg(ddata
->dev
, "disable\n");
118 if (!omapdss_device_is_enabled(dssdev
))
121 in
->ops
.hdmi
->disable(in
);
123 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
126 static void hdmic_set_timings(struct omap_dss_device
*dssdev
,
127 struct videomode
*vm
)
129 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
130 struct omap_dss_device
*in
= ddata
->in
;
133 dssdev
->panel
.vm
= *vm
;
135 in
->ops
.hdmi
->set_timings(in
, vm
);
138 static void hdmic_get_timings(struct omap_dss_device
*dssdev
,
139 struct videomode
*vm
)
141 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
146 static int hdmic_check_timings(struct omap_dss_device
*dssdev
,
147 struct videomode
*vm
)
149 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
150 struct omap_dss_device
*in
= ddata
->in
;
152 return in
->ops
.hdmi
->check_timings(in
, vm
);
155 static int hdmic_read_edid(struct omap_dss_device
*dssdev
,
158 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
159 struct omap_dss_device
*in
= ddata
->in
;
161 return in
->ops
.hdmi
->read_edid(in
, edid
, len
);
164 static bool hdmic_detect(struct omap_dss_device
*dssdev
)
166 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
167 struct omap_dss_device
*in
= ddata
->in
;
169 if (gpio_is_valid(ddata
->hpd_gpio
))
170 return gpio_get_value_cansleep(ddata
->hpd_gpio
);
172 return in
->ops
.hdmi
->detect(in
);
175 static int hdmic_register_hpd_cb(struct omap_dss_device
*dssdev
,
176 void (*cb
)(void *cb_data
,
177 enum drm_connector_status status
),
180 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
181 struct omap_dss_device
*in
= ddata
->in
;
183 if (gpio_is_valid(ddata
->hpd_gpio
)) {
184 mutex_lock(&ddata
->hpd_lock
);
186 ddata
->hpd_cb_data
= cb_data
;
187 mutex_unlock(&ddata
->hpd_lock
);
189 } else if (in
->ops
.hdmi
->register_hpd_cb
) {
190 return in
->ops
.hdmi
->register_hpd_cb(in
, cb
, cb_data
);
196 static void hdmic_unregister_hpd_cb(struct omap_dss_device
*dssdev
)
198 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
199 struct omap_dss_device
*in
= ddata
->in
;
201 if (gpio_is_valid(ddata
->hpd_gpio
)) {
202 mutex_lock(&ddata
->hpd_lock
);
203 ddata
->hpd_cb
= NULL
;
204 ddata
->hpd_cb_data
= NULL
;
205 mutex_unlock(&ddata
->hpd_lock
);
206 } else if (in
->ops
.hdmi
->unregister_hpd_cb
) {
207 in
->ops
.hdmi
->unregister_hpd_cb(in
);
211 static void hdmic_enable_hpd(struct omap_dss_device
*dssdev
)
213 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
214 struct omap_dss_device
*in
= ddata
->in
;
216 if (gpio_is_valid(ddata
->hpd_gpio
)) {
217 mutex_lock(&ddata
->hpd_lock
);
218 ddata
->hpd_enabled
= true;
219 mutex_unlock(&ddata
->hpd_lock
);
220 } else if (in
->ops
.hdmi
->enable_hpd
) {
221 in
->ops
.hdmi
->enable_hpd(in
);
225 static void hdmic_disable_hpd(struct omap_dss_device
*dssdev
)
227 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
228 struct omap_dss_device
*in
= ddata
->in
;
230 if (gpio_is_valid(ddata
->hpd_gpio
)) {
231 mutex_lock(&ddata
->hpd_lock
);
232 ddata
->hpd_enabled
= false;
233 mutex_unlock(&ddata
->hpd_lock
);
234 } else if (in
->ops
.hdmi
->disable_hpd
) {
235 in
->ops
.hdmi
->disable_hpd(in
);
239 static int hdmic_set_hdmi_mode(struct omap_dss_device
*dssdev
, bool hdmi_mode
)
241 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
242 struct omap_dss_device
*in
= ddata
->in
;
244 return in
->ops
.hdmi
->set_hdmi_mode(in
, hdmi_mode
);
247 static int hdmic_set_infoframe(struct omap_dss_device
*dssdev
,
248 const struct hdmi_avi_infoframe
*avi
)
250 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
251 struct omap_dss_device
*in
= ddata
->in
;
253 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
256 static struct omap_dss_driver hdmic_driver
= {
257 .connect
= hdmic_connect
,
258 .disconnect
= hdmic_disconnect
,
260 .enable
= hdmic_enable
,
261 .disable
= hdmic_disable
,
263 .set_timings
= hdmic_set_timings
,
264 .get_timings
= hdmic_get_timings
,
265 .check_timings
= hdmic_check_timings
,
267 .read_edid
= hdmic_read_edid
,
268 .detect
= hdmic_detect
,
269 .register_hpd_cb
= hdmic_register_hpd_cb
,
270 .unregister_hpd_cb
= hdmic_unregister_hpd_cb
,
271 .enable_hpd
= hdmic_enable_hpd
,
272 .disable_hpd
= hdmic_disable_hpd
,
273 .set_hdmi_mode
= hdmic_set_hdmi_mode
,
274 .set_hdmi_infoframe
= hdmic_set_infoframe
,
277 static irqreturn_t
hdmic_hpd_isr(int irq
, void *data
)
279 struct panel_drv_data
*ddata
= data
;
281 mutex_lock(&ddata
->hpd_lock
);
282 if (ddata
->hpd_enabled
&& ddata
->hpd_cb
) {
283 enum drm_connector_status status
;
285 if (hdmic_detect(&ddata
->dssdev
))
286 status
= connector_status_connected
;
288 status
= connector_status_disconnected
;
290 ddata
->hpd_cb(ddata
->hpd_cb_data
, status
);
292 mutex_unlock(&ddata
->hpd_lock
);
297 static int hdmic_probe_of(struct platform_device
*pdev
)
299 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
300 struct device_node
*node
= pdev
->dev
.of_node
;
301 struct omap_dss_device
*in
;
305 gpio
= of_get_named_gpio(node
, "hpd-gpios", 0);
306 if (gpio_is_valid(gpio
))
307 ddata
->hpd_gpio
= gpio
;
309 ddata
->hpd_gpio
= -ENODEV
;
311 in
= omapdss_of_find_source_for_first_ep(node
);
313 dev_err(&pdev
->dev
, "failed to find video source\n");
322 static int hdmic_probe(struct platform_device
*pdev
)
324 struct panel_drv_data
*ddata
;
325 struct omap_dss_device
*dssdev
;
328 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
332 platform_set_drvdata(pdev
, ddata
);
333 ddata
->dev
= &pdev
->dev
;
335 if (!pdev
->dev
.of_node
)
338 r
= hdmic_probe_of(pdev
);
342 mutex_init(&ddata
->hpd_lock
);
344 if (gpio_is_valid(ddata
->hpd_gpio
)) {
345 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->hpd_gpio
,
346 GPIOF_DIR_IN
, "hdmi_hpd");
350 r
= devm_request_threaded_irq(&pdev
->dev
,
351 gpio_to_irq(ddata
->hpd_gpio
),
353 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
360 ddata
->vm
= hdmic_default_vm
;
362 dssdev
= &ddata
->dssdev
;
363 dssdev
->driver
= &hdmic_driver
;
364 dssdev
->dev
= &pdev
->dev
;
365 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
366 dssdev
->owner
= THIS_MODULE
;
367 dssdev
->panel
.vm
= hdmic_default_vm
;
369 r
= omapdss_register_display(dssdev
);
371 dev_err(&pdev
->dev
, "Failed to register panel\n");
377 omap_dss_put_device(ddata
->in
);
381 static int __exit
hdmic_remove(struct platform_device
*pdev
)
383 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
384 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
385 struct omap_dss_device
*in
= ddata
->in
;
387 omapdss_unregister_display(&ddata
->dssdev
);
389 hdmic_disable(dssdev
);
390 hdmic_disconnect(dssdev
);
392 omap_dss_put_device(in
);
397 static const struct of_device_id hdmic_of_match
[] = {
398 { .compatible
= "omapdss,hdmi-connector", },
402 MODULE_DEVICE_TABLE(of
, hdmic_of_match
);
404 static struct platform_driver hdmi_connector_driver
= {
405 .probe
= hdmic_probe
,
406 .remove
= __exit_p(hdmic_remove
),
408 .name
= "connector-hdmi",
409 .of_match_table
= hdmic_of_match
,
410 .suppress_bind_attrs
= true,
414 module_platform_driver(hdmi_connector_driver
);
416 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
417 MODULE_DESCRIPTION("HDMI Connector driver");
418 MODULE_LICENSE("GPL");