Prev: [PATCH] drivers/serial/sunsab.c: adjust the constant used to initialize the interrupt_mask0 fields
Next: regulator: Get rid of lockdep warning
From: H Hartley Sweeten on 12 Mar 2010 12:20 It's usually more convenient to set the backlight brightness as a 'percent' of total brightness rather than using the raw 'brightness' value. This provides the necessary sysfs attributes to handle this. Signed-off-by: H Hartley Sweeten <hsweeten(a)visionengravers.com> Cc: Richard Purdie <rpurdie(a)rpsys.net> --- diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 18829cf..af25bfa 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -190,6 +190,50 @@ static ssize_t backlight_show_actual_brightness(struct device *dev, return rc; } +static ssize_t backlight_show_percent(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct backlight_device *bd = to_backlight_device(dev); + int percent; + + percent = bd->props.brightness * 100 / bd->props.max_brightness; + return sprintf(buf, "%d\n", percent); +} + +static ssize_t backlight_store_percent(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct backlight_device *bd = to_backlight_device(dev); + unsigned long percent, brightness; + int rc; + + rc = strict_strtoul(buf, 0, &percent); + if (rc) + return rc; + + brightness = percent * bd->props.max_brightness / 100; + + rc = -ENXIO; + + mutex_lock(&bd->ops_lock); + if (bd->ops) { + if (brightness > bd->props.max_brightness) + rc = -EINVAL; + else { + pr_debug("backlight: set to %lu%% (brightness of %lu)\n", + percent, 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; +} + static struct class *backlight_class; static int backlight_suspend(struct device *dev, pm_message_t state) @@ -233,6 +277,7 @@ static struct device_attribute bl_device_attributes[] = { __ATTR(actual_brightness, 0444, backlight_show_actual_brightness, NULL), __ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), + __ATTR(percent, 0644, backlight_show_percent, backlight_store_percent), __ATTR_NULL, }; |