Linux-GPIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3] pinctrl: core: print gpio in pins debugfs file
@ 2020-07-21 14:02 Drew Fustini
  2020-07-21 14:10 ` Drew Fustini
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Fustini @ 2020-07-21 14:02 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
chip and line index for the pin in the debugfs 'pins' file with the
format: "[gpiochip-label]:line-[index] "

For example, here is a section of 'pins' the PocketBeagle (AM3358):
/sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins

pin 25 (PIN25) gpio-32-63:line-25 44e10864 00000037 pinctrl-single 
pin 26 (PIN26) gpio-32-63:line-26 44e10868 00000037 pinctrl-single 
pin 27 (PIN27) gpio-32-63:line-27 44e1086c 00000037 pinctrl-single 
pin 28 (PIN28) NA 44e10870 00000036 pinctrl-single 
pin 29 (PIN29) NA 44e10874 00000006 pinctrl-single 
pin 30 (PIN30) gpio-32-63:line-28 44e10878 00000027 pinctrl-single 
pin 31 (PIN31) gpio-32-63:line-29 44e1087c 00000037 pinctrl-single 
pin 32 (PIN32) gpio-32-63:line-30 44e10880 00000037 pinctrl-single 
pin 33 (PIN33) gpio-32-63:line-31 44e10884 00000037 pinctrl-single 
pin 34 (PIN34) gpio-64-95:line-0 44e10888 00000037 pinctrl-single 
pin 35 (PIN35) gpio-64-95:line-1 44e1088c 00000037 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>

v3 changes:
- gpio column is now gpiochip label and line index

v2 changes:
- print 'NA' if pin does not have a GPIO number
- change gpio_num from unsigned to unsigned int per checkpatch
---
 drivers/pinctrl/core.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 821242bb4b16..a23dc264cae7 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,9 @@ 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;
 
 	seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
 
@@ -1618,6 +1622,23 @@ 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;
+			}
+		}
+		chip = gpio_to_chip(gpio_num);
+		if (chip && chip->gpiodev && chip->gpiodev->base)
+			seq_printf(s, "%s:line-%u ", chip->label,
+				gpio_num - chip->gpiodev->base);
+		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

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

On Tue, Jul 21, 2020 at 04:02:34PM +0200, Drew Fustini wrote:
> If there is a gpio range mapping for the pin, then print out the gpio
> chip and line index for the pin in the debugfs 'pins' file with the
> format: "[gpiochip-label]:line-[index] "
> 
> For example, here is a section of 'pins' the PocketBeagle (AM3358):
> /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins
> 
> pin 25 (PIN25) gpio-32-63:line-25 44e10864 00000037 pinctrl-single 
> pin 26 (PIN26) gpio-32-63:line-26 44e10868 00000037 pinctrl-single 
> pin 27 (PIN27) gpio-32-63:line-27 44e1086c 00000037 pinctrl-single 
> pin 28 (PIN28) NA 44e10870 00000036 pinctrl-single 
> pin 29 (PIN29) NA 44e10874 00000006 pinctrl-single 
> pin 30 (PIN30) gpio-32-63:line-28 44e10878 00000027 pinctrl-single 
> pin 31 (PIN31) gpio-32-63:line-29 44e1087c 00000037 pinctrl-single 
> pin 32 (PIN32) gpio-32-63:line-30 44e10880 00000037 pinctrl-single 
> pin 33 (PIN33) gpio-32-63:line-31 44e10884 00000037 pinctrl-single 
> pin 34 (PIN34) gpio-64-95:line-0 44e10888 00000037 pinctrl-single 
> pin 35 (PIN35) gpio-64-95:line-1 44e1088c 00000037 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>
> 
> v3 changes:
> - gpio column is now gpiochip label and line index
> 
> v2 changes:
> - print 'NA' if pin does not have a GPIO number
> - change gpio_num from unsigned to unsigned int per checkpatch
> ---
>  drivers/pinctrl/core.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> index 821242bb4b16..a23dc264cae7 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,9 @@ 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;
>  
>  	seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
>  
> @@ -1618,6 +1622,23 @@ 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;
> +			}
> +		}
> +		chip = gpio_to_chip(gpio_num);
> +		if (chip && chip->gpiodev && chip->gpiodev->base)
> +			seq_printf(s, "%s:line-%u ", chip->label,
> +				gpio_num - chip->gpiodev->base);
> +		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
> 

Apologies - I should not have put the change log in the commit message.
Please let me know if I should resubmit.

thanks,
drew

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

* Re: [PATCH v3] pinctrl: core: print gpio in pins debugfs file
  2020-07-21 14:10 ` Drew Fustini
@ 2020-07-21 14:17   ` Andy Shevchenko
  2020-07-21 14:19     ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2020-07-21 14:17 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 Tue, Jul 21, 2020 at 5:10 PM Drew Fustini <drew@beagleboard.org> wrote:
> On Tue, Jul 21, 2020 at 04:02:34PM +0200, Drew Fustini wrote:
> > If there is a gpio range mapping for the pin, then print out the gpio
> > chip and line index for the pin in the debugfs 'pins' file with the
> > format: "[gpiochip-label]:line-[index] "
> >
> > For example, here is a section of 'pins' the PocketBeagle (AM3358):
> > /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins
> >
> > pin 25 (PIN25) gpio-32-63:line-25 44e10864 00000037 pinctrl-single
> > pin 26 (PIN26) gpio-32-63:line-26 44e10868 00000037 pinctrl-single
> > pin 27 (PIN27) gpio-32-63:line-27 44e1086c 00000037 pinctrl-single
> > pin 28 (PIN28) NA 44e10870 00000036 pinctrl-single
> > pin 29 (PIN29) NA 44e10874 00000006 pinctrl-single
> > pin 30 (PIN30) gpio-32-63:line-28 44e10878 00000027 pinctrl-single
> > pin 31 (PIN31) gpio-32-63:line-29 44e1087c 00000037 pinctrl-single
> > pin 32 (PIN32) gpio-32-63:line-30 44e10880 00000037 pinctrl-single
> > pin 33 (PIN33) gpio-32-63:line-31 44e10884 00000037 pinctrl-single
> > pin 34 (PIN34) gpio-64-95:line-0 44e10888 00000037 pinctrl-single
> > pin 35 (PIN35) gpio-64-95:line-1 44e1088c 00000037 pinctrl-single

Because line is integer and label is string it is better (from parsing
of view) to put it other way around, i.e.

%u:%s, label, line

...

> Apologies - I should not have put the change log in the commit message.
> Please let me know if I should resubmit.

Since the above comment, I guess it would be good.
Thanks for doing this!

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v3] pinctrl: core: print gpio in pins debugfs file
  2020-07-21 14:17   ` Andy Shevchenko
@ 2020-07-21 14:19     ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2020-07-21 14:19 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 Tue, Jul 21, 2020 at 5:17 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Tue, Jul 21, 2020 at 5:10 PM Drew Fustini <drew@beagleboard.org> wrote:
> > On Tue, Jul 21, 2020 at 04:02:34PM +0200, Drew Fustini wrote:
> > > If there is a gpio range mapping for the pin, then print out the gpio
> > > chip and line index for the pin in the debugfs 'pins' file with the
> > > format: "[gpiochip-label]:line-[index] "

...

> > > pin 25 (PIN25) gpio-32-63:line-25 44e10864 00000037 pinctrl-single
> > > pin 26 (PIN26) gpio-32-63:line-26 44e10868 00000037 pinctrl-single
> > > pin 27 (PIN27) gpio-32-63:line-27 44e1086c 00000037 pinctrl-single
> > > pin 28 (PIN28) NA 44e10870 00000036 pinctrl-single
> > > pin 29 (PIN29) NA 44e10874 00000006 pinctrl-single

And would be also better to have

0:N/A

to keep both arguments in it.

> Because line is integer and label is string it is better (from parsing
> of view) to put it other way around, i.e.
>
> %u:%s, label, line
>
> ...
>
> > Apologies - I should not have put the change log in the commit message.
> > Please let me know if I should resubmit.
>
> Since the above comment, I guess it would be good.
> Thanks for doing this!

-- 
With Best Regards,
Andy Shevchenko

^ 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-21 14:02 [PATCH v3] pinctrl: core: print gpio in pins debugfs file Drew Fustini
2020-07-21 14:10 ` Drew Fustini
2020-07-21 14:17   ` Andy Shevchenko
2020-07-21 14:19     ` Andy Shevchenko

Linux-GPIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-gpio/0 linux-gpio/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-gpio linux-gpio/ https://lore.kernel.org/linux-gpio \
		linux-gpio@vger.kernel.org
	public-inbox-index linux-gpio

Example config snippet for mirrors

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


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