diff mbox series

[U-Boot,v2,3/5] gpio: stm32f7: Add ops get_alternate_function

Message ID 1533308471-14098-4-git-send-email-patrice.chotard@st.com
State Superseded
Delegated to: Tom Rini
Headers show
Series Add get_alternate_function ops | expand

Commit Message

Patrice CHOTARD Aug. 3, 2018, 3:01 p.m. UTC
From: Patrick Delaunay <patrick.delaunay@st.com>

Allow to display alternate function index using "gpio" command.
Example, display all gpio state :

gpio status -a
  GPIOD2: func: 12
  GPIOD3: func: 9
  GPIOE3: func: 9
  GPIOG6: func: 10

It's useful to control pin configuration

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---

Changes in v2:
  - Rename get_function_number to get_alternate_function in
    drivers/gpio/stm32f7_gpio.c

 drivers/gpio/stm32f7_gpio.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Simon Glass Aug. 8, 2018, 9:55 a.m. UTC | #1
On 3 August 2018 at 09:01, Patrice Chotard <patrice.chotard@st.com> wrote:
> From: Patrick Delaunay <patrick.delaunay@st.com>
>
> Allow to display alternate function index using "gpio" command.
> Example, display all gpio state :
>
> gpio status -a
>   GPIOD2: func: 12
>   GPIOD3: func: 9
>   GPIOE3: func: 9
>   GPIOG6: func: 10
>
> It's useful to control pin configuration
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
> ---
>
> Changes in v2:
>   - Rename get_function_number to get_alternate_function in
>     drivers/gpio/stm32f7_gpio.c
>
>  drivers/gpio/stm32f7_gpio.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/drivers/gpio/stm32f7_gpio.c b/drivers/gpio/stm32f7_gpio.c
index 55e121699022..ddc277c4e5ee 100644
--- a/drivers/gpio/stm32f7_gpio.c
+++ b/drivers/gpio/stm32f7_gpio.c
@@ -85,12 +85,28 @@  static int stm32_gpio_get_function(struct udevice *dev, unsigned int offset)
 	return GPIOF_FUNC;
 }
 
+static int stm32_gpio_get_alternate_function(struct udevice *dev,
+					     unsigned int offset)
+{
+	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	struct stm32_gpio_regs *regs = priv->regs;
+	u32 af;
+	u32 alt_shift = (offset % 8) * 4;
+	u32 alt_index =  offset / 8;
+
+	af = (readl(&regs->afr[alt_index]) &
+	      GENMASK(alt_shift + 3, alt_shift)) >> alt_shift;
+
+	return af;
+}
+
 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,
+	.get_alternate_function	= stm32_gpio_get_alternate_function,
 };
 
 static int gpio_stm32_probe(struct udevice *dev)