The patch below tweaks the broadcom-diag module so as to complement /proc/diag/led with a /proc/diag/button subdirectory which shows the current status of the various buttons.
The same information can already be obtained via `gpioctl' (which requires the `gpio_dev' kernel module), except that gpioctl does not know which GPIO is a button and doesn't know their name (and the broadcom-diag module is needed in any case, so this patch can save space by getting rid of the gpio_dev module and the gpioctl tool). I wrote it so as to have some control over the early boot process (i.e. to enter into a kind of rescue mode if some button is pressed) in my WL-700gE where the real rootfs is loaded from an HDD via a tiny rootfs stored in the 2MB flash. Stefan Index: package/broadcom-diag/src/diag.c =================================================================== --- package/broadcom-diag/src/diag.c (révision 14525) +++ package/broadcom-diag/src/diag.c (copie de travail) @@ -910,9 +910,25 @@ static void register_buttons(struct button_t *b) { - for (; b->name; b++) + buttons = proc_mkdir("button", diag); + if (!buttons) + return; + + for (; b->name; b++) { + struct proc_dir_entry *p; platform.button_mask |= b->gpio; + if (b->gpio & gpiomask) + continue; + + if ((p = create_proc_entry(b->name, S_IRUSR, buttons))) { + b->proc.type = PROC_BUTTON; + b->proc.ptr = b; + p->data = (void *) &b->proc; + p->proc_fops = &diag_proc_fops; + } + } + platform.button_mask &= ~gpiomask; gpio_outen(platform.button_mask, 0); @@ -926,6 +942,9 @@ static void unregister_buttons(struct button_t *b) { + for(; b->name; b++) + remove_proc_entry(b->name, buttons); + gpio_intmask(platform.button_mask, 0); gpio_set_irqenable(0, button_handler); @@ -1179,6 +1198,12 @@ } break; } + case PROC_BUTTON: { + struct button_t * button = (struct button_t *) handler->ptr; + u32 in = (gpio_in() & button->gpio ? 1 : 0); + len = sprintf(page, "%d\n", in); + break; + } case PROC_MODEL: len = sprintf(page, "%s\n", platform.name); break; Index: package/broadcom-diag/src/diag.h =================================================================== --- package/broadcom-diag/src/diag.h (révision 14525) +++ package/broadcom-diag/src/diag.h (copie de travail) @@ -125,7 +125,7 @@ /* proc */ -static struct proc_dir_entry *diag, *leds; +static struct proc_dir_entry *diag, *leds, *buttons; static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos); static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos); _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel