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 gpiod_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 1);
50 /* DC-DC converter needs at max 300us to get to 90% of 5V */
56 static void tpd_disconnect(struct omap_dss_device
*dssdev
,
57 struct omap_dss_device
*dst
)
59 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
60 struct omap_dss_device
*in
= ddata
->in
;
62 WARN_ON(dst
!= dssdev
->dst
);
64 if (dst
!= dssdev
->dst
)
67 gpiod_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 0);
72 in
->ops
.hdmi
->disconnect(in
, &ddata
->dssdev
);
75 static int tpd_enable(struct omap_dss_device
*dssdev
)
77 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
78 struct omap_dss_device
*in
= ddata
->in
;
81 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
)
84 in
->ops
.hdmi
->set_timings(in
, &ddata
->timings
);
86 r
= in
->ops
.hdmi
->enable(in
);
90 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
95 static void tpd_disable(struct omap_dss_device
*dssdev
)
97 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
98 struct omap_dss_device
*in
= ddata
->in
;
100 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
103 in
->ops
.hdmi
->disable(in
);
105 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
108 static void tpd_set_timings(struct omap_dss_device
*dssdev
,
109 struct omap_video_timings
*timings
)
111 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
112 struct omap_dss_device
*in
= ddata
->in
;
114 ddata
->timings
= *timings
;
115 dssdev
->panel
.timings
= *timings
;
117 in
->ops
.hdmi
->set_timings(in
, timings
);
120 static void tpd_get_timings(struct omap_dss_device
*dssdev
,
121 struct omap_video_timings
*timings
)
123 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
125 *timings
= ddata
->timings
;
128 static int tpd_check_timings(struct omap_dss_device
*dssdev
,
129 struct omap_video_timings
*timings
)
131 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
132 struct omap_dss_device
*in
= ddata
->in
;
135 r
= in
->ops
.hdmi
->check_timings(in
, timings
);
140 static int tpd_read_edid(struct omap_dss_device
*dssdev
,
143 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
144 struct omap_dss_device
*in
= ddata
->in
;
147 if (!gpiod_get_value_cansleep(ddata
->hpd_gpio
))
150 gpiod_set_value_cansleep(ddata
->ls_oe_gpio
, 1);
152 r
= in
->ops
.hdmi
->read_edid(in
, edid
, len
);
154 gpiod_set_value_cansleep(ddata
->ls_oe_gpio
, 0);
159 static bool tpd_detect(struct omap_dss_device
*dssdev
)
161 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
163 return gpiod_get_value_cansleep(ddata
->hpd_gpio
);
166 static int tpd_set_infoframe(struct omap_dss_device
*dssdev
,
167 const struct hdmi_avi_infoframe
*avi
)
169 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
170 struct omap_dss_device
*in
= ddata
->in
;
172 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
175 static int tpd_set_hdmi_mode(struct omap_dss_device
*dssdev
,
178 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
179 struct omap_dss_device
*in
= ddata
->in
;
181 return in
->ops
.hdmi
->set_hdmi_mode(in
, hdmi_mode
);
184 static const struct omapdss_hdmi_ops tpd_hdmi_ops
= {
185 .connect
= tpd_connect
,
186 .disconnect
= tpd_disconnect
,
188 .enable
= tpd_enable
,
189 .disable
= tpd_disable
,
191 .check_timings
= tpd_check_timings
,
192 .set_timings
= tpd_set_timings
,
193 .get_timings
= tpd_get_timings
,
195 .read_edid
= tpd_read_edid
,
196 .detect
= tpd_detect
,
197 .set_infoframe
= tpd_set_infoframe
,
198 .set_hdmi_mode
= tpd_set_hdmi_mode
,
201 static int tpd_probe_of(struct platform_device
*pdev
)
203 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
204 struct device_node
*node
= pdev
->dev
.of_node
;
205 struct omap_dss_device
*in
;
207 in
= omapdss_of_find_source_for_first_ep(node
);
209 dev_err(&pdev
->dev
, "failed to find video source\n");
218 static int tpd_probe(struct platform_device
*pdev
)
220 struct omap_dss_device
*in
, *dssdev
;
221 struct panel_drv_data
*ddata
;
223 struct gpio_desc
*gpio
;
225 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
229 platform_set_drvdata(pdev
, ddata
);
231 if (!pdev
->dev
.of_node
)
234 r
= tpd_probe_of(pdev
);
239 gpio
= devm_gpiod_get_index_optional(&pdev
->dev
, NULL
, 0,
244 ddata
->ct_cp_hpd_gpio
= gpio
;
246 gpio
= devm_gpiod_get_index_optional(&pdev
->dev
, NULL
, 1,
251 ddata
->ls_oe_gpio
= gpio
;
253 gpio
= devm_gpiod_get_index(&pdev
->dev
, NULL
, 2,
258 ddata
->hpd_gpio
= gpio
;
260 dssdev
= &ddata
->dssdev
;
261 dssdev
->ops
.hdmi
= &tpd_hdmi_ops
;
262 dssdev
->dev
= &pdev
->dev
;
263 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
264 dssdev
->output_type
= OMAP_DISPLAY_TYPE_HDMI
;
265 dssdev
->owner
= THIS_MODULE
;
266 dssdev
->port_num
= 1;
270 r
= omapdss_register_output(dssdev
);
272 dev_err(&pdev
->dev
, "Failed to register output\n");
279 omap_dss_put_device(ddata
->in
);
283 static int __exit
tpd_remove(struct platform_device
*pdev
)
285 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
286 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
287 struct omap_dss_device
*in
= ddata
->in
;
289 omapdss_unregister_output(&ddata
->dssdev
);
291 WARN_ON(omapdss_device_is_enabled(dssdev
));
292 if (omapdss_device_is_enabled(dssdev
))
295 WARN_ON(omapdss_device_is_connected(dssdev
));
296 if (omapdss_device_is_connected(dssdev
))
297 tpd_disconnect(dssdev
, dssdev
->dst
);
299 omap_dss_put_device(in
);
304 static const struct of_device_id tpd_of_match
[] = {
305 { .compatible
= "omapdss,ti,tpd12s015", },
309 MODULE_DEVICE_TABLE(of
, tpd_of_match
);
311 static struct platform_driver tpd_driver
= {
313 .remove
= __exit_p(tpd_remove
),
316 .of_match_table
= tpd_of_match
,
317 .suppress_bind_attrs
= true,
321 module_platform_driver(tpd_driver
);
323 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
324 MODULE_DESCRIPTION("TPD12S015 driver");
325 MODULE_LICENSE("GPL");