iwinfo: make 'type' visible in wrapped iwinfo
[openwrt.git] / package / kernel / gpio-button-hotplug / src / gpio-button-hotplug.c
index 412c045..ea6f94b 100644 (file)
@@ -49,6 +49,7 @@ struct bh_priv {
 
 struct bh_event {
        const char              *name;
+       unsigned int            type;
        char                    *action;
        unsigned long           seen;
 
@@ -91,9 +92,7 @@ static struct bh_map button_map[] = {
        BH_MAP(BTN_9,           "BTN_9"),
        BH_MAP(KEY_RESTART,     "reset"),
        BH_MAP(KEY_RFKILL,      "rfkill"),
-#ifdef KEY_WPS_BUTTON
        BH_MAP(KEY_WPS_BUTTON,  "wps"),
-#endif /* KEY_WPS_BUTTON */
 };
 
 /* -------------------------------------------------------------------------*/
@@ -129,6 +128,7 @@ static int bh_event_add_var(struct bh_event *event, int argv,
 
 static int button_hotplug_fill_event(struct bh_event *event)
 {
+       char *s;
        int ret;
 
        ret = bh_event_add_var(event, 0, "HOME=%s", "/");
@@ -140,7 +140,17 @@ static int button_hotplug_fill_event(struct bh_event *event)
        if (ret)
                return ret;
 
-       ret = bh_event_add_var(event, 0, "SUBSYSTEM=%s", "button");
+       switch (event->type) {
+               case EV_SW:
+                       s = "switch";
+                       break;
+               case EV_KEY:
+               default:
+                       s = "button";
+                       break;
+       }
+
+       ret = bh_event_add_var(event, 0, "SUBSYSTEM=%s", s);
        if (ret)
                return ret;
 
@@ -190,8 +200,8 @@ static void button_hotplug_work(struct work_struct *work)
        kfree(event);
 }
 
-static int button_hotplug_create_event(const char *name, unsigned long seen,
-               int pressed)
+static int button_hotplug_create_event(const char *name, unsigned int type,
+               unsigned long seen, int pressed)
 {
        struct bh_event *event;
 
@@ -203,6 +213,7 @@ static int button_hotplug_create_event(const char *name, unsigned long seen,
                return -ENOMEM;
 
        event->name = name;
+       event->type = type;
        event->seen = seen;
        event->action = pressed ? "pressed" : "released";
 
@@ -225,6 +236,7 @@ static int button_get_index(unsigned int code)
 
        return -1;
 }
+
 static void button_hotplug_event(struct gpio_keys_button_data *data,
                           unsigned int type, unsigned int code, int value)
 {
@@ -234,14 +246,14 @@ static void button_hotplug_event(struct gpio_keys_button_data *data,
 
        BH_DBG("event type=%u, code=%u, value=%d\n", type, code, value);
 
-       if (type != EV_KEY)
+       if ((type != EV_KEY) && (type != EV_SW))
                return;
 
        btn = button_get_index(code);
        if (btn < 0)
                return;
 
-       button_hotplug_create_event(button_map[btn].name,
+       button_hotplug_create_event(button_map[btn].name, type,
                        (seen - priv->seen) / HZ, value);
        priv->seen = seen;
 }
@@ -260,17 +272,24 @@ struct gpio_keys_polled_dev {
        struct gpio_keys_button_data data[0];
 };
 
-static void gpio_keys_polled_check_state(struct gpio_keys_button *button,
-                                        struct gpio_keys_button_data *bdata)
+static int gpio_button_get_value(struct gpio_keys_button *button,
+                                struct gpio_keys_button_data *bdata)
 {
-       int state;
+       int val;
 
        if (bdata->can_sleep)
-               state = !!gpio_get_value_cansleep(button->gpio);
+               val = !!gpio_get_value_cansleep(button->gpio);
        else
-               state = !!gpio_get_value(button->gpio);
+               val = !!gpio_get_value(button->gpio);
+
+       return val ^ button->active_low;
+}
+
+static void gpio_keys_polled_check_state(struct gpio_keys_button *button,
+                                        struct gpio_keys_button_data *bdata)
+{
+       int state = gpio_button_get_value(button, bdata);
 
-       state = !!(state ^ button->active_low);
        if (state != bdata->last_state) {
                unsigned int type = button->type ?: EV_KEY;
 
@@ -279,7 +298,9 @@ static void gpio_keys_polled_check_state(struct gpio_keys_button *button,
                        return;
                }
 
-               button_hotplug_event(bdata, type, button->code, state);
+               if (bdata->last_state != -1)
+                       button_hotplug_event(bdata, type, button->code, state);
+
                bdata->last_state = state;
        }
 
@@ -489,7 +510,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
                }
 
                bdata->can_sleep = gpio_cansleep(gpio);
-               bdata->last_state = 0;
+               bdata->last_state = -1;
                bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
                                                pdata->poll_interval);
        }