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