devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: "linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	Grant Likely <grant.likely@linaro.org>,
	Jonathan Cameron <jic23@kernel.org>,
	Alexandre Courbot <gnurou@gmail.com>
Cc: Johan Hovold <johan@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Lee Campbell <leecam@google.com>,
	Amit Kucheria <amit.kucheria@linaro.org>,
	Markus Pargmann <mpa@pengutronix.de>,
	Michael Welling <mwelling@ieee.org>
Subject: GPIO character device next steps
Date: Fri, 8 Apr 2016 20:32:31 +0200	[thread overview]
Message-ID: <CACRpkdYDjN8R60hhhu4RK9LF2cChOkA98pgvy2TzG9MAT1qGRw@mail.gmail.com> (raw)

As you know we froze the GPIO sysfs ABI in kernel v4.6 and
now we need to complete its replacement with a new mechanism
using the character device.

We can currently:

- Enumerate gpiochips - udev/systemd and its siblings
  will do this automatically from the character devices
  (a patch for mdev will be needed for BusyBox to enumerate
  the chips).

- List its lines with name and consumer strings, that is what
  "lsgpio" from tools/gpio/lsgpio.c does.

- Locate the offset of any desired GPIO line from this string

- Locate the gpiochip in the bus topology using sysfs
  (as with any device)

So I need some help, rants, ACKs etc on whatever I come up
with next, and the next steps are (from the top of my head):

- Naming GPIO lines from DT files
  (So you have something reasonable to look for from userspace)
  What do people think about just using
  gpio-names = "foo", "bar", "baz"; as suggested by Rob Herring?

- Getting a filehandle for one or several GPIOs
  I would prefer to support getting multiple GPIOs from day one
  as we know this is going to be a usecase sooner or later.
  For example it is not uncommon to bitbang a bus from userspace
  and then clock and data lines should

- Give them consumer names from userspace (label who's
  using this GPIO)

- Setting flags on a line from userspace (such as ACTIVE_LOW
  or OPEN_DRAIN) so the hardware can act accordingly.

- Using this filehandle, shake the lines from low to high and vice
  versa from userspace.

- Getting a filehandle to listen to input events (interrupts) from a
  certain GPIO line. Here I am primarily thinking about something
  akin to IIO's event mechanism using poll() which I like a lot.

- Getting the filehandle for events involves selecting trigger type
  for rising/falling edge events. (I don't see how userspace could
  possibly support or want to support level IRQs.)

I am thinking about using filehandles to get a grip on (multiple)
GPIOs and for events because it has the nice property that we
know very well when userspace is using the resource, and we can
free it when the file is closed (which also happens if the application
crashes or get killed, or at shutdown etc).

I'm thinking about staying with a single open() on the chardev
from userspace, but several processes can open handles, then
we need to use an ioctl() to say what we want from this
filehandle: whether a handle on a few GPIO lines or a polled
event.

We want to be mutually exclusive to processes when getting
pins for output, while making it possible for several clients
to read the same line or subscribe to events from the same
line.

Your thoughts?

Yours,
Linus Walleij

             reply	other threads:[~2016-04-08 18:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-08 18:32 Linus Walleij [this message]
2016-04-10 15:16 ` GPIO character device next steps Jonathan Cameron
2016-04-10 15:53   ` Linus Walleij
2016-04-10 17:18     ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACRpkdYDjN8R60hhhu4RK9LF2cChOkA98pgvy2TzG9MAT1qGRw@mail.gmail.com \
    --to=linus.walleij@linaro.org \
    --cc=amit.kucheria@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gnurou@gmail.com \
    --cc=grant.likely@linaro.org \
    --cc=jic23@kernel.org \
    --cc=johan@kernel.org \
    --cc=leecam@google.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=mpa@pengutronix.de \
    --cc=mwelling@ieee.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).