Skip to contentSkip to conversation

pinctrl: add helper to expose pinctrl state in debugfs

RFC PATCH In review Drew Fustini 4 participants 9 messages Dec 18, 2020 – Jan 21, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 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/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/pinctrl/pinctrl_state/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 Pantelis Antoniou <[email protected]>
Cc Pantelis Antoniou <[email protected]>
Cc Jason Kridner <[email protected]>
Cc Robert Nelson <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Tony Lindgren <[email protected]>
Cc Andy Shevchenko <[email protected]>

---
v2 changes:
- add RFC: comments in places where I would appreciate feedback
- remove [email protected] as it is bouncing
- add alternative email addresses for Pantelis
- update pinctrl_state_read() to use kasprintf() based on Andy's advice
- update pinctrl_state_write() to use memdup_user_nul()
- call debugfs_lookup() to use existing "pinctrl" dir as parent
- create subdir "pinctrl_state" to be parent of per-pin directories
- add pinctrl_state_helper_init() and pinctrl_state_helper_exit() to handle creating and cleaning up debugfs_root ("pinctrl_state")

 drivers/pinctrl/Kconfig                |  10 +
 drivers/pinctrl/Makefile               |   1 +
 drivers/pinctrl/pinctrl-state-helper.c | 241 +++++++++++++++++++++++++
 3 files changed, 252 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 +241 -0

241 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 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. 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].

Quoted 5 lines

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.

No objections here.

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?

Here is the first concern. Why does this require to be a driver with a compatible string?

Quoted 11 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/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
pwm
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.

Two more concerns:
- why is it OF only?
- why has it been separated from pin control per device debug folder?

Quoted 6 lines

[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

--
With Best Regards,
Andy Shevchenko

#2 lore raw
Quoted 16 lines · Andy Shevchenko
Quoted 9 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. 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].

Quoted 5 lines

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.

Quoted 7 lines

No objections here.

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?

Here is the first concern. Why does this require to be a driver with a compatible string?

I have not been able to figure out how to have different active pinctrl states for each header pins (for example P2 header pin 3) unless they are represented as DT nodes with their own compatible for this helper driver such as:

&ocp {
	P2_03_pinmux {
		compatible = "pinctrl,state-helper";
		pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "gpio_input", "pwm";
		pinctrl-0 = <&P2_03_default_pin>;
		pinctrl-1 = <&P2_03_gpio_pin>;
		pinctrl-2 = <&P2_03_gpio_pu_pin>;
		pinctrl-3 = <&P2_03_gpio_pd_pin>;
		pinctrl-4 = <&P2_03_gpio_input_pin>;
		pinctrl-5 = <&P2_03_pwm_pin>;
	};
}

I can assign pinctrl states in the pin controller DT node which has compatible pinctrl-single (line 301 arch/arm/boot/dts/am33xx-l4.dtsi):

&am33xx_pinmux {

        pinctrl-names = "default", "gpio", "pwm";
        pinctrl-0 =   < &P2_03_default_pin &P1_34_default_pin &P2_19_default_pin &P2_24_default_pin
                        &P2_33_default_pin &P2_22_default_pin &P2_18_default_pin &P2_10_default_pin
                        &P2_06_default_pin &P2_04_default_pin &P2_02_default_pin &P2_08_default_pin
                        &P2_17_default_pin >;
        pinctrl-1 =   < &P2_03_gpio_pin &P1_34_gpio_pin &P2_19_gpio_pin &P2_24_gpio_pin
                        &P2_33_gpio_pin &P2_22_gpio_pin &P2_18_gpio_pin &P2_10_gpio_pin
                        &P2_06_gpio_pin &P2_04_gpio_pin &P2_02_gpio_pin &P2_08_gpio_pin
                        &P2_17_gpio_pin >;
        pinctrl-2 =   < &P2_03_pwm &P1_34_pwm &P2_19_pwm &P2_24_pwm
                        &P2_33_pwm &P2_22_pwm &P2_18_pwm &P2_10_pwm
                        &P2_06_pwm &P2_04_pwm &P2_02_pwm &P2_08_pwm
                        &P2_17_pwm >;

}

However, there is no way to later select "gpio" for P2.03 and select "pwm" for P1.34 at the same time. Thus, I can not figure out a way to select independent states per pin unless I make a node for each pin that binds to a helper driver.

It feels like there may be a simpler soluation but I can't see to figure it out. Suggestions welcome!

Quoted 12 lines
Quoted 12 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/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
pwm
Quoted 6 lines
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.

Two more concerns:
- why is it OF only?

I am open to figuring out a more general solution but I am really only familiar with Device Tree. Is there a way to represent the possible pinctrl states in ACPI?

Quoted 1 line

- why has it been separated from pin control per device debug folder?

From the v1 thread, I see what you mean that there could be a combined state file for each pinctrl device where one would echo '<pin> <state-name>' such as 'P2_03 pwm'. I will attempt to implement that.

Quoted 9 lines
Quoted 8 lines

[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

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

Thanks for reviewing,
Drew

#3 lore raw
Quoted 95 lines · Drew Fustini
Quoted 16 lines · Andy Shevchenko
Quoted 9 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. 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].

Quoted 5 lines

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.

Quoted 7 lines

No objections here.

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?

Here is the first concern. Why does this require to be a driver with a compatible string?

I have not been able to figure out how to have different active pinctrl states for each header pins (for example P2 header pin 3) unless they are represented as DT nodes with their own compatible for this helper driver such as:

&ocp {
	P2_03_pinmux {
		compatible = "pinctrl,state-helper";
		pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "gpio_input", "pwm";
		pinctrl-0 = <&P2_03_default_pin>;
		pinctrl-1 = <&P2_03_gpio_pin>;
		pinctrl-2 = <&P2_03_gpio_pu_pin>;
		pinctrl-3 = <&P2_03_gpio_pd_pin>;
		pinctrl-4 = <&P2_03_gpio_input_pin>;
		pinctrl-5 = <&P2_03_pwm_pin>;
	};
}

I can assign pinctrl states in the pin controller DT node which has compatible pinctrl-single (line 301 arch/arm/boot/dts/am33xx-l4.dtsi):

&am33xx_pinmux {

        pinctrl-names = "default", "gpio", "pwm";
        pinctrl-0 =   < &P2_03_default_pin &P1_34_default_pin &P2_19_default_pin &P2_24_default_pin
                        &P2_33_default_pin &P2_22_default_pin &P2_18_default_pin &P2_10_default_pin
                        &P2_06_default_pin &P2_04_default_pin &P2_02_default_pin &P2_08_default_pin
                        &P2_17_default_pin >;
        pinctrl-1 =   < &P2_03_gpio_pin &P1_34_gpio_pin &P2_19_gpio_pin &P2_24_gpio_pin
                        &P2_33_gpio_pin &P2_22_gpio_pin &P2_18_gpio_pin &P2_10_gpio_pin
                        &P2_06_gpio_pin &P2_04_gpio_pin &P2_02_gpio_pin &P2_08_gpio_pin
                        &P2_17_gpio_pin >;
        pinctrl-2 =   < &P2_03_pwm &P1_34_pwm &P2_19_pwm &P2_24_pwm
                        &P2_33_pwm &P2_22_pwm &P2_18_pwm &P2_10_pwm
                        &P2_06_pwm &P2_04_pwm &P2_02_pwm &P2_08_pwm
                        &P2_17_pwm >;

}

However, there is no way to later select "gpio" for P2.03 and select "pwm" for P1.34 at the same time. Thus, I can not figure out a way to select independent states per pin unless I make a node for each pin that binds to a helper driver.

It feels like there may be a simpler soluation but I can't see to figure it out. Suggestions welcome!

Quoted 12 lines
Quoted 12 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/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
default
root@beaglebone:~# echo pwm > /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
root@beaglebone:~# cat /sys/kernel/debug/pinctrl/pinctrl_state/ocp:P9_14_pinmux/state
pwm
Quoted 6 lines
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.

Two more concerns:
- why is it OF only?

I am open to figuring out a more general solution but I am really only familiar with Device Tree. Is there a way to represent the possible pinctrl states in ACPI?

Quoted 5 lines
Quoted 3 lines

- why has it been separated from pin control per device debug folder?

From the v1 thread, I see what you mean that there could be a combined

state file for each pinctrl device where one would echo '<pin> <state-name>' such as 'P2_03 pwm'. I will attempt to implement that.

I have tried creating a single state file:
/sys/kernel/debug/pinctrl/pinctrl_state

where one can write into it:

<device-name> <pinctrl-state-name>

such as:

ocp:P9_14_pinmux gpio

However, I can not figure out a way for this to work.

I create the pinctrl_state file in pinctrl_state_helper_init() and store the dentry in a global variable.

pinctrl_state_helper_probe() still runs for each Px_0y_pinmux device tree entry with compatible "pinctrl,state-helper" but there is no per-device file created.

The problem comes in pinctrl_state_write(). I use this to extract the device_name and state_name:

	ret = sscanf(buf, "%s %s", device_name, state_name);

This does work okay but I don't know what to do with the device_name string, such as "ocp:P9_14_pinmux". Previously, the device was saved in the private info:

        sfile = file->private_data;
        priv = sfile->private;
        p = devm_pinctrl_get(priv->dev); // use device_name instead?
	state = pinctrl_lookup_state(p, state_name);

But I don't know how to look up a device based on its name.

Any suggestions as to how to handle that?

Thanks and happy new year!
Drew

Quoted 16 lines
Quoted 10 lines
Quoted 9 lines

[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

Quoted 3 lines

--
With Best Regards,
Andy Shevchenko

Thanks for reviewing,
Drew

#4 lore raw
In reply to Drew Fustini

Hi Drew,

sorry for belated review. The approach is so uncommon so it had me confused.

Quoted 11 lines · Drew Fustini
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?

Here is the first concern. Why does this require to be a driver with a compatible string?

I have not been able to figure out how to have different active pinctrl states for each header pins (for example P2 header pin 3) unless they are represented as DT nodes with their own compatible for this helper driver such as:

Quoted 12 lines
&ocp {
        P2_03_pinmux {
                compatible = "pinctrl,state-helper";
                pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "gpio_input", "pwm";
                pinctrl-0 = <&P2_03_default_pin>;
                pinctrl-1 = <&P2_03_gpio_pin>;
                pinctrl-2 = <&P2_03_gpio_pu_pin>;
                pinctrl-3 = <&P2_03_gpio_pd_pin>;
                pinctrl-4 = <&P2_03_gpio_input_pin>;
                pinctrl-5 = <&P2_03_pwm_pin>;
        };
}

I do not think the DT people are going to appreciate this pseudo-device.

Can you not just represent them as pin control hogs and have the debugfs code with the other debugfs code in drivers/pinctrl/core.c?

Normal drivers cannot play around with the state assigned to a hog, but debugfs can certainly do that so go ahead and patch the core.

Quoted 21 lines

I can assign pinctrl states in the pin controller DT node which has compatible pinctrl-single (line 301 arch/arm/boot/dts/am33xx-l4.dtsi):

&am33xx_pinmux {

        pinctrl-names = "default", "gpio", "pwm";
        pinctrl-0 =   < &P2_03_default_pin &P1_34_default_pin &P2_19_default_pin &P2_24_default_pin
                        &P2_33_default_pin &P2_22_default_pin &P2_18_default_pin &P2_10_default_pin
                        &P2_06_default_pin &P2_04_default_pin &P2_02_default_pin &P2_08_default_pin
                        &P2_17_default_pin >;
        pinctrl-1 =   < &P2_03_gpio_pin &P1_34_gpio_pin &P2_19_gpio_pin &P2_24_gpio_pin
                        &P2_33_gpio_pin &P2_22_gpio_pin &P2_18_gpio_pin &P2_10_gpio_pin
                        &P2_06_gpio_pin &P2_04_gpio_pin &P2_02_gpio_pin &P2_08_gpio_pin
                        &P2_17_gpio_pin >;
        pinctrl-2 =   < &P2_03_pwm &P1_34_pwm &P2_19_pwm &P2_24_pwm
                        &P2_33_pwm &P2_22_pwm &P2_18_pwm &P2_10_pwm
                        &P2_06_pwm &P2_04_pwm &P2_02_pwm &P2_08_pwm
                        &P2_17_pwm >;

}

Quoted 7 lines

However, there is no way to later select "gpio" for P2.03 and select "pwm" for P1.34 at the same time. Thus, I can not figure out a way to select independent states per pin unless I make a node for each pin that binds to a helper driver.

It feels like there may be a simpler soluation but I can't see to figure it out. Suggestions welcome!

I think maybe there is no solution because you are solving a problem that only pinctrl-single while trying to stay generic? The single driver is special in that it requires all states of pins to be encoded into the device tree, but for debugging that is kind of unfriendly which was mentioned in its inception. For deep debugging it is good to let the core know of all available functions and groups and single does not IIUC.

Yours,
Linus Walleij

#5 lore raw
Quoted 31 lines · Linus Walleij

Hi Drew,

sorry for belated review. The approach is so uncommon so it had me confused.

Quoted 11 lines · Drew Fustini
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?

Here is the first concern. Why does this require to be a driver with a compatible string?

I have not been able to figure out how to have different active pinctrl states for each header pins (for example P2 header pin 3) unless they are represented as DT nodes with their own compatible for this helper driver such as:

Quoted 12 lines
&ocp {
        P2_03_pinmux {
                compatible = "pinctrl,state-helper";
                pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd", "gpio_input", "pwm";
                pinctrl-0 = <&P2_03_default_pin>;
                pinctrl-1 = <&P2_03_gpio_pin>;
                pinctrl-2 = <&P2_03_gpio_pu_pin>;
                pinctrl-3 = <&P2_03_gpio_pd_pin>;
                pinctrl-4 = <&P2_03_gpio_input_pin>;
                pinctrl-5 = <&P2_03_pwm_pin>;
        };
}
Quoted 1 line

I do not think the DT people are going to appreciate this pseudo-device.

Thank you for reviewing and commenting.

It is does seem like creating a platform device for each header pin and binding to this proposed helper driver is not the correct approach.

Quoted 2 lines

Can you not just represent them as pin control hogs and have the debugfs code with the other debugfs code in drivers/pinctrl/core.c?

I tried defining pinctrl states in the am33xx_pinmux DT node (which has compatible "pinctrl-single"). It does work to have default state defined for pins. However, I was not sure how represent having different states active for independent header pins.

Instead of DT binds, maybe I need to use PIN_MAP_MUX_GROUP_HOG_DEFAULT() in pinctrl-single code?

Quoted 4 lines

Normal drivers cannot play around with the state assigned to a hog, but debugfs can certainly do that so go ahead and patch the core.

Is there an existing debugfs file that you think would be appropriate to allow the state of a hog to be changed?

Quoted 37 lines
Quoted 21 lines

I can assign pinctrl states in the pin controller DT node which has compatible pinctrl-single (line 301 arch/arm/boot/dts/am33xx-l4.dtsi):

&am33xx_pinmux {

        pinctrl-names = "default", "gpio", "pwm";
        pinctrl-0 =   < &P2_03_default_pin &P1_34_default_pin &P2_19_default_pin &P2_24_default_pin
                        &P2_33_default_pin &P2_22_default_pin &P2_18_default_pin &P2_10_default_pin
                        &P2_06_default_pin &P2_04_default_pin &P2_02_default_pin &P2_08_default_pin
                        &P2_17_default_pin >;
        pinctrl-1 =   < &P2_03_gpio_pin &P1_34_gpio_pin &P2_19_gpio_pin &P2_24_gpio_pin
                        &P2_33_gpio_pin &P2_22_gpio_pin &P2_18_gpio_pin &P2_10_gpio_pin
                        &P2_06_gpio_pin &P2_04_gpio_pin &P2_02_gpio_pin &P2_08_gpio_pin
                        &P2_17_gpio_pin >;
        pinctrl-2 =   < &P2_03_pwm &P1_34_pwm &P2_19_pwm &P2_24_pwm
                        &P2_33_pwm &P2_22_pwm &P2_18_pwm &P2_10_pwm
                        &P2_06_pwm &P2_04_pwm &P2_02_pwm &P2_08_pwm
                        &P2_17_pwm >;

}

Quoted 7 lines

However, there is no way to later select "gpio" for P2.03 and select "pwm" for P1.34 at the same time. Thus, I can not figure out a way to select independent states per pin unless I make a node for each pin that binds to a helper driver.

It feels like there may be a simpler soluation but I can't see to figure it out. Suggestions welcome!

I think maybe there is no solution because you are solving a problem that only pinctrl-single while trying to stay generic? The single driver is special in that it requires all states of pins to be encoded into the device tree, but for debugging that is kind of unfriendly which was mentioned in its inception. For deep debugging it is good to let the core know of all available functions and groups and single does not IIUC.

Quoted 2 lines

Yours,
Linus Walleij

I discussed my use case and this patch on #armlinux earlier this week and Alexandre Belloni suggested looking at the pinmux-pins debugfs file.

This made me think that a possible solution could be to define a store function for pinmux-pins to handle something like "<pin#> <function#>". I believe the ability to activate a pin function (or pin group) from userspace would satisfy our beagleboard.org use-case.

Does that seem like a reasonable approach?

Thank you!
Drew

#6 lore raw
Quoted 2 lines · Drew Fustini

I discussed my use case and this patch on #armlinux earlier this week and Alexandre Belloni suggested looking at the pinmux-pins debugfs file.

This sounds reasonable.

Quoted 6 lines

This made me think that a possible solution could be to define a store function for pinmux-pins to handle something like "<pin#> <function#>". I believe the ability to activate a pin function (or pin group) from userspace would satisfy our beagleboard.org use-case.

Does that seem like a reasonable approach?

This sounds like a good approach.

Yours,
Linus Walleij

#7 lore raw

Hi,

Quoted 7 lines · Linus Walleij
Quoted 2 lines · Drew Fustini

I discussed my use case and this patch on #armlinux earlier this week and Alexandre Belloni suggested looking at the pinmux-pins debugfs file.

This sounds reasonable.

Quoted 8 lines
Quoted 6 lines

This made me think that a possible solution could be to define a store function for pinmux-pins to handle something like "<pin#> <function#>". I believe the ability to activate a pin function (or pin group) from userspace would satisfy our beagleboard.org use-case.

Does that seem like a reasonable approach?

This sounds like a good approach.

Makes sense to me too.

We may want to make it into a proper sysfs interface eventually to not require debugfs be enabled in .config. But that's another set of patches, certainly makes sense to first enable it for debugfs.

Regards,

Tony

#8 lore raw
Quoted 21 lines · Tony Lindgren

Hi,

Quoted 7 lines · Linus Walleij
Quoted 2 lines · Drew Fustini

I discussed my use case and this patch on #armlinux earlier this week and Alexandre Belloni suggested looking at the pinmux-pins debugfs file.

This sounds reasonable.

Quoted 8 lines
Quoted 6 lines

This made me think that a possible solution could be to define a store function for pinmux-pins to handle something like "<pin#> <function#>". I believe the ability to activate a pin function (or pin group) from userspace would satisfy our beagleboard.org use-case.

Does that seem like a reasonable approach?

This sounds like a good approach.

Makes sense to me too.

Quoted 7 lines

We may want to make it into a proper sysfs interface eventually to not require debugfs be enabled in .config. But that's another set of patches, certainly makes sense to first enable it for debugfs.

Regards,

Tony

I have added a debugfs file "pinmux-set" to pinmux.c. This allows "<function-number> <group-number>" to be written into that file. The function pinmux_set_write() calls ops->set_mux() with fsel and gsel.

I'll post an RFC with the code, but I am wondering if it would better to take the function as a name and then lookup the function number (fsel)?

thanks,
drew