]> Git Repo - linux.git/blob - drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c
tcp: add tp->tcp_mstamp field
[linux.git] / drivers / gpu / drm / omapdrm / displays / encoder-tfp410.c
1 /*
2  * TFP410 DPI-to-DVI encoder driver
3  *
4  * Copyright (C) 2013 Texas Instruments
5  * Author: Tomi Valkeinen <[email protected]>
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_gpio.h>
17
18 #include "../dss/omapdss.h"
19
20 struct panel_drv_data {
21         struct omap_dss_device dssdev;
22         struct omap_dss_device *in;
23
24         int pd_gpio;
25         int data_lines;
26
27         struct videomode vm;
28 };
29
30 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
31
32 static int tfp410_connect(struct omap_dss_device *dssdev,
33                 struct omap_dss_device *dst)
34 {
35         struct panel_drv_data *ddata = to_panel_data(dssdev);
36         struct omap_dss_device *in = ddata->in;
37         int r;
38
39         if (omapdss_device_is_connected(dssdev))
40                 return -EBUSY;
41
42         r = in->ops.dpi->connect(in, dssdev);
43         if (r)
44                 return r;
45
46         dst->src = dssdev;
47         dssdev->dst = dst;
48
49         return 0;
50 }
51
52 static void tfp410_disconnect(struct omap_dss_device *dssdev,
53                 struct omap_dss_device *dst)
54 {
55         struct panel_drv_data *ddata = to_panel_data(dssdev);
56         struct omap_dss_device *in = ddata->in;
57
58         WARN_ON(!omapdss_device_is_connected(dssdev));
59         if (!omapdss_device_is_connected(dssdev))
60                 return;
61
62         WARN_ON(dst != dssdev->dst);
63         if (dst != dssdev->dst)
64                 return;
65
66         dst->src = NULL;
67         dssdev->dst = NULL;
68
69         in->ops.dpi->disconnect(in, &ddata->dssdev);
70 }
71
72 static int tfp410_enable(struct omap_dss_device *dssdev)
73 {
74         struct panel_drv_data *ddata = to_panel_data(dssdev);
75         struct omap_dss_device *in = ddata->in;
76         int r;
77
78         if (!omapdss_device_is_connected(dssdev))
79                 return -ENODEV;
80
81         if (omapdss_device_is_enabled(dssdev))
82                 return 0;
83
84         in->ops.dpi->set_timings(in, &ddata->vm);
85         if (ddata->data_lines)
86                 in->ops.dpi->set_data_lines(in, ddata->data_lines);
87
88         r = in->ops.dpi->enable(in);
89         if (r)
90                 return r;
91
92         if (gpio_is_valid(ddata->pd_gpio))
93                 gpio_set_value_cansleep(ddata->pd_gpio, 1);
94
95         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
96
97         return 0;
98 }
99
100 static void tfp410_disable(struct omap_dss_device *dssdev)
101 {
102         struct panel_drv_data *ddata = to_panel_data(dssdev);
103         struct omap_dss_device *in = ddata->in;
104
105         if (!omapdss_device_is_enabled(dssdev))
106                 return;
107
108         if (gpio_is_valid(ddata->pd_gpio))
109                 gpio_set_value_cansleep(ddata->pd_gpio, 0);
110
111         in->ops.dpi->disable(in);
112
113         dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
114 }
115
116 static void tfp410_fix_timings(struct videomode *vm)
117 {
118         vm->flags |= DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_PIXDATA_POSEDGE |
119                      DISPLAY_FLAGS_SYNC_POSEDGE;
120 }
121
122 static void tfp410_set_timings(struct omap_dss_device *dssdev,
123                                struct videomode *vm)
124 {
125         struct panel_drv_data *ddata = to_panel_data(dssdev);
126         struct omap_dss_device *in = ddata->in;
127
128         tfp410_fix_timings(vm);
129
130         ddata->vm = *vm;
131         dssdev->panel.vm = *vm;
132
133         in->ops.dpi->set_timings(in, vm);
134 }
135
136 static void tfp410_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
144 static int tfp410_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         tfp410_fix_timings(vm);
151
152         return in->ops.dpi->check_timings(in, vm);
153 }
154
155 static const struct omapdss_dvi_ops tfp410_dvi_ops = {
156         .connect        = tfp410_connect,
157         .disconnect     = tfp410_disconnect,
158
159         .enable         = tfp410_enable,
160         .disable        = tfp410_disable,
161
162         .check_timings  = tfp410_check_timings,
163         .set_timings    = tfp410_set_timings,
164         .get_timings    = tfp410_get_timings,
165 };
166
167 static int tfp410_probe_of(struct platform_device *pdev)
168 {
169         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
170         struct device_node *node = pdev->dev.of_node;
171         struct omap_dss_device *in;
172         int gpio;
173
174         gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
175
176         if (gpio_is_valid(gpio) || gpio == -ENOENT) {
177                 ddata->pd_gpio = gpio;
178         } else {
179                 dev_err(&pdev->dev, "failed to parse PD gpio\n");
180                 return gpio;
181         }
182
183         in = omapdss_of_find_source_for_first_ep(node);
184         if (IS_ERR(in)) {
185                 dev_err(&pdev->dev, "failed to find video source\n");
186                 return PTR_ERR(in);
187         }
188
189         ddata->in = in;
190
191         return 0;
192 }
193
194 static int tfp410_probe(struct platform_device *pdev)
195 {
196         struct panel_drv_data *ddata;
197         struct omap_dss_device *dssdev;
198         int r;
199
200         ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
201         if (!ddata)
202                 return -ENOMEM;
203
204         platform_set_drvdata(pdev, ddata);
205
206         if (!pdev->dev.of_node)
207                 return -ENODEV;
208
209         r = tfp410_probe_of(pdev);
210         if (r)
211                 return r;
212
213         if (gpio_is_valid(ddata->pd_gpio)) {
214                 r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
215                                 GPIOF_OUT_INIT_LOW, "tfp410 PD");
216                 if (r) {
217                         dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
218                                         ddata->pd_gpio);
219                         goto err_gpio;
220                 }
221         }
222
223         dssdev = &ddata->dssdev;
224         dssdev->ops.dvi = &tfp410_dvi_ops;
225         dssdev->dev = &pdev->dev;
226         dssdev->type = OMAP_DISPLAY_TYPE_DPI;
227         dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
228         dssdev->owner = THIS_MODULE;
229         dssdev->phy.dpi.data_lines = ddata->data_lines;
230         dssdev->port_num = 1;
231
232         r = omapdss_register_output(dssdev);
233         if (r) {
234                 dev_err(&pdev->dev, "Failed to register output\n");
235                 goto err_reg;
236         }
237
238         return 0;
239 err_reg:
240 err_gpio:
241         omap_dss_put_device(ddata->in);
242         return r;
243 }
244
245 static int __exit tfp410_remove(struct platform_device *pdev)
246 {
247         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
248         struct omap_dss_device *dssdev = &ddata->dssdev;
249         struct omap_dss_device *in = ddata->in;
250
251         omapdss_unregister_output(&ddata->dssdev);
252
253         WARN_ON(omapdss_device_is_enabled(dssdev));
254         if (omapdss_device_is_enabled(dssdev))
255                 tfp410_disable(dssdev);
256
257         WARN_ON(omapdss_device_is_connected(dssdev));
258         if (omapdss_device_is_connected(dssdev))
259                 tfp410_disconnect(dssdev, dssdev->dst);
260
261         omap_dss_put_device(in);
262
263         return 0;
264 }
265
266 static const struct of_device_id tfp410_of_match[] = {
267         { .compatible = "omapdss,ti,tfp410", },
268         {},
269 };
270
271 MODULE_DEVICE_TABLE(of, tfp410_of_match);
272
273 static struct platform_driver tfp410_driver = {
274         .probe  = tfp410_probe,
275         .remove = __exit_p(tfp410_remove),
276         .driver = {
277                 .name   = "tfp410",
278                 .of_match_table = tfp410_of_match,
279                 .suppress_bind_attrs = true,
280         },
281 };
282
283 module_platform_driver(tfp410_driver);
284
285 MODULE_AUTHOR("Tomi Valkeinen <[email protected]>");
286 MODULE_DESCRIPTION("TFP410 DPI to DVI encoder driver");
287 MODULE_LICENSE("GPL");
This page took 0.049933 seconds and 4 git commands to generate.