Input: gpio_keys - add support for switches (EV_SW)
authorRoman Moravcik <roman.moravcik@gmail.com>
Tue, 1 May 2007 04:39:13 +0000 (00:39 -0400)
committerDmitry Torokhov <dtor@insightbb.com>
Tue, 1 May 2007 04:39:13 +0000 (00:39 -0400)
Signed-off-by: Roman Moravcik <roman.moravcik@gmail.com>
Signed-off-by: Paul Sokolovsky <pmiscml@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
drivers/input/keyboard/gpio_keys.c
include/linux/gpio_keys.h

index 0d2796cdf738d1631539db8e9b29d5887db98735..739212252b09aefb874d56dc431ce72eccdb22f7 100644 (file)
@@ -35,11 +35,14 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
        struct input_dev *input = platform_get_drvdata(pdev);
 
        for (i = 0; i < pdata->nbuttons; i++) {
-               int gpio = pdata->buttons[i].gpio;
+               struct gpio_keys_button *button = &pdata->buttons[i];
+               int gpio = button->gpio;
+
                if (irq == gpio_to_irq(gpio)) {
-                       int state = (gpio_get_value(gpio) ? 1 : 0) ^ (pdata->buttons[i].active_low);
+                       unsigned int type = button->type ?: EV_KEY;
+                       int state = (gpio_get_value(gpio) ? 1 : 0) ^ button->active_low;
 
-                       input_report_key(input, pdata->buttons[i].keycode, state);
+                       input_event(input, type, button->code, !!state);
                        input_sync(input);
                }
        }
@@ -71,19 +74,21 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
        input->id.version = 0x0100;
 
        for (i = 0; i < pdata->nbuttons; i++) {
-               int code = pdata->buttons[i].keycode;
-               int irq = gpio_to_irq(pdata->buttons[i].gpio);
+               struct gpio_keys_button *button = &pdata->buttons[i];
+               int irq = gpio_to_irq(button->gpio);
+               unsigned int type = button->type ?: EV_KEY;
 
                set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);
                error = request_irq(irq, gpio_keys_isr, IRQF_SAMPLE_RANDOM,
-                                    pdata->buttons[i].desc ? pdata->buttons[i].desc : "gpio_keys",
+                                    button->desc ? button->desc : "gpio_keys",
                                     pdev);
                if (error) {
                        printk(KERN_ERR "gpio-keys: unable to claim irq %d; error %d\n",
                                irq, error);
                        goto fail;
                }
-               set_bit(code, input->keybit);
+
+               input_set_capability(input, type, button->code);
        }
 
        error = input_register_device(input);
index 2b217c7b931252b962402442244dc00b212041ea..265d17830a0f7500cdc83e393d8950f616ff3c86 100644 (file)
@@ -3,10 +3,11 @@
 
 struct gpio_keys_button {
        /* Configuration parameters */
-       int keycode;
+       int code;               /* input event code (KEY_*, SW_*) */
        int gpio;
        int active_low;
        char *desc;
+       int type;               /* input event type (EV_KEY, EV_SW) */
 };
 
 struct gpio_keys_platform_data {