diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-22 11:19:46 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-22 11:19:46 -0700 |
commit | 2fe83b3ad12d43799af5f3156886eca443a88bac (patch) | |
tree | 1f09c2f0013f4742106f7b1732da6fdc45b18d39 /drivers/video/backlight | |
parent | dd6ccfe64dad4ea498392805b477308abef43a4c (diff) | |
parent | ce8c47cf88af4da2ff429933c07f203a55d5d0a1 (diff) |
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
Diffstat (limited to 'drivers/video/backlight')
-rw-r--r-- | drivers/video/backlight/Kconfig | 26 | ||||
-rw-r--r-- | drivers/video/backlight/backlight.c | 125 | ||||
-rw-r--r-- | drivers/video/backlight/cr_bllcd.c | 2 | ||||
-rw-r--r-- | drivers/video/backlight/lcd.c | 112 |
4 files changed, 120 insertions, 145 deletions
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index fbef663fc057..2580f5fa2486 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig @@ -8,26 +8,32 @@ menuconfig BACKLIGHT_LCD_SUPPORT Enable this to be able to choose the drivers for controlling the backlight and the LCD panel on some platforms, for example on PDAs. -config BACKLIGHT_CLASS_DEVICE - tristate "Lowlevel Backlight controls" +# +# LCD +# +config LCD_CLASS_DEVICE + tristate "Lowlevel LCD controls" depends on BACKLIGHT_LCD_SUPPORT default m help - This framework adds support for low-level control of the LCD - backlight. This includes support for brightness and power. + This framework adds support for low-level control of LCD. + Some framebuffer devices connect to platform-specific LCD modules + in order to have a platform-specific way to control the flat panel + (contrast and applying power to the LCD (not to the backlight!)). To have support for your specific LCD panel you will have to select the proper drivers which depend on this option. -config LCD_CLASS_DEVICE - tristate "Lowlevel LCD controls" +# +# Backlight +# +config BACKLIGHT_CLASS_DEVICE + tristate "Lowlevel Backlight controls" depends on BACKLIGHT_LCD_SUPPORT default m help - This framework adds support for low-level control of LCD. - Some framebuffer devices connect to platform-specific LCD modules - in order to have a platform-specific way to control the flat panel - (contrast and applying power to the LCD (not to the backlight!)). + This framework adds support for low-level control of the LCD + backlight. This includes support for brightness and power. To have support for your specific LCD panel you will have to select the proper drivers which depend on this option. diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 7e06223bca94..b26de8cf3112 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -69,18 +69,20 @@ static inline void backlight_unregister_fb(struct backlight_device *bd) } #endif /* CONFIG_FB */ -static ssize_t backlight_show_power(struct class_device *cdev, char *buf) +static ssize_t backlight_show_power(struct device *dev, + struct device_attribute *attr,char *buf) { - struct backlight_device *bd = to_backlight_device(cdev); + struct backlight_device *bd = to_backlight_device(dev); return sprintf(buf, "%d\n", bd->props.power); } -static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) +static ssize_t backlight_store_power(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) { int rc = -ENXIO; char *endp; - struct backlight_device *bd = to_backlight_device(cdev); + struct backlight_device *bd = to_backlight_device(dev); int power = simple_strtoul(buf, &endp, 0); size_t size = endp - buf; @@ -101,18 +103,20 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, return rc; } -static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) +static ssize_t backlight_show_brightness(struct device *dev, + struct device_attribute *attr, char *buf) { - struct backlight_device *bd = to_backlight_device(cdev); + struct backlight_device *bd = to_backlight_device(dev); return sprintf(buf, "%d\n", bd->props.brightness); } -static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) +static ssize_t backlight_store_brightness(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) { int rc = -ENXIO; char *endp; - struct backlight_device *bd = to_backlight_device(cdev); + struct backlight_device *bd = to_backlight_device(dev); int brightness = simple_strtoul(buf, &endp, 0); size_t size = endp - buf; @@ -138,18 +142,19 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char return rc; } -static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf) +static ssize_t backlight_show_max_brightness(struct device *dev, + struct device_attribute *attr, char *buf) { - struct backlight_device *bd = to_backlight_device(cdev); + struct backlight_device *bd = to_backlight_device(dev); return sprintf(buf, "%d\n", bd->props.max_brightness); } -static ssize_t backlight_show_actual_brightness(struct class_device *cdev, - char *buf) +static ssize_t backlight_show_actual_brightness(struct device *dev, + struct device_attribute *attr, char *buf) { int rc = -ENXIO; - struct backlight_device *bd = to_backlight_device(cdev); + struct backlight_device *bd = to_backlight_device(dev); mutex_lock(&bd->ops_lock); if (bd->ops && bd->ops->get_brightness) @@ -159,31 +164,22 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev, return rc; } -static void backlight_class_release(struct class_device *dev) +struct class *backlight_class; + +static void bl_device_release(struct device *dev) { struct backlight_device *bd = to_backlight_device(dev); kfree(bd); } -static struct class backlight_class = { - .name = "backlight", - .release = backlight_class_release, -}; - -#define DECLARE_ATTR(_name,_mode,_show,_store) \ -{ \ - .attr = { .name = __stringify(_name), .mode = _mode }, \ - .show = _show, \ - .store = _store, \ -} - -static const struct class_device_attribute bl_class_device_attributes[] = { - DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power), - DECLARE_ATTR(brightness, 0644, backlight_show_brightness, +static struct device_attribute bl_device_attributes[] = { + __ATTR(bl_power, 0644, backlight_show_power, backlight_store_power), + __ATTR(brightness, 0644, backlight_show_brightness, backlight_store_brightness), - DECLARE_ATTR(actual_brightness, 0444, backlight_show_actual_brightness, + __ATTR(actual_brightness, 0444, backlight_show_actual_brightness, NULL), - DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), + __ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), + __ATTR_NULL, }; /** @@ -191,22 +187,20 @@ static const struct class_device_attribute bl_class_device_attributes[] = { * backlight_device class. * @name: the name of the new object(must be the same as the name of the * respective framebuffer device). - * @devdata: an optional pointer to be stored in the class_device. The - * methods may retrieve it by using class_get_devdata(&bd->class_dev). + * @devdata: an optional pointer to be stored for private driver use. The + * methods may retrieve it by using bl_get_data(bd). * @ops: the backlight operations structure. * - * Creates and registers new backlight class_device. Returns either an + * Creates and registers new backlight device. Returns either an * ERR_PTR() or a pointer to the newly allocated device. */ struct backlight_device *backlight_device_register(const char *name, - struct device *dev, - void *devdata, - struct backlight_ops *ops) + struct device *parent, void *devdata, struct backlight_ops *ops) { - int i, rc; struct backlight_device *new_bd; + int rc; - pr_debug("backlight_device_alloc: name=%s\n", name); + pr_debug("backlight_device_register: name=%s\n", name); new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL); if (!new_bd) @@ -214,13 +208,14 @@ struct backlight_device *backlight_device_register(const char *name, mutex_init(&new_bd->update_lock); mutex_init(&new_bd->ops_lock); - new_bd->ops = ops; - new_bd->class_dev.class = &backlight_class; - new_bd->class_dev.dev = dev; - strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN); - class_set_devdata(&new_bd->class_dev, devdata); - rc = class_device_register(&new_bd->class_dev); + new_bd->dev.class = backlight_class; + new_bd->dev.parent = parent; + new_bd->dev.release = bl_device_release; + strlcpy(new_bd->dev.bus_id, name, BUS_ID_SIZE); + dev_set_drvdata(&new_bd->dev, devdata); + + rc = device_register(&new_bd->dev); if (rc) { kfree(new_bd); return ERR_PTR(rc); @@ -228,23 +223,11 @@ struct backlight_device *backlight_device_register(const char *name, rc = backlight_register_fb(new_bd); if (rc) { - class_device_unregister(&new_bd->class_dev); + device_unregister(&new_bd->dev); return ERR_PTR(rc); } - - for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) { - rc = class_device_create_file(&new_bd->class_dev, - &bl_class_device_attributes[i]); - if (rc) { - while (--i >= 0) - class_device_remove_file(&new_bd->class_dev, - &bl_class_device_attributes[i]); - class_device_unregister(&new_bd->class_dev); - /* No need to kfree(new_bd) since release() method was called */ - return ERR_PTR(rc); - } - } + new_bd->ops = ops; #ifdef CONFIG_PMAC_BACKLIGHT mutex_lock(&pmac_backlight_mutex); @@ -265,42 +248,40 @@ EXPORT_SYMBOL(backlight_device_register); */ void backlight_device_unregister(struct backlight_device *bd) { - int i; - if (!bd) return; - pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id); - #ifdef CONFIG_PMAC_BACKLIGHT mutex_lock(&pmac_backlight_mutex); if (pmac_backlight == bd) pmac_backlight = NULL; mutex_unlock(&pmac_backlight_mutex); #endif - - for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) - class_device_remove_file(&bd->class_dev, - &bl_class_device_attributes[i]); - mutex_lock(&bd->ops_lock); bd->ops = NULL; mutex_unlock(&bd->ops_lock); backlight_unregister_fb(bd); - - class_device_unregister(&bd->class_dev); + device_unregister(&bd->dev); } EXPORT_SYMBOL(backlight_device_unregister); static void __exit backlight_class_exit(void) { - class_unregister(&backlight_class); + class_destroy(backlight_class); } static int __init backlight_class_init(void) { - return class_register(&backlight_class); + backlight_class = class_create(THIS_MODULE, "backlight"); + if (IS_ERR(backlight_class)) { + printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n", + PTR_ERR(backlight_class)); + return PTR_ERR(backlight_class); + } + + backlight_class->dev_attrs = bl_device_attributes; + return 0; } /* diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c index 1b3f6586bc9f..b7904da51b23 100644 --- a/drivers/video/backlight/cr_bllcd.c +++ b/drivers/video/backlight/cr_bllcd.c @@ -202,7 +202,7 @@ static int cr_backlight_probe(struct platform_device *pdev) } crp->cr_lcd_device = lcd_device_register("cr-lcd", - &pdev->dev, + &pdev->dev, NULL, &cr_lcd_ops); if (IS_ERR(crp->cr_lcd_device)) { diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c index 648b53c1fdea..6f652c65fae1 100644 --- a/drivers/video/backlight/lcd.c +++ b/drivers/video/backlight/lcd.c @@ -61,10 +61,11 @@ static inline void lcd_unregister_fb(struct lcd_device *ld) } #endif /* CONFIG_FB */ -static ssize_t lcd_show_power(struct class_device *cdev, char *buf) +static ssize_t lcd_show_power(struct device *dev, struct device_attribute *attr, + char *buf) { int rc; - struct lcd_device *ld = to_lcd_device(cdev); + struct lcd_device *ld = to_lcd_device(dev); mutex_lock(&ld->ops_lock); if (ld->ops && ld->ops->get_power) @@ -76,11 +77,12 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf) return rc; } -static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_t count) +static ssize_t lcd_store_power(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) { int rc = -ENXIO; char *endp; - struct lcd_device *ld = to_lcd_device(cdev); + struct lcd_device *ld = to_lcd_device(dev); int power = simple_strtoul(buf, &endp, 0); size_t size = endp - buf; @@ -100,10 +102,11 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_ return rc; } -static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf) +static ssize_t lcd_show_contrast(struct device *dev, + struct device_attribute *attr, char *buf) { int rc = -ENXIO; - struct lcd_device *ld = to_lcd_device(cdev); + struct lcd_device *ld = to_lcd_device(dev); mutex_lock(&ld->ops_lock); if (ld->ops && ld->ops->get_contrast) @@ -113,11 +116,12 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf) return rc; } -static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, size_t count) +static ssize_t lcd_store_contrast(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) { int rc = -ENXIO; char *endp; - struct lcd_device *ld = to_lcd_device(cdev); + struct lcd_device *ld = to_lcd_device(dev); int contrast = simple_strtoul(buf, &endp, 0); size_t size = endp - buf; @@ -137,53 +141,45 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si return rc; } -static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf) +static ssize_t lcd_show_max_contrast(struct device *dev, + struct device_attribute *attr, char *buf) { - struct lcd_device *ld = to_lcd_device(cdev); + struct lcd_device *ld = to_lcd_device(dev); return sprintf(buf, "%d\n", ld->props.max_contrast); } -static void lcd_class_release(struct class_device *dev) +struct class *lcd_class; + +static void lcd_device_release(struct device *dev) { struct lcd_device *ld = to_lcd_device(dev); kfree(ld); } -static struct class lcd_class = { - .name = "lcd", - .release = lcd_class_release, -}; - -#define DECLARE_ATTR(_name,_mode,_show,_store) \ -{ \ - .attr = { .name = __stringify(_name), .mode = _mode }, \ - .show = _show, \ - .store = _store, \ -} - -static const struct class_device_attribute lcd_class_device_attributes[] = { - DECLARE_ATTR(power, 0644, lcd_show_power, lcd_store_power), - DECLARE_ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast), - DECLARE_ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL), +static struct device_attribute lcd_device_attributes[] = { + __ATTR(lcd_power, 0644, lcd_show_power, lcd_store_power), + __ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast), + __ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL), + __ATTR_NULL, }; /** * lcd_device_register - register a new object of lcd_device class. * @name: the name of the new object(must be the same as the name of the * respective framebuffer device). - * @devdata: an optional pointer to be stored in the class_device. The - * methods may retrieve it by using class_get_devdata(ld->class_dev). + * @devdata: an optional pointer to be stored in the device. The + * methods may retrieve it by using lcd_get_data(ld). * @ops: the lcd operations structure. * - * Creates and registers a new lcd class_device. Returns either an ERR_PTR() + * Creates and registers a new lcd device. Returns either an ERR_PTR() * or a pointer to the newly allocated device. */ -struct lcd_device *lcd_device_register(const char *name, void *devdata, - struct lcd_ops *ops) +struct lcd_device *lcd_device_register(const char *name, struct device *parent, + void *devdata, struct lcd_ops *ops) { - int i, rc; struct lcd_device *new_ld; + int rc; pr_debug("lcd_device_register: name=%s\n", name); @@ -193,12 +189,14 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata, mutex_init(&new_ld->ops_lock); mutex_init(&new_ld->update_lock); - new_ld->ops = ops; - new_ld->class_dev.class = &lcd_class; - strlcpy(new_ld->class_dev.class_id, name, KOBJ_NAME_LEN); - class_set_devdata(&new_ld->class_dev, devdata); - rc = class_device_register(&new_ld->class_dev); + new_ld->dev.class = lcd_class; + new_ld->dev.parent = parent; + new_ld->dev.release = lcd_device_release; + strlcpy(new_ld->dev.bus_id, name, BUS_ID_SIZE); + dev_set_drvdata(&new_ld->dev, devdata); + + rc = device_register(&new_ld->dev); if (rc) { kfree(new_ld); return ERR_PTR(rc); @@ -206,22 +204,11 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata, rc = lcd_register_fb(new_ld); if (rc) { - class_device_unregister(&new_ld->class_dev); + device_unregister(&new_ld->dev); return ERR_PTR(rc); } - for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) { - rc = class_device_create_file(&new_ld->class_dev, - &lcd_class_device_attributes[i]); - if (rc) { - while (--i >= 0) - class_device_remove_file(&new_ld->class_dev, - &lcd_class_device_attributes[i]); - class_device_unregister(&new_ld->class_dev); - /* No need to kfree(new_ld) since release() method was called */ - return ERR_PTR(rc); - } - } + new_ld->ops = ops; return new_ld; } @@ -235,33 +222,34 @@ EXPORT_SYMBOL(lcd_device_register); */ void lcd_device_unregister(struct lcd_device *ld) { - int i; - if (!ld) return; - pr_debug("lcd_device_unregister: name=%s\n", ld->class_dev.class_id); - - for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) - class_device_remove_file(&ld->class_dev, - &lcd_class_device_attributes[i]); - mutex_lock(&ld->ops_lock); ld->ops = NULL; mutex_unlock(&ld->ops_lock); lcd_unregister_fb(ld); - class_device_unregister(&ld->class_dev); + + device_unregister(&ld->dev); } EXPORT_SYMBOL(lcd_device_unregister); static void __exit lcd_class_exit(void) { - class_unregister(&lcd_class); + class_destroy(lcd_class); } static int __init lcd_class_init(void) { - return class_register(&lcd_class); + lcd_class = class_create(THIS_MODULE, "lcd"); + if (IS_ERR(lcd_class)) { + printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n", + PTR_ERR(lcd_class)); + return PTR_ERR(lcd_class); + } + + lcd_class->dev_attrs = lcd_device_attributes; + return 0; } /* |