blob: 80963697d384c1b353def21f76a3c280d64ed331 [file] [log] [blame]
Archit Taneja156fd992012-07-06 20:52:37 +05301/*
2 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
4 *
5 * VENC panel driver
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 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/kernel.h>
21#include <linux/err.h>
22#include <linux/io.h>
23#include <linux/mutex.h>
24#include <linux/module.h>
25
26#include <video/omapdss.h>
27
28#include "dss.h"
29
30static struct {
31 struct mutex lock;
32} venc_panel;
33
34static ssize_t display_output_type_show(struct device *dev,
35 struct device_attribute *attr, char *buf)
36{
37 struct omap_dss_device *dssdev = to_dss_device(dev);
38 const char *ret;
39
40 switch (dssdev->phy.venc.type) {
41 case OMAP_DSS_VENC_TYPE_COMPOSITE:
42 ret = "composite";
43 break;
44 case OMAP_DSS_VENC_TYPE_SVIDEO:
45 ret = "svideo";
46 break;
47 default:
48 return -EINVAL;
49 }
50
51 return snprintf(buf, PAGE_SIZE, "%s\n", ret);
52}
53
54static ssize_t display_output_type_store(struct device *dev,
55 struct device_attribute *attr, const char *buf, size_t size)
56{
57 struct omap_dss_device *dssdev = to_dss_device(dev);
58 enum omap_dss_venc_type new_type;
59
60 if (sysfs_streq("composite", buf))
61 new_type = OMAP_DSS_VENC_TYPE_COMPOSITE;
62 else if (sysfs_streq("svideo", buf))
63 new_type = OMAP_DSS_VENC_TYPE_SVIDEO;
64 else
65 return -EINVAL;
66
67 mutex_lock(&venc_panel.lock);
68
69 if (dssdev->phy.venc.type != new_type) {
70 dssdev->phy.venc.type = new_type;
71 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
72 omapdss_venc_display_disable(dssdev);
73 omapdss_venc_display_enable(dssdev);
74 }
75 }
76
77 mutex_unlock(&venc_panel.lock);
78
79 return size;
80}
81
82static DEVICE_ATTR(output_type, S_IRUGO | S_IWUSR,
83 display_output_type_show, display_output_type_store);
84
85static int venc_panel_probe(struct omap_dss_device *dssdev)
86{
87 /* set default timings to PAL */
88 const struct omap_video_timings default_timings = {
89 .x_res = 720,
90 .y_res = 574,
91 .pixel_clock = 13500,
92 .hsw = 64,
93 .hfp = 12,
94 .hbp = 68,
95 .vsw = 5,
96 .vfp = 5,
97 .vbp = 41,
98
99 .vsync_level = OMAPDSS_SIG_ACTIVE_HIGH,
100 .hsync_level = OMAPDSS_SIG_ACTIVE_HIGH,
101
102 .interlace = true,
103 };
104
105 mutex_init(&venc_panel.lock);
106
107 dssdev->panel.timings = default_timings;
108
109 return device_create_file(&dssdev->dev, &dev_attr_output_type);
110}
111
112static void venc_panel_remove(struct omap_dss_device *dssdev)
113{
114 device_remove_file(&dssdev->dev, &dev_attr_output_type);
115}
116
117static int venc_panel_enable(struct omap_dss_device *dssdev)
118{
119 int r;
120
121 dev_dbg(&dssdev->dev, "venc_panel_enable\n");
122
123 mutex_lock(&venc_panel.lock);
124
125 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
126 r = -EINVAL;
127 goto err;
128 }
129
Archit Tanejaa5abf472012-07-20 16:15:44 +0530130 omapdss_venc_set_timings(dssdev, &dssdev->panel.timings);
131
Archit Taneja156fd992012-07-06 20:52:37 +0530132 r = omapdss_venc_display_enable(dssdev);
133 if (r)
134 goto err;
135
136 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
137
138 mutex_unlock(&venc_panel.lock);
139
140 return 0;
141err:
142 mutex_unlock(&venc_panel.lock);
143
144 return r;
145}
146
147static void venc_panel_disable(struct omap_dss_device *dssdev)
148{
149 dev_dbg(&dssdev->dev, "venc_panel_disable\n");
150
151 mutex_lock(&venc_panel.lock);
152
153 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED)
154 goto end;
155
156 if (dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED) {
157 /* suspended is the same as disabled with venc */
158 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
159 goto end;
160 }
161
162 omapdss_venc_display_disable(dssdev);
163
164 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
165end:
166 mutex_unlock(&venc_panel.lock);
167}
168
169static int venc_panel_suspend(struct omap_dss_device *dssdev)
170{
171 venc_panel_disable(dssdev);
172 return 0;
173}
174
175static int venc_panel_resume(struct omap_dss_device *dssdev)
176{
177 return venc_panel_enable(dssdev);
178}
179
180static void venc_panel_set_timings(struct omap_dss_device *dssdev,
181 struct omap_video_timings *timings)
182{
183 dev_dbg(&dssdev->dev, "venc_panel_set_timings\n");
184
185 mutex_lock(&venc_panel.lock);
186
187 omapdss_venc_set_timings(dssdev, timings);
Archit Tanejaa5abf472012-07-20 16:15:44 +0530188 dssdev->panel.timings = *timings;
Archit Taneja156fd992012-07-06 20:52:37 +0530189
190 mutex_unlock(&venc_panel.lock);
191}
192
193static int venc_panel_check_timings(struct omap_dss_device *dssdev,
194 struct omap_video_timings *timings)
195{
196 dev_dbg(&dssdev->dev, "venc_panel_check_timings\n");
197
198 return omapdss_venc_check_timings(dssdev, timings);
199}
200
201static u32 venc_panel_get_wss(struct omap_dss_device *dssdev)
202{
203 dev_dbg(&dssdev->dev, "venc_panel_get_wss\n");
204
205 return omapdss_venc_get_wss(dssdev);
206}
207
208static int venc_panel_set_wss(struct omap_dss_device *dssdev, u32 wss)
209{
210 dev_dbg(&dssdev->dev, "venc_panel_set_wss\n");
211
212 return omapdss_venc_set_wss(dssdev, wss);
213}
214
215static struct omap_dss_driver venc_driver = {
216 .probe = venc_panel_probe,
217 .remove = venc_panel_remove,
218
219 .enable = venc_panel_enable,
220 .disable = venc_panel_disable,
221 .suspend = venc_panel_suspend,
222 .resume = venc_panel_resume,
223
224 .get_resolution = omapdss_default_get_resolution,
225 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
226
227 .set_timings = venc_panel_set_timings,
228 .check_timings = venc_panel_check_timings,
229
230 .get_wss = venc_panel_get_wss,
231 .set_wss = venc_panel_set_wss,
232
233 .driver = {
234 .name = "venc",
235 .owner = THIS_MODULE,
236 },
237};
238
239int venc_panel_init(void)
240{
241 return omap_dss_register_driver(&venc_driver);
242}
243
244void venc_panel_exit(void)
245{
246 omap_dss_unregister_driver(&venc_driver);
247}