diff options
Diffstat (limited to 'drivers/video/fbdev/omap2/displays-new/encoder-tfp410.c')
-rw-r--r-- | drivers/video/fbdev/omap2/displays-new/encoder-tfp410.c | 308 |
1 files changed, 308 insertions, 0 deletions
diff --git a/drivers/video/fbdev/omap2/displays-new/encoder-tfp410.c b/drivers/video/fbdev/omap2/displays-new/encoder-tfp410.c new file mode 100644 index 000000000000..b4e9a42a79e6 --- /dev/null +++ b/drivers/video/fbdev/omap2/displays-new/encoder-tfp410.c | |||
@@ -0,0 +1,308 @@ | |||
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> | ||
16 | #include <linux/of_gpio.h> | ||
17 | |||
18 | #include <video/omapdss.h> | ||
19 | #include <video/omap-panel-data.h> | ||
20 | |||
21 | struct 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 | |||
33 | static 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 | |||
47 | dst->src = dssdev; | ||
48 | dssdev->dst = dst; | ||
49 | |||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | static 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 | |||
63 | WARN_ON(dst != dssdev->dst); | ||
64 | if (dst != dssdev->dst) | ||
65 | return; | ||
66 | |||
67 | dst->src = NULL; | ||
68 | dssdev->dst = NULL; | ||
69 | |||
70 | in->ops.dpi->disconnect(in, &ddata->dssdev); | ||
71 | } | ||
72 | |||
73 | static 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); | ||
86 | if (ddata->data_lines) | ||
87 | in->ops.dpi->set_data_lines(in, ddata->data_lines); | ||
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 | |||
101 | static 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 | |||
117 | static 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 | |||
129 | static 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 | |||
137 | static 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 | |||
146 | static 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 | |||
158 | static 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 | |||
184 | static 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 | |||
211 | static 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; | ||
227 | } else if (pdev->dev.of_node) { | ||
228 | r = tfp410_probe_of(pdev); | ||
229 | if (r) | ||
230 | return r; | ||
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; | ||
260 | err_reg: | ||
261 | err_gpio: | ||
262 | omap_dss_put_device(ddata->in); | ||
263 | return r; | ||
264 | } | ||
265 | |||
266 | static 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)) | ||
280 | tfp410_disconnect(dssdev, dssdev->dst); | ||
281 | |||
282 | omap_dss_put_device(in); | ||
283 | |||
284 | return 0; | ||
285 | } | ||
286 | |||
287 | static const struct of_device_id tfp410_of_match[] = { | ||
288 | { .compatible = "omapdss,ti,tfp410", }, | ||
289 | {}, | ||
290 | }; | ||
291 | |||
292 | MODULE_DEVICE_TABLE(of, tfp410_of_match); | ||
293 | |||
294 | static struct platform_driver tfp410_driver = { | ||
295 | .probe = tfp410_probe, | ||
296 | .remove = __exit_p(tfp410_remove), | ||
297 | .driver = { | ||
298 | .name = "tfp410", | ||
299 | .owner = THIS_MODULE, | ||
300 | .of_match_table = tfp410_of_match, | ||
301 | }, | ||
302 | }; | ||
303 | |||
304 | module_platform_driver(tfp410_driver); | ||
305 | |||
306 | MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>"); | ||
307 | MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver"); | ||
308 | MODULE_LICENSE("GPL"); | ||