From 253fb33bb81b0e88bcfa0184ef29206598fbb5d4 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 13 Jan 2016 12:14:33 +0100 Subject: input: gpio-keys: convert to input framework To allow asking for the button states. Signed-off-by: Sascha Hauer --- drivers/input/Kconfig | 1 + drivers/input/gpio_keys.c | 64 +++++++++++++---------------------------------- 2 files changed, 18 insertions(+), 47 deletions(-) (limited to 'drivers/input') diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 7cc98f2d5c..1f89ae3892 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -15,6 +15,7 @@ config KEYBOARD_GPIO bool "GPIO Buttons" depends on GENERIC_GPIO select POLLER + select INPUT help This driver implements support for buttons connected to GPIO pins of various CPUs (and some other chips). diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c index acb9e07fb8..38c0f11535 100644 --- a/drivers/input/gpio_keys.c +++ b/drivers/input/gpio_keys.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include struct gpio_key { int code; @@ -30,12 +30,9 @@ struct gpio_keys { struct gpio_key *buttons; int nbuttons; - /* optional */ - int fifo_size; - - struct kfifo *recv_fifo; struct poller_struct poller; - struct console_device cdev; + struct input_device input; + struct device_d *dev; }; static inline struct gpio_keys * @@ -44,12 +41,6 @@ poller_to_gk_pdata(struct poller_struct *poller) return container_of(poller, struct gpio_keys, poller); } -static inline struct gpio_keys * -cdev_to_gk_pdata(struct console_device *cdev) -{ - return container_of(cdev, struct gpio_keys, cdev); -} - static void gpio_key_poller(struct poller_struct *poller) { struct gpio_keys *gk = poller_to_gk_pdata(poller); @@ -65,33 +56,17 @@ static void gpio_key_poller(struct poller_struct *poller) continue; if (val != gb->previous_state) { + int pressed = val != gb->active_low; + gb->debounce_start = get_time_ns(); - if (val != gb->active_low) { - kfifo_put(gk->recv_fifo, (u_char*)&gb->code, sizeof(int)); - debug("pressed gpio(%d) as %d\n", gb->gpio, gb->code); - } + input_report_key_event(&gk->input, gb->code, pressed); + dev_dbg(gk->dev, "%s gpio(%d) as %d\n", + pressed ? "pressed" : "released", gb->gpio, gb->code); gb->previous_state = val; } } } -static int gpio_keys_tstc(struct console_device *cdev) -{ - struct gpio_keys *gk = cdev_to_gk_pdata(cdev); - - return (kfifo_len(gk->recv_fifo) == 0) ? 0 : 1; -} - -static int gpio_keys_getc(struct console_device *cdev) -{ - int code = 0; - struct gpio_keys *gk = cdev_to_gk_pdata(cdev); - - kfifo_get(gk->recv_fifo, (u_char*)&code, sizeof(int)); - - return keycode_bb_keys[code]; -} - static int gpio_keys_probe_pdata(struct gpio_keys *gk, struct device_d *dev) { struct gpio_keys_platform_data *pdata; @@ -105,9 +80,6 @@ static int gpio_keys_probe_pdata(struct gpio_keys *gk, struct device_d *dev) return -ENODEV; } - if (pdata->fifo_size) - gk->fifo_size = pdata->fifo_size; - gk->buttons = xzalloc(pdata->nbuttons * sizeof(*gk->buttons)); gk->nbuttons = pdata->nbuttons; @@ -163,11 +135,11 @@ static int gpio_keys_probe_dt(struct gpio_keys *gk, struct device_d *dev) static int __init gpio_keys_probe(struct device_d *dev) { int ret, i, gpio; - struct console_device *cdev; struct gpio_keys *gk; gk = xzalloc(sizeof(*gk)); - gk->fifo_size = 50; + + gk->dev = dev; if (dev->device_node) ret = gpio_keys_probe_dt(gk, dev); @@ -177,8 +149,6 @@ static int __init gpio_keys_probe(struct device_d *dev) if (ret) return ret; - gk->recv_fifo = kfifo_alloc(gk->fifo_size); - for (i = 0; i < gk->nbuttons; i++) { gpio = gk->buttons[i].gpio; ret = gpio_request(gpio, "gpio_keys"); @@ -192,15 +162,15 @@ static int __init gpio_keys_probe(struct device_d *dev) gk->poller.func = gpio_key_poller; - cdev = &gk->cdev; - dev->type_data = cdev; - cdev->dev = dev; - cdev->tstc = gpio_keys_tstc; - cdev->getc = gpio_keys_getc; + ret = input_device_register(&gk->input); + if (ret) + return ret; - console_register(&gk->cdev); + ret = poller_register(&gk->poller); + if (ret) + return ret; - return poller_register(&gk->poller); + return 0; } static struct of_device_id key_gpio_of_ids[] = { -- cgit v1.2.3