Skip to content

Commit

Permalink
leds-gpio: Implement the brightness_get method
Browse files Browse the repository at this point in the history
The power LED uses some clever logic that means it is driven
by a voltage measuring circuit when configured as input, otherwise
it is driven by the GPIO output value. This patch wires up the
brightness_get method for leds-gpio so that user-space can monitor
the LED value via /sys/class/gpio/led1/brightness. Using the input
trigger this returns an indication of the system power health,
otherwise it is just whatever value the trigger has written most
recently.

See: #1064
  • Loading branch information
Phil Elwell authored and popcornmix committed Sep 11, 2015
1 parent 0f476f6 commit 4980c16
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/leds/leds-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ static void gpio_led_set(struct led_classdev *led_cdev,
}
}

static enum led_brightness gpio_led_get(struct led_classdev *led_cdev)
{
struct gpio_led_data *led_dat =
container_of(led_cdev, struct gpio_led_data, cdev);
return gpiod_get_value_cansleep(led_dat->gpiod) ? LED_FULL : LED_OFF;
}

static int gpio_blink_set(struct led_classdev *led_cdev,
unsigned long *delay_on, unsigned long *delay_off)
{
Expand Down Expand Up @@ -139,6 +146,7 @@ static int create_gpio_led(const struct gpio_led *template,
led_dat->cdev.blink_set = gpio_blink_set;
}
led_dat->cdev.brightness_set = gpio_led_set;
led_dat->cdev.brightness_get = gpio_led_get;
if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP)
state = !!gpiod_get_value_cansleep(led_dat->gpiod);
else
Expand Down

0 comments on commit 4980c16

Please sign in to comment.