Re: [PATCH][RFC][2/3] mode attribute in sysfs tree
From: Kronos <hidden>
Date: 2004-06-16 09:30:30
fb_show_mode function and FB_MODE_ATTR macro. diff -Nru -X dontdiff linux-2.6-vanilla/drivers/video/fbsysfs.c linux-2.6/drivers/video/fbsysfs.c
--- linux-2.6-vanilla/drivers/video/fbsysfs.c 2004-02-28 13:32:58.000000000 +0100
+++ linux-2.6/drivers/video/fbsysfs.c 2004-06-14 17:34:15.000000000 +0200@@ -70,5 +70,32 @@ kfree(info); } +ssize_t fb_show_mode(struct class_device *class_dev, char * buf) { + struct fb_info *info = class_get_devdata(class_dev); + struct fb_var_screeninfo *var = &info->var; + + u32 htotal = var->xres + var->upper_margin + var->lower_margin + var->hsync_len; + u32 vtotal = var->yres + var->left_margin + var->right_margin + var->vsync_len; + + if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) + vtotal = vtotal << 2; + else if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED) + vtotal = vtotal << 1; + + /* + * This should be: + * 1000000000000 + * ------------------------------- * 2 + * var->pixclock * htotal * vtotal + * + * we divide numerator and pixclock by 1000 so the expression does not overflow. + */ + u32 refresh = 1000000000UL / ((var->pixclock / 1000) * htotal * vtotal) * 2; + + return snprintf(buf, PAGE_SIZE, "%ux%u-%u@%u\n", var->xres, var->yres, + var->bits_per_pixel, refresh); +} + +EXPORT_SYMBOL(fb_show_mode); EXPORT_SYMBOL(framebuffer_release); EXPORT_SYMBOL(framebuffer_alloc);
diff -Nru -X dontdiff linux-2.6-vanilla/include/linux/fb.h linux-2.6/include/linux/fb.h
--- linux-2.6-vanilla/include/linux/fb.h 2004-06-15 15:38:40.000000000 +0200
+++ linux-2.6/include/linux/fb.h 2004-06-14 17:34:28.000000000 +0200@@ -611,6 +611,15 @@ /* drivers/video/fbsysfs.c */ extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev); extern void framebuffer_release(struct fb_info *info); +extern ssize_t fb_show_mode(struct class_device *class_dev, char * buf); + +#define FB_MODE_ATTR(_name) \ +struct class_device_attribute _name = { \ + .attr = {.name = "mode", .mode = 0444, .owner = THIS_MODULE }, \ + .show = fb_show_mode, \ + .store = NULL, \ +}; + /* drivers/video/fbmon.c */ #define FB_MAXTIMINGS 0
Luca -- Home: http://kronoz.cjb.net Not an editor command: Wq ------------------------------------------------------- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND