1 /*
2 * Analog TV Connector driver
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
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 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
44
tvc_connect(struct omap_dss_device * dssdev)45 static 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;
49 int r;
50
51 dev_dbg(ddata->dev, "connect\n");
52
53 if (omapdss_device_is_connected(dssdev))
54 return 0;
55
56 in = omapdss_of_find_source_for_first_ep(ddata->dev->of_node);
57 if (IS_ERR(in)) {
58 dev_err(ddata->dev, "failed to find video source\n");
59 return PTR_ERR(in);
60 }
61
62 r = in->ops.atv->connect(in, dssdev);
63 if (r) {
64 omap_dss_put_device(in);
65 return r;
66 }
67
68 ddata->in = in;
69 return 0;
70 }
71
tvc_disconnect(struct omap_dss_device * dssdev)72 static 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 omap_dss_put_device(in);
85 ddata->in = NULL;
86 }
87
tvc_enable(struct omap_dss_device * dssdev)88 static int tvc_enable(struct omap_dss_device *dssdev)
89 {
90 struct panel_drv_data *ddata = to_panel_data(dssdev);
91 struct omap_dss_device *in = ddata->in;
92 int r;
93
94 dev_dbg(ddata->dev, "enable\n");
95
96 if (!omapdss_device_is_connected(dssdev))
97 return -ENODEV;
98
99 if (omapdss_device_is_enabled(dssdev))
100 return 0;
101
102 in->ops.atv->set_timings(in, &ddata->vm);
103
104 r = in->ops.atv->enable(in);
105 if (r)
106 return r;
107
108 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
109
110 return r;
111 }
112
tvc_disable(struct omap_dss_device * dssdev)113 static void tvc_disable(struct omap_dss_device *dssdev)
114 {
115 struct panel_drv_data *ddata = to_panel_data(dssdev);
116 struct omap_dss_device *in = ddata->in;
117
118 dev_dbg(ddata->dev, "disable\n");
119
120 if (!omapdss_device_is_enabled(dssdev))
121 return;
122
123 in->ops.atv->disable(in);
124
125 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
126 }
127
tvc_set_timings(struct omap_dss_device * dssdev,struct videomode * vm)128 static void tvc_set_timings(struct omap_dss_device *dssdev,
129 struct videomode *vm)
130 {
131 struct panel_drv_data *ddata = to_panel_data(dssdev);
132 struct omap_dss_device *in = ddata->in;
133
134 ddata->vm = *vm;
135 dssdev->panel.vm = *vm;
136
137 in->ops.atv->set_timings(in, vm);
138 }
139
tvc_get_timings(struct omap_dss_device * dssdev,struct videomode * vm)140 static void tvc_get_timings(struct omap_dss_device *dssdev,
141 struct videomode *vm)
142 {
143 struct panel_drv_data *ddata = to_panel_data(dssdev);
144
145 *vm = ddata->vm;
146 }
147
tvc_check_timings(struct omap_dss_device * dssdev,struct videomode * vm)148 static int tvc_check_timings(struct omap_dss_device *dssdev,
149 struct videomode *vm)
150 {
151 struct panel_drv_data *ddata = to_panel_data(dssdev);
152 struct omap_dss_device *in = ddata->in;
153
154 return in->ops.atv->check_timings(in, vm);
155 }
156
tvc_get_wss(struct omap_dss_device * dssdev)157 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
158 {
159 struct panel_drv_data *ddata = to_panel_data(dssdev);
160 struct omap_dss_device *in = ddata->in;
161
162 return in->ops.atv->get_wss(in);
163 }
164
tvc_set_wss(struct omap_dss_device * dssdev,u32 wss)165 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
166 {
167 struct panel_drv_data *ddata = to_panel_data(dssdev);
168 struct omap_dss_device *in = ddata->in;
169
170 return in->ops.atv->set_wss(in, wss);
171 }
172
173 static struct omap_dss_driver tvc_driver = {
174 .connect = tvc_connect,
175 .disconnect = tvc_disconnect,
176
177 .enable = tvc_enable,
178 .disable = tvc_disable,
179
180 .set_timings = tvc_set_timings,
181 .get_timings = tvc_get_timings,
182 .check_timings = tvc_check_timings,
183
184 .get_wss = tvc_get_wss,
185 .set_wss = tvc_set_wss,
186 };
187
tvc_probe(struct platform_device * pdev)188 static int tvc_probe(struct platform_device *pdev)
189 {
190 struct panel_drv_data *ddata;
191 struct omap_dss_device *dssdev;
192 int r;
193
194 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
195 if (!ddata)
196 return -ENOMEM;
197
198 platform_set_drvdata(pdev, ddata);
199 ddata->dev = &pdev->dev;
200
201 ddata->vm = tvc_pal_vm;
202
203 dssdev = &ddata->dssdev;
204 dssdev->driver = &tvc_driver;
205 dssdev->dev = &pdev->dev;
206 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
207 dssdev->owner = THIS_MODULE;
208 dssdev->panel.vm = tvc_pal_vm;
209
210 r = omapdss_register_display(dssdev);
211 if (r) {
212 dev_err(&pdev->dev, "Failed to register panel\n");
213 return r;
214 }
215
216 return 0;
217 }
218
tvc_remove(struct platform_device * pdev)219 static int __exit tvc_remove(struct platform_device *pdev)
220 {
221 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
222 struct omap_dss_device *dssdev = &ddata->dssdev;
223
224 omapdss_unregister_display(&ddata->dssdev);
225
226 tvc_disable(dssdev);
227 tvc_disconnect(dssdev);
228
229 return 0;
230 }
231
232 static const struct of_device_id tvc_of_match[] = {
233 { .compatible = "omapdss,svideo-connector", },
234 { .compatible = "omapdss,composite-video-connector", },
235 {},
236 };
237
238 MODULE_DEVICE_TABLE(of, tvc_of_match);
239
240 static struct platform_driver tvc_connector_driver = {
241 .probe = tvc_probe,
242 .remove = __exit_p(tvc_remove),
243 .driver = {
244 .name = "connector-analog-tv",
245 .of_match_table = tvc_of_match,
246 .suppress_bind_attrs = true,
247 },
248 };
249
250 module_platform_driver(tvc_connector_driver);
251
252 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
253 MODULE_DESCRIPTION("Analog TV Connector driver");
254 MODULE_LICENSE("GPL");
255