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