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 "../dss/omapdss.h"
23 static const struct videomode hdmic_default_vm = {
26 .pixelclock = 25175000,
34 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
37 struct panel_drv_data {
38 struct omap_dss_device dssdev;
39 struct omap_dss_device *in;
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->vm);
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 videomode *vm)
124 struct panel_drv_data *ddata = to_panel_data(dssdev);
125 struct omap_dss_device *in = ddata->in;
128 dssdev->panel.vm = *vm;
130 in->ops.hdmi->set_timings(in, vm);
133 static void hdmic_get_timings(struct omap_dss_device *dssdev,
134 struct videomode *vm)
136 struct panel_drv_data *ddata = to_panel_data(dssdev);
141 static int hdmic_check_timings(struct omap_dss_device *dssdev,
142 struct videomode *vm)
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, vm);
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 if (gpio_is_valid(ddata->hpd_gpio))
165 return gpio_get_value_cansleep(ddata->hpd_gpio);
167 return in->ops.hdmi->detect(in);
170 static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
172 struct panel_drv_data *ddata = to_panel_data(dssdev);
173 struct omap_dss_device *in = ddata->in;
175 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
178 static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
179 const struct hdmi_avi_infoframe *avi)
181 struct panel_drv_data *ddata = to_panel_data(dssdev);
182 struct omap_dss_device *in = ddata->in;
184 return in->ops.hdmi->set_infoframe(in, avi);
187 static struct omap_dss_driver hdmic_driver = {
188 .connect = hdmic_connect,
189 .disconnect = hdmic_disconnect,
191 .enable = hdmic_enable,
192 .disable = hdmic_disable,
194 .set_timings = hdmic_set_timings,
195 .get_timings = hdmic_get_timings,
196 .check_timings = hdmic_check_timings,
198 .read_edid = hdmic_read_edid,
199 .detect = hdmic_detect,
200 .set_hdmi_mode = hdmic_set_hdmi_mode,
201 .set_hdmi_infoframe = hdmic_set_infoframe,
204 static int hdmic_probe_of(struct platform_device *pdev)
206 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
207 struct device_node *node = pdev->dev.of_node;
208 struct omap_dss_device *in;
212 gpio = of_get_named_gpio(node, "hpd-gpios", 0);
213 if (gpio_is_valid(gpio))
214 ddata->hpd_gpio = gpio;
216 ddata->hpd_gpio = -ENODEV;
218 in = omapdss_of_find_source_for_first_ep(node);
220 dev_err(&pdev->dev, "failed to find video source\n");
229 static int hdmic_probe(struct platform_device *pdev)
231 struct panel_drv_data *ddata;
232 struct omap_dss_device *dssdev;
235 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
239 platform_set_drvdata(pdev, ddata);
240 ddata->dev = &pdev->dev;
242 if (!pdev->dev.of_node)
245 r = hdmic_probe_of(pdev);
249 if (gpio_is_valid(ddata->hpd_gpio)) {
250 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
251 GPIOF_DIR_IN, "hdmi_hpd");
256 ddata->vm = hdmic_default_vm;
258 dssdev = &ddata->dssdev;
259 dssdev->driver = &hdmic_driver;
260 dssdev->dev = &pdev->dev;
261 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
262 dssdev->owner = THIS_MODULE;
263 dssdev->panel.vm = hdmic_default_vm;
265 r = omapdss_register_display(dssdev);
267 dev_err(&pdev->dev, "Failed to register panel\n");
273 omap_dss_put_device(ddata->in);
277 static int __exit hdmic_remove(struct platform_device *pdev)
279 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
280 struct omap_dss_device *dssdev = &ddata->dssdev;
281 struct omap_dss_device *in = ddata->in;
283 omapdss_unregister_display(&ddata->dssdev);
285 hdmic_disable(dssdev);
286 hdmic_disconnect(dssdev);
288 omap_dss_put_device(in);
293 static const struct of_device_id hdmic_of_match[] = {
294 { .compatible = "omapdss,hdmi-connector", },
298 MODULE_DEVICE_TABLE(of, hdmic_of_match);
300 static struct platform_driver hdmi_connector_driver = {
301 .probe = hdmic_probe,
302 .remove = __exit_p(hdmic_remove),
304 .name = "connector-hdmi",
305 .of_match_table = hdmic_of_match,
306 .suppress_bind_attrs = true,
310 module_platform_driver(hdmi_connector_driver);
312 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
313 MODULE_DESCRIPTION("HDMI Connector driver");
314 MODULE_LICENSE("GPL");