diff mbox series

pinctrl: single: print gpio number in pins debugfs file

Message ID 20200717013338.1741659-1-drew@beagleboard.org (mailing list archive)
State New, archived
Headers show
Series pinctrl: single: print gpio number in pins debugfs file | expand

Commit Message

Drew Fustini July 17, 2020, 1:33 a.m. UTC
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 on the BeagleBone Black:

  $ cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |head -20
  registered pins: 142
  pin 0 (PIN0) 44e10800 00000027 pinctrl-single GPIO-32
  pin 1 (PIN1) 44e10804 00000027 pinctrl-single GPIO-33
  pin 2 (PIN2) 44e10808 00000027 pinctrl-single GPIO-34
  pin 3 (PIN3) 44e1080c 00000027 pinctrl-single GPIO-35
  pin 4 (PIN4) 44e10810 00000027 pinctrl-single GPIO-36
  pin 5 (PIN5) 44e10814 00000027 pinctrl-single GPIO-37
  pin 6 (PIN6) 44e10818 00000027 pinctrl-single GPIO-38
  pin 7 (PIN7) 44e1081c 00000027 pinctrl-single GPIO-39
  pin 8 (PIN8) 44e10820 00000027 pinctrl-single GPIO-22
  pin 9 (PIN9) 44e10824 00000030 pinctrl-single GPIO-23
  pin 10 (PIN10) 44e10828 00000030 pinctrl-single GPIO-26
  pin 11 (PIN11) 44e1082c 00000030 pinctrl-single GPIO-27
  pin 12 (PIN12) 44e10830 00000030 pinctrl-single GPIO-44
  pin 13 (PIN13) 44e10834 00000030 pinctrl-single GPIO-45
  pin 14 (PIN14) 44e10838 00000030 pinctrl-single GPIO-46
  pin 15 (PIN15) 44e1083c 00000030 pinctrl-single GPIO-47
  pin 16 (PIN16) 44e10840 00000027 pinctrl-single GPIO-48
  pin 17 (PIN17) 44e10844 00000027 pinctrl-single GPIO-49
  pin 18 (PIN18) 44e10848 00000000 pinctrl-single GPIO-50

Signed-off-by: Drew Fustini <drew@beagleboard.org>
---
 drivers/pinctrl/pinctrl-single.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko July 17, 2020, 3:14 p.m. UTC | #1
On Fri, Jul 17, 2020 at 4:36 AM 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 on the BeagleBone Black:

>   pin 0 (PIN0) 44e10800 00000027 pinctrl-single GPIO-32
>   pin 1 (PIN1) 44e10804 00000027 pinctrl-single GPIO-33
>   pin 2 (PIN2) 44e10808 00000027 pinctrl-single GPIO-34
>   pin 3 (PIN3) 44e1080c 00000027 pinctrl-single GPIO-35
>   pin 4 (PIN4) 44e10810 00000027 pinctrl-single GPIO-36
>   pin 5 (PIN5) 44e10814 00000027 pinctrl-single GPIO-37
>   pin 6 (PIN6) 44e10818 00000027 pinctrl-single GPIO-38
>   pin 7 (PIN7) 44e1081c 00000027 pinctrl-single GPIO-39
>   pin 8 (PIN8) 44e10820 00000027 pinctrl-single GPIO-22
>   pin 9 (PIN9) 44e10824 00000030 pinctrl-single GPIO-23

Wouldn't it be better to have this for all types of pin controllers?
But I'm not sure about the format of output.
Drew Fustini July 17, 2020, 7:50 p.m. UTC | #2
On Fri, Jul 17, 2020 at 06:14:06PM +0300, Andy Shevchenko wrote:
> On Fri, Jul 17, 2020 at 4:36 AM 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 on the BeagleBone Black:
> 
> >   pin 0 (PIN0) 44e10800 00000027 pinctrl-single GPIO-32
> >   pin 1 (PIN1) 44e10804 00000027 pinctrl-single GPIO-33
> >   pin 2 (PIN2) 44e10808 00000027 pinctrl-single GPIO-34
> >   pin 3 (PIN3) 44e1080c 00000027 pinctrl-single GPIO-35
> >   pin 4 (PIN4) 44e10810 00000027 pinctrl-single GPIO-36
> >   pin 5 (PIN5) 44e10814 00000027 pinctrl-single GPIO-37
> >   pin 6 (PIN6) 44e10818 00000027 pinctrl-single GPIO-38
> >   pin 7 (PIN7) 44e1081c 00000027 pinctrl-single GPIO-39
> >   pin 8 (PIN8) 44e10820 00000027 pinctrl-single GPIO-22
> >   pin 9 (PIN9) 44e10824 00000030 pinctrl-single GPIO-23
> 
> Wouldn't it be better to have this for all types of pin controllers?
> But I'm not sure about the format of output.
> 
> -- 
> With Best Regards,
> Andy Shevchenko

I added the gpio column based on Tony's feedback [0].

I'm not sure how I could do it genericly.

The pin_dbg_show callback is implemented in pcs_pin_dbg_show() which
prints the contents of each line in the 'pins' file.

Any advice on how I could implement a gpio column for 'pins' file
without chaning the pin_dbg_show in all the drivers?A

thanks,
drew

[0] https://lore.kernel.org/linux-gpio/20200713180519.GN5849@atomide.com/
Andy Shevchenko July 17, 2020, 8:09 p.m. UTC | #3
On Fri, Jul 17, 2020 at 10:50 PM Drew Fustini <drew@beagleboard.org> wrote:
> On Fri, Jul 17, 2020 at 06:14:06PM +0300, Andy Shevchenko wrote:
> > On Fri, Jul 17, 2020 at 4:36 AM Drew Fustini <drew@beagleboard.org> wrote:

...

> > >   pin 0 (PIN0) 44e10800 00000027 pinctrl-single GPIO-32
> > >   pin 1 (PIN1) 44e10804 00000027 pinctrl-single GPIO-33
> > >   pin 2 (PIN2) 44e10808 00000027 pinctrl-single GPIO-34
> > >   pin 3 (PIN3) 44e1080c 00000027 pinctrl-single GPIO-35
> > >   pin 4 (PIN4) 44e10810 00000027 pinctrl-single GPIO-36
> > >   pin 5 (PIN5) 44e10814 00000027 pinctrl-single GPIO-37
> > >   pin 6 (PIN6) 44e10818 00000027 pinctrl-single GPIO-38
> > >   pin 7 (PIN7) 44e1081c 00000027 pinctrl-single GPIO-39
> > >   pin 8 (PIN8) 44e10820 00000027 pinctrl-single GPIO-22
> > >   pin 9 (PIN9) 44e10824 00000030 pinctrl-single GPIO-23
> >
> > Wouldn't it be better to have this for all types of pin controllers?
> > But I'm not sure about the format of output.

...

> I added the gpio column based on Tony's feedback [0].
>
> I'm not sure how I could do it genericly.
>
> The pin_dbg_show callback is implemented in pcs_pin_dbg_show() which
> prints the contents of each line in the 'pins' file.
>
> Any advice on how I could implement a gpio column for 'pins' file
> without chaning the pin_dbg_show in all the drivers?A

My question was exactly about changing core, i.e. pinctrl_pins_show(),
rather than each driver.
Drew Fustini July 17, 2020, 10:56 p.m. UTC | #4
On Fri, Jul 17, 2020 at 11:09:11PM +0300, Andy Shevchenko wrote:
> On Fri, Jul 17, 2020 at 10:50 PM Drew Fustini <drew@beagleboard.org> wrote:
> > On Fri, Jul 17, 2020 at 06:14:06PM +0300, Andy Shevchenko wrote:
> > > On Fri, Jul 17, 2020 at 4:36 AM Drew Fustini <drew@beagleboard.org> wrote:
> 
> ...
> 
> > > >   pin 0 (PIN0) 44e10800 00000027 pinctrl-single GPIO-32
> > > >   pin 1 (PIN1) 44e10804 00000027 pinctrl-single GPIO-33
> > > >   pin 2 (PIN2) 44e10808 00000027 pinctrl-single GPIO-34
> > > >   pin 3 (PIN3) 44e1080c 00000027 pinctrl-single GPIO-35
> > > >   pin 4 (PIN4) 44e10810 00000027 pinctrl-single GPIO-36
> > > >   pin 5 (PIN5) 44e10814 00000027 pinctrl-single GPIO-37
> > > >   pin 6 (PIN6) 44e10818 00000027 pinctrl-single GPIO-38
> > > >   pin 7 (PIN7) 44e1081c 00000027 pinctrl-single GPIO-39
> > > >   pin 8 (PIN8) 44e10820 00000027 pinctrl-single GPIO-22
> > > >   pin 9 (PIN9) 44e10824 00000030 pinctrl-single GPIO-23
> > >
> > > Wouldn't it be better to have this for all types of pin controllers?
> > > But I'm not sure about the format of output.
> 
> ...
> 
> > I added the gpio column based on Tony's feedback [0].
> >
> > I'm not sure how I could do it genericly.
> >
> > The pin_dbg_show callback is implemented in pcs_pin_dbg_show() which
> > prints the contents of each line in the 'pins' file.
> >
> > Any advice on how I could implement a gpio column for 'pins' file
> > without chaning the pin_dbg_show in all the drivers?A
> 
> My question was exactly about changing core, i.e. pinctrl_pins_show(),
> rather than each driver.
> 
> -- 
> With Best Regards,
> Andy Shevchenko

Ah ok, so I see in pinctrl_pins_show() that it prints:

                seq_printf(s, "pin %d (%s) ", pin, desc->name);

and then calls ops->pin_dbg_show() to have the driver finish printing
the line.

I will try to add the gpio number to the seq_printf() after desc->name.

thanks,
drew
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index f3a8a465d27e..473fe0f61792 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -275,6 +275,14 @@  static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev,
 	unsigned val, mux_bytes;
 	unsigned long offset;
 	size_t pa;
+	struct pinctrl_gpio_range *range;
+	unsigned 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);
+	}
 
 	pcs = pinctrl_dev_get_drvdata(pctldev);
 
@@ -283,7 +291,10 @@  static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev,
 	val = pcs->read(pcs->base + offset);
 	pa = pcs->res->start + offset;
 
-	seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME);
+	if (gpio_num > 0)
+		seq_printf(s, "%zx %08x %s GPIO-%u", pa, val, DRIVER_NAME, gpio_num);
+	else
+		seq_printf(s, "%zx %08x %s", pa, val, DRIVER_NAME);
 }
 
 static void pcs_dt_free_map(struct pinctrl_dev *pctldev,