Skip to contentSkip to conversation

pinctrl: add helper to expose pinctrl state in debugfs

RFC PATCH Superseded Drew Fustini 2 participants 11 messages Dec 11, 2020 – Dec 19, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 pinctrl: add helper to expose pinctrl state in debugfs

BeagleBoard.org [0] currently uses an out-of-tree driver called bone-pinmux-helper [1] developed by Pantelis Antoniou [2] back in 2013. The driver assists users of our BeagleBone and PocketBeagle boards in rapid prototyping by allowing them to change at run-time between defined set of pinctrl states [3] for each pin on the expansion connectors [4]. This is achieved by exposing a 'state' file in sysfs for each pin which is used by our 'config-pin' utility [5].

Our goal is to eliminate all out-of-tree drivers for BeagleBoard.org boards and thus I have been working to replace bone-pinmux-helper with a new driver that could be acceptable upstream. My understanding is that debugfs, unlike sysfs, could be the appropriate mechanism to expose such functionality.

Here is an example of how pin P9.14 on the BeagleBone Black expansion connector [6] would be represented in device tree:

&am33xx_pinmux {
	/* P9_14 (ZCZ ball U14) gpio1_18 */
	P9_14_default_pin: pinmux_P9_14_default_pin { pinctrl-single,pins = <
		AM33XX_IOPAD(0x0848, PIN_OUTPUT_PULLDOWN | INPUT_EN | MUX_MODE7) >; };
	P9_14_gpio_pin: pinmux_P9_14_gpio_pin { pinctrl-single,pins = <
		AM33XX_IOPAD(0x0848, PIN_OUTPUT | INPUT_EN | MUX_MODE7) >; };
	P9_14_gpio_pu_pin: pinmux_P9_14_gpio_pu_pin { pinctrl-single,pins = <
		AM33XX_IOPAD(0x0848, PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE7) >; };
	P9_14_gpio_pd_pin: pinmux_P9_14_gpio_pd_pin { pinctrl-single,pins = <
		AM33XX_IOPAD(0x0848, PIN_OUTPUT_PULLDOWN | INPUT_EN | MUX_MODE7) >; };
	P9_14_gpio_input_pin: pinmux_P9_14_gpio_input_pin { pinctrl-single,pins = <
		AM33XX_IOPAD(0x0848, PIN_INPUT | MUX_MODE7) >; };
	P9_14_pwm_pin: pinmux_P9_14_pwm_pin { pinctrl-single,pins = <
		AM33XX_IOPAD(0x0848, PIN_OUTPUT_PULLDOWN | INPUT_EN | MUX_MODE6) >; };
};
&ocp {
	/* P9_14 (ZCZ ball U14) */
	P9_14_pinmux {
		compatible = "pinctrl,state-helper";
		status = "okay";
		pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "gpio_input", "pwm";
		pinctrl-0 = <&P9_14_default_pin>;
		pinctrl-1 = <&P9_14_gpio_pin>;
		pinctrl-2 = <&P9_14_gpio_pu_pin>;
		pinctrl-3 = <&P9_14_gpio_pd_pin>;
		pinctrl-4 = <&P9_14_gpio_input_pin>;
		pinctrl-5 = <&P9_14_pwm_pin>;
	};
};

I used the compatible string "pinctrl,state-helper" but would appreciate advice on how to best name this. Should I create a new vendor prefix?

The P9_14_pinmux entry would cause pinctrl-state-helper to be probed. The driver would create the corresponding pinctrl state file in debugfs for the pin. Here is an example of how the state can be read and written from userspace:

root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/ocp\:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
pwm

I would very much appreciate feedback on both this general concept, and also specific areas in which the code should be changed to be acceptable upstream.

Thank you!
Drew

[0] http://beagleboard.org/latest-images
[1] https://github.com/beagleboard/linux/blob/5.4/drivers/misc/cape/beaglebone/bone-pinmux-helper.c
[2] https://github.com/RobertCNelson/linux-dev/blob/master/patches/drivers/ti/gpio/0001-BeagleBone-pinmux-helper.patch
[3] https://github.com/beagleboard/BeagleBoard-DeviceTrees/blob/v5.4.x-ti-overlays/src/arm/am335x-bone-common-univ.dtsi#L2084
[4] https://github.com/beagleboard/beaglebone-black/wiki/System-Reference-Manual#section-7-1
[5] https://github.com/beagleboard/bb.org-overlays/blob/master/tools/beaglebone-universal-io/config-pin
[6] https://beagleboard.org/Support/bone101/#headers

Cc Pantelis Antoniou <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Tony Lindgren <[email protected]>
---
 drivers/pinctrl/Kconfig                |  10 ++
 drivers/pinctrl/Makefile               |   1 +
 drivers/pinctrl/pinctrl-state-helper.c | 233 +++++++++++++++++++++++++
 3 files changed, 244 insertions(+)
 create mode 100644 drivers/pinctrl/pinctrl-state-helper.c
drivers/pinctrl/Kconfig +10 -0
index 8828613c4e0e..4faed5c8c83b 100644
@@ -255,6 +255,16 @@ config PINCTRL_SINGLE
 	help
 	  This selects the device tree based generic pinctrl driver.
 
+config PINCTRL_STATE_HELPER
+	tristate "Helper to expose pinctrl state to debugfs"
+	depends on OF
+	depends on HAS_IOMEM
+	select GENERIC_PINCTRL_GROUPS
+	select GENERIC_PINMUX_FUNCTIONS
+	select GENERIC_PINCONF
+	help
+	  This selects the device tree based generic pinctrl driver.
+
 config PINCTRL_SIRF
 	bool "CSR SiRFprimaII pin controller driver"
 	depends on ARCH_SIRF
drivers/pinctrl/Makefile +1 -0
index 1731b2154df9..156c356dbd3f 100644
@@ -34,6 +34,7 @@ obj-$(CONFIG_PINCTRL_RZA1)	+= pinctrl-rza1.o
 obj-$(CONFIG_PINCTRL_RZA2)	+= pinctrl-rza2.o
 obj-$(CONFIG_PINCTRL_RZN1)	+= pinctrl-rzn1.o
 obj-$(CONFIG_PINCTRL_SINGLE)	+= pinctrl-single.o
+obj-$(CONFIG_PINCTRL_STATE_HELPER)	+= pinctrl-state-helper.o
 obj-$(CONFIG_PINCTRL_SIRF)	+= sirf/
 obj-$(CONFIG_PINCTRL_SX150X)	+= pinctrl-sx150x.o
 obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
drivers/pinctrl/pinctrl-state-helper.c new file +233 -0

233 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Drew Fustini

BeagleBoard.org [0] currently uses an out-of-tree driver called bone-pinmux-helper [1] developed by Pantelis Antoniou [2] back in 2013.

And it looks like it's still using APIs from 2013. Needs quite a clean up.

Quoted 11 lines

The driver assists users of our BeagleBone and PocketBeagle boards in rapid prototyping by allowing them to change at run-time between defined set of pinctrl states [3] for each pin on the expansion connectors [4]. This is achieved by exposing a 'state' file in sysfs for each pin which is used by our 'config-pin' utility [5].

Our goal is to eliminate all out-of-tree drivers for BeagleBoard.org boards and thus I have been working to replace bone-pinmux-helper with a new driver that could be acceptable upstream. My understanding is that debugfs, unlike sysfs, could be the appropriate mechanism to expose such functionality.

Yeah, for debugfs we don't require too much and esp. there is no requirement to keep backward compatibility thru interface. I.o.w. it's *not* an ABI.

...

Quoted 2 lines

I used the compatible string "pinctrl,state-helper" but would appreciate advice on how to best name this. Should I create a new vendor prefix?

Since it's BB specific, it should have file name and compatible string accordingly.
But I'm wondering, why it requires this kind of thing and can't be simply always part of the kernel based on configuration option?

Quoted 10 lines

The P9_14_pinmux entry would cause pinctrl-state-helper to be probed. The driver would create the corresponding pinctrl state file in debugfs for the pin. Here is an example of how the state can be read and written from userspace:

root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/ocp\:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
pwm

Shouldn't it be rather a part of a certain pin control folder:
debug/pinctrl/.../mux/...
?

Quoted 3 lines

I would very much appreciate feedback on both this general concept, and also specific areas in which the code should be changed to be acceptable upstream.

I will give time for more discussion about concepts and so, because code (as stated above) is quite old and requires a lot of cleaning up.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Drew Fustini

BeagleBoard.org [0] currently uses an out-of-tree driver called bone-pinmux-helper [1] developed by Pantelis Antoniou [2] back in 2013.

And it looks like it's still using APIs from 2013. Needs quite a clean up.

Thanks for taking a look at my RFC and responding. It is good to know that it is using out-dated APIs. Would you be able to elaborate?

It interacts with pinctrl core through devm_pinctrl_get(), pinctrl_lookup_state() and pinctrl_select_state(). Is there newer way of doing that?

Quoted 16 lines
Quoted 11 lines

The driver assists users of our BeagleBone and PocketBeagle boards in rapid prototyping by allowing them to change at run-time between defined set of pinctrl states [3] for each pin on the expansion connectors [4]. This is achieved by exposing a 'state' file in sysfs for each pin which is used by our 'config-pin' utility [5].

Our goal is to eliminate all out-of-tree drivers for BeagleBoard.org boards and thus I have been working to replace bone-pinmux-helper with a new driver that could be acceptable upstream. My understanding is that debugfs, unlike sysfs, could be the appropriate mechanism to expose such functionality.

Yeah, for debugfs we don't require too much and esp. there is no requirement to keep backward compatibility thru interface. I.o.w. it's *not* an ABI.

Quoted 7 lines

...

Quoted 2 lines

I used the compatible string "pinctrl,state-helper" but would appreciate advice on how to best name this. Should I create a new vendor prefix?

Since it's BB specific, it should have file name and compatible string accordingly.

At first, I was thinking about this as a beaglebone specific solution and had bone in the driver name and compatible string. But then I realized it could used in other situations where it is beneficial to to read and select a pinctrl state through debugfs.

I'm happy to rebrand the naming as beaglebone if that would be more acceptable.

Quoted 2 lines

But I'm wondering, why it requires this kind of thing and can't be simply always part of the kernel based on configuration option?

Do you mean not having a new CONFIG option for this driver and just have it be enabled by CONFIG_PINCTRL?

Quoted 11 lines
Quoted 10 lines

The P9_14_pinmux entry would cause pinctrl-state-helper to be probed. The driver would create the corresponding pinctrl state file in debugfs for the pin. Here is an example of how the state can be read and written from userspace:

root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/ocp\:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
pwm
Quoted 3 lines

Shouldn't it be rather a part of a certain pin control folder:
debug/pinctrl/.../mux/...
?

Yes, I think that would make sense, but I was struggling to figure out how to do that. pinctrl_init_debugfs() in pinctrl/core.c does create the "pinctrl" directory, but I could not figure out how to use this as the parent dir when calling debugfs_create_dir() in this driver's probe().

I thought there might be a way in debugfs API to use existing directory path as a parent but I couldn't figure anything like that. I would appreciate any advice.

Quoted 7 lines
Quoted 4 lines

I would very much appreciate feedback on both this general concept, and also specific areas in which the code should be changed to be acceptable upstream.

I will give time for more discussion about concepts and so, because code (as stated above) is quite old and requires a lot of cleaning up.

Thanks for taking the time to comment. I'll look at other drivers to see the ways in which this drivers is out-dated.

-Drew

#3 lore raw
Quoted 9 lines · Drew Fustini
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Drew Fustini

BeagleBoard.org [0] currently uses an out-of-tree driver called bone-pinmux-helper [1] developed by Pantelis Antoniou [2] back in 2013.

And it looks like it's still using APIs from 2013. Needs quite a clean up.

Quoted 6 lines

Thanks for taking a look at my RFC and responding. It is good to know that it is using out-dated APIs. Would you be able to elaborate?

It interacts with pinctrl core through devm_pinctrl_get(), pinctrl_lookup_state() and pinctrl_select_state(). Is there newer way of doing that?

No. I'm talking mostly about FS callbacks where some relatively old new APIs can be used, such as kasprintf().

...

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

I used the compatible string "pinctrl,state-helper" but would appreciate advice on how to best name this. Should I create a new vendor prefix?

Since it's BB specific, it should have file name and compatible string accordingly.

Quoted 7 lines

At first, I was thinking about this as a beaglebone specific solution and had bone in the driver name and compatible string. But then I realized it could used in other situations where it is beneficial to to read and select a pinctrl state through debugfs.

I'm happy to rebrand the naming as beaglebone if that would be more acceptable.

See below.

Quoted 5 lines
Quoted 2 lines

But I'm wondering, why it requires this kind of thing and can't be simply always part of the kernel based on configuration option?

Do you mean not having a new CONFIG option for this driver and just have it be enabled by CONFIG_PINCTRL?

No, configuration option stays, but no compatible strings no nothing like that. Just probed always when loaded.
Actually not even sure we want to have it as a module.

...

Quoted 15 lines
Quoted 11 lines
Quoted 10 lines

The P9_14_pinmux entry would cause pinctrl-state-helper to be probed. The driver would create the corresponding pinctrl state file in debugfs for the pin. Here is an example of how the state can be read and written from userspace:

root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/ocp\:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
pwm
Quoted 3 lines

Shouldn't it be rather a part of a certain pin control folder:
debug/pinctrl/.../mux/...
?

Quoted 8 lines

Yes, I think that would make sense, but I was struggling to figure out how to do that. pinctrl_init_debugfs() in pinctrl/core.c does create the "pinctrl" directory, but I could not figure out how to use this as the parent dir when calling debugfs_create_dir() in this driver's probe().

I thought there might be a way in debugfs API to use existing directory path as a parent but I couldn't figure anything like that. I would appreciate any advice.

If the option is boolean from the beginning then you just call it from the corresponding pin control instantiation chain.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Drew Fustini
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Drew Fustini

BeagleBoard.org [0] currently uses an out-of-tree driver called bone-pinmux-helper [1] developed by Pantelis Antoniou [2] back in 2013.

And it looks like it's still using APIs from 2013. Needs quite a clean up.

Thanks for taking a look at my RFC and responding. It is good to know that it is using out-dated APIs. Would you be able to elaborate?

Quoted 6 lines
Quoted 3 lines

It interacts with pinctrl core through devm_pinctrl_get(), pinctrl_lookup_state() and pinctrl_select_state(). Is there newer way of doing that?

No. I'm talking mostly about FS callbacks where some relatively old new APIs can be used, such as kasprintf().

Thanks for following up. I'll will take a look at that and update the code.

Quoted 16 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

I used the compatible string "pinctrl,state-helper" but would appreciate advice on how to best name this. Should I create a new vendor prefix?

Since it's BB specific, it should have file name and compatible string accordingly.

Quoted 7 lines

At first, I was thinking about this as a beaglebone specific solution and had bone in the driver name and compatible string. But then I realized it could used in other situations where it is beneficial to to read and select a pinctrl state through debugfs.

I'm happy to rebrand the naming as beaglebone if that would be more acceptable.

See below.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

But I'm wondering, why it requires this kind of thing and can't be simply always part of the kernel based on configuration option?

Do you mean not having a new CONFIG option for this driver and just have it be enabled by CONFIG_PINCTRL?

No, configuration option stays, but no compatible strings no nothing like that. Just probed always when loaded.

I first started down the route of implementing this inside of pinctrl-single. I found it didn't work because devm_pinctrl_get() would fail. I think was because it was happening too early for pinctrl to be ready.

I do think it seems awkward to have to add this to dts and have the driver get probed for each entry:

        P1_04_pinmux {
                compatible = "pinctrl,state-helper";
                status = "okay";
                pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "gpio_input", "pruout", "pruin";
                pinctrl-0 = <&P1_04_default_pin>;
                pinctrl-1 = <&P1_04_gpio_pin>;
                pinctrl-2 = <&P1_04_gpio_pu_pin>;
                pinctrl-3 = <&P1_04_gpio_pd_pin>;
                pinctrl-4 = <&P1_04_gpio_input_pin>;
                pinctrl-5 = <&P1_04_pruout_pin>;
                pinctrl-6 = <&P1_04_pruin_pin>;
        };

But I am having a hard time figuring out another way of doing it.

Any ideas as to what would trigger the probe() if there was not a match on a compatible like "pinctrl,state-helper"?

Quoted 1 line

Actually not even sure we want to have it as a module.

And have just be a part of one of the existing pinctrl files like core.c?

Quoted 23 lines

...

Quoted 20 lines
Quoted 11 lines
Quoted 10 lines

The P9_14_pinmux entry would cause pinctrl-state-helper to be probed. The driver would create the corresponding pinctrl state file in debugfs for the pin. Here is an example of how the state can be read and written from userspace:

root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/ocp\:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/ocp\:P9_14_pinmux/state
pwm
Quoted 3 lines

Shouldn't it be rather a part of a certain pin control folder:
debug/pinctrl/.../mux/...
?

Yes, I think that would make sense, but I was struggling to figure out how to do that. pinctrl_init_debugfs() in pinctrl/core.c does create the "pinctrl" directory, but I could not figure out how to use this as the parent dir when calling debugfs_create_dir() in this driver's probe().

Quoted 6 lines
Quoted 3 lines

I thought there might be a way in debugfs API to use existing directory path as a parent but I couldn't figure anything like that. I would appreciate any advice.

If the option is boolean from the beginning then you just call it from the corresponding pin control instantiation chain.

Sorry, I am not sure I understand what you mean here. What does "option" mean in this context? I don't think there is any value that is boolean invovled. The pinctrl states are strings.

With regards to parent directory, I did discover there is debugfs_lookup(), so I can get the dentry for "pinctrl" and create new subdirectory inside of it. This is the structure now:

/sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_35_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_34_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_33_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_32_pinmux/state etc..

Quoted 4 lines
Signature · 3 lines
-- 
With Best Regards,
Andy Shevchenko

Thanks for reviewing,
Drew

#5 lore raw
Quoted 4 lines · Drew Fustini
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Drew Fustini
Quoted 1 line · Andy Shevchenko

On Fri, Dec 11, 2020 at 1:54 PM Drew Fustini <[email protected]> wrote:

...

Quoted 30 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

But I'm wondering, why it requires this kind of thing and can't be simply always part of the kernel based on configuration option?

Do you mean not having a new CONFIG option for this driver and just have it be enabled by CONFIG_PINCTRL?

No, configuration option stays, but no compatible strings no nothing like that. Just probed always when loaded.

I first started down the route of implementing this inside of pinctrl-single. I found it didn't work because devm_pinctrl_get() would fail. I think was because it was happening too early for pinctrl to be ready.

I do think it seems awkward to have to add this to dts and have the driver get probed for each entry:

        P1_04_pinmux {
                compatible = "pinctrl,state-helper";
                status = "okay";
                pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "gpio_input", "pruout", "pruin";
                pinctrl-0 = <&P1_04_default_pin>;
                pinctrl-1 = <&P1_04_gpio_pin>;
                pinctrl-2 = <&P1_04_gpio_pu_pin>;
                pinctrl-3 = <&P1_04_gpio_pd_pin>;
                pinctrl-4 = <&P1_04_gpio_input_pin>;
                pinctrl-5 = <&P1_04_pruout_pin>;
                pinctrl-6 = <&P1_04_pruin_pin>;
        };
Quoted 1 line

But I am having a hard time figuring out another way of doing it.

I'm not a DT expert and I have no clue why you need all this. To me it looks over engineered to engage DT for debugging things. OTOH, you may add a property to allow debug mux (but it prevent ACPI enabled platforms to utilize this).

...

Quoted 6 lines

Any ideas as to what would trigger the probe() if there was not a match on a compatible like "pinctrl,state-helper"?

Quoted 1 line

Actually not even sure we want to have it as a module.

And have just be a part of one of the existing pinctrl files like core.c?

Separate file, but in conjunction with core.c and pinmux and so on.

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 3 lines

Shouldn't it be rather a part of a certain pin control folder:
debug/pinctrl/.../mux/...
?

Yes, I think that would make sense, but I was struggling to figure out how to do that. pinctrl_init_debugfs() in pinctrl/core.c does create the "pinctrl" directory, but I could not figure out how to use this as the parent dir when calling debugfs_create_dir() in this driver's probe().

I thought there might be a way in debugfs API to use existing directory path as a parent but I couldn't figure anything like that. I would appreciate any advice.

Quoted 6 lines
Quoted 2 lines

If the option is boolean from the beginning then you just call it from the corresponding pin control instantiation chain.

Sorry, I am not sure I understand what you mean here. What does "option" mean in this context? I don't think there is any value that is boolean invovled. The pinctrl states are strings.

config PINMUX_DEBUG
bool "..."
depends on PINMUX

Quoted 10 lines

With regards to parent directory, I did discover there is debugfs_lookup(), so I can get the dentry for "pinctrl" and create new subdirectory inside of it. This is the structure now:

/sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_35_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_34_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_33_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_32_pinmux/state etc..

--
With Best Regards,
Andy Shevchenko

#6 lore raw
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Drew Fustini

On Mon, Dec 14, 2020 at 07:55:12PM +0200, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 9 lines

With regards to parent directory, I did discover there is debugfs_lookup(), so I can get the dentry for "pinctrl" and create new subdirectory inside of it. This is the structure now:

/sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_35_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_34_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_33_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_32_pinmux/state etc..

Missed part to comment.

I was talking about

/sys/kernel/debug/pinctrl/<$PINCTRL>/mux/<$PIN> (maybe folder, maybe node)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 17 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Drew Fustini

On Mon, Dec 14, 2020 at 07:55:12PM +0200, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 9 lines

With regards to parent directory, I did discover there is debugfs_lookup(), so I can get the dentry for "pinctrl" and create new subdirectory inside of it. This is the structure now:

/sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_35_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_34_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_33_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_32_pinmux/state etc..

Quoted 5 lines

Missed part to comment.

I was talking about

/sys/kernel/debug/pinctrl/<$PINCTRL>/mux/<$PIN> (maybe folder, maybe node)

Thanks for the example.

What would the value be "<$PINCTRL>"? The name of the driver?

The "ocp:Px_yy_pinmux" directory name comes from dev_name(dev). Is that the name you were referencing in "<$PIN>"?

thanks,
drew

#8 lore raw
Quoted 20 lines · Drew Fustini
Quoted 19 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Drew Fustini

On Mon, Dec 14, 2020 at 07:55:12PM +0200, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 9 lines

With regards to parent directory, I did discover there is debugfs_lookup(), so I can get the dentry for "pinctrl" and create new subdirectory inside of it. This is the structure now:

/sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_35_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_34_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_33_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_32_pinmux/state etc..

Missed part to comment.

Quoted 7 lines
Quoted 3 lines

I was talking about

/sys/kernel/debug/pinctrl/<$PINCTRL>/mux/<$PIN> (maybe folder, maybe node)

Thanks for the example.

What would the value be "<$PINCTRL>"? The name of the driver?

The name of the device instance. This is already done in the pin control code.

Quoted 2 lines

The "ocp:Px_yy_pinmux" directory name comes from dev_name(dev). Is that the name you were referencing in "<$PIN>"?

No, the <$PIN> is an actual pin on this controller. However, I think we probably don't need this, just supply it as tuple of the parameters to be set: like
echo $PIN $STATE > .../<$PINCTRL>/mux or alike.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw
Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Drew Fustini
Quoted 21 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Drew Fustini

On Mon, Dec 14, 2020 at 07:55:12PM +0200, Andy Shevchenko wrote:

...

Quoted 9 lines
Quoted 9 lines

With regards to parent directory, I did discover there is debugfs_lookup(), so I can get the dentry for "pinctrl" and create new subdirectory inside of it. This is the structure now:

/sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_35_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_34_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_33_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_32_pinmux/state etc..

Missed part to comment.

I was talking about

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

/sys/kernel/debug/pinctrl/<$PINCTRL>/mux/<$PIN> (maybe folder, maybe node)

Thanks for the example.

What would the value be "<$PINCTRL>"? The name of the driver?

The name of the device instance. This is already done in the pin control code.

Ah, so for the BeagleBone, that would be 44e10800.pinmux-pinctrl-single:

/sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/

Quoted 8 lines
Quoted 3 lines

The "ocp:Px_yy_pinmux" directory name comes from dev_name(dev). Is that the name you were referencing in "<$PIN>"?

No, the <$PIN> is an actual pin on this controller. However, I think we probably don't need this, just supply it as tuple of the parameters to be set: like
echo $PIN $STATE > .../<$PINCTRL>/mux or alike.

Do you mean not having a debugfs file for each pin, but instead just using the existing combined file?

/sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pinmux-pins

There is one line in there for each pin in the pinctrl-single instance.

For example:

pin 105 (PIN105): ocp:P2_34_pinmux (GPIO UNCLAIMED) function pinmux_P2_34_default_pin group pinmux_P2_34_default_pin

So maybe one solution to changing pinctrl state could to:

echo "105 gpio_pu" > /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pinmux-pins

I'll make an attempt at implementing that.

Quoted 4 lines
Signature · 3 lines
-- 
With Best Regards,
Andy Shevchenko
#10 lore raw
In reply to Andy Shevchenko
Quoted 38 lines · Andy Shevchenko
Quoted 4 lines · Drew Fustini
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Drew Fustini
Quoted 1 line · Andy Shevchenko

On Fri, Dec 11, 2020 at 1:54 PM Drew Fustini <[email protected]> wrote:

...

Quoted 30 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

But I'm wondering, why it requires this kind of thing and can't be simply always part of the kernel based on configuration option?

Do you mean not having a new CONFIG option for this driver and just have it be enabled by CONFIG_PINCTRL?

No, configuration option stays, but no compatible strings no nothing like that. Just probed always when loaded.

I first started down the route of implementing this inside of pinctrl-single. I found it didn't work because devm_pinctrl_get() would fail. I think was because it was happening too early for pinctrl to be ready.

I do think it seems awkward to have to add this to dts and have the driver get probed for each entry:

        P1_04_pinmux {
                compatible = "pinctrl,state-helper";
                status = "okay";
                pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "gpio_input", "pruout", "pruin";
                pinctrl-0 = <&P1_04_default_pin>;
                pinctrl-1 = <&P1_04_gpio_pin>;
                pinctrl-2 = <&P1_04_gpio_pu_pin>;
                pinctrl-3 = <&P1_04_gpio_pd_pin>;
                pinctrl-4 = <&P1_04_gpio_input_pin>;
                pinctrl-5 = <&P1_04_pruout_pin>;
                pinctrl-6 = <&P1_04_pruin_pin>;
        };
Quoted 6 lines
Quoted 1 line

But I am having a hard time figuring out another way of doing it.

I'm not a DT expert and I have no clue why you need all this. To me it looks over engineered to engage DT for debugging things. OTOH, you may add a property to allow debug mux (but it prevent ACPI enabled platforms to utilize this).

There needs to be some mechanism through which to list the possible valid pinctrl states for each pin on the expansion connectors (P1/P2 for PocketBeagle and P8/P9 for BeagleBones). For these ARM boards, device tree pinctrl bindings are the only way I can see to do this. I am not familiar enough with ACPI to understand if this needs to be extended for boards without device tree.

Quoted 30 lines

...

Quoted 6 lines

Any ideas as to what would trigger the probe() if there was not a match on a compatible like "pinctrl,state-helper"?

Quoted 1 line

Actually not even sure we want to have it as a module.

And have just be a part of one of the existing pinctrl files like core.c?

Separate file, but in conjunction with core.c and pinmux and so on.

...

Quoted 16 lines
Quoted 15 lines
Quoted 4 lines
Quoted 3 lines

Shouldn't it be rather a part of a certain pin control folder:
debug/pinctrl/.../mux/...
?

Quoted 8 lines

Yes, I think that would make sense, but I was struggling to figure out how to do that. pinctrl_init_debugfs() in pinctrl/core.c does create the "pinctrl" directory, but I could not figure out how to use this as the parent dir when calling debugfs_create_dir() in this driver's probe().

I thought there might be a way in debugfs API to use existing directory path as a parent but I couldn't figure anything like that. I would appreciate any advice.

If the option is boolean from the beginning then you just call it from the corresponding pin control instantiation chain.

Quoted 7 lines
Quoted 3 lines

Sorry, I am not sure I understand what you mean here. What does "option" mean in this context? I don't think there is any value that is boolean invovled. The pinctrl states are strings.

config PINMUX_DEBUG
bool "..."
depends on PINMUX

Okay, thanks for califying.

There is already DEBUG_PINCTRL which just adds -DDEBUG compile option. The existing debugfs logic in pinctrl core and drivers is gated by CONFIG_DEBUG_FS.

It seems for this new capability to expose pinctrl state in debugfs that I should use something like:

#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_PINMUX_DEBUG)

Does that seem reasonable?

Quoted 15 lines
Quoted 8 lines

With regards to parent directory, I did discover there is debugfs_lookup(), so I can get the dentry for "pinctrl" and create new subdirectory inside of it. This is the structure now:

Quoted 5 lines

/sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_35_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_34_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_33_pinmux/state /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P2_32_pinmux/state etc..

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

thanks,
drew