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