Skip to content

Commit

Permalink
leds: Improve and export led_update_brightness
Browse files Browse the repository at this point in the history
led_update_brightness helper function used to be exploited only locally
in the led-class.c module, where its result was being passed to the
brightness_show sysfs callback. With the introduction of v4l2-flash
subdevice the same functionality becomes required for reading current
brightness from a LED device. This patch adds checking of return value
of the brightness_get callback and moves the led_update_brightness()
function to the LED subsystem public API.

Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
  • Loading branch information
Jacek Anaszewski authored and Bryan Wu committed Sep 12, 2014
1 parent 914ae25 commit 3ef7de5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 0 additions & 6 deletions drivers/leds/led-class.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@

static struct class *leds_class;

static void led_update_brightness(struct led_classdev *led_cdev)
{
if (led_cdev->brightness_get)
led_cdev->brightness = led_cdev->brightness_get(led_cdev);
}

static ssize_t brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
Expand Down
16 changes: 16 additions & 0 deletions drivers/leds/led-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ void led_set_brightness(struct led_classdev *led_cdev,
__led_set_brightness(led_cdev, brightness);
}
EXPORT_SYMBOL(led_set_brightness);

int led_update_brightness(struct led_classdev *led_cdev)
{
int ret = 0;

if (led_cdev->brightness_get) {
ret = led_cdev->brightness_get(led_cdev);
if (ret >= 0) {
led_cdev->brightness = ret;
return 0;
}
}

return ret;
}
EXPORT_SYMBOL(led_update_brightness);
10 changes: 10 additions & 0 deletions include/linux/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,
*/
extern void led_set_brightness(struct led_classdev *led_cdev,
enum led_brightness brightness);
/**
* led_update_brightness - update LED brightness
* @led_cdev: the LED to query
*
* Get an LED's current brightness and update led_cdev->brightness
* member with the obtained value.
*
* Returns: 0 on success or negative error value on failure
*/
extern int led_update_brightness(struct led_classdev *led_cdev);

/*
* LED Triggers
Expand Down

0 comments on commit 3ef7de5

Please sign in to comment.