]> rtime.felk.cvut.cz Git - linux-imx.git/blob - drivers/video/omap2/displays-new/connector-analog-tv.c
[SCSI] Don't attempt to send extended INQUIRY command if skip_vpd_pages is set
[linux-imx.git] / drivers / video / omap2 / displays-new / connector-analog-tv.c
1 /*
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>
15
16 #include <video/omapdss.h>
17 #include <video/omap-panel-data.h>
18
19 struct panel_drv_data {
20         struct omap_dss_device dssdev;
21         struct omap_dss_device *in;
22
23         struct device *dev;
24
25         struct omap_video_timings timings;
26
27         enum omap_dss_venc_type connector_type;
28         bool invert_polarity;
29 };
30
31 #define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
32
33 static int tvc_connect(struct omap_dss_device *dssdev)
34 {
35         struct panel_drv_data *ddata = to_panel_data(dssdev);
36         struct omap_dss_device *in = ddata->in;
37         int r;
38
39         dev_dbg(ddata->dev, "connect\n");
40
41         if (omapdss_device_is_connected(dssdev))
42                 return 0;
43
44         r = in->ops.atv->connect(in, dssdev);
45         if (r)
46                 return r;
47
48         return 0;
49 }
50
51 static void tvc_disconnect(struct omap_dss_device *dssdev)
52 {
53         struct panel_drv_data *ddata = to_panel_data(dssdev);
54         struct omap_dss_device *in = ddata->in;
55
56         dev_dbg(ddata->dev, "disconnect\n");
57
58         if (!omapdss_device_is_connected(dssdev))
59                 return;
60
61         in->ops.atv->disconnect(in, dssdev);
62 }
63
64 static int tvc_enable(struct omap_dss_device *dssdev)
65 {
66         struct panel_drv_data *ddata = to_panel_data(dssdev);
67         struct omap_dss_device *in = ddata->in;
68         int r;
69
70         dev_dbg(ddata->dev, "enable\n");
71
72         if (!omapdss_device_is_connected(dssdev))
73                 return -ENODEV;
74
75         if (omapdss_device_is_enabled(dssdev))
76                 return 0;
77
78         in->ops.atv->set_timings(in, &ddata->timings);
79
80         in->ops.atv->set_type(in, ddata->connector_type);
81         in->ops.atv->invert_vid_out_polarity(in, ddata->invert_polarity);
82
83         r = in->ops.atv->enable(in);
84         if (r)
85                 return r;
86
87         dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
88
89         return r;
90 }
91
92 static void tvc_disable(struct omap_dss_device *dssdev)
93 {
94         struct panel_drv_data *ddata = to_panel_data(dssdev);
95         struct omap_dss_device *in = ddata->in;
96
97         dev_dbg(ddata->dev, "disable\n");
98
99         if (!omapdss_device_is_enabled(dssdev))
100                 return;
101
102         in->ops.atv->disable(in);
103
104         dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
105 }
106
107 static void tvc_set_timings(struct omap_dss_device *dssdev,
108                 struct omap_video_timings *timings)
109 {
110         struct panel_drv_data *ddata = to_panel_data(dssdev);
111         struct omap_dss_device *in = ddata->in;
112
113         ddata->timings = *timings;
114         dssdev->panel.timings = *timings;
115
116         in->ops.atv->set_timings(in, timings);
117 }
118
119 static void tvc_get_timings(struct omap_dss_device *dssdev,
120                 struct omap_video_timings *timings)
121 {
122         struct panel_drv_data *ddata = to_panel_data(dssdev);
123
124         *timings = ddata->timings;
125 }
126
127 static int tvc_check_timings(struct omap_dss_device *dssdev,
128                 struct omap_video_timings *timings)
129 {
130         struct panel_drv_data *ddata = to_panel_data(dssdev);
131         struct omap_dss_device *in = ddata->in;
132
133         return in->ops.atv->check_timings(in, timings);
134 }
135
136 static u32 tvc_get_wss(struct omap_dss_device *dssdev)
137 {
138         struct panel_drv_data *ddata = to_panel_data(dssdev);
139         struct omap_dss_device *in = ddata->in;
140
141         return in->ops.atv->get_wss(in);
142 }
143
144 static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
145 {
146         struct panel_drv_data *ddata = to_panel_data(dssdev);
147         struct omap_dss_device *in = ddata->in;
148
149         return in->ops.atv->set_wss(in, wss);
150 }
151
152 static struct omap_dss_driver tvc_driver = {
153         .connect                = tvc_connect,
154         .disconnect             = tvc_disconnect,
155
156         .enable                 = tvc_enable,
157         .disable                = tvc_disable,
158
159         .set_timings            = tvc_set_timings,
160         .get_timings            = tvc_get_timings,
161         .check_timings          = tvc_check_timings,
162
163         .get_resolution         = omapdss_default_get_resolution,
164
165         .get_wss                = tvc_get_wss,
166         .set_wss                = tvc_set_wss,
167 };
168
169 static int tvc_probe_pdata(struct platform_device *pdev)
170 {
171         struct panel_drv_data *ddata = platform_get_drvdata(pdev);
172         struct connector_atv_platform_data *pdata;
173         struct omap_dss_device *in, *dssdev;
174
175         pdata = dev_get_platdata(&pdev->dev);
176
177         in = omap_dss_find_output(pdata->source);
178         if (in == NULL) {
179                 dev_err(&pdev->dev, "Failed to find video source\n");
180                 return -ENODEV;
181         }
182
183         ddata->in = in;
184
185         ddata->connector_type = pdata->connector_type;
186         ddata->invert_polarity = ddata->invert_polarity;
187
188         dssdev = &ddata->dssdev;
189         dssdev->name = pdata->name;
190
191         return 0;
192 }
193
194 static int tvc_probe(struct platform_device *pdev)
195 {
196         struct panel_drv_data *ddata;
197         struct omap_dss_device *dssdev;
198         int r;
199
200         ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
201         if (!ddata)
202                 return -ENOMEM;
203
204         platform_set_drvdata(pdev, ddata);
205         ddata->dev = &pdev->dev;
206
207         if (dev_get_platdata(&pdev->dev)) {
208                 r = tvc_probe_pdata(pdev);
209                 if (r)
210                         return r;
211         } else {
212                 return -ENODEV;
213         }
214
215         ddata->timings = omap_dss_pal_timings;
216
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;
223
224         r = omapdss_register_display(dssdev);
225         if (r) {
226                 dev_err(&pdev->dev, "Failed to register panel\n");
227                 goto err_reg;
228         }
229
230         return 0;
231 err_reg:
232         omap_dss_put_device(ddata->in);
233         return r;
234 }
235
236 static int __exit tvc_remove(struct platform_device *pdev)
237 {
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;
241
242         omapdss_unregister_display(&ddata->dssdev);
243
244         tvc_disable(dssdev);
245         tvc_disconnect(dssdev);
246
247         omap_dss_put_device(in);
248
249         return 0;
250 }
251
252 static struct platform_driver tvc_connector_driver = {
253         .probe  = tvc_probe,
254         .remove = __exit_p(tvc_remove),
255         .driver = {
256                 .name   = "connector-analog-tv",
257                 .owner  = THIS_MODULE,
258         },
259 };
260
261 module_platform_driver(tvc_connector_driver);
262
263 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
264 MODULE_DESCRIPTION("Analog TV Connector driver");
265 MODULE_LICENSE("GPL");