PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / video / omap2 / displays-new / encoder-tpd12s015.c
blobd5c936cb217fe78bc0f072a602f22c14b61e388f
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/gpio.h>
17 #include <linux/platform_device.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 int ct_cp_hpd_gpio;
27 int ls_oe_gpio;
28 int hpd_gpio;
30 struct omap_video_timings timings;
32 struct completion hpd_completion;
35 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
37 static irqreturn_t tpd_hpd_irq_handler(int irq, void *data)
39 struct panel_drv_data *ddata = data;
40 bool hpd;
42 hpd = gpio_get_value_cansleep(ddata->hpd_gpio);
44 dev_dbg(ddata->dssdev.dev, "hpd %d\n", hpd);
46 if (gpio_is_valid(ddata->ls_oe_gpio)) {
47 if (hpd)
48 gpio_set_value_cansleep(ddata->ls_oe_gpio, 1);
49 else
50 gpio_set_value_cansleep(ddata->ls_oe_gpio, 0);
53 complete_all(&ddata->hpd_completion);
55 return IRQ_HANDLED;
58 static int tpd_connect(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;
63 int r;
65 r = in->ops.hdmi->connect(in, dssdev);
66 if (r)
67 return r;
69 dst->src = dssdev;
70 dssdev->dst = dst;
72 reinit_completion(&ddata->hpd_completion);
74 gpio_set_value_cansleep(ddata->ct_cp_hpd_gpio, 1);
75 /* DC-DC converter needs at max 300us to get to 90% of 5V */
76 udelay(300);
79 * If there's a cable connected, wait for the hpd irq to trigger,
80 * which turns on the level shifters.
82 if (gpio_get_value_cansleep(ddata->hpd_gpio)) {
83 unsigned long to;
84 to = wait_for_completion_timeout(&ddata->hpd_completion,
85 msecs_to_jiffies(250));
86 WARN_ON_ONCE(to == 0);
89 return 0;
92 static void tpd_disconnect(struct omap_dss_device *dssdev,
93 struct omap_dss_device *dst)
95 struct panel_drv_data *ddata = to_panel_data(dssdev);
96 struct omap_dss_device *in = ddata->in;
98 WARN_ON(dst != dssdev->dst);
100 if (dst != dssdev->dst)
101 return;
103 gpio_set_value_cansleep(ddata->ct_cp_hpd_gpio, 0);
105 dst->src = NULL;
106 dssdev->dst = NULL;
108 in->ops.hdmi->disconnect(in, &ddata->dssdev);
111 static int tpd_enable(struct omap_dss_device *dssdev)
113 struct panel_drv_data *ddata = to_panel_data(dssdev);
114 struct omap_dss_device *in = ddata->in;
115 int r;
117 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
118 return 0;
120 in->ops.hdmi->set_timings(in, &ddata->timings);
122 r = in->ops.hdmi->enable(in);
123 if (r)
124 return r;
126 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
128 return r;
131 static void tpd_disable(struct omap_dss_device *dssdev)
133 struct panel_drv_data *ddata = to_panel_data(dssdev);
134 struct omap_dss_device *in = ddata->in;
136 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
137 return;
139 in->ops.hdmi->disable(in);
141 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
144 static void tpd_set_timings(struct omap_dss_device *dssdev,
145 struct omap_video_timings *timings)
147 struct panel_drv_data *ddata = to_panel_data(dssdev);
148 struct omap_dss_device *in = ddata->in;
150 ddata->timings = *timings;
151 dssdev->panel.timings = *timings;
153 in->ops.hdmi->set_timings(in, timings);
156 static void tpd_get_timings(struct omap_dss_device *dssdev,
157 struct omap_video_timings *timings)
159 struct panel_drv_data *ddata = to_panel_data(dssdev);
161 *timings = ddata->timings;
164 static int tpd_check_timings(struct omap_dss_device *dssdev,
165 struct omap_video_timings *timings)
167 struct panel_drv_data *ddata = to_panel_data(dssdev);
168 struct omap_dss_device *in = ddata->in;
169 int r;
171 r = in->ops.hdmi->check_timings(in, timings);
173 return r;
176 static int tpd_read_edid(struct omap_dss_device *dssdev,
177 u8 *edid, int len)
179 struct panel_drv_data *ddata = to_panel_data(dssdev);
180 struct omap_dss_device *in = ddata->in;
182 if (!gpio_get_value_cansleep(ddata->hpd_gpio))
183 return -ENODEV;
185 return in->ops.hdmi->read_edid(in, edid, len);
188 static bool tpd_detect(struct omap_dss_device *dssdev)
190 struct panel_drv_data *ddata = to_panel_data(dssdev);
192 return gpio_get_value_cansleep(ddata->hpd_gpio);
195 static int tpd_audio_enable(struct omap_dss_device *dssdev)
197 struct panel_drv_data *ddata = to_panel_data(dssdev);
198 struct omap_dss_device *in = ddata->in;
200 return in->ops.hdmi->audio_enable(in);
203 static void tpd_audio_disable(struct omap_dss_device *dssdev)
205 struct panel_drv_data *ddata = to_panel_data(dssdev);
206 struct omap_dss_device *in = ddata->in;
208 in->ops.hdmi->audio_disable(in);
211 static int tpd_audio_start(struct omap_dss_device *dssdev)
213 struct panel_drv_data *ddata = to_panel_data(dssdev);
214 struct omap_dss_device *in = ddata->in;
216 return in->ops.hdmi->audio_start(in);
219 static void tpd_audio_stop(struct omap_dss_device *dssdev)
221 struct panel_drv_data *ddata = to_panel_data(dssdev);
222 struct omap_dss_device *in = ddata->in;
224 in->ops.hdmi->audio_stop(in);
227 static bool tpd_audio_supported(struct omap_dss_device *dssdev)
229 struct panel_drv_data *ddata = to_panel_data(dssdev);
230 struct omap_dss_device *in = ddata->in;
232 return in->ops.hdmi->audio_supported(in);
235 static int tpd_audio_config(struct omap_dss_device *dssdev,
236 struct omap_dss_audio *audio)
238 struct panel_drv_data *ddata = to_panel_data(dssdev);
239 struct omap_dss_device *in = ddata->in;
241 return in->ops.hdmi->audio_config(in, audio);
244 static const struct omapdss_hdmi_ops tpd_hdmi_ops = {
245 .connect = tpd_connect,
246 .disconnect = tpd_disconnect,
248 .enable = tpd_enable,
249 .disable = tpd_disable,
251 .check_timings = tpd_check_timings,
252 .set_timings = tpd_set_timings,
253 .get_timings = tpd_get_timings,
255 .read_edid = tpd_read_edid,
256 .detect = tpd_detect,
258 .audio_enable = tpd_audio_enable,
259 .audio_disable = tpd_audio_disable,
260 .audio_start = tpd_audio_start,
261 .audio_stop = tpd_audio_stop,
262 .audio_supported = tpd_audio_supported,
263 .audio_config = tpd_audio_config,
266 static int tpd_probe_pdata(struct platform_device *pdev)
268 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
269 struct encoder_tpd12s015_platform_data *pdata;
270 struct omap_dss_device *dssdev, *in;
272 pdata = dev_get_platdata(&pdev->dev);
274 ddata->ct_cp_hpd_gpio = pdata->ct_cp_hpd_gpio;
275 ddata->ls_oe_gpio = pdata->ls_oe_gpio;
276 ddata->hpd_gpio = pdata->hpd_gpio;
278 in = omap_dss_find_output(pdata->source);
279 if (in == NULL) {
280 dev_err(&pdev->dev, "Failed to find video source\n");
281 return -ENODEV;
284 ddata->in = in;
286 dssdev = &ddata->dssdev;
287 dssdev->name = pdata->name;
289 return 0;
292 static int tpd_probe(struct platform_device *pdev)
294 struct omap_dss_device *in, *dssdev;
295 struct panel_drv_data *ddata;
296 int r;
298 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
299 if (!ddata)
300 return -ENOMEM;
302 platform_set_drvdata(pdev, ddata);
304 init_completion(&ddata->hpd_completion);
306 if (dev_get_platdata(&pdev->dev)) {
307 r = tpd_probe_pdata(pdev);
308 if (r)
309 return r;
310 } else {
311 return -ENODEV;
314 r = devm_gpio_request_one(&pdev->dev, ddata->ct_cp_hpd_gpio,
315 GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd");
316 if (r)
317 goto err_gpio;
319 if (gpio_is_valid(ddata->ls_oe_gpio)) {
320 r = devm_gpio_request_one(&pdev->dev, ddata->ls_oe_gpio,
321 GPIOF_OUT_INIT_LOW, "hdmi_ls_oe");
322 if (r)
323 goto err_gpio;
326 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
327 GPIOF_DIR_IN, "hdmi_hpd");
328 if (r)
329 goto err_gpio;
331 r = devm_request_threaded_irq(&pdev->dev, gpio_to_irq(ddata->hpd_gpio),
332 NULL, tpd_hpd_irq_handler,
333 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
334 IRQF_ONESHOT, "hpd", ddata);
335 if (r)
336 goto err_irq;
338 dssdev = &ddata->dssdev;
339 dssdev->ops.hdmi = &tpd_hdmi_ops;
340 dssdev->dev = &pdev->dev;
341 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
342 dssdev->output_type = OMAP_DISPLAY_TYPE_HDMI;
343 dssdev->owner = THIS_MODULE;
345 in = ddata->in;
347 r = omapdss_register_output(dssdev);
348 if (r) {
349 dev_err(&pdev->dev, "Failed to register output\n");
350 goto err_reg;
353 return 0;
354 err_reg:
355 err_irq:
356 err_gpio:
357 omap_dss_put_device(ddata->in);
358 return r;
361 static int __exit tpd_remove(struct platform_device *pdev)
363 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
364 struct omap_dss_device *dssdev = &ddata->dssdev;
365 struct omap_dss_device *in = ddata->in;
367 omapdss_unregister_output(&ddata->dssdev);
369 WARN_ON(omapdss_device_is_enabled(dssdev));
370 if (omapdss_device_is_enabled(dssdev))
371 tpd_disable(dssdev);
373 WARN_ON(omapdss_device_is_connected(dssdev));
374 if (omapdss_device_is_connected(dssdev))
375 tpd_disconnect(dssdev, dssdev->dst);
377 omap_dss_put_device(in);
379 return 0;
382 static struct platform_driver tpd_driver = {
383 .probe = tpd_probe,
384 .remove = __exit_p(tpd_remove),
385 .driver = {
386 .name = "tpd12s015",
387 .owner = THIS_MODULE,
391 module_platform_driver(tpd_driver);
393 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
394 MODULE_DESCRIPTION("TPD12S015 driver");
395 MODULE_LICENSE("GPL");