linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: core: print gpio in pins debugfs file
@ 2020-07-18 15:49 Drew Fustini
  2020-07-18 17:24 ` Tony Lindgren
  2020-07-20 14:26 ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Drew Fustini @ 2020-07-18 15:49 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) 44e109b8 00000030 pinctrl-single
pin 111 (PIN111) 44e109bc 00000028 pinctrl-single
pin 112 (PIN112) 44e109c0 00000030 pinctrl-single
pin 113 (PIN113) 44e109c4 00000028 pinctrl-single
pin 114 (PIN114) 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>
---
Note:
- I am hoping to get feedback if another format is better.  Currently
  the column 'GPIO-xxx' will only be printed when there is a GPIO num

 drivers/pinctrl/core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 70e13fcd94c4..e3eee950a553 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1633,6 +1633,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 gpio_num;
 
 	seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
 
@@ -1650,6 +1652,16 @@ 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);
+
 		/* Driver-specific info per pin */
 		if (ops->pin_dbg_show)
 			ops->pin_dbg_show(pctldev, s, pin);
-- 
2.25.1


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

* Re: [PATCH] pinctrl: core: print gpio in pins debugfs file
  2020-07-18 15:49 [PATCH] pinctrl: core: print gpio in pins debugfs file Drew Fustini
@ 2020-07-18 17:24 ` Tony Lindgren
  2020-07-20 14:26 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Tony Lindgren @ 2020-07-18 17:24 UTC (permalink / raw)
  To: Drew Fustini
  Cc: Andy Shevchenko, Linus Walleij, linux-omap, linux-gpio,
	linux-kernel, Jason Kridner, Robert Nelson

* Drew Fustini <drew@beagleboard.org> [200718 15:53]:
> 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) 44e109b8 00000030 pinctrl-single
> pin 111 (PIN111) 44e109bc 00000028 pinctrl-single
> pin 112 (PIN112) 44e109c0 00000030 pinctrl-single
> pin 113 (PIN113) 44e109c4 00000028 pinctrl-single
> pin 114 (PIN114) 44e109c8 00000028 pinctrl-single

This looks nice to me, maybe just show NA if no GPIO name is
available?

This is debugfs so the output format can change at any point
AFAIK.

Regards,

Tony

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

* Re: [PATCH] pinctrl: core: print gpio in pins debugfs file
  2020-07-18 15:49 [PATCH] pinctrl: core: print gpio in pins debugfs file Drew Fustini
  2020-07-18 17:24 ` Tony Lindgren
@ 2020-07-20 14:26 ` Linus Walleij
  2020-07-20 19:21   ` Drew Fustini
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2020-07-20 14:26 UTC (permalink / raw)
  To: Drew Fustini
  Cc: Andy Shevchenko, Tony Lindgren, Linux-OMAP,
	open list:GPIO SUBSYSTEM, linux-kernel, Jason Kridner,
	Robert Nelson

Hi Drew,

thanks for this patch, we're going the right direction here
and creating things that are generically useful.

On Sat, Jul 18, 2020 at 5:53 PM Drew Fustini <drew@beagleboard.org> wrote:

> pin 103 (PIN103) GPIO-113 44e1099c 00000027 pinctrl-single
> pin 104 (PIN104) GPIO-114 44e109a0 0000002c pinctrl-single
(...)

Uh oh, that is the global GPIO number that we want to get
rid of.

> +               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);

There should be a break; here should it not?

> +               }
> +
> +               if (gpio_num > 0)
> +                       seq_printf(s, "GPIO-%u ", gpio_num);

Can we print the gpio_chip name and offset instead?
I want to discourage the world from thinking about these
global GPIO numbers.

You can fetch the gpio_chip for the range pretty easily
with

struct gpio_chip *chip = gpio_to_chip(gpio_num);

Also notice that this code needs to be
#ifdef CONFIG_GPIOLIB somehow
(maybe IS_ENABLED() works) because there
are pin controllers in use without gpiolib believe it
or not.

Yours,
Linus Walleij

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

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

On Mon, Jul 20, 2020 at 04:26:21PM +0200, Linus Walleij wrote:
> Hi Drew,
> 
> thanks for this patch, we're going the right direction here
> and creating things that are generically useful.
> 
> On Sat, Jul 18, 2020 at 5:53 PM Drew Fustini <drew@beagleboard.org> wrote:
> 
> > pin 103 (PIN103) GPIO-113 44e1099c 00000027 pinctrl-single
> > pin 104 (PIN104) GPIO-114 44e109a0 0000002c pinctrl-single
> (...)
> 
> Uh oh, that is the global GPIO number that we want to get
> rid of.
> 
> > +               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);
> 
> There should be a break; here should it not?

Yes, good point. 

> > +               }
> > +
> > +               if (gpio_num > 0)
> > +                       seq_printf(s, "GPIO-%u ", gpio_num);
> 
> Can we print the gpio_chip name and offset instead?
> I want to discourage the world from thinking about these
> global GPIO numbers.
> 
> You can fetch the gpio_chip for the range pretty easily
> with
> 
> struct gpio_chip *chip = gpio_to_chip(gpio_num);
> 
> Also notice that this code needs to be
> #ifdef CONFIG_GPIOLIB somehow
> (maybe IS_ENABLED() works) because there
> are pin controllers in use without gpiolib believe it
> or not.
> 
> Yours,
> Linus Walleij

I've just posted a v2 [0] which makes sure the gpio information is only
if CONFIG_GPIOLIB.

I had a hard time finding line offset so I printed the line name
instead.  I would appreciate it if you could point me in the right place
to get the offset as that is cleaner in the 'pins' output.

thanks,
drew

[0] https://lore.kernel.org/linux-omap/20200720191740.1974132-1-drew@beagleboard.org/

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

end of thread, other threads:[~2020-07-20 19:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-18 15:49 [PATCH] pinctrl: core: print gpio in pins debugfs file Drew Fustini
2020-07-18 17:24 ` Tony Lindgren
2020-07-20 14:26 ` Linus Walleij
2020-07-20 19:21   ` Drew Fustini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).