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 "../dss/omapdss.h"
19 struct panel_drv_data {
20 struct omap_dss_device dssdev;
21 struct omap_dss_device *in;
28 static const struct videomode tvc_pal_vm = {
31 .pixelclock = 13500000,
39 .flags = DISPLAY_FLAGS_INTERLACED | DISPLAY_FLAGS_HSYNC_LOW |
40 DISPLAY_FLAGS_VSYNC_LOW,
43 static const struct of_device_id tvc_of_match[];
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->vm);
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 videomode *vm)
121 struct panel_drv_data *ddata = to_panel_data(dssdev);
122 struct omap_dss_device *in = ddata->in;
125 dssdev->panel.vm = *vm;
127 in->ops.atv->set_timings(in, vm);
130 static void tvc_get_timings(struct omap_dss_device *dssdev,
131 struct videomode *vm)
133 struct panel_drv_data *ddata = to_panel_data(dssdev);
138 static int tvc_check_timings(struct omap_dss_device *dssdev,
139 struct videomode *vm)
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, vm);
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_wss = tvc_get_wss,
175 .set_wss = tvc_set_wss,
178 static int tvc_probe_of(struct platform_device *pdev)
180 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
181 struct device_node *node = pdev->dev.of_node;
182 struct omap_dss_device *in;
184 in = omapdss_of_find_source_for_first_ep(node);
186 dev_err(&pdev->dev, "failed to find video source\n");
195 static int tvc_probe(struct platform_device *pdev)
197 struct panel_drv_data *ddata;
198 struct omap_dss_device *dssdev;
201 if (!pdev->dev.of_node)
204 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
208 platform_set_drvdata(pdev, ddata);
209 ddata->dev = &pdev->dev;
211 r = tvc_probe_of(pdev);
215 ddata->vm = tvc_pal_vm;
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.vm = tvc_pal_vm;
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 const struct of_device_id tvc_of_match[] = {
253 { .compatible = "omapdss,svideo-connector", },
254 { .compatible = "omapdss,composite-video-connector", },
258 MODULE_DEVICE_TABLE(of, tvc_of_match);
260 static struct platform_driver tvc_connector_driver = {
262 .remove = __exit_p(tvc_remove),
264 .name = "connector-analog-tv",
265 .of_match_table = tvc_of_match,
266 .suppress_bind_attrs = true,
270 module_platform_driver(tvc_connector_driver);
272 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
273 MODULE_DESCRIPTION("Analog TV Connector driver");
274 MODULE_LICENSE("GPL");