x86/boot: Rename overlapping memcpy() to memmove()
[linux/fpc-iii.git] / drivers / video / fbdev / omap2 / omapfb / displays / encoder-tpd12s015.c
blob677e2545fcbe680c7460aab3c1b25e1d6e7add2e
1 /*
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;
40 int r;
42 r = in->ops.hdmi->connect(in, dssdev);
43 if (r)
44 return r;
46 dst->src = dssdev;
47 dssdev->dst = dst;
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 */
52 udelay(300);
55 return 0;
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)
67 return;
69 gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 0);
71 dst->src = NULL;
72 dssdev->dst = NULL;
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;
81 int r;
83 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
84 return 0;
86 in->ops.hdmi->set_timings(in, &ddata->timings);
88 r = in->ops.hdmi->enable(in);
89 if (r)
90 return r;
92 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
94 return r;
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)
103 return;
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;
135 int r;
137 r = in->ops.hdmi->check_timings(in, timings);
139 return r;
142 static int tpd_read_edid(struct omap_dss_device *dssdev,
143 u8 *edid, int len)
145 struct panel_drv_data *ddata = to_panel_data(dssdev);
146 struct omap_dss_device *in = ddata->in;
147 int r;
149 if (!gpiod_get_value_cansleep(ddata->hpd_gpio))
150 return -ENODEV;
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);
158 return r;
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,
178 bool hdmi_mode)
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);
210 if (IS_ERR(in)) {
211 dev_err(&pdev->dev, "failed to find video source\n");
212 return PTR_ERR(in);
215 ddata->in = in;
217 return 0;
220 static int tpd_probe(struct platform_device *pdev)
222 struct omap_dss_device *in, *dssdev;
223 struct panel_drv_data *ddata;
224 int r;
225 struct gpio_desc *gpio;
227 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
228 if (!ddata)
229 return -ENOMEM;
231 platform_set_drvdata(pdev, ddata);
233 if (pdev->dev.of_node) {
234 r = tpd_probe_of(pdev);
235 if (r)
236 return r;
237 } else {
238 return -ENODEV;
242 gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 0,
243 GPIOD_OUT_LOW);
244 if (IS_ERR(gpio))
245 goto err_gpio;
247 ddata->ct_cp_hpd_gpio = gpio;
249 gpio = devm_gpiod_get_index_optional(&pdev->dev, NULL, 1,
250 GPIOD_OUT_LOW);
251 if (IS_ERR(gpio))
252 goto err_gpio;
254 ddata->ls_oe_gpio = gpio;
256 gpio = devm_gpiod_get_index(&pdev->dev, NULL, 2,
257 GPIOD_IN);
258 if (IS_ERR(gpio))
259 goto err_gpio;
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;
271 in = ddata->in;
273 r = omapdss_register_output(dssdev);
274 if (r) {
275 dev_err(&pdev->dev, "Failed to register output\n");
276 goto err_reg;
279 return 0;
280 err_reg:
281 err_gpio:
282 omap_dss_put_device(ddata->in);
283 return r;
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))
296 tpd_disable(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);
304 return 0;
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 = {
315 .probe = tpd_probe,
316 .remove = __exit_p(tpd_remove),
317 .driver = {
318 .name = "tpd12s015",
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");