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/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
;
27 struct omap_video_timings timings
;
32 static const struct omap_video_timings tvc_pal_timings
= {
35 .pixelclock
= 13500000,
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
;
56 dev_dbg(ddata
->dev
, "connect\n");
58 if (omapdss_device_is_connected(dssdev
))
61 r
= in
->ops
.atv
->connect(in
, dssdev
);
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
))
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
;
87 dev_dbg(ddata
->dev
, "enable\n");
89 if (!omapdss_device_is_connected(dssdev
))
92 if (omapdss_device_is_enabled(dssdev
))
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
);
108 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
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
))
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
);
200 dev_err(&pdev
->dev
, "Failed to find video source\n");
201 return -EPROBE_DEFER
;
206 ddata
->invert_polarity
= pdata
->invert_polarity
;
208 dssdev
= &ddata
->dssdev
;
209 dssdev
->name
= pdata
->name
;
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
);
222 dev_err(&pdev
->dev
, "failed to find video source\n");
231 static int tvc_probe(struct platform_device
*pdev
)
233 struct panel_drv_data
*ddata
;
234 struct omap_dss_device
*dssdev
;
237 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
241 platform_set_drvdata(pdev
, ddata
);
242 ddata
->dev
= &pdev
->dev
;
244 if (dev_get_platdata(&pdev
->dev
)) {
245 r
= tvc_probe_pdata(pdev
);
248 } else if (pdev
->dev
.of_node
) {
249 r
= tvc_probe_of(pdev
);
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
);
267 dev_err(&pdev
->dev
, "Failed to register panel\n");
273 omap_dss_put_device(ddata
->in
);
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
);
286 tvc_disconnect(dssdev
);
288 omap_dss_put_device(in
);
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
= {
303 .remove
= __exit_p(tvc_remove
),
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");