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 <linux/of_gpio.h>
18 #include <drm/drm_edid.h>
20 #include <video/omapdss.h>
21 #include <video/omap-panel-data.h>
23 static const struct omap_video_timings hdmic_default_timings
= {
26 .pixelclock
= 25175000,
34 .vsync_level
= OMAPDSS_SIG_ACTIVE_LOW
,
35 .hsync_level
= OMAPDSS_SIG_ACTIVE_LOW
,
40 struct panel_drv_data
{
41 struct omap_dss_device dssdev
;
42 struct omap_dss_device
*in
;
46 struct omap_video_timings timings
;
51 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
53 static int hdmic_connect(struct omap_dss_device
*dssdev
)
55 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
56 struct omap_dss_device
*in
= ddata
->in
;
59 dev_dbg(ddata
->dev
, "connect\n");
61 if (omapdss_device_is_connected(dssdev
))
64 r
= in
->ops
.hdmi
->connect(in
, dssdev
);
71 static void hdmic_disconnect(struct omap_dss_device
*dssdev
)
73 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
74 struct omap_dss_device
*in
= ddata
->in
;
76 dev_dbg(ddata
->dev
, "disconnect\n");
78 if (!omapdss_device_is_connected(dssdev
))
81 in
->ops
.hdmi
->disconnect(in
, dssdev
);
84 static int hdmic_enable(struct omap_dss_device
*dssdev
)
86 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
87 struct omap_dss_device
*in
= ddata
->in
;
90 dev_dbg(ddata
->dev
, "enable\n");
92 if (!omapdss_device_is_connected(dssdev
))
95 if (omapdss_device_is_enabled(dssdev
))
98 in
->ops
.hdmi
->set_timings(in
, &ddata
->timings
);
100 r
= in
->ops
.hdmi
->enable(in
);
104 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
109 static void hdmic_disable(struct omap_dss_device
*dssdev
)
111 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
112 struct omap_dss_device
*in
= ddata
->in
;
114 dev_dbg(ddata
->dev
, "disable\n");
116 if (!omapdss_device_is_enabled(dssdev
))
119 in
->ops
.hdmi
->disable(in
);
121 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
124 static void hdmic_set_timings(struct omap_dss_device
*dssdev
,
125 struct omap_video_timings
*timings
)
127 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
128 struct omap_dss_device
*in
= ddata
->in
;
130 ddata
->timings
= *timings
;
131 dssdev
->panel
.timings
= *timings
;
133 in
->ops
.hdmi
->set_timings(in
, timings
);
136 static void hdmic_get_timings(struct omap_dss_device
*dssdev
,
137 struct omap_video_timings
*timings
)
139 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
141 *timings
= ddata
->timings
;
144 static int hdmic_check_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 return in
->ops
.hdmi
->check_timings(in
, timings
);
153 static int hdmic_read_edid(struct omap_dss_device
*dssdev
,
156 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
157 struct omap_dss_device
*in
= ddata
->in
;
159 return in
->ops
.hdmi
->read_edid(in
, edid
, len
);
162 static bool hdmic_detect(struct omap_dss_device
*dssdev
)
164 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
165 struct omap_dss_device
*in
= ddata
->in
;
167 if (gpio_is_valid(ddata
->hpd_gpio
))
168 return gpio_get_value_cansleep(ddata
->hpd_gpio
);
170 return in
->ops
.hdmi
->detect(in
);
173 static int hdmic_audio_enable(struct omap_dss_device
*dssdev
)
175 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
176 struct omap_dss_device
*in
= ddata
->in
;
179 /* enable audio only if the display is active */
180 if (!omapdss_device_is_enabled(dssdev
))
183 r
= in
->ops
.hdmi
->audio_enable(in
);
187 dssdev
->audio_state
= OMAP_DSS_AUDIO_ENABLED
;
192 static void hdmic_audio_disable(struct omap_dss_device
*dssdev
)
194 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
195 struct omap_dss_device
*in
= ddata
->in
;
197 in
->ops
.hdmi
->audio_disable(in
);
199 dssdev
->audio_state
= OMAP_DSS_AUDIO_DISABLED
;
202 static int hdmic_audio_start(struct omap_dss_device
*dssdev
)
204 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
205 struct omap_dss_device
*in
= ddata
->in
;
209 * No need to check the panel state. It was checked when trasitioning
212 if (dssdev
->audio_state
!= OMAP_DSS_AUDIO_ENABLED
)
215 r
= in
->ops
.hdmi
->audio_start(in
);
219 dssdev
->audio_state
= OMAP_DSS_AUDIO_PLAYING
;
224 static void hdmic_audio_stop(struct omap_dss_device
*dssdev
)
226 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
227 struct omap_dss_device
*in
= ddata
->in
;
229 in
->ops
.hdmi
->audio_stop(in
);
231 dssdev
->audio_state
= OMAP_DSS_AUDIO_ENABLED
;
234 static bool hdmic_audio_supported(struct omap_dss_device
*dssdev
)
236 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
237 struct omap_dss_device
*in
= ddata
->in
;
239 if (!omapdss_device_is_enabled(dssdev
))
242 return in
->ops
.hdmi
->audio_supported(in
);
245 static int hdmic_audio_config(struct omap_dss_device
*dssdev
,
246 struct omap_dss_audio
*audio
)
248 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
249 struct omap_dss_device
*in
= ddata
->in
;
252 /* config audio only if the display is active */
253 if (!omapdss_device_is_enabled(dssdev
))
256 r
= in
->ops
.hdmi
->audio_config(in
, audio
);
260 dssdev
->audio_state
= OMAP_DSS_AUDIO_CONFIGURED
;
265 static int hdmic_set_hdmi_mode(struct omap_dss_device
*dssdev
, bool hdmi_mode
)
267 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
268 struct omap_dss_device
*in
= ddata
->in
;
270 return in
->ops
.hdmi
->set_hdmi_mode(in
, hdmi_mode
);
273 static int hdmic_set_infoframe(struct omap_dss_device
*dssdev
,
274 const struct hdmi_avi_infoframe
*avi
)
276 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
277 struct omap_dss_device
*in
= ddata
->in
;
279 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
282 static struct omap_dss_driver hdmic_driver
= {
283 .connect
= hdmic_connect
,
284 .disconnect
= hdmic_disconnect
,
286 .enable
= hdmic_enable
,
287 .disable
= hdmic_disable
,
289 .set_timings
= hdmic_set_timings
,
290 .get_timings
= hdmic_get_timings
,
291 .check_timings
= hdmic_check_timings
,
293 .get_resolution
= omapdss_default_get_resolution
,
295 .read_edid
= hdmic_read_edid
,
296 .detect
= hdmic_detect
,
297 .set_hdmi_mode
= hdmic_set_hdmi_mode
,
298 .set_hdmi_infoframe
= hdmic_set_infoframe
,
300 .audio_enable
= hdmic_audio_enable
,
301 .audio_disable
= hdmic_audio_disable
,
302 .audio_start
= hdmic_audio_start
,
303 .audio_stop
= hdmic_audio_stop
,
304 .audio_supported
= hdmic_audio_supported
,
305 .audio_config
= hdmic_audio_config
,
308 static int hdmic_probe_pdata(struct platform_device
*pdev
)
310 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
311 struct connector_hdmi_platform_data
*pdata
;
312 struct omap_dss_device
*in
, *dssdev
;
314 pdata
= dev_get_platdata(&pdev
->dev
);
316 ddata
->hpd_gpio
= -ENODEV
;
318 in
= omap_dss_find_output(pdata
->source
);
320 dev_err(&pdev
->dev
, "Failed to find video source\n");
321 return -EPROBE_DEFER
;
326 dssdev
= &ddata
->dssdev
;
327 dssdev
->name
= pdata
->name
;
332 static int hdmic_probe_of(struct platform_device
*pdev
)
334 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
335 struct device_node
*node
= pdev
->dev
.of_node
;
336 struct omap_dss_device
*in
;
340 gpio
= of_get_named_gpio(node
, "hpd-gpios", 0);
341 if (gpio_is_valid(gpio
))
342 ddata
->hpd_gpio
= gpio
;
344 ddata
->hpd_gpio
= -ENODEV
;
346 in
= omapdss_of_find_source_for_first_ep(node
);
348 dev_err(&pdev
->dev
, "failed to find video source\n");
357 static int hdmic_probe(struct platform_device
*pdev
)
359 struct panel_drv_data
*ddata
;
360 struct omap_dss_device
*dssdev
;
363 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
367 platform_set_drvdata(pdev
, ddata
);
368 ddata
->dev
= &pdev
->dev
;
370 if (dev_get_platdata(&pdev
->dev
)) {
371 r
= hdmic_probe_pdata(pdev
);
374 } else if (pdev
->dev
.of_node
) {
375 r
= hdmic_probe_of(pdev
);
382 if (gpio_is_valid(ddata
->hpd_gpio
)) {
383 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->hpd_gpio
,
384 GPIOF_DIR_IN
, "hdmi_hpd");
389 ddata
->timings
= hdmic_default_timings
;
391 dssdev
= &ddata
->dssdev
;
392 dssdev
->driver
= &hdmic_driver
;
393 dssdev
->dev
= &pdev
->dev
;
394 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
395 dssdev
->owner
= THIS_MODULE
;
396 dssdev
->panel
.timings
= hdmic_default_timings
;
398 r
= omapdss_register_display(dssdev
);
400 dev_err(&pdev
->dev
, "Failed to register panel\n");
406 omap_dss_put_device(ddata
->in
);
410 static int __exit
hdmic_remove(struct platform_device
*pdev
)
412 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
413 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
414 struct omap_dss_device
*in
= ddata
->in
;
416 omapdss_unregister_display(&ddata
->dssdev
);
418 hdmic_disable(dssdev
);
419 hdmic_disconnect(dssdev
);
421 omap_dss_put_device(in
);
426 static const struct of_device_id hdmic_of_match
[] = {
427 { .compatible
= "omapdss,hdmi-connector", },
431 MODULE_DEVICE_TABLE(of
, hdmic_of_match
);
433 static struct platform_driver hdmi_connector_driver
= {
434 .probe
= hdmic_probe
,
435 .remove
= __exit_p(hdmic_remove
),
437 .name
= "connector-hdmi",
438 .owner
= THIS_MODULE
,
439 .of_match_table
= hdmic_of_match
,
440 .suppress_bind_attrs
= true,
444 module_platform_driver(hdmi_connector_driver
);
446 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
447 MODULE_DESCRIPTION("HDMI Connector driver");
448 MODULE_LICENSE("GPL");