diff mbox series

[1/3] gpio: Allow to print pin's label even for pin with GPIOF_FUNC function

Message ID 20220802090910.277343-2-patrice.chotard@foss.st.com
State Superseded
Delegated to: Tom Rini
Headers show
Series gpio: update gpio_get_status() | expand

Commit Message

Patrice CHOTARD Aug. 2, 2022, 9:09 a.m. UTC
Currently, if pin's function is GPIOF_FUNC, only "func" if displayed
without any other information. It would be interesting, if information is
available, to indicate which pinmuxing's name is used.

For example, for STM32 SoC's based platform, "gpio status" command
output :

   before
    Bank GPIOZ:
      GPIOZ0: unused : 0 [ ]
      GPIOZ1: unused : 0 [ ]
      GPIOZ2: unused : 0 [ ]
      GPIOZ3: unused : 0 [ ]
      GPIOZ4: func
      GPIOZ5: func
      GPIOZ6: unused : 0 [ ]
      GPIOZ7: unused : 0 [ ]
      GPIOZ8: unknown
      GPIOZ9: unknown
      GPIOZ10: unknown
      GPIOZ11: unknown
      GPIOZ12: unknown
      GPIOZ13: unknown
      GPIOZ14: unknown
      GPIOZ15: unknown

   After
    Bank GPIOZ:
      GPIOZ0: unused : 0 [ ]
      GPIOZ1: unused : 0 [ ]
      GPIOZ2: unused : 0 [ ]
      GPIOZ3: unused : 0 [ ]
      GPIOZ4: func i2c4-0
      GPIOZ5: func i2c4-0
      GPIOZ6: unused : 0 [ ]
      GPIOZ7: unused : 0 [ ]
      GPIOZ8: unknown
      GPIOZ9: unknown
      GPIOZ10: unknown
      GPIOZ11: unknown
      GPIOZ12: unknown
      GPIOZ13: unknown
      GPIOZ14: unknown
      GPIOZ15: unknown

Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
---

 drivers/gpio/gpio-uclass.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Simon Glass Aug. 2, 2022, 12:41 p.m. UTC | #1
On Tue, 2 Aug 2022 at 03:09, Patrice Chotard
<patrice.chotard@foss.st.com> wrote:
>
> Currently, if pin's function is GPIOF_FUNC, only "func" if displayed
> without any other information. It would be interesting, if information is
> available, to indicate which pinmuxing's name is used.
>
> For example, for STM32 SoC's based platform, "gpio status" command
> output :
>
>    before
>     Bank GPIOZ:
>       GPIOZ0: unused : 0 [ ]
>       GPIOZ1: unused : 0 [ ]
>       GPIOZ2: unused : 0 [ ]
>       GPIOZ3: unused : 0 [ ]
>       GPIOZ4: func
>       GPIOZ5: func
>       GPIOZ6: unused : 0 [ ]
>       GPIOZ7: unused : 0 [ ]
>       GPIOZ8: unknown
>       GPIOZ9: unknown
>       GPIOZ10: unknown
>       GPIOZ11: unknown
>       GPIOZ12: unknown
>       GPIOZ13: unknown
>       GPIOZ14: unknown
>       GPIOZ15: unknown
>
>    After
>     Bank GPIOZ:
>       GPIOZ0: unused : 0 [ ]
>       GPIOZ1: unused : 0 [ ]
>       GPIOZ2: unused : 0 [ ]
>       GPIOZ3: unused : 0 [ ]
>       GPIOZ4: func i2c4-0
>       GPIOZ5: func i2c4-0
>       GPIOZ6: unused : 0 [ ]
>       GPIOZ7: unused : 0 [ ]
>       GPIOZ8: unknown
>       GPIOZ9: unknown
>       GPIOZ10: unknown
>       GPIOZ11: unknown
>       GPIOZ12: unknown
>       GPIOZ13: unknown
>       GPIOZ14: unknown
>       GPIOZ15: unknown
>
> Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
> ---
>
>  drivers/gpio/gpio-uclass.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)

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

Do you think you could create a basic test for the gpio command? See
test/dm/acpi.c for an example.

Regards,
Simon
Patrice CHOTARD Aug. 3, 2022, 1:12 p.m. UTC | #2
Hi Simon

On 8/2/22 14:41, Simon Glass wrote:
> On Tue, 2 Aug 2022 at 03:09, Patrice Chotard
> <patrice.chotard@foss.st.com> wrote:
>>
>> Currently, if pin's function is GPIOF_FUNC, only "func" if displayed
>> without any other information. It would be interesting, if information is
>> available, to indicate which pinmuxing's name is used.
>>
>> For example, for STM32 SoC's based platform, "gpio status" command
>> output :
>>
>>    before
>>     Bank GPIOZ:
>>       GPIOZ0: unused : 0 [ ]
>>       GPIOZ1: unused : 0 [ ]
>>       GPIOZ2: unused : 0 [ ]
>>       GPIOZ3: unused : 0 [ ]
>>       GPIOZ4: func
>>       GPIOZ5: func
>>       GPIOZ6: unused : 0 [ ]
>>       GPIOZ7: unused : 0 [ ]
>>       GPIOZ8: unknown
>>       GPIOZ9: unknown
>>       GPIOZ10: unknown
>>       GPIOZ11: unknown
>>       GPIOZ12: unknown
>>       GPIOZ13: unknown
>>       GPIOZ14: unknown
>>       GPIOZ15: unknown
>>
>>    After
>>     Bank GPIOZ:
>>       GPIOZ0: unused : 0 [ ]
>>       GPIOZ1: unused : 0 [ ]
>>       GPIOZ2: unused : 0 [ ]
>>       GPIOZ3: unused : 0 [ ]
>>       GPIOZ4: func i2c4-0
>>       GPIOZ5: func i2c4-0
>>       GPIOZ6: unused : 0 [ ]
>>       GPIOZ7: unused : 0 [ ]
>>       GPIOZ8: unknown
>>       GPIOZ9: unknown
>>       GPIOZ10: unknown
>>       GPIOZ11: unknown
>>       GPIOZ12: unknown
>>       GPIOZ13: unknown
>>       GPIOZ14: unknown
>>       GPIOZ15: unknown
>>
>> Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
>> ---
>>
>>  drivers/gpio/gpio-uclass.c | 16 +++++++++++-----
>>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> Do you think you could create a basic test for the gpio command? See
> test/dm/acpi.c for an example.

OK i will send a v2 with a test

Thanks
Patrice

> 
> Regards,
> Simon
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 0ed32b7217..d60e46159a 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -884,26 +884,31 @@  int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)
 	const struct dm_gpio_ops *ops = gpio_get_ops(dev);
 	struct gpio_dev_priv *priv;
 	char *str = buf;
+	const char *label;
 	int func;
 	int ret;
 	int len;
+	bool used;
 
 	BUILD_BUG_ON(GPIOF_COUNT != ARRAY_SIZE(gpio_function));
 
 	*buf = 0;
 	priv = dev_get_uclass_priv(dev);
-	ret = gpio_get_raw_function(dev, offset, NULL);
+	ret = gpio_get_raw_function(dev, offset, &label);
 	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;
 
+	switch (func) {
+	case GPIOF_FUNC:
+		snprintf(str + len, buffsize - len, " %s", label ? label : "");
+		break;
+	case GPIOF_INPUT:
+	case GPIOF_OUTPUT:
+	case GPIOF_UNUSED:
 		ret = ops->get_value(dev, offset);
 		if (ret < 0)
 			return ret;
@@ -913,6 +918,7 @@  int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)
 			 used ? 'x' : ' ',
 			 used ? " " : "",
 			 label ? label : "");
+		break;
 	}
 
 	return 0;