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 "../dss/omapdss.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 gpiod_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 1);
49 /* DC-DC converter needs at max 300us to get to 90% of 5V */
55 static void tpd_disconnect(struct omap_dss_device
*dssdev
,
56 struct omap_dss_device
*dst
)
58 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
59 struct omap_dss_device
*in
= ddata
->in
;
61 WARN_ON(dst
!= dssdev
->dst
);
63 if (dst
!= dssdev
->dst
)
66 gpiod_set_value_cansleep(ddata
->ct_cp_hpd_gpio
, 0);
71 in
->ops
.hdmi
->disconnect(in
, &ddata
->dssdev
);
74 static int tpd_enable(struct omap_dss_device
*dssdev
)
76 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
77 struct omap_dss_device
*in
= ddata
->in
;
80 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
)
83 in
->ops
.hdmi
->set_timings(in
, &ddata
->timings
);
85 r
= in
->ops
.hdmi
->enable(in
);
89 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
94 static void tpd_disable(struct omap_dss_device
*dssdev
)
96 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
97 struct omap_dss_device
*in
= ddata
->in
;
99 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
102 in
->ops
.hdmi
->disable(in
);
104 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
107 static void tpd_set_timings(struct omap_dss_device
*dssdev
,
108 struct omap_video_timings
*timings
)
110 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
111 struct omap_dss_device
*in
= ddata
->in
;
113 ddata
->timings
= *timings
;
114 dssdev
->panel
.timings
= *timings
;
116 in
->ops
.hdmi
->set_timings(in
, timings
);
119 static void tpd_get_timings(struct omap_dss_device
*dssdev
,
120 struct omap_video_timings
*timings
)
122 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
124 *timings
= ddata
->timings
;
127 static int tpd_check_timings(struct omap_dss_device
*dssdev
,
128 struct omap_video_timings
*timings
)
130 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
131 struct omap_dss_device
*in
= ddata
->in
;
134 r
= in
->ops
.hdmi
->check_timings(in
, timings
);
139 static int tpd_read_edid(struct omap_dss_device
*dssdev
,
142 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
143 struct omap_dss_device
*in
= ddata
->in
;
146 if (!gpiod_get_value_cansleep(ddata
->hpd_gpio
))
149 gpiod_set_value_cansleep(ddata
->ls_oe_gpio
, 1);
151 r
= in
->ops
.hdmi
->read_edid(in
, edid
, len
);
153 gpiod_set_value_cansleep(ddata
->ls_oe_gpio
, 0);
158 static bool tpd_detect(struct omap_dss_device
*dssdev
)
160 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
162 return gpiod_get_value_cansleep(ddata
->hpd_gpio
);
165 static int tpd_set_infoframe(struct omap_dss_device
*dssdev
,
166 const struct hdmi_avi_infoframe
*avi
)
168 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
169 struct omap_dss_device
*in
= ddata
->in
;
171 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
174 static int tpd_set_hdmi_mode(struct omap_dss_device
*dssdev
,
177 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
178 struct omap_dss_device
*in
= ddata
->in
;
180 return in
->ops
.hdmi
->set_hdmi_mode(in
, hdmi_mode
);
183 static const struct omapdss_hdmi_ops tpd_hdmi_ops
= {
184 .connect
= tpd_connect
,
185 .disconnect
= tpd_disconnect
,
187 .enable
= tpd_enable
,
188 .disable
= tpd_disable
,
190 .check_timings
= tpd_check_timings
,
191 .set_timings
= tpd_set_timings
,
192 .get_timings
= tpd_get_timings
,
194 .read_edid
= tpd_read_edid
,
195 .detect
= tpd_detect
,
196 .set_infoframe
= tpd_set_infoframe
,
197 .set_hdmi_mode
= tpd_set_hdmi_mode
,
200 static int tpd_probe_of(struct platform_device
*pdev
)
202 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
203 struct device_node
*node
= pdev
->dev
.of_node
;
204 struct omap_dss_device
*in
;
206 in
= omapdss_of_find_source_for_first_ep(node
);
208 dev_err(&pdev
->dev
, "failed to find video source\n");
217 static int tpd_probe(struct platform_device
*pdev
)
219 struct omap_dss_device
*in
, *dssdev
;
220 struct panel_drv_data
*ddata
;
222 struct gpio_desc
*gpio
;
224 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
228 platform_set_drvdata(pdev
, ddata
);
230 if (!pdev
->dev
.of_node
)
233 r
= tpd_probe_of(pdev
);
238 gpio
= devm_gpiod_get_index_optional(&pdev
->dev
, NULL
, 0,
243 ddata
->ct_cp_hpd_gpio
= gpio
;
245 gpio
= devm_gpiod_get_index_optional(&pdev
->dev
, NULL
, 1,
250 ddata
->ls_oe_gpio
= gpio
;
252 gpio
= devm_gpiod_get_index(&pdev
->dev
, NULL
, 2,
257 ddata
->hpd_gpio
= gpio
;
259 dssdev
= &ddata
->dssdev
;
260 dssdev
->ops
.hdmi
= &tpd_hdmi_ops
;
261 dssdev
->dev
= &pdev
->dev
;
262 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
263 dssdev
->output_type
= OMAP_DISPLAY_TYPE_HDMI
;
264 dssdev
->owner
= THIS_MODULE
;
265 dssdev
->port_num
= 1;
269 r
= omapdss_register_output(dssdev
);
271 dev_err(&pdev
->dev
, "Failed to register output\n");
278 omap_dss_put_device(ddata
->in
);
282 static int __exit
tpd_remove(struct platform_device
*pdev
)
284 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
285 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
286 struct omap_dss_device
*in
= ddata
->in
;
288 omapdss_unregister_output(&ddata
->dssdev
);
290 WARN_ON(omapdss_device_is_enabled(dssdev
));
291 if (omapdss_device_is_enabled(dssdev
))
294 WARN_ON(omapdss_device_is_connected(dssdev
));
295 if (omapdss_device_is_connected(dssdev
))
296 tpd_disconnect(dssdev
, dssdev
->dst
);
298 omap_dss_put_device(in
);
303 static const struct of_device_id tpd_of_match
[] = {
304 { .compatible
= "omapdss,ti,tpd12s015", },
308 MODULE_DEVICE_TABLE(of
, tpd_of_match
);
310 static struct platform_driver tpd_driver
= {
312 .remove
= __exit_p(tpd_remove
),
315 .of_match_table
= tpd_of_match
,
316 .suppress_bind_attrs
= true,
320 module_platform_driver(tpd_driver
);
322 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
323 MODULE_DESCRIPTION("TPD12S015 driver");
324 MODULE_LICENSE("GPL");