blob: 81d5dc6e509f1f14465f90635a2e91e7f93a73c0 [file] [log] [blame]
Tomi Valkeinen3f30b8c2012-11-08 13:13:02 +02001/*
2 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
4 *
5 * Some code and ideas taken from drivers/video/omap/ driver
6 * by Imre Deak.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#define DSS_SUBSYS_NAME "DISPLAY"
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/jiffies.h>
26#include <linux/platform_device.h>
27
28#include <video/omapdss.h>
29#include "dss.h"
30#include "dss_features.h"
31
32static ssize_t display_enabled_show(struct device *dev,
33 struct device_attribute *attr, char *buf)
34{
35 struct omap_dss_device *dssdev = to_dss_device(dev);
Tomi Valkeinen3f30b8c2012-11-08 13:13:02 +020036
Tomi Valkeinena7e71e72013-05-08 16:23:32 +030037 return snprintf(buf, PAGE_SIZE, "%d\n",
38 omapdss_device_is_enabled(dssdev));
Tomi Valkeinen3f30b8c2012-11-08 13:13:02 +020039}
40
41static ssize_t display_enabled_store(struct device *dev,
42 struct device_attribute *attr,
43 const char *buf, size_t size)
44{
45 struct omap_dss_device *dssdev = to_dss_device(dev);
46 int r;
Tomi Valkeinena7e71e72013-05-08 16:23:32 +030047 bool enable;
Tomi Valkeinen3f30b8c2012-11-08 13:13:02 +020048
Tomi Valkeinena7e71e72013-05-08 16:23:32 +030049 r = strtobool(buf, &enable);
Tomi Valkeinen3f30b8c2012-11-08 13:13:02 +020050 if (r)
51 return r;
52
Tomi Valkeinena7e71e72013-05-08 16:23:32 +030053 if (enable == omapdss_device_is_enabled(dssdev))
54 return size;
55
56 if (omapdss_device_is_connected(dssdev) == false)
57 return -ENODEV;
58
59 if (enable) {
60 r = dssdev->driver->enable(dssdev);
61 if (r)
62 return r;
63 } else {
64 dssdev->driver->disable(dssdev);
Tomi Valkeinen3f30b8c2012-11-08 13:13:02 +020065 }
66
67 return size;
68}
69
70static ssize_t display_tear_show(struct device *dev,
71 struct device_attribute *attr, char *buf)
72{
73 struct omap_dss_device *dssdev = to_dss_device(dev);
74 return snprintf(buf, PAGE_SIZE, "%d\n",
75 dssdev->driver->get_te ?
76 dssdev->driver->get_te(dssdev) : 0);
77}
78
79static ssize_t display_tear_store(struct device *dev,
80 struct device_attribute *attr, const char *buf, size_t size)
81{
82 struct omap_dss_device *dssdev = to_dss_device(dev);
83 int r;
84 bool te;
85
86 if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
87 return -ENOENT;
88
89 r = strtobool(buf, &te);
90 if (r)
91 return r;
92
93 r = dssdev->driver->enable_te(dssdev, te);
94 if (r)
95 return r;
96
97 return size;
98}
99
100static ssize_t display_timings_show(struct device *dev,
101 struct device_attribute *attr, char *buf)
102{
103 struct omap_dss_device *dssdev = to_dss_device(dev);
104 struct omap_video_timings t;
105
106 if (!dssdev->driver->get_timings)
107 return -ENOENT;
108
109 dssdev->driver->get_timings(dssdev, &t);
110
111 return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
112 t.pixel_clock,
113 t.x_res, t.hfp, t.hbp, t.hsw,
114 t.y_res, t.vfp, t.vbp, t.vsw);
115}
116
117static ssize_t display_timings_store(struct device *dev,
118 struct device_attribute *attr, const char *buf, size_t size)
119{
120 struct omap_dss_device *dssdev = to_dss_device(dev);
121 struct omap_video_timings t = dssdev->panel.timings;
122 int r, found;
123
124 if (!dssdev->driver->set_timings || !dssdev->driver->check_timings)
125 return -ENOENT;
126
127 found = 0;
128#ifdef CONFIG_OMAP2_DSS_VENC
129 if (strncmp("pal", buf, 3) == 0) {
130 t = omap_dss_pal_timings;
131 found = 1;
132 } else if (strncmp("ntsc", buf, 4) == 0) {
133 t = omap_dss_ntsc_timings;
134 found = 1;
135 }
136#endif
137 if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
138 &t.pixel_clock,
139 &t.x_res, &t.hfp, &t.hbp, &t.hsw,
140 &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
141 return -EINVAL;
142
143 r = dssdev->driver->check_timings(dssdev, &t);
144 if (r)
145 return r;
146
147 dssdev->driver->disable(dssdev);
148 dssdev->driver->set_timings(dssdev, &t);
149 r = dssdev->driver->enable(dssdev);
150 if (r)
151 return r;
152
153 return size;
154}
155
156static ssize_t display_rotate_show(struct device *dev,
157 struct device_attribute *attr, char *buf)
158{
159 struct omap_dss_device *dssdev = to_dss_device(dev);
160 int rotate;
161 if (!dssdev->driver->get_rotate)
162 return -ENOENT;
163 rotate = dssdev->driver->get_rotate(dssdev);
164 return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
165}
166
167static ssize_t display_rotate_store(struct device *dev,
168 struct device_attribute *attr, const char *buf, size_t size)
169{
170 struct omap_dss_device *dssdev = to_dss_device(dev);
171 int rot, r;
172
173 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
174 return -ENOENT;
175
176 r = kstrtoint(buf, 0, &rot);
177 if (r)
178 return r;
179
180 r = dssdev->driver->set_rotate(dssdev, rot);
181 if (r)
182 return r;
183
184 return size;
185}
186
187static ssize_t display_mirror_show(struct device *dev,
188 struct device_attribute *attr, char *buf)
189{
190 struct omap_dss_device *dssdev = to_dss_device(dev);
191 int mirror;
192 if (!dssdev->driver->get_mirror)
193 return -ENOENT;
194 mirror = dssdev->driver->get_mirror(dssdev);
195 return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
196}
197
198static ssize_t display_mirror_store(struct device *dev,
199 struct device_attribute *attr, const char *buf, size_t size)
200{
201 struct omap_dss_device *dssdev = to_dss_device(dev);
202 int r;
203 bool mirror;
204
205 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
206 return -ENOENT;
207
208 r = strtobool(buf, &mirror);
209 if (r)
210 return r;
211
212 r = dssdev->driver->set_mirror(dssdev, mirror);
213 if (r)
214 return r;
215
216 return size;
217}
218
219static ssize_t display_wss_show(struct device *dev,
220 struct device_attribute *attr, char *buf)
221{
222 struct omap_dss_device *dssdev = to_dss_device(dev);
223 unsigned int wss;
224
225 if (!dssdev->driver->get_wss)
226 return -ENOENT;
227
228 wss = dssdev->driver->get_wss(dssdev);
229
230 return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
231}
232
233static ssize_t display_wss_store(struct device *dev,
234 struct device_attribute *attr, const char *buf, size_t size)
235{
236 struct omap_dss_device *dssdev = to_dss_device(dev);
237 u32 wss;
238 int r;
239
240 if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
241 return -ENOENT;
242
243 r = kstrtou32(buf, 0, &wss);
244 if (r)
245 return r;
246
247 if (wss > 0xfffff)
248 return -EINVAL;
249
250 r = dssdev->driver->set_wss(dssdev, wss);
251 if (r)
252 return r;
253
254 return size;
255}
256
257static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
258 display_enabled_show, display_enabled_store);
259static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
260 display_tear_show, display_tear_store);
261static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
262 display_timings_show, display_timings_store);
263static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
264 display_rotate_show, display_rotate_store);
265static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
266 display_mirror_show, display_mirror_store);
267static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
268 display_wss_show, display_wss_store);
269
270static struct device_attribute *display_sysfs_attrs[] = {
271 &dev_attr_enabled,
272 &dev_attr_tear_elim,
273 &dev_attr_timings,
274 &dev_attr_rotate,
275 &dev_attr_mirror,
276 &dev_attr_wss,
277 NULL
278};
279
280int display_init_sysfs(struct platform_device *pdev,
281 struct omap_dss_device *dssdev)
282{
283 struct device_attribute *attr;
284 int i, r;
285
286 /* create device sysfs files */
287 i = 0;
288 while ((attr = display_sysfs_attrs[i++]) != NULL) {
289 r = device_create_file(&dssdev->dev, attr);
290 if (r) {
291 for (i = i - 2; i >= 0; i--) {
292 attr = display_sysfs_attrs[i];
293 device_remove_file(&dssdev->dev, attr);
294 }
295
296 DSSERR("failed to create sysfs file\n");
297 return r;
298 }
299 }
300
301 /* create display? sysfs links */
302 r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
303 dev_name(&dssdev->dev));
304 if (r) {
305 while ((attr = display_sysfs_attrs[i++]) != NULL)
306 device_remove_file(&dssdev->dev, attr);
307
308 DSSERR("failed to create sysfs display link\n");
309 return r;
310 }
311
312 return 0;
313}
314
315void display_uninit_sysfs(struct platform_device *pdev,
316 struct omap_dss_device *dssdev)
317{
318 struct device_attribute *attr;
319 int i = 0;
320
321 sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
322
323 while ((attr = display_sysfs_attrs[i++]) != NULL)
324 device_remove_file(&dssdev->dev, attr);
325}