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>
15 #include <video/omap-panel-data.h>
17 struct panel_drv_data {
18 struct omap_dss_device dssdev;
19 struct omap_dss_device *in;
23 struct omap_video_timings timings;
28 static const struct omap_video_timings tvc_pal_timings = {
31 .pixelclock = 13500000,
42 static const struct of_device_id tvc_of_match[];
44 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
46 static int tvc_connect(struct omap_dss_device *dssdev)
48 struct panel_drv_data *ddata = to_panel_data(dssdev);
49 struct omap_dss_device *in = ddata->in;
52 dev_dbg(ddata->dev, "connect\n");
54 if (omapdss_device_is_connected(dssdev))
57 r = in->ops.atv->connect(in, dssdev);
64 static void tvc_disconnect(struct omap_dss_device *dssdev)
66 struct panel_drv_data *ddata = to_panel_data(dssdev);
67 struct omap_dss_device *in = ddata->in;
69 dev_dbg(ddata->dev, "disconnect\n");
71 if (!omapdss_device_is_connected(dssdev))
74 in->ops.atv->disconnect(in, dssdev);
77 static int tvc_enable(struct omap_dss_device *dssdev)
79 struct panel_drv_data *ddata = to_panel_data(dssdev);
80 struct omap_dss_device *in = ddata->in;
83 dev_dbg(ddata->dev, "enable\n");
85 if (!omapdss_device_is_connected(dssdev))
88 if (omapdss_device_is_enabled(dssdev))
91 in->ops.atv->set_timings(in, &ddata->timings);
93 if (!ddata->dev->of_node) {
94 in->ops.atv->set_type(in, OMAP_DSS_VENC_TYPE_COMPOSITE);
96 in->ops.atv->invert_vid_out_polarity(in,
97 ddata->invert_polarity);
100 r = in->ops.atv->enable(in);
104 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
109 static void tvc_disable(struct omap_dss_device *dssdev)
111 struct panel_drv_data *ddata = to_panel_data(dssdev);
112 struct omap_dss_device *in = ddata->in;
114 dev_dbg(ddata->dev, "disable\n");
116 if (!omapdss_device_is_enabled(dssdev))
119 in->ops.atv->disable(in);
121 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
124 static void tvc_set_timings(struct omap_dss_device *dssdev,
125 struct omap_video_timings *timings)
127 struct panel_drv_data *ddata = to_panel_data(dssdev);
128 struct omap_dss_device *in = ddata->in;
130 ddata->timings = *timings;
131 dssdev->panel.timings = *timings;
133 in->ops.atv->set_timings(in, timings);
136 static void tvc_get_timings(struct omap_dss_device *dssdev,
137 struct omap_video_timings *timings)
139 struct panel_drv_data *ddata = to_panel_data(dssdev);
141 *timings = ddata->timings;
144 static int tvc_check_timings(struct omap_dss_device *dssdev,
145 struct omap_video_timings *timings)
147 struct panel_drv_data *ddata = to_panel_data(dssdev);
148 struct omap_dss_device *in = ddata->in;
150 return in->ops.atv->check_timings(in, timings);
153 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
155 struct panel_drv_data *ddata = to_panel_data(dssdev);
156 struct omap_dss_device *in = ddata->in;
158 return in->ops.atv->get_wss(in);
161 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
163 struct panel_drv_data *ddata = to_panel_data(dssdev);
164 struct omap_dss_device *in = ddata->in;
166 return in->ops.atv->set_wss(in, wss);
169 static struct omap_dss_driver tvc_driver = {
170 .connect = tvc_connect,
171 .disconnect = tvc_disconnect,
173 .enable = tvc_enable,
174 .disable = tvc_disable,
176 .set_timings = tvc_set_timings,
177 .get_timings = tvc_get_timings,
178 .check_timings = tvc_check_timings,
180 .get_resolution = omapdss_default_get_resolution,
182 .get_wss = tvc_get_wss,
183 .set_wss = tvc_set_wss,
186 static int tvc_probe_pdata(struct platform_device *pdev)
188 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
189 struct connector_atv_platform_data *pdata;
190 struct omap_dss_device *in, *dssdev;
192 pdata = dev_get_platdata(&pdev->dev);
194 in = omap_dss_find_output(pdata->source);
196 dev_err(&pdev->dev, "Failed to find video source\n");
197 return -EPROBE_DEFER;
202 ddata->invert_polarity = pdata->invert_polarity;
204 dssdev = &ddata->dssdev;
205 dssdev->name = pdata->name;
210 static int tvc_probe_of(struct platform_device *pdev)
212 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
213 struct device_node *node = pdev->dev.of_node;
214 struct omap_dss_device *in;
216 in = omapdss_of_find_source_for_first_ep(node);
218 dev_err(&pdev->dev, "failed to find video source\n");
227 static int tvc_probe(struct platform_device *pdev)
229 struct panel_drv_data *ddata;
230 struct omap_dss_device *dssdev;
233 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
237 platform_set_drvdata(pdev, ddata);
238 ddata->dev = &pdev->dev;
240 if (dev_get_platdata(&pdev->dev)) {
241 r = tvc_probe_pdata(pdev);
244 } else if (pdev->dev.of_node) {
245 r = tvc_probe_of(pdev);
252 ddata->timings = tvc_pal_timings;
254 dssdev = &ddata->dssdev;
255 dssdev->driver = &tvc_driver;
256 dssdev->dev = &pdev->dev;
257 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
258 dssdev->owner = THIS_MODULE;
259 dssdev->panel.timings = tvc_pal_timings;
261 r = omapdss_register_display(dssdev);
263 dev_err(&pdev->dev, "Failed to register panel\n");
269 omap_dss_put_device(ddata->in);
273 static int __exit tvc_remove(struct platform_device *pdev)
275 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
276 struct omap_dss_device *dssdev = &ddata->dssdev;
277 struct omap_dss_device *in = ddata->in;
279 omapdss_unregister_display(&ddata->dssdev);
282 tvc_disconnect(dssdev);
284 omap_dss_put_device(in);
289 static const struct of_device_id tvc_of_match[] = {
290 { .compatible = "omapdss,svideo-connector", },
291 { .compatible = "omapdss,composite-video-connector", },
295 MODULE_DEVICE_TABLE(of, tvc_of_match);
297 static struct platform_driver tvc_connector_driver = {
299 .remove = __exit_p(tvc_remove),
301 .name = "connector-analog-tv",
302 .of_match_table = tvc_of_match,
303 .suppress_bind_attrs = true,
307 module_platform_driver(tvc_connector_driver);
309 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
310 MODULE_DESCRIPTION("Analog TV Connector driver");
311 MODULE_LICENSE("GPL");