summaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-02-11 21:49:38 +0800
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-02-16 18:17:30 +0800
commitef654d161766c13e002f2bf738007ccf44d84749 (patch)
tree7832b5c0be73693de74382f6c896496ba0c665da /drivers/input
parent4b06ebc820aa9a46dfb73c7050b073d8224b4b70 (diff)
downloadbarebox-ef654d161766c13e002f2bf738007ccf44d84749.tar.gz
barebox-ef654d161766c13e002f2bf738007ccf44d84749.tar.xz
add gpio keyboard support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/Kconfig19
-rw-r--r--drivers/input/Makefile1
-rw-r--r--drivers/input/gpio_keys.c115
3 files changed, 135 insertions, 0 deletions
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
new file mode 100644
index 0000000000..b488553680
--- /dev/null
+++ b/drivers/input/Kconfig
@@ -0,0 +1,19 @@
+#
+# Input device configuration
+#
+
+menu "Input device support"
+
+config KEYBOARD_GPIO
+ bool "GPIO Buttons"
+ depends on GENERIC_GPIO
+ help
+ This driver implements support for buttons connected
+ to GPIO pins of various CPUs (and some other chips).
+
+ Say Y here if your device has buttons connected
+ directly to such GPIO pins. Your board-specific
+ setup logic must also provide a platform device,
+ with configuration data saying which GPIOs are used.
+
+endmenu
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
new file mode 100644
index 0000000000..7784d522ae
--- /dev/null
+++ b/drivers/input/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
new file mode 100644
index 0000000000..4d0f6ab2ed
--- /dev/null
+++ b/drivers/input/gpio_keys.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * Under GPLv2
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <init.h>
+#include <clock.h>
+#include <gpio_keys.h>
+#include <poller.h>
+#include <gpio.h>
+
+static inline struct gpio_keys_platform_data *
+poller_to_gk_pdata(struct poller_struct *poller)
+{
+ return container_of(poller, struct gpio_keys_platform_data, poller);
+}
+
+static inline struct gpio_keys_platform_data *
+cdev_to_gk_pdata(struct console_device *cdev)
+{
+ return container_of(cdev, struct gpio_keys_platform_data, cdev);
+}
+
+static void gpio_key_poller(struct poller_struct *poller)
+{
+ struct gpio_keys_platform_data *pdata = poller_to_gk_pdata(poller);
+ struct gpio_keys_button *gb;
+ int i, val;
+
+ for (i = 0; i < pdata->nbuttons; i++) {
+
+ gb = &pdata->buttons[i];
+ val = gpio_get_value(gb->gpio);
+
+ if (val != gb->previous_state && val != gb->active_low) {
+ kfifo_put(pdata->recv_fifo, (u_char*)&gb->code, sizeof(int));
+ debug("pressed gpio(%d) as %d\n", gb->gpio, gb->code);
+ }
+ gb->previous_state = val;
+ }
+}
+
+static int gpio_keys_tstc(struct console_device *cdev)
+{
+ struct gpio_keys_platform_data *pdata = cdev_to_gk_pdata(cdev);
+
+ return (kfifo_len(pdata->recv_fifo) == 0) ? 0 : 1;
+}
+
+static int gpio_keys_getc(struct console_device *cdev)
+{
+ int code = 0;
+ struct gpio_keys_platform_data *pdata = cdev_to_gk_pdata(cdev);
+
+ kfifo_get(pdata->recv_fifo, (u_char*)&code, sizeof(int));
+ return code;
+}
+
+static int __init gpio_keys_probe(struct device_d *dev)
+{
+ int ret, i, gpio;
+ struct gpio_keys_platform_data *pdata;
+ struct console_device *cdev;
+
+ pdata = dev->platform_data;
+
+ if (!pdata) {
+ /* small (so we copy it) but critical! */
+ pr_err("missing platform_data\n");
+ return -ENODEV;
+ }
+
+ if (!pdata->fifo_size)
+ pdata->fifo_size = 50;
+
+ pdata->recv_fifo = kfifo_alloc(pdata->fifo_size);
+
+ for (i = 0; i < pdata->nbuttons; i++) {
+ gpio = pdata->buttons->gpio;
+ ret = gpio_request(gpio, "gpio_keys");
+ if (ret) {
+ pr_err("gpio_keys: (%d) can not be requested\n", gpio);
+ return ret;
+ }
+ gpio_direction_input(gpio);
+ }
+
+ pdata->poller.func = gpio_key_poller;
+
+ cdev = &pdata->cdev;
+ dev->type_data = cdev;
+ cdev->dev = dev;
+ cdev->f_caps = CONSOLE_STDIN;
+ cdev->tstc = gpio_keys_tstc;
+ cdev->getc = gpio_keys_getc;
+
+ console_register(&pdata->cdev);
+
+ return poller_register(&pdata->poller);
+}
+
+static struct driver_d gpio_keys_driver = {
+ .name = "gpio_keys",
+ .probe = gpio_keys_probe,
+};
+
+static int gpio_keys_init(void)
+{
+ register_driver(&gpio_keys_driver);
+ return 0;
+}
+device_initcall(gpio_keys_init);