Merge branch 'for-linus' of git://git.o-hand.com/linux-rpurdie-backlight

* 'for-linus' of git://git.o-hand.com/linux-rpurdie-backlight:
leds: cr_bllcd.c: build fix
backlight: Convert from struct class_device to struct device
backlight: Fix order of Kconfig entries

+149 -163
+2 -2
drivers/acpi/video.c
··· 284 { 285 unsigned long cur_level; 286 struct acpi_video_device *vd = 287 - (struct acpi_video_device *)class_get_devdata(&bd->class_dev); 288 acpi_video_device_lcd_get_level_current(vd, &cur_level); 289 return (int) cur_level; 290 } ··· 293 { 294 int request_level = bd->props.brightness; 295 struct acpi_video_device *vd = 296 - (struct acpi_video_device *)class_get_devdata(&bd->class_dev); 297 acpi_video_device_lcd_set_level(vd, request_level); 298 return 0; 299 }
··· 284 { 285 unsigned long cur_level; 286 struct acpi_video_device *vd = 287 + (struct acpi_video_device *)bl_get_data(bd); 288 acpi_video_device_lcd_get_level_current(vd, &cur_level); 289 return (int) cur_level; 290 } ··· 293 { 294 int request_level = bd->props.brightness; 295 struct acpi_video_device *vd = 296 + (struct acpi_video_device *)bl_get_data(bd); 297 acpi_video_device_lcd_set_level(vd, request_level); 298 return 0; 299 }
+2 -2
drivers/usb/misc/appledisplay.c
··· 138 139 static int appledisplay_bl_update_status(struct backlight_device *bd) 140 { 141 - struct appledisplay *pdata = class_get_devdata(&bd->class_dev); 142 int retval; 143 144 pdata->msgdata[0] = 0x10; ··· 159 160 static int appledisplay_bl_get_brightness(struct backlight_device *bd) 161 { 162 - struct appledisplay *pdata = class_get_devdata(&bd->class_dev); 163 int retval; 164 165 retval = usb_control_msg(
··· 138 139 static int appledisplay_bl_update_status(struct backlight_device *bd) 140 { 141 + struct appledisplay *pdata = bl_get_data(bd); 142 int retval; 143 144 pdata->msgdata[0] = 0x10; ··· 159 160 static int appledisplay_bl_get_brightness(struct backlight_device *bd) 161 { 162 + struct appledisplay *pdata = bl_get_data(bd); 163 int retval; 164 165 retval = usb_control_msg(
+1 -1
drivers/video/aty/aty128fb.c
··· 1733 1734 static int aty128_bl_update_status(struct backlight_device *bd) 1735 { 1736 - struct aty128fb_par *par = class_get_devdata(&bd->class_dev); 1737 unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL); 1738 int level; 1739
··· 1733 1734 static int aty128_bl_update_status(struct backlight_device *bd) 1735 { 1736 + struct aty128fb_par *par = bl_get_data(bd); 1737 unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL); 1738 int level; 1739
+1 -1
drivers/video/aty/atyfb_base.c
··· 2141 2142 static int aty_bl_update_status(struct backlight_device *bd) 2143 { 2144 - struct atyfb_par *par = class_get_devdata(&bd->class_dev); 2145 unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par); 2146 int level; 2147
··· 2141 2142 static int aty_bl_update_status(struct backlight_device *bd) 2143 { 2144 + struct atyfb_par *par = bl_get_data(bd); 2145 unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par); 2146 int level; 2147
+2 -2
drivers/video/aty/radeon_backlight.c
··· 47 48 static int radeon_bl_update_status(struct backlight_device *bd) 49 { 50 - struct radeon_bl_privdata *pdata = class_get_devdata(&bd->class_dev); 51 struct radeonfb_info *rinfo = pdata->rinfo; 52 u32 lvds_gen_cntl, tmpPixclksCntl; 53 int level; ··· 206 if (bd) { 207 struct radeon_bl_privdata *pdata; 208 209 - pdata = class_get_devdata(&bd->class_dev); 210 backlight_device_unregister(bd); 211 kfree(pdata); 212 rinfo->info->bl_dev = NULL;
··· 47 48 static int radeon_bl_update_status(struct backlight_device *bd) 49 { 50 + struct radeon_bl_privdata *pdata = bl_get_data(bd); 51 struct radeonfb_info *rinfo = pdata->rinfo; 52 u32 lvds_gen_cntl, tmpPixclksCntl; 53 int level; ··· 206 if (bd) { 207 struct radeon_bl_privdata *pdata; 208 209 + pdata = bl_get_data(bd); 210 backlight_device_unregister(bd); 211 kfree(pdata); 212 rinfo->info->bl_dev = NULL;
+17 -11
drivers/video/backlight/Kconfig
··· 8 Enable this to be able to choose the drivers for controlling the 9 backlight and the LCD panel on some platforms, for example on PDAs. 10 11 - config BACKLIGHT_CLASS_DEVICE 12 - tristate "Lowlevel Backlight controls" 13 - depends on BACKLIGHT_LCD_SUPPORT 14 - default m 15 - help 16 - This framework adds support for low-level control of the LCD 17 - backlight. This includes support for brightness and power. 18 - 19 - To have support for your specific LCD panel you will have to 20 - select the proper drivers which depend on this option. 21 - 22 config LCD_CLASS_DEVICE 23 tristate "Lowlevel LCD controls" 24 depends on BACKLIGHT_LCD_SUPPORT ··· 20 Some framebuffer devices connect to platform-specific LCD modules 21 in order to have a platform-specific way to control the flat panel 22 (contrast and applying power to the LCD (not to the backlight!)). 23 24 To have support for your specific LCD panel you will have to 25 select the proper drivers which depend on this option.
··· 8 Enable this to be able to choose the drivers for controlling the 9 backlight and the LCD panel on some platforms, for example on PDAs. 10 11 + # 12 + # LCD 13 + # 14 config LCD_CLASS_DEVICE 15 tristate "Lowlevel LCD controls" 16 depends on BACKLIGHT_LCD_SUPPORT ··· 28 Some framebuffer devices connect to platform-specific LCD modules 29 in order to have a platform-specific way to control the flat panel 30 (contrast and applying power to the LCD (not to the backlight!)). 31 + 32 + To have support for your specific LCD panel you will have to 33 + select the proper drivers which depend on this option. 34 + 35 + # 36 + # Backlight 37 + # 38 + config BACKLIGHT_CLASS_DEVICE 39 + tristate "Lowlevel Backlight controls" 40 + depends on BACKLIGHT_LCD_SUPPORT 41 + default m 42 + help 43 + This framework adds support for low-level control of the LCD 44 + backlight. This includes support for brightness and power. 45 46 To have support for your specific LCD panel you will have to 47 select the proper drivers which depend on this option.
+53 -72
drivers/video/backlight/backlight.c
··· 69 } 70 #endif /* CONFIG_FB */ 71 72 - static ssize_t backlight_show_power(struct class_device *cdev, char *buf) 73 { 74 - struct backlight_device *bd = to_backlight_device(cdev); 75 76 return sprintf(buf, "%d\n", bd->props.power); 77 } 78 79 - static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) 80 { 81 int rc = -ENXIO; 82 char *endp; 83 - struct backlight_device *bd = to_backlight_device(cdev); 84 int power = simple_strtoul(buf, &endp, 0); 85 size_t size = endp - buf; 86 ··· 103 return rc; 104 } 105 106 - static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) 107 { 108 - struct backlight_device *bd = to_backlight_device(cdev); 109 110 return sprintf(buf, "%d\n", bd->props.brightness); 111 } 112 113 - static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) 114 { 115 int rc = -ENXIO; 116 char *endp; 117 - struct backlight_device *bd = to_backlight_device(cdev); 118 int brightness = simple_strtoul(buf, &endp, 0); 119 size_t size = endp - buf; 120 ··· 142 return rc; 143 } 144 145 - static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf) 146 { 147 - struct backlight_device *bd = to_backlight_device(cdev); 148 149 return sprintf(buf, "%d\n", bd->props.max_brightness); 150 } 151 152 - static ssize_t backlight_show_actual_brightness(struct class_device *cdev, 153 - char *buf) 154 { 155 int rc = -ENXIO; 156 - struct backlight_device *bd = to_backlight_device(cdev); 157 158 mutex_lock(&bd->ops_lock); 159 if (bd->ops && bd->ops->get_brightness) ··· 164 return rc; 165 } 166 167 - static void backlight_class_release(struct class_device *dev) 168 { 169 struct backlight_device *bd = to_backlight_device(dev); 170 kfree(bd); 171 } 172 173 - static struct class backlight_class = { 174 - .name = "backlight", 175 - .release = backlight_class_release, 176 - }; 177 - 178 - #define DECLARE_ATTR(_name,_mode,_show,_store) \ 179 - { \ 180 - .attr = { .name = __stringify(_name), .mode = _mode }, \ 181 - .show = _show, \ 182 - .store = _store, \ 183 - } 184 - 185 - static const struct class_device_attribute bl_class_device_attributes[] = { 186 - DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power), 187 - DECLARE_ATTR(brightness, 0644, backlight_show_brightness, 188 backlight_store_brightness), 189 - DECLARE_ATTR(actual_brightness, 0444, backlight_show_actual_brightness, 190 NULL), 191 - DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), 192 }; 193 194 /** ··· 187 * backlight_device class. 188 * @name: the name of the new object(must be the same as the name of the 189 * respective framebuffer device). 190 - * @devdata: an optional pointer to be stored in the class_device. The 191 - * methods may retrieve it by using class_get_devdata(&bd->class_dev). 192 * @ops: the backlight operations structure. 193 * 194 - * Creates and registers new backlight class_device. Returns either an 195 * ERR_PTR() or a pointer to the newly allocated device. 196 */ 197 struct backlight_device *backlight_device_register(const char *name, 198 - struct device *dev, 199 - void *devdata, 200 - struct backlight_ops *ops) 201 { 202 - int i, rc; 203 struct backlight_device *new_bd; 204 205 - pr_debug("backlight_device_alloc: name=%s\n", name); 206 207 new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL); 208 if (!new_bd) ··· 208 209 mutex_init(&new_bd->update_lock); 210 mutex_init(&new_bd->ops_lock); 211 - new_bd->ops = ops; 212 - new_bd->class_dev.class = &backlight_class; 213 - new_bd->class_dev.dev = dev; 214 - strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN); 215 - class_set_devdata(&new_bd->class_dev, devdata); 216 217 - rc = class_device_register(&new_bd->class_dev); 218 if (rc) { 219 kfree(new_bd); 220 return ERR_PTR(rc); ··· 223 224 rc = backlight_register_fb(new_bd); 225 if (rc) { 226 - class_device_unregister(&new_bd->class_dev); 227 return ERR_PTR(rc); 228 } 229 230 - 231 - for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) { 232 - rc = class_device_create_file(&new_bd->class_dev, 233 - &bl_class_device_attributes[i]); 234 - if (rc) { 235 - while (--i >= 0) 236 - class_device_remove_file(&new_bd->class_dev, 237 - &bl_class_device_attributes[i]); 238 - class_device_unregister(&new_bd->class_dev); 239 - /* No need to kfree(new_bd) since release() method was called */ 240 - return ERR_PTR(rc); 241 - } 242 - } 243 244 #ifdef CONFIG_PMAC_BACKLIGHT 245 mutex_lock(&pmac_backlight_mutex); ··· 248 */ 249 void backlight_device_unregister(struct backlight_device *bd) 250 { 251 - int i; 252 - 253 if (!bd) 254 return; 255 - 256 - pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id); 257 258 #ifdef CONFIG_PMAC_BACKLIGHT 259 mutex_lock(&pmac_backlight_mutex); ··· 257 pmac_backlight = NULL; 258 mutex_unlock(&pmac_backlight_mutex); 259 #endif 260 - 261 - for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) 262 - class_device_remove_file(&bd->class_dev, 263 - &bl_class_device_attributes[i]); 264 - 265 mutex_lock(&bd->ops_lock); 266 bd->ops = NULL; 267 mutex_unlock(&bd->ops_lock); 268 269 backlight_unregister_fb(bd); 270 - 271 - class_device_unregister(&bd->class_dev); 272 } 273 EXPORT_SYMBOL(backlight_device_unregister); 274 275 static void __exit backlight_class_exit(void) 276 { 277 - class_unregister(&backlight_class); 278 } 279 280 static int __init backlight_class_init(void) 281 { 282 - return class_register(&backlight_class); 283 } 284 285 /*
··· 69 } 70 #endif /* CONFIG_FB */ 71 72 + static ssize_t backlight_show_power(struct device *dev, 73 + struct device_attribute *attr,char *buf) 74 { 75 + struct backlight_device *bd = to_backlight_device(dev); 76 77 return sprintf(buf, "%d\n", bd->props.power); 78 } 79 80 + static ssize_t backlight_store_power(struct device *dev, 81 + struct device_attribute *attr, const char *buf, size_t count) 82 { 83 int rc = -ENXIO; 84 char *endp; 85 + struct backlight_device *bd = to_backlight_device(dev); 86 int power = simple_strtoul(buf, &endp, 0); 87 size_t size = endp - buf; 88 ··· 101 return rc; 102 } 103 104 + static ssize_t backlight_show_brightness(struct device *dev, 105 + struct device_attribute *attr, char *buf) 106 { 107 + struct backlight_device *bd = to_backlight_device(dev); 108 109 return sprintf(buf, "%d\n", bd->props.brightness); 110 } 111 112 + static ssize_t backlight_store_brightness(struct device *dev, 113 + struct device_attribute *attr, const char *buf, size_t count) 114 { 115 int rc = -ENXIO; 116 char *endp; 117 + struct backlight_device *bd = to_backlight_device(dev); 118 int brightness = simple_strtoul(buf, &endp, 0); 119 size_t size = endp - buf; 120 ··· 138 return rc; 139 } 140 141 + static ssize_t backlight_show_max_brightness(struct device *dev, 142 + struct device_attribute *attr, char *buf) 143 { 144 + struct backlight_device *bd = to_backlight_device(dev); 145 146 return sprintf(buf, "%d\n", bd->props.max_brightness); 147 } 148 149 + static ssize_t backlight_show_actual_brightness(struct device *dev, 150 + struct device_attribute *attr, char *buf) 151 { 152 int rc = -ENXIO; 153 + struct backlight_device *bd = to_backlight_device(dev); 154 155 mutex_lock(&bd->ops_lock); 156 if (bd->ops && bd->ops->get_brightness) ··· 159 return rc; 160 } 161 162 + struct class *backlight_class; 163 + 164 + static void bl_device_release(struct device *dev) 165 { 166 struct backlight_device *bd = to_backlight_device(dev); 167 kfree(bd); 168 } 169 170 + static struct device_attribute bl_device_attributes[] = { 171 + __ATTR(bl_power, 0644, backlight_show_power, backlight_store_power), 172 + __ATTR(brightness, 0644, backlight_show_brightness, 173 backlight_store_brightness), 174 + __ATTR(actual_brightness, 0444, backlight_show_actual_brightness, 175 NULL), 176 + __ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), 177 + __ATTR_NULL, 178 }; 179 180 /** ··· 191 * backlight_device class. 192 * @name: the name of the new object(must be the same as the name of the 193 * respective framebuffer device). 194 + * @devdata: an optional pointer to be stored for private driver use. The 195 + * methods may retrieve it by using bl_get_data(bd). 196 * @ops: the backlight operations structure. 197 * 198 + * Creates and registers new backlight device. Returns either an 199 * ERR_PTR() or a pointer to the newly allocated device. 200 */ 201 struct backlight_device *backlight_device_register(const char *name, 202 + struct device *parent, void *devdata, struct backlight_ops *ops) 203 { 204 struct backlight_device *new_bd; 205 + int rc; 206 207 + pr_debug("backlight_device_register: name=%s\n", name); 208 209 new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL); 210 if (!new_bd) ··· 214 215 mutex_init(&new_bd->update_lock); 216 mutex_init(&new_bd->ops_lock); 217 218 + new_bd->dev.class = backlight_class; 219 + new_bd->dev.parent = parent; 220 + new_bd->dev.release = bl_device_release; 221 + strlcpy(new_bd->dev.bus_id, name, BUS_ID_SIZE); 222 + dev_set_drvdata(&new_bd->dev, devdata); 223 + 224 + rc = device_register(&new_bd->dev); 225 if (rc) { 226 kfree(new_bd); 227 return ERR_PTR(rc); ··· 228 229 rc = backlight_register_fb(new_bd); 230 if (rc) { 231 + device_unregister(&new_bd->dev); 232 return ERR_PTR(rc); 233 } 234 235 + new_bd->ops = ops; 236 237 #ifdef CONFIG_PMAC_BACKLIGHT 238 mutex_lock(&pmac_backlight_mutex); ··· 265 */ 266 void backlight_device_unregister(struct backlight_device *bd) 267 { 268 if (!bd) 269 return; 270 271 #ifdef CONFIG_PMAC_BACKLIGHT 272 mutex_lock(&pmac_backlight_mutex); ··· 278 pmac_backlight = NULL; 279 mutex_unlock(&pmac_backlight_mutex); 280 #endif 281 mutex_lock(&bd->ops_lock); 282 bd->ops = NULL; 283 mutex_unlock(&bd->ops_lock); 284 285 backlight_unregister_fb(bd); 286 + device_unregister(&bd->dev); 287 } 288 EXPORT_SYMBOL(backlight_device_unregister); 289 290 static void __exit backlight_class_exit(void) 291 { 292 + class_destroy(backlight_class); 293 } 294 295 static int __init backlight_class_init(void) 296 { 297 + backlight_class = class_create(THIS_MODULE, "backlight"); 298 + if (IS_ERR(backlight_class)) { 299 + printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n", 300 + PTR_ERR(backlight_class)); 301 + return PTR_ERR(backlight_class); 302 + } 303 + 304 + backlight_class->dev_attrs = bl_device_attributes; 305 + return 0; 306 } 307 308 /*
+1 -1
drivers/video/backlight/cr_bllcd.c
··· 202 } 203 204 crp->cr_lcd_device = lcd_device_register("cr-lcd", 205 - &pdev->dev, 206 &cr_lcd_ops); 207 208 if (IS_ERR(crp->cr_lcd_device)) {
··· 202 } 203 204 crp->cr_lcd_device = lcd_device_register("cr-lcd", 205 + &pdev->dev, NULL, 206 &cr_lcd_ops); 207 208 if (IS_ERR(crp->cr_lcd_device)) {
+50 -62
drivers/video/backlight/lcd.c
··· 61 } 62 #endif /* CONFIG_FB */ 63 64 - static ssize_t lcd_show_power(struct class_device *cdev, char *buf) 65 { 66 int rc; 67 - struct lcd_device *ld = to_lcd_device(cdev); 68 69 mutex_lock(&ld->ops_lock); 70 if (ld->ops && ld->ops->get_power) ··· 77 return rc; 78 } 79 80 - static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_t count) 81 { 82 int rc = -ENXIO; 83 char *endp; 84 - struct lcd_device *ld = to_lcd_device(cdev); 85 int power = simple_strtoul(buf, &endp, 0); 86 size_t size = endp - buf; 87 ··· 102 return rc; 103 } 104 105 - static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf) 106 { 107 int rc = -ENXIO; 108 - struct lcd_device *ld = to_lcd_device(cdev); 109 110 mutex_lock(&ld->ops_lock); 111 if (ld->ops && ld->ops->get_contrast) ··· 116 return rc; 117 } 118 119 - static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, size_t count) 120 { 121 int rc = -ENXIO; 122 char *endp; 123 - struct lcd_device *ld = to_lcd_device(cdev); 124 int contrast = simple_strtoul(buf, &endp, 0); 125 size_t size = endp - buf; 126 ··· 141 return rc; 142 } 143 144 - static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf) 145 { 146 - struct lcd_device *ld = to_lcd_device(cdev); 147 148 return sprintf(buf, "%d\n", ld->props.max_contrast); 149 } 150 151 - static void lcd_class_release(struct class_device *dev) 152 { 153 struct lcd_device *ld = to_lcd_device(dev); 154 kfree(ld); 155 } 156 157 - static struct class lcd_class = { 158 - .name = "lcd", 159 - .release = lcd_class_release, 160 - }; 161 - 162 - #define DECLARE_ATTR(_name,_mode,_show,_store) \ 163 - { \ 164 - .attr = { .name = __stringify(_name), .mode = _mode }, \ 165 - .show = _show, \ 166 - .store = _store, \ 167 - } 168 - 169 - static const struct class_device_attribute lcd_class_device_attributes[] = { 170 - DECLARE_ATTR(power, 0644, lcd_show_power, lcd_store_power), 171 - DECLARE_ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast), 172 - DECLARE_ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL), 173 }; 174 175 /** 176 * lcd_device_register - register a new object of lcd_device class. 177 * @name: the name of the new object(must be the same as the name of the 178 * respective framebuffer device). 179 - * @devdata: an optional pointer to be stored in the class_device. The 180 - * methods may retrieve it by using class_get_devdata(ld->class_dev). 181 * @ops: the lcd operations structure. 182 * 183 - * Creates and registers a new lcd class_device. Returns either an ERR_PTR() 184 * or a pointer to the newly allocated device. 185 */ 186 - struct lcd_device *lcd_device_register(const char *name, void *devdata, 187 - struct lcd_ops *ops) 188 { 189 - int i, rc; 190 struct lcd_device *new_ld; 191 192 pr_debug("lcd_device_register: name=%s\n", name); 193 ··· 189 190 mutex_init(&new_ld->ops_lock); 191 mutex_init(&new_ld->update_lock); 192 - new_ld->ops = ops; 193 - new_ld->class_dev.class = &lcd_class; 194 - strlcpy(new_ld->class_dev.class_id, name, KOBJ_NAME_LEN); 195 - class_set_devdata(&new_ld->class_dev, devdata); 196 197 - rc = class_device_register(&new_ld->class_dev); 198 if (rc) { 199 kfree(new_ld); 200 return ERR_PTR(rc); ··· 204 205 rc = lcd_register_fb(new_ld); 206 if (rc) { 207 - class_device_unregister(&new_ld->class_dev); 208 return ERR_PTR(rc); 209 } 210 211 - for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) { 212 - rc = class_device_create_file(&new_ld->class_dev, 213 - &lcd_class_device_attributes[i]); 214 - if (rc) { 215 - while (--i >= 0) 216 - class_device_remove_file(&new_ld->class_dev, 217 - &lcd_class_device_attributes[i]); 218 - class_device_unregister(&new_ld->class_dev); 219 - /* No need to kfree(new_ld) since release() method was called */ 220 - return ERR_PTR(rc); 221 - } 222 - } 223 224 return new_ld; 225 } ··· 222 */ 223 void lcd_device_unregister(struct lcd_device *ld) 224 { 225 - int i; 226 - 227 if (!ld) 228 return; 229 - 230 - pr_debug("lcd_device_unregister: name=%s\n", ld->class_dev.class_id); 231 - 232 - for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) 233 - class_device_remove_file(&ld->class_dev, 234 - &lcd_class_device_attributes[i]); 235 236 mutex_lock(&ld->ops_lock); 237 ld->ops = NULL; 238 mutex_unlock(&ld->ops_lock); 239 lcd_unregister_fb(ld); 240 - class_device_unregister(&ld->class_dev); 241 } 242 EXPORT_SYMBOL(lcd_device_unregister); 243 244 static void __exit lcd_class_exit(void) 245 { 246 - class_unregister(&lcd_class); 247 } 248 249 static int __init lcd_class_init(void) 250 { 251 - return class_register(&lcd_class); 252 } 253 254 /*
··· 61 } 62 #endif /* CONFIG_FB */ 63 64 + static ssize_t lcd_show_power(struct device *dev, struct device_attribute *attr, 65 + char *buf) 66 { 67 int rc; 68 + struct lcd_device *ld = to_lcd_device(dev); 69 70 mutex_lock(&ld->ops_lock); 71 if (ld->ops && ld->ops->get_power) ··· 76 return rc; 77 } 78 79 + static ssize_t lcd_store_power(struct device *dev, 80 + struct device_attribute *attr, const char *buf, size_t count) 81 { 82 int rc = -ENXIO; 83 char *endp; 84 + struct lcd_device *ld = to_lcd_device(dev); 85 int power = simple_strtoul(buf, &endp, 0); 86 size_t size = endp - buf; 87 ··· 100 return rc; 101 } 102 103 + static ssize_t lcd_show_contrast(struct device *dev, 104 + struct device_attribute *attr, char *buf) 105 { 106 int rc = -ENXIO; 107 + struct lcd_device *ld = to_lcd_device(dev); 108 109 mutex_lock(&ld->ops_lock); 110 if (ld->ops && ld->ops->get_contrast) ··· 113 return rc; 114 } 115 116 + static ssize_t lcd_store_contrast(struct device *dev, 117 + struct device_attribute *attr, const char *buf, size_t count) 118 { 119 int rc = -ENXIO; 120 char *endp; 121 + struct lcd_device *ld = to_lcd_device(dev); 122 int contrast = simple_strtoul(buf, &endp, 0); 123 size_t size = endp - buf; 124 ··· 137 return rc; 138 } 139 140 + static ssize_t lcd_show_max_contrast(struct device *dev, 141 + struct device_attribute *attr, char *buf) 142 { 143 + struct lcd_device *ld = to_lcd_device(dev); 144 145 return sprintf(buf, "%d\n", ld->props.max_contrast); 146 } 147 148 + struct class *lcd_class; 149 + 150 + static void lcd_device_release(struct device *dev) 151 { 152 struct lcd_device *ld = to_lcd_device(dev); 153 kfree(ld); 154 } 155 156 + static struct device_attribute lcd_device_attributes[] = { 157 + __ATTR(lcd_power, 0644, lcd_show_power, lcd_store_power), 158 + __ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast), 159 + __ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL), 160 + __ATTR_NULL, 161 }; 162 163 /** 164 * lcd_device_register - register a new object of lcd_device class. 165 * @name: the name of the new object(must be the same as the name of the 166 * respective framebuffer device). 167 + * @devdata: an optional pointer to be stored in the device. The 168 + * methods may retrieve it by using lcd_get_data(ld). 169 * @ops: the lcd operations structure. 170 * 171 + * Creates and registers a new lcd device. Returns either an ERR_PTR() 172 * or a pointer to the newly allocated device. 173 */ 174 + struct lcd_device *lcd_device_register(const char *name, struct device *parent, 175 + void *devdata, struct lcd_ops *ops) 176 { 177 struct lcd_device *new_ld; 178 + int rc; 179 180 pr_debug("lcd_device_register: name=%s\n", name); 181 ··· 193 194 mutex_init(&new_ld->ops_lock); 195 mutex_init(&new_ld->update_lock); 196 197 + new_ld->dev.class = lcd_class; 198 + new_ld->dev.parent = parent; 199 + new_ld->dev.release = lcd_device_release; 200 + strlcpy(new_ld->dev.bus_id, name, BUS_ID_SIZE); 201 + dev_set_drvdata(&new_ld->dev, devdata); 202 + 203 + rc = device_register(&new_ld->dev); 204 if (rc) { 205 kfree(new_ld); 206 return ERR_PTR(rc); ··· 206 207 rc = lcd_register_fb(new_ld); 208 if (rc) { 209 + device_unregister(&new_ld->dev); 210 return ERR_PTR(rc); 211 } 212 213 + new_ld->ops = ops; 214 215 return new_ld; 216 } ··· 235 */ 236 void lcd_device_unregister(struct lcd_device *ld) 237 { 238 if (!ld) 239 return; 240 241 mutex_lock(&ld->ops_lock); 242 ld->ops = NULL; 243 mutex_unlock(&ld->ops_lock); 244 lcd_unregister_fb(ld); 245 + 246 + device_unregister(&ld->dev); 247 } 248 EXPORT_SYMBOL(lcd_device_unregister); 249 250 static void __exit lcd_class_exit(void) 251 { 252 + class_destroy(lcd_class); 253 } 254 255 static int __init lcd_class_init(void) 256 { 257 + lcd_class = class_create(THIS_MODULE, "lcd"); 258 + if (IS_ERR(lcd_class)) { 259 + printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n", 260 + PTR_ERR(lcd_class)); 261 + return PTR_ERR(lcd_class); 262 + } 263 + 264 + lcd_class->dev_attrs = lcd_device_attributes; 265 + return 0; 266 } 267 268 /*
+1 -1
drivers/video/nvidia/nv_backlight.c
··· 50 51 static int nvidia_bl_update_status(struct backlight_device *bd) 52 { 53 - struct nvidia_par *par = class_get_devdata(&bd->class_dev); 54 u32 tmp_pcrt, tmp_pmc, fpcontrol; 55 int level; 56
··· 50 51 static int nvidia_bl_update_status(struct backlight_device *bd) 52 { 53 + struct nvidia_par *par = bl_get_data(bd); 54 u32 tmp_pcrt, tmp_pmc, fpcontrol; 55 int level; 56
+1 -1
drivers/video/riva/fbdev.c
··· 307 308 static int riva_bl_update_status(struct backlight_device *bd) 309 { 310 - struct riva_par *par = class_get_devdata(&bd->class_dev); 311 U032 tmp_pcrt, tmp_pmc; 312 int level; 313
··· 307 308 static int riva_bl_update_status(struct backlight_device *bd) 309 { 310 + struct riva_par *par = bl_get_data(bd); 311 U032 tmp_pcrt, tmp_pmc; 312 int level; 313
+8 -3
include/linux/backlight.h
··· 69 70 /* The framebuffer notifier block */ 71 struct notifier_block fb_notif; 72 - /* The class device structure */ 73 - struct class_device class_dev; 74 }; 75 76 static inline void backlight_update_status(struct backlight_device *bd) ··· 85 struct device *dev, void *devdata, struct backlight_ops *ops); 86 extern void backlight_device_unregister(struct backlight_device *bd); 87 88 - #define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev) 89 90 #endif
··· 69 70 /* The framebuffer notifier block */ 71 struct notifier_block fb_notif; 72 + 73 + struct device dev; 74 }; 75 76 static inline void backlight_update_status(struct backlight_device *bd) ··· 85 struct device *dev, void *devdata, struct backlight_ops *ops); 86 extern void backlight_device_unregister(struct backlight_device *bd); 87 88 + #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev) 89 + 90 + static inline void * bl_get_data(struct backlight_device *bl_dev) 91 + { 92 + return dev_get_drvdata(&bl_dev->dev); 93 + } 94 95 #endif
+10 -4
include/linux/lcd.h
··· 62 struct mutex update_lock; 63 /* The framebuffer notifier block */ 64 struct notifier_block fb_notif; 65 - /* The class device structure */ 66 - struct class_device class_dev; 67 }; 68 69 static inline void lcd_set_power(struct lcd_device *ld, int power) ··· 75 } 76 77 extern struct lcd_device *lcd_device_register(const char *name, 78 - void *devdata, struct lcd_ops *ops); 79 extern void lcd_device_unregister(struct lcd_device *ld); 80 81 - #define to_lcd_device(obj) container_of(obj, struct lcd_device, class_dev) 82 83 #endif
··· 62 struct mutex update_lock; 63 /* The framebuffer notifier block */ 64 struct notifier_block fb_notif; 65 + 66 + struct device dev; 67 }; 68 69 static inline void lcd_set_power(struct lcd_device *ld, int power) ··· 75 } 76 77 extern struct lcd_device *lcd_device_register(const char *name, 78 + struct device *parent, void *devdata, struct lcd_ops *ops); 79 extern void lcd_device_unregister(struct lcd_device *ld); 80 81 + #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev) 82 + 83 + static inline void * lcd_get_data(struct lcd_device *ld_dev) 84 + { 85 + return dev_get_drvdata(&ld_dev->dev); 86 + } 87 + 88 89 #endif