1 From 5a3324e4eb8898d293fdc562117877cb313718a1 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Wed, 15 Jul 2015 13:46:08 +0100
4 Subject: [PATCH 123/203] leds-gpio: Implement the brightness_get method
6 The power LED uses some clever logic that means it is driven
7 by a voltage measuring circuit when configured as input, otherwise
8 it is driven by the GPIO output value. This patch wires up the
9 brightness_get method for leds-gpio so that user-space can monitor
10 the LED value via /sys/class/gpio/led1/brightness. Using the input
11 trigger this returns an indication of the system power health,
12 otherwise it is just whatever value the trigger has written most
15 See: https://github.com/raspberrypi/linux/issues/1064
17 drivers/leds/leds-gpio.c | 8 ++++++++
18 1 file changed, 8 insertions(+)
20 --- a/drivers/leds/leds-gpio.c
21 +++ b/drivers/leds/leds-gpio.c
22 @@ -82,6 +82,13 @@ static void gpio_led_set(struct led_clas
26 +static enum led_brightness gpio_led_get(struct led_classdev *led_cdev)
28 + struct gpio_led_data *led_dat =
29 + container_of(led_cdev, struct gpio_led_data, cdev);
30 + return gpiod_get_value_cansleep(led_dat->gpiod) ? LED_FULL : LED_OFF;
33 static int gpio_blink_set(struct led_classdev *led_cdev,
34 unsigned long *delay_on, unsigned long *delay_off)
36 @@ -138,6 +145,7 @@ static int create_gpio_led(const struct
37 led_dat->cdev.blink_set = gpio_blink_set;
39 led_dat->cdev.brightness_set = gpio_led_set;
40 + led_dat->cdev.brightness_get = gpio_led_get;
41 if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP)
42 state = !!gpiod_get_value_cansleep(led_dat->gpiod);