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>
20 #include <video/omap-panel-data.h>
22 #include "../dss/omapdss.h"
24 static const struct omap_video_timings hdmic_default_timings = {
27 .pixelclock = 25175000,
35 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
38 struct panel_drv_data {
39 struct omap_dss_device dssdev;
40 struct omap_dss_device *in;
44 struct omap_video_timings timings;
49 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
51 static int hdmic_connect(struct omap_dss_device *dssdev)
53 struct panel_drv_data *ddata = to_panel_data(dssdev);
54 struct omap_dss_device *in = ddata->in;
57 dev_dbg(ddata->dev, "connect\n");
59 if (omapdss_device_is_connected(dssdev))
62 r = in->ops.hdmi->connect(in, dssdev);
69 static void hdmic_disconnect(struct omap_dss_device *dssdev)
71 struct panel_drv_data *ddata = to_panel_data(dssdev);
72 struct omap_dss_device *in = ddata->in;
74 dev_dbg(ddata->dev, "disconnect\n");
76 if (!omapdss_device_is_connected(dssdev))
79 in->ops.hdmi->disconnect(in, dssdev);
82 static int hdmic_enable(struct omap_dss_device *dssdev)
84 struct panel_drv_data *ddata = to_panel_data(dssdev);
85 struct omap_dss_device *in = ddata->in;
88 dev_dbg(ddata->dev, "enable\n");
90 if (!omapdss_device_is_connected(dssdev))
93 if (omapdss_device_is_enabled(dssdev))
96 in->ops.hdmi->set_timings(in, &ddata->timings);
98 r = in->ops.hdmi->enable(in);
102 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
107 static void hdmic_disable(struct omap_dss_device *dssdev)
109 struct panel_drv_data *ddata = to_panel_data(dssdev);
110 struct omap_dss_device *in = ddata->in;
112 dev_dbg(ddata->dev, "disable\n");
114 if (!omapdss_device_is_enabled(dssdev))
117 in->ops.hdmi->disable(in);
119 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
122 static void hdmic_set_timings(struct omap_dss_device *dssdev,
123 struct omap_video_timings *timings)
125 struct panel_drv_data *ddata = to_panel_data(dssdev);
126 struct omap_dss_device *in = ddata->in;
128 ddata->timings = *timings;
129 dssdev->panel.timings = *timings;
131 in->ops.hdmi->set_timings(in, timings);
134 static void hdmic_get_timings(struct omap_dss_device *dssdev,
135 struct omap_video_timings *timings)
137 struct panel_drv_data *ddata = to_panel_data(dssdev);
139 *timings = ddata->timings;
142 static int hdmic_check_timings(struct omap_dss_device *dssdev,
143 struct omap_video_timings *timings)
145 struct panel_drv_data *ddata = to_panel_data(dssdev);
146 struct omap_dss_device *in = ddata->in;
148 return in->ops.hdmi->check_timings(in, timings);
151 static int hdmic_read_edid(struct omap_dss_device *dssdev,
154 struct panel_drv_data *ddata = to_panel_data(dssdev);
155 struct omap_dss_device *in = ddata->in;
157 return in->ops.hdmi->read_edid(in, edid, len);
160 static bool hdmic_detect(struct omap_dss_device *dssdev)
162 struct panel_drv_data *ddata = to_panel_data(dssdev);
163 struct omap_dss_device *in = ddata->in;
165 if (gpio_is_valid(ddata->hpd_gpio))
166 return gpio_get_value_cansleep(ddata->hpd_gpio);
168 return in->ops.hdmi->detect(in);
171 static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
173 struct panel_drv_data *ddata = to_panel_data(dssdev);
174 struct omap_dss_device *in = ddata->in;
176 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
179 static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
180 const struct hdmi_avi_infoframe *avi)
182 struct panel_drv_data *ddata = to_panel_data(dssdev);
183 struct omap_dss_device *in = ddata->in;
185 return in->ops.hdmi->set_infoframe(in, avi);
188 static struct omap_dss_driver hdmic_driver = {
189 .connect = hdmic_connect,
190 .disconnect = hdmic_disconnect,
192 .enable = hdmic_enable,
193 .disable = hdmic_disable,
195 .set_timings = hdmic_set_timings,
196 .get_timings = hdmic_get_timings,
197 .check_timings = hdmic_check_timings,
199 .get_resolution = omapdss_default_get_resolution,
201 .read_edid = hdmic_read_edid,
202 .detect = hdmic_detect,
203 .set_hdmi_mode = hdmic_set_hdmi_mode,
204 .set_hdmi_infoframe = hdmic_set_infoframe,
207 static int hdmic_probe_of(struct platform_device *pdev)
209 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
210 struct device_node *node = pdev->dev.of_node;
211 struct omap_dss_device *in;
215 gpio = of_get_named_gpio(node, "hpd-gpios", 0);
216 if (gpio_is_valid(gpio))
217 ddata->hpd_gpio = gpio;
219 ddata->hpd_gpio = -ENODEV;
221 in = omapdss_of_find_source_for_first_ep(node);
223 dev_err(&pdev->dev, "failed to find video source\n");
232 static int hdmic_probe(struct platform_device *pdev)
234 struct panel_drv_data *ddata;
235 struct omap_dss_device *dssdev;
238 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
242 platform_set_drvdata(pdev, ddata);
243 ddata->dev = &pdev->dev;
245 if (!pdev->dev.of_node)
248 r = hdmic_probe_of(pdev);
252 if (gpio_is_valid(ddata->hpd_gpio)) {
253 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
254 GPIOF_DIR_IN, "hdmi_hpd");
259 ddata->timings = hdmic_default_timings;
261 dssdev = &ddata->dssdev;
262 dssdev->driver = &hdmic_driver;
263 dssdev->dev = &pdev->dev;
264 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
265 dssdev->owner = THIS_MODULE;
266 dssdev->panel.timings = hdmic_default_timings;
268 r = omapdss_register_display(dssdev);
270 dev_err(&pdev->dev, "Failed to register panel\n");
276 omap_dss_put_device(ddata->in);
280 static int __exit hdmic_remove(struct platform_device *pdev)
282 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
283 struct omap_dss_device *dssdev = &ddata->dssdev;
284 struct omap_dss_device *in = ddata->in;
286 omapdss_unregister_display(&ddata->dssdev);
288 hdmic_disable(dssdev);
289 hdmic_disconnect(dssdev);
291 omap_dss_put_device(in);
296 static const struct of_device_id hdmic_of_match[] = {
297 { .compatible = "omapdss,hdmi-connector", },
301 MODULE_DEVICE_TABLE(of, hdmic_of_match);
303 static struct platform_driver hdmi_connector_driver = {
304 .probe = hdmic_probe,
305 .remove = __exit_p(hdmic_remove),
307 .name = "connector-hdmi",
308 .of_match_table = hdmic_of_match,
309 .suppress_bind_attrs = true,
313 module_platform_driver(hdmi_connector_driver);
315 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
316 MODULE_DESCRIPTION("HDMI Connector driver");
317 MODULE_LICENSE("GPL");