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>
17 #include <drm/drm_edid.h>
19 #include <video/omapdss.h>
20 #include <video/omap-panel-data.h>
22 static const struct omap_video_timings hdmic_default_timings = {
25 .pixelclock = 25175000,
33 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
34 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
39 struct panel_drv_data {
40 struct omap_dss_device dssdev;
41 struct omap_dss_device *in;
45 struct omap_video_timings timings;
48 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
50 static int hdmic_connect(struct omap_dss_device *dssdev)
52 struct panel_drv_data *ddata = to_panel_data(dssdev);
53 struct omap_dss_device *in = ddata->in;
56 dev_dbg(ddata->dev, "connect\n");
58 if (omapdss_device_is_connected(dssdev))
61 r = in->ops.hdmi->connect(in, dssdev);
68 static void hdmic_disconnect(struct omap_dss_device *dssdev)
70 struct panel_drv_data *ddata = to_panel_data(dssdev);
71 struct omap_dss_device *in = ddata->in;
73 dev_dbg(ddata->dev, "disconnect\n");
75 if (!omapdss_device_is_connected(dssdev))
78 in->ops.hdmi->disconnect(in, dssdev);
81 static int hdmic_enable(struct omap_dss_device *dssdev)
83 struct panel_drv_data *ddata = to_panel_data(dssdev);
84 struct omap_dss_device *in = ddata->in;
87 dev_dbg(ddata->dev, "enable\n");
89 if (!omapdss_device_is_connected(dssdev))
92 if (omapdss_device_is_enabled(dssdev))
95 in->ops.hdmi->set_timings(in, &ddata->timings);
97 r = in->ops.hdmi->enable(in);
101 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
106 static void hdmic_disable(struct omap_dss_device *dssdev)
108 struct panel_drv_data *ddata = to_panel_data(dssdev);
109 struct omap_dss_device *in = ddata->in;
111 dev_dbg(ddata->dev, "disable\n");
113 if (!omapdss_device_is_enabled(dssdev))
116 in->ops.hdmi->disable(in);
118 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
121 static void hdmic_set_timings(struct omap_dss_device *dssdev,
122 struct omap_video_timings *timings)
124 struct panel_drv_data *ddata = to_panel_data(dssdev);
125 struct omap_dss_device *in = ddata->in;
127 ddata->timings = *timings;
128 dssdev->panel.timings = *timings;
130 in->ops.hdmi->set_timings(in, timings);
133 static void hdmic_get_timings(struct omap_dss_device *dssdev,
134 struct omap_video_timings *timings)
136 struct panel_drv_data *ddata = to_panel_data(dssdev);
138 *timings = ddata->timings;
141 static int hdmic_check_timings(struct omap_dss_device *dssdev,
142 struct omap_video_timings *timings)
144 struct panel_drv_data *ddata = to_panel_data(dssdev);
145 struct omap_dss_device *in = ddata->in;
147 return in->ops.hdmi->check_timings(in, timings);
150 static int hdmic_read_edid(struct omap_dss_device *dssdev,
153 struct panel_drv_data *ddata = to_panel_data(dssdev);
154 struct omap_dss_device *in = ddata->in;
156 return in->ops.hdmi->read_edid(in, edid, len);
159 static bool hdmic_detect(struct omap_dss_device *dssdev)
161 struct panel_drv_data *ddata = to_panel_data(dssdev);
162 struct omap_dss_device *in = ddata->in;
164 return in->ops.hdmi->detect(in);
167 static int hdmic_audio_enable(struct omap_dss_device *dssdev)
169 struct panel_drv_data *ddata = to_panel_data(dssdev);
170 struct omap_dss_device *in = ddata->in;
173 /* enable audio only if the display is active */
174 if (!omapdss_device_is_enabled(dssdev))
177 r = in->ops.hdmi->audio_enable(in);
181 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
186 static void hdmic_audio_disable(struct omap_dss_device *dssdev)
188 struct panel_drv_data *ddata = to_panel_data(dssdev);
189 struct omap_dss_device *in = ddata->in;
191 in->ops.hdmi->audio_disable(in);
193 dssdev->audio_state = OMAP_DSS_AUDIO_DISABLED;
196 static int hdmic_audio_start(struct omap_dss_device *dssdev)
198 struct panel_drv_data *ddata = to_panel_data(dssdev);
199 struct omap_dss_device *in = ddata->in;
203 * No need to check the panel state. It was checked when trasitioning
206 if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED)
209 r = in->ops.hdmi->audio_start(in);
213 dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
218 static void hdmic_audio_stop(struct omap_dss_device *dssdev)
220 struct panel_drv_data *ddata = to_panel_data(dssdev);
221 struct omap_dss_device *in = ddata->in;
223 in->ops.hdmi->audio_stop(in);
225 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
228 static bool hdmic_audio_supported(struct omap_dss_device *dssdev)
230 struct panel_drv_data *ddata = to_panel_data(dssdev);
231 struct omap_dss_device *in = ddata->in;
233 if (!omapdss_device_is_enabled(dssdev))
236 return in->ops.hdmi->audio_supported(in);
239 static int hdmic_audio_config(struct omap_dss_device *dssdev,
240 struct omap_dss_audio *audio)
242 struct panel_drv_data *ddata = to_panel_data(dssdev);
243 struct omap_dss_device *in = ddata->in;
246 /* config audio only if the display is active */
247 if (!omapdss_device_is_enabled(dssdev))
250 r = in->ops.hdmi->audio_config(in, audio);
254 dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
259 static struct omap_dss_driver hdmic_driver = {
260 .connect = hdmic_connect,
261 .disconnect = hdmic_disconnect,
263 .enable = hdmic_enable,
264 .disable = hdmic_disable,
266 .set_timings = hdmic_set_timings,
267 .get_timings = hdmic_get_timings,
268 .check_timings = hdmic_check_timings,
270 .get_resolution = omapdss_default_get_resolution,
272 .read_edid = hdmic_read_edid,
273 .detect = hdmic_detect,
275 .audio_enable = hdmic_audio_enable,
276 .audio_disable = hdmic_audio_disable,
277 .audio_start = hdmic_audio_start,
278 .audio_stop = hdmic_audio_stop,
279 .audio_supported = hdmic_audio_supported,
280 .audio_config = hdmic_audio_config,
283 static int hdmic_probe_pdata(struct platform_device *pdev)
285 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
286 struct connector_hdmi_platform_data *pdata;
287 struct omap_dss_device *in, *dssdev;
289 pdata = dev_get_platdata(&pdev->dev);
291 in = omap_dss_find_output(pdata->source);
293 dev_err(&pdev->dev, "Failed to find video source\n");
294 return -EPROBE_DEFER;
299 dssdev = &ddata->dssdev;
300 dssdev->name = pdata->name;
305 static int hdmic_probe_of(struct platform_device *pdev)
307 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
308 struct device_node *node = pdev->dev.of_node;
309 struct omap_dss_device *in;
311 in = omapdss_of_find_source_for_first_ep(node);
313 dev_err(&pdev->dev, "failed to find video source\n");
322 static int hdmic_probe(struct platform_device *pdev)
324 struct panel_drv_data *ddata;
325 struct omap_dss_device *dssdev;
328 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
332 platform_set_drvdata(pdev, ddata);
333 ddata->dev = &pdev->dev;
335 if (dev_get_platdata(&pdev->dev)) {
336 r = hdmic_probe_pdata(pdev);
339 } else if (pdev->dev.of_node) {
340 r = hdmic_probe_of(pdev);
347 ddata->timings = hdmic_default_timings;
349 dssdev = &ddata->dssdev;
350 dssdev->driver = &hdmic_driver;
351 dssdev->dev = &pdev->dev;
352 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
353 dssdev->owner = THIS_MODULE;
354 dssdev->panel.timings = hdmic_default_timings;
356 r = omapdss_register_display(dssdev);
358 dev_err(&pdev->dev, "Failed to register panel\n");
364 omap_dss_put_device(ddata->in);
368 static int __exit hdmic_remove(struct platform_device *pdev)
370 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
371 struct omap_dss_device *dssdev = &ddata->dssdev;
372 struct omap_dss_device *in = ddata->in;
374 omapdss_unregister_display(&ddata->dssdev);
376 hdmic_disable(dssdev);
377 hdmic_disconnect(dssdev);
379 omap_dss_put_device(in);
384 static const struct of_device_id hdmic_of_match[] = {
385 { .compatible = "omapdss,hdmi-connector", },
389 MODULE_DEVICE_TABLE(of, hdmic_of_match);
391 static struct platform_driver hdmi_connector_driver = {
392 .probe = hdmic_probe,
393 .remove = __exit_p(hdmic_remove),
395 .name = "connector-hdmi",
396 .owner = THIS_MODULE,
397 .of_match_table = hdmic_of_match,
401 module_platform_driver(hdmi_connector_driver);
403 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
404 MODULE_DESCRIPTION("HDMI Connector driver");
405 MODULE_LICENSE("GPL");