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 <plat/display.h>
33 #include <plat/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 enum omap_dss_rotation_type rot_type;
55 rot_type = simple_strtoul(buf, NULL, 0);
57 if (rot_type != OMAP_DSS_ROT_DMA && rot_type != OMAP_DSS_ROT_VRFB)
60 if (!lock_fb_info(fbi))
64 if (rot_type == ofbi->rotation_type)
67 if (ofbi->region.size) {
72 ofbi->rotation_type = rot_type;
75 * Since the VRAM for this FB is not allocated at the moment we don't
76 * need to do any further parameter checking at this point.
85 static ssize_t show_mirror(struct device *dev,
86 struct device_attribute *attr, char *buf)
88 struct fb_info *fbi = dev_get_drvdata(dev);
89 struct omapfb_info *ofbi = FB2OFB(fbi);
91 return snprintf(buf, PAGE_SIZE, "%d\n", ofbi->mirror);
94 static ssize_t store_mirror(struct device *dev,
95 struct device_attribute *attr,
96 const char *buf, size_t count)
98 struct fb_info *fbi = dev_get_drvdata(dev);
99 struct omapfb_info *ofbi = FB2OFB(fbi);
102 struct fb_var_screeninfo new_var;
104 mirror = simple_strtoul(buf, NULL, 0);
106 if (mirror != 0 && mirror != 1)
109 if (!lock_fb_info(fbi))
112 ofbi->mirror = mirror;
114 memcpy(&new_var, &fbi->var, sizeof(new_var));
115 r = check_fb_var(fbi, &new_var);
118 memcpy(&fbi->var, &new_var, sizeof(fbi->var));
122 r = omapfb_apply_changes(fbi, 0);
133 static ssize_t show_overlays(struct device *dev,
134 struct device_attribute *attr, char *buf)
136 struct fb_info *fbi = dev_get_drvdata(dev);
137 struct omapfb_info *ofbi = FB2OFB(fbi);
138 struct omapfb2_device *fbdev = ofbi->fbdev;
142 if (!lock_fb_info(fbi))
146 for (t = 0; t < ofbi->num_overlays; t++) {
147 struct omap_overlay *ovl = ofbi->overlays[t];
150 for (ovlnum = 0; ovlnum < fbdev->num_overlays; ++ovlnum)
151 if (ovl == fbdev->overlays[ovlnum])
154 l += snprintf(buf + l, PAGE_SIZE - l, "%s%d",
155 t == 0 ? "" : ",", ovlnum);
158 l += snprintf(buf + l, PAGE_SIZE - l, "\n");
160 omapfb_unlock(fbdev);
166 static struct omapfb_info *get_overlay_fb(struct omapfb2_device *fbdev,
167 struct omap_overlay *ovl)
171 for (i = 0; i < fbdev->num_fbs; i++) {
172 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
174 for (t = 0; t < ofbi->num_overlays; t++) {
175 if (ofbi->overlays[t] == ovl)
183 static ssize_t store_overlays(struct device *dev, struct device_attribute *attr,
184 const char *buf, size_t count)
186 struct fb_info *fbi = dev_get_drvdata(dev);
187 struct omapfb_info *ofbi = FB2OFB(fbi);
188 struct omapfb2_device *fbdev = ofbi->fbdev;
189 struct omap_overlay *ovls[OMAPFB_MAX_OVL_PER_FB];
190 struct omap_overlay *ovl;
198 if (buf[len - 1] == '\n')
201 if (!lock_fb_info(fbi))
206 char *p = (char *)buf;
209 while (p < buf + len) {
211 if (num_ovls == OMAPFB_MAX_OVL_PER_FB) {
216 ovlnum = simple_strtoul(p, &p, 0);
217 if (ovlnum > fbdev->num_overlays) {
223 for (i = 0; i < num_ovls; ++i) {
224 if (ovls[i] == fbdev->overlays[ovlnum]) {
231 ovls[num_ovls++] = fbdev->overlays[ovlnum];
237 for (i = 0; i < num_ovls; ++i) {
238 struct omapfb_info *ofbi2 = get_overlay_fb(fbdev, ovls[i]);
239 if (ofbi2 && ofbi2 != ofbi) {
240 dev_err(fbdev->dev, "overlay already in use\n");
246 /* detach unused overlays */
247 for (i = 0; i < ofbi->num_overlays; ++i) {
250 ovl = ofbi->overlays[i];
254 for (t = 0; t < num_ovls; ++t) {
255 if (ovl == ovls[t]) {
264 DBG("detaching %d\n", ofbi->overlays[i]->id);
266 omapfb_overlay_enable(ovl, 0);
269 ovl->manager->apply(ovl->manager);
271 for (t = i + 1; t < ofbi->num_overlays; t++) {
272 ofbi->rotation[t-1] = ofbi->rotation[t];
273 ofbi->overlays[t-1] = ofbi->overlays[t];
276 ofbi->num_overlays--;
280 for (i = 0; i < num_ovls; ++i) {
287 for (t = 0; t < ofbi->num_overlays; ++t) {
288 if (ovl == ofbi->overlays[t]) {
296 ofbi->rotation[ofbi->num_overlays] = 0;
297 ofbi->overlays[ofbi->num_overlays++] = ovl;
303 r = omapfb_apply_changes(fbi, 0);
310 omapfb_unlock(fbdev);
316 static ssize_t show_overlays_rotate(struct device *dev,
317 struct device_attribute *attr, char *buf)
319 struct fb_info *fbi = dev_get_drvdata(dev);
320 struct omapfb_info *ofbi = FB2OFB(fbi);
324 if (!lock_fb_info(fbi))
327 for (t = 0; t < ofbi->num_overlays; t++) {
328 l += snprintf(buf + l, PAGE_SIZE - l, "%s%d",
329 t == 0 ? "" : ",", ofbi->rotation[t]);
332 l += snprintf(buf + l, PAGE_SIZE - l, "\n");
339 static ssize_t store_overlays_rotate(struct device *dev,
340 struct device_attribute *attr, const char *buf, size_t count)
342 struct fb_info *fbi = dev_get_drvdata(dev);
343 struct omapfb_info *ofbi = FB2OFB(fbi);
344 int num_ovls = 0, r, i;
346 bool changed = false;
347 u8 rotation[OMAPFB_MAX_OVL_PER_FB];
350 if (buf[len - 1] == '\n')
353 if (!lock_fb_info(fbi))
357 char *p = (char *)buf;
359 while (p < buf + len) {
362 if (num_ovls == ofbi->num_overlays) {
367 rot = simple_strtoul(p, &p, 0);
368 if (rot < 0 || rot > 3) {
373 if (ofbi->rotation[num_ovls] != rot)
376 rotation[num_ovls++] = rot;
382 if (num_ovls != ofbi->num_overlays) {
388 for (i = 0; i < num_ovls; ++i)
389 ofbi->rotation[i] = rotation[i];
391 r = omapfb_apply_changes(fbi, 0);
395 /* FIXME error handling? */
405 static ssize_t show_size(struct device *dev,
406 struct device_attribute *attr, char *buf)
408 struct fb_info *fbi = dev_get_drvdata(dev);
409 struct omapfb_info *ofbi = FB2OFB(fbi);
411 return snprintf(buf, PAGE_SIZE, "%lu\n", ofbi->region.size);
414 static ssize_t store_size(struct device *dev, struct device_attribute *attr,
415 const char *buf, size_t count)
417 struct fb_info *fbi = dev_get_drvdata(dev);
418 struct omapfb_info *ofbi = FB2OFB(fbi);
423 size = PAGE_ALIGN(simple_strtoul(buf, NULL, 0));
425 if (!lock_fb_info(fbi))
428 for (i = 0; i < ofbi->num_overlays; i++) {
429 if (ofbi->overlays[i]->info.enabled) {
435 if (size != ofbi->region.size) {
436 r = omapfb_realloc_fbmem(fbi, size, ofbi->region.type);
438 dev_err(dev, "realloc fbmem failed\n");
450 static ssize_t show_phys(struct device *dev,
451 struct device_attribute *attr, char *buf)
453 struct fb_info *fbi = dev_get_drvdata(dev);
454 struct omapfb_info *ofbi = FB2OFB(fbi);
456 return snprintf(buf, PAGE_SIZE, "%0x\n", ofbi->region.paddr);
459 static ssize_t show_virt(struct device *dev,
460 struct device_attribute *attr, char *buf)
462 struct fb_info *fbi = dev_get_drvdata(dev);
463 struct omapfb_info *ofbi = FB2OFB(fbi);
465 return snprintf(buf, PAGE_SIZE, "%p\n", ofbi->region.vaddr);
468 static struct device_attribute omapfb_attrs[] = {
469 __ATTR(rotate_type, S_IRUGO | S_IWUSR, show_rotate_type,
471 __ATTR(mirror, S_IRUGO | S_IWUSR, show_mirror, store_mirror),
472 __ATTR(size, S_IRUGO | S_IWUSR, show_size, store_size),
473 __ATTR(overlays, S_IRUGO | S_IWUSR, show_overlays, store_overlays),
474 __ATTR(overlays_rotate, S_IRUGO | S_IWUSR, show_overlays_rotate,
475 store_overlays_rotate),
476 __ATTR(phys_addr, S_IRUGO, show_phys, NULL),
477 __ATTR(virt_addr, S_IRUGO, show_virt, NULL),
480 int omapfb_create_sysfs(struct omapfb2_device *fbdev)
485 DBG("create sysfs for fbs\n");
486 for (i = 0; i < fbdev->num_fbs; i++) {
488 for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++) {
489 r = device_create_file(fbdev->fbs[i]->dev,
493 dev_err(fbdev->dev, "failed to create sysfs "
503 void omapfb_remove_sysfs(struct omapfb2_device *fbdev)
507 DBG("remove sysfs for fbs\n");
508 for (i = 0; i < fbdev->num_fbs; i++) {
509 for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++)
510 device_remove_file(fbdev->fbs[i]->dev,