diff options
author | Patrick Delaunay <patrick.delaunay@st.com> | 2020-01-13 11:35:01 +0100 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-04-16 23:06:54 -0400 |
commit | 9f2b066cda3dd0b4bf583c40610eba347f2c03cd (patch) | |
tree | abfe9fc2eb8900c72d449766a916cbe9e8171906 /drivers/gpio | |
parent | e3f3a121d8ebe15da868be8afbfb3e2a9ff80d4d (diff) | |
download | u-boot-9f2b066cda3dd0b4bf583c40610eba347f2c03cd.zip u-boot-9f2b066cda3dd0b4bf583c40610eba347f2c03cd.tar.gz u-boot-9f2b066cda3dd0b4bf583c40610eba347f2c03cd.tar.bz2 |
gpio: add gpio descriptor initialization helper
Add a helper function gpio_desc_init() to initialize the gpio descriptor;
with this function the flags will be always set to 0.
It wasn't the case before this patch in dm_gpio_lookup_name.
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpio-uclass.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 2515df4..32fdc5b 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -19,6 +19,22 @@ DECLARE_GLOBAL_DATA_PTR; /** + * gpio_desc_init() - Initialize the GPIO descriptor + * + * @desc: GPIO descriptor to initialize + * @dev: GPIO device + * @offset: Offset of device GPIO + */ +static void gpio_desc_init(struct gpio_desc *desc, + struct udevice *dev, + uint offset) +{ + desc->dev = dev; + desc->offset = offset; + desc->flags = 0; +} + +/** * gpio_to_device() - Convert global GPIO number to device, number * * Convert the GPIO number to an entry in the list of GPIOs @@ -41,9 +57,7 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc) uc_priv = dev_get_uclass_priv(dev); if (gpio >= uc_priv->gpio_base && gpio < uc_priv->gpio_base + uc_priv->gpio_count) { - desc->dev = dev; - desc->offset = gpio - uc_priv->gpio_base; - desc->flags = 0; + gpio_desc_init(desc, dev, gpio - uc_priv->gpio_base); return 0; } } @@ -85,8 +99,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc) if (!dev) return ret ? ret : -EINVAL; - desc->dev = dev; - desc->offset = offset; + gpio_desc_init(desc, dev, offset); return 0; } @@ -772,9 +785,7 @@ static int gpio_request_tail(int ret, const char *nodename, struct gpio_desc *desc, int flags, bool add_index, struct udevice *gpio_dev) { - desc->dev = gpio_dev; - desc->offset = 0; - desc->flags = 0; + gpio_desc_init(desc, gpio_dev, 0); if (ret) goto err; |