2 * linux/drivers/video/omap2/omapfb-sysfs.c
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <linux/sysfs.h>
25 #include <linux/device.h>
26 #include <linux/uaccess.h>
27 #include <linux/platform_device.h>
28 #include <linux/kernel.h>
30 #include <linux/omapfb.h>
32 #include <mach/display.h>
33 #include <mach/vrfb.h>
37 static ssize_t show_rotate_type(struct device *dev,
38 struct device_attribute *attr, char *buf)
40 struct fb_info *fbi = dev_get_drvdata(dev);
41 struct omapfb_info *ofbi = FB2OFB(fbi);
43 return snprintf(buf, PAGE_SIZE, "%d\n", ofbi->rotation_type);
46 static ssize_t store_rotate_type(struct device *dev,
47 struct device_attribute *attr,
48 const char *buf, size_t count)
50 struct fb_info *fbi = dev_get_drvdata(dev);
51 struct omapfb_info *ofbi = FB2OFB(fbi);
52 struct omapfb2_device *fbdev = ofbi->fbdev;
53 enum omap_dss_rotation_type rot_type;
56 rot_type = simple_strtoul(buf, NULL, 0);
58 if (rot_type != OMAP_DSS_ROT_DMA && rot_type != OMAP_DSS_ROT_VRFB)
64 if (rot_type == ofbi->rotation_type)
68 if (ofbi->region.size)
71 ofbi->rotation_type = rot_type;
74 * Since the VRAM for this FB is not allocated at the moment we don't need to
75 * do any further parameter checking at this point.
86 static ssize_t show_mirror(struct device *dev,
87 struct device_attribute *attr, char *buf)
89 struct fb_info *fbi = dev_get_drvdata(dev);
90 struct omapfb_info *ofbi = FB2OFB(fbi);
92 return snprintf(buf, PAGE_SIZE, "%d\n", ofbi->mirror);
95 static ssize_t store_mirror(struct device *dev,
96 struct device_attribute *attr,
97 const char *buf, size_t count)
99 struct fb_info *fbi = dev_get_drvdata(dev);
100 struct omapfb_info *ofbi = FB2OFB(fbi);
101 struct omapfb2_device *fbdev = ofbi->fbdev;
104 struct fb_var_screeninfo new_var;
106 mirror = simple_strtoul(buf, NULL, 0);
108 if (mirror != 0 && mirror != 1)
113 ofbi->mirror = mirror;
115 memcpy(&new_var, &fbi->var, sizeof(new_var));
116 r = check_fb_var(fbi, &new_var);
119 memcpy(&fbi->var, &new_var, sizeof(fbi->var));
123 r = omapfb_apply_changes(fbi, 0);
129 omapfb_unlock(fbdev);
134 static ssize_t show_overlays(struct device *dev,
135 struct device_attribute *attr, char *buf)
137 struct fb_info *fbi = dev_get_drvdata(dev);
138 struct omapfb_info *ofbi = FB2OFB(fbi);
139 struct omapfb2_device *fbdev = ofbi->fbdev;
143 for (t = 0; t < ofbi->num_overlays; t++) {
144 struct omap_overlay *ovl = ofbi->overlays[t];
147 for (ovlnum = 0; ovlnum < fbdev->num_overlays; ++ovlnum)
148 if (ovl == fbdev->overlays[ovlnum])
151 l += snprintf(buf + l, PAGE_SIZE - l, "%s%d",
152 t == 0 ? "" : ",", ovlnum);
155 l += snprintf(buf + l, PAGE_SIZE - l, "\n");
160 static struct omapfb_info *get_overlay_fb(struct omapfb2_device *fbdev,
161 struct omap_overlay *ovl)
165 for (i = 0; i < fbdev->num_fbs; i++) {
166 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
168 for (t = 0; t < ofbi->num_overlays; t++) {
169 if (ofbi->overlays[t] == ovl)
177 static ssize_t store_overlays(struct device *dev, struct device_attribute *attr,
178 const char *buf, size_t count)
180 struct fb_info *fbi = dev_get_drvdata(dev);
181 struct omapfb_info *ofbi = FB2OFB(fbi);
182 struct omapfb2_device *fbdev = ofbi->fbdev;
183 struct omap_overlay *ovls[OMAPFB_MAX_OVL_PER_FB];
184 struct omap_overlay *ovl;
191 if (buf[len - 1] == '\n')
197 char *p = (char *)buf;
200 while (p < buf + len) {
202 if (num_ovls == OMAPFB_MAX_OVL_PER_FB) {
207 ovlnum = simple_strtoul(p, &p, 0);
208 if (ovlnum > fbdev->num_overlays) {
214 for (i = 0; i < num_ovls; ++i) {
215 if (ovls[i] == fbdev->overlays[ovlnum]) {
222 ovls[num_ovls++] = fbdev->overlays[ovlnum];
228 for (i = 0; i < num_ovls; ++i) {
229 struct omapfb_info *ofbi2 = get_overlay_fb(fbdev, ovls[i]);
230 if (ofbi2 && ofbi2 != ofbi) {
231 dev_err(fbdev->dev, "overlay already in use\n");
237 /* detach unused overlays */
238 for (i = 0; i < ofbi->num_overlays; ++i) {
241 ovl = ofbi->overlays[i];
245 for (t = 0; t < num_ovls; ++t) {
246 if (ovl == ovls[t]) {
255 DBG("detaching %d\n", ofbi->overlays[i]->id);
257 omapfb_overlay_enable(ovl, 0);
260 ovl->manager->apply(ovl->manager);
262 for (t = i + 1; t < ofbi->num_overlays; t++)
263 ofbi->overlays[t-1] = ofbi->overlays[t];
265 ofbi->num_overlays--;
269 for (i = 0; i < num_ovls; ++i) {
276 for (t = 0; t < ofbi->num_overlays; ++t) {
277 if (ovl == ofbi->overlays[t]) {
286 ofbi->overlays[ofbi->num_overlays++] = ovl;
288 r = omapfb_apply_changes(fbi, 1);
293 r = ovl->manager->apply(ovl->manager);
301 omapfb_unlock(fbdev);
306 static ssize_t show_size(struct device *dev,
307 struct device_attribute *attr, char *buf)
309 struct fb_info *fbi = dev_get_drvdata(dev);
310 struct omapfb_info *ofbi = FB2OFB(fbi);
312 return snprintf(buf, PAGE_SIZE, "%lu\n", ofbi->region.size);
315 static ssize_t store_size(struct device *dev, struct device_attribute *attr,
316 const char *buf, size_t count)
318 struct fb_info *fbi = dev_get_drvdata(dev);
319 struct omapfb_info *ofbi = FB2OFB(fbi);
320 struct omapfb2_device *fbdev = ofbi->fbdev;
325 size = PAGE_ALIGN(simple_strtoul(buf, NULL, 0));
329 for (i = 0; i < ofbi->num_overlays; i++) {
330 if (ofbi->overlays[i]->info.enabled) {
336 if (size != ofbi->region.size) {
337 r = omapfb_realloc_fbmem(fbi, size, ofbi->region.type);
339 dev_err(dev, "realloc fbmem failed\n");
346 omapfb_unlock(fbdev);
351 static ssize_t show_phys(struct device *dev,
352 struct device_attribute *attr, char *buf)
354 struct fb_info *fbi = dev_get_drvdata(dev);
355 struct omapfb_info *ofbi = FB2OFB(fbi);
357 return snprintf(buf, PAGE_SIZE, "%0x\n", ofbi->region.paddr);
360 static ssize_t show_virt(struct device *dev,
361 struct device_attribute *attr, char *buf)
363 struct fb_info *fbi = dev_get_drvdata(dev);
364 struct omapfb_info *ofbi = FB2OFB(fbi);
366 return snprintf(buf, PAGE_SIZE, "%p\n", ofbi->region.vaddr);
369 static struct device_attribute omapfb_attrs[] = {
370 __ATTR(rotate_type, S_IRUGO | S_IWUSR, show_rotate_type, store_rotate_type),
371 __ATTR(mirror, S_IRUGO | S_IWUSR, show_mirror, store_mirror),
372 __ATTR(size, S_IRUGO | S_IWUSR, show_size, store_size),
373 __ATTR(overlays, S_IRUGO | S_IWUSR, show_overlays, store_overlays),
374 __ATTR(phys_addr, S_IRUGO, show_phys, NULL),
375 __ATTR(virt_addr, S_IRUGO, show_virt, NULL),
378 int omapfb_create_sysfs(struct omapfb2_device *fbdev)
383 DBG("create sysfs for fbs\n");
384 for (i = 0; i < fbdev->num_fbs; i++) {
386 for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++) {
387 r = device_create_file(fbdev->fbs[i]->dev,
391 dev_err(fbdev->dev, "failed to create sysfs file\n");
400 void omapfb_remove_sysfs(struct omapfb2_device *fbdev)
404 DBG("remove sysfs for fbs\n");
405 for (i = 0; i < fbdev->num_fbs; i++) {
406 for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++)
407 device_remove_file(fbdev->fbs[i]->dev,