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/platform_device.h>
17 #include <linux/gpio/consumer.h>
19 #include <video/omapfb_dss.h>
21 struct panel_drv_data
{
22 struct omap_dss_device dssdev
;
23 struct omap_dss_device
*in
;
25 struct gpio_desc
*ct_cp_hpd_gpio
;
26 struct gpio_desc
*ls_oe_gpio
;
27 struct gpio_desc
*hpd_gpio
;
29 struct omap_video_timings timings
;
32 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
34 static int tpd_connect(struct omap_dss_device
*dssdev
,
35 struct omap_dss_device
*dst
)
37 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
38 struct omap_dss_device
*in
= ddata
->in
;
41 r
= in
->ops
.hdmi
->connect(in
, dssdev
);
48 if (ddata
->ct_cp_hpd_gpio
) {
49 gpiod_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 1);
50 /* DC-DC converter needs at max 300us to get to 90% of 5V */
57 static void tpd_disconnect(struct omap_dss_device
*dssdev
,
58 struct omap_dss_device
*dst
)
60 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
61 struct omap_dss_device
*in
= ddata
->in
;
63 WARN_ON(dst
!= dssdev
->dst
);
65 if (dst
!= dssdev
->dst
)
68 gpiod_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 0);
73 in
->ops
.hdmi
->disconnect(in
, &ddata
->dssdev
);
76 static int tpd_enable(struct omap_dss_device
*dssdev
)
78 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
79 struct omap_dss_device
*in
= ddata
->in
;
82 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
)
85 in
->ops
.hdmi
->set_timings(in
, &ddata
->timings
);
87 r
= in
->ops
.hdmi
->enable(in
);
91 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
96 static void tpd_disable(struct omap_dss_device
*dssdev
)
98 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
99 struct omap_dss_device
*in
= ddata
->in
;
101 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
104 in
->ops
.hdmi
->disable(in
);
106 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
109 static void tpd_set_timings(struct omap_dss_device
*dssdev
,
110 struct omap_video_timings
*timings
)
112 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
113 struct omap_dss_device
*in
= ddata
->in
;
115 ddata
->timings
= *timings
;
116 dssdev
->panel
.timings
= *timings
;
118 in
->ops
.hdmi
->set_timings(in
, timings
);
121 static void tpd_get_timings(struct omap_dss_device
*dssdev
,
122 struct omap_video_timings
*timings
)
124 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
126 *timings
= ddata
->timings
;
129 static int tpd_check_timings(struct omap_dss_device
*dssdev
,
130 struct omap_video_timings
*timings
)
132 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
133 struct omap_dss_device
*in
= ddata
->in
;
136 r
= in
->ops
.hdmi
->check_timings(in
, timings
);
141 static int tpd_read_edid(struct omap_dss_device
*dssdev
,
144 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
145 struct omap_dss_device
*in
= ddata
->in
;
148 if (!gpiod_get_value_cansleep(ddata
->hpd_gpio
))
151 gpiod_set_value_cansleep(ddata
->ls_oe_gpio
, 1);
153 r
= in
->ops
.hdmi
->read_edid(in
, edid
, len
);
155 gpiod_set_value_cansleep(ddata
->ls_oe_gpio
, 0);
160 static bool tpd_detect(struct omap_dss_device
*dssdev
)
162 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
164 return gpiod_get_value_cansleep(ddata
->hpd_gpio
);
167 static int tpd_set_infoframe(struct omap_dss_device
*dssdev
,
168 const struct hdmi_avi_infoframe
*avi
)
170 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
171 struct omap_dss_device
*in
= ddata
->in
;
173 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
176 static int tpd_set_hdmi_mode(struct omap_dss_device
*dssdev
,
179 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
180 struct omap_dss_device
*in
= ddata
->in
;
182 return in
->ops
.hdmi
->set_hdmi_mode(in
, hdmi_mode
);
185 static const struct omapdss_hdmi_ops tpd_hdmi_ops
= {
186 .connect
= tpd_connect
,
187 .disconnect
= tpd_disconnect
,
189 .enable
= tpd_enable
,
190 .disable
= tpd_disable
,
192 .check_timings
= tpd_check_timings
,
193 .set_timings
= tpd_set_timings
,
194 .get_timings
= tpd_get_timings
,
196 .read_edid
= tpd_read_edid
,
197 .detect
= tpd_detect
,
198 .set_infoframe
= tpd_set_infoframe
,
199 .set_hdmi_mode
= tpd_set_hdmi_mode
,
202 static int tpd_probe_of(struct platform_device
*pdev
)
204 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
205 struct device_node
*node
= pdev
->dev
.of_node
;
206 struct omap_dss_device
*in
;
208 in
= omapdss_of_find_source_for_first_ep(node
);
210 dev_err(&pdev
->dev
, "failed to find video source\n");
219 static int tpd_probe(struct platform_device
*pdev
)
221 struct omap_dss_device
*in
, *dssdev
;
222 struct panel_drv_data
*ddata
;
224 struct gpio_desc
*gpio
;
226 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
230 platform_set_drvdata(pdev
, ddata
);
232 if (pdev
->dev
.of_node
) {
233 r
= tpd_probe_of(pdev
);
241 gpio
= devm_gpiod_get_index_optional(&pdev
->dev
, NULL
, 0,
246 ddata
->ct_cp_hpd_gpio
= gpio
;
248 gpio
= devm_gpiod_get_index_optional(&pdev
->dev
, NULL
, 1,
253 ddata
->ls_oe_gpio
= gpio
;
255 gpio
= devm_gpiod_get_index(&pdev
->dev
, NULL
, 2,
260 ddata
->hpd_gpio
= gpio
;
262 dssdev
= &ddata
->dssdev
;
263 dssdev
->ops
.hdmi
= &tpd_hdmi_ops
;
264 dssdev
->dev
= &pdev
->dev
;
265 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
266 dssdev
->output_type
= OMAP_DISPLAY_TYPE_HDMI
;
267 dssdev
->owner
= THIS_MODULE
;
268 dssdev
->port_num
= 1;
272 r
= omapdss_register_output(dssdev
);
274 dev_err(&pdev
->dev
, "Failed to register output\n");
281 omap_dss_put_device(ddata
->in
);
285 static int __exit
tpd_remove(struct platform_device
*pdev
)
287 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
288 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
289 struct omap_dss_device
*in
= ddata
->in
;
291 omapdss_unregister_output(&ddata
->dssdev
);
293 WARN_ON(omapdss_device_is_enabled(dssdev
));
294 if (omapdss_device_is_enabled(dssdev
))
297 WARN_ON(omapdss_device_is_connected(dssdev
));
298 if (omapdss_device_is_connected(dssdev
))
299 tpd_disconnect(dssdev
, dssdev
->dst
);
301 omap_dss_put_device(in
);
306 static const struct of_device_id tpd_of_match
[] = {
307 { .compatible
= "omapdss,ti,tpd12s015", },
311 MODULE_DEVICE_TABLE(of
, tpd_of_match
);
313 static struct platform_driver tpd_driver
= {
315 .remove
= __exit_p(tpd_remove
),
318 .of_match_table
= tpd_of_match
,
319 .suppress_bind_attrs
= true,
323 module_platform_driver(tpd_driver
);
325 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
326 MODULE_DESCRIPTION("TPD12S015 driver");
327 MODULE_LICENSE("GPL");