]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/video/fbdev/omap2/displays-new/encoder-tfp410.c
Merge remote-tracking branches 'spi/topic/mxs', 'spi/topic/pxa', 'spi/topic/rockchip...
[mirror_ubuntu-eoan-kernel.git] / drivers / video / fbdev / omap2 / displays-new / encoder-tfp410.c
CommitLineData
2773fefb
TV
1/*
2 * TFP410 DPI-to-DVI encoder 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.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
cfa71144 16#include <linux/of_gpio.h>
2773fefb
TV
17
18#include <video/omapdss.h>
19#include <video/omap-panel-data.h>
20
21struct panel_drv_data {
22 struct omap_dss_device dssdev;
23 struct omap_dss_device *in;
24
25 int pd_gpio;
26 int data_lines;
27
28 struct omap_video_timings timings;
29};
30
31#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
32
33static int tfp410_connect(struct omap_dss_device *dssdev,
34 struct omap_dss_device *dst)
35{
36 struct panel_drv_data *ddata = to_panel_data(dssdev);
37 struct omap_dss_device *in = ddata->in;
38 int r;
39
40 if (omapdss_device_is_connected(dssdev))
41 return -EBUSY;
42
43 r = in->ops.dpi->connect(in, dssdev);
44 if (r)
45 return r;
46
a73fdc64 47 dst->src = dssdev;
9560dc10 48 dssdev->dst = dst;
2773fefb
TV
49
50 return 0;
51}
52
53static void tfp410_disconnect(struct omap_dss_device *dssdev,
54 struct omap_dss_device *dst)
55{
56 struct panel_drv_data *ddata = to_panel_data(dssdev);
57 struct omap_dss_device *in = ddata->in;
58
59 WARN_ON(!omapdss_device_is_connected(dssdev));
60 if (!omapdss_device_is_connected(dssdev))
61 return;
62
9560dc10
TV
63 WARN_ON(dst != dssdev->dst);
64 if (dst != dssdev->dst)
2773fefb
TV
65 return;
66
a73fdc64 67 dst->src = NULL;
9560dc10 68 dssdev->dst = NULL;
2773fefb
TV
69
70 in->ops.dpi->disconnect(in, &ddata->dssdev);
71}
72
73static int tfp410_enable(struct omap_dss_device *dssdev)
74{
75 struct panel_drv_data *ddata = to_panel_data(dssdev);
76 struct omap_dss_device *in = ddata->in;
77 int r;
78
79 if (!omapdss_device_is_connected(dssdev))
80 return -ENODEV;
81
82 if (omapdss_device_is_enabled(dssdev))
83 return 0;
84
85 in->ops.dpi->set_timings(in, &ddata->timings);
cfa71144
TV
86 if (ddata->data_lines)
87 in->ops.dpi->set_data_lines(in, ddata->data_lines);
2773fefb
TV
88
89 r = in->ops.dpi->enable(in);
90 if (r)
91 return r;
92
93 if (gpio_is_valid(ddata->pd_gpio))
94 gpio_set_value_cansleep(ddata->pd_gpio, 1);
95
96 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
97
98 return 0;
99}
100
101static void tfp410_disable(struct omap_dss_device *dssdev)
102{
103 struct panel_drv_data *ddata = to_panel_data(dssdev);
104 struct omap_dss_device *in = ddata->in;
105
106 if (!omapdss_device_is_enabled(dssdev))
107 return;
108
109 if (gpio_is_valid(ddata->pd_gpio))
110 gpio_set_value_cansleep(ddata->pd_gpio, 0);
111
112 in->ops.dpi->disable(in);
113
114 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
115}
116
117static void tfp410_set_timings(struct omap_dss_device *dssdev,
118 struct omap_video_timings *timings)
119{
120 struct panel_drv_data *ddata = to_panel_data(dssdev);
121 struct omap_dss_device *in = ddata->in;
122
123 ddata->timings = *timings;
124 dssdev->panel.timings = *timings;
125
126 in->ops.dpi->set_timings(in, timings);
127}
128
129static void tfp410_get_timings(struct omap_dss_device *dssdev,
130 struct omap_video_timings *timings)
131{
132 struct panel_drv_data *ddata = to_panel_data(dssdev);
133
134 *timings = ddata->timings;
135}
136
137static int tfp410_check_timings(struct omap_dss_device *dssdev,
138 struct omap_video_timings *timings)
139{
140 struct panel_drv_data *ddata = to_panel_data(dssdev);
141 struct omap_dss_device *in = ddata->in;
142
143 return in->ops.dpi->check_timings(in, timings);
144}
145
146static const struct omapdss_dvi_ops tfp410_dvi_ops = {
147 .connect = tfp410_connect,
148 .disconnect = tfp410_disconnect,
149
150 .enable = tfp410_enable,
151 .disable = tfp410_disable,
152
153 .check_timings = tfp410_check_timings,
154 .set_timings = tfp410_set_timings,
155 .get_timings = tfp410_get_timings,
156};
157
158static int tfp410_probe_pdata(struct platform_device *pdev)
159{
160 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
161 struct encoder_tfp410_platform_data *pdata;
162 struct omap_dss_device *dssdev, *in;
163
164 pdata = dev_get_platdata(&pdev->dev);
165
166 ddata->pd_gpio = pdata->power_down_gpio;
167
168 ddata->data_lines = pdata->data_lines;
169
170 in = omap_dss_find_output(pdata->source);
171 if (in == NULL) {
172 dev_err(&pdev->dev, "Failed to find video source\n");
173 return -ENODEV;
174 }
175
176 ddata->in = in;
177
178 dssdev = &ddata->dssdev;
179 dssdev->name = pdata->name;
180
181 return 0;
182}
183
cfa71144
TV
184static int tfp410_probe_of(struct platform_device *pdev)
185{
186 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
187 struct device_node *node = pdev->dev.of_node;
188 struct omap_dss_device *in;
189 int gpio;
190
191 gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
192
193 if (gpio_is_valid(gpio) || gpio == -ENOENT) {
194 ddata->pd_gpio = gpio;
195 } else {
196 dev_err(&pdev->dev, "failed to parse PD gpio\n");
197 return gpio;
198 }
199
200 in = omapdss_of_find_source_for_first_ep(node);
201 if (IS_ERR(in)) {
202 dev_err(&pdev->dev, "failed to find video source\n");
203 return PTR_ERR(in);
204 }
205
206 ddata->in = in;
207
208 return 0;
209}
210
2773fefb
TV
211static int tfp410_probe(struct platform_device *pdev)
212{
213 struct panel_drv_data *ddata;
214 struct omap_dss_device *dssdev;
215 int r;
216
217 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
218 if (!ddata)
219 return -ENOMEM;
220
221 platform_set_drvdata(pdev, ddata);
222
223 if (dev_get_platdata(&pdev->dev)) {
224 r = tfp410_probe_pdata(pdev);
225 if (r)
226 return r;
cfa71144
TV
227 } else if (pdev->dev.of_node) {
228 r = tfp410_probe_of(pdev);
229 if (r)
230 return r;
2773fefb
TV
231 } else {
232 return -ENODEV;
233 }
234
235 if (gpio_is_valid(ddata->pd_gpio)) {
236 r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
237 GPIOF_OUT_INIT_LOW, "tfp410 PD");
238 if (r) {
239 dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
240 ddata->pd_gpio);
241 goto err_gpio;
242 }
243 }
244
245 dssdev = &ddata->dssdev;
246 dssdev->ops.dvi = &tfp410_dvi_ops;
247 dssdev->dev = &pdev->dev;
248 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
249 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
250 dssdev->owner = THIS_MODULE;
251 dssdev->phy.dpi.data_lines = ddata->data_lines;
252
253 r = omapdss_register_output(dssdev);
254 if (r) {
255 dev_err(&pdev->dev, "Failed to register output\n");
256 goto err_reg;
257 }
258
259 return 0;
260err_reg:
261err_gpio:
262 omap_dss_put_device(ddata->in);
263 return r;
264}
265
266static int __exit tfp410_remove(struct platform_device *pdev)
267{
268 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
269 struct omap_dss_device *dssdev = &ddata->dssdev;
270 struct omap_dss_device *in = ddata->in;
271
272 omapdss_unregister_output(&ddata->dssdev);
273
274 WARN_ON(omapdss_device_is_enabled(dssdev));
275 if (omapdss_device_is_enabled(dssdev))
276 tfp410_disable(dssdev);
277
278 WARN_ON(omapdss_device_is_connected(dssdev));
279 if (omapdss_device_is_connected(dssdev))
9560dc10 280 tfp410_disconnect(dssdev, dssdev->dst);
2773fefb
TV
281
282 omap_dss_put_device(in);
283
284 return 0;
285}
286
cfa71144
TV
287static const struct of_device_id tfp410_of_match[] = {
288 { .compatible = "omapdss,ti,tfp410", },
289 {},
290};
291
292MODULE_DEVICE_TABLE(of, tfp410_of_match);
293
2773fefb
TV
294static struct platform_driver tfp410_driver = {
295 .probe = tfp410_probe,
296 .remove = __exit_p(tfp410_remove),
297 .driver = {
298 .name = "tfp410",
299 .owner = THIS_MODULE,
cfa71144 300 .of_match_table = tfp410_of_match,
422ccbd5 301 .suppress_bind_attrs = true,
2773fefb
TV
302 },
303};
304
305module_platform_driver(tfp410_driver);
306
307MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
308MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
309MODULE_LICENSE("GPL");