blob: e1fa143a5625b228a833e79e8b0042b421c5f7f1 [file] [log] [blame]
Tomi Valkeinen61a7f242013-05-24 14:21:30 +03001/*
2 * Analog TV Connector driver
3 *
4 * Copyright (C) 2013 Texas Instruments
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
6 *
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.
10 */
11
12#include <linux/slab.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
Tomi Valkeinenfcc900a2013-05-29 15:34:06 +030015#include <linux/of.h>
Tomi Valkeinen61a7f242013-05-24 14:21:30 +030016
Peter Ujfalusi32043da2016-05-27 14:40:49 +030017#include "../dss/omapdss.h"
18
Tomi Valkeinen61a7f242013-05-24 14:21:30 +030019struct panel_drv_data {
20 struct omap_dss_device dssdev;
21 struct omap_dss_device *in;
22
23 struct device *dev;
24
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030025 struct videomode vm;
Tomi Valkeinen61a7f242013-05-24 14:21:30 +030026};
27
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030028static const struct videomode tvc_pal_vm = {
Peter Ujfalusi81899062016-09-22 14:06:46 +030029 .hactive = 720,
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +030030 .vactive = 574,
Tomi Valkeinend8d789412013-04-10 14:12:14 +030031 .pixelclock = 13500000,
Peter Ujfalusi4dc22502016-09-22 14:06:48 +030032 .hsync_len = 64,
Peter Ujfalusi0a30e152016-09-22 14:06:49 +030033 .hfront_porch = 12,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +030034 .hback_porch = 68,
Peter Ujfalusid5bcf0a2016-09-22 14:06:51 +030035 .vsync_len = 5,
Peter Ujfalusi0996c682016-09-22 14:06:52 +030036 .vfront_porch = 5,
Peter Ujfalusi458540c2016-09-22 14:06:53 +030037 .vback_porch = 41,
Tomi Valkeinen005358c2013-08-02 10:15:01 +030038
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +030039 .flags = DISPLAY_FLAGS_INTERLACED | DISPLAY_FLAGS_HSYNC_LOW |
40 DISPLAY_FLAGS_VSYNC_LOW,
Tomi Valkeinen005358c2013-08-02 10:15:01 +030041};
42
Tomi Valkeinenfcc900a2013-05-29 15:34:06 +030043static const struct of_device_id tvc_of_match[];
44
Tomi Valkeinen61a7f242013-05-24 14:21:30 +030045#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
46
47static int tvc_connect(struct omap_dss_device *dssdev)
48{
49 struct panel_drv_data *ddata = to_panel_data(dssdev);
50 struct omap_dss_device *in = ddata->in;
51 int r;
52
53 dev_dbg(ddata->dev, "connect\n");
54
55 if (omapdss_device_is_connected(dssdev))
56 return 0;
57
58 r = in->ops.atv->connect(in, dssdev);
59 if (r)
60 return r;
61
62 return 0;
63}
64
65static void tvc_disconnect(struct omap_dss_device *dssdev)
66{
67 struct panel_drv_data *ddata = to_panel_data(dssdev);
68 struct omap_dss_device *in = ddata->in;
69
70 dev_dbg(ddata->dev, "disconnect\n");
71
72 if (!omapdss_device_is_connected(dssdev))
73 return;
74
75 in->ops.atv->disconnect(in, dssdev);
76}
77
78static int tvc_enable(struct omap_dss_device *dssdev)
79{
80 struct panel_drv_data *ddata = to_panel_data(dssdev);
81 struct omap_dss_device *in = ddata->in;
82 int r;
83
84 dev_dbg(ddata->dev, "enable\n");
85
86 if (!omapdss_device_is_connected(dssdev))
87 return -ENODEV;
88
89 if (omapdss_device_is_enabled(dssdev))
90 return 0;
91
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030092 in->ops.atv->set_timings(in, &ddata->vm);
Tomi Valkeinen61a7f242013-05-24 14:21:30 +030093
Tomi Valkeinen61a7f242013-05-24 14:21:30 +030094 r = in->ops.atv->enable(in);
95 if (r)
96 return r;
97
98 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
99
100 return r;
101}
102
103static void tvc_disable(struct omap_dss_device *dssdev)
104{
105 struct panel_drv_data *ddata = to_panel_data(dssdev);
106 struct omap_dss_device *in = ddata->in;
107
108 dev_dbg(ddata->dev, "disable\n");
109
110 if (!omapdss_device_is_enabled(dssdev))
111 return;
112
113 in->ops.atv->disable(in);
114
115 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
116}
117
118static void tvc_set_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300119 struct videomode *vm)
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300120{
121 struct panel_drv_data *ddata = to_panel_data(dssdev);
122 struct omap_dss_device *in = ddata->in;
123
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300124 ddata->vm = *vm;
125 dssdev->panel.vm = *vm;
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300126
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300127 in->ops.atv->set_timings(in, vm);
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300128}
129
130static void tvc_get_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300131 struct videomode *vm)
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300132{
133 struct panel_drv_data *ddata = to_panel_data(dssdev);
134
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300135 *vm = ddata->vm;
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300136}
137
138static int tvc_check_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300139 struct videomode *vm)
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300140{
141 struct panel_drv_data *ddata = to_panel_data(dssdev);
142 struct omap_dss_device *in = ddata->in;
143
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300144 return in->ops.atv->check_timings(in, vm);
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300145}
146
147static u32 tvc_get_wss(struct omap_dss_device *dssdev)
148{
149 struct panel_drv_data *ddata = to_panel_data(dssdev);
150 struct omap_dss_device *in = ddata->in;
151
152 return in->ops.atv->get_wss(in);
153}
154
155static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
156{
157 struct panel_drv_data *ddata = to_panel_data(dssdev);
158 struct omap_dss_device *in = ddata->in;
159
160 return in->ops.atv->set_wss(in, wss);
161}
162
163static struct omap_dss_driver tvc_driver = {
164 .connect = tvc_connect,
165 .disconnect = tvc_disconnect,
166
167 .enable = tvc_enable,
168 .disable = tvc_disable,
169
170 .set_timings = tvc_set_timings,
171 .get_timings = tvc_get_timings,
172 .check_timings = tvc_check_timings,
173
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300174 .get_wss = tvc_get_wss,
175 .set_wss = tvc_set_wss,
176};
177
Tomi Valkeinenfcc900a2013-05-29 15:34:06 +0300178static int tvc_probe_of(struct platform_device *pdev)
179{
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;
183
184 in = omapdss_of_find_source_for_first_ep(node);
185 if (IS_ERR(in)) {
186 dev_err(&pdev->dev, "failed to find video source\n");
187 return PTR_ERR(in);
188 }
189
190 ddata->in = in;
191
192 return 0;
193}
194
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300195static int tvc_probe(struct platform_device *pdev)
196{
197 struct panel_drv_data *ddata;
198 struct omap_dss_device *dssdev;
199 int r;
200
201 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
202 if (!ddata)
203 return -ENOMEM;
204
205 platform_set_drvdata(pdev, ddata);
206 ddata->dev = &pdev->dev;
207
Tomi Valkeinen11b23e12017-05-12 12:36:48 +0300208 r = tvc_probe_of(pdev);
209 if (r)
210 return r;
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300211
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300212 ddata->vm = tvc_pal_vm;
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300213
214 dssdev = &ddata->dssdev;
215 dssdev->driver = &tvc_driver;
216 dssdev->dev = &pdev->dev;
217 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
218 dssdev->owner = THIS_MODULE;
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +0300219 dssdev->panel.vm = tvc_pal_vm;
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300220
221 r = omapdss_register_display(dssdev);
222 if (r) {
223 dev_err(&pdev->dev, "Failed to register panel\n");
224 goto err_reg;
225 }
226
227 return 0;
228err_reg:
229 omap_dss_put_device(ddata->in);
230 return r;
231}
232
233static int __exit tvc_remove(struct platform_device *pdev)
234{
235 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
236 struct omap_dss_device *dssdev = &ddata->dssdev;
237 struct omap_dss_device *in = ddata->in;
238
239 omapdss_unregister_display(&ddata->dssdev);
240
241 tvc_disable(dssdev);
242 tvc_disconnect(dssdev);
243
244 omap_dss_put_device(in);
245
246 return 0;
247}
248
Tomi Valkeinenfcc900a2013-05-29 15:34:06 +0300249static const struct of_device_id tvc_of_match[] = {
250 { .compatible = "omapdss,svideo-connector", },
251 { .compatible = "omapdss,composite-video-connector", },
252 {},
253};
254
Marek Belisko4ee9d9d2014-10-27 21:24:03 +0100255MODULE_DEVICE_TABLE(of, tvc_of_match);
256
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300257static struct platform_driver tvc_connector_driver = {
258 .probe = tvc_probe,
259 .remove = __exit_p(tvc_remove),
260 .driver = {
261 .name = "connector-analog-tv",
Tomi Valkeinenfcc900a2013-05-29 15:34:06 +0300262 .of_match_table = tvc_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300263 .suppress_bind_attrs = true,
Tomi Valkeinen61a7f242013-05-24 14:21:30 +0300264 },
265};
266
267module_platform_driver(tvc_connector_driver);
268
269MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
270MODULE_DESCRIPTION("Analog TV Connector driver");
271MODULE_LICENSE("GPL");