summaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-04-04 14:20:33 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-04-04 14:20:33 +0200
commiteebe92e3ad8b8516108aa1e00092ed542429087c (patch)
treee11c0b606ef032fddb117e3d14ece37e47399019 /drivers/input
parentc4da77611c7b04778eeba2a153447a81fd3a4c49 (diff)
parentc1bea6f4eddfe68c8e46aca63814e9513eb89c9a (diff)
downloadbarebox-eebe92e3ad8b8516108aa1e00092ed542429087c.tar.gz
barebox-eebe92e3ad8b8516108aa1e00092ed542429087c.tar.xz
Merge branch 'for-next/omap'
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/Kconfig7
-rw-r--r--drivers/input/Makefile1
-rw-r--r--drivers/input/gpio_keys.c2
-rw-r--r--drivers/input/twl6030_pwrbtn.c108
4 files changed, 118 insertions, 0 deletions
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index a6f1f47f8d..3d9016b3fa 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -38,4 +38,11 @@ config KEYBOARD_QT1070
Say Y here if you want to use Atmel AT42QT1070 QTouch
Sensor chip as input device.
+config KEYBOARD_TWL6030
+ tristate "TWL6030 power button"
+ depends on MFD_TWL6030
+ select POLLER
+ help
+ Say Y here if you want to use TWL6030 power button as a key.
+
endmenu
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index d042980b15..b9bcc82759 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -1,3 +1,4 @@
obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
+obj-$(CONFIG_KEYBOARD_TWL6030) += twl6030_pwrbtn.o
obj-$(CONFIG_KEYBOARD_IMX_KEYPAD) += imx_keypad.o
obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o
diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
index b02e0ede34..b43911149e 100644
--- a/drivers/input/gpio_keys.c
+++ b/drivers/input/gpio_keys.c
@@ -86,6 +86,8 @@ static int __init gpio_keys_probe(struct device_d *dev)
return ret;
}
gpio_direction_input(gpio);
+ pdata->buttons[i].previous_state =
+ pdata->buttons[i].active_low;
}
pdata->poller.func = gpio_key_poller;
diff --git a/drivers/input/twl6030_pwrbtn.c b/drivers/input/twl6030_pwrbtn.c
new file mode 100644
index 0000000000..ca51dee605
--- /dev/null
+++ b/drivers/input/twl6030_pwrbtn.c
@@ -0,0 +1,108 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <malloc.h>
+#include <poller.h>
+#include <kfifo.h>
+#include <mfd/twl6030.h>
+#include <twl6030_pwrbtn.h>
+
+struct twl6030_pwrbtn_internal_data {
+ int code;
+ u8 previous_state;
+ struct twl6030 *twl6030;
+ struct kfifo *recv_fifo;
+ struct console_device cdev;
+ struct poller_struct poller;
+};
+
+#define PWR_PWRON_IRQ (1 << 0)
+
+static void ic2_key_poller(struct poller_struct *poller)
+{
+ struct twl6030_pwrbtn_internal_data *idata = container_of(
+ poller, struct twl6030_pwrbtn_internal_data, poller);
+ u8 val;
+
+ if (twl6030_reg_read(idata->twl6030, TWL6030_PMCM_HW, &val)) {
+ dev_err(idata->cdev.dev, "reading i2c\n");
+ return;
+ }
+ val = !(val & PWR_PWRON_IRQ);
+ if (val != idata->previous_state && val) {
+ kfifo_put(idata->recv_fifo, (u_char *)&idata->code,
+ sizeof(int));
+ dev_dbg(idata->cdev.dev, "pressed power button as %d\n",
+ idata->code);
+ }
+ idata->previous_state = val;
+}
+
+static int twl6030_pwrbtn_tstc(struct console_device *cdev)
+{
+ struct twl6030_pwrbtn_internal_data *idata = container_of(
+ cdev, struct twl6030_pwrbtn_internal_data, cdev);
+
+ return kfifo_len(idata->recv_fifo) ? 1 : 0;
+}
+
+static int twl6030_pwrbtn_getc(struct console_device *cdev)
+{
+ int code = 0;
+ struct twl6030_pwrbtn_internal_data *idata = container_of(
+ cdev, struct twl6030_pwrbtn_internal_data, cdev);
+
+ kfifo_get(idata->recv_fifo, (u_char *)&code, sizeof(int));
+ return code;
+}
+
+static int __init twl6030_pwrbtn_probe(struct device_d *dev)
+{
+ struct twl6030_pwrbtn_internal_data *idata;
+ struct twl6030_pwrbtn_platform_data *pdata;
+
+ pdata = dev->platform_data;
+ if (!pdata) {
+ dev_err(dev, "missing platform_data\n");
+ return -ENODEV;
+ }
+
+ idata = xzalloc(sizeof(struct twl6030_pwrbtn_internal_data));
+
+ idata->recv_fifo = kfifo_alloc(sizeof(int));
+ if (!idata->recv_fifo) {
+ dev_err(dev, "out of memory allocating kfifo\n");
+ free(idata);
+ return -ENOMEM;
+ }
+
+ idata->code = pdata->code;
+ idata->twl6030 = twl6030_get();
+ idata->poller.func = ic2_key_poller;
+
+ dev->type_data = &idata->cdev;
+ idata->cdev.dev = dev;
+ idata->cdev.f_caps = CONSOLE_STDIN;
+ idata->cdev.tstc = twl6030_pwrbtn_tstc;
+ idata->cdev.getc = twl6030_pwrbtn_getc;
+ console_register(&idata->cdev);
+
+ return poller_register(&idata->poller);
+}
+
+static struct driver_d twl6030_pwrbtn_driver = {
+ .name = "twl6030_pwrbtn",
+ .probe = twl6030_pwrbtn_probe,
+};
+device_platform_driver(twl6030_pwrbtn_driver);