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 const struct omapdss_hdmi_ops tpd_hdmi_ops = {
246 .connect = tpd_connect,
247 .disconnect = tpd_disconnect,
249 .enable = tpd_enable,
250 .disable = tpd_disable,
252 .check_timings = tpd_check_timings,
253 .set_timings = tpd_set_timings,
254 .get_timings = tpd_get_timings,
256 .read_edid = tpd_read_edid,
257 .detect = tpd_detect,
259 .audio_enable = tpd_audio_enable,
260 .audio_disable = tpd_audio_disable,
261 .audio_start = tpd_audio_start,
262 .audio_stop = tpd_audio_stop,
263 .audio_supported = tpd_audio_supported,
264 .audio_config = tpd_audio_config,
267 static int tpd_probe_pdata(struct platform_device *pdev)
269 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
270 struct encoder_tpd12s015_platform_data *pdata;
271 struct omap_dss_device *dssdev, *in;
273 pdata = dev_get_platdata(&pdev->dev);
275 ddata->ct_cp_hpd_gpio = pdata->ct_cp_hpd_gpio;
276 ddata->ls_oe_gpio = pdata->ls_oe_gpio;
277 ddata->hpd_gpio = pdata->hpd_gpio;
279 in = omap_dss_find_output(pdata->source);
281 dev_err(&pdev->dev, "Failed to find video source\n");
287 dssdev = &ddata->dssdev;
288 dssdev->name = pdata->name;
293 static int tpd_probe_of(struct platform_device *pdev)
295 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
296 struct device_node *node = pdev->dev.of_node;
297 struct omap_dss_device *in;
301 gpio = of_get_gpio(node, 0);
302 if (!gpio_is_valid(gpio)) {
303 dev_err(&pdev->dev, "failed to parse CT CP HPD gpio\n");
306 ddata->ct_cp_hpd_gpio = gpio;
309 gpio = of_get_gpio(node, 1);
310 if (gpio_is_valid(gpio) || gpio == -ENOENT) {
311 ddata->ls_oe_gpio = gpio;
313 dev_err(&pdev->dev, "failed to parse LS OE gpio\n");
318 gpio = of_get_gpio(node, 2);
319 if (!gpio_is_valid(gpio)) {
320 dev_err(&pdev->dev, "failed to parse HPD gpio\n");
323 ddata->hpd_gpio = gpio;
325 in = omapdss_of_find_source_for_first_ep(node);
327 dev_err(&pdev->dev, "failed to find video source\n");
336 static int tpd_probe(struct platform_device *pdev)
338 struct omap_dss_device *in, *dssdev;
339 struct panel_drv_data *ddata;
342 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
346 platform_set_drvdata(pdev, ddata);
348 init_completion(&ddata->hpd_completion);
350 if (dev_get_platdata(&pdev->dev)) {
351 r = tpd_probe_pdata(pdev);
354 } else if (pdev->dev.of_node) {
355 r = tpd_probe_of(pdev);
362 r = devm_gpio_request_one(&pdev->dev, ddata->ct_cp_hpd_gpio,
363 GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd");
367 if (gpio_is_valid(ddata->ls_oe_gpio)) {
368 r = devm_gpio_request_one(&pdev->dev, ddata->ls_oe_gpio,
369 GPIOF_OUT_INIT_LOW, "hdmi_ls_oe");
374 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
375 GPIOF_DIR_IN, "hdmi_hpd");
379 r = devm_request_threaded_irq(&pdev->dev, gpio_to_irq(ddata->hpd_gpio),
380 NULL, tpd_hpd_irq_handler,
381 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
382 IRQF_ONESHOT, "hpd", ddata);
386 dssdev = &ddata->dssdev;
387 dssdev->ops.hdmi = &tpd_hdmi_ops;
388 dssdev->dev = &pdev->dev;
389 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
390 dssdev->output_type = OMAP_DISPLAY_TYPE_HDMI;
391 dssdev->owner = THIS_MODULE;
395 r = omapdss_register_output(dssdev);
397 dev_err(&pdev->dev, "Failed to register output\n");
405 omap_dss_put_device(ddata->in);
409 static int __exit tpd_remove(struct platform_device *pdev)
411 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
412 struct omap_dss_device *dssdev = &ddata->dssdev;
413 struct omap_dss_device *in = ddata->in;
415 omapdss_unregister_output(&ddata->dssdev);
417 WARN_ON(omapdss_device_is_enabled(dssdev));
418 if (omapdss_device_is_enabled(dssdev))
421 WARN_ON(omapdss_device_is_connected(dssdev));
422 if (omapdss_device_is_connected(dssdev))
423 tpd_disconnect(dssdev, dssdev->dst);
425 omap_dss_put_device(in);
430 static const struct of_device_id tpd_of_match[] = {
431 { .compatible = "omapdss,ti,tpd12s015", },
435 MODULE_DEVICE_TABLE(of, tpd_of_match);
437 static struct platform_driver tpd_driver = {
439 .remove = __exit_p(tpd_remove),
442 .owner = THIS_MODULE,
443 .of_match_table = tpd_of_match,
447 module_platform_driver(tpd_driver);
449 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
450 MODULE_DESCRIPTION("TPD12S015 driver");
451 MODULE_LICENSE("GPL");