]> err.no Git - linux-2.6/blobdiff - drivers/video/fbsysfs.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-2.6
[linux-2.6] / drivers / video / fbsysfs.c
index 6de02189abbef378733a06c417d5fd95059b30de..d3a50417ed9a6ab09d16841e435597bf8f6da312 100644 (file)
@@ -20,6 +20,8 @@
 #include <linux/console.h>
 #include <linux/module.h>
 
+#define FB_SYSFS_FLAG_ATTR 1
+
 /**
  * framebuffer_alloc - creates a new frame buffer info structure
  *
@@ -247,45 +249,6 @@ static ssize_t show_rotate(struct class_device *class_device, char *buf)
        return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.rotate);
 }
 
-static ssize_t store_con_rotate(struct class_device *class_device,
-                               const char *buf, size_t count)
-{
-       struct fb_info *fb_info = class_get_devdata(class_device);
-       int rotate;
-       char **last = NULL;
-
-       acquire_console_sem();
-       rotate = simple_strtoul(buf, last, 0);
-       fb_con_duit(fb_info, FB_EVENT_SET_CON_ROTATE, &rotate);
-       release_console_sem();
-       return count;
-}
-
-static ssize_t store_con_rotate_all(struct class_device *class_device,
-                               const char *buf, size_t count)
-{
-       struct fb_info *fb_info = class_get_devdata(class_device);
-       int rotate;
-       char **last = NULL;
-
-       acquire_console_sem();
-       rotate = simple_strtoul(buf, last, 0);
-       fb_con_duit(fb_info, FB_EVENT_SET_CON_ROTATE_ALL, &rotate);
-       release_console_sem();
-       return count;
-}
-
-static ssize_t show_con_rotate(struct class_device *class_device, char *buf)
-{
-       struct fb_info *fb_info = class_get_devdata(class_device);
-       int rotate;
-
-       acquire_console_sem();
-       rotate = fb_con_duit(fb_info, FB_EVENT_GET_CON_ROTATE, NULL);
-       release_console_sem();
-       return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
-}
-
 static ssize_t store_virtual(struct class_device *class_device,
                             const char * buf, size_t count)
 {
@@ -436,6 +399,12 @@ static ssize_t store_bl_curve(struct class_device *class_device,
        u8 tmp_curve[FB_BACKLIGHT_LEVELS];
        unsigned int i;
 
+       /* Some drivers don't use framebuffer_alloc(), but those also
+        * don't have backlights.
+        */
+       if (!fb_info || !fb_info->bl_dev)
+               return -ENODEV;
+
        if (count != (FB_BACKLIGHT_LEVELS / 8 * 24))
                return -EINVAL;
 
@@ -469,6 +438,12 @@ static ssize_t show_bl_curve(struct class_device *class_device, char *buf)
        ssize_t len = 0;
        unsigned int i;
 
+       /* Some drivers don't use framebuffer_alloc(), but those also
+        * don't have backlights.
+        */
+       if (!fb_info || !fb_info->bl_dev)
+               return -ENODEV;
+
        mutex_lock(&fb_info->bl_mutex);
        for (i = 0; i < FB_BACKLIGHT_LEVELS; i += 8)
                len += snprintf(&buf[len], PAGE_SIZE,
@@ -502,8 +477,6 @@ static struct class_device_attribute class_device_attrs[] = {
        __ATTR(name, S_IRUGO, show_name, NULL),
        __ATTR(stride, S_IRUGO, show_stride, NULL),
        __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
-       __ATTR(con_rotate, S_IRUGO|S_IWUSR, show_con_rotate, store_con_rotate),
-       __ATTR(con_rotate_all, S_IWUSR, NULL, store_con_rotate_all),
        __ATTR(state, S_IRUGO|S_IWUSR, show_fbstate, store_fbstate),
 #ifdef CONFIG_FB_BACKLIGHT
        __ATTR(bl_curve, S_IRUGO|S_IWUSR, show_bl_curve, store_bl_curve),
@@ -512,12 +485,27 @@ static struct class_device_attribute class_device_attrs[] = {
 
 int fb_init_class_device(struct fb_info *fb_info)
 {
-       unsigned int i;
+       int i, error = 0;
+
        class_set_devdata(fb_info->class_device, fb_info);
 
-       for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
-               class_device_create_file(fb_info->class_device,
-                                        &class_device_attrs[i]);
+       fb_info->class_flag |= FB_SYSFS_FLAG_ATTR;
+
+       for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
+               error = class_device_create_file(fb_info->class_device,
+                                                &class_device_attrs[i]);
+
+               if (error)
+                       break;
+       }
+
+       if (error) {
+               while (--i >= 0)
+                       class_device_remove_file(fb_info->class_device,
+                                                &class_device_attrs[i]);
+               fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
+       }
+
        return 0;
 }
 
@@ -525,9 +513,13 @@ void fb_cleanup_class_device(struct fb_info *fb_info)
 {
        unsigned int i;
 
-       for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
-               class_device_remove_file(fb_info->class_device,
-                                        &class_device_attrs[i]);
+       if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) {
+               for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
+                       class_device_remove_file(fb_info->class_device,
+                                                &class_device_attrs[i]);
+
+               fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
+       }
 }
 
 #ifdef CONFIG_FB_BACKLIGHT