The patch below adds a /proc/diag/button subdirectory, parallel to
/proc/diag/led.  In my case it saves me from having to add kmod-gpio-dev
and gpioctl to my firmware, since I only need them to check whether the
ezsetup button is pressed during boot (to trigger some kind of
failsafe/rescue mode).  Also it has the advantage of exposing
a meaningful name rather than a gpio number.


        Stefan


Index: package/broadcom-diag/src/diag.c
===================================================================
--- package/broadcom-diag/src/diag.c    (révision 14043)
+++ 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 14043)
+++ 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

Reply via email to