2 * TPD12S015 HDMI ESD protection & level shifter chip 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/completion.h>
13 #include <linux/delay.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/gpio.h>
17 #include <linux/platform_device.h>
18 #include <linux/of_gpio.h>
20 #include <video/omapdss.h>
21 #include <video/omap-panel-data.h>
23 struct panel_drv_data
{
24 struct omap_dss_device dssdev
;
25 struct omap_dss_device
*in
;
31 struct omap_video_timings timings
;
33 struct completion hpd_completion
;
36 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
38 static irqreturn_t
tpd_hpd_irq_handler(int irq
, void *data
)
40 struct panel_drv_data
*ddata
= data
;
43 hpd
= gpio_get_value_cansleep(ddata
->hpd_gpio
);
45 dev_dbg(ddata
->dssdev
.dev
, "hpd %d\n", hpd
);
47 if (gpio_is_valid(ddata
->ls_oe_gpio
)) {
49 gpio_set_value_cansleep(ddata
->ls_oe_gpio
, 1);
51 gpio_set_value_cansleep(ddata
->ls_oe_gpio
, 0);
54 complete_all(&ddata
->hpd_completion
);
59 static int tpd_connect(struct omap_dss_device
*dssdev
,
60 struct omap_dss_device
*dst
)
62 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
63 struct omap_dss_device
*in
= ddata
->in
;
66 r
= in
->ops
.hdmi
->connect(in
, dssdev
);
73 reinit_completion(&ddata
->hpd_completion
);
75 gpio_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 1);
76 /* DC-DC converter needs at max 300us to get to 90% of 5V */
80 * If there's a cable connected, wait for the hpd irq to trigger,
81 * which turns on the level shifters.
83 if (gpio_get_value_cansleep(ddata
->hpd_gpio
)) {
85 to
= wait_for_completion_timeout(&ddata
->hpd_completion
,
86 msecs_to_jiffies(250));
87 WARN_ON_ONCE(to
== 0);
93 static void tpd_disconnect(struct omap_dss_device
*dssdev
,
94 struct omap_dss_device
*dst
)
96 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
97 struct omap_dss_device
*in
= ddata
->in
;
99 WARN_ON(dst
!= dssdev
->dst
);
101 if (dst
!= dssdev
->dst
)
104 gpio_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 0);
109 in
->ops
.hdmi
->disconnect(in
, &ddata
->dssdev
);
112 static int tpd_enable(struct omap_dss_device
*dssdev
)
114 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
115 struct omap_dss_device
*in
= ddata
->in
;
118 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
)
121 in
->ops
.hdmi
->set_timings(in
, &ddata
->timings
);
123 r
= in
->ops
.hdmi
->enable(in
);
127 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
132 static void tpd_disable(struct omap_dss_device
*dssdev
)
134 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
135 struct omap_dss_device
*in
= ddata
->in
;
137 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
140 in
->ops
.hdmi
->disable(in
);
142 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
145 static void tpd_set_timings(struct omap_dss_device
*dssdev
,
146 struct omap_video_timings
*timings
)
148 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
149 struct omap_dss_device
*in
= ddata
->in
;
151 ddata
->timings
= *timings
;
152 dssdev
->panel
.timings
= *timings
;
154 in
->ops
.hdmi
->set_timings(in
, timings
);
157 static void tpd_get_timings(struct omap_dss_device
*dssdev
,
158 struct omap_video_timings
*timings
)
160 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
162 *timings
= ddata
->timings
;
165 static int tpd_check_timings(struct omap_dss_device
*dssdev
,
166 struct omap_video_timings
*timings
)
168 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
169 struct omap_dss_device
*in
= ddata
->in
;
172 r
= in
->ops
.hdmi
->check_timings(in
, timings
);
177 static int tpd_read_edid(struct omap_dss_device
*dssdev
,
180 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
181 struct omap_dss_device
*in
= ddata
->in
;
183 if (!gpio_get_value_cansleep(ddata
->hpd_gpio
))
186 return in
->ops
.hdmi
->read_edid(in
, edid
, len
);
189 static bool tpd_detect(struct omap_dss_device
*dssdev
)
191 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
193 return gpio_get_value_cansleep(ddata
->hpd_gpio
);
196 static int tpd_audio_enable(struct omap_dss_device
*dssdev
)
198 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
199 struct omap_dss_device
*in
= ddata
->in
;
201 return in
->ops
.hdmi
->audio_enable(in
);
204 static void tpd_audio_disable(struct omap_dss_device
*dssdev
)
206 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
207 struct omap_dss_device
*in
= ddata
->in
;
209 in
->ops
.hdmi
->audio_disable(in
);
212 static int tpd_audio_start(struct omap_dss_device
*dssdev
)
214 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
215 struct omap_dss_device
*in
= ddata
->in
;
217 return in
->ops
.hdmi
->audio_start(in
);
220 static void tpd_audio_stop(struct omap_dss_device
*dssdev
)
222 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
223 struct omap_dss_device
*in
= ddata
->in
;
225 in
->ops
.hdmi
->audio_stop(in
);
228 static bool tpd_audio_supported(struct omap_dss_device
*dssdev
)
230 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
231 struct omap_dss_device
*in
= ddata
->in
;
233 return in
->ops
.hdmi
->audio_supported(in
);
236 static int tpd_audio_config(struct omap_dss_device
*dssdev
,
237 struct omap_dss_audio
*audio
)
239 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
240 struct omap_dss_device
*in
= ddata
->in
;
242 return in
->ops
.hdmi
->audio_config(in
, audio
);
245 static int tpd_set_infoframe(struct omap_dss_device
*dssdev
,
246 const struct hdmi_avi_infoframe
*avi
)
248 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
249 struct omap_dss_device
*in
= ddata
->in
;
251 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
254 static int tpd_set_hdmi_mode(struct omap_dss_device
*dssdev
,
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 const struct omapdss_hdmi_ops tpd_hdmi_ops
= {
264 .connect
= tpd_connect
,
265 .disconnect
= tpd_disconnect
,
267 .enable
= tpd_enable
,
268 .disable
= tpd_disable
,
270 .check_timings
= tpd_check_timings
,
271 .set_timings
= tpd_set_timings
,
272 .get_timings
= tpd_get_timings
,
274 .read_edid
= tpd_read_edid
,
275 .detect
= tpd_detect
,
276 .set_infoframe
= tpd_set_infoframe
,
277 .set_hdmi_mode
= tpd_set_hdmi_mode
,
279 .audio_enable
= tpd_audio_enable
,
280 .audio_disable
= tpd_audio_disable
,
281 .audio_start
= tpd_audio_start
,
282 .audio_stop
= tpd_audio_stop
,
283 .audio_supported
= tpd_audio_supported
,
284 .audio_config
= tpd_audio_config
,
287 static int tpd_probe_pdata(struct platform_device
*pdev
)
289 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
290 struct encoder_tpd12s015_platform_data
*pdata
;
291 struct omap_dss_device
*dssdev
, *in
;
293 pdata
= dev_get_platdata(&pdev
->dev
);
295 ddata
->ct_cp_hpd_gpio
= pdata
->ct_cp_hpd_gpio
;
296 ddata
->ls_oe_gpio
= pdata
->ls_oe_gpio
;
297 ddata
->hpd_gpio
= pdata
->hpd_gpio
;
299 in
= omap_dss_find_output(pdata
->source
);
301 dev_err(&pdev
->dev
, "Failed to find video source\n");
307 dssdev
= &ddata
->dssdev
;
308 dssdev
->name
= pdata
->name
;
313 static int tpd_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
;
317 struct omap_dss_device
*in
;
321 gpio
= of_get_gpio(node
, 0);
322 if (!gpio_is_valid(gpio
)) {
323 dev_err(&pdev
->dev
, "failed to parse CT CP HPD gpio\n");
326 ddata
->ct_cp_hpd_gpio
= gpio
;
329 gpio
= of_get_gpio(node
, 1);
330 if (gpio_is_valid(gpio
) || gpio
== -ENOENT
) {
331 ddata
->ls_oe_gpio
= gpio
;
333 dev_err(&pdev
->dev
, "failed to parse LS OE gpio\n");
338 gpio
= of_get_gpio(node
, 2);
339 if (!gpio_is_valid(gpio
)) {
340 dev_err(&pdev
->dev
, "failed to parse HPD gpio\n");
343 ddata
->hpd_gpio
= gpio
;
345 in
= omapdss_of_find_source_for_first_ep(node
);
347 dev_err(&pdev
->dev
, "failed to find video source\n");
356 static int tpd_probe(struct platform_device
*pdev
)
358 struct omap_dss_device
*in
, *dssdev
;
359 struct panel_drv_data
*ddata
;
362 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
366 platform_set_drvdata(pdev
, ddata
);
368 init_completion(&ddata
->hpd_completion
);
370 if (dev_get_platdata(&pdev
->dev
)) {
371 r
= tpd_probe_pdata(pdev
);
374 } else if (pdev
->dev
.of_node
) {
375 r
= tpd_probe_of(pdev
);
382 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->ct_cp_hpd_gpio
,
383 GPIOF_OUT_INIT_LOW
, "hdmi_ct_cp_hpd");
387 if (gpio_is_valid(ddata
->ls_oe_gpio
)) {
388 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->ls_oe_gpio
,
389 GPIOF_OUT_INIT_LOW
, "hdmi_ls_oe");
394 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->hpd_gpio
,
395 GPIOF_DIR_IN
, "hdmi_hpd");
399 r
= devm_request_threaded_irq(&pdev
->dev
, gpio_to_irq(ddata
->hpd_gpio
),
400 NULL
, tpd_hpd_irq_handler
,
401 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
402 IRQF_ONESHOT
, "hpd", ddata
);
406 dssdev
= &ddata
->dssdev
;
407 dssdev
->ops
.hdmi
= &tpd_hdmi_ops
;
408 dssdev
->dev
= &pdev
->dev
;
409 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
410 dssdev
->output_type
= OMAP_DISPLAY_TYPE_HDMI
;
411 dssdev
->owner
= THIS_MODULE
;
415 r
= omapdss_register_output(dssdev
);
417 dev_err(&pdev
->dev
, "Failed to register output\n");
425 omap_dss_put_device(ddata
->in
);
429 static int __exit
tpd_remove(struct platform_device
*pdev
)
431 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
432 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
433 struct omap_dss_device
*in
= ddata
->in
;
435 omapdss_unregister_output(&ddata
->dssdev
);
437 WARN_ON(omapdss_device_is_enabled(dssdev
));
438 if (omapdss_device_is_enabled(dssdev
))
441 WARN_ON(omapdss_device_is_connected(dssdev
));
442 if (omapdss_device_is_connected(dssdev
))
443 tpd_disconnect(dssdev
, dssdev
->dst
);
445 omap_dss_put_device(in
);
450 static const struct of_device_id tpd_of_match
[] = {
451 { .compatible
= "omapdss,ti,tpd12s015", },
455 MODULE_DEVICE_TABLE(of
, tpd_of_match
);
457 static struct platform_driver tpd_driver
= {
459 .remove
= __exit_p(tpd_remove
),
462 .owner
= THIS_MODULE
,
463 .of_match_table
= tpd_of_match
,
464 .suppress_bind_attrs
= true,
468 module_platform_driver(tpd_driver
);
470 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
471 MODULE_DESCRIPTION("TPD12S015 driver");
472 MODULE_LICENSE("GPL");