Linux 4.16.11
[linux/fpc-iii.git] / drivers / video / fbdev / omap2 / omapfb / displays / connector-analog-tv.c
blob9d78411a3bf75123783df932cacc4dfb142b85bd
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/omapfb_dss.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 bool invert_polarity;
31 static const struct omap_video_timings tvc_pal_timings = {
32 .x_res = 720,
33 .y_res = 574,
34 .pixelclock = 13500000,
35 .hsw = 64,
36 .hfp = 12,
37 .hbp = 68,
38 .vsw = 5,
39 .vfp = 5,
40 .vbp = 41,
42 .interlace = true,
45 static const struct of_device_id tvc_of_match[];
47 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
49 static int tvc_connect(struct omap_dss_device *dssdev)
51 struct panel_drv_data *ddata = to_panel_data(dssdev);
52 struct omap_dss_device *in = ddata->in;
53 int r;
55 dev_dbg(ddata->dev, "connect\n");
57 if (omapdss_device_is_connected(dssdev))
58 return 0;
60 r = in->ops.atv->connect(in, dssdev);
61 if (r)
62 return r;
64 return 0;
67 static void tvc_disconnect(struct omap_dss_device *dssdev)
69 struct panel_drv_data *ddata = to_panel_data(dssdev);
70 struct omap_dss_device *in = ddata->in;
72 dev_dbg(ddata->dev, "disconnect\n");
74 if (!omapdss_device_is_connected(dssdev))
75 return;
77 in->ops.atv->disconnect(in, dssdev);
80 static int tvc_enable(struct omap_dss_device *dssdev)
82 struct panel_drv_data *ddata = to_panel_data(dssdev);
83 struct omap_dss_device *in = ddata->in;
84 int r;
86 dev_dbg(ddata->dev, "enable\n");
88 if (!omapdss_device_is_connected(dssdev))
89 return -ENODEV;
91 if (omapdss_device_is_enabled(dssdev))
92 return 0;
94 in->ops.atv->set_timings(in, &ddata->timings);
96 if (!ddata->dev->of_node) {
97 in->ops.atv->set_type(in, OMAP_DSS_VENC_TYPE_COMPOSITE);
99 in->ops.atv->invert_vid_out_polarity(in,
100 ddata->invert_polarity);
103 r = in->ops.atv->enable(in);
104 if (r)
105 return r;
107 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
109 return r;
112 static void tvc_disable(struct omap_dss_device *dssdev)
114 struct panel_drv_data *ddata = to_panel_data(dssdev);
115 struct omap_dss_device *in = ddata->in;
117 dev_dbg(ddata->dev, "disable\n");
119 if (!omapdss_device_is_enabled(dssdev))
120 return;
122 in->ops.atv->disable(in);
124 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
127 static void tvc_set_timings(struct omap_dss_device *dssdev,
128 struct omap_video_timings *timings)
130 struct panel_drv_data *ddata = to_panel_data(dssdev);
131 struct omap_dss_device *in = ddata->in;
133 ddata->timings = *timings;
134 dssdev->panel.timings = *timings;
136 in->ops.atv->set_timings(in, timings);
139 static void tvc_get_timings(struct omap_dss_device *dssdev,
140 struct omap_video_timings *timings)
142 struct panel_drv_data *ddata = to_panel_data(dssdev);
144 *timings = ddata->timings;
147 static int tvc_check_timings(struct omap_dss_device *dssdev,
148 struct omap_video_timings *timings)
150 struct panel_drv_data *ddata = to_panel_data(dssdev);
151 struct omap_dss_device *in = ddata->in;
153 return in->ops.atv->check_timings(in, timings);
156 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
158 struct panel_drv_data *ddata = to_panel_data(dssdev);
159 struct omap_dss_device *in = ddata->in;
161 return in->ops.atv->get_wss(in);
164 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
166 struct panel_drv_data *ddata = to_panel_data(dssdev);
167 struct omap_dss_device *in = ddata->in;
169 return in->ops.atv->set_wss(in, wss);
172 static struct omap_dss_driver tvc_driver = {
173 .connect = tvc_connect,
174 .disconnect = tvc_disconnect,
176 .enable = tvc_enable,
177 .disable = tvc_disable,
179 .set_timings = tvc_set_timings,
180 .get_timings = tvc_get_timings,
181 .check_timings = tvc_check_timings,
183 .get_resolution = omapdss_default_get_resolution,
185 .get_wss = tvc_get_wss,
186 .set_wss = tvc_set_wss,
189 static int tvc_probe_pdata(struct platform_device *pdev)
191 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
192 struct connector_atv_platform_data *pdata;
193 struct omap_dss_device *in, *dssdev;
195 pdata = dev_get_platdata(&pdev->dev);
197 in = omap_dss_find_output(pdata->source);
198 if (in == NULL) {
199 dev_err(&pdev->dev, "Failed to find video source\n");
200 return -EPROBE_DEFER;
203 ddata->in = in;
205 ddata->invert_polarity = pdata->invert_polarity;
207 dssdev = &ddata->dssdev;
208 dssdev->name = pdata->name;
210 return 0;
213 static int tvc_probe_of(struct platform_device *pdev)
215 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
216 struct device_node *node = pdev->dev.of_node;
217 struct omap_dss_device *in;
219 in = omapdss_of_find_source_for_first_ep(node);
220 if (IS_ERR(in)) {
221 dev_err(&pdev->dev, "failed to find video source\n");
222 return PTR_ERR(in);
225 ddata->in = in;
227 return 0;
230 static int tvc_probe(struct platform_device *pdev)
232 struct panel_drv_data *ddata;
233 struct omap_dss_device *dssdev;
234 int r;
236 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
237 if (!ddata)
238 return -ENOMEM;
240 platform_set_drvdata(pdev, ddata);
241 ddata->dev = &pdev->dev;
243 if (dev_get_platdata(&pdev->dev)) {
244 r = tvc_probe_pdata(pdev);
245 if (r)
246 return r;
247 } else if (pdev->dev.of_node) {
248 r = tvc_probe_of(pdev);
249 if (r)
250 return r;
251 } else {
252 return -ENODEV;
255 ddata->timings = tvc_pal_timings;
257 dssdev = &ddata->dssdev;
258 dssdev->driver = &tvc_driver;
259 dssdev->dev = &pdev->dev;
260 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
261 dssdev->owner = THIS_MODULE;
262 dssdev->panel.timings = tvc_pal_timings;
264 r = omapdss_register_display(dssdev);
265 if (r) {
266 dev_err(&pdev->dev, "Failed to register panel\n");
267 goto err_reg;
270 return 0;
271 err_reg:
272 omap_dss_put_device(ddata->in);
273 return r;
276 static int __exit tvc_remove(struct platform_device *pdev)
278 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
279 struct omap_dss_device *dssdev = &ddata->dssdev;
280 struct omap_dss_device *in = ddata->in;
282 omapdss_unregister_display(&ddata->dssdev);
284 tvc_disable(dssdev);
285 tvc_disconnect(dssdev);
287 omap_dss_put_device(in);
289 return 0;
292 static const struct of_device_id tvc_of_match[] = {
293 { .compatible = "omapdss,svideo-connector", },
294 { .compatible = "omapdss,composite-video-connector", },
298 MODULE_DEVICE_TABLE(of, tvc_of_match);
300 static struct platform_driver tvc_connector_driver = {
301 .probe = tvc_probe,
302 .remove = __exit_p(tvc_remove),
303 .driver = {
304 .name = "connector-analog-tv",
305 .of_match_table = tvc_of_match,
306 .suppress_bind_attrs = true,
310 module_platform_driver(tvc_connector_driver);
312 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
313 MODULE_DESCRIPTION("Analog TV Connector driver");
314 MODULE_LICENSE("GPL");