Input: xpad - add support for Xbox1 PDP Camo series gamepad
[linux/fpc-iii.git] / drivers / gpu / drm / omapdrm / displays / connector-analog-tv.c
blob3485d1ecd6557e271443920804e09f21230af33d
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/omap-panel-data.h>
19 #include "../dss/omapdss.h"
21 struct panel_drv_data {
22 struct omap_dss_device dssdev;
23 struct omap_dss_device *in;
25 struct device *dev;
27 struct omap_video_timings timings;
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 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
50 static int tvc_connect(struct omap_dss_device *dssdev)
52 struct panel_drv_data *ddata = to_panel_data(dssdev);
53 struct omap_dss_device *in = ddata->in;
54 int r;
56 dev_dbg(ddata->dev, "connect\n");
58 if (omapdss_device_is_connected(dssdev))
59 return 0;
61 r = in->ops.atv->connect(in, dssdev);
62 if (r)
63 return r;
65 return 0;
68 static void tvc_disconnect(struct omap_dss_device *dssdev)
70 struct panel_drv_data *ddata = to_panel_data(dssdev);
71 struct omap_dss_device *in = ddata->in;
73 dev_dbg(ddata->dev, "disconnect\n");
75 if (!omapdss_device_is_connected(dssdev))
76 return;
78 in->ops.atv->disconnect(in, dssdev);
81 static int tvc_enable(struct omap_dss_device *dssdev)
83 struct panel_drv_data *ddata = to_panel_data(dssdev);
84 struct omap_dss_device *in = ddata->in;
85 int r;
87 dev_dbg(ddata->dev, "enable\n");
89 if (!omapdss_device_is_connected(dssdev))
90 return -ENODEV;
92 if (omapdss_device_is_enabled(dssdev))
93 return 0;
95 in->ops.atv->set_timings(in, &ddata->timings);
97 if (!ddata->dev->of_node) {
98 in->ops.atv->set_type(in, OMAP_DSS_VENC_TYPE_COMPOSITE);
100 in->ops.atv->invert_vid_out_polarity(in,
101 ddata->invert_polarity);
104 r = in->ops.atv->enable(in);
105 if (r)
106 return r;
108 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
110 return r;
113 static void tvc_disable(struct omap_dss_device *dssdev)
115 struct panel_drv_data *ddata = to_panel_data(dssdev);
116 struct omap_dss_device *in = ddata->in;
118 dev_dbg(ddata->dev, "disable\n");
120 if (!omapdss_device_is_enabled(dssdev))
121 return;
123 in->ops.atv->disable(in);
125 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
128 static void tvc_set_timings(struct omap_dss_device *dssdev,
129 struct omap_video_timings *timings)
131 struct panel_drv_data *ddata = to_panel_data(dssdev);
132 struct omap_dss_device *in = ddata->in;
134 ddata->timings = *timings;
135 dssdev->panel.timings = *timings;
137 in->ops.atv->set_timings(in, timings);
140 static void tvc_get_timings(struct omap_dss_device *dssdev,
141 struct omap_video_timings *timings)
143 struct panel_drv_data *ddata = to_panel_data(dssdev);
145 *timings = ddata->timings;
148 static int tvc_check_timings(struct omap_dss_device *dssdev,
149 struct omap_video_timings *timings)
151 struct panel_drv_data *ddata = to_panel_data(dssdev);
152 struct omap_dss_device *in = ddata->in;
154 return in->ops.atv->check_timings(in, timings);
157 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
159 struct panel_drv_data *ddata = to_panel_data(dssdev);
160 struct omap_dss_device *in = ddata->in;
162 return in->ops.atv->get_wss(in);
165 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
167 struct panel_drv_data *ddata = to_panel_data(dssdev);
168 struct omap_dss_device *in = ddata->in;
170 return in->ops.atv->set_wss(in, wss);
173 static struct omap_dss_driver tvc_driver = {
174 .connect = tvc_connect,
175 .disconnect = tvc_disconnect,
177 .enable = tvc_enable,
178 .disable = tvc_disable,
180 .set_timings = tvc_set_timings,
181 .get_timings = tvc_get_timings,
182 .check_timings = tvc_check_timings,
184 .get_resolution = omapdss_default_get_resolution,
186 .get_wss = tvc_get_wss,
187 .set_wss = tvc_set_wss,
190 static int tvc_probe_pdata(struct platform_device *pdev)
192 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
193 struct connector_atv_platform_data *pdata;
194 struct omap_dss_device *in, *dssdev;
196 pdata = dev_get_platdata(&pdev->dev);
198 in = omap_dss_find_output(pdata->source);
199 if (in == NULL) {
200 dev_err(&pdev->dev, "Failed to find video source\n");
201 return -EPROBE_DEFER;
204 ddata->in = in;
206 ddata->invert_polarity = pdata->invert_polarity;
208 dssdev = &ddata->dssdev;
209 dssdev->name = pdata->name;
211 return 0;
214 static int tvc_probe_of(struct platform_device *pdev)
216 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
217 struct device_node *node = pdev->dev.of_node;
218 struct omap_dss_device *in;
220 in = omapdss_of_find_source_for_first_ep(node);
221 if (IS_ERR(in)) {
222 dev_err(&pdev->dev, "failed to find video source\n");
223 return PTR_ERR(in);
226 ddata->in = in;
228 return 0;
231 static int tvc_probe(struct platform_device *pdev)
233 struct panel_drv_data *ddata;
234 struct omap_dss_device *dssdev;
235 int r;
237 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
238 if (!ddata)
239 return -ENOMEM;
241 platform_set_drvdata(pdev, ddata);
242 ddata->dev = &pdev->dev;
244 if (dev_get_platdata(&pdev->dev)) {
245 r = tvc_probe_pdata(pdev);
246 if (r)
247 return r;
248 } else if (pdev->dev.of_node) {
249 r = tvc_probe_of(pdev);
250 if (r)
251 return r;
252 } else {
253 return -ENODEV;
256 ddata->timings = tvc_pal_timings;
258 dssdev = &ddata->dssdev;
259 dssdev->driver = &tvc_driver;
260 dssdev->dev = &pdev->dev;
261 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
262 dssdev->owner = THIS_MODULE;
263 dssdev->panel.timings = tvc_pal_timings;
265 r = omapdss_register_display(dssdev);
266 if (r) {
267 dev_err(&pdev->dev, "Failed to register panel\n");
268 goto err_reg;
271 return 0;
272 err_reg:
273 omap_dss_put_device(ddata->in);
274 return r;
277 static int __exit tvc_remove(struct platform_device *pdev)
279 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
280 struct omap_dss_device *dssdev = &ddata->dssdev;
281 struct omap_dss_device *in = ddata->in;
283 omapdss_unregister_display(&ddata->dssdev);
285 tvc_disable(dssdev);
286 tvc_disconnect(dssdev);
288 omap_dss_put_device(in);
290 return 0;
293 static const struct of_device_id tvc_of_match[] = {
294 { .compatible = "omapdss,svideo-connector", },
295 { .compatible = "omapdss,composite-video-connector", },
299 MODULE_DEVICE_TABLE(of, tvc_of_match);
301 static struct platform_driver tvc_connector_driver = {
302 .probe = tvc_probe,
303 .remove = __exit_p(tvc_remove),
304 .driver = {
305 .name = "connector-analog-tv",
306 .of_match_table = tvc_of_match,
307 .suppress_bind_attrs = true,
311 module_platform_driver(tvc_connector_driver);
313 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
314 MODULE_DESCRIPTION("Analog TV Connector driver");
315 MODULE_LICENSE("GPL");