1 // SPDX-License-Identifier: GPL-2.0-only
3 * HDMI Connector driver
5 * Copyright (C) 2013 Texas Instruments
6 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
9 #include <linux/slab.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
13 #include <linux/of_gpio.h>
15 #include <drm/drm_edid.h>
17 #include <video/omapfb_dss.h>
19 static const struct omap_video_timings hdmic_default_timings = {
22 .pixelclock = 25175000,
30 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
31 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
36 struct panel_drv_data {
37 struct omap_dss_device dssdev;
38 struct omap_dss_device *in;
42 struct omap_video_timings timings;
47 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
49 static int hdmic_connect(struct omap_dss_device *dssdev)
51 struct panel_drv_data *ddata = to_panel_data(dssdev);
52 struct omap_dss_device *in = ddata->in;
55 dev_dbg(ddata->dev, "connect\n");
57 if (omapdss_device_is_connected(dssdev))
60 r = in->ops.hdmi->connect(in, dssdev);
67 static void hdmic_disconnect(struct omap_dss_device *dssdev)
69 struct panel_drv_data *ddata = to_panel_data(dssdev);
70 struct omap_dss_device *in = ddata->in;
72 dev_dbg(ddata->dev, "disconnect\n");
74 if (!omapdss_device_is_connected(dssdev))
77 in->ops.hdmi->disconnect(in, dssdev);
80 static int hdmic_enable(struct omap_dss_device *dssdev)
82 struct panel_drv_data *ddata = to_panel_data(dssdev);
83 struct omap_dss_device *in = ddata->in;
86 dev_dbg(ddata->dev, "enable\n");
88 if (!omapdss_device_is_connected(dssdev))
91 if (omapdss_device_is_enabled(dssdev))
94 in->ops.hdmi->set_timings(in, &ddata->timings);
96 r = in->ops.hdmi->enable(in);
100 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
105 static void hdmic_disable(struct omap_dss_device *dssdev)
107 struct panel_drv_data *ddata = to_panel_data(dssdev);
108 struct omap_dss_device *in = ddata->in;
110 dev_dbg(ddata->dev, "disable\n");
112 if (!omapdss_device_is_enabled(dssdev))
115 in->ops.hdmi->disable(in);
117 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
120 static void hdmic_set_timings(struct omap_dss_device *dssdev,
121 struct omap_video_timings *timings)
123 struct panel_drv_data *ddata = to_panel_data(dssdev);
124 struct omap_dss_device *in = ddata->in;
126 ddata->timings = *timings;
127 dssdev->panel.timings = *timings;
129 in->ops.hdmi->set_timings(in, timings);
132 static void hdmic_get_timings(struct omap_dss_device *dssdev,
133 struct omap_video_timings *timings)
135 struct panel_drv_data *ddata = to_panel_data(dssdev);
137 *timings = ddata->timings;
140 static int hdmic_check_timings(struct omap_dss_device *dssdev,
141 struct omap_video_timings *timings)
143 struct panel_drv_data *ddata = to_panel_data(dssdev);
144 struct omap_dss_device *in = ddata->in;
146 return in->ops.hdmi->check_timings(in, timings);
149 static int hdmic_read_edid(struct omap_dss_device *dssdev,
152 struct panel_drv_data *ddata = to_panel_data(dssdev);
153 struct omap_dss_device *in = ddata->in;
155 return in->ops.hdmi->read_edid(in, edid, len);
158 static bool hdmic_detect(struct omap_dss_device *dssdev)
160 struct panel_drv_data *ddata = to_panel_data(dssdev);
161 struct omap_dss_device *in = ddata->in;
163 if (gpio_is_valid(ddata->hpd_gpio))
164 return gpio_get_value_cansleep(ddata->hpd_gpio);
166 return in->ops.hdmi->detect(in);
169 static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
171 struct panel_drv_data *ddata = to_panel_data(dssdev);
172 struct omap_dss_device *in = ddata->in;
174 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
177 static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
178 const struct hdmi_avi_infoframe *avi)
180 struct panel_drv_data *ddata = to_panel_data(dssdev);
181 struct omap_dss_device *in = ddata->in;
183 return in->ops.hdmi->set_infoframe(in, avi);
186 static struct omap_dss_driver hdmic_driver = {
187 .connect = hdmic_connect,
188 .disconnect = hdmic_disconnect,
190 .enable = hdmic_enable,
191 .disable = hdmic_disable,
193 .set_timings = hdmic_set_timings,
194 .get_timings = hdmic_get_timings,
195 .check_timings = hdmic_check_timings,
197 .get_resolution = omapdss_default_get_resolution,
199 .read_edid = hdmic_read_edid,
200 .detect = hdmic_detect,
201 .set_hdmi_mode = hdmic_set_hdmi_mode,
202 .set_hdmi_infoframe = hdmic_set_infoframe,
205 static int hdmic_probe_of(struct platform_device *pdev)
207 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
208 struct device_node *node = pdev->dev.of_node;
209 struct omap_dss_device *in;
213 gpio = of_get_named_gpio(node, "hpd-gpios", 0);
214 if (gpio_is_valid(gpio))
215 ddata->hpd_gpio = gpio;
217 ddata->hpd_gpio = -ENODEV;
219 in = omapdss_of_find_source_for_first_ep(node);
221 dev_err(&pdev->dev, "failed to find video source\n");
230 static int hdmic_probe(struct platform_device *pdev)
232 struct panel_drv_data *ddata;
233 struct omap_dss_device *dssdev;
236 if (!pdev->dev.of_node)
239 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
243 platform_set_drvdata(pdev, ddata);
244 ddata->dev = &pdev->dev;
246 r = hdmic_probe_of(pdev);
250 if (gpio_is_valid(ddata->hpd_gpio)) {
251 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
252 GPIOF_DIR_IN, "hdmi_hpd");
257 ddata->timings = hdmic_default_timings;
259 dssdev = &ddata->dssdev;
260 dssdev->driver = &hdmic_driver;
261 dssdev->dev = &pdev->dev;
262 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
263 dssdev->owner = THIS_MODULE;
264 dssdev->panel.timings = hdmic_default_timings;
266 r = omapdss_register_display(dssdev);
268 dev_err(&pdev->dev, "Failed to register panel\n");
274 omap_dss_put_device(ddata->in);
278 static int __exit hdmic_remove(struct platform_device *pdev)
280 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
281 struct omap_dss_device *dssdev = &ddata->dssdev;
282 struct omap_dss_device *in = ddata->in;
284 omapdss_unregister_display(&ddata->dssdev);
286 hdmic_disable(dssdev);
287 hdmic_disconnect(dssdev);
289 omap_dss_put_device(in);
294 static const struct of_device_id hdmic_of_match[] = {
295 { .compatible = "omapdss,hdmi-connector", },
299 MODULE_DEVICE_TABLE(of, hdmic_of_match);
301 static struct platform_driver hdmi_connector_driver = {
302 .probe = hdmic_probe,
303 .remove = __exit_p(hdmic_remove),
305 .name = "connector-hdmi",
306 .of_match_table = hdmic_of_match,
307 .suppress_bind_attrs = true,
311 module_platform_driver(hdmi_connector_driver);
313 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
314 MODULE_DESCRIPTION("HDMI Connector driver");
315 MODULE_LICENSE("GPL");