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 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
33 static int tvc_connect(struct omap_dss_device
*dssdev
)
35 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
36 struct omap_dss_device
*in
= ddata
->in
;
39 dev_dbg(ddata
->dev
, "connect\n");
41 if (omapdss_device_is_connected(dssdev
))
44 r
= in
->ops
.atv
->connect(in
, dssdev
);
51 static void tvc_disconnect(struct omap_dss_device
*dssdev
)
53 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
54 struct omap_dss_device
*in
= ddata
->in
;
56 dev_dbg(ddata
->dev
, "disconnect\n");
58 if (!omapdss_device_is_connected(dssdev
))
61 in
->ops
.atv
->disconnect(in
, dssdev
);
64 static int tvc_enable(struct omap_dss_device
*dssdev
)
66 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
67 struct omap_dss_device
*in
= ddata
->in
;
70 dev_dbg(ddata
->dev
, "enable\n");
72 if (!omapdss_device_is_connected(dssdev
))
75 if (omapdss_device_is_enabled(dssdev
))
78 in
->ops
.atv
->set_timings(in
, &ddata
->timings
);
80 in
->ops
.atv
->set_type(in
, ddata
->connector_type
);
81 in
->ops
.atv
->invert_vid_out_polarity(in
, ddata
->invert_polarity
);
83 r
= in
->ops
.atv
->enable(in
);
87 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
92 static void tvc_disable(struct omap_dss_device
*dssdev
)
94 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
95 struct omap_dss_device
*in
= ddata
->in
;
97 dev_dbg(ddata
->dev
, "disable\n");
99 if (!omapdss_device_is_enabled(dssdev
))
102 in
->ops
.atv
->disable(in
);
104 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
107 static void tvc_set_timings(struct omap_dss_device
*dssdev
,
108 struct omap_video_timings
*timings
)
110 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
111 struct omap_dss_device
*in
= ddata
->in
;
113 ddata
->timings
= *timings
;
114 dssdev
->panel
.timings
= *timings
;
116 in
->ops
.atv
->set_timings(in
, timings
);
119 static void tvc_get_timings(struct omap_dss_device
*dssdev
,
120 struct omap_video_timings
*timings
)
122 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
124 *timings
= ddata
->timings
;
127 static int tvc_check_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 return in
->ops
.atv
->check_timings(in
, timings
);
136 static u32
tvc_get_wss(struct omap_dss_device
*dssdev
)
138 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
139 struct omap_dss_device
*in
= ddata
->in
;
141 return in
->ops
.atv
->get_wss(in
);
144 static int tvc_set_wss(struct omap_dss_device
*dssdev
, u32 wss
)
146 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
147 struct omap_dss_device
*in
= ddata
->in
;
149 return in
->ops
.atv
->set_wss(in
, wss
);
152 static struct omap_dss_driver tvc_driver
= {
153 .connect
= tvc_connect
,
154 .disconnect
= tvc_disconnect
,
156 .enable
= tvc_enable
,
157 .disable
= tvc_disable
,
159 .set_timings
= tvc_set_timings
,
160 .get_timings
= tvc_get_timings
,
161 .check_timings
= tvc_check_timings
,
163 .get_resolution
= omapdss_default_get_resolution
,
165 .get_wss
= tvc_get_wss
,
166 .set_wss
= tvc_set_wss
,
169 static int tvc_probe_pdata(struct platform_device
*pdev
)
171 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
172 struct connector_atv_platform_data
*pdata
;
173 struct omap_dss_device
*in
, *dssdev
;
175 pdata
= dev_get_platdata(&pdev
->dev
);
177 in
= omap_dss_find_output(pdata
->source
);
179 dev_err(&pdev
->dev
, "Failed to find video source\n");
185 ddata
->connector_type
= pdata
->connector_type
;
186 ddata
->invert_polarity
= ddata
->invert_polarity
;
188 dssdev
= &ddata
->dssdev
;
189 dssdev
->name
= pdata
->name
;
194 static int tvc_probe(struct platform_device
*pdev
)
196 struct panel_drv_data
*ddata
;
197 struct omap_dss_device
*dssdev
;
200 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
204 platform_set_drvdata(pdev
, ddata
);
205 ddata
->dev
= &pdev
->dev
;
207 if (dev_get_platdata(&pdev
->dev
)) {
208 r
= tvc_probe_pdata(pdev
);
215 ddata
->timings
= omap_dss_pal_timings
;
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
.timings
= omap_dss_pal_timings
;
224 r
= omapdss_register_display(dssdev
);
226 dev_err(&pdev
->dev
, "Failed to register panel\n");
232 omap_dss_put_device(ddata
->in
);
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
);
245 tvc_disconnect(dssdev
);
247 omap_dss_put_device(in
);
252 static struct platform_driver tvc_connector_driver
= {
254 .remove
= __exit_p(tvc_remove
),
256 .name
= "connector-analog-tv",
257 .owner
= THIS_MODULE
,
261 module_platform_driver(tvc_connector_driver
);
263 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
264 MODULE_DESCRIPTION("Analog TV Connector driver");
265 MODULE_LICENSE("GPL");