x86/boot: Rename overlapping memcpy() to memmove()
[linux/fpc-iii.git] / drivers / video / fbdev / omap2 / omapfb / displays / connector-analog-tv.c
blob8511c648a15c21cd5d7239e804ca1088c3e189bf
1 /*
2 * Analog TV Connector driver
4 * Copyright (C) 2013 Texas Instruments
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
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.
12 #include <linux/slab.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/of.h>
17 #include <video/omapdss.h>
18 #include <video/omap-panel-data.h>
20 struct panel_drv_data {
21 struct omap_dss_device dssdev;
22 struct omap_dss_device *in;
24 struct device *dev;
26 struct omap_video_timings timings;
28 enum omap_dss_venc_type connector_type;
29 bool invert_polarity;
32 static 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,
43 .interlace = true,
46 static const struct of_device_id tvc_of_match[];
48 struct tvc_of_data {
49 enum omap_dss_venc_type connector_type;
52 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
54 static int tvc_connect(struct omap_dss_device *dssdev)
56 struct panel_drv_data *ddata = to_panel_data(dssdev);
57 struct omap_dss_device *in = ddata->in;
58 int r;
60 dev_dbg(ddata->dev, "connect\n");
62 if (omapdss_device_is_connected(dssdev))
63 return 0;
65 r = in->ops.atv->connect(in, dssdev);
66 if (r)
67 return r;
69 return 0;
72 static void tvc_disconnect(struct omap_dss_device *dssdev)
74 struct panel_drv_data *ddata = to_panel_data(dssdev);
75 struct omap_dss_device *in = ddata->in;
77 dev_dbg(ddata->dev, "disconnect\n");
79 if (!omapdss_device_is_connected(dssdev))
80 return;
82 in->ops.atv->disconnect(in, dssdev);
85 static int tvc_enable(struct omap_dss_device *dssdev)
87 struct panel_drv_data *ddata = to_panel_data(dssdev);
88 struct omap_dss_device *in = ddata->in;
89 int r;
91 dev_dbg(ddata->dev, "enable\n");
93 if (!omapdss_device_is_connected(dssdev))
94 return -ENODEV;
96 if (omapdss_device_is_enabled(dssdev))
97 return 0;
99 in->ops.atv->set_timings(in, &ddata->timings);
101 if (!ddata->dev->of_node) {
102 in->ops.atv->set_type(in, ddata->connector_type);
104 in->ops.atv->invert_vid_out_polarity(in,
105 ddata->invert_polarity);
108 r = in->ops.atv->enable(in);
109 if (r)
110 return r;
112 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
114 return r;
117 static void tvc_disable(struct omap_dss_device *dssdev)
119 struct panel_drv_data *ddata = to_panel_data(dssdev);
120 struct omap_dss_device *in = ddata->in;
122 dev_dbg(ddata->dev, "disable\n");
124 if (!omapdss_device_is_enabled(dssdev))
125 return;
127 in->ops.atv->disable(in);
129 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
132 static void tvc_set_timings(struct omap_dss_device *dssdev,
133 struct omap_video_timings *timings)
135 struct panel_drv_data *ddata = to_panel_data(dssdev);
136 struct omap_dss_device *in = ddata->in;
138 ddata->timings = *timings;
139 dssdev->panel.timings = *timings;
141 in->ops.atv->set_timings(in, timings);
144 static void tvc_get_timings(struct omap_dss_device *dssdev,
145 struct omap_video_timings *timings)
147 struct panel_drv_data *ddata = to_panel_data(dssdev);
149 *timings = ddata->timings;
152 static int tvc_check_timings(struct omap_dss_device *dssdev,
153 struct omap_video_timings *timings)
155 struct panel_drv_data *ddata = to_panel_data(dssdev);
156 struct omap_dss_device *in = ddata->in;
158 return in->ops.atv->check_timings(in, timings);
161 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
163 struct panel_drv_data *ddata = to_panel_data(dssdev);
164 struct omap_dss_device *in = ddata->in;
166 return in->ops.atv->get_wss(in);
169 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
171 struct panel_drv_data *ddata = to_panel_data(dssdev);
172 struct omap_dss_device *in = ddata->in;
174 return in->ops.atv->set_wss(in, wss);
177 static struct omap_dss_driver tvc_driver = {
178 .connect = tvc_connect,
179 .disconnect = tvc_disconnect,
181 .enable = tvc_enable,
182 .disable = tvc_disable,
184 .set_timings = tvc_set_timings,
185 .get_timings = tvc_get_timings,
186 .check_timings = tvc_check_timings,
188 .get_resolution = omapdss_default_get_resolution,
190 .get_wss = tvc_get_wss,
191 .set_wss = tvc_set_wss,
194 static int tvc_probe_pdata(struct platform_device *pdev)
196 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
197 struct connector_atv_platform_data *pdata;
198 struct omap_dss_device *in, *dssdev;
200 pdata = dev_get_platdata(&pdev->dev);
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;
208 ddata->in = in;
210 ddata->connector_type = pdata->connector_type;
211 ddata->invert_polarity = pdata->invert_polarity;
213 dssdev = &ddata->dssdev;
214 dssdev->name = pdata->name;
216 return 0;
219 static int tvc_probe_of(struct platform_device *pdev)
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;
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);
231 ddata->in = in;
233 return 0;
236 static int tvc_probe(struct platform_device *pdev)
238 struct panel_drv_data *ddata;
239 struct omap_dss_device *dssdev;
240 int r;
242 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
243 if (!ddata)
244 return -ENOMEM;
246 platform_set_drvdata(pdev, ddata);
247 ddata->dev = &pdev->dev;
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;
261 ddata->timings = tvc_pal_timings;
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;
270 r = omapdss_register_display(dssdev);
271 if (r) {
272 dev_err(&pdev->dev, "Failed to register panel\n");
273 goto err_reg;
276 return 0;
277 err_reg:
278 omap_dss_put_device(ddata->in);
279 return r;
282 static int __exit tvc_remove(struct platform_device *pdev)
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;
288 omapdss_unregister_display(&ddata->dssdev);
290 tvc_disable(dssdev);
291 tvc_disconnect(dssdev);
293 omap_dss_put_device(in);
295 return 0;
298 static const struct of_device_id tvc_of_match[] = {
299 { .compatible = "omapdss,svideo-connector", },
300 { .compatible = "omapdss,composite-video-connector", },
304 MODULE_DEVICE_TABLE(of, tvc_of_match);
306 static 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,
316 module_platform_driver(tvc_connector_driver);
318 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
319 MODULE_DESCRIPTION("Analog TV Connector driver");
320 MODULE_LICENSE("GPL");