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/omapfb_dss.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
;
50 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
52 static int hdmic_connect(struct omap_dss_device
*dssdev
)
54 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
55 struct omap_dss_device
*in
= ddata
->in
;
58 dev_dbg(ddata
->dev
, "connect\n");
60 if (omapdss_device_is_connected(dssdev
))
63 r
= in
->ops
.hdmi
->connect(in
, dssdev
);
70 static void hdmic_disconnect(struct omap_dss_device
*dssdev
)
72 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
73 struct omap_dss_device
*in
= ddata
->in
;
75 dev_dbg(ddata
->dev
, "disconnect\n");
77 if (!omapdss_device_is_connected(dssdev
))
80 in
->ops
.hdmi
->disconnect(in
, dssdev
);
83 static int hdmic_enable(struct omap_dss_device
*dssdev
)
85 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
86 struct omap_dss_device
*in
= ddata
->in
;
89 dev_dbg(ddata
->dev
, "enable\n");
91 if (!omapdss_device_is_connected(dssdev
))
94 if (omapdss_device_is_enabled(dssdev
))
97 in
->ops
.hdmi
->set_timings(in
, &ddata
->timings
);
99 r
= in
->ops
.hdmi
->enable(in
);
103 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
108 static void hdmic_disable(struct omap_dss_device
*dssdev
)
110 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
111 struct omap_dss_device
*in
= ddata
->in
;
113 dev_dbg(ddata
->dev
, "disable\n");
115 if (!omapdss_device_is_enabled(dssdev
))
118 in
->ops
.hdmi
->disable(in
);
120 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
123 static void hdmic_set_timings(struct omap_dss_device
*dssdev
,
124 struct omap_video_timings
*timings
)
126 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
127 struct omap_dss_device
*in
= ddata
->in
;
129 ddata
->timings
= *timings
;
130 dssdev
->panel
.timings
= *timings
;
132 in
->ops
.hdmi
->set_timings(in
, timings
);
135 static void hdmic_get_timings(struct omap_dss_device
*dssdev
,
136 struct omap_video_timings
*timings
)
138 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
140 *timings
= ddata
->timings
;
143 static int hdmic_check_timings(struct omap_dss_device
*dssdev
,
144 struct omap_video_timings
*timings
)
146 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
147 struct omap_dss_device
*in
= ddata
->in
;
149 return in
->ops
.hdmi
->check_timings(in
, timings
);
152 static int hdmic_read_edid(struct omap_dss_device
*dssdev
,
155 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
156 struct omap_dss_device
*in
= ddata
->in
;
158 return in
->ops
.hdmi
->read_edid(in
, edid
, len
);
161 static bool hdmic_detect(struct omap_dss_device
*dssdev
)
163 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
164 struct omap_dss_device
*in
= ddata
->in
;
166 if (gpio_is_valid(ddata
->hpd_gpio
))
167 return gpio_get_value_cansleep(ddata
->hpd_gpio
);
169 return in
->ops
.hdmi
->detect(in
);
172 static int hdmic_set_hdmi_mode(struct omap_dss_device
*dssdev
, bool hdmi_mode
)
174 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
175 struct omap_dss_device
*in
= ddata
->in
;
177 return in
->ops
.hdmi
->set_hdmi_mode(in
, hdmi_mode
);
180 static int hdmic_set_infoframe(struct omap_dss_device
*dssdev
,
181 const struct hdmi_avi_infoframe
*avi
)
183 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
184 struct omap_dss_device
*in
= ddata
->in
;
186 return in
->ops
.hdmi
->set_infoframe(in
, avi
);
189 static struct omap_dss_driver hdmic_driver
= {
190 .connect
= hdmic_connect
,
191 .disconnect
= hdmic_disconnect
,
193 .enable
= hdmic_enable
,
194 .disable
= hdmic_disable
,
196 .set_timings
= hdmic_set_timings
,
197 .get_timings
= hdmic_get_timings
,
198 .check_timings
= hdmic_check_timings
,
200 .get_resolution
= omapdss_default_get_resolution
,
202 .read_edid
= hdmic_read_edid
,
203 .detect
= hdmic_detect
,
204 .set_hdmi_mode
= hdmic_set_hdmi_mode
,
205 .set_hdmi_infoframe
= hdmic_set_infoframe
,
208 static int hdmic_probe_of(struct platform_device
*pdev
)
210 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
211 struct device_node
*node
= pdev
->dev
.of_node
;
212 struct omap_dss_device
*in
;
216 gpio
= of_get_named_gpio(node
, "hpd-gpios", 0);
217 if (gpio_is_valid(gpio
))
218 ddata
->hpd_gpio
= gpio
;
220 ddata
->hpd_gpio
= -ENODEV
;
222 in
= omapdss_of_find_source_for_first_ep(node
);
224 dev_err(&pdev
->dev
, "failed to find video source\n");
233 static int hdmic_probe(struct platform_device
*pdev
)
235 struct panel_drv_data
*ddata
;
236 struct omap_dss_device
*dssdev
;
239 if (!pdev
->dev
.of_node
)
242 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
246 platform_set_drvdata(pdev
, ddata
);
247 ddata
->dev
= &pdev
->dev
;
249 r
= hdmic_probe_of(pdev
);
253 if (gpio_is_valid(ddata
->hpd_gpio
)) {
254 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->hpd_gpio
,
255 GPIOF_DIR_IN
, "hdmi_hpd");
260 ddata
->timings
= hdmic_default_timings
;
262 dssdev
= &ddata
->dssdev
;
263 dssdev
->driver
= &hdmic_driver
;
264 dssdev
->dev
= &pdev
->dev
;
265 dssdev
->type
= OMAP_DISPLAY_TYPE_HDMI
;
266 dssdev
->owner
= THIS_MODULE
;
267 dssdev
->panel
.timings
= hdmic_default_timings
;
269 r
= omapdss_register_display(dssdev
);
271 dev_err(&pdev
->dev
, "Failed to register panel\n");
277 omap_dss_put_device(ddata
->in
);
281 static int __exit
hdmic_remove(struct platform_device
*pdev
)
283 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
284 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
285 struct omap_dss_device
*in
= ddata
->in
;
287 omapdss_unregister_display(&ddata
->dssdev
);
289 hdmic_disable(dssdev
);
290 hdmic_disconnect(dssdev
);
292 omap_dss_put_device(in
);
297 static const struct of_device_id hdmic_of_match
[] = {
298 { .compatible
= "omapdss,hdmi-connector", },
302 MODULE_DEVICE_TABLE(of
, hdmic_of_match
);
304 static struct platform_driver hdmi_connector_driver
= {
305 .probe
= hdmic_probe
,
306 .remove
= __exit_p(hdmic_remove
),
308 .name
= "connector-hdmi",
309 .of_match_table
= hdmic_of_match
,
310 .suppress_bind_attrs
= true,
314 module_platform_driver(hdmi_connector_driver
);
316 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
317 MODULE_DESCRIPTION("HDMI Connector driver");
318 MODULE_LICENSE("GPL");