summaryrefslogtreecommitdiff
path: root/drivers/gpio
diff options
context:
space:
mode:
authorPatrice Chotard <patrice.chotard@st.com>2018-10-24 14:10:21 +0200
committerTom Rini <trini@konsulko.com>2018-11-16 16:51:56 -0500
commitcad732499ba1aef2ea9288b30428465793b2d013 (patch)
treefe26538407d26508ccd6bae3603ec0d422265fa1 /drivers/gpio
parentb42d938c247dd956a04d533dfc9f5c0ecf287ff2 (diff)
downloadu-boot-cad732499ba1aef2ea9288b30428465793b2d013.tar.gz
u-boot-cad732499ba1aef2ea9288b30428465793b2d013.tar.bz2
u-boot-cad732499ba1aef2ea9288b30428465793b2d013.zip
gpio: stm32f7: Add ops get_function
This patch adds gpio get_function ops support. This function reports the state of a gpio. Signed-off-by: Christophe Kerello <christophe.kerello@st.com> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/stm32f7_gpio.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/drivers/gpio/stm32f7_gpio.c b/drivers/gpio/stm32f7_gpio.c
index b903dc46b3..a690c437eb 100644
--- a/drivers/gpio/stm32f7_gpio.c
+++ b/drivers/gpio/stm32f7_gpio.c
@@ -65,11 +65,31 @@ static int stm32_gpio_set_value(struct udevice *dev, unsigned offset, int value)
return 0;
}
+static int stm32_gpio_get_function(struct udevice *dev, unsigned int offset)
+{
+ struct stm32_gpio_priv *priv = dev_get_priv(dev);
+ struct stm32_gpio_regs *regs = priv->regs;
+ int bits_index = MODE_BITS(offset);
+ int mask = MODE_BITS_MASK << bits_index;
+ u32 mode;
+
+ mode = (readl(&regs->moder) & mask) >> bits_index;
+ if (mode == STM32_GPIO_MODE_OUT)
+ return GPIOF_OUTPUT;
+ if (mode == STM32_GPIO_MODE_IN)
+ return GPIOF_INPUT;
+ if (mode == STM32_GPIO_MODE_AN)
+ return GPIOF_UNUSED;
+
+ return GPIOF_FUNC;
+}
+
static const struct dm_gpio_ops gpio_stm32_ops = {
.direction_input = stm32_gpio_direction_input,
.direction_output = stm32_gpio_direction_output,
.get_value = stm32_gpio_get_value,
.set_value = stm32_gpio_set_value,
+ .get_function = stm32_gpio_get_function,
};
static int gpio_stm32_probe(struct udevice *dev)