summaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-26 12:59:53 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-26 12:59:53 -0700
commit945c40c6b007eb4b07374a38ea37b2a34da306b1 (patch)
tree09d36ed7d59cd7d63162de84671761366939450b /drivers/input/keyboard
parent0082c16e3a6d87c7b156ccf21f5e6c448b102809 (diff)
parent314820c9e892d8f41ba4db300ec96770d9c8294b (diff)
downloadop-kernel-dev-945c40c6b007eb4b07374a38ea37b2a34da306b1.zip
op-kernel-dev-945c40c6b007eb4b07374a38ea37b2a34da306b1.tar.gz
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
Pull input layer updates from Dmitry Torokhov: "First set of updates for the input subsystem. You will get a new touchscreen driver (Melfas mms114), a new keypad driver for LPC32xx SoC, large update to Atmel mXT touchscreen driver, a lot of drivers acquired device tree support and a slew of other fixes." * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (57 commits) Input: add MELFAS mms114 touchscreen driver Input: add support for key scan interface of the LPC32xx SoC Input: omap4-keypad - add device tree support Input: hanwang - add support for Art Master II tablet Input: spear_keyboard - reconfigure operating frequency on suspend Input: spear_keyboard - fix clock handling during suspend/resume Input: ff-memless - fix a couple min_t() casts Input: synaptics - print firmware ID and board number at init Input: spear_keyboard - generalize keyboard frequency configuration Input: spear_keyboard - rename bit definitions to reflect register Input: spear_keyboard - use correct io accessors Input: spear-keyboard - fix disable device_init_wakeup in remove Input: wacom_i2c - fix compiler warning Input: imx_keypad - check error returned by clk_prepare_enable() Input: imx_keypad - adapt the new kpp clock name Input: imx_keypad - use clk_prepare_enable/clk_disable_unprepare() Input: ad7879 - add option to correct xy axis Input: synaptics_usb - Remove TrackPoint name trailing whitespace Revert "Input: atmel_mxt_ts - warn if sysfs could not be created" Input: MT - Include win8 support ...
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/gpio_keys.c1
-rw-r--r--drivers/input/keyboard/imx_keypad.c25
-rw-r--r--drivers/input/keyboard/lpc32xx-keys.c394
-rw-r--r--drivers/input/keyboard/nomadik-ske-keypad.c76
-rw-r--r--drivers/input/keyboard/omap4-keypad.c127
-rw-r--r--drivers/input/keyboard/spear-keyboard.c137
8 files changed, 649 insertions, 122 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index c0e11ecc..c50fa75 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -332,6 +332,16 @@ config KEYBOARD_LOCOMO
To compile this driver as a module, choose M here: the
module will be called locomokbd.
+config KEYBOARD_LPC32XX
+ tristate "LPC32XX matrix key scanner support"
+ depends on ARCH_LPC32XX && OF
+ help
+ Say Y here if you want to use NXP LPC32XX SoC key scanner interface,
+ connected to a key matrix.
+
+ To compile this driver as a module, choose M here: the
+ module will be called lpc32xx-keys.
+
config KEYBOARD_MAPLE
tristate "Maple bus keyboard"
depends on SH_DREAMCAST && MAPLE
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index b03b024..44e7600 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o
obj-$(CONFIG_KEYBOARD_LM8323) += lm8323.o
obj-$(CONFIG_KEYBOARD_LM8333) += lm8333.o
obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o
+obj-$(CONFIG_KEYBOARD_LPC32XX) += lpc32xx-keys.o
obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o
obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 62bfce4..cbb1add 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -559,7 +559,6 @@ static int gpio_keys_get_devtree_pdata(struct device *dev,
pdata->rep = !!of_get_property(node, "autorepeat", NULL);
/* First count the subnodes */
- pdata->nbuttons = 0;
pp = NULL;
while ((pp = of_get_next_child(node, pp)))
pdata->nbuttons++;
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index 6ee7421..ff4c0a8 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -378,20 +378,24 @@ static void imx_keypad_close(struct input_dev *dev)
imx_keypad_inhibit(keypad);
/* Disable clock unit */
- clk_disable(keypad->clk);
+ clk_disable_unprepare(keypad->clk);
}
static int imx_keypad_open(struct input_dev *dev)
{
struct imx_keypad *keypad = input_get_drvdata(dev);
+ int error;
dev_dbg(&dev->dev, ">%s\n", __func__);
+ /* Enable the kpp clock */
+ error = clk_prepare_enable(keypad->clk);
+ if (error)
+ return error;
+
/* We became active from now */
keypad->enabled = true;
- /* Enable the kpp clock */
- clk_enable(keypad->clk);
imx_keypad_config(keypad);
/* Sanity control, not all the rows must be actived now. */
@@ -467,7 +471,7 @@ static int __devinit imx_keypad_probe(struct platform_device *pdev)
goto failed_free_priv;
}
- keypad->clk = clk_get(&pdev->dev, "kpp");
+ keypad->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(keypad->clk)) {
dev_err(&pdev->dev, "failed to get keypad clock\n");
error = PTR_ERR(keypad->clk);
@@ -581,7 +585,7 @@ static int imx_kbd_suspend(struct device *dev)
mutex_lock(&input_dev->mutex);
if (input_dev->users)
- clk_disable(kbd->clk);
+ clk_disable_unprepare(kbd->clk);
mutex_unlock(&input_dev->mutex);
@@ -596,18 +600,23 @@ static int imx_kbd_resume(struct device *dev)
struct platform_device *pdev = to_platform_device(dev);
struct imx_keypad *kbd = platform_get_drvdata(pdev);
struct input_dev *input_dev = kbd->input_dev;
+ int ret = 0;
if (device_may_wakeup(&pdev->dev))
disable_irq_wake(kbd->irq);
mutex_lock(&input_dev->mutex);
- if (input_dev->users)
- clk_enable(kbd->clk);
+ if (input_dev->users) {
+ ret = clk_prepare_enable(kbd->clk);
+ if (ret)
+ goto err_clk;
+ }
+err_clk:
mutex_unlock(&input_dev->mutex);
- return 0;
+ return ret;
}
#endif
diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c
new file mode 100644
index 0000000..dd786c8
--- /dev/null
+++ b/drivers/input/keyboard/lpc32xx-keys.c
@@ -0,0 +1,394 @@
+/*
+ * NXP LPC32xx SoC Key Scan Interface
+ *
+ * Authors:
+ * Kevin Wells <kevin.wells@nxp.com>
+ * Roland Stigge <stigge@antcom.de>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ * Copyright (C) 2012 Roland Stigge
+ *
+ * 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.
+ *
+ *
+ * This controller supports square key matrices from 1x1 up to 8x8
+ */
+
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/slab.h>
+#include <linux/irq.h>
+#include <linux/pm.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/input/matrix_keypad.h>
+
+#define DRV_NAME "lpc32xx_keys"
+
+/*
+ * Key scanner register offsets
+ */
+#define LPC32XX_KS_DEB(x) ((x) + 0x00)
+#define LPC32XX_KS_STATE_COND(x) ((x) + 0x04)
+#define LPC32XX_KS_IRQ(x) ((x) + 0x08)
+#define LPC32XX_KS_SCAN_CTL(x) ((x) + 0x0C)
+#define LPC32XX_KS_FAST_TST(x) ((x) + 0x10)
+#define LPC32XX_KS_MATRIX_DIM(x) ((x) + 0x14) /* 1..8 */
+#define LPC32XX_KS_DATA(x, y) ((x) + 0x40 + ((y) << 2))
+
+#define LPC32XX_KSCAN_DEB_NUM_DEB_PASS(n) ((n) & 0xFF)
+
+#define LPC32XX_KSCAN_SCOND_IN_IDLE 0x0
+#define LPC32XX_KSCAN_SCOND_IN_SCANONCE 0x1
+#define LPC32XX_KSCAN_SCOND_IN_IRQGEN 0x2
+#define LPC32XX_KSCAN_SCOND_IN_SCAN_MATRIX 0x3
+
+#define LPC32XX_KSCAN_IRQ_PENDING_CLR 0x1
+
+#define LPC32XX_KSCAN_SCTRL_SCAN_DELAY(n) ((n) & 0xFF)
+
+#define LPC32XX_KSCAN_FTST_FORCESCANONCE 0x1
+#define LPC32XX_KSCAN_FTST_USE32K_CLK 0x2
+
+#define LPC32XX_KSCAN_MSEL_SELECT(n) ((n) & 0xF)
+
+struct lpc32xx_kscan_drv {
+ struct input_dev *input;
+ struct clk *clk;
+ struct resource *iores;
+ void __iomem *kscan_base;
+ unsigned int irq;
+
+ u32 matrix_sz; /* Size of matrix in XxY, ie. 3 = 3x3 */
+ u32 deb_clks; /* Debounce clocks (based on 32KHz clock) */
+ u32 scan_delay; /* Scan delay (based on 32KHz clock) */
+
+ unsigned short *keymap; /* Pointer to key map for the scan matrix */
+ unsigned int row_shift;
+
+ u8 lastkeystates[8];
+};
+
+static void lpc32xx_mod_states(struct lpc32xx_kscan_drv *kscandat, int col)
+{
+ struct input_dev *input = kscandat->input;
+ unsigned row, changed, scancode, keycode;
+ u8 key;
+
+ key = readl(LPC32XX_KS_DATA(kscandat->kscan_base, col));
+ changed = key ^ kscandat->lastkeystates[col];
+ kscandat->lastkeystates[col] = key;
+
+ for (row = 0; changed; row++, changed >>= 1) {
+ if (changed & 1) {
+ /* Key state changed, signal an event */
+ scancode = MATRIX_SCAN_CODE(row, col,
+ kscandat->row_shift);
+ keycode = kscandat->keymap[scancode];
+ input_event(input, EV_MSC, MSC_SCAN, scancode);
+ input_report_key(input, keycode, key & (1 << row));
+ }
+ }
+}
+
+static irqreturn_t lpc32xx_kscan_irq(int irq, void *dev_id)
+{
+ struct lpc32xx_kscan_drv *kscandat = dev_id;
+ int i;
+
+ for (i = 0; i < kscandat->matrix_sz; i++)
+ lpc32xx_mod_states(kscandat, i);
+
+ writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
+
+ input_sync(kscandat->input);
+
+ return IRQ_HANDLED;
+}
+
+static int lpc32xx_kscan_open(struct input_dev *dev)
+{
+ struct lpc32xx_kscan_drv *kscandat = input_get_drvdata(dev);
+ int error;
+
+ error = clk_prepare_enable(kscandat->clk);
+ if (error)
+ return error;
+
+ writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
+
+ return 0;
+}
+
+static void lpc32xx_kscan_close(struct input_dev *dev)
+{
+ struct lpc32xx_kscan_drv *kscandat = input_get_drvdata(dev);
+
+ writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
+ clk_disable_unprepare(kscandat->clk);
+}
+
+static int __devinit lpc32xx_parse_dt(struct device *dev,
+ struct lpc32xx_kscan_drv *kscandat)
+{
+ struct device_node *np = dev->of_node;
+ u32 rows = 0, columns = 0;
+
+ of_property_read_u32(np, "keypad,num-rows", &rows);
+ of_property_read_u32(np, "keypad,num-columns", &columns);
+ if (!rows || rows != columns) {
+ dev_err(dev,
+ "rows and columns must be specified and be equal!\n");
+ return -EINVAL;
+ }
+
+ kscandat->matrix_sz = rows;
+ kscandat->row_shift = get_count_order(columns);
+
+ of_property_read_u32(np, "nxp,debounce-delay-ms", &kscandat->deb_clks);
+ of_property_read_u32(np, "nxp,scan-delay-ms", &kscandat->scan_delay);
+ if (!kscandat->deb_clks || !kscandat->scan_delay) {
+ dev_err(dev, "debounce or scan delay not specified\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int __devinit lpc32xx_kscan_probe(struct platform_device *pdev)
+{
+ struct lpc32xx_kscan_drv *kscandat;
+ struct input_dev *input;
+ struct resource *res;
+ size_t keymap_size;
+ int error;
+ int irq;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(&pdev->dev, "failed to get platform I/O memory\n");
+ return -EINVAL;
+ }
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0 || irq >= NR_IRQS) {
+ dev_err(&pdev->dev, "failed to get platform irq\n");
+ return -EINVAL;
+ }
+
+ kscandat = kzalloc(sizeof(struct lpc32xx_kscan_drv), GFP_KERNEL);
+ if (!kscandat) {
+ dev_err(&pdev->dev, "failed to allocate memory\n");
+ return -ENOMEM;
+ }
+
+ error = lpc32xx_parse_dt(&pdev->dev, kscandat);
+ if (error) {
+ dev_err(&pdev->dev, "failed to parse device tree\n");
+ goto err_free_mem;
+ }
+
+ keymap_size = sizeof(kscandat->keymap[0]) *
+ (kscandat->matrix_sz << kscandat->row_shift);
+ kscandat->keymap = kzalloc(keymap_size, GFP_KERNEL);
+ if (!kscandat->keymap) {
+ dev_err(&pdev->dev, "could not allocate memory for keymap\n");
+ error = -ENOMEM;
+ goto err_free_mem;
+ }
+
+ kscandat->input = input = input_allocate_device();
+ if (!input) {
+ dev_err(&pdev->dev, "failed to allocate input device\n");
+ error = -ENOMEM;
+ goto err_free_keymap;
+ }
+
+ /* Setup key input */
+ input->name = pdev->name;
+ input->phys = "lpc32xx/input0";
+ input->id.vendor = 0x0001;
+ input->id.product = 0x0001;
+ input->id.version = 0x0100;
+ input->open = lpc32xx_kscan_open;
+ input->close = lpc32xx_kscan_close;
+ input->dev.parent = &pdev->dev;
+
+ input_set_capability(input, EV_MSC, MSC_SCAN);
+
+ error = matrix_keypad_build_keymap(NULL, NULL,
+ kscandat->matrix_sz,
+ kscandat->matrix_sz,
+ kscandat->keymap, kscandat->input);
+ if (error) {
+ dev_err(&pdev->dev, "failed to build keymap\n");
+ goto err_free_input;
+ }
+
+ input_set_drvdata(kscandat->input, kscandat);
+
+ kscandat->iores = request_mem_region(res->start, resource_size(res),
+ pdev->name);
+ if (!kscandat->iores) {
+ dev_err(&pdev->dev, "failed to request I/O memory\n");
+ error = -EBUSY;
+ goto err_free_input;
+ }
+
+ kscandat->kscan_base = ioremap(kscandat->iores->start,
+ resource_size(kscandat->iores));
+ if (!kscandat->kscan_base) {
+ dev_err(&pdev->dev, "failed to remap I/O memory\n");
+ error = -EBUSY;
+ goto err_release_memregion;
+ }
+
+ /* Get the key scanner clock */
+ kscandat->clk = clk_get(&pdev->dev, NULL);
+ if (IS_ERR(kscandat->clk)) {
+ dev_err(&pdev->dev, "failed to get clock\n");
+ error = PTR_ERR(kscandat->clk);
+ goto err_unmap;
+ }
+
+ /* Configure the key scanner */
+ error = clk_prepare_enable(kscandat->clk);
+ if (error)
+ goto err_clk_put;
+
+ writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base));
+ writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base));
+ writel(LPC32XX_KSCAN_FTST_USE32K_CLK,
+ LPC32XX_KS_FAST_TST(kscandat->kscan_base));
+ writel(kscandat->matrix_sz,
+ LPC32XX_KS_MATRIX_DIM(kscandat->kscan_base));
+ writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
+ clk_disable_unprepare(kscandat->clk);
+
+ error = request_irq(irq, lpc32xx_kscan_irq, 0, pdev->name, kscandat);
+ if (error) {
+ dev_err(&pdev->dev, "failed to request irq\n");
+ goto err_clk_put;
+ }
+
+ error = input_register_device(kscandat->input);
+ if (error) {
+ dev_err(&pdev->dev, "failed to register input device\n");
+ goto err_free_irq;
+ }
+
+ platform_set_drvdata(pdev, kscandat);
+ return 0;
+
+err_free_irq:
+ free_irq(irq, kscandat);
+err_clk_put:
+ clk_put(kscandat->clk);
+err_unmap:
+ iounmap(kscandat->kscan_base);
+err_release_memregion:
+ release_mem_region(kscandat->iores->start,
+ resource_size(kscandat->iores));
+err_free_input:
+ input_free_device(kscandat->input);
+err_free_keymap:
+ kfree(kscandat->keymap);
+err_free_mem:
+ kfree(kscandat);
+
+ return error;
+}
+
+static int __devexit lpc32xx_kscan_remove(struct platform_device *pdev)
+{
+ struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
+
+ free_irq(platform_get_irq(pdev, 0), kscandat);
+ clk_put(kscandat->clk);
+ iounmap(kscandat->kscan_base);
+ release_mem_region(kscandat->iores->start,
+ resource_size(kscandat->iores));
+ input_unregister_device(kscandat->input);
+ kfree(kscandat->keymap);
+ kfree(kscandat);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int lpc32xx_kscan_suspend(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
+ struct input_dev *input = kscandat->input;
+
+ mutex_lock(&input->mutex);
+
+ if (input->users) {
+ /* Clear IRQ and disable clock */
+ writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
+ clk_disable_unprepare(kscandat->clk);
+ }
+
+ mutex_unlock(&input->mutex);
+ return 0;
+}
+
+static int lpc32xx_kscan_resume(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev);
+ struct input_dev *input = kscandat->input;
+ int retval = 0;
+
+ mutex_lock(&input->mutex);
+
+ if (input->users) {
+ /* Enable clock and clear IRQ */
+ retval = clk_prepare_enable(kscandat->clk);
+ if (retval == 0)
+ writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base));
+ }
+
+ mutex_unlock(&input->mutex);
+ return retval;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(lpc32xx_kscan_pm_ops, lpc32xx_kscan_suspend,
+ lpc32xx_kscan_resume);
+
+static const struct of_device_id lpc32xx_kscan_match[] = {
+ { .compatible = "nxp,lpc3220-key" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, lpc32xx_kscan_match);
+
+static struct platform_driver lpc32xx_kscan_driver = {
+ .probe = lpc32xx_kscan_probe,
+ .remove = __devexit_p(lpc32xx_kscan_remove),
+ .driver = {
+ .name = DRV_NAME,
+ .owner = THIS_MODULE,
+ .pm = &lpc32xx_kscan_pm_ops,
+ .of_match_table = of_match_ptr(lpc32xx_kscan_match),
+ }
+};
+
+module_platform_driver(lpc32xx_kscan_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>");
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("Key scanner driver for LPC32XX devices");
diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c
index 4ea4341..a880e74 100644
--- a/drivers/input/keyboard/nomadik-ske-keypad.c
+++ b/drivers/input/keyboard/nomadik-ske-keypad.c
@@ -49,6 +49,7 @@
#define SKE_ASR3 0x2C
#define SKE_NUM_ASRX_REGISTERS (4)
+#define KEY_PRESSED_DELAY 10
/**
* struct ske_keypad - data structure used by keypad driver
@@ -92,7 +93,7 @@ static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr,
static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
{
u32 value;
- int timeout = 50;
+ int timeout = keypad->board->debounce_ms;
/* check SKE_RIS to be 0 */
while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--)
@@ -135,12 +136,37 @@ static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
return 0;
}
-static void ske_keypad_read_data(struct ske_keypad *keypad)
+static void ske_keypad_report(struct ske_keypad *keypad, u8 status, int col)
{
+ int row = 0, code, pos;
struct input_dev *input = keypad->input;
- u16 status;
- int col = 0, row = 0, code;
- int ske_asr, ske_ris, key_pressed, i;
+ u32 ske_ris;
+ int key_pressed;
+ int num_of_rows;
+
+ /* find out the row */
+ num_of_rows = hweight8(status);
+ do {
+ pos = __ffs(status);
+ row = pos;
+ status &= ~(1 << pos);
+
+ code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
+ ske_ris = readl(keypad->reg_base + SKE_RIS);
+ key_pressed = ske_ris & SKE_KPRISA;
+
+ input_event(input, EV_MSC, MSC_SCAN, code);
+ input_report_key(input, keypad->keymap[code], key_pressed);
+ input_sync(input);
+ num_of_rows--;
+ } while (num_of_rows);
+}
+
+static void ske_keypad_read_data(struct ske_keypad *keypad)
+{
+ u8 status;
+ int col = 0;
+ int ske_asr, i;
/*
* Read the auto scan registers
@@ -154,44 +180,38 @@ static void ske_keypad_read_data(struct ske_keypad *keypad)
if (!ske_asr)
continue;
- /* now that ASRx is zero, find out the column x and row y*/
- if (ske_asr & 0xff) {
+ /* now that ASRx is zero, find out the coloumn x and row y */
+ status = ske_asr & 0xff;
+ if (status) {
col = i * 2;
- status = ske_asr & 0xff;
- } else {
+ ske_keypad_report(keypad, status, col);
+ }
+ status = (ske_asr & 0xff00) >> 8;
+ if (status) {
col = (i * 2) + 1;
- status = (ske_asr & 0xff00) >> 8;
+ ske_keypad_report(keypad, status, col);
}
-
- /* find out the row */
- row = __ffs(status);
-
- code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
- ske_ris = readl(keypad->reg_base + SKE_RIS);
- key_pressed = ske_ris & SKE_KPRISA;
-
- input_event(input, EV_MSC, MSC_SCAN, code);
- input_report_key(input, keypad->keymap[code], key_pressed);
- input_sync(input);
}
}
static irqreturn_t ske_keypad_irq(int irq, void *dev_id)
{
struct ske_keypad *keypad = dev_id;
- int retries = 20;
+ int timeout = keypad->board->debounce_ms;
/* disable auto scan interrupt; mask the interrupt generated */
ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA);
- while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --retries)
- msleep(5);
+ while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --timeout)
+ cpu_relax();
- if (retries) {
- /* SKEx registers are stable and can be read */
- ske_keypad_read_data(keypad);
- }
+ /* SKEx registers are stable and can be read */
+ ske_keypad_read_data(keypad);
+
+ /* wait until raw interrupt is clear */
+ while ((readl(keypad->reg_base + SKE_RIS)) && --timeout)
+ msleep(KEY_PRESSED_DELAY);
/* enable auto scan interrupts */
ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
index aed5f69..c05f98c 100644
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -27,6 +27,7 @@
#include <linux/platform_device.h>
#include <linux/errno.h>
#include <linux/io.h>
+#include <linux/of.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/pm_runtime.h>
@@ -84,8 +85,9 @@ struct omap4_keypad {
u32 reg_offset;
u32 irqreg_offset;
unsigned int row_shift;
+ bool no_autorepeat;
unsigned char key_state[8];
- unsigned short keymap[];
+ unsigned short *keymap;
};
static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset)
@@ -208,25 +210,51 @@ static void omap4_keypad_close(struct input_dev *input)
pm_runtime_put_sync(input->dev.parent);
}
+#ifdef CONFIG_OF
+static int __devinit omap4_keypad_parse_dt(struct device *dev,
+ struct omap4_keypad *keypad_data)
+{
+ struct device_node *np = dev->of_node;
+
+ if (!np) {
+ dev_err(dev, "missing DT data");
+ return -EINVAL;
+ }
+
+ of_property_read_u32(np, "keypad,num-rows", &keypad_data->rows);
+ of_property_read_u32(np, "keypad,num-columns", &keypad_data->cols);
+ if (!keypad_data->rows || !keypad_data->cols) {
+ dev_err(dev, "number of keypad rows/columns not specified\n");
+ return -EINVAL;
+ }
+
+ if (of_get_property(np, "linux,input-no-autorepeat", NULL))
+ keypad_data->no_autorepeat = true;
+
+ return 0;
+}
+#else
+static inline int omap4_keypad_parse_dt(struct device *dev,
+ struct omap4_keypad *keypad_data)
+{
+ return -ENOSYS;
+}
+#endif
+
static int __devinit omap4_keypad_probe(struct platform_device *pdev)
{
- const struct omap4_keypad_platform_data *pdata;
+ const struct omap4_keypad_platform_data *pdata =
+ dev_get_platdata(&pdev->dev);
+ const struct matrix_keymap_data *keymap_data =
+ pdata ? pdata->keymap_data : NULL;
struct omap4_keypad *keypad_data;
struct input_dev *input_dev;
struct resource *res;
- resource_size_t size;
- unsigned int row_shift, max_keys;
+ unsigned int max_keys;
int rev;
int irq;
int error;
- /* platform data */
- pdata = pdev->dev.platform_data;
- if (!pdata) {
- dev_err(&pdev->dev, "no platform data defined\n");
- return -EINVAL;
- }
-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "no base address specified\n");
@@ -239,25 +267,24 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
return -EINVAL;
}
- if (!pdata->keymap_data) {
- dev_err(&pdev->dev, "no keymap data defined\n");
- return -EINVAL;
- }
-
- row_shift = get_count_order(pdata->cols);
- max_keys = pdata->rows << row_shift;
-
- keypad_data = kzalloc(sizeof(struct omap4_keypad) +
- max_keys * sizeof(keypad_data->keymap[0]),
- GFP_KERNEL);
+ keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
if (!keypad_data) {
dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
return -ENOMEM;
}
- size = resource_size(res);
+ keypad_data->irq = irq;
+
+ if (pdata) {
+ keypad_data->rows = pdata->rows;
+ keypad_data->cols = pdata->cols;
+ } else {
+ error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
+ if (error)
+ return error;
+ }
- res = request_mem_region(res->start, size, pdev->name);
+ res = request_mem_region(res->start, resource_size(res), pdev->name);
if (!res) {
dev_err(&pdev->dev, "can't request mem region\n");
error = -EBUSY;
@@ -271,15 +298,11 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
goto err_release_mem;
}
- keypad_data->irq = irq;
- keypad_data->row_shift = row_shift;
- keypad_data->rows = pdata->rows;
- keypad_data->cols = pdata->cols;
/*
- * Enable clocks for the keypad module so that we can read
- * revision register.
- */
+ * Enable clocks for the keypad module so that we can read
+ * revision register.
+ */
pm_runtime_enable(&pdev->dev);
error = pm_runtime_get_sync(&pdev->dev);
if (error) {
@@ -322,19 +345,30 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
input_dev->open = omap4_keypad_open;
input_dev->close = omap4_keypad_close;
- error = matrix_keypad_build_keymap(pdata->keymap_data, NULL,
- pdata->rows, pdata->cols,
+ input_set_capability(input_dev, EV_MSC, MSC_SCAN);
+ if (!keypad_data->no_autorepeat)
+ __set_bit(EV_REP, input_dev->evbit);
+
+ input_set_drvdata(input_dev, keypad_data);
+
+ keypad_data->row_shift = get_count_order(keypad_data->cols);
+ max_keys = keypad_data->rows << keypad_data->row_shift;
+ keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]),
+ GFP_KERNEL);
+ if (!keypad_data->keymap) {
+ dev_err(&pdev->dev, "Not enough memory for keymap\n");
+ error = -ENOMEM;
+ goto err_free_input;
+ }
+
+ error = matrix_keypad_build_keymap(keymap_data, NULL,
+ keypad_data->rows, keypad_data->cols,
keypad_data->keymap, input_dev);
if (error) {
dev_err(&pdev->dev, "failed to build keymap\n");
- goto err_free_input;
+ goto err_free_keymap;
}
- __set_bit(EV_REP, input_dev->evbit);
- input_set_capability(input_dev, EV_MSC, MSC_SCAN);
-
- input_set_drvdata(input_dev, keypad_data);
-
error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
IRQF_TRIGGER_RISING,
"omap4-keypad", keypad_data);
@@ -357,6 +391,8 @@ static int __devinit omap4_keypad_probe(struct platform_device *pdev)
err_pm_disable:
pm_runtime_disable(&pdev->dev);
free_irq(keypad_data->irq, keypad_data);
+err_free_keymap:
+ kfree(keypad_data->keymap);
err_free_input:
input_free_device(input_dev);
err_pm_put_sync:
@@ -364,7 +400,7 @@ err_pm_put_sync:
err_unmap:
iounmap(keypad_data->base);
err_release_mem:
- release_mem_region(res->start, size);
+ release_mem_region(res->start, resource_size(res));
err_free_keypad:
kfree(keypad_data);
return error;
@@ -386,18 +422,29 @@ static int __devexit omap4_keypad_remove(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
+ kfree(keypad_data->keymap);
kfree(keypad_data);
+
platform_set_drvdata(pdev, NULL);
return 0;
}
+#ifdef CONFIG_OF
+static const struct of_device_id omap_keypad_dt_match[] = {
+ { .compatible = "ti,omap4-keypad" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, omap_keypad_dt_match);
+#endif
+
static struct platform_driver omap4_keypad_driver = {
.probe = omap4_keypad_probe,
.remove = __devexit_p(omap4_keypad_remove),
.driver = {
.name = "omap4-keypad",
.owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(omap_keypad_dt_match),
},
};
module_platform_driver(omap4_keypad_driver);
diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c
index 6f287f7..72ef01b 100644
--- a/drivers/input/keyboard/spear-keyboard.c
+++ b/drivers/input/keyboard/spear-keyboard.c
@@ -27,33 +27,31 @@
#include <plat/keyboard.h>
/* Keyboard Registers */
-#define MODE_REG 0x00 /* 16 bit reg */
-#define STATUS_REG 0x0C /* 2 bit reg */
-#define DATA_REG 0x10 /* 8 bit reg */
+#define MODE_CTL_REG 0x00
+#define STATUS_REG 0x0C
+#define DATA_REG 0x10
#define INTR_MASK 0x54
/* Register Values */
-/*
- * pclk freq mask = (APB FEQ -1)= 82 MHZ.Programme bit 15-9 in mode
- * control register as 1010010(82MHZ)
- */
-#define PCLK_FREQ_MSK 0xA400 /* 82 MHz */
-#define START_SCAN 0x0100
-#define SCAN_RATE_10 0x0000
-#define SCAN_RATE_20 0x0004
-#define SCAN_RATE_40 0x0008
-#define SCAN_RATE_80 0x000C
-#define MODE_KEYBOARD 0x0002
-#define DATA_AVAIL 0x2
-
-#define KEY_MASK 0xFF000000
-#define KEY_VALUE 0x00FFFFFF
-#define ROW_MASK 0xF0
-#define COLUMN_MASK 0x0F
#define NUM_ROWS 16
#define NUM_COLS 16
+#define MODE_CTL_PCLK_FREQ_SHIFT 9
+#define MODE_CTL_PCLK_FREQ_MSK 0x7F
+
+#define MODE_CTL_KEYBOARD (0x2 << 0)
+#define MODE_CTL_SCAN_RATE_10 (0x0 << 2)
+#define MODE_CTL_SCAN_RATE_20 (0x1 << 2)
+#define MODE_CTL_SCAN_RATE_40 (0x2 << 2)
+#define MODE_CTL_SCAN_RATE_80 (0x3 << 2)
+#define MODE_CTL_KEYNUM_SHIFT 6
+#define MODE_CTL_START_SCAN (0x1 << 8)
-#define KEY_MATRIX_SHIFT 6
+#define STATUS_DATA_AVAIL (0x1 << 1)
+
+#define DATA_ROW_MASK 0xF0
+#define DATA_COLUMN_MASK 0x0F
+
+#define ROW_SHIFT 4
struct spear_kbd {
struct input_dev *input;
@@ -65,6 +63,8 @@ struct spear_kbd {
unsigned short last_key;
unsigned short keycodes[NUM_ROWS * NUM_COLS];
bool rep;
+ unsigned int suspended_rate;
+ u32 mode_ctl_reg;
};
static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
@@ -72,10 +72,10 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
struct spear_kbd *kbd = dev_id;
struct input_dev *input = kbd->input;
unsigned int key;
- u8 sts, val;
+ u32 sts, val;
- sts = readb(kbd->io_base + STATUS_REG);
- if (!(sts & DATA_AVAIL))
+ sts = readl_relaxed(kbd->io_base + STATUS_REG);
+ if (!(sts & STATUS_DATA_AVAIL))
return IRQ_NONE;
if (kbd->last_key != KEY_RESERVED) {
@@ -84,7 +84,8 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
}
/* following reads active (row, col) pair */
- val = readb(kbd->io_base + DATA_REG);
+ val = readl_relaxed(kbd->io_base + DATA_REG) &
+ (DATA_ROW_MASK | DATA_COLUMN_MASK);
key = kbd->keycodes[val];
input_event(input, EV_MSC, MSC_SCAN, val);
@@ -94,7 +95,7 @@ static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id)
kbd->last_key = key;
/* clear interrupt */
- writeb(0, kbd->io_base + STATUS_REG);
+ writel_relaxed(0, kbd->io_base + STATUS_REG);
return IRQ_HANDLED;
}
@@ -103,7 +104,7 @@ static int spear_kbd_open(struct input_dev *dev)
{
struct spear_kbd *kbd = input_get_drvdata(dev);
int error;
- u16 val;
+ u32 val;
kbd->last_key = KEY_RESERVED;
@@ -111,16 +112,20 @@ static int spear_kbd_open(struct input_dev *dev)
if (error)
return error;
+ /* keyboard rate to be programmed is input clock (in MHz) - 1 */
+ val = clk_get_rate(kbd->clk) / 1000000 - 1;
+ val = (val & MODE_CTL_PCLK_FREQ_MSK) << MODE_CTL_PCLK_FREQ_SHIFT;
+
/* program keyboard */
- val = SCAN_RATE_80 | MODE_KEYBOARD | PCLK_FREQ_MSK |
- (kbd->mode << KEY_MATRIX_SHIFT);
- writew(val, kbd->io_base + MODE_REG);
- writeb(1, kbd->io_base + STATUS_REG);
+ val = MODE_CTL_SCAN_RATE_80 | MODE_CTL_KEYBOARD | val |
+ (kbd->mode << MODE_CTL_KEYNUM_SHIFT);
+ writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
+ writel_relaxed(1, kbd->io_base + STATUS_REG);
/* start key scan */
- val = readw(kbd->io_base + MODE_REG);
- val |= START_SCAN;
- writew(val, kbd->io_base + MODE_REG);
+ val = readl_relaxed(kbd->io_base + MODE_CTL_REG);
+ val |= MODE_CTL_START_SCAN;
+ writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
return 0;
}
@@ -128,12 +133,12 @@ static int spear_kbd_open(struct input_dev *dev)
static void spear_kbd_close(struct input_dev *dev)
{
struct spear_kbd *kbd = input_get_drvdata(dev);
- u16 val;
+ u32 val;
/* stop key scan */
- val = readw(kbd->io_base + MODE_REG);
- val &= ~START_SCAN;
- writew(val, kbd->io_base + MODE_REG);
+ val = readl_relaxed(kbd->io_base + MODE_CTL_REG);
+ val &= ~MODE_CTL_START_SCAN;
+ writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
clk_disable(kbd->clk);
@@ -146,7 +151,7 @@ static int __devinit spear_kbd_parse_dt(struct platform_device *pdev,
{
struct device_node *np = pdev->dev.of_node;
int error;
- u32 val;
+ u32 val, suspended_rate;
if (!np) {
dev_err(&pdev->dev, "Missing DT data\n");
@@ -156,6 +161,9 @@ static int __devinit spear_kbd_parse_dt(struct platform_device *pdev,
if (of_property_read_bool(np, "autorepeat"))
kbd->rep = true;
+ if (of_property_read_u32(np, "suspended_rate", &suspended_rate))
+ kbd->suspended_rate = suspended_rate;
+
error = of_property_read_u32(np, "st,mode", &val);
if (error) {
dev_err(&pdev->dev, "DT: Invalid or missing mode\n");
@@ -213,6 +221,7 @@ static int __devinit spear_kbd_probe(struct platform_device *pdev)
} else {
kbd->mode = pdata->mode;
kbd->rep = pdata->rep;
+ kbd->suspended_rate = pdata->suspended_rate;
}
kbd->res = request_mem_region(res->start, resource_size(res),
@@ -302,7 +311,7 @@ static int __devexit spear_kbd_remove(struct platform_device *pdev)
release_mem_region(kbd->res->start, resource_size(kbd->res));
kfree(kbd);
- device_init_wakeup(&pdev->dev, 1);
+ device_init_wakeup(&pdev->dev, 0);
platform_set_drvdata(pdev, NULL);
return 0;
@@ -314,15 +323,48 @@ static int spear_kbd_suspend(struct device *dev)
struct platform_device *pdev = to_platform_device(dev);
struct spear_kbd *kbd = platform_get_drvdata(pdev);
struct input_dev *input_dev = kbd->input;
+ unsigned int rate = 0, mode_ctl_reg, val;
mutex_lock(&input_dev->mutex);
- if (input_dev->users)
- clk_enable(kbd->clk);
+ /* explicitly enable clock as we may program device */
+ clk_enable(kbd->clk);
- if (device_may_wakeup(&pdev->dev))
+ mode_ctl_reg = readl_relaxed(kbd->io_base + MODE_CTL_REG);
+
+ if (device_may_wakeup(&pdev->dev)) {
enable_irq_wake(kbd->irq);
+ /*
+ * reprogram the keyboard operating frequency as on some
+ * platform it may change during system suspended
+ */
+ if (kbd->suspended_rate)
+ rate = kbd->suspended_rate / 1000000 - 1;
+ else
+ rate = clk_get_rate(kbd->clk) / 1000000 - 1;
+
+ val = mode_ctl_reg &
+ ~(MODE_CTL_PCLK_FREQ_MSK << MODE_CTL_PCLK_FREQ_SHIFT);
+ val |= (rate & MODE_CTL_PCLK_FREQ_MSK)
+ << MODE_CTL_PCLK_FREQ_SHIFT;
+ writel_relaxed(val, kbd->io_base + MODE_CTL_REG);
+
+ } else {
+ if (input_dev->users) {
+ writel_relaxed(mode_ctl_reg & ~MODE_CTL_START_SCAN,
+ kbd->io_base + MODE_CTL_REG);
+ clk_disable(kbd->clk);
+ }
+ }
+
+ /* store current configuration */
+ if (input_dev->users)
+ kbd->mode_ctl_reg = mode_ctl_reg;
+
+ /* restore previous clk state */
+ clk_disable(kbd->clk);
+
mutex_unlock(&input_dev->mutex);
return 0;
@@ -336,11 +378,16 @@ static int spear_kbd_resume(struct device *dev)
mutex_lock(&input_dev->mutex);
- if (device_may_wakeup(&pdev->dev))
+ if (device_may_wakeup(&pdev->dev)) {
disable_irq_wake(kbd->irq);
+ } else {
+ if (input_dev->users)
+ clk_enable(kbd->clk);
+ }
+ /* restore current configuration */
if (input_dev->users)
- clk_enable(kbd->clk);
+ writel_relaxed(kbd->mode_ctl_reg, kbd->io_base + MODE_CTL_REG);
mutex_unlock(&input_dev->mutex);
OpenPOWER on IntegriCloud