Date: Sat, 8 Nov 2014 13:01:08 +1100 From: Johny Mattsson <johny.mattsson+fbsd@gmail.com> To: Warner Losh <imp@bsdimp.com> Cc: arm@freebsd.org, embedded@freebsd.org, Rui Paulo <rpaulo@me.com> Subject: Re: libgpio Message-ID: <CAGW5k5Y0XGsSYKxD-pt27a0F6f0=JW9Yw2FvoXMfuqeSeVPGEA@mail.gmail.com> In-Reply-To: <58908C87-6046-4873-87B1-74995EFA72D1@bsdimp.com> References: <B3B50210-8AE9-411A-84B1-AE6C10494149@me.com> <58908C87-6046-4873-87B1-74995EFA72D1@bsdimp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 8 November 2014 02:44, Warner Losh <imp@bsdimp.com> wrote:On Nov 6, 2014, at 11:41 PM, Rui Paulo <rpaulo@me.com> wrote: > Finally a question: What does Linux do here? Is there a standard interface > that we could use to leverage off applications written for Linux? On Linux, userspace GPIO is typically* used through the GPIO SysFS module which provides entries under /sys/class/gpio (or wherever you've mounted your sysfs). Individual pins are transferred to userspace control by writing the pin number to the "export" file, which when successful then adds a virtual directory for that GPIO line, with entries for direction, value, edge and whether it's active-low. Depending on the backing kernel driver and hardware, interrupt support may or may not be available. When available it's enabled by writing "rising", "falling" or "both" (again subject to hw/driver) to the "edge" file, and then select(2)ing on the "value" file return when said edge is triggered. Changing the output on a line is as simple as writing "0" or "1" to the "value" file. Example (drive gpio #32 high): echo 32 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio32/direction # this annoyingly/reassuringly clears this pin - i.e. cat value gives 0 echo 1 > /sys/class/gpio/gpio32/value # some time later, maybe echo 32 > /sys/class/gpio/unexport There is no support for synchronously setting multiple pins through this interface. Even if there was, it would have to be limited to within the one controller/bank. Also, if I remember the i.MX25 correctly, there was no hardware support for doing more than one line at a time anyway due to the register layout. While such a feature would be nice, I wouldn't stress too much about getting it in. At best, support for it will be sporadic depending on hardware. The (limited) documentation for GPIO SysFS on Linux, other than the source itself, can be found here: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt Cheers, /Johny *) Based on personal experience at $work, and the companies we work with, doing various embedded micro and embedded Linux things.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGW5k5Y0XGsSYKxD-pt27a0F6f0=JW9Yw2FvoXMfuqeSeVPGEA>