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>
16 #include <video/omapdss.h>
17 #include <video/omap-panel-data.h>
19 struct panel_drv_data
{
20 struct omap_dss_device dssdev
;
21 struct omap_dss_device
*in
;
25 struct omap_video_timings timings
;
27 enum omap_dss_venc_type connector_type
;
31 static const struct omap_video_timings tvc_pal_timings
= {
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
;
53 dev_dbg(ddata
->dev
, "connect\n");
55 if (omapdss_device_is_connected(dssdev
))
58 r
= in
->ops
.atv
->connect(in
, dssdev
);
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
))
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
;
84 dev_dbg(ddata
->dev
, "enable\n");
86 if (!omapdss_device_is_connected(dssdev
))
89 if (omapdss_device_is_enabled(dssdev
))
92 in
->ops
.atv
->set_timings(in
, &ddata
->timings
);
94 in
->ops
.atv
->set_type(in
, ddata
->connector_type
);
95 in
->ops
.atv
->invert_vid_out_polarity(in
, ddata
->invert_polarity
);
97 r
= in
->ops
.atv
->enable(in
);
101 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
106 static void tvc_disable(struct omap_dss_device
*dssdev
)
108 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
109 struct omap_dss_device
*in
= ddata
->in
;
111 dev_dbg(ddata
->dev
, "disable\n");
113 if (!omapdss_device_is_enabled(dssdev
))
116 in
->ops
.atv
->disable(in
);
118 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
121 static void tvc_set_timings(struct omap_dss_device
*dssdev
,
122 struct omap_video_timings
*timings
)
124 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
125 struct omap_dss_device
*in
= ddata
->in
;
127 ddata
->timings
= *timings
;
128 dssdev
->panel
.timings
= *timings
;
130 in
->ops
.atv
->set_timings(in
, timings
);
133 static void tvc_get_timings(struct omap_dss_device
*dssdev
,
134 struct omap_video_timings
*timings
)
136 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
138 *timings
= ddata
->timings
;
141 static int tvc_check_timings(struct omap_dss_device
*dssdev
,
142 struct omap_video_timings
*timings
)
144 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
145 struct omap_dss_device
*in
= ddata
->in
;
147 return in
->ops
.atv
->check_timings(in
, timings
);
150 static u32
tvc_get_wss(struct omap_dss_device
*dssdev
)
152 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
153 struct omap_dss_device
*in
= ddata
->in
;
155 return in
->ops
.atv
->get_wss(in
);
158 static int tvc_set_wss(struct omap_dss_device
*dssdev
, u32 wss
)
160 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
161 struct omap_dss_device
*in
= ddata
->in
;
163 return in
->ops
.atv
->set_wss(in
, wss
);
166 static struct omap_dss_driver tvc_driver
= {
167 .connect
= tvc_connect
,
168 .disconnect
= tvc_disconnect
,
170 .enable
= tvc_enable
,
171 .disable
= tvc_disable
,
173 .set_timings
= tvc_set_timings
,
174 .get_timings
= tvc_get_timings
,
175 .check_timings
= tvc_check_timings
,
177 .get_resolution
= omapdss_default_get_resolution
,
179 .get_wss
= tvc_get_wss
,
180 .set_wss
= tvc_set_wss
,
183 static int tvc_probe_pdata(struct platform_device
*pdev
)
185 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
186 struct connector_atv_platform_data
*pdata
;
187 struct omap_dss_device
*in
, *dssdev
;
189 pdata
= dev_get_platdata(&pdev
->dev
);
191 in
= omap_dss_find_output(pdata
->source
);
193 dev_err(&pdev
->dev
, "Failed to find video source\n");
194 return -EPROBE_DEFER
;
199 ddata
->connector_type
= pdata
->connector_type
;
200 ddata
->invert_polarity
= ddata
->invert_polarity
;
202 dssdev
= &ddata
->dssdev
;
203 dssdev
->name
= pdata
->name
;
208 static int tvc_probe(struct platform_device
*pdev
)
210 struct panel_drv_data
*ddata
;
211 struct omap_dss_device
*dssdev
;
214 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
218 platform_set_drvdata(pdev
, ddata
);
219 ddata
->dev
= &pdev
->dev
;
221 if (dev_get_platdata(&pdev
->dev
)) {
222 r
= tvc_probe_pdata(pdev
);
229 ddata
->timings
= tvc_pal_timings
;
231 dssdev
= &ddata
->dssdev
;
232 dssdev
->driver
= &tvc_driver
;
233 dssdev
->dev
= &pdev
->dev
;
234 dssdev
->type
= OMAP_DISPLAY_TYPE_VENC
;
235 dssdev
->owner
= THIS_MODULE
;
236 dssdev
->panel
.timings
= tvc_pal_timings
;
238 r
= omapdss_register_display(dssdev
);
240 dev_err(&pdev
->dev
, "Failed to register panel\n");
246 omap_dss_put_device(ddata
->in
);
250 static int __exit
tvc_remove(struct platform_device
*pdev
)
252 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
253 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
254 struct omap_dss_device
*in
= ddata
->in
;
256 omapdss_unregister_display(&ddata
->dssdev
);
259 tvc_disconnect(dssdev
);
261 omap_dss_put_device(in
);
266 static struct platform_driver tvc_connector_driver
= {
268 .remove
= __exit_p(tvc_remove
),
270 .name
= "connector-analog-tv",
271 .owner
= THIS_MODULE
,
275 module_platform_driver(tvc_connector_driver
);
277 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
278 MODULE_DESCRIPTION("Analog TV Connector driver");
279 MODULE_LICENSE("GPL");