V4L/DVB (3518): Creates a virtual video device driver
[safe/jmp/linux-2.6] / drivers / video / fbsysfs.c
index ed1d4d1..6d26057 100644 (file)
@@ -43,10 +43,11 @@ struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
        if (size)
                fb_info_size += PADDING;
 
-       p = kmalloc(fb_info_size + size, GFP_KERNEL);
+       p = kzalloc(fb_info_size + size, GFP_KERNEL);
+
        if (!p)
                return NULL;
-       memset(p, 0, fb_info_size + size);
+
        info = (struct fb_info *) p;
 
        if (size)
@@ -106,8 +107,7 @@ static int mode_string(char *buf, unsigned int offset,
 static ssize_t store_mode(struct class_device *class_device, const char * buf,
                          size_t count)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        char mstr[100];
        struct fb_var_screeninfo var;
        struct fb_modelist *modelist;
@@ -137,8 +137,7 @@ static ssize_t store_mode(struct class_device *class_device, const char * buf,
 
 static ssize_t show_mode(struct class_device *class_device, char *buf)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
 
        if (!fb_info->mode)
                return 0;
@@ -149,8 +148,7 @@ static ssize_t show_mode(struct class_device *class_device, char *buf)
 static ssize_t store_modes(struct class_device *class_device, const char * buf,
                           size_t count)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        LIST_HEAD(old_list);
        int i = count / sizeof(struct fb_videomode);
 
@@ -174,8 +172,7 @@ static ssize_t store_modes(struct class_device *class_device, const char * buf,
 
 static ssize_t show_modes(struct class_device *class_device, char *buf)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        unsigned int i;
        struct list_head *pos;
        struct fb_modelist *modelist;
@@ -193,8 +190,7 @@ static ssize_t show_modes(struct class_device *class_device, char *buf)
 static ssize_t store_bpp(struct class_device *class_device, const char * buf,
                         size_t count)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        struct fb_var_screeninfo var;
        char ** last = NULL;
        int err;
@@ -208,16 +204,78 @@ static ssize_t store_bpp(struct class_device *class_device, const char * buf,
 
 static ssize_t show_bpp(struct class_device *class_device, char *buf)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.bits_per_pixel);
 }
 
+static ssize_t store_rotate(struct class_device *class_device, const char *buf,
+                           size_t count)
+{
+       struct fb_info *fb_info = class_get_devdata(class_device);
+       struct fb_var_screeninfo var;
+       char **last = NULL;
+       int err;
+
+       var = fb_info->var;
+       var.rotate = simple_strtoul(buf, last, 0);
+
+       if ((err = activate(fb_info, &var)))
+               return err;
+
+       return count;
+}
+
+
+static ssize_t show_rotate(struct class_device *class_device, char *buf)
+{
+       struct fb_info *fb_info = class_get_devdata(class_device);
+
+       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)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        struct fb_var_screeninfo var;
        char *last = NULL;
        int err;
@@ -236,12 +294,17 @@ static ssize_t store_virtual(struct class_device *class_device,
 
 static ssize_t show_virtual(struct class_device *class_device, char *buf)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xres_virtual,
                        fb_info->var.yres_virtual);
 }
 
+static ssize_t show_stride(struct class_device *class_device, char *buf)
+{
+       struct fb_info *fb_info = class_get_devdata(class_device);
+       return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->fix.line_length);
+}
+
 /* Format for cmap is "%02x%c%4x%4x%4x\n" */
 /* %02x entry %c transp %4x red %4x blue %4x green \n */
 /* 256 rows at 16 chars equals 4096, the normal page size */
@@ -249,7 +312,7 @@ static ssize_t show_virtual(struct class_device *class_device, char *buf)
 static ssize_t store_cmap(struct class_device *class_device, const char *buf,
                          size_t count)
 {
-       struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        int rc, i, start, length, transp = 0;
 
        if ((count > PAGE_SIZE) || ((count % 16) != 0))
@@ -309,8 +372,7 @@ static ssize_t store_cmap(struct class_device *class_device, const char *buf,
 
 static ssize_t show_cmap(struct class_device *class_device, char *buf)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        unsigned int i;
 
        if (!fb_info->cmap.red || !fb_info->cmap.blue ||
@@ -334,8 +396,7 @@ static ssize_t show_cmap(struct class_device *class_device, char *buf)
 static ssize_t store_blank(struct class_device *class_device, const char * buf,
                           size_t count)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        char *last = NULL;
        int err;
 
@@ -351,41 +412,40 @@ static ssize_t store_blank(struct class_device *class_device, const char * buf,
 
 static ssize_t show_blank(struct class_device *class_device, char *buf)
 {
-//     struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//     struct fb_info *fb_info = class_get_devdata(class_device);
        return 0;
 }
 
 static ssize_t store_console(struct class_device *class_device,
                             const char * buf, size_t count)
 {
-//     struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//     struct fb_info *fb_info = class_get_devdata(class_device);
        return 0;
 }
 
 static ssize_t show_console(struct class_device *class_device, char *buf)
 {
-//     struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//     struct fb_info *fb_info = class_get_devdata(class_device);
        return 0;
 }
 
 static ssize_t store_cursor(struct class_device *class_device,
                            const char * buf, size_t count)
 {
-//     struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//     struct fb_info *fb_info = class_get_devdata(class_device);
        return 0;
 }
 
 static ssize_t show_cursor(struct class_device *class_device, char *buf)
 {
-//     struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
+//     struct fb_info *fb_info = class_get_devdata(class_device);
        return 0;
 }
 
 static ssize_t store_pan(struct class_device *class_device, const char * buf,
                         size_t count)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        struct fb_var_screeninfo var;
        char *last = NULL;
        int err;
@@ -408,12 +468,40 @@ static ssize_t store_pan(struct class_device *class_device, const char * buf,
 
 static ssize_t show_pan(struct class_device *class_device, char *buf)
 {
-       struct fb_info *fb_info =
-               (struct fb_info *)class_get_devdata(class_device);
+       struct fb_info *fb_info = class_get_devdata(class_device);
        return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xoffset,
                        fb_info->var.xoffset);
 }
 
+static ssize_t show_name(struct class_device *class_device, char *buf)
+{
+       struct fb_info *fb_info = class_get_devdata(class_device);
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", fb_info->fix.id);
+}
+
+static ssize_t store_fbstate(struct class_device *class_device,
+                       const char *buf, size_t count)
+{
+       struct fb_info *fb_info = class_get_devdata(class_device);
+       u32 state;
+       char *last = NULL;
+
+       state = simple_strtoul(buf, &last, 0);
+
+       acquire_console_sem();
+       fb_set_suspend(fb_info, (int)state);
+       release_console_sem();
+
+       return count;
+}
+
+static ssize_t show_fbstate(struct class_device *class_device, char *buf)
+{
+       struct fb_info *fb_info = class_get_devdata(class_device);
+       return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->state);
+}
+
 static struct class_device_attribute class_device_attrs[] = {
        __ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp),
        __ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank),
@@ -424,6 +512,12 @@ static struct class_device_attribute class_device_attrs[] = {
        __ATTR(modes, S_IRUGO|S_IWUSR, show_modes, store_modes),
        __ATTR(pan, S_IRUGO|S_IWUSR, show_pan, store_pan),
        __ATTR(virtual_size, S_IRUGO|S_IWUSR, show_virtual, store_virtual),
+       __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),
 };
 
 int fb_init_class_device(struct fb_info *fb_info)