blob: 8e246b9142d71f139c3175e9c3cf62ad156410e4 [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#include <video/omap-panel-data.h>
21
Peter Ujfalusi32043da2016-05-27 14:40:49 +030022#include "../dss/omapdss.h"
23
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030024static const struct omap_video_timings hdmic_default_timings = {
Peter Ujfalusi81899062016-09-22 14:06:46 +030025 .hactive = 640,
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +030026 .vactive = 480,
Tomi Valkeinend8d789412013-04-10 14:12:14 +030027 .pixelclock = 25175000,
Peter Ujfalusi4dc22502016-09-22 14:06:48 +030028 .hsync_len = 96,
Peter Ujfalusi0a30e152016-09-22 14:06:49 +030029 .hfront_porch = 16,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +030030 .hback_porch = 48,
Peter Ujfalusid5bcf0a2016-09-22 14:06:51 +030031 .vsync_len = 2,
Peter Ujfalusi0996c682016-09-22 14:06:52 +030032 .vfront_porch = 11,
Peter Ujfalusi458540c2016-09-22 14:06:53 +030033 .vback_porch = 31,
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030034
35 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
36 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030037};
38
39struct panel_drv_data {
40 struct omap_dss_device dssdev;
41 struct omap_dss_device *in;
42
43 struct device *dev;
44
45 struct omap_video_timings timings;
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +030046
47 int hpd_gpio;
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +030048};
49
50#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
51
52static int hdmic_connect(struct omap_dss_device *dssdev)
53{
54 struct panel_drv_data *ddata = to_panel_data(dssdev);
55 struct omap_dss_device *in = ddata->in;
56 int r;
57
58 dev_dbg(ddata->dev, "connect\n");
59
60 if (omapdss_device_is_connected(dssdev))
61 return 0;
62
63 r = in->ops.hdmi->connect(in, dssdev);
64 if (r)
65 return r;
66
67 return 0;
68}
69
70static void hdmic_disconnect(struct omap_dss_device *dssdev)
71{
72 struct panel_drv_data *ddata = to_panel_data(dssdev);
73 struct omap_dss_device *in = ddata->in;
74
75 dev_dbg(ddata->dev, "disconnect\n");
76
77 if (!omapdss_device_is_connected(dssdev))
78 return;
79
80 in->ops.hdmi->disconnect(in, dssdev);
81}
82
83static int hdmic_enable(struct omap_dss_device *dssdev)
84{
85 struct panel_drv_data *ddata = to_panel_data(dssdev);
86 struct omap_dss_device *in = ddata->in;
87 int r;
88
89 dev_dbg(ddata->dev, "enable\n");
90
91 if (!omapdss_device_is_connected(dssdev))
92 return -ENODEV;
93
94 if (omapdss_device_is_enabled(dssdev))
95 return 0;
96
97 in->ops.hdmi->set_timings(in, &ddata->timings);
98
99 r = in->ops.hdmi->enable(in);
100 if (r)
101 return r;
102
103 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
104
105 return r;
106}
107
108static void hdmic_disable(struct omap_dss_device *dssdev)
109{
110 struct panel_drv_data *ddata = to_panel_data(dssdev);
111 struct omap_dss_device *in = ddata->in;
112
113 dev_dbg(ddata->dev, "disable\n");
114
115 if (!omapdss_device_is_enabled(dssdev))
116 return;
117
118 in->ops.hdmi->disable(in);
119
120 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
121}
122
123static void hdmic_set_timings(struct omap_dss_device *dssdev,
124 struct omap_video_timings *timings)
125{
126 struct panel_drv_data *ddata = to_panel_data(dssdev);
127 struct omap_dss_device *in = ddata->in;
128
129 ddata->timings = *timings;
130 dssdev->panel.timings = *timings;
131
132 in->ops.hdmi->set_timings(in, timings);
133}
134
135static void hdmic_get_timings(struct omap_dss_device *dssdev,
136 struct omap_video_timings *timings)
137{
138 struct panel_drv_data *ddata = to_panel_data(dssdev);
139
140 *timings = ddata->timings;
141}
142
143static int hdmic_check_timings(struct omap_dss_device *dssdev,
144 struct omap_video_timings *timings)
145{
146 struct panel_drv_data *ddata = to_panel_data(dssdev);
147 struct omap_dss_device *in = ddata->in;
148
149 return in->ops.hdmi->check_timings(in, timings);
150}
151
152static int hdmic_read_edid(struct omap_dss_device *dssdev,
153 u8 *edid, int len)
154{
155 struct panel_drv_data *ddata = to_panel_data(dssdev);
156 struct omap_dss_device *in = ddata->in;
157
158 return in->ops.hdmi->read_edid(in, edid, len);
159}
160
161static bool hdmic_detect(struct omap_dss_device *dssdev)
162{
163 struct panel_drv_data *ddata = to_panel_data(dssdev);
164 struct omap_dss_device *in = ddata->in;
165
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +0300166 if (gpio_is_valid(ddata->hpd_gpio))
167 return gpio_get_value_cansleep(ddata->hpd_gpio);
168 else
169 return in->ops.hdmi->detect(in);
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300170}
171
Tomi Valkeinen9fb17372014-06-18 12:58:02 +0300172static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
173{
174 struct panel_drv_data *ddata = to_panel_data(dssdev);
175 struct omap_dss_device *in = ddata->in;
176
177 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
178}
179
180static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
181 const struct hdmi_avi_infoframe *avi)
182{
183 struct panel_drv_data *ddata = to_panel_data(dssdev);
184 struct omap_dss_device *in = ddata->in;
185
186 return in->ops.hdmi->set_infoframe(in, avi);
187}
188
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300189static struct omap_dss_driver hdmic_driver = {
190 .connect = hdmic_connect,
191 .disconnect = hdmic_disconnect,
192
193 .enable = hdmic_enable,
194 .disable = hdmic_disable,
195
196 .set_timings = hdmic_set_timings,
197 .get_timings = hdmic_get_timings,
198 .check_timings = hdmic_check_timings,
199
200 .get_resolution = omapdss_default_get_resolution,
201
202 .read_edid = hdmic_read_edid,
203 .detect = hdmic_detect,
Tomi Valkeinen9fb17372014-06-18 12:58:02 +0300204 .set_hdmi_mode = hdmic_set_hdmi_mode,
205 .set_hdmi_infoframe = hdmic_set_infoframe,
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300206};
207
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +0300208static int hdmic_probe_of(struct platform_device *pdev)
209{
210 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
211 struct device_node *node = pdev->dev.of_node;
212 struct omap_dss_device *in;
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +0300213 int gpio;
214
215 /* HPD GPIO */
216 gpio = of_get_named_gpio(node, "hpd-gpios", 0);
217 if (gpio_is_valid(gpio))
218 ddata->hpd_gpio = gpio;
219 else
220 ddata->hpd_gpio = -ENODEV;
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +0300221
222 in = omapdss_of_find_source_for_first_ep(node);
223 if (IS_ERR(in)) {
224 dev_err(&pdev->dev, "failed to find video source\n");
225 return PTR_ERR(in);
226 }
227
228 ddata->in = in;
229
230 return 0;
231}
232
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300233static int hdmic_probe(struct platform_device *pdev)
234{
235 struct panel_drv_data *ddata;
236 struct omap_dss_device *dssdev;
237 int r;
238
239 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
240 if (!ddata)
241 return -ENOMEM;
242
243 platform_set_drvdata(pdev, ddata);
244 ddata->dev = &pdev->dev;
245
Tomi Valkeinen7f7642b2016-02-18 17:20:54 +0200246 if (!pdev->dev.of_node)
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300247 return -ENODEV;
Tomi Valkeinen7f7642b2016-02-18 17:20:54 +0200248
249 r = hdmic_probe_of(pdev);
250 if (r)
251 return r;
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300252
Tomi Valkeinen2c75e3c2014-04-17 10:18:58 +0300253 if (gpio_is_valid(ddata->hpd_gpio)) {
254 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio,
255 GPIOF_DIR_IN, "hdmi_hpd");
256 if (r)
257 goto err_reg;
258 }
259
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300260 ddata->timings = hdmic_default_timings;
261
262 dssdev = &ddata->dssdev;
263 dssdev->driver = &hdmic_driver;
264 dssdev->dev = &pdev->dev;
265 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
266 dssdev->owner = THIS_MODULE;
267 dssdev->panel.timings = hdmic_default_timings;
268
269 r = omapdss_register_display(dssdev);
270 if (r) {
271 dev_err(&pdev->dev, "Failed to register panel\n");
272 goto err_reg;
273 }
274
275 return 0;
276err_reg:
277 omap_dss_put_device(ddata->in);
278 return r;
279}
280
281static int __exit hdmic_remove(struct platform_device *pdev)
282{
283 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
284 struct omap_dss_device *dssdev = &ddata->dssdev;
285 struct omap_dss_device *in = ddata->in;
286
287 omapdss_unregister_display(&ddata->dssdev);
288
289 hdmic_disable(dssdev);
290 hdmic_disconnect(dssdev);
291
292 omap_dss_put_device(in);
293
294 return 0;
295}
296
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +0300297static const struct of_device_id hdmic_of_match[] = {
298 { .compatible = "omapdss,hdmi-connector", },
299 {},
300};
301
302MODULE_DEVICE_TABLE(of, hdmic_of_match);
303
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300304static struct platform_driver hdmi_connector_driver = {
305 .probe = hdmic_probe,
306 .remove = __exit_p(hdmic_remove),
307 .driver = {
308 .name = "connector-hdmi",
Tomi Valkeinen0b8879f2013-07-30 10:37:34 +0300309 .of_match_table = hdmic_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300310 .suppress_bind_attrs = true,
Tomi Valkeinen3cb07ee2013-05-24 14:21:08 +0300311 },
312};
313
314module_platform_driver(hdmi_connector_driver);
315
316MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
317MODULE_DESCRIPTION("HDMI Connector driver");
318MODULE_LICENSE("GPL");