public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Green <andy@warmcat.com>
To: linux-kernel@vger.kernel.org
Subject: Generic GPIO on USB / hotpluggable gpiolib device
Date: Fri, 10 Sep 2010 09:51:55 +0100	[thread overview]
Message-ID: <4C89F1AB.3070701@warmcat.com> (raw)

Hi -

I just wrote a small driver that exposes a USB device's IO as generic 
GPIO using a little protocol.  I often needed a simple way to bitbang 
something from my laptop and this is going to be very useful to 
implement it.

It works fine with dynamic GPIO allocation and so on, but I maybe 
realized at the end why nobody did this until now, in gpiolib it says...

/**
  * gpiochip_remove() - unregister a gpio_chip
  * @chip: the chip to unregister
  *
  * A gpio_chip with any GPIOs still requested may not be removed.
  */
int gpiochip_remove(struct gpio_chip *chip)
{
...
	for (id = chip->base; id < chip->base + chip->ngpio; id++) {
		if (test_bit(FLAG_REQUESTED, &gpio_desc[id].flags)) {
			status = -EBUSY;
			break;
		}
	}
...

In short gpiolib doesn't have the concept that the chip can be 
hot(un)plugged randomly, including at times when something has requested 
the GPIO.

I am quite certain that USB generic GPIO would be something very nice 
for end users, to be able to casually plug in even the cheapest USB 
micro and bitbang as much GPIO as you like from userspace in a 
standardized way (including being able to exploit the existing bitbang 
protocol drivers on the exposed GPIO) would be very handy.  The protocol 
is simple and flexible (1 x IN endpoint and 1 x OUT endpoint, only one 
packet per call, device announces number of GPIO it supports).

What'd be the feeling if I enhanced gpiolib a bit along the lines of:

  - changing the chip set() function to be able to return errors, at the 
moment it's void return from that

  - adding a flag marking a chip as "dead", causing all IO via it to 
fail immediately and it to be auto-removed when the last request goes

Does this seem workable?  What to do about say SPI bitbang protocol 
driver instance that sees its generic gpio calls started failing?

-Andy

                 reply	other threads:[~2010-09-10  8:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4C89F1AB.3070701@warmcat.com \
    --to=andy@warmcat.com \
    --cc=linux-kernel@vger.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