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/gpio/consumer.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
17 #include <linux/of_gpio.h>
19 #include <drm/drm_edid.h>
21 #include <video/omapdss.h>
22 #include <video/omap-panel-data.h>
24 static const struct omap_video_timings hdmic_default_timings = {
27 .pixelclock = 25175000,
35 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
36 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
41 struct panel_drv_data {
42 struct omap_dss_device dssdev;
43 struct omap_dss_device *in;
47 struct omap_video_timings timings;
52 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
54 static int hdmic_connect(struct omap_dss_device *dssdev)
56 struct panel_drv_data *ddata = to_panel_data(dssdev);
57 struct omap_dss_device *in = ddata->in;
60 dev_dbg(ddata->dev, "connect\n");
62 if (omapdss_device_is_connected(dssdev))
65 r = in->ops.hdmi->connect(in, dssdev);
72 static void hdmic_disconnect(struct omap_dss_device *dssdev)
74 struct panel_drv_data *ddata = to_panel_data(dssdev);
75 struct omap_dss_device *in = ddata->in;
77 dev_dbg(ddata->dev, "disconnect\n");
79 if (!omapdss_device_is_connected(dssdev))
82 in->ops.hdmi->disconnect(in, dssdev);
85 static int hdmic_enable(struct omap_dss_device *dssdev)
87 struct panel_drv_data *ddata = to_panel_data(dssdev);
88 struct omap_dss_device *in = ddata->in;
91 dev_dbg(ddata->dev, "enable\n");
93 if (!omapdss_device_is_connected(dssdev))
96 if (omapdss_device_is_enabled(dssdev))
99 in->ops.hdmi->set_timings(in, &ddata->timings);
101 r = in->ops.hdmi->enable(in);
105 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
110 static void hdmic_disable(struct omap_dss_device *dssdev)
112 struct panel_drv_data *ddata = to_panel_data(dssdev);
113 struct omap_dss_device *in = ddata->in;
115 dev_dbg(ddata->dev, "disable\n");
117 if (!omapdss_device_is_enabled(dssdev))
120 in->ops.hdmi->disable(in);
122 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
125 static void hdmic_set_timings(struct omap_dss_device *dssdev,
126 struct omap_video_timings *timings)
128 struct panel_drv_data *ddata = to_panel_data(dssdev);
129 struct omap_dss_device *in = ddata->in;
131 ddata->timings = *timings;
132 dssdev->panel.timings = *timings;
134 in->ops.hdmi->set_timings(in, timings);
137 static void hdmic_get_timings(struct omap_dss_device *dssdev,
138 struct omap_video_timings *timings)
140 struct panel_drv_data *ddata = to_panel_data(dssdev);
142 *timings = ddata->timings;
145 static int hdmic_check_timings(struct omap_dss_device *dssdev,
146 struct omap_video_timings *timings)
148 struct panel_drv_data *ddata = to_panel_data(dssdev);
149 struct omap_dss_device *in = ddata->in;
151 return in->ops.hdmi->check_timings(in, timings);
154 static int hdmic_read_edid(struct omap_dss_device *dssdev,
157 struct panel_drv_data *ddata = to_panel_data(dssdev);
158 struct omap_dss_device *in = ddata->in;
160 return in->ops.hdmi->read_edid(in, edid, len);
163 static bool hdmic_detect(struct omap_dss_device *dssdev)
165 struct panel_drv_data *ddata = to_panel_data(dssdev);
166 struct omap_dss_device *in = ddata->in;
168 if (gpio_is_valid(ddata->hpd_gpio))
169 return gpio_get_value_cansleep(ddata->hpd_gpio);
171 return in->ops.hdmi->detect(in);
174 static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
176 struct panel_drv_data *ddata = to_panel_data(dssdev);
177 struct omap_dss_device *in = ddata->in;
179 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
182 static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
183 const struct hdmi_avi_infoframe *avi)
185 struct panel_drv_data *ddata = to_panel_data(dssdev);
186 struct omap_dss_device *in = ddata->in;
188 return in->ops.hdmi->set_infoframe(in, avi);
191 static struct omap_dss_driver hdmic_driver = {
192 .connect = hdmic_connect,
193 .disconnect = hdmic_disconnect,
195 .enable = hdmic_enable,
196 .disable = hdmic_disable,
198 .set_timings = hdmic_set_timings,
199 .get_timings = hdmic_get_timings,
200 .check_timings = hdmic_check_timings,
202 .get_resolution = omapdss_default_get_resolution,
204 .read_edid = hdmic_read_edid,
205 .detect = hdmic_detect,
206 .set_hdmi_mode = hdmic_set_hdmi_mode,
207 .set_hdmi_infoframe = hdmic_set_infoframe,
210 static int hdmic_probe_of(struct platform_device *pdev)
212 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
213 struct device_node *node = pdev->dev.of_node;
214 struct omap_dss_device *in;
218 gpio = of_get_named_gpio(node, "hpd-gpios", 0);
219 if (gpio_is_valid(gpio))
220 ddata->hpd_gpio = gpio;
222 ddata->hpd_gpio = -ENODEV;
224 in = omapdss_of_find_source_for_first_ep(node);
226 dev_err(&pdev->dev, "failed to find video source\n");
235 static int hdmic_probe(struct platform_device *pdev)
237 struct panel_drv_data *ddata;
238 struct omap_dss_device *dssdev;
241 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
245 platform_set_drvdata(pdev, ddata);
246 ddata->dev = &pdev->dev;
248 if (!pdev->dev.of_node)
251 r = hdmic_probe_of(pdev);
255 if (gpio_is_valid(ddata->hpd_gpio)) {
256 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
257 GPIOF_DIR_IN, "hdmi_hpd");
262 ddata->timings = hdmic_default_timings;
264 dssdev = &ddata->dssdev;
265 dssdev->driver = &hdmic_driver;
266 dssdev->dev = &pdev->dev;
267 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
268 dssdev->owner = THIS_MODULE;
269 dssdev->panel.timings = hdmic_default_timings;
271 r = omapdss_register_display(dssdev);
273 dev_err(&pdev->dev, "Failed to register panel\n");
279 omap_dss_put_device(ddata->in);
283 static int __exit hdmic_remove(struct platform_device *pdev)
285 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
286 struct omap_dss_device *dssdev = &ddata->dssdev;
287 struct omap_dss_device *in = ddata->in;
289 omapdss_unregister_display(&ddata->dssdev);
291 hdmic_disable(dssdev);
292 hdmic_disconnect(dssdev);
294 omap_dss_put_device(in);
299 static const struct of_device_id hdmic_of_match[] = {
300 { .compatible = "omapdss,hdmi-connector", },
304 MODULE_DEVICE_TABLE(of, hdmic_of_match);
306 static struct platform_driver hdmi_connector_driver = {
307 .probe = hdmic_probe,
308 .remove = __exit_p(hdmic_remove),
310 .name = "connector-hdmi",
311 .of_match_table = hdmic_of_match,
312 .suppress_bind_attrs = true,
316 module_platform_driver(hdmi_connector_driver);
318 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
319 MODULE_DESCRIPTION("HDMI Connector driver");
320 MODULE_LICENSE("GPL");