diff options
author | Simon Glass <sjg@chromium.org> | 2014-10-04 11:29:44 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2014-10-23 19:29:52 -0600 |
commit | 0757535a7eee3ae5603520fe4a0588a01a590ea7 (patch) | |
tree | 1e87d9fc38cab2e3d78bcd16047de8bbacb0fad5 /drivers/gpio/gpio-uclass.c | |
parent | 6449a506d67b0374bf23a3833f15afa0c92a7a0e (diff) | |
download | u-boot-imx-0757535a7eee3ae5603520fe4a0588a01a590ea7.zip u-boot-imx-0757535a7eee3ae5603520fe4a0588a01a590ea7.tar.gz u-boot-imx-0757535a7eee3ae5603520fe4a0588a01a590ea7.tar.bz2 |
dm: Move the function for getting GPIO status into the uclass
This function can be more easily tested if it is in the uclass.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/gpio/gpio-uclass.c')
-rw-r--r-- | drivers/gpio/gpio-uclass.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 04b7b16..6367093 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -330,6 +330,45 @@ int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep) return get_function(dev, offset, false, namep); } +int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize) +{ + struct dm_gpio_ops *ops = gpio_get_ops(dev); + struct gpio_dev_priv *priv; + char *str = buf; + int func; + int ret; + int len; + + BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function)); + + *buf = 0; + priv = dev->uclass_priv; + ret = gpio_get_raw_function(dev, offset, NULL); + if (ret < 0) + return ret; + func = ret; + len = snprintf(str, buffsize, "%s%d: %s", + priv->bank_name ? priv->bank_name : "", + offset, gpio_function[func]); + if (func == GPIOF_INPUT || func == GPIOF_OUTPUT || + func == GPIOF_UNUSED) { + const char *label; + bool used; + + ret = ops->get_value(dev, offset); + if (ret < 0) + return ret; + used = gpio_get_function(dev, offset, &label) != GPIOF_UNUSED; + snprintf(str + len, buffsize - len, ": %d [%c]%s%s", + ret, + used ? 'x' : ' ', + used ? " " : "", + label ? label : ""); + } + + return 0; +} + /* We need to renumber the GPIOs when any driver is probed/removed */ static int gpio_renumber(struct udevice *removed_dev) { |