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)
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 need to
76 * 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);
100 struct omapfb2_device *fbdev = ofbi->fbdev;
103 struct fb_var_screeninfo new_var;
105 mirror = simple_strtoul(buf, NULL, 0);
107 if (mirror != 0 && mirror != 1)
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);
128 omapfb_unlock(fbdev);
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 for (t = 0; t < ofbi->num_overlays; t++) {
143 struct omap_overlay *ovl = ofbi->overlays[t];
146 for (ovlnum = 0; ovlnum < fbdev->num_overlays; ++ovlnum)
147 if (ovl == fbdev->overlays[ovlnum])
150 l += snprintf(buf + l, PAGE_SIZE - l, "%s%d",
151 t == 0 ? "" : ",", ovlnum);
154 l += snprintf(buf + l, PAGE_SIZE - l, "\n");
159 static struct omapfb_info *get_overlay_fb(struct omapfb2_device *fbdev,
160 struct omap_overlay *ovl)
164 for (i = 0; i < fbdev->num_fbs; i++) {
165 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
167 for (t = 0; t < ofbi->num_overlays; t++) {
168 if (ofbi->overlays[t] == ovl)
176 static ssize_t store_overlays(struct device *dev, struct device_attribute *attr,
177 const char *buf, size_t count)
179 struct fb_info *fbi = dev_get_drvdata(dev);
180 struct omapfb_info *ofbi = FB2OFB(fbi);
181 struct omapfb2_device *fbdev = ofbi->fbdev;
182 struct omap_overlay *ovls[OMAPFB_MAX_OVL_PER_FB];
183 struct omap_overlay *ovl;
190 if (buf[len - 1] == '\n')
196 char *p = (char *)buf;
199 while (p < buf + len) {
201 if (num_ovls == OMAPFB_MAX_OVL_PER_FB) {
206 ovlnum = simple_strtoul(p, &p, 0);
207 if (ovlnum > fbdev->num_overlays) {
213 for (i = 0; i < num_ovls; ++i) {
214 if (ovls[i] == fbdev->overlays[ovlnum]) {
221 ovls[num_ovls++] = fbdev->overlays[ovlnum];
227 for (i = 0; i < num_ovls; ++i) {
228 struct omapfb_info *ofbi2 = get_overlay_fb(fbdev, ovls[i]);
229 if (ofbi2 && ofbi2 != ofbi) {
230 dev_err(fbdev->dev, "overlay already in use\n");
236 /* detach unused overlays */
237 for (i = 0; i < ofbi->num_overlays; ++i) {
240 ovl = ofbi->overlays[i];
244 for (t = 0; t < num_ovls; ++t) {
245 if (ovl == ovls[t]) {
254 DBG("detaching %d\n", ofbi->overlays[i]->id);
256 omapfb_overlay_enable(ovl, 0);
259 ovl->manager->apply(ovl->manager);
261 for (t = i + 1; t < ofbi->num_overlays; t++)
262 ofbi->overlays[t-1] = ofbi->overlays[t];
264 ofbi->num_overlays--;
268 for (i = 0; i < num_ovls; ++i) {
275 for (t = 0; t < ofbi->num_overlays; ++t) {
276 if (ovl == ofbi->overlays[t]) {
285 ofbi->overlays[ofbi->num_overlays++] = ovl;
287 r = omapfb_apply_changes(fbi, 1);
292 r = ovl->manager->apply(ovl->manager);
300 omapfb_unlock(fbdev);
305 static ssize_t show_size(struct device *dev,
306 struct device_attribute *attr, char *buf)
308 struct fb_info *fbi = dev_get_drvdata(dev);
309 struct omapfb_info *ofbi = FB2OFB(fbi);
311 return snprintf(buf, PAGE_SIZE, "%lu\n", ofbi->region.size);
314 static ssize_t store_size(struct device *dev, struct device_attribute *attr,
315 const char *buf, size_t count)
317 struct fb_info *fbi = dev_get_drvdata(dev);
318 struct omapfb_info *ofbi = FB2OFB(fbi);
319 struct omapfb2_device *fbdev = ofbi->fbdev;
324 size = PAGE_ALIGN(simple_strtoul(buf, NULL, 0));
328 for (i = 0; i < ofbi->num_overlays; i++) {
329 if (ofbi->overlays[i]->info.enabled) {
335 if (size != ofbi->region.size) {
336 r = omapfb_realloc_fbmem(fbi, size, ofbi->region.type);
338 dev_err(dev, "realloc fbmem failed\n");
345 omapfb_unlock(fbdev);
350 static ssize_t show_phys(struct device *dev,
351 struct device_attribute *attr, char *buf)
353 struct fb_info *fbi = dev_get_drvdata(dev);
354 struct omapfb_info *ofbi = FB2OFB(fbi);
356 return snprintf(buf, PAGE_SIZE, "%0x\n", ofbi->region.paddr);
359 static ssize_t show_virt(struct device *dev,
360 struct device_attribute *attr, char *buf)
362 struct fb_info *fbi = dev_get_drvdata(dev);
363 struct omapfb_info *ofbi = FB2OFB(fbi);
365 return snprintf(buf, PAGE_SIZE, "%p\n", ofbi->region.vaddr);
368 static struct device_attribute omapfb_attrs[] = {
369 __ATTR(rotate_type, S_IRUGO | S_IWUSR, show_rotate_type, store_rotate_type),
370 __ATTR(mirror, S_IRUGO | S_IWUSR, show_mirror, store_mirror),
371 __ATTR(size, S_IRUGO | S_IWUSR, show_size, store_size),
372 __ATTR(overlays, S_IRUGO | S_IWUSR, show_overlays, store_overlays),
373 __ATTR(phys_addr, S_IRUGO, show_phys, NULL),
374 __ATTR(virt_addr, S_IRUGO, show_virt, NULL),
377 int omapfb_create_sysfs(struct omapfb2_device *fbdev)
382 DBG("create sysfs for fbs\n");
383 for (i = 0; i < fbdev->num_fbs; i++) {
385 for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++) {
386 r = device_create_file(fbdev->fbs[i]->dev,
390 dev_err(fbdev->dev, "failed to create sysfs file\n");
399 void omapfb_remove_sysfs(struct omapfb2_device *fbdev)
403 DBG("remove sysfs for fbs\n");
404 for (i = 0; i < fbdev->num_fbs; i++) {
405 for (t = 0; t < ARRAY_SIZE(omapfb_attrs); t++)
406 device_remove_file(fbdev->fbs[i]->dev,