1 // SPDX-License-Identifier: GPL-2.0-only
3 * Analog TV Connector driver
5 * Copyright (C) 2013 Texas Instruments
6 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
9 #include <linux/slab.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
14 #include <video/omapfb_dss.h>
16 struct panel_drv_data
{
17 struct omap_dss_device dssdev
;
18 struct omap_dss_device
*in
;
22 struct omap_video_timings timings
;
27 static const struct omap_video_timings tvc_pal_timings
= {
30 .pixelclock
= 13500000,
41 static const struct of_device_id tvc_of_match
[];
43 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
45 static int tvc_connect(struct omap_dss_device
*dssdev
)
47 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
48 struct omap_dss_device
*in
= ddata
->in
;
50 dev_dbg(ddata
->dev
, "connect\n");
52 if (omapdss_device_is_connected(dssdev
))
55 return in
->ops
.atv
->connect(in
, dssdev
);
58 static void tvc_disconnect(struct omap_dss_device
*dssdev
)
60 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
61 struct omap_dss_device
*in
= ddata
->in
;
63 dev_dbg(ddata
->dev
, "disconnect\n");
65 if (!omapdss_device_is_connected(dssdev
))
68 in
->ops
.atv
->disconnect(in
, dssdev
);
71 static int tvc_enable(struct omap_dss_device
*dssdev
)
73 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
74 struct omap_dss_device
*in
= ddata
->in
;
77 dev_dbg(ddata
->dev
, "enable\n");
79 if (!omapdss_device_is_connected(dssdev
))
82 if (omapdss_device_is_enabled(dssdev
))
85 in
->ops
.atv
->set_timings(in
, &ddata
->timings
);
87 if (!ddata
->dev
->of_node
) {
88 in
->ops
.atv
->set_type(in
, OMAP_DSS_VENC_TYPE_COMPOSITE
);
90 in
->ops
.atv
->invert_vid_out_polarity(in
,
91 ddata
->invert_polarity
);
94 r
= in
->ops
.atv
->enable(in
);
98 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
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
))
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 omap_video_timings
*timings
)
121 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
122 struct omap_dss_device
*in
= ddata
->in
;
124 ddata
->timings
= *timings
;
125 dssdev
->panel
.timings
= *timings
;
127 in
->ops
.atv
->set_timings(in
, timings
);
130 static void tvc_get_timings(struct omap_dss_device
*dssdev
,
131 struct omap_video_timings
*timings
)
133 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
135 *timings
= ddata
->timings
;
138 static int tvc_check_timings(struct omap_dss_device
*dssdev
,
139 struct omap_video_timings
*timings
)
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
, timings
);
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_resolution
= omapdss_default_get_resolution
,
176 .get_wss
= tvc_get_wss
,
177 .set_wss
= tvc_set_wss
,
180 static int tvc_probe(struct platform_device
*pdev
)
182 struct panel_drv_data
*ddata
;
183 struct omap_dss_device
*dssdev
;
186 if (!pdev
->dev
.of_node
)
189 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
193 platform_set_drvdata(pdev
, ddata
);
194 ddata
->dev
= &pdev
->dev
;
196 ddata
->in
= omapdss_of_find_source_for_first_ep(pdev
->dev
.of_node
);
197 r
= PTR_ERR_OR_ZERO(ddata
->in
);
199 dev_err(&pdev
->dev
, "failed to find video source\n");
203 ddata
->timings
= tvc_pal_timings
;
205 dssdev
= &ddata
->dssdev
;
206 dssdev
->driver
= &tvc_driver
;
207 dssdev
->dev
= &pdev
->dev
;
208 dssdev
->type
= OMAP_DISPLAY_TYPE_VENC
;
209 dssdev
->owner
= THIS_MODULE
;
210 dssdev
->panel
.timings
= tvc_pal_timings
;
212 r
= omapdss_register_display(dssdev
);
214 dev_err(&pdev
->dev
, "Failed to register panel\n");
220 omap_dss_put_device(ddata
->in
);
224 static void tvc_remove(struct platform_device
*pdev
)
226 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
227 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
228 struct omap_dss_device
*in
= ddata
->in
;
230 omapdss_unregister_display(&ddata
->dssdev
);
233 tvc_disconnect(dssdev
);
235 omap_dss_put_device(in
);
238 static const struct of_device_id tvc_of_match
[] = {
239 { .compatible
= "omapdss,svideo-connector", },
240 { .compatible
= "omapdss,composite-video-connector", },
244 MODULE_DEVICE_TABLE(of
, tvc_of_match
);
246 static struct platform_driver tvc_connector_driver
= {
248 .remove
= tvc_remove
,
250 .name
= "connector-analog-tv",
251 .of_match_table
= tvc_of_match
,
255 module_platform_driver(tvc_connector_driver
);
257 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
258 MODULE_DESCRIPTION("Analog TV Connector driver");
259 MODULE_LICENSE("GPL");