From 56e19871dc2a05aa5508ea51af35df59bbdb6cf5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 10 Apr 2017 11:34:53 -0600 Subject: dm: led: Rename struct led_uclass_plat These structures are normally named with 'uc' instead of 'uclass'. Change this one for consistency. Signed-off-by: Simon Glass Reviewed-by: Ziping Chen --- drivers/led/led_gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/led/led_gpio.c') diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c index 5b119903f5..97b5da35cd 100644 --- a/drivers/led/led_gpio.c +++ b/drivers/led/led_gpio.c @@ -30,7 +30,7 @@ static int gpio_led_set_on(struct udevice *dev, int on) static int led_gpio_probe(struct udevice *dev) { - struct led_uclass_plat *uc_plat = dev_get_uclass_platdata(dev); + struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev); struct led_gpio_priv *priv = dev_get_priv(dev); /* Ignore the top-level LED node */ @@ -65,7 +65,7 @@ static int led_gpio_bind(struct udevice *parent) for (node = fdt_first_subnode(blob, dev_of_offset(parent)); node > 0; node = fdt_next_subnode(blob, node)) { - struct led_uclass_plat *uc_plat; + struct led_uc_plat *uc_plat; const char *label; label = fdt_getprop(blob, node, "label", NULL); -- cgit From ddae9fcddc48d1e624c941148d0df5a4fc7d7d5c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 10 Apr 2017 11:34:54 -0600 Subject: dm: led: Adjust the LED uclass At present this is very simple, supporting only on and off. We want to also support toggling and blinking. As a first step, change the name of the main method and use an enum to indicate the state. Signed-off-by: Simon Glass Reviewed-by: Ziping Chen --- drivers/led/led_gpio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/led/led_gpio.c') diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c index 97b5da35cd..af8133d3c7 100644 --- a/drivers/led/led_gpio.c +++ b/drivers/led/led_gpio.c @@ -18,14 +18,14 @@ struct led_gpio_priv { struct gpio_desc gpio; }; -static int gpio_led_set_on(struct udevice *dev, int on) +static int gpio_led_set_state(struct udevice *dev, enum led_state_t state) { struct led_gpio_priv *priv = dev_get_priv(dev); if (!dm_gpio_is_valid(&priv->gpio)) return -EREMOTEIO; - return dm_gpio_set_value(&priv->gpio, on); + return dm_gpio_set_value(&priv->gpio, state); } static int led_gpio_probe(struct udevice *dev) @@ -87,7 +87,7 @@ static int led_gpio_bind(struct udevice *parent) } static const struct led_ops gpio_led_ops = { - .set_on = gpio_led_set_on, + .set_state = gpio_led_set_state, }; static const struct udevice_id led_gpio_ids[] = { -- cgit From 8f4b612333ee0381eedf767c1c005a830886df27 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 10 Apr 2017 11:34:55 -0600 Subject: dm: led: Add support for getting the state of an LED It is useful to be able to read the LED as well as write it. Add this to the uclass and update the GPIO driver. Signed-off-by: Simon Glass Reviewed-by: Ziping Chen --- drivers/led/led_gpio.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'drivers/led/led_gpio.c') diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c index af8133d3c7..789d15600f 100644 --- a/drivers/led/led_gpio.c +++ b/drivers/led/led_gpio.c @@ -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[] = { -- cgit From 9413ad4f0def2e06a5042106a6e1650a1aa03a5a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 10 Apr 2017 11:34:56 -0600 Subject: dm: led: Support toggling LEDs Add support for toggling an LED into the uclass interface. This can be efficiently implemented by the driver. Signed-off-by: Simon Glass Reviewed-by: Ziping Chen --- drivers/led/led_gpio.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/led/led_gpio.c') diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c index 789d15600f..4106ecb679 100644 --- a/drivers/led/led_gpio.c +++ b/drivers/led/led_gpio.c @@ -21,6 +21,7 @@ struct led_gpio_priv { static int gpio_led_set_state(struct udevice *dev, enum led_state_t state) { struct led_gpio_priv *priv = dev_get_priv(dev); + int ret; if (!dm_gpio_is_valid(&priv->gpio)) return -EREMOTEIO; @@ -28,6 +29,12 @@ static int gpio_led_set_state(struct udevice *dev, enum led_state_t state) case LEDST_OFF: case LEDST_ON: break; + case LEDST_TOGGLE: + ret = dm_gpio_get_value(&priv->gpio); + if (ret < 0) + return ret; + state = !ret; + break; default: return -ENOSYS; } -- cgit