]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/led/led_gpio.c
dm: led: Add support for getting the state of an LED
[people/ms/u-boot.git] / drivers / led / led_gpio.c
index af8133d3c700b26c752def58b02543ac62002202..789d15600fdc1092e66c8279e54b8d6288ee4543 100644 (file)
@@ -24,10 +24,31 @@ static int gpio_led_set_state(struct udevice *dev, enum led_state_t state)
 
        if (!dm_gpio_is_valid(&priv->gpio))
                return -EREMOTEIO;
+       switch (state) {
+       case LEDST_OFF:
+       case LEDST_ON:
+               break;
+       default:
+               return -ENOSYS;
+       }
 
        return dm_gpio_set_value(&priv->gpio, state);
 }
 
+static enum led_state_t gpio_led_get_state(struct udevice *dev)
+{
+       struct led_gpio_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       if (!dm_gpio_is_valid(&priv->gpio))
+               return -EREMOTEIO;
+       ret = dm_gpio_get_value(&priv->gpio);
+       if (ret < 0)
+               return ret;
+
+       return ret ? LEDST_ON : LEDST_OFF;
+}
+
 static int led_gpio_probe(struct udevice *dev)
 {
        struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev);
@@ -88,6 +109,7 @@ static int led_gpio_bind(struct udevice *parent)
 
 static const struct led_ops gpio_led_ops = {
        .set_state      = gpio_led_set_state,
+       .get_state      = gpio_led_get_state,
 };
 
 static const struct udevice_id led_gpio_ids[] = {