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/omapdss.h>
20 #include <video/omap-panel-data.h>
22 struct panel_drv_data
{
23 struct omap_dss_device dssdev
;
24 struct omap_dss_device
*in
;
26 struct gpio_desc
*ct_cp_hpd_gpio
;
27 struct gpio_desc
*ls_oe_gpio
;
28 struct gpio_desc
*hpd_gpio
;
30 struct omap_video_timings timings
;
33 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
35 static int tpd_connect(struct omap_dss_device
*dssdev
,
36 struct omap_dss_device
*dst
)
38 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
39 struct omap_dss_device
*in
= ddata
->in
;
42 r
= in
->ops
.hdmi
->connect(in
, dssdev
);
49 if (ddata
->ct_cp_hpd_gpio
) {
50 gpiod_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 1);
51 /* DC-DC converter needs at max 300us to get to 90% of 5V */
58 static void tpd_disconnect(struct omap_dss_device
*dssdev
,
59 struct omap_dss_device
*dst
)
61 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
62 struct omap_dss_device
*in
= ddata
->in
;
64 WARN_ON(dst
!= dssdev
->dst
);
66 if (dst
!= dssdev
->dst
)
69 gpiod_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 0);
74 in
->ops
.hdmi
->disconnect(in
, &ddata
->dssdev
);
77 static int tpd_enable(struct omap_dss_device
*dssdev
)
79 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
80 struct omap_dss_device
*in
= ddata
->in
;
83 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
)
86 in
->ops
.hdmi
->set_timings(in
, &ddata
->timings
);
88 r
= in
->ops
.hdmi
->enable(in
);
92 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
97 static void tpd_disable(struct omap_dss_device
*dssdev
)
99 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
100 struct omap_dss_device
*in
= ddata
->in
;
102 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
105 in
->ops
.hdmi
->disable(in
);
107 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
110 static void tpd_set_timings(struct omap_dss_device
*dssdev
,
111 struct omap_video_timings
*timings
)
113 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
114 struct omap_dss_device
*in
= ddata
->in
;
116 ddata
->timings
= *timings
;
117 dssdev
->panel
.timings
= *timings
;
119 in
->ops
.hdmi
->set_timings(in
, timings
);
122 static void tpd_get_timings(struct omap_dss_device
*dssdev
,
123 struct omap_video_timings
*timings
)
125 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
127 *timings
= ddata
->timings
;
130 static int tpd_check_timings(struct omap_dss_device
*dssdev
,
131 struct omap_video_timings
*timings
)
133 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
134 struct omap_dss_device
*in
= ddata
->in
;
137 r
= in
->ops
.hdmi
->check_timings(in
, timings
);
142 static int tpd_read_edid(struct omap_dss_device
*dssdev
,
145 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
146 struct omap_dss_device
*in
= ddata
->in
;
149 if (!gpiod_get_value_cansleep(ddata
->hpd_gpio
))
152 gpiod_set_value_cansleep(ddata
->ls_oe_gpio
, 1);
154 r
= in
->ops
.hdmi
->read_edid(in
, edid
, len
);
156 gpiod_set_value_cansleep(ddata
->ls_oe_gpio
, 0);
161 static bool tpd_detect(struct omap_dss_device
*dssdev
)
163 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
165 return gpiod_get_value_cansleep(ddata
->hpd_gpio
);
168 static int tpd_set_infoframe(struct omap_dss_device
*dssdev
,
169 const struct hdmi_avi_infoframe
*avi
)
171 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
172 struct omap_dss_device
*in
= ddata
->in
;
174 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
177 static int tpd_set_hdmi_mode(struct omap_dss_device
*dssdev
,
180 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
181 struct omap_dss_device
*in
= ddata
->in
;
183 return in
->ops
.hdmi
->set_hdmi_mode(in
, hdmi_mode
);
186 static const struct omapdss_hdmi_ops tpd_hdmi_ops
= {
187 .connect
= tpd_connect
,
188 .disconnect
= tpd_disconnect
,
190 .enable
= tpd_enable
,
191 .disable
= tpd_disable
,
193 .check_timings
= tpd_check_timings
,
194 .set_timings
= tpd_set_timings
,
195 .get_timings
= tpd_get_timings
,
197 .read_edid
= tpd_read_edid
,
198 .detect
= tpd_detect
,
199 .set_infoframe
= tpd_set_infoframe
,
200 .set_hdmi_mode
= tpd_set_hdmi_mode
,
203 static int tpd_probe_of(struct platform_device
*pdev
)
205 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
206 struct device_node
*node
= pdev
->dev
.of_node
;
207 struct omap_dss_device
*in
;
209 in
= omapdss_of_find_source_for_first_ep(node
);
211 dev_err(&pdev
->dev
, "failed to find video source\n");
220 static int tpd_probe(struct platform_device
*pdev
)
222 struct omap_dss_device
*in
, *dssdev
;
223 struct panel_drv_data
*ddata
;
225 struct gpio_desc
*gpio
;
227 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
231 platform_set_drvdata(pdev
, ddata
);
233 if (pdev
->dev
.of_node
) {
234 r
= tpd_probe_of(pdev
);
242 gpio
= devm_gpiod_get_index_optional(&pdev
->dev
, NULL
, 0,
247 ddata
->ct_cp_hpd_gpio
= gpio
;
249 gpio
= devm_gpiod_get_index_optional(&pdev
->dev
, NULL
, 1,
254 ddata
->ls_oe_gpio
= gpio
;
256 gpio
= devm_gpiod_get_index(&pdev
->dev
, NULL
, 2,
261 ddata
->hpd_gpio
= gpio
;
263 dssdev
= &ddata
->dssdev
;
264 dssdev
->ops
.hdmi
= &tpd_hdmi_ops
;
265 dssdev
->dev
= &pdev
->dev
;
266 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
267 dssdev
->output_type
= OMAP_DISPLAY_TYPE_HDMI
;
268 dssdev
->owner
= THIS_MODULE
;
269 dssdev
->port_num
= 1;
273 r
= omapdss_register_output(dssdev
);
275 dev_err(&pdev
->dev
, "Failed to register output\n");
282 omap_dss_put_device(ddata
->in
);
286 static int __exit
tpd_remove(struct platform_device
*pdev
)
288 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
289 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
290 struct omap_dss_device
*in
= ddata
->in
;
292 omapdss_unregister_output(&ddata
->dssdev
);
294 WARN_ON(omapdss_device_is_enabled(dssdev
));
295 if (omapdss_device_is_enabled(dssdev
))
298 WARN_ON(omapdss_device_is_connected(dssdev
));
299 if (omapdss_device_is_connected(dssdev
))
300 tpd_disconnect(dssdev
, dssdev
->dst
);
302 omap_dss_put_device(in
);
307 static const struct of_device_id tpd_of_match
[] = {
308 { .compatible
= "omapdss,ti,tpd12s015", },
312 MODULE_DEVICE_TABLE(of
, tpd_of_match
);
314 static struct platform_driver tpd_driver
= {
316 .remove
= __exit_p(tpd_remove
),
319 .of_match_table
= tpd_of_match
,
320 .suppress_bind_attrs
= true,
324 module_platform_driver(tpd_driver
);
326 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
327 MODULE_DESCRIPTION("TPD12S015 driver");
328 MODULE_LICENSE("GPL");