linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* AM335x: how to mux a pin for libgpiod to use?
@ 2020-06-25 23:22 Drew Fustini
  2020-06-26 10:36 ` Grygorii Strashko
  0 siblings, 1 reply; 3+ messages in thread
From: Drew Fustini @ 2020-06-25 23:22 UTC (permalink / raw)
  To: Tony Lindgren, Haojian Zhuang, Linus Walleij, linux-omap, linux-gpio
  Cc: Jason Kridner, Robert Nelson

I am trying to determine an upstream method to be able to mux an AM3358
pin to gpio and then allow that line to be used from the gpiod userspace
ABI.  A "pinctrl-single,pins" device tree property can easily define a
gpio mux for a given pin.  For example, the P9_14 pin on the BeagleBone
[0] can be set to gpio (mode 7) with this node:

P9_14_gpio_pin: pinmux_P9_14_gpio_pin {
	pinctrl-single,pins = <
	AM33XX_PADCONF(AM335X_PIN_GPMC_A2, PIN_INPUT_PULLDOWN, MUX_MODE7)
	>;
};

GPMC_A2 is gpio1_18 per the AM3358 datasheet [1].  Normally, a node for
a driver, like gpio-keys, would have a gpio property that cause the
driver to claim the gpio line.  But, in that case, the line will not be
available to be used through the gpiod userspace ABI.

If no driver claims the gpio line, then I find that the pin mux in
"pinctrl-single,pins" does not get applied by the pinctrl-single driver.

Thus, I can't figure out how to mux a pin to gpio and then use that gpio
line from userspace.  The natural question is why try access a gpio line
from userspace.  BeagleBone users do want this capability for prototyping
and I believe that is an accepted use case based on what Linus Walleij
wrote in "Using GPIO Lines in Linux" [2].

The kernel used in our BeagleBoard.org Debian images has an out-of-tree
driver [3] named gpio-of-helper will claim the gpio line but a hack [4]
allows the line to still be controlled through the gpiod userspace ABI.
This does not seem to be an acceptable upstream solution, so I am trying
to figure out what an upstream solution would look like.

Maybe one soltion would be to make pinctrl-single set the mux for any
"pinctrl-single,pins" properties regardless of whether a driver
references it or not.  Thus, the pin would be muxed to gpio by
pinctrl-single and libgpiod would be able to use the line as it was not
claimed by any driver.

I would very much appreciate any feedback.

Thanks,
Drew

[0] https://git.io/JfjYH
[1] http://www.ti.com/lit/ds/symlink/am3358.pdf
[2] Documentation/driver-api/gpio/using-gpio.rst
[3] https://git.io/JfjYf
[4] https://git.io/JfjYJ

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

* Re: AM335x: how to mux a pin for libgpiod to use?
  2020-06-25 23:22 AM335x: how to mux a pin for libgpiod to use? Drew Fustini
@ 2020-06-26 10:36 ` Grygorii Strashko
  2020-06-26 15:57   ` Drew Fustini
  0 siblings, 1 reply; 3+ messages in thread
From: Grygorii Strashko @ 2020-06-26 10:36 UTC (permalink / raw)
  To: Drew Fustini, Tony Lindgren, Haojian Zhuang, Linus Walleij,
	linux-omap, linux-gpio
  Cc: Jason Kridner, Robert Nelson



On 26/06/2020 02:22, Drew Fustini wrote:
> I am trying to determine an upstream method to be able to mux an AM3358
> pin to gpio and then allow that line to be used from the gpiod userspace
> ABI.  A "pinctrl-single,pins" device tree property can easily define a
> gpio mux for a given pin.  For example, the P9_14 pin on the BeagleBone
> [0] can be set to gpio (mode 7) with this node:
> 
> P9_14_gpio_pin: pinmux_P9_14_gpio_pin {
> 	pinctrl-single,pins = <
> 	AM33XX_PADCONF(AM335X_PIN_GPMC_A2, PIN_INPUT_PULLDOWN, MUX_MODE7)
> 	>;
> };
> 
> GPMC_A2 is gpio1_18 per the AM3358 datasheet [1].  Normally, a node for
> a driver, like gpio-keys, would have a gpio property that cause the
> driver to claim the gpio line.  But, in that case, the line will not be
> available to be used through the gpiod userspace ABI.
> 
> If no driver claims the gpio line, then I find that the pin mux in
> "pinctrl-single,pins" does not get applied by the pinctrl-single driver.

pinmux node can have default node by itself, like

&am43xx_pinmux {
	pinctrl-names = "default";
	pinctrl-0 = <&cm_t43_led_pins>;

> 
> Thus, I can't figure out how to mux a pin to gpio and then use that gpio
> line from userspace.  The natural question is why try access a gpio line
> from userspace.  BeagleBone users do want this capability for prototyping
> and I believe that is an accepted use case based on what Linus Walleij
> wrote in "Using GPIO Lines in Linux" [2].
> 
> The kernel used in our BeagleBoard.org Debian images has an out-of-tree
> driver [3] named gpio-of-helper will claim the gpio line but a hack [4]
> allows the line to still be controlled through the gpiod userspace ABI.
> This does not seem to be an acceptable upstream solution, so I am trying
> to figure out what an upstream solution would look like.
> 
> Maybe one soltion would be to make pinctrl-single set the mux for any
> "pinctrl-single,pins" properties regardless of whether a driver
> references it or not.  Thus, the pin would be muxed to gpio by
> pinctrl-single and libgpiod would be able to use the line as it was not
> claimed by any driver.
> 
> I would very much appreciate any feedback.
> 
> Thanks,
> Drew
> 
> [0] https://git.io/JfjYH
> [1] http://www.ti.com/lit/ds/symlink/am3358.pdf
> [2] Documentation/driver-api/gpio/using-gpio.rst
> [3] https://git.io/JfjYf
> [4] https://git.io/JfjYJ
> 

-- 
Best regards,
grygorii

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

* Re: AM335x: how to mux a pin for libgpiod to use?
  2020-06-26 10:36 ` Grygorii Strashko
@ 2020-06-26 15:57   ` Drew Fustini
  0 siblings, 0 replies; 3+ messages in thread
From: Drew Fustini @ 2020-06-26 15:57 UTC (permalink / raw)
  To: Grygorii Strashko
  Cc: Tony Lindgren, Haojian Zhuang, Linus Walleij, linux-omap,
	linux-gpio, Jason Kridner, Robert Nelson

On Fri, Jun 26, 2020 at 01:36:50PM +0300, Grygorii Strashko wrote:
> 
> 
> On 26/06/2020 02:22, Drew Fustini wrote:
> > I am trying to determine an upstream method to be able to mux an AM3358
> > pin to gpio and then allow that line to be used from the gpiod userspace
> > ABI.  A "pinctrl-single,pins" device tree property can easily define a
> > gpio mux for a given pin.  For example, the P9_14 pin on the BeagleBone
> > [0] can be set to gpio (mode 7) with this node:
> > 
> > P9_14_gpio_pin: pinmux_P9_14_gpio_pin {
> > 	pinctrl-single,pins = <
> > 	AM33XX_PADCONF(AM335X_PIN_GPMC_A2, PIN_INPUT_PULLDOWN, MUX_MODE7)
> > 	>;
> > };
> > 
> > GPMC_A2 is gpio1_18 per the AM3358 datasheet [1].  Normally, a node for
> > a driver, like gpio-keys, would have a gpio property that cause the
> > driver to claim the gpio line.  But, in that case, the line will not be
> > available to be used through the gpiod userspace ABI.
> > 
> > If no driver claims the gpio line, then I find that the pin mux in
> > "pinctrl-single,pins" does not get applied by the pinctrl-single driver.
> 
> pinmux node can have default node by itself, like
> 
> &am43xx_pinmux {
> 	pinctrl-names = "default";
> 	pinctrl-0 = <&cm_t43_led_pins>;
> 

Thank you, this is what I was missing.

I think this should do what I was looking for:

&am33xx_pinmux {

        pinctrl-names = "default";
        pinctrl-0 = <&libgpiod_pins>;

        libgpiod_pins: pinmux-libgpiod-pins {
                pinctrl-single,pins = <
                        AM33XX_PADCONF(AM335X_PIN_GPMC_A2, PIN_INPUT_PULLDOWN, MUX_MODE7)
                >;
        };


-Drew

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

end of thread, other threads:[~2020-06-26 15:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-25 23:22 AM335x: how to mux a pin for libgpiod to use? Drew Fustini
2020-06-26 10:36 ` Grygorii Strashko
2020-06-26 15:57   ` 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).