GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / gpu / drm / omapdrm / displays / connector-analog-tv.c
1 /*
2  * Analog TV Connector 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/slab.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/of.h>
16
17 #include "../dss/omapdss.h"
18
19 struct panel_drv_data {
20         struct omap_dss_device dssdev;
21         struct omap_dss_device *in;
22
23         struct device *dev;
24
25         struct videomode vm;
26 };
27
28 static const struct videomode tvc_pal_vm = {
29         .hactive        = 720,
30         .vactive        = 574,
31         .pixelclock     = 13500000,
32         .hsync_len      = 64,
33         .hfront_porch   = 12,
34         .hback_porch    = 68,
35         .vsync_len      = 5,
36         .vfront_porch   = 5,
37         .vback_porch    = 41,
38
39         .flags          = DISPLAY_FLAGS_INTERLACED | DISPLAY_FLAGS_HSYNC_LOW |
40                           DISPLAY_FLAGS_VSYNC_LOW,
41 };
42
43 static const struct of_device_id tvc_of_match[];
44
45 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
46
47 static int tvc_connect(struct omap_dss_device *dssdev)
48 {
49         struct panel_drv_data *ddata = to_panel_data(dssdev);
50         struct omap_dss_device *in = ddata->in;
51         int r;
52
53         dev_dbg(ddata->dev, "connect\n");
54
55         if (omapdss_device_is_connected(dssdev))
56                 return 0;
57
58         r = in->ops.atv->connect(in, dssdev);
59         if (r)
60                 return r;
61
62         return 0;
63 }
64
65 static void tvc_disconnect(struct omap_dss_device *dssdev)
66 {
67         struct panel_drv_data *ddata = to_panel_data(dssdev);
68         struct omap_dss_device *in = ddata->in;
69
70         dev_dbg(ddata->dev, "disconnect\n");
71
72         if (!omapdss_device_is_connected(dssdev))
73                 return;
74
75         in->ops.atv->disconnect(in, dssdev);
76 }
77
78 static int tvc_enable(struct omap_dss_device *dssdev)
79 {
80         struct panel_drv_data *ddata = to_panel_data(dssdev);
81         struct omap_dss_device *in = ddata->in;
82         int r;
83
84         dev_dbg(ddata->dev, "enable\n");
85
86         if (!omapdss_device_is_connected(dssdev))
87                 return -ENODEV;
88
89         if (omapdss_device_is_enabled(dssdev))
90                 return 0;
91
92         in->ops.atv->set_timings(in, &ddata->vm);
93
94         r = in->ops.atv->enable(in);
95         if (r)
96                 return r;
97
98         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
99
100         return r;
101 }
102
103 static void tvc_disable(struct omap_dss_device *dssdev)
104 {
105         struct panel_drv_data *ddata = to_panel_data(dssdev);
106         struct omap_dss_device *in = ddata->in;
107
108         dev_dbg(ddata->dev, "disable\n");
109
110         if (!omapdss_device_is_enabled(dssdev))
111                 return;
112
113         in->ops.atv->disable(in);
114
115         dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
116 }
117
118 static void tvc_set_timings(struct omap_dss_device *dssdev,
119                             struct videomode *vm)
120 {
121         struct panel_drv_data *ddata = to_panel_data(dssdev);
122         struct omap_dss_device *in = ddata->in;
123
124         ddata->vm = *vm;
125         dssdev->panel.vm = *vm;
126
127         in->ops.atv->set_timings(in, vm);
128 }
129
130 static void tvc_get_timings(struct omap_dss_device *dssdev,
131                             struct videomode *vm)
132 {
133         struct panel_drv_data *ddata = to_panel_data(dssdev);
134
135         *vm = ddata->vm;
136 }
137
138 static int tvc_check_timings(struct omap_dss_device *dssdev,
139                              struct videomode *vm)
140 {
141         struct panel_drv_data *ddata = to_panel_data(dssdev);
142         struct omap_dss_device *in = ddata->in;
143
144         return in->ops.atv->check_timings(in, vm);
145 }
146
147 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
148 {
149         struct panel_drv_data *ddata = to_panel_data(dssdev);
150         struct omap_dss_device *in = ddata->in;
151
152         return in->ops.atv->get_wss(in);
153 }
154
155 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
156 {
157         struct panel_drv_data *ddata = to_panel_data(dssdev);
158         struct omap_dss_device *in = ddata->in;
159
160         return in->ops.atv->set_wss(in, wss);
161 }
162
163 static struct omap_dss_driver tvc_driver = {
164         .connect                = tvc_connect,
165         .disconnect             = tvc_disconnect,
166
167         .enable                 = tvc_enable,
168         .disable                = tvc_disable,
169
170         .set_timings            = tvc_set_timings,
171         .get_timings            = tvc_get_timings,
172         .check_timings          = tvc_check_timings,
173
174         .get_wss                = tvc_get_wss,
175         .set_wss                = tvc_set_wss,
176 };
177
178 static int tvc_probe_of(struct platform_device *pdev)
179 {
180         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
181         struct device_node *node = pdev->dev.of_node;
182         struct omap_dss_device *in;
183
184         in = omapdss_of_find_source_for_first_ep(node);
185         if (IS_ERR(in)) {
186                 dev_err(&pdev->dev, "failed to find video source\n");
187                 return PTR_ERR(in);
188         }
189
190         ddata->in = in;
191
192         return 0;
193 }
194
195 static int tvc_probe(struct platform_device *pdev)
196 {
197         struct panel_drv_data *ddata;
198         struct omap_dss_device *dssdev;
199         int r;
200
201         if (!pdev->dev.of_node)
202                 return -ENODEV;
203
204         ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
205         if (!ddata)
206                 return -ENOMEM;
207
208         platform_set_drvdata(pdev, ddata);
209         ddata->dev = &pdev->dev;
210
211         r = tvc_probe_of(pdev);
212         if (r)
213                 return r;
214
215         ddata->vm = tvc_pal_vm;
216
217         dssdev = &ddata->dssdev;
218         dssdev->driver = &tvc_driver;
219         dssdev->dev = &pdev->dev;
220         dssdev->type = OMAP_DISPLAY_TYPE_VENC;
221         dssdev->owner = THIS_MODULE;
222         dssdev->panel.vm = tvc_pal_vm;
223
224         r = omapdss_register_display(dssdev);
225         if (r) {
226                 dev_err(&pdev->dev, "Failed to register panel\n");
227                 goto err_reg;
228         }
229
230         return 0;
231 err_reg:
232         omap_dss_put_device(ddata->in);
233         return r;
234 }
235
236 static int __exit tvc_remove(struct platform_device *pdev)
237 {
238         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
239         struct omap_dss_device *dssdev = &ddata->dssdev;
240         struct omap_dss_device *in = ddata->in;
241
242         omapdss_unregister_display(&ddata->dssdev);
243
244         tvc_disable(dssdev);
245         tvc_disconnect(dssdev);
246
247         omap_dss_put_device(in);
248
249         return 0;
250 }
251
252 static const struct of_device_id tvc_of_match[] = {
253         { .compatible = "omapdss,svideo-connector", },
254         { .compatible = "omapdss,composite-video-connector", },
255         {},
256 };
257
258 MODULE_DEVICE_TABLE(of, tvc_of_match);
259
260 static struct platform_driver tvc_connector_driver = {
261         .probe  = tvc_probe,
262         .remove = __exit_p(tvc_remove),
263         .driver = {
264                 .name   = "connector-analog-tv",
265                 .of_match_table = tvc_of_match,
266                 .suppress_bind_attrs = true,
267         },
268 };
269
270 module_platform_driver(tvc_connector_driver);
271
272 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
273 MODULE_DESCRIPTION("Analog TV Connector driver");
274 MODULE_LICENSE("GPL");