[U-Boot] [PATCH v3 0/5] Add get_alt_function ops

This series : - Add new gpio ops get_alt_function - Add get_function and get_alt_function support to stm32 gpio driver - Add get_alt_function test
Changes in v3: - Rename get_alternate_function to get_alt_function in include/asm-generic/gpio.h - Rename get_alternate_function to get_alt_function in drivers/gpio/stm32f7_gpio.c - Rename SDBX_GPIO_(OUTPUT|HIGH|ODR) to SANDBOX_GPIO_(OUTPUT|HIGH|ODR) - Rename get_alternate_function to get_alt_function
Changes in v2: - Rename get_function_number to get_alternate_function in include/asm-generic/gpio.h - Rename get_function_number to get_alternate_function in drivers/gpio/stm32f7_gpio.c - Rename get_function_number to get_alternate_function in test/dm/gpio.c, drivers/gpio/sandbox.c and in arch/sandbox/include/asm/gpio.h
Christophe Kerello (1): gpio: stm32f7: Add ops get_function
Patrice Chotard (2): gpio: sandbox: Rename GPIOF_(OUTPUT|HIGH|ODR) to SANDBOX_GPIO_(OUTPUT|HIGH|ODR) test: dm: Add gpio get_alt_function ops test
Patrick Delaunay (2): dm: gpio: Add get_alt_function ops gpio: stm32f7: Add ops get_alt_function
arch/sandbox/include/asm/gpio.h | 24 ++++++++++++++++++++ drivers/gpio/gpio-uclass.c | 6 +++++ drivers/gpio/sandbox.c | 49 ++++++++++++++++++++++++++++++++--------- drivers/gpio/stm32f7_gpio.c | 36 ++++++++++++++++++++++++++++++ include/asm-generic/gpio.h | 13 +++++++++++ test/dm/gpio.c | 13 +++++++++++ 6 files changed, 130 insertions(+), 11 deletions(-)

From: Patrick Delaunay patrick.delaunay@st.com
When a pin is not configured as a GPIO, it could have several alternate function.
To be able to identify the alternate function, add ops get_alt_function() to request the pin alternate function index from the driver when pin is not used as gpio.
Signed-off-by: Patrick Delaunay patrick.delaunay@st.com Reviewed-by: Simon Glass sjg@chromium.org Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v3: - Rename get_alternate_function to get_alt_function in include/asm-generic/gpio.h
Changes in v2: - Rename get_function_number to get_alternate_function in include/asm-generic/gpio.h
drivers/gpio/gpio-uclass.c | 6 ++++++ include/asm-generic/gpio.h | 13 +++++++++++++ 2 files changed, 19 insertions(+)
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index da5e9ba6e524..27010a1ebf22 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -568,6 +568,12 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize) label ? label : ""); }
+ if (func == GPIOF_FUNC && ops->get_alt_function) { + ret = ops->get_alt_function(dev, offset); + if (ret >= 0) + snprintf(str + len, buffsize - len, ": %d", ret); + } + return 0; }
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index d03602696f6d..dd3d77fafa98 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -266,6 +266,19 @@ struct dm_gpio_ops { int (*get_function)(struct udevice *dev, unsigned offset);
/** + * get_alt_function() Get the pins alternate function + * + * When a pin is not configured as GPIO, this pin can have several + * alternate function. get_alt_function indicate the current + * pin's alternate function index + * + * @dev: Device to check + * @offset: GPIO offset within that device + * @return current alternate function index + */ + int (*get_alt_function)(struct udevice *dev, unsigned int offset); + + /** * xlate() - Translate phandle arguments into a GPIO description * * This function should set up the fields in desc according to the

From: Christophe Kerello christophe.kerello@st.com
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 ---
Changes in v3: None Changes in v2: None
drivers/gpio/stm32f7_gpio.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/drivers/gpio/stm32f7_gpio.c b/drivers/gpio/stm32f7_gpio.c index 5b08e7ee275c..55e121699022 100644 --- a/drivers/gpio/stm32f7_gpio.c +++ b/drivers/gpio/stm32f7_gpio.c @@ -66,11 +66,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(®s->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)

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 Reviewed-by: Simon Glass sjg@chromium.org Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v3: - Rename get_alternate_function to get_alt_function in drivers/gpio/stm32f7_gpio.c
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(+)
diff --git a/drivers/gpio/stm32f7_gpio.c b/drivers/gpio/stm32f7_gpio.c index 55e121699022..d9a6c1dc6f1e 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_alt_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(®s->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_alt_function = stm32_gpio_get_alt_function, };
static int gpio_stm32_probe(struct udevice *dev)

To avoid confusion with enum gpio_func_t GPIOF_OUTPUT defined in asm-generic/gpio.h, rename all sandbox flags GPIOF_(OUTPUT|HIGH|ODR) to SANDBOX_GPIO_(OUTPUT|HIGH|ODR)
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: - Rename SDBX_GPIO_(OUTPUT|HIGH|ODR) to SANDBOX_GPIO_(OUTPUT|HIGH|ODR)
Changes in v2: None
drivers/gpio/sandbox.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index 2ef5c67ad593..e7bed17d0db0 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -12,9 +12,9 @@ #include <dt-bindings/gpio/gpio.h>
/* Flags for each GPIO */ -#define GPIOF_OUTPUT (1 << 0) /* Currently set as an output */ -#define GPIOF_HIGH (1 << 1) /* Currently set high */ -#define GPIOF_ODR (1 << 2) /* Currently set to open drain mode */ +#define SANDBOX_GPIO_OUTPUT BIT(0) /* Currently set as an output */ +#define SANDBOX_GPIO_HIGH BIT(1) /* Currently set high */ +#define SANDBOX_GPIO_ODR BIT(2) /* Currently set to open drain mode */
struct gpio_state { const char *label; /* label given by requester */ @@ -60,34 +60,34 @@ static int set_gpio_flag(struct udevice *dev, unsigned offset, int flag,
int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) { - if (get_gpio_flag(dev, offset, GPIOF_OUTPUT)) + if (get_gpio_flag(dev, offset, SANDBOX_GPIO_OUTPUT)) debug("sandbox_gpio: get_value on output gpio %u\n", offset); - return get_gpio_flag(dev, offset, GPIOF_HIGH); + return get_gpio_flag(dev, offset, SANDBOX_GPIO_HIGH); }
int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value) { - return set_gpio_flag(dev, offset, GPIOF_HIGH, value); + return set_gpio_flag(dev, offset, SANDBOX_GPIO_HIGH, value); }
int sandbox_gpio_get_open_drain(struct udevice *dev, unsigned offset) { - return get_gpio_flag(dev, offset, GPIOF_ODR); + return get_gpio_flag(dev, offset, SANDBOX_GPIO_ODR); }
int sandbox_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value) { - return set_gpio_flag(dev, offset, GPIOF_ODR, value); + return set_gpio_flag(dev, offset, SANDBOX_GPIO_ODR, value); }
int sandbox_gpio_get_direction(struct udevice *dev, unsigned offset) { - return get_gpio_flag(dev, offset, GPIOF_OUTPUT); + return get_gpio_flag(dev, offset, SANDBOX_GPIO_OUTPUT); }
int sandbox_gpio_set_direction(struct udevice *dev, unsigned offset, int output) { - return set_gpio_flag(dev, offset, GPIOF_OUTPUT, output); + return set_gpio_flag(dev, offset, SANDBOX_GPIO_OUTPUT, output); }
/* @@ -158,7 +158,7 @@ static int sb_gpio_set_open_drain(struct udevice *dev, unsigned offset, int valu
static int sb_gpio_get_function(struct udevice *dev, unsigned offset) { - if (get_gpio_flag(dev, offset, GPIOF_OUTPUT)) + if (get_gpio_flag(dev, offset, SDBX_GPIO_OUTPUT)) return GPIOF_OUTPUT; return GPIOF_INPUT; }

In order to test get_alt_function ops, add sandbox_gpio_set_function() and sandbox_gpio_set_alternate_function() to be able to configure a pin not as a GPIO and to select the alternate function index.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: - Rename get_alternate_function to get_alt_function
Changes in v2: - Rename get_function_number to get_alternate_function in test/dm/gpio.c, drivers/gpio/sandbox.c and in arch/sandbox/include/asm/gpio.h
arch/sandbox/include/asm/gpio.h | 24 ++++++++++++++++++++++++ drivers/gpio/sandbox.c | 29 ++++++++++++++++++++++++++++- test/dm/gpio.c | 13 +++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/arch/sandbox/include/asm/gpio.h b/arch/sandbox/include/asm/gpio.h index de8ac37f4262..217f6435b8bd 100644 --- a/arch/sandbox/include/asm/gpio.h +++ b/arch/sandbox/include/asm/gpio.h @@ -82,4 +82,28 @@ int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset); int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset, int output);
+/** + * Set the simulated usage of a pin, as a GPIO or not (used only in sandbox + * test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @param value 0 to set as GPIO, 1 to set as not a GPIO + * @return -1 on error, 0 if ok + */ +int sandbox_gpio_set_function(struct udevice *dev, unsigned int offset, + int value); + +/** + * Set the simulated alt function of a pin when pin is not used as a GPIO + * (used only in sandbox test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @param value pin alternate function number + * @return -1 on error, 0 if ok + */ +int sandbox_gpio_set_alt_function(struct udevice *dev, + unsigned int offset, + int value); #endif diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index e7bed17d0db0..55b7a2579db6 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -15,6 +15,8 @@ #define SANDBOX_GPIO_OUTPUT BIT(0) /* Currently set as an output */ #define SANDBOX_GPIO_HIGH BIT(1) /* Currently set high */ #define SANDBOX_GPIO_ODR BIT(2) /* Currently set to open drain mode */ +#define SANDBOX_GPIO_FUNC BIT(3) /* Currently set as not used as GPIO */ +#define SANDBOX_GPIO_FUNC_NB BIT(4) /* Currently set as function number 1 */
struct gpio_state { const char *label; /* label given by requester */ @@ -90,6 +92,19 @@ int sandbox_gpio_set_direction(struct udevice *dev, unsigned offset, int output) return set_gpio_flag(dev, offset, SANDBOX_GPIO_OUTPUT, output); }
+int sandbox_gpio_set_function(struct udevice *dev, unsigned int offset, + int value) +{ + return set_gpio_flag(dev, offset, SANDBOX_GPIO_FUNC, value); +} + +int sandbox_gpio_set_alt_function(struct udevice *dev, + unsigned int offset, + int value) +{ + return set_gpio_flag(dev, offset, SANDBOX_GPIO_FUNC_NB, value); +} + /* * These functions implement the public interface within U-Boot */ @@ -158,11 +173,22 @@ static int sb_gpio_set_open_drain(struct udevice *dev, unsigned offset, int valu
static int sb_gpio_get_function(struct udevice *dev, unsigned offset) { - if (get_gpio_flag(dev, offset, SDBX_GPIO_OUTPUT)) + if (get_gpio_flag(dev, offset, SANDBOX_GPIO_FUNC)) + return GPIOF_FUNC; + + if (get_gpio_flag(dev, offset, SANDBOX_GPIO_OUTPUT)) return GPIOF_OUTPUT; return GPIOF_INPUT; }
+static int sb_gpio_get_alt_function(struct udevice *dev, + unsigned int offset) +{ + debug("%s: offset:%u\n", __func__, offset); + + return get_gpio_flag(dev, offset, SANDBOX_GPIO_FUNC_NB); +} + static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc, struct ofnode_phandle_args *args) { @@ -189,6 +215,7 @@ static const struct dm_gpio_ops gpio_sandbox_ops = { .get_open_drain = sb_gpio_get_open_drain, .set_open_drain = sb_gpio_set_open_drain, .get_function = sb_gpio_get_function, + .get_alt_function = sb_gpio_get_alt_function, .xlate = sb_gpio_xlate, };
diff --git a/test/dm/gpio.c b/test/dm/gpio.c index bb4b20cea938..302342c2e0ce 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -92,6 +92,19 @@ static int dm_test_gpio(struct unit_test_state *uts) ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); ut_asserteq_str("b4: input: 0 [ ]", buf);
+ /* + * Make it not used as GPIO, select function + * (by default function number 0 is active) + */ + sandbox_gpio_set_function(dev, offset, 1); + ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); + ut_asserteq_str("b4: func: 0", buf); + + /* select function number 1 */ + sandbox_gpio_set_alt_function(dev, offset, 1); + ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf))); + ut_asserteq_str("b4: func: 1", buf); + /* Check the 'a' bank also */ ut_assertok(gpio_lookup_name("a15", &dev, &offset, &gpio)); ut_asserteq_str(dev->name, "base-gpios");

On 10.9.2018 18:11, Patrice Chotard wrote:
This series :
- Add new gpio ops get_alt_function
- Add get_function and get_alt_function support to stm32 gpio driver
- Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Thanks, Michal

Hi Michal
On 09/11/2018 07:51 AM, Michal Simek wrote:
On 10.9.2018 18:11, Patrice Chotard wrote:
This series :
- Add new gpio ops get_alt_function
- Add get_function and get_alt_function support to stm32 gpio driver
- Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Currently, get_function callback returns the state of a gpio (GPIOF_INPUT, GPIOF_OUTPUT or GPIO_FUNC).
If a pin's state is GPIO_FUNC, it's useful to know which alternate function is selected for debug purpose.
As example, on STM32 SoCs, a pins can be configured as GPIO or also configured with up to 16 alternate function. Using command "gpio", user can retrieve this information as shown below:
STM32MP> gpio state -a
Bank GPIOA: GPIOA0: unused: 0 [ ] GPIOA1: unused: 0 [ ] GPIOA2: unused: 0 [ ] GPIOA3: unused: 0 [ ] GPIOA4: unused: 0 [ ] GPIOA5: unused: 0 [ ] GPIOA6: unused: 0 [ ] GPIOA7: unused: 0 [ ] GPIOA8: func: 9 GPIOA9: func: 10 GPIOA10: unused: 0 [ ] GPIOA11: unused: 0 [ ] GPIOA12: unused: 0 [ ] GPIOA13: output: 1 [x] red.gpios GPIOA14: output: 0 [x] green.gpios GPIOA15: unused: 0 [ ]
It shows that pin 8 and 9 of bank A are configured respectively in alternate function 9 and 10.
Patrice
Thanks, Michal

Hi,
On 11.9.2018 09:31, Patrice CHOTARD wrote:
Hi Michal
On 09/11/2018 07:51 AM, Michal Simek wrote:
On 10.9.2018 18:11, Patrice Chotard wrote:
This series :
- Add new gpio ops get_alt_function
- Add get_function and get_alt_function support to stm32 gpio driver
- Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Currently, get_function callback returns the state of a gpio (GPIOF_INPUT, GPIOF_OUTPUT or GPIO_FUNC).
If a pin's state is GPIO_FUNC, it's useful to know which alternate function is selected for debug purpose.
As example, on STM32 SoCs, a pins can be configured as GPIO or also configured with up to 16 alternate function. Using command "gpio", user can retrieve this information as shown below:
STM32MP> gpio state -a
Bank GPIOA: GPIOA0: unused: 0 [ ] GPIOA1: unused: 0 [ ] GPIOA2: unused: 0 [ ] GPIOA3: unused: 0 [ ] GPIOA4: unused: 0 [ ] GPIOA5: unused: 0 [ ] GPIOA6: unused: 0 [ ] GPIOA7: unused: 0 [ ] GPIOA8: func: 9 GPIOA9: func: 10 GPIOA10: unused: 0 [ ] GPIOA11: unused: 0 [ ] GPIOA12: unused: 0 [ ] GPIOA13: output: 1 [x] red.gpios GPIOA14: output: 0 [x] green.gpios GPIOA15: unused: 0 [ ]
It shows that pin 8 and 9 of bank A are configured respectively in alternate function 9 and 10.
Can you list that functionality? Isn't it something what should be shown with a name instead of number? I expect that user has to go to any decode table to find out what 9 or 10 means.
Thanks, Michal

Hi,
On 09/11/2018 12:24 PM, Michal Simek wrote:
Hi,
On 11.9.2018 09:31, Patrice CHOTARD wrote:
Hi Michal
On 09/11/2018 07:51 AM, Michal Simek wrote:
On 10.9.2018 18:11, Patrice Chotard wrote:
This series :
- Add new gpio ops get_alt_function
- Add get_function and get_alt_function support to stm32 gpio driver
- Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Currently, get_function callback returns the state of a gpio (GPIOF_INPUT, GPIOF_OUTPUT or GPIO_FUNC).
If a pin's state is GPIO_FUNC, it's useful to know which alternate function is selected for debug purpose.
As example, on STM32 SoCs, a pins can be configured as GPIO or also configured with up to 16 alternate function. Using command "gpio", user can retrieve this information as shown below:
STM32MP> gpio state -a
Bank GPIOA: GPIOA0: unused: 0 [ ] GPIOA1: unused: 0 [ ] GPIOA2: unused: 0 [ ] GPIOA3: unused: 0 [ ] GPIOA4: unused: 0 [ ] GPIOA5: unused: 0 [ ] GPIOA6: unused: 0 [ ] GPIOA7: unused: 0 [ ] GPIOA8: func: 9 GPIOA9: func: 10 GPIOA10: unused: 0 [ ] GPIOA11: unused: 0 [ ] GPIOA12: unused: 0 [ ] GPIOA13: output: 1 [x] red.gpios GPIOA14: output: 0 [x] green.gpios GPIOA15: unused: 0 [ ]
It shows that pin 8 and 9 of bank A are configured respectively in alternate function 9 and 10.
Can you list that functionality? Isn't it something what should be shown with a name instead of number?
Listing this functionality is possible and printing name instead of number also, but for each pins, alternate function configuration is different and need to store all these informations into a table, which consumes a lot of memory.
I expect that user has to go to any decode table to find out what 9 or 10 means.
Yes, using the SoC's datasheet, user can find the corresponding alternate function description.
Thanks
Patrice
Thanks, Michal

On 11.9.2018 13:12, Patrice CHOTARD wrote:
Hi,
On 09/11/2018 12:24 PM, Michal Simek wrote:
Hi,
On 11.9.2018 09:31, Patrice CHOTARD wrote:
Hi Michal
On 09/11/2018 07:51 AM, Michal Simek wrote:
On 10.9.2018 18:11, Patrice Chotard wrote:
This series :
- Add new gpio ops get_alt_function
- Add get_function and get_alt_function support to stm32 gpio driver
- Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Currently, get_function callback returns the state of a gpio (GPIOF_INPUT, GPIOF_OUTPUT or GPIO_FUNC).
If a pin's state is GPIO_FUNC, it's useful to know which alternate function is selected for debug purpose.
As example, on STM32 SoCs, a pins can be configured as GPIO or also configured with up to 16 alternate function. Using command "gpio", user can retrieve this information as shown below:
STM32MP> gpio state -a
Bank GPIOA: GPIOA0: unused: 0 [ ] GPIOA1: unused: 0 [ ] GPIOA2: unused: 0 [ ] GPIOA3: unused: 0 [ ] GPIOA4: unused: 0 [ ] GPIOA5: unused: 0 [ ] GPIOA6: unused: 0 [ ] GPIOA7: unused: 0 [ ] GPIOA8: func: 9 GPIOA9: func: 10 GPIOA10: unused: 0 [ ] GPIOA11: unused: 0 [ ] GPIOA12: unused: 0 [ ] GPIOA13: output: 1 [x] red.gpios GPIOA14: output: 0 [x] green.gpios GPIOA15: unused: 0 [ ]
It shows that pin 8 and 9 of bank A are configured respectively in alternate function 9 and 10.
Can you list that functionality? Isn't it something what should be shown with a name instead of number?
Listing this functionality is possible and printing name instead of number also, but for each pins, alternate function configuration is different and need to store all these informations into a table, which consumes a lot of memory.
I expect that user has to go to any decode table to find out what 9 or 10 means.
Yes, using the SoC's datasheet, user can find the corresponding alternate function description.
Can you give some examples of that functionality or link to datasheet and page?
M

On 09/11/2018 02:17 PM, Michal Simek wrote:
On 11.9.2018 13:12, Patrice CHOTARD wrote:
Hi,
On 09/11/2018 12:24 PM, Michal Simek wrote:
Hi,
On 11.9.2018 09:31, Patrice CHOTARD wrote:
Hi Michal
On 09/11/2018 07:51 AM, Michal Simek wrote:
On 10.9.2018 18:11, Patrice Chotard wrote:
This series :
- Add new gpio ops get_alt_function
- Add get_function and get_alt_function support to stm32 gpio driver
- Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Currently, get_function callback returns the state of a gpio (GPIOF_INPUT, GPIOF_OUTPUT or GPIO_FUNC).
If a pin's state is GPIO_FUNC, it's useful to know which alternate function is selected for debug purpose.
As example, on STM32 SoCs, a pins can be configured as GPIO or also configured with up to 16 alternate function. Using command "gpio", user can retrieve this information as shown below:
STM32MP> gpio state -a
Bank GPIOA: GPIOA0: unused: 0 [ ] GPIOA1: unused: 0 [ ] GPIOA2: unused: 0 [ ] GPIOA3: unused: 0 [ ] GPIOA4: unused: 0 [ ] GPIOA5: unused: 0 [ ] GPIOA6: unused: 0 [ ] GPIOA7: unused: 0 [ ] GPIOA8: func: 9 GPIOA9: func: 10 GPIOA10: unused: 0 [ ] GPIOA11: unused: 0 [ ] GPIOA12: unused: 0 [ ] GPIOA13: output: 1 [x] red.gpios GPIOA14: output: 0 [x] green.gpios GPIOA15: unused: 0 [ ]
It shows that pin 8 and 9 of bank A are configured respectively in alternate function 9 and 10.
Can you list that functionality? Isn't it something what should be shown with a name instead of number?
Listing this functionality is possible and printing name instead of number also, but for each pins, alternate function configuration is different and need to store all these informations into a table, which consumes a lot of memory.
I expect that user has to go to any decode table to find out what 9 or 10 means.
Yes, using the SoC's datasheet, user can find the corresponding alternate function description.
Can you give some examples of that functionality or link to datasheet and page?
As example, regarding the pin 8 of bank A (GPIOA8 above), alternate function 9 means that pins is currently configured as SDMMC2_DATA4.
For this pins, here are all the possible alternate function : alternate function description
AF0 MCO0 AF1 TIM1_CH1 AF2 AF3 TIM8_BKIN2 AF4 I2C3_SCL AF5 SPI3_MOSI/SDO AF6 AF7 USART1_CK AF8 SDMMC2 CKIN AF9 SDMMC2 DATA4 AF10 USB_SOF AF11 AF12 SAI4_SD_B AF13 UART7_RX AF14 LCD_R6 AF15 EVENTOUT
Patrice
M _______________________________________________ Uboot-stm32 mailing list Uboot-stm32@st-md-mailman.stormreply.com https://st-md-mailman.stormreply.com/mailman/listinfo/uboot-stm32

On 11.9.2018 15:31, Patrice CHOTARD wrote:
On 09/11/2018 02:17 PM, Michal Simek wrote:
On 11.9.2018 13:12, Patrice CHOTARD wrote:
Hi,
On 09/11/2018 12:24 PM, Michal Simek wrote:
Hi,
On 11.9.2018 09:31, Patrice CHOTARD wrote:
Hi Michal
On 09/11/2018 07:51 AM, Michal Simek wrote:
On 10.9.2018 18:11, Patrice Chotard wrote: > > This series : > - Add new gpio ops get_alt_function > - Add get_function and get_alt_function support to stm32 gpio driver > - Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Currently, get_function callback returns the state of a gpio (GPIOF_INPUT, GPIOF_OUTPUT or GPIO_FUNC).
If a pin's state is GPIO_FUNC, it's useful to know which alternate function is selected for debug purpose.
As example, on STM32 SoCs, a pins can be configured as GPIO or also configured with up to 16 alternate function. Using command "gpio", user can retrieve this information as shown below:
STM32MP> gpio state -a
Bank GPIOA: GPIOA0: unused: 0 [ ] GPIOA1: unused: 0 [ ] GPIOA2: unused: 0 [ ] GPIOA3: unused: 0 [ ] GPIOA4: unused: 0 [ ] GPIOA5: unused: 0 [ ] GPIOA6: unused: 0 [ ] GPIOA7: unused: 0 [ ] GPIOA8: func: 9 GPIOA9: func: 10 GPIOA10: unused: 0 [ ] GPIOA11: unused: 0 [ ] GPIOA12: unused: 0 [ ] GPIOA13: output: 1 [x] red.gpios GPIOA14: output: 0 [x] green.gpios GPIOA15: unused: 0 [ ]
It shows that pin 8 and 9 of bank A are configured respectively in alternate function 9 and 10.
Can you list that functionality? Isn't it something what should be shown with a name instead of number?
Listing this functionality is possible and printing name instead of number also, but for each pins, alternate function configuration is different and need to store all these informations into a table, which consumes a lot of memory.
I expect that user has to go to any decode table to find out what 9 or 10 means.
Yes, using the SoC's datasheet, user can find the corresponding alternate function description.
Can you give some examples of that functionality or link to datasheet and page?
As example, regarding the pin 8 of bank A (GPIOA8 above), alternate function 9 means that pins is currently configured as SDMMC2_DATA4.
For this pins, here are all the possible alternate function :
alternate function description
AF0 MCO0 AF1 TIM1_CH1 AF2 AF3 TIM8_BKIN2 AF4 I2C3_SCL AF5 SPI3_MOSI/SDO AF6 AF7 USART1_CK AF8 SDMMC2 CKIN AF9 SDMMC2 DATA4 AF10 USB_SOF AF11 AF12 SAI4_SD_B AF13 UART7_RX AF14 LCD_R6 AF15 EVENTOUT
ok that means that it is pin mux decoding and you want to use gpio status command to show it. I would expect when you set a value for gpio that nothing is going to change because it is not propagated to output pin.
I can do it for zynq/zynqmp device but I don't think this is something what should be shown via gpio status command. In my case there is even different address range which should be used to get this value.
Anyway I think that it would be better to create regular pinctrl command for this instead of trying to reuse gpio command for that but that's just my opinion.
Thanks, Michal

On 09/11/2018 01:31 AM, Patrice CHOTARD wrote:
Hi Michal
On 09/11/2018 07:51 AM, Michal Simek wrote:
On 10.9.2018 18:11, Patrice Chotard wrote:
This series :
- Add new gpio ops get_alt_function
- Add get_function and get_alt_function support to stm32 gpio driver
- Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Currently, get_function callback returns the state of a gpio (GPIOF_INPUT, GPIOF_OUTPUT or GPIO_FUNC).
If a pin's state is GPIO_FUNC, it's useful to know which alternate function is selected for debug purpose.
This sounds like pinmux not GPIO. There should be a pinmux printing command to dump the pinmux state; the GPIO command shouldn't know about it.

Hi Stephen
On 09/11/2018 07:03 PM, Stephen Warren wrote:
On 09/11/2018 01:31 AM, Patrice CHOTARD wrote:
Hi Michal
On 09/11/2018 07:51 AM, Michal Simek wrote:
On 10.9.2018 18:11, Patrice Chotard wrote:
This series : - Add new gpio ops get_alt_function - Add get_function and get_alt_function support to stm32 gpio driver - Add get_alt_function test
I went quickly over this series and TBH I am not getting what this is for. It looks like that this is the part of pinmux.
Can you please elaborate more what this is for?
Currently, get_function callback returns the state of a gpio (GPIOF_INPUT, GPIOF_OUTPUT or GPIO_FUNC).
If a pin's state is GPIO_FUNC, it's useful to know which alternate function is selected for debug purpose.
This sounds like pinmux not GPIO. There should be a pinmux printing command to dump the pinmux state; the GPIO command shouldn't know about it.
Ok i will abandon this series and submit a new one implementing a new pinmux command.
Thanks
Patrice
participants (4)
-
Michal Simek
-
Patrice CHOTARD
-
Patrice Chotard
-
Stephen Warren