Linux-OMAP Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] pinctrl: core: print gpio in pins debugfs file
@ 2020-07-19 13:22 Drew Fustini
  2020-07-19 13:28 ` Drew Fustini
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Fustini @ 2020-07-19 13:22 UTC (permalink / raw)
  To: Andy Shevchenko, Tony Lindgren, Linus Walleij, linux-omap,
	linux-gpio, linux-kernel, Jason Kridner, Robert Nelson
  Cc: Drew Fustini

If there is a gpio range mapping for the pin, then print out the gpio
number for the pin in the debugfs 'pins' file.

Here is an example output on the BeagleBone Black from:
/sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins

pin 103 (PIN103) GPIO-113 44e1099c 00000027 pinctrl-single
pin 104 (PIN104) GPIO-114 44e109a0 0000002c pinctrl-single
pin 105 (PIN105) GPIO-115 44e109a4 00000027 pinctrl-single
pin 106 (PIN106) GPIO-116 44e109a8 00000027 pinctrl-single
pin 107 (PIN107) GPIO-117 44e109ac 00000027 pinctrl-single
pin 108 (PIN108) GPIO-19 44e109b0 00000027 pinctrl-single
pin 109 (PIN109) GPIO-20 44e109b4 00000027 pinctrl-single
pin 110 (PIN110) NA 44e109b8 00000030 pinctrl-single
pin 111 (PIN111) NA 44e109bc 00000028 pinctrl-single
pin 112 (PIN112) NA 44e109c0 00000030 pinctrl-single
pin 113 (PIN113) NA 44e109c4 00000028 pinctrl-single
pin 114 (PIN114) NA 44e109c8 00000028 pinctrl-single

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Suggested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Drew Fustini <drew@beagleboard.org>
---
 drivers/pinctrl/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

v2 changes:
- print 'NA' if pin does not have a GPIO number
- change gpio_num from unsigned to unsigned int per checkpatch

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 821242bb4b16..8478025926a2 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1601,6 +1601,8 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
 	struct pinctrl_dev *pctldev = s->private;
 	const struct pinctrl_ops *ops = pctldev->desc->pctlops;
 	unsigned i, pin;
+	struct pinctrl_gpio_range *range;
+	unsigned int gpio_num;
 
 	seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
 
@@ -1618,6 +1620,18 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
 
 		seq_printf(s, "pin %d (%s) ", pin, desc->name);
 
+		gpio_num = 0;
+		list_for_each_entry(range, &pctldev->gpio_ranges, node) {
+			if ((pin >= range->pin_base) &&
+			    (pin < (range->pin_base + range->npins)))
+				gpio_num = range->base + (pin - range->pin_base);
+		}
+
+		if (gpio_num > 0)
+			seq_printf(s, "GPIO-%u ", gpio_num);
+		else
+			seq_puts(s, "NA ");
+
 		/* Driver-specific info per pin */
 		if (ops->pin_dbg_show)
 			ops->pin_dbg_show(pctldev, s, pin);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] pinctrl: core: print gpio in pins debugfs file
  2020-07-19 13:22 [PATCH v2] pinctrl: core: print gpio in pins debugfs file Drew Fustini
@ 2020-07-19 13:28 ` Drew Fustini
  0 siblings, 0 replies; 4+ messages in thread
From: Drew Fustini @ 2020-07-19 13:28 UTC (permalink / raw)
  To: Andy Shevchenko, Tony Lindgren, Linus Walleij, linux-omap,
	linux-gpio, linux-kernel, Jason Kridner, Robert Nelson

On Sun, Jul 19, 2020 at 03:22:01PM +0200, Drew Fustini wrote:
> If there is a gpio range mapping for the pin, then print out the gpio
> number for the pin in the debugfs 'pins' file.
> 
> Here is an example output on the BeagleBone Black from:
> /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins
> 
> pin 103 (PIN103) GPIO-113 44e1099c 00000027 pinctrl-single
> pin 104 (PIN104) GPIO-114 44e109a0 0000002c pinctrl-single
> pin 105 (PIN105) GPIO-115 44e109a4 00000027 pinctrl-single
> pin 106 (PIN106) GPIO-116 44e109a8 00000027 pinctrl-single
> pin 107 (PIN107) GPIO-117 44e109ac 00000027 pinctrl-single
> pin 108 (PIN108) GPIO-19 44e109b0 00000027 pinctrl-single
> pin 109 (PIN109) GPIO-20 44e109b4 00000027 pinctrl-single
> pin 110 (PIN110) NA 44e109b8 00000030 pinctrl-single
> pin 111 (PIN111) NA 44e109bc 00000028 pinctrl-single
> pin 112 (PIN112) NA 44e109c0 00000030 pinctrl-single
> pin 113 (PIN113) NA 44e109c4 00000028 pinctrl-single
> pin 114 (PIN114) NA 44e109c8 00000028 pinctrl-single
> 
> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Suggested-by: Tony Lindgren <tony@atomide.com>
> Signed-off-by: Drew Fustini <drew@beagleboard.org>
> ---
>  drivers/pinctrl/core.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> v2 changes:
> - print 'NA' if pin does not have a GPIO number
> - change gpio_num from unsigned to unsigned int per checkpatch
> 
> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> index 821242bb4b16..8478025926a2 100644
> --- a/drivers/pinctrl/core.c
> +++ b/drivers/pinctrl/core.c
> @@ -1601,6 +1601,8 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
>  	struct pinctrl_dev *pctldev = s->private;
>  	const struct pinctrl_ops *ops = pctldev->desc->pctlops;
>  	unsigned i, pin;
> +	struct pinctrl_gpio_range *range;
> +	unsigned int gpio_num;
>  
>  	seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
>  
> @@ -1618,6 +1620,18 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
>  
>  		seq_printf(s, "pin %d (%s) ", pin, desc->name);
>  
> +		gpio_num = 0;
> +		list_for_each_entry(range, &pctldev->gpio_ranges, node) {
> +			if ((pin >= range->pin_base) &&
> +			    (pin < (range->pin_base + range->npins)))
> +				gpio_num = range->base + (pin - range->pin_base);
> +		}
> +
> +		if (gpio_num > 0)
> +			seq_printf(s, "GPIO-%u ", gpio_num);
> +		else
> +			seq_puts(s, "NA ");
> +
>  		/* Driver-specific info per pin */
>  		if (ops->pin_dbg_show)
>  			ops->pin_dbg_show(pctldev, s, pin);
> -- 
> 2.25.1
> 

Linus - would it better if I printed the gpio chip and line number
instead of the GPIO number?

If so, any advice on how to best convert the gpio number to the gpio
descriptor inside pinctrl_pins_show()?

Thanks,
Drew

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] pinctrl: core: print gpio in pins debugfs file
  2020-07-20 19:17 Drew Fustini
@ 2020-07-21  6:49 ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2020-07-21  6:49 UTC (permalink / raw)
  To: Drew Fustini
  Cc: Tony Lindgren, Linus Walleij, Linux OMAP Mailing List,
	open list:GPIO SUBSYSTEM, Linux Kernel Mailing List,
	Jason Kridner, Robert Nelson

On Mon, Jul 20, 2020 at 10:18 PM Drew Fustini <drew@beagleboard.org> wrote:
>
> If there is a gpio range mapping for the pin, then print out the gpio
> number for the pin in the debugfs 'pins' file.
>
> Here is an example output on the BeagleBone Black from:
> /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins
>
> pin 100 (PIN100) gpiochip:gpio-96-127 line-name:P1.36 [PWM0A] 44e10990 00000001 pinctrl-single
> pin 101 (PIN101) gpiochip:gpio-96-127 line-name:P1.33 [PRU0.1] 44e10994 00000027 pinctrl-single
> pin 102 (PIN102) gpiochip:gpio-96-127 line-name:P2.32 [PRU0.2] 44e10998 00000027 pinctrl-single

It becomes unnecessarily long. I would drop these 'gpiochip:' and
'line-name:' prefixes and NA case you rather should have the same
amount of arguments, so here would be something like NA NA or alike.



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] pinctrl: core: print gpio in pins debugfs file
@ 2020-07-20 19:17 Drew Fustini
  2020-07-21  6:49 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Fustini @ 2020-07-20 19:17 UTC (permalink / raw)
  To: Andy Shevchenko, Tony Lindgren, Linus Walleij, linux-omap,
	linux-gpio, linux-kernel, Jason Kridner, Robert Nelson
  Cc: Drew Fustini

If there is a gpio range mapping for the pin, then print out the gpio
number for the pin in the debugfs 'pins' file.

Here is an example output on the BeagleBone Black from:
/sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins

pin 100 (PIN100) gpiochip:gpio-96-127 line-name:P1.36 [PWM0A] 44e10990 00000001 pinctrl-single 
pin 101 (PIN101) gpiochip:gpio-96-127 line-name:P1.33 [PRU0.1] 44e10994 00000027 pinctrl-single 
pin 102 (PIN102) gpiochip:gpio-96-127 line-name:P2.32 [PRU0.2] 44e10998 00000027 pinctrl-single 
pin 103 (PIN103) gpiochip:gpio-96-127 line-name:P2.30 [PRU0.3] 44e1099c 00000027 pinctrl-single 
pin 104 (PIN104) gpiochip:gpio-96-127 line-name:P1.31 [PRU0.4] 44e109a0 0000002c pinctrl-single 
pin 105 (PIN105) gpiochip:gpio-96-127 line-name:P2.34 [PRU0.5] 44e109a4 00000027 pinctrl-single 
pin 106 (PIN106) gpiochip:gpio-96-127 line-name:P2.28 [PRU0.6] 44e109a8 00000027 pinctrl-single 
pin 107 (PIN107) gpiochip:gpio-96-127 line-name:P1.29 [PRU0.7] 44e109ac 00000027 pinctrl-single 
pin 108 (PIN108) gpiochip:gpio-0-31 line-name:P2.31 [SPI1_CS] 44e109b0 00000027 pinctrl-single 
pin 109 (PIN109) gpiochip:gpio-0-31 line-name:P1.20 [PRU0.16] 44e109b4 00000027 pinctrl-single 
pin 110 (PIN110) NA 44e109b8 00000030 pinctrl-single 
pin 111 (PIN111) NA 44e109bc 00000028 pinctrl-single 
pin 112 (PIN112) NA 44e109c0 00000030 pinctrl-single 
pin 113 (PIN113) NA 44e109c4 00000028 pinctrl-single 
pin 114 (PIN114) NA 44e109c8 00000028 pinctrl-single 
pin 115 (PIN115) NA 44e109cc 00000028 pinctrl-single 

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Suggested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Drew Fustini <drew@beagleboard.org>
---
 drivers/pinctrl/core.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

v2 changes:
- only include GPIO information if CONFIG_GPIOLIB
- print gpiochip and line name instead of global GPIO number

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 821242bb4b16..b61fab96c5c2 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -27,6 +27,7 @@
 #include <linux/pinctrl/machine.h>
 
 #ifdef CONFIG_GPIOLIB
+#include "../gpio/gpiolib.h"
 #include <asm-generic/gpio.h>
 #endif
 
@@ -1601,6 +1602,11 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
 	struct pinctrl_dev *pctldev = s->private;
 	const struct pinctrl_ops *ops = pctldev->desc->pctlops;
 	unsigned i, pin;
+	struct pinctrl_gpio_range *range;
+	unsigned int gpio_num;
+	struct gpio_chip *chip;
+	struct gpio_desc *gdesc;
+
 
 	seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
 
@@ -1618,6 +1624,30 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
 
 		seq_printf(s, "pin %d (%s) ", pin, desc->name);
 
+#ifdef CONFIG_GPIOLIB
+		gpio_num = 0;
+		list_for_each_entry(range, &pctldev->gpio_ranges, node) {
+			if ((pin >= range->pin_base) &&
+			    (pin < (range->pin_base + range->npins))) {
+				gpio_num = range->base + (pin - range->pin_base);
+				break;
+			}
+		}
+		if (gpio_num > 0) {
+			chip = gpio_to_chip(gpio_num);
+			if (chip != NULL) {
+				if (chip->label)
+					seq_printf(s, "gpiochip:%s ", chip->label);
+			}
+			gdesc = gpio_to_desc(gpio_num);
+			if (gdesc != NULL)
+				if (gdesc->name)
+					seq_printf(s, "line-name:%s ", gdesc->name);
+		} else {
+			seq_puts(s, "NA ");
+		}
+#endif
+
 		/* Driver-specific info per pin */
 		if (ops->pin_dbg_show)
 			ops->pin_dbg_show(pctldev, s, pin);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-19 13:22 [PATCH v2] pinctrl: core: print gpio in pins debugfs file Drew Fustini
2020-07-19 13:28 ` Drew Fustini
2020-07-20 19:17 Drew Fustini
2020-07-21  6:49 ` Andy Shevchenko

Linux-OMAP Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-omap/0 linux-omap/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-omap linux-omap/ https://lore.kernel.org/linux-omap \
		linux-omap@vger.kernel.org
	public-inbox-index linux-omap

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-omap


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git