Loading...
Note: File does not exist in v5.4.
1/*
2 * Generic MIPI DPI Panel 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
12#include <linux/gpio/consumer.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
16#include <linux/of.h>
17#include <linux/of_gpio.h>
18#include <linux/regulator/consumer.h>
19
20#include <video/omap-panel-data.h>
21#include <video/of_display_timing.h>
22
23#include "../dss/omapdss.h"
24
25struct panel_drv_data {
26 struct omap_dss_device dssdev;
27 struct omap_dss_device *in;
28
29 int data_lines;
30
31 struct videomode vm;
32
33 /* used for non-DT boot, to be removed */
34 int backlight_gpio;
35
36 struct gpio_desc *enable_gpio;
37 struct regulator *vcc_supply;
38};
39
40#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
41
42static int panel_dpi_connect(struct omap_dss_device *dssdev)
43{
44 struct panel_drv_data *ddata = to_panel_data(dssdev);
45 struct omap_dss_device *in = ddata->in;
46 int r;
47
48 if (omapdss_device_is_connected(dssdev))
49 return 0;
50
51 r = in->ops.dpi->connect(in, dssdev);
52 if (r)
53 return r;
54
55 return 0;
56}
57
58static void panel_dpi_disconnect(struct omap_dss_device *dssdev)
59{
60 struct panel_drv_data *ddata = to_panel_data(dssdev);
61 struct omap_dss_device *in = ddata->in;
62
63 if (!omapdss_device_is_connected(dssdev))
64 return;
65
66 in->ops.dpi->disconnect(in, dssdev);
67}
68
69static int panel_dpi_enable(struct omap_dss_device *dssdev)
70{
71 struct panel_drv_data *ddata = to_panel_data(dssdev);
72 struct omap_dss_device *in = ddata->in;
73 int r;
74
75 if (!omapdss_device_is_connected(dssdev))
76 return -ENODEV;
77
78 if (omapdss_device_is_enabled(dssdev))
79 return 0;
80
81 if (ddata->data_lines)
82 in->ops.dpi->set_data_lines(in, ddata->data_lines);
83 in->ops.dpi->set_timings(in, &ddata->vm);
84
85 r = in->ops.dpi->enable(in);
86 if (r)
87 return r;
88
89 r = regulator_enable(ddata->vcc_supply);
90 if (r) {
91 in->ops.dpi->disable(in);
92 return r;
93 }
94
95 gpiod_set_value_cansleep(ddata->enable_gpio, 1);
96
97 if (gpio_is_valid(ddata->backlight_gpio))
98 gpio_set_value_cansleep(ddata->backlight_gpio, 1);
99
100 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
101
102 return 0;
103}
104
105static void panel_dpi_disable(struct omap_dss_device *dssdev)
106{
107 struct panel_drv_data *ddata = to_panel_data(dssdev);
108 struct omap_dss_device *in = ddata->in;
109
110 if (!omapdss_device_is_enabled(dssdev))
111 return;
112
113 if (gpio_is_valid(ddata->backlight_gpio))
114 gpio_set_value_cansleep(ddata->backlight_gpio, 0);
115
116 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
117 regulator_disable(ddata->vcc_supply);
118
119 in->ops.dpi->disable(in);
120
121 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
122}
123
124static void panel_dpi_set_timings(struct omap_dss_device *dssdev,
125 struct videomode *vm)
126{
127 struct panel_drv_data *ddata = to_panel_data(dssdev);
128 struct omap_dss_device *in = ddata->in;
129
130 ddata->vm = *vm;
131 dssdev->panel.vm = *vm;
132
133 in->ops.dpi->set_timings(in, vm);
134}
135
136static void panel_dpi_get_timings(struct omap_dss_device *dssdev,
137 struct videomode *vm)
138{
139 struct panel_drv_data *ddata = to_panel_data(dssdev);
140
141 *vm = ddata->vm;
142}
143
144static int panel_dpi_check_timings(struct omap_dss_device *dssdev,
145 struct videomode *vm)
146{
147 struct panel_drv_data *ddata = to_panel_data(dssdev);
148 struct omap_dss_device *in = ddata->in;
149
150 return in->ops.dpi->check_timings(in, vm);
151}
152
153static struct omap_dss_driver panel_dpi_ops = {
154 .connect = panel_dpi_connect,
155 .disconnect = panel_dpi_disconnect,
156
157 .enable = panel_dpi_enable,
158 .disable = panel_dpi_disable,
159
160 .set_timings = panel_dpi_set_timings,
161 .get_timings = panel_dpi_get_timings,
162 .check_timings = panel_dpi_check_timings,
163
164 .get_resolution = omapdss_default_get_resolution,
165};
166
167static int panel_dpi_probe_pdata(struct platform_device *pdev)
168{
169 const struct panel_dpi_platform_data *pdata;
170 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
171 struct omap_dss_device *dssdev, *in;
172 int r;
173
174 pdata = dev_get_platdata(&pdev->dev);
175
176 in = omap_dss_find_output(pdata->source);
177 if (in == NULL) {
178 dev_err(&pdev->dev, "failed to find video source '%s'\n",
179 pdata->source);
180 return -EPROBE_DEFER;
181 }
182
183 ddata->in = in;
184
185 ddata->data_lines = pdata->data_lines;
186
187 videomode_from_timing(pdata->display_timing, &ddata->vm);
188
189 dssdev = &ddata->dssdev;
190 dssdev->name = pdata->name;
191
192 r = devm_gpio_request_one(&pdev->dev, pdata->enable_gpio,
193 GPIOF_OUT_INIT_LOW, "panel enable");
194 if (r)
195 goto err_gpio;
196
197 ddata->enable_gpio = gpio_to_desc(pdata->enable_gpio);
198
199 ddata->backlight_gpio = pdata->backlight_gpio;
200
201 return 0;
202
203err_gpio:
204 omap_dss_put_device(ddata->in);
205 return r;
206}
207
208static int panel_dpi_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;
213 int r;
214 struct display_timing timing;
215 struct gpio_desc *gpio;
216
217 gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
218 if (IS_ERR(gpio))
219 return PTR_ERR(gpio);
220
221 ddata->enable_gpio = gpio;
222
223 /*
224 * Many different panels are supported by this driver and there are
225 * probably very different needs for their reset pins in regards to
226 * timing and order relative to the enable gpio. So for now it's just
227 * ensured that the reset line isn't active.
228 */
229 gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
230 if (IS_ERR(gpio))
231 return PTR_ERR(gpio);
232
233 ddata->vcc_supply = devm_regulator_get(&pdev->dev, "vcc");
234 if (IS_ERR(ddata->vcc_supply))
235 return PTR_ERR(ddata->vcc_supply);
236
237 ddata->backlight_gpio = -ENOENT;
238
239 r = of_get_display_timing(node, "panel-timing", &timing);
240 if (r) {
241 dev_err(&pdev->dev, "failed to get video timing\n");
242 return r;
243 }
244
245 videomode_from_timing(&timing, &ddata->vm);
246
247 in = omapdss_of_find_source_for_first_ep(node);
248 if (IS_ERR(in)) {
249 dev_err(&pdev->dev, "failed to find video source\n");
250 return PTR_ERR(in);
251 }
252
253 ddata->in = in;
254
255 return 0;
256}
257
258static int panel_dpi_probe(struct platform_device *pdev)
259{
260 struct panel_drv_data *ddata;
261 struct omap_dss_device *dssdev;
262 int r;
263
264 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
265 if (ddata == NULL)
266 return -ENOMEM;
267
268 platform_set_drvdata(pdev, ddata);
269
270 if (dev_get_platdata(&pdev->dev)) {
271 r = panel_dpi_probe_pdata(pdev);
272 if (r)
273 return r;
274 } else if (pdev->dev.of_node) {
275 r = panel_dpi_probe_of(pdev);
276 if (r)
277 return r;
278 } else {
279 return -ENODEV;
280 }
281
282 if (gpio_is_valid(ddata->backlight_gpio)) {
283 r = devm_gpio_request_one(&pdev->dev, ddata->backlight_gpio,
284 GPIOF_OUT_INIT_LOW, "panel backlight");
285 if (r)
286 goto err_gpio;
287 }
288
289 dssdev = &ddata->dssdev;
290 dssdev->dev = &pdev->dev;
291 dssdev->driver = &panel_dpi_ops;
292 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
293 dssdev->owner = THIS_MODULE;
294 dssdev->panel.vm = ddata->vm;
295 dssdev->phy.dpi.data_lines = ddata->data_lines;
296
297 r = omapdss_register_display(dssdev);
298 if (r) {
299 dev_err(&pdev->dev, "Failed to register panel\n");
300 goto err_reg;
301 }
302
303 return 0;
304
305err_reg:
306err_gpio:
307 omap_dss_put_device(ddata->in);
308 return r;
309}
310
311static int __exit panel_dpi_remove(struct platform_device *pdev)
312{
313 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
314 struct omap_dss_device *dssdev = &ddata->dssdev;
315 struct omap_dss_device *in = ddata->in;
316
317 omapdss_unregister_display(dssdev);
318
319 panel_dpi_disable(dssdev);
320 panel_dpi_disconnect(dssdev);
321
322 omap_dss_put_device(in);
323
324 return 0;
325}
326
327static const struct of_device_id panel_dpi_of_match[] = {
328 { .compatible = "omapdss,panel-dpi", },
329 {},
330};
331
332MODULE_DEVICE_TABLE(of, panel_dpi_of_match);
333
334static struct platform_driver panel_dpi_driver = {
335 .probe = panel_dpi_probe,
336 .remove = __exit_p(panel_dpi_remove),
337 .driver = {
338 .name = "panel-dpi",
339 .of_match_table = panel_dpi_of_match,
340 .suppress_bind_attrs = true,
341 },
342};
343
344module_platform_driver(panel_dpi_driver);
345
346MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
347MODULE_DESCRIPTION("Generic MIPI DPI Panel Driver");
348MODULE_LICENSE("GPL");