2 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
5 * Some code and ideas taken from drivers/video/omap/ driver
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.
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
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/>.
21 #define DSS_SUBSYS_NAME "DISPLAY"
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/jiffies.h>
26 #include <linux/platform_device.h>
28 #include <video/omapdss.h>
30 #include "dss_features.h"
32 static ssize_t display_enabled_show(struct device *dev,
33 struct device_attribute *attr, char *buf)
35 struct omap_dss_device *dssdev = to_dss_device(dev);
36 bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
38 return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
41 static ssize_t display_enabled_store(struct device *dev,
42 struct device_attribute *attr,
43 const char *buf, size_t size)
45 struct omap_dss_device *dssdev = to_dss_device(dev);
49 r = strtobool(buf, &enabled);
53 if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
55 r = dssdev->driver->enable(dssdev);
59 dssdev->driver->disable(dssdev);
66 static ssize_t display_tear_show(struct device *dev,
67 struct device_attribute *attr, char *buf)
69 struct omap_dss_device *dssdev = to_dss_device(dev);
70 return snprintf(buf, PAGE_SIZE, "%d\n",
71 dssdev->driver->get_te ?
72 dssdev->driver->get_te(dssdev) : 0);
75 static ssize_t display_tear_store(struct device *dev,
76 struct device_attribute *attr, const char *buf, size_t size)
78 struct omap_dss_device *dssdev = to_dss_device(dev);
82 if (!dssdev->driver->enable_te || !dssdev->driver->get_te)
85 r = strtobool(buf, &te);
89 r = dssdev->driver->enable_te(dssdev, te);
96 static ssize_t display_timings_show(struct device *dev,
97 struct device_attribute *attr, char *buf)
99 struct omap_dss_device *dssdev = to_dss_device(dev);
100 struct omap_video_timings t;
102 if (!dssdev->driver->get_timings)
105 dssdev->driver->get_timings(dssdev, &t);
107 return snprintf(buf, PAGE_SIZE, "%u,%u/%u/%u/%u,%u/%u/%u/%u\n",
109 t.x_res, t.hfp, t.hbp, t.hsw,
110 t.y_res, t.vfp, t.vbp, t.vsw);
113 static ssize_t display_timings_store(struct device *dev,
114 struct device_attribute *attr, const char *buf, size_t size)
116 struct omap_dss_device *dssdev = to_dss_device(dev);
117 struct omap_video_timings t = dssdev->panel.timings;
120 if (!dssdev->driver->set_timings || !dssdev->driver->check_timings)
124 #ifdef CONFIG_OMAP2_DSS_VENC
125 if (strncmp("pal", buf, 3) == 0) {
126 t = omap_dss_pal_timings;
128 } else if (strncmp("ntsc", buf, 4) == 0) {
129 t = omap_dss_ntsc_timings;
133 if (!found && sscanf(buf, "%u,%hu/%hu/%hu/%hu,%hu/%hu/%hu/%hu",
135 &t.x_res, &t.hfp, &t.hbp, &t.hsw,
136 &t.y_res, &t.vfp, &t.vbp, &t.vsw) != 9)
139 r = dssdev->driver->check_timings(dssdev, &t);
143 dssdev->driver->disable(dssdev);
144 dssdev->driver->set_timings(dssdev, &t);
145 r = dssdev->driver->enable(dssdev);
152 static ssize_t display_rotate_show(struct device *dev,
153 struct device_attribute *attr, char *buf)
155 struct omap_dss_device *dssdev = to_dss_device(dev);
157 if (!dssdev->driver->get_rotate)
159 rotate = dssdev->driver->get_rotate(dssdev);
160 return snprintf(buf, PAGE_SIZE, "%u\n", rotate);
163 static ssize_t display_rotate_store(struct device *dev,
164 struct device_attribute *attr, const char *buf, size_t size)
166 struct omap_dss_device *dssdev = to_dss_device(dev);
169 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
172 r = kstrtoint(buf, 0, &rot);
176 r = dssdev->driver->set_rotate(dssdev, rot);
183 static ssize_t display_mirror_show(struct device *dev,
184 struct device_attribute *attr, char *buf)
186 struct omap_dss_device *dssdev = to_dss_device(dev);
188 if (!dssdev->driver->get_mirror)
190 mirror = dssdev->driver->get_mirror(dssdev);
191 return snprintf(buf, PAGE_SIZE, "%u\n", mirror);
194 static ssize_t display_mirror_store(struct device *dev,
195 struct device_attribute *attr, const char *buf, size_t size)
197 struct omap_dss_device *dssdev = to_dss_device(dev);
201 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
204 r = strtobool(buf, &mirror);
208 r = dssdev->driver->set_mirror(dssdev, mirror);
215 static ssize_t display_wss_show(struct device *dev,
216 struct device_attribute *attr, char *buf)
218 struct omap_dss_device *dssdev = to_dss_device(dev);
221 if (!dssdev->driver->get_wss)
224 wss = dssdev->driver->get_wss(dssdev);
226 return snprintf(buf, PAGE_SIZE, "0x%05x\n", wss);
229 static ssize_t display_wss_store(struct device *dev,
230 struct device_attribute *attr, const char *buf, size_t size)
232 struct omap_dss_device *dssdev = to_dss_device(dev);
236 if (!dssdev->driver->get_wss || !dssdev->driver->set_wss)
239 r = kstrtou32(buf, 0, &wss);
246 r = dssdev->driver->set_wss(dssdev, wss);
253 static DEVICE_ATTR(enabled, S_IRUGO|S_IWUSR,
254 display_enabled_show, display_enabled_store);
255 static DEVICE_ATTR(tear_elim, S_IRUGO|S_IWUSR,
256 display_tear_show, display_tear_store);
257 static DEVICE_ATTR(timings, S_IRUGO|S_IWUSR,
258 display_timings_show, display_timings_store);
259 static DEVICE_ATTR(rotate, S_IRUGO|S_IWUSR,
260 display_rotate_show, display_rotate_store);
261 static DEVICE_ATTR(mirror, S_IRUGO|S_IWUSR,
262 display_mirror_show, display_mirror_store);
263 static DEVICE_ATTR(wss, S_IRUGO|S_IWUSR,
264 display_wss_show, display_wss_store);
266 static struct device_attribute *display_sysfs_attrs[] = {
276 int display_init_sysfs(struct platform_device *pdev,
277 struct omap_dss_device *dssdev)
279 struct device_attribute *attr;
282 /* create device sysfs files */
284 while ((attr = display_sysfs_attrs[i++]) != NULL) {
285 r = device_create_file(&dssdev->dev, attr);
287 for (i = i - 2; i >= 0; i--) {
288 attr = display_sysfs_attrs[i];
289 device_remove_file(&dssdev->dev, attr);
292 DSSERR("failed to create sysfs file\n");
297 /* create display? sysfs links */
298 r = sysfs_create_link(&pdev->dev.kobj, &dssdev->dev.kobj,
299 dev_name(&dssdev->dev));
301 while ((attr = display_sysfs_attrs[i++]) != NULL)
302 device_remove_file(&dssdev->dev, attr);
304 DSSERR("failed to create sysfs display link\n");
311 void display_uninit_sysfs(struct platform_device *pdev,
312 struct omap_dss_device *dssdev)
314 struct device_attribute *attr;
317 sysfs_remove_link(&pdev->dev.kobj, dev_name(&dssdev->dev));
319 while ((attr = display_sysfs_attrs[i++]) != NULL)
320 device_remove_file(&dssdev->dev, attr);