diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index bddc8b17a4d8..18901b9b1eb4 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -164,6 +164,30 @@ static ssize_t brightness_show(struct device *dev, return sprintf(buf, "%d\n", bd->props.brightness); } +int backlight_device_set_brightness(struct backlight_device *bd, + unsigned long brightness) +{ + int rc = -ENXIO; + + mutex_lock(&bd->ops_lock); + if (bd->ops) { + if (brightness > bd->props.max_brightness) + rc = -EINVAL; + else { + pr_debug("set brightness to %lu\n", brightness); + bd->props.brightness = brightness; + backlight_update_status(bd); + rc = 0; + } + } + mutex_unlock(&bd->ops_lock); + + backlight_generate_event(bd, BACKLIGHT_UPDATE_SYSFS); + + return rc; +} +EXPORT_SYMBOL(backlight_device_set_brightness); + static ssize_t brightness_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -175,24 +199,9 @@ static ssize_t brightness_store(struct device *dev, if (rc) return rc; - rc = -ENXIO; + rc = backlight_device_set_brightness(bd, brightness); - mutex_lock(&bd->ops_lock); - if (bd->ops) { - if (brightness > bd->props.max_brightness) - rc = -EINVAL; - else { - pr_debug("set brightness to %lu\n", brightness); - bd->props.brightness = brightness; - backlight_update_status(bd); - rc = count; - } - } - mutex_unlock(&bd->ops_lock); - - backlight_generate_event(bd, BACKLIGHT_UPDATE_SYSFS); - - return rc; + return rc ? rc : count; } static DEVICE_ATTR_RW(brightness); @@ -380,7 +389,7 @@ struct backlight_device *backlight_device_register(const char *name, } EXPORT_SYMBOL(backlight_device_register); -bool backlight_device_registered(enum backlight_type type) +struct backlight_device *backlight_device_get_by_type(enum backlight_type type) { bool found = false; struct backlight_device *bd; @@ -394,7 +403,13 @@ bool backlight_device_registered(enum backlight_type type) } mutex_unlock(&backlight_dev_list_mutex); - return found; + return found ? bd : NULL; +} +EXPORT_SYMBOL(backlight_device_get_by_type); + +bool backlight_device_registered(enum backlight_type type) +{ + return backlight_device_get_by_type(type) ? true : false; } EXPORT_SYMBOL(backlight_device_registered); diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 1e7a69adbe6f..f46b88fa4a09 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -144,6 +144,8 @@ extern void backlight_force_update(struct backlight_device *bd, extern bool backlight_device_registered(enum backlight_type type); extern int backlight_register_notifier(struct notifier_block *nb); extern int backlight_unregister_notifier(struct notifier_block *nb); +extern struct backlight_device *backlight_device_get_by_type(enum backlight_type type); +extern int backlight_device_set_brightness(struct backlight_device *bd, unsigned long brightness); #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)