X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=drivers%2Fvideo%2Ffbsysfs.c;h=34e07399756b4ebd739792dff78abc1114dade2c;hb=862fc81b62c2d41a7e0b97b90844c80e59c7b0f1;hp=08dac9580d15440728d5c6374ec7c2de20a8e86c;hpb=5643f000c1e10ab991182478b76550e1364c3570;p=powerpc.git diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c index 08dac9580d..34e0739975 100644 --- a/drivers/video/fbsysfs.c +++ b/drivers/video/fbsysfs.c @@ -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,8 +204,7 @@ 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); } @@ -280,8 +275,7 @@ static ssize_t show_con_rotate(struct class_device *class_device, char *buf) 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; @@ -300,113 +294,21 @@ 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 = - (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->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 */ -/* the code will automatically adjust for different page sizes */ -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); - int rc, i, start, length, transp = 0; - - if ((count > PAGE_SIZE) || ((count % 16) != 0)) - return -EINVAL; - - if (!fb_info->fbops->fb_setcolreg && !fb_info->fbops->fb_setcmap) - return -EINVAL; - - sscanf(buf, "%02x", &start); - length = count / 16; - - for (i = 0; i < length; i++) - if (buf[i * 16 + 2] != ' ') - transp = 1; - - /* If we can batch, do it */ - if (fb_info->fbops->fb_setcmap && length > 1) { - struct fb_cmap umap; - - memset(&umap, 0, sizeof(umap)); - if ((rc = fb_alloc_cmap(&umap, length, transp))) - return rc; - - umap.start = start; - for (i = 0; i < length; i++) { - sscanf(&buf[i * 16 + 3], "%4hx", &umap.red[i]); - sscanf(&buf[i * 16 + 7], "%4hx", &umap.blue[i]); - sscanf(&buf[i * 16 + 11], "%4hx", &umap.green[i]); - if (transp) - umap.transp[i] = (buf[i * 16 + 2] != ' '); - } - rc = fb_info->fbops->fb_setcmap(&umap, fb_info); - fb_copy_cmap(&umap, &fb_info->cmap); - fb_dealloc_cmap(&umap); - - return rc; - } - for (i = 0; i < length; i++) { - u16 red, blue, green, tsp; - - sscanf(&buf[i * 16 + 3], "%4hx", &red); - sscanf(&buf[i * 16 + 7], "%4hx", &blue); - sscanf(&buf[i * 16 + 11], "%4hx", &green); - tsp = (buf[i * 16 + 2] != ' '); - if ((rc = fb_info->fbops->fb_setcolreg(start++, - red, green, blue, tsp, fb_info))) - return rc; - - fb_info->cmap.red[i] = red; - fb_info->cmap.blue[i] = blue; - fb_info->cmap.green[i] = green; - if (transp) - fb_info->cmap.transp[i] = tsp; - } - return 0; -} - -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); - unsigned int i; - - if (!fb_info->cmap.red || !fb_info->cmap.blue || - !fb_info->cmap.green) - return -EINVAL; - - if (fb_info->cmap.len > PAGE_SIZE / 16) - return -EINVAL; - - /* don't mess with the format, the buffer is PAGE_SIZE */ - /* 256 entries at 16 chars per line equals 4096 = PAGE_SIZE */ - for (i = 0; i < fb_info->cmap.len; i++) { - snprintf(&buf[ i * 16], PAGE_SIZE - i * 16, "%02x%c%4x%4x%4x\n", i + fb_info->cmap.start, - ((fb_info->cmap.transp && fb_info->cmap.transp[i]) ? '*' : ' '), - fb_info->cmap.red[i], fb_info->cmap.blue[i], - fb_info->cmap.green[i]); - } - return 16 * fb_info->cmap.len; -} - 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; @@ -422,41 +324,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; @@ -479,23 +380,46 @@ 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 = (struct fb_info *)class_get_devdata(class_device); + 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); +} + +/* When cmap is added back in it should be a binary attribute + * not a text one. Consideration should also be given to converting + * fbdev to use configfs instead of sysfs */ 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), - __ATTR(color_map, S_IRUGO|S_IWUSR, show_cmap, store_cmap), __ATTR(console, S_IRUGO|S_IWUSR, show_console, store_console), __ATTR(cursor, S_IRUGO|S_IWUSR, show_cursor, store_cursor), __ATTR(mode, S_IRUGO|S_IWUSR, show_mode, store_mode), @@ -507,6 +431,7 @@ static struct class_device_attribute class_device_attrs[] = { __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)