summaryrefslogtreecommitdiff
path: root/drivers/led/led_gpio.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2017-04-16 22:07:52 -0400
committerTom Rini <trini@konsulko.com>2017-04-16 22:07:52 -0400
commit51f866e8da758a27af596af73466bd5f0a450c4d (patch)
treeb4d47e5782265bec5ad8adcc43c43a118062ba6d /drivers/led/led_gpio.c
parent3fea95369850987de15a2a0ac009d05e13b90246 (diff)
parentad46af0e76384b22058d9ac979f34fad2483aff3 (diff)
Merge git://git.denx.de/u-boot-dm
Diffstat (limited to 'drivers/led/led_gpio.c')
-rw-r--r--drivers/led/led_gpio.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c
index 5b119903f5..4106ecb679 100644
--- a/drivers/led/led_gpio.c
+++ b/drivers/led/led_gpio.c
@@ -18,19 +18,47 @@ 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);
+ int ret;
+
+ if (!dm_gpio_is_valid(&priv->gpio))
+ return -EREMOTEIO;
+ switch (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;
+ }
+
+ 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 dm_gpio_set_value(&priv->gpio, on);
+ return ret ? LEDST_ON : LEDST_OFF;
}
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 +93,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);
@@ -87,7 +115,8 @@ 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,
+ .get_state = gpio_led_get_state,
};
static const struct udevice_id led_gpio_ids[] = {