How do I set user space GPIO polarity (active state) via device tree?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

tl;dr: How do I set the polarity (active state) of a GPIO in the device
tree and use it from user space?

I have an i.MX6 based board where some GPIO lines are controlled from
user space. The access to the GPIOs is done by name using libgpio from
kernel.org. So far this works fine. In the latest revision of the board
the polarity of a GPIO was changed from active-high to active-low.

At first I thought it would be easy to store this information in the
device tree. Sadly, I cannot find the right way how to do it. What
works is to create a gpio-hog and to set the polarity there. The
unwanted side effect there is that the GPIO is hogged and thus not
accessible by user space any more.

How is that done correctly?

Why do I want to do this via the device tree? Because I do not want to
hard code this into the user land. I would like to run the same kernel
and user land on boards with different GPIO polarity.

The following is the relevant except from the device tree; the gpio5
node is created by the mainline arch/arm/boot/dts/imx6qdl.dtsi.

&gpio5 {
	gpio-line-names = "", "", "", "",
                      "", "", "", "",
                      "", "", "", "",
                      "", "", "", "",
                      "", "", "RESET_COMPANION", "",
                      "", "", "", "",
                      "", "", "", "",
                      "", "", "", "";

	reset_companion {
	    gpio-hog;
	    gpios = <18 GPIO_ACTIVE_LOW>;
	    output-high;
    };
};

This is where the user space now sees that the GPIO is active-low -- but
it is hogged by the kernel and thus cannot be used.

# gpioinfo gpiochip4
gpiochip4 - 32 lines:
        line   0:      unnamed    "spi_imx"  output  active-high [kernel]
        line   1:      unnamed       unused   input  active-high
        line   2:      unnamed    "spi_imx"  output  active-high [kernel]
        line   3:      unnamed       unused   input  active-high
[..]
        line  17:      unnamed       unused   input  active-high
        line  18: "RESET_COMPANION" "reset_companion" output active-low [kernel]
        line  19:      unnamed       unused   input  active-high
        line  20:      unnamed   "watchdog"  output  active-high [kernel]
        line  21:      unnamed       unused   input  active-high
[..]
        line  31:      unnamed       unused   input  active-high

Thank you very much in advance for your help.

Regards,
Mark Jonas

Mit freundlichen Grüßen / Best regards

 Mark Jonas

Security Systems, Panel Software Fire (ST-FIR/ENG1) 
Bosch Sicherheitssysteme GmbH | Postfach 11 11 | 85626 Grasbrunn | GERMANY | www.bosch-sicherheitsprodukte.de

Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart HRB 23118 
Aufsichtsratsvorsitzender: Stefan Hartung; Geschäftsführung: Gert van Iperen, Andreas Bartz, Thomas Quante, Bernhard Schuster 




--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux