Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / gpu / drm / omapdrm / displays / connector-analog-tv.c
blob95ea6abae9142e99dc299ea1cff124a7d35c6d5b
1 /*
2 * Analog TV Connector driver
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
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 "../dss/omapdss.h"
19 struct panel_drv_data {
20 struct omap_dss_device dssdev;
21 struct omap_dss_device *in;
23 struct device *dev;
25 struct videomode vm;
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,
39 .flags = DISPLAY_FLAGS_INTERLACED | DISPLAY_FLAGS_HSYNC_LOW |
40 DISPLAY_FLAGS_VSYNC_LOW,
43 static const struct of_device_id tvc_of_match[];
45 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
47 static int tvc_connect(struct omap_dss_device *dssdev)
49 struct panel_drv_data *ddata = to_panel_data(dssdev);
50 struct omap_dss_device *in = ddata->in;
51 int r;
53 dev_dbg(ddata->dev, "connect\n");
55 if (omapdss_device_is_connected(dssdev))
56 return 0;
58 r = in->ops.atv->connect(in, dssdev);
59 if (r)
60 return r;
62 return 0;
65 static void tvc_disconnect(struct omap_dss_device *dssdev)
67 struct panel_drv_data *ddata = to_panel_data(dssdev);
68 struct omap_dss_device *in = ddata->in;
70 dev_dbg(ddata->dev, "disconnect\n");
72 if (!omapdss_device_is_connected(dssdev))
73 return;
75 in->ops.atv->disconnect(in, dssdev);
78 static int tvc_enable(struct omap_dss_device *dssdev)
80 struct panel_drv_data *ddata = to_panel_data(dssdev);
81 struct omap_dss_device *in = ddata->in;
82 int r;
84 dev_dbg(ddata->dev, "enable\n");
86 if (!omapdss_device_is_connected(dssdev))
87 return -ENODEV;
89 if (omapdss_device_is_enabled(dssdev))
90 return 0;
92 in->ops.atv->set_timings(in, &ddata->vm);
94 r = in->ops.atv->enable(in);
95 if (r)
96 return r;
98 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
100 return r;
103 static void tvc_disable(struct omap_dss_device *dssdev)
105 struct panel_drv_data *ddata = to_panel_data(dssdev);
106 struct omap_dss_device *in = ddata->in;
108 dev_dbg(ddata->dev, "disable\n");
110 if (!omapdss_device_is_enabled(dssdev))
111 return;
113 in->ops.atv->disable(in);
115 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
118 static void tvc_set_timings(struct omap_dss_device *dssdev,
119 struct videomode *vm)
121 struct panel_drv_data *ddata = to_panel_data(dssdev);
122 struct omap_dss_device *in = ddata->in;
124 ddata->vm = *vm;
125 dssdev->panel.vm = *vm;
127 in->ops.atv->set_timings(in, vm);
130 static void tvc_get_timings(struct omap_dss_device *dssdev,
131 struct videomode *vm)
133 struct panel_drv_data *ddata = to_panel_data(dssdev);
135 *vm = ddata->vm;
138 static int tvc_check_timings(struct omap_dss_device *dssdev,
139 struct videomode *vm)
141 struct panel_drv_data *ddata = to_panel_data(dssdev);
142 struct omap_dss_device *in = ddata->in;
144 return in->ops.atv->check_timings(in, vm);
147 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
149 struct panel_drv_data *ddata = to_panel_data(dssdev);
150 struct omap_dss_device *in = ddata->in;
152 return in->ops.atv->get_wss(in);
155 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
157 struct panel_drv_data *ddata = to_panel_data(dssdev);
158 struct omap_dss_device *in = ddata->in;
160 return in->ops.atv->set_wss(in, wss);
163 static struct omap_dss_driver tvc_driver = {
164 .connect = tvc_connect,
165 .disconnect = tvc_disconnect,
167 .enable = tvc_enable,
168 .disable = tvc_disable,
170 .set_timings = tvc_set_timings,
171 .get_timings = tvc_get_timings,
172 .check_timings = tvc_check_timings,
174 .get_wss = tvc_get_wss,
175 .set_wss = tvc_set_wss,
178 static int tvc_probe_of(struct platform_device *pdev)
180 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
181 struct device_node *node = pdev->dev.of_node;
182 struct omap_dss_device *in;
184 in = omapdss_of_find_source_for_first_ep(node);
185 if (IS_ERR(in)) {
186 dev_err(&pdev->dev, "failed to find video source\n");
187 return PTR_ERR(in);
190 ddata->in = in;
192 return 0;
195 static int tvc_probe(struct platform_device *pdev)
197 struct panel_drv_data *ddata;
198 struct omap_dss_device *dssdev;
199 int r;
201 if (!pdev->dev.of_node)
202 return -ENODEV;
204 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
205 if (!ddata)
206 return -ENOMEM;
208 platform_set_drvdata(pdev, ddata);
209 ddata->dev = &pdev->dev;
211 r = tvc_probe_of(pdev);
212 if (r)
213 return r;
215 ddata->vm = tvc_pal_vm;
217 dssdev = &ddata->dssdev;
218 dssdev->driver = &tvc_driver;
219 dssdev->dev = &pdev->dev;
220 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
221 dssdev->owner = THIS_MODULE;
222 dssdev->panel.vm = tvc_pal_vm;
224 r = omapdss_register_display(dssdev);
225 if (r) {
226 dev_err(&pdev->dev, "Failed to register panel\n");
227 goto err_reg;
230 return 0;
231 err_reg:
232 omap_dss_put_device(ddata->in);
233 return r;
236 static int __exit tvc_remove(struct platform_device *pdev)
238 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
239 struct omap_dss_device *dssdev = &ddata->dssdev;
240 struct omap_dss_device *in = ddata->in;
242 omapdss_unregister_display(&ddata->dssdev);
244 tvc_disable(dssdev);
245 tvc_disconnect(dssdev);
247 omap_dss_put_device(in);
249 return 0;
252 static const struct of_device_id tvc_of_match[] = {
253 { .compatible = "omapdss,svideo-connector", },
254 { .compatible = "omapdss,composite-video-connector", },
258 MODULE_DEVICE_TABLE(of, tvc_of_match);
260 static struct platform_driver tvc_connector_driver = {
261 .probe = tvc_probe,
262 .remove = __exit_p(tvc_remove),
263 .driver = {
264 .name = "connector-analog-tv",
265 .of_match_table = tvc_of_match,
266 .suppress_bind_attrs = true,
270 module_platform_driver(tvc_connector_driver);
272 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
273 MODULE_DESCRIPTION("Analog TV Connector driver");
274 MODULE_LICENSE("GPL");