blob: 79cb69f1acf5c68ceedc51623cfc20f58ca94cb9 [file] [log] [blame]
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +03001/*
2 * HDMI Connector driver
3 *
4 * Copyright (C) 2013 Texas Instruments
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
6 *
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.
10 */
11
Arnd Bergmannd0196c82016-05-11 18:05:39 +020012#include <linux/gpio/consumer.h>
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030013#include <linux/slab.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +030016#include <linux/of.h>
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +030017#include <linux/of_gpio.h>
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030018
19#include <drm/drm_edid.h>
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030020
Peter Ujfalusi32043da2016-05-27 14:40:49 +030021#include "../dss/omapdss.h"
22
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030023static const struct videomode hdmic_default_vm = {
Peter Ujfalusi81899062016-09-22 14:06:46 +030024 .hactive = 640,
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +030025 .vactive = 480,
Tomi Valkeinend8d789412013-04-10 14:12:14 +030026 .pixelclock = 25175000,
Peter Ujfalusi4dc22502016-09-22 14:06:48 +030027 .hsync_len = 96,
Peter Ujfalusi0a30e152016-09-22 14:06:49 +030028 .hfront_porch = 16,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +030029 .hback_porch = 48,
Peter Ujfalusid5bcf0a2016-09-22 14:06:51 +030030 .vsync_len = 2,
Peter Ujfalusi0996c682016-09-22 14:06:52 +030031 .vfront_porch = 11,
Peter Ujfalusi458540c2016-09-22 14:06:53 +030032 .vback_porch = 31,
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030033
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +030034 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030035};
36
37struct panel_drv_data {
38 struct omap_dss_device dssdev;
39 struct omap_dss_device *in;
40
41 struct device *dev;
42
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030043 struct videomode vm;
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +030044
45 int hpd_gpio;
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030046};
47
48#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
49
50static int hdmic_connect(struct omap_dss_device *dssdev)
51{
52 struct panel_drv_data *ddata = to_panel_data(dssdev);
53 struct omap_dss_device *in = ddata->in;
54 int r;
55
56 dev_dbg(ddata->dev, "connect\n");
57
58 if (omapdss_device_is_connected(dssdev))
59 return 0;
60
61 r = in->ops.hdmi->connect(in, dssdev);
62 if (r)
63 return r;
64
65 return 0;
66}
67
68static void hdmic_disconnect(struct omap_dss_device *dssdev)
69{
70 struct panel_drv_data *ddata = to_panel_data(dssdev);
71 struct omap_dss_device *in = ddata->in;
72
73 dev_dbg(ddata->dev, "disconnect\n");
74
75 if (!omapdss_device_is_connected(dssdev))
76 return;
77
78 in->ops.hdmi->disconnect(in, dssdev);
79}
80
81static int hdmic_enable(struct omap_dss_device *dssdev)
82{
83 struct panel_drv_data *ddata = to_panel_data(dssdev);
84 struct omap_dss_device *in = ddata->in;
85 int r;
86
87 dev_dbg(ddata->dev, "enable\n");
88
89 if (!omapdss_device_is_connected(dssdev))
90 return -ENODEV;
91
92 if (omapdss_device_is_enabled(dssdev))
93 return 0;
94
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030095 in->ops.hdmi->set_timings(in, &ddata->vm);
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030096
97 r = in->ops.hdmi->enable(in);
98 if (r)
99 return r;
100
101 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
102
103 return r;
104}
105
106static void hdmic_disable(struct omap_dss_device *dssdev)
107{
108 struct panel_drv_data *ddata = to_panel_data(dssdev);
109 struct omap_dss_device *in = ddata->in;
110
111 dev_dbg(ddata->dev, "disable\n");
112
113 if (!omapdss_device_is_enabled(dssdev))
114 return;
115
116 in->ops.hdmi->disable(in);
117
118 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
119}
120
121static void hdmic_set_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300122 struct videomode *vm)
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300123{
124 struct panel_drv_data *ddata = to_panel_data(dssdev);
125 struct omap_dss_device *in = ddata->in;
126
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300127 ddata->vm = *vm;
128 dssdev->panel.vm = *vm;
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300129
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300130 in->ops.hdmi->set_timings(in, vm);
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300131}
132
133static void hdmic_get_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300134 struct videomode *vm)
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300135{
136 struct panel_drv_data *ddata = to_panel_data(dssdev);
137
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300138 *vm = ddata->vm;
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300139}
140
141static int hdmic_check_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300142 struct videomode *vm)
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300143{
144 struct panel_drv_data *ddata = to_panel_data(dssdev);
145 struct omap_dss_device *in = ddata->in;
146
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300147 return in->ops.hdmi->check_timings(in, vm);
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300148}
149
150static int hdmic_read_edid(struct omap_dss_device *dssdev,
151 u8 *edid, int len)
152{
153 struct panel_drv_data *ddata = to_panel_data(dssdev);
154 struct omap_dss_device *in = ddata->in;
155
156 return in->ops.hdmi->read_edid(in, edid, len);
157}
158
159static bool hdmic_detect(struct omap_dss_device *dssdev)
160{
161 struct panel_drv_data *ddata = to_panel_data(dssdev);
162 struct omap_dss_device *in = ddata->in;
163
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +0300164 if (gpio_is_valid(ddata->hpd_gpio))
165 return gpio_get_value_cansleep(ddata->hpd_gpio);
166 else
167 return in->ops.hdmi->detect(in);
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300168}
169
Tomi Valkeinen9fb17372014-06-18 12:58:02 +0300170static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
171{
172 struct panel_drv_data *ddata = to_panel_data(dssdev);
173 struct omap_dss_device *in = ddata->in;
174
175 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
176}
177
178static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
179 const struct hdmi_avi_infoframe *avi)
180{
181 struct panel_drv_data *ddata = to_panel_data(dssdev);
182 struct omap_dss_device *in = ddata->in;
183
184 return in->ops.hdmi->set_infoframe(in, avi);
185}
186
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300187static struct omap_dss_driver hdmic_driver = {
188 .connect = hdmic_connect,
189 .disconnect = hdmic_disconnect,
190
191 .enable = hdmic_enable,
192 .disable = hdmic_disable,
193
194 .set_timings = hdmic_set_timings,
195 .get_timings = hdmic_get_timings,
196 .check_timings = hdmic_check_timings,
197
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300198 .read_edid = hdmic_read_edid,
199 .detect = hdmic_detect,
Tomi Valkeinen9fb17372014-06-18 12:58:02 +0300200 .set_hdmi_mode = hdmic_set_hdmi_mode,
201 .set_hdmi_infoframe = hdmic_set_infoframe,
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300202};
203
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +0300204static int hdmic_probe_of(struct platform_device *pdev)
205{
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;
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +0300209 int gpio;
210
211 /* HPD GPIO */
212 gpio = of_get_named_gpio(node, "hpd-gpios", 0);
213 if (gpio_is_valid(gpio))
214 ddata->hpd_gpio = gpio;
215 else
216 ddata->hpd_gpio = -ENODEV;
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +0300217
218 in = omapdss_of_find_source_for_first_ep(node);
219 if (IS_ERR(in)) {
220 dev_err(&pdev->dev, "failed to find video source\n");
221 return PTR_ERR(in);
222 }
223
224 ddata->in = in;
225
226 return 0;
227}
228
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300229static int hdmic_probe(struct platform_device *pdev)
230{
231 struct panel_drv_data *ddata;
232 struct omap_dss_device *dssdev;
233 int r;
234
235 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
236 if (!ddata)
237 return -ENOMEM;
238
239 platform_set_drvdata(pdev, ddata);
240 ddata->dev = &pdev->dev;
241
Tomi Valkeinen7f7642b2016-02-18 17:20:54 +0200242 if (!pdev->dev.of_node)
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300243 return -ENODEV;
Tomi Valkeinen7f7642b2016-02-18 17:20:54 +0200244
245 r = hdmic_probe_of(pdev);
246 if (r)
247 return r;
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300248
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +0300249 if (gpio_is_valid(ddata->hpd_gpio)) {
250 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
251 GPIOF_DIR_IN, "hdmi_hpd");
252 if (r)
253 goto err_reg;
254 }
255
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300256 ddata->vm = hdmic_default_vm;
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300257
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;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300263 dssdev->panel.vm = hdmic_default_vm;
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300264
265 r = omapdss_register_display(dssdev);
266 if (r) {
267 dev_err(&pdev->dev, "Failed to register panel\n");
268 goto err_reg;
269 }
270
271 return 0;
272err_reg:
273 omap_dss_put_device(ddata->in);
274 return r;
275}
276
277static int __exit hdmic_remove(struct platform_device *pdev)
278{
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;
282
283 omapdss_unregister_display(&ddata->dssdev);
284
285 hdmic_disable(dssdev);
286 hdmic_disconnect(dssdev);
287
288 omap_dss_put_device(in);
289
290 return 0;
291}
292
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +0300293static const struct of_device_id hdmic_of_match[] = {
294 { .compatible = "omapdss,hdmi-connector", },
295 {},
296};
297
298MODULE_DEVICE_TABLE(of, hdmic_of_match);
299
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300300static struct platform_driver hdmi_connector_driver = {
301 .probe = hdmic_probe,
302 .remove = __exit_p(hdmic_remove),
303 .driver = {
304 .name = "connector-hdmi",
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +0300305 .of_match_table = hdmic_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300306 .suppress_bind_attrs = true,
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300307 },
308};
309
310module_platform_driver(hdmi_connector_driver);
311
312MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
313MODULE_DESCRIPTION("HDMI Connector driver");
314MODULE_LICENSE("GPL");