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; } --
| david | Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3 |
| Greg Kroah-Hartman | [PATCH 001/196] Chinese: Add the known_regression URI to the HOWTO |
| David Miller | Re: [RFC/PATCH] Documentation of kernel messages |
| Tony Lindgren | [PATCH 48/90] ARM: OMAP: I2C-1 init fix for 2430 |
git: | |
| Josip Rodin | bnx2_poll panicking kernel |
| Gerrit Renker | [PATCH 03/37] dccp: List management for new feature negotiation |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| David Miller | [GIT]: Networking |
