PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / video / omap2 / displays-new / connector-hdmi.c
blob9abe2c039ae9c44f0ea2cb2a3362c021e9273df4
1 /*
2 * HDMI Connector 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/slab.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
16 #include <drm/drm_edid.h>
18 #include <video/omapdss.h>
19 #include <video/omap-panel-data.h>
21 static const struct omap_video_timings hdmic_default_timings = {
22 .x_res = 640,
23 .y_res = 480,
24 .pixel_clock = 25175,
25 .hsw = 96,
26 .hfp = 16,
27 .hbp = 48,
28 .vsw = 2,
29 .vfp = 11,
30 .vbp = 31,
32 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
33 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
35 .interlace = false,
38 struct panel_drv_data {
39 struct omap_dss_device dssdev;
40 struct omap_dss_device *in;
42 struct device *dev;
44 struct omap_video_timings timings;
47 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
49 static int hdmic_connect(struct omap_dss_device *dssdev)
51 struct panel_drv_data *ddata = to_panel_data(dssdev);
52 struct omap_dss_device *in = ddata->in;
53 int r;
55 dev_dbg(ddata->dev, "connect\n");
57 if (omapdss_device_is_connected(dssdev))
58 return 0;
60 r = in->ops.hdmi->connect(in, dssdev);
61 if (r)
62 return r;
64 return 0;
67 static void hdmic_disconnect(struct omap_dss_device *dssdev)
69 struct panel_drv_data *ddata = to_panel_data(dssdev);
70 struct omap_dss_device *in = ddata->in;
72 dev_dbg(ddata->dev, "disconnect\n");
74 if (!omapdss_device_is_connected(dssdev))
75 return;
77 in->ops.hdmi->disconnect(in, dssdev);
80 static int hdmic_enable(struct omap_dss_device *dssdev)
82 struct panel_drv_data *ddata = to_panel_data(dssdev);
83 struct omap_dss_device *in = ddata->in;
84 int r;
86 dev_dbg(ddata->dev, "enable\n");
88 if (!omapdss_device_is_connected(dssdev))
89 return -ENODEV;
91 if (omapdss_device_is_enabled(dssdev))
92 return 0;
94 in->ops.hdmi->set_timings(in, &ddata->timings);
96 r = in->ops.hdmi->enable(in);
97 if (r)
98 return r;
100 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
102 return r;
105 static void hdmic_disable(struct omap_dss_device *dssdev)
107 struct panel_drv_data *ddata = to_panel_data(dssdev);
108 struct omap_dss_device *in = ddata->in;
110 dev_dbg(ddata->dev, "disable\n");
112 if (!omapdss_device_is_enabled(dssdev))
113 return;
115 in->ops.hdmi->disable(in);
117 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
120 static void hdmic_set_timings(struct omap_dss_device *dssdev,
121 struct omap_video_timings *timings)
123 struct panel_drv_data *ddata = to_panel_data(dssdev);
124 struct omap_dss_device *in = ddata->in;
126 ddata->timings = *timings;
127 dssdev->panel.timings = *timings;
129 in->ops.hdmi->set_timings(in, timings);
132 static void hdmic_get_timings(struct omap_dss_device *dssdev,
133 struct omap_video_timings *timings)
135 struct panel_drv_data *ddata = to_panel_data(dssdev);
137 *timings = ddata->timings;
140 static int hdmic_check_timings(struct omap_dss_device *dssdev,
141 struct omap_video_timings *timings)
143 struct panel_drv_data *ddata = to_panel_data(dssdev);
144 struct omap_dss_device *in = ddata->in;
146 return in->ops.hdmi->check_timings(in, timings);
149 static int hdmic_read_edid(struct omap_dss_device *dssdev,
150 u8 *edid, int len)
152 struct panel_drv_data *ddata = to_panel_data(dssdev);
153 struct omap_dss_device *in = ddata->in;
155 return in->ops.hdmi->read_edid(in, edid, len);
158 static bool hdmic_detect(struct omap_dss_device *dssdev)
160 struct panel_drv_data *ddata = to_panel_data(dssdev);
161 struct omap_dss_device *in = ddata->in;
163 return in->ops.hdmi->detect(in);
166 static int hdmic_audio_enable(struct omap_dss_device *dssdev)
168 struct panel_drv_data *ddata = to_panel_data(dssdev);
169 struct omap_dss_device *in = ddata->in;
170 int r;
172 /* enable audio only if the display is active */
173 if (!omapdss_device_is_enabled(dssdev))
174 return -EPERM;
176 r = in->ops.hdmi->audio_enable(in);
177 if (r)
178 return r;
180 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
182 return 0;
185 static void hdmic_audio_disable(struct omap_dss_device *dssdev)
187 struct panel_drv_data *ddata = to_panel_data(dssdev);
188 struct omap_dss_device *in = ddata->in;
190 in->ops.hdmi->audio_disable(in);
192 dssdev->audio_state = OMAP_DSS_AUDIO_DISABLED;
195 static int hdmic_audio_start(struct omap_dss_device *dssdev)
197 struct panel_drv_data *ddata = to_panel_data(dssdev);
198 struct omap_dss_device *in = ddata->in;
199 int r;
202 * No need to check the panel state. It was checked when trasitioning
203 * to AUDIO_ENABLED.
205 if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED)
206 return -EPERM;
208 r = in->ops.hdmi->audio_start(in);
209 if (r)
210 return r;
212 dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
214 return 0;
217 static void hdmic_audio_stop(struct omap_dss_device *dssdev)
219 struct panel_drv_data *ddata = to_panel_data(dssdev);
220 struct omap_dss_device *in = ddata->in;
222 in->ops.hdmi->audio_stop(in);
224 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
227 static bool hdmic_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 if (!omapdss_device_is_enabled(dssdev))
233 return false;
235 return in->ops.hdmi->audio_supported(in);
238 static int hdmic_audio_config(struct omap_dss_device *dssdev,
239 struct omap_dss_audio *audio)
241 struct panel_drv_data *ddata = to_panel_data(dssdev);
242 struct omap_dss_device *in = ddata->in;
243 int r;
245 /* config audio only if the display is active */
246 if (!omapdss_device_is_enabled(dssdev))
247 return -EPERM;
249 r = in->ops.hdmi->audio_config(in, audio);
250 if (r)
251 return r;
253 dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
255 return 0;
258 static struct omap_dss_driver hdmic_driver = {
259 .connect = hdmic_connect,
260 .disconnect = hdmic_disconnect,
262 .enable = hdmic_enable,
263 .disable = hdmic_disable,
265 .set_timings = hdmic_set_timings,
266 .get_timings = hdmic_get_timings,
267 .check_timings = hdmic_check_timings,
269 .get_resolution = omapdss_default_get_resolution,
271 .read_edid = hdmic_read_edid,
272 .detect = hdmic_detect,
274 .audio_enable = hdmic_audio_enable,
275 .audio_disable = hdmic_audio_disable,
276 .audio_start = hdmic_audio_start,
277 .audio_stop = hdmic_audio_stop,
278 .audio_supported = hdmic_audio_supported,
279 .audio_config = hdmic_audio_config,
282 static int hdmic_probe_pdata(struct platform_device *pdev)
284 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
285 struct connector_hdmi_platform_data *pdata;
286 struct omap_dss_device *in, *dssdev;
288 pdata = dev_get_platdata(&pdev->dev);
290 in = omap_dss_find_output(pdata->source);
291 if (in == NULL) {
292 dev_err(&pdev->dev, "Failed to find video source\n");
293 return -EPROBE_DEFER;
296 ddata->in = in;
298 dssdev = &ddata->dssdev;
299 dssdev->name = pdata->name;
301 return 0;
304 static int hdmic_probe(struct platform_device *pdev)
306 struct panel_drv_data *ddata;
307 struct omap_dss_device *dssdev;
308 int r;
310 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
311 if (!ddata)
312 return -ENOMEM;
314 platform_set_drvdata(pdev, ddata);
315 ddata->dev = &pdev->dev;
317 if (dev_get_platdata(&pdev->dev)) {
318 r = hdmic_probe_pdata(pdev);
319 if (r)
320 return r;
321 } else {
322 return -ENODEV;
325 ddata->timings = hdmic_default_timings;
327 dssdev = &ddata->dssdev;
328 dssdev->driver = &hdmic_driver;
329 dssdev->dev = &pdev->dev;
330 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
331 dssdev->owner = THIS_MODULE;
332 dssdev->panel.timings = hdmic_default_timings;
334 r = omapdss_register_display(dssdev);
335 if (r) {
336 dev_err(&pdev->dev, "Failed to register panel\n");
337 goto err_reg;
340 return 0;
341 err_reg:
342 omap_dss_put_device(ddata->in);
343 return r;
346 static int __exit hdmic_remove(struct platform_device *pdev)
348 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
349 struct omap_dss_device *dssdev = &ddata->dssdev;
350 struct omap_dss_device *in = ddata->in;
352 omapdss_unregister_display(&ddata->dssdev);
354 hdmic_disable(dssdev);
355 hdmic_disconnect(dssdev);
357 omap_dss_put_device(in);
359 return 0;
362 static struct platform_driver hdmi_connector_driver = {
363 .probe = hdmic_probe,
364 .remove = __exit_p(hdmic_remove),
365 .driver = {
366 .name = "connector-hdmi",
367 .owner = THIS_MODULE,
371 module_platform_driver(hdmi_connector_driver);
373 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
374 MODULE_DESCRIPTION("HDMI Connector driver");
375 MODULE_LICENSE("GPL");