2 * HDMI Connector driver
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
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
;
61 dev_dbg(ddata
->dev
, "connect\n");
63 if (omapdss_device_is_connected(dssdev
))
66 in
= omapdss_of_find_source_for_first_ep(ddata
->dev
->of_node
);
68 dev_err(ddata
->dev
, "failed to find video source\n");
72 r
= in
->ops
.hdmi
->connect(in
, dssdev
);
74 omap_dss_put_device(in
);
82 static void hdmic_disconnect(struct omap_dss_device
*dssdev
)
84 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
85 struct omap_dss_device
*in
= ddata
->in
;
87 dev_dbg(ddata
->dev
, "disconnect\n");
89 if (!omapdss_device_is_connected(dssdev
))
92 in
->ops
.hdmi
->disconnect(in
, dssdev
);
94 omap_dss_put_device(in
);
98 static int hdmic_enable(struct omap_dss_device
*dssdev
)
100 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
101 struct omap_dss_device
*in
= ddata
->in
;
104 dev_dbg(ddata
->dev
, "enable\n");
106 if (!omapdss_device_is_connected(dssdev
))
109 if (omapdss_device_is_enabled(dssdev
))
112 in
->ops
.hdmi
->set_timings(in
, &ddata
->vm
);
114 r
= in
->ops
.hdmi
->enable(in
);
118 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
123 static void hdmic_disable(struct omap_dss_device
*dssdev
)
125 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
126 struct omap_dss_device
*in
= ddata
->in
;
128 dev_dbg(ddata
->dev
, "disable\n");
130 if (!omapdss_device_is_enabled(dssdev
))
133 in
->ops
.hdmi
->disable(in
);
135 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
138 static void hdmic_set_timings(struct omap_dss_device
*dssdev
,
139 struct videomode
*vm
)
141 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
142 struct omap_dss_device
*in
= ddata
->in
;
145 dssdev
->panel
.vm
= *vm
;
147 in
->ops
.hdmi
->set_timings(in
, vm
);
150 static void hdmic_get_timings(struct omap_dss_device
*dssdev
,
151 struct videomode
*vm
)
153 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
158 static int hdmic_check_timings(struct omap_dss_device
*dssdev
,
159 struct videomode
*vm
)
161 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
162 struct omap_dss_device
*in
= ddata
->in
;
164 return in
->ops
.hdmi
->check_timings(in
, vm
);
167 static int hdmic_read_edid(struct omap_dss_device
*dssdev
,
170 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
171 struct omap_dss_device
*in
= ddata
->in
;
173 return in
->ops
.hdmi
->read_edid(in
, edid
, len
);
176 static bool hdmic_detect(struct omap_dss_device
*dssdev
)
178 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
179 struct omap_dss_device
*in
= ddata
->in
;
182 if (gpio_is_valid(ddata
->hpd_gpio
))
183 connected
= gpio_get_value_cansleep(ddata
->hpd_gpio
);
185 connected
= in
->ops
.hdmi
->detect(in
);
186 if (!connected
&& in
->ops
.hdmi
->lost_hotplug
)
187 in
->ops
.hdmi
->lost_hotplug(in
);
191 static int hdmic_register_hpd_cb(struct omap_dss_device
*dssdev
,
192 void (*cb
)(void *cb_data
,
193 enum drm_connector_status status
),
196 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
197 struct omap_dss_device
*in
= ddata
->in
;
199 if (gpio_is_valid(ddata
->hpd_gpio
)) {
200 mutex_lock(&ddata
->hpd_lock
);
202 ddata
->hpd_cb_data
= cb_data
;
203 mutex_unlock(&ddata
->hpd_lock
);
205 } else if (in
->ops
.hdmi
->register_hpd_cb
) {
206 return in
->ops
.hdmi
->register_hpd_cb(in
, cb
, cb_data
);
212 static void hdmic_unregister_hpd_cb(struct omap_dss_device
*dssdev
)
214 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
215 struct omap_dss_device
*in
= ddata
->in
;
217 if (gpio_is_valid(ddata
->hpd_gpio
)) {
218 mutex_lock(&ddata
->hpd_lock
);
219 ddata
->hpd_cb
= NULL
;
220 ddata
->hpd_cb_data
= NULL
;
221 mutex_unlock(&ddata
->hpd_lock
);
222 } else if (in
->ops
.hdmi
->unregister_hpd_cb
) {
223 in
->ops
.hdmi
->unregister_hpd_cb(in
);
227 static void hdmic_enable_hpd(struct omap_dss_device
*dssdev
)
229 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
230 struct omap_dss_device
*in
= ddata
->in
;
232 if (gpio_is_valid(ddata
->hpd_gpio
)) {
233 mutex_lock(&ddata
->hpd_lock
);
234 ddata
->hpd_enabled
= true;
235 mutex_unlock(&ddata
->hpd_lock
);
236 } else if (in
->ops
.hdmi
->enable_hpd
) {
237 in
->ops
.hdmi
->enable_hpd(in
);
241 static void hdmic_disable_hpd(struct omap_dss_device
*dssdev
)
243 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
244 struct omap_dss_device
*in
= ddata
->in
;
246 if (gpio_is_valid(ddata
->hpd_gpio
)) {
247 mutex_lock(&ddata
->hpd_lock
);
248 ddata
->hpd_enabled
= false;
249 mutex_unlock(&ddata
->hpd_lock
);
250 } else if (in
->ops
.hdmi
->disable_hpd
) {
251 in
->ops
.hdmi
->disable_hpd(in
);
255 static int hdmic_set_hdmi_mode(struct omap_dss_device
*dssdev
, bool hdmi_mode
)
257 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
258 struct omap_dss_device
*in
= ddata
->in
;
260 return in
->ops
.hdmi
->set_hdmi_mode(in
, hdmi_mode
);
263 static int hdmic_set_infoframe(struct omap_dss_device
*dssdev
,
264 const struct hdmi_avi_infoframe
*avi
)
266 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
267 struct omap_dss_device
*in
= ddata
->in
;
269 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
272 static struct omap_dss_driver hdmic_driver
= {
273 .connect
= hdmic_connect
,
274 .disconnect
= hdmic_disconnect
,
276 .enable
= hdmic_enable
,
277 .disable
= hdmic_disable
,
279 .set_timings
= hdmic_set_timings
,
280 .get_timings
= hdmic_get_timings
,
281 .check_timings
= hdmic_check_timings
,
283 .read_edid
= hdmic_read_edid
,
284 .detect
= hdmic_detect
,
285 .register_hpd_cb
= hdmic_register_hpd_cb
,
286 .unregister_hpd_cb
= hdmic_unregister_hpd_cb
,
287 .enable_hpd
= hdmic_enable_hpd
,
288 .disable_hpd
= hdmic_disable_hpd
,
289 .set_hdmi_mode
= hdmic_set_hdmi_mode
,
290 .set_hdmi_infoframe
= hdmic_set_infoframe
,
293 static irqreturn_t
hdmic_hpd_isr(int irq
, void *data
)
295 struct panel_drv_data
*ddata
= data
;
297 mutex_lock(&ddata
->hpd_lock
);
298 if (ddata
->hpd_enabled
&& ddata
->hpd_cb
) {
299 enum drm_connector_status status
;
301 if (hdmic_detect(&ddata
->dssdev
))
302 status
= connector_status_connected
;
304 status
= connector_status_disconnected
;
306 ddata
->hpd_cb(ddata
->hpd_cb_data
, status
);
308 mutex_unlock(&ddata
->hpd_lock
);
313 static int hdmic_probe_of(struct platform_device
*pdev
)
315 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
316 struct device_node
*node
= pdev
->dev
.of_node
;
320 gpio
= of_get_named_gpio(node
, "hpd-gpios", 0);
321 if (gpio_is_valid(gpio
))
322 ddata
->hpd_gpio
= gpio
;
324 ddata
->hpd_gpio
= -ENODEV
;
329 static int hdmic_probe(struct platform_device
*pdev
)
331 struct panel_drv_data
*ddata
;
332 struct omap_dss_device
*dssdev
;
335 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
339 platform_set_drvdata(pdev
, ddata
);
340 ddata
->dev
= &pdev
->dev
;
342 r
= hdmic_probe_of(pdev
);
346 mutex_init(&ddata
->hpd_lock
);
348 if (gpio_is_valid(ddata
->hpd_gpio
)) {
349 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->hpd_gpio
,
350 GPIOF_DIR_IN
, "hdmi_hpd");
354 r
= devm_request_threaded_irq(&pdev
->dev
,
355 gpio_to_irq(ddata
->hpd_gpio
),
357 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
364 ddata
->vm
= hdmic_default_vm
;
366 dssdev
= &ddata
->dssdev
;
367 dssdev
->driver
= &hdmic_driver
;
368 dssdev
->dev
= &pdev
->dev
;
369 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
370 dssdev
->owner
= THIS_MODULE
;
371 dssdev
->panel
.vm
= hdmic_default_vm
;
373 r
= omapdss_register_display(dssdev
);
375 dev_err(&pdev
->dev
, "Failed to register panel\n");
382 static int __exit
hdmic_remove(struct platform_device
*pdev
)
384 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
385 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
387 omapdss_unregister_display(&ddata
->dssdev
);
389 hdmic_disable(dssdev
);
390 hdmic_disconnect(dssdev
);
395 static const struct of_device_id hdmic_of_match
[] = {
396 { .compatible
= "omapdss,hdmi-connector", },
400 MODULE_DEVICE_TABLE(of
, hdmic_of_match
);
402 static struct platform_driver hdmi_connector_driver
= {
403 .probe
= hdmic_probe
,
404 .remove
= __exit_p(hdmic_remove
),
406 .name
= "connector-hdmi",
407 .of_match_table
= hdmic_of_match
,
408 .suppress_bind_attrs
= true,
412 module_platform_driver(hdmi_connector_driver
);
414 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
415 MODULE_DESCRIPTION("HDMI Connector driver");
416 MODULE_LICENSE("GPL");