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>
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
;
26 struct omap_video_timings timings
;
31 static const struct omap_video_timings tvc_pal_timings
= {
34 .pixelclock
= 13500000,
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
;
55 dev_dbg(ddata
->dev
, "connect\n");
57 if (omapdss_device_is_connected(dssdev
))
60 r
= in
->ops
.atv
->connect(in
, dssdev
);
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
))
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
;
86 dev_dbg(ddata
->dev
, "enable\n");
88 if (!omapdss_device_is_connected(dssdev
))
91 if (omapdss_device_is_enabled(dssdev
))
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
);
107 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
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
))
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
);
199 dev_err(&pdev
->dev
, "Failed to find video source\n");
200 return -EPROBE_DEFER
;
205 ddata
->invert_polarity
= pdata
->invert_polarity
;
207 dssdev
= &ddata
->dssdev
;
208 dssdev
->name
= pdata
->name
;
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
);
221 dev_err(&pdev
->dev
, "failed to find video source\n");
230 static int tvc_probe(struct platform_device
*pdev
)
232 struct panel_drv_data
*ddata
;
233 struct omap_dss_device
*dssdev
;
236 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
240 platform_set_drvdata(pdev
, ddata
);
241 ddata
->dev
= &pdev
->dev
;
243 if (dev_get_platdata(&pdev
->dev
)) {
244 r
= tvc_probe_pdata(pdev
);
247 } else if (pdev
->dev
.of_node
) {
248 r
= tvc_probe_of(pdev
);
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
);
266 dev_err(&pdev
->dev
, "Failed to register panel\n");
272 omap_dss_put_device(ddata
->in
);
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
);
285 tvc_disconnect(dssdev
);
287 omap_dss_put_device(in
);
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
= {
302 .remove
= __exit_p(tvc_remove
),
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");