pinctrl: core: print gpio in pins debugfs file
Subsystems (2)
PATCH v2 1/1 pinctrl: core: print gpio in pins debugfs file
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
--- 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
drivers/pinctrl/core.c +14 -0
@@ -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);
Signature · 1 line
2.25.1
Quoted 65 lines · 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/pinspin 103 (PIN103) GPIO-113
44e1099c00000027 pinctrl-single pin 104 (PIN104) GPIO-11444e109a00000002cpinctrl-single pin 105 (PIN105) GPIO-11544e109a400000027 pinctrl-single pin 106 (PIN106) GPIO-11644e109a800000027 pinctrl-single pin 107 (PIN107) GPIO-11744e109ac00000027 pinctrl-single pin 108 (PIN108) GPIO-1944e109b000000027 pinctrl-single pin 109 (PIN109) GPIO-2044e109b400000027 pinctrl-single pin 110 (PIN110) NA44e109b800000030 pinctrl-single pin 111 (PIN111) NA44e109bc00000028 pinctrl-single pin 112 (PIN112) NA44e109c000000030 pinctrl-single pin 113 (PIN113) NA44e109c400000028 pinctrl-single pin 114 (PIN114) NA44e109c800000028 pinctrl-singleSuggested-by Andy Shevchenko <[email protected]>Suggested-by Tony Lindgren <[email protected]>Signed-off-by Drew Fustini <[email protected]>--- drivers/pinctrl/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)v2 changes:
- print 'NA' if pin does not have a GPIO number
- changegpio_numfrom unsigned to unsigned int per checkpatchdrivers/pinctrl/core.c +14
-0@@ -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);Signature · 1 line
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