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 = {
32 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
33 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
38 struct panel_drv_data {
39 struct omap_dss_device dssdev;
40 struct omap_dss_device *in;
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;
55 dev_dbg(ddata->dev, "connect\n");
57 if (omapdss_device_is_connected(dssdev))
60 r = in->ops.hdmi->connect(in, dssdev);
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))
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;
86 dev_dbg(ddata->dev, "enable\n");
88 if (!omapdss_device_is_connected(dssdev))
91 if (omapdss_device_is_enabled(dssdev))
94 in->ops.hdmi->set_timings(in, &ddata->timings);
96 r = in->ops.hdmi->enable(in);
100 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
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))
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,
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;
172 /* enable audio only if the display is active */
173 if (!omapdss_device_is_enabled(dssdev))
176 r = in->ops.hdmi->audio_enable(in);
180 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
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;
202 * No need to check the panel state. It was checked when trasitioning
205 if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED)
208 r = in->ops.hdmi->audio_start(in);
212 dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
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))
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;
245 /* config audio only if the display is active */
246 if (!omapdss_device_is_enabled(dssdev))
249 r = in->ops.hdmi->audio_config(in, audio);
253 dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
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);
292 dev_err(&pdev->dev, "Failed to find video source\n");
293 return -EPROBE_DEFER;
298 dssdev = &ddata->dssdev;
299 dssdev->name = pdata->name;
304 static int hdmic_probe(struct platform_device *pdev)
306 struct panel_drv_data *ddata;
307 struct omap_dss_device *dssdev;
310 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
314 platform_set_drvdata(pdev, ddata);
315 ddata->dev = &pdev->dev;
317 if (dev_get_platdata(&pdev->dev)) {
318 r = hdmic_probe_pdata(pdev);
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);
336 dev_err(&pdev->dev, "Failed to register panel\n");
342 omap_dss_put_device(ddata->in);
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);
362 static struct platform_driver hdmi_connector_driver = {
363 .probe = hdmic_probe,
364 .remove = __exit_p(hdmic_remove),
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");