From owner-freebsd-embedded@FreeBSD.ORG Sat Nov 8 02:01:10 2014 Return-Path: Delivered-To: embedded@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 707A46B8; Sat, 8 Nov 2014 02:01:10 +0000 (UTC) Received: from mail-vc0-x234.google.com (mail-vc0-x234.google.com [IPv6:2607:f8b0:400c:c03::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1A90DBEF; Sat, 8 Nov 2014 02:01:10 +0000 (UTC) Received: by mail-vc0-f180.google.com with SMTP id hy10so2381025vcb.25 for ; Fri, 07 Nov 2014 18:01:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=cBESePNobtBycFlq/KEHatA5ey5wUqNrwvlun3CBliE=; b=tlzG45NUvLIBzj7SQGcIfJN63i2CDvWbcHsFF1tfwHtxPJKiz56nLKWBp+W6wFUNHw H96/CpelcLLWtfbYf9q054PqiAVzIqQfYxOBk7JSIGFe0j5mClCuLuVBTH7ueRnNGH+c bM7BGq1gKWt3LpQGafR+i9sAVf8a6izsJnQBO/CpofOdjLt4BC4ojXggGBmgKikwrixa o20zdt+KUEjEYHWfIXa9RIR0OdUolMKFHnRoPe+7zvIiBAKLizVinz/B6hSywbue31jn CoyCCeQ+wbGUu+w5XmpaeMjIkE5eMER8mkArZCKKGLldDHC0Un8iMFrHJSuy31rsygi+ 92sg== MIME-Version: 1.0 X-Received: by 10.52.64.180 with SMTP id p20mr7587554vds.8.1415412068963; Fri, 07 Nov 2014 18:01:08 -0800 (PST) Sender: johny.mattsson@gmail.com Received: by 10.220.71.136 with HTTP; Fri, 7 Nov 2014 18:01:08 -0800 (PST) In-Reply-To: <58908C87-6046-4873-87B1-74995EFA72D1@bsdimp.com> References: <58908C87-6046-4873-87B1-74995EFA72D1@bsdimp.com> Date: Sat, 8 Nov 2014 13:01:08 +1100 X-Google-Sender-Auth: FIOtr6M6hryJCCCFesJbmiMzsgI Message-ID: Subject: Re: libgpio From: Johny Mattsson To: Warner Losh Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 Cc: arm@freebsd.org, embedded@freebsd.org, Rui Paulo X-BeenThere: freebsd-embedded@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Dedicated and Embedded Systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Nov 2014 02:01:10 -0000 On 8 November 2014 02:44, Warner Losh wrote:On Nov 6, 2014, at 11:41 PM, Rui Paulo 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.