Re: [patch/rfc 2.6.25-git] gpio: sysfs interface

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Trent Piepho
Date: Tuesday, April 29, 2008 - 11:15 am

On Tue, 29 Apr 2008, Ben Nizette wrote:

Well, is it really that much?  There are 579 files under /sys/class/tty.  But
suppose it is too much (why isn't tty too much then?), then we can do 3.


The back end doesn't seem that big to me.  Here's code for it.  If anything,
the parsing code is simpler than what David has.  It's certainly not huge. 
David's code for parsing the control file plus code for generating a mapping
range file would certainly be larger.


/* Format:  -?(chiplabel:)?number
  * The optional leading - unexports the gpio, without it the gpio is exported.
  * The optional chip label followed by a : gives you the Nth gpio of that
  * chip.  With no label you get gpio "number".
  */

static ssize_t control_store(struct class *class, const char *buf, size_t len)
{
 	const char *numstr;
 	unsigned long num;
 	int mode = 0;

 	if (buf[0] == '-') { /* un-export? */
 		mode = 1;
 		buf++;
 	}

 	numstr = strrchr(buf, ':');

 	/* Get GPIO number */
 	if (strict_strtoul(numstr ? numstr + 1 : buf, 0, &num))
 		return -EINVAL;

 	/* Match chip label, if one was specified */
 	if (numstr) {
 		/* No + 1 in len to not include the ':' at the end */
 		int i, len = numstr - buf;
 		const struct gpio_chip *chip = NULL;

 		for (i = 0; gpio_is_valid(i); i++) {
 			if (chip == gpio_desc[i].chip)
 				continue;
 			chip = gpio_desc[i].chip;
 			if (!chip)
 				continue;

 			if (!strncmp(buf, chip->label, len) &&
 			    chip->label[len] == '\0')
 				goto found_chip;
 		}
 		return -EINVAL;
found_chip:
 		if (num >= chip->ngpio)
 			return -EINVAL;
 		num += chip->base;
 	}

 	if (mode) {
 		/* Unexport */
 		if (!gpio_is_valid(num))
 			return -EINVAL;
 		if (!test_and_clear_bit(FLAG_SYSFS, &gpio_desc[num].flags))
 			return -EINVAL;

 		gpio_free(num);
 	} else {
 		/* Export */
 		int status = gpio_request(num, "sysfs");

 		if (status < 0)
 			return status;

 		status = gpio_export(num);
 		if (status < 0) {
 			gpio_free(num);
 			return status;
 		}

 		set_bit(FLAG_SYSFS, &gpio_desc[num].flags);
 	}

 	return len;
}
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Mon Apr 28, 12:39 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Andrew Morton, (Mon Apr 28, 1:46 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Mon Apr 28, 4:01 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Trent Piepho, (Mon Apr 28, 4:09 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Mon Apr 28, 4:28 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Mon Apr 28, 5:44 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Mon Apr 28, 5:45 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Mon Apr 28, 5:47 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Mon Apr 28, 6:58 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Andrew Morton, (Mon Apr 28, 7:54 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Greg KH, (Mon Apr 28, 8:42 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Mon Apr 28, 8:44 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Mon Apr 28, 9:47 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Trent Piepho, (Mon Apr 28, 10:48 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Trent Piepho, (Mon Apr 28, 11:17 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Tue Apr 29, 5:35 am)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Trent Piepho, (Tue Apr 29, 11:15 am)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Tue Apr 29, 11:45 am)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Andrew Morton, (Tue Apr 29, 12:09 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Tue Apr 29, 2:28 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Tue Apr 29, 2:55 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Tue Apr 29, 2:56 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Tue Apr 29, 3:39 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Tue Apr 29, 4:29 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Trent Piepho, (Tue Apr 29, 5:49 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Tue Apr 29, 6:04 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Tue Apr 29, 7:08 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Trent Piepho, (Tue Apr 29, 8:13 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Wed Apr 30, 3:33 am)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Wed Apr 30, 10:42 am)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Wed Apr 30, 10:49 am)
[patch/rfc 2.6.25-git v2] gpio: sysfs interface, David Brownell, (Wed Apr 30, 2:34 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, Trent Piepho, (Wed Apr 30, 3:47 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, Ben Nizette, (Wed Apr 30, 4:14 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, Ben Nizette, (Wed Apr 30, 4:28 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, David Brownell, (Wed Apr 30, 7:08 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, David Brownell, (Wed Apr 30, 7:12 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, Trent Piepho, (Wed Apr 30, 8:41 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, David Brownell, (Wed Apr 30, 9:35 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, Trent Piepho, (Thu May 1, 2:16 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, David Brownell, (Thu May 1, 2:40 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Pavel Machek, (Fri May 2, 1:36 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, David Brownell, (Fri May 2, 7:58 pm)
Re: [patch/rfc 2.6.25-git v2] gpio: sysfs interface, David Brownell, (Fri May 2, 8:05 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Sat May 17, 3:14 pm)
[patch 2.6.26-rc2-git] gpio: sysfs interface, David Brownell, (Sat May 17, 5:36 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Ben Nizette, (Sat May 17, 9:55 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Pavel Machek, (Mon May 19, 3:39 pm)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, David Brownell, (Mon May 19, 6:26 pm)
Re: [patch 2.6.26-rc2-git] gpio: sysfs interface, Andrew Morton, (Tue May 20, 12:17 am)
Re: [patch/rfc 2.6.25-git] gpio: sysfs interface, Pavel Machek, (Tue May 20, 1:02 am)