diff options
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r-- | drivers/input/keyboard/atkbd.c | 74 | ||||
-rw-r--r-- | drivers/input/keyboard/davinci_keyscan.c | 8 | ||||
-rw-r--r-- | drivers/input/keyboard/ep93xx_keypad.c | 150 | ||||
-rw-r--r-- | drivers/input/keyboard/matrix_keypad.c | 29 | ||||
-rw-r--r-- | drivers/input/keyboard/twl4030_keypad.c | 11 |
5 files changed, 117 insertions, 155 deletions
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index a3573570c52f..7b4056292eaf 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -134,7 +134,8 @@ static const unsigned short atkbd_unxlate_table[128] = { #define ATKBD_CMD_GETID 0x02f2 #define ATKBD_CMD_SETREP 0x10f3 #define ATKBD_CMD_ENABLE 0x00f4 -#define ATKBD_CMD_RESET_DIS 0x00f5 +#define ATKBD_CMD_RESET_DIS 0x00f5 /* Reset to defaults and disable */ +#define ATKBD_CMD_RESET_DEF 0x00f6 /* Reset to defaults */ #define ATKBD_CMD_SETALL_MBR 0x00fa #define ATKBD_CMD_RESET_BAT 0x02ff #define ATKBD_CMD_RESEND 0x00fe @@ -224,8 +225,10 @@ struct atkbd { struct delayed_work event_work; unsigned long event_jiffies; - struct mutex event_mutex; unsigned long event_mask; + + /* Serializes reconnect(), attr->set() and event work */ + struct mutex mutex; }; /* @@ -576,7 +579,7 @@ static void atkbd_event_work(struct work_struct *work) { struct atkbd *atkbd = container_of(work, struct atkbd, event_work.work); - mutex_lock(&atkbd->event_mutex); + mutex_lock(&atkbd->mutex); if (!atkbd->enabled) { /* @@ -595,7 +598,7 @@ static void atkbd_event_work(struct work_struct *work) atkbd_set_repeat_rate(atkbd); } - mutex_unlock(&atkbd->event_mutex); + mutex_unlock(&atkbd->mutex); } /* @@ -611,7 +614,7 @@ static void atkbd_schedule_event_work(struct atkbd *atkbd, int event_bit) atkbd->event_jiffies = jiffies; set_bit(event_bit, &atkbd->event_mask); - wmb(); + mb(); schedule_delayed_work(&atkbd->event_work, delay); } @@ -836,7 +839,7 @@ static void atkbd_cleanup(struct serio *serio) struct atkbd *atkbd = serio_get_drvdata(serio); atkbd_disable(atkbd); - ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_BAT); + ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF); } @@ -848,13 +851,20 @@ static void atkbd_disconnect(struct serio *serio) { struct atkbd *atkbd = serio_get_drvdata(serio); + sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group); + atkbd_disable(atkbd); - /* make sure we don't have a command in flight */ + input_unregister_device(atkbd->dev); + + /* + * Make sure we don't have a command in flight. + * Note that since atkbd->enabled is false event work will keep + * rescheduling itself until it gets canceled and will not try + * accessing freed input device or serio port. + */ cancel_delayed_work_sync(&atkbd->event_work); - sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group); - input_unregister_device(atkbd->dev); serio_close(serio); serio_set_drvdata(serio, NULL); kfree(atkbd); @@ -1086,7 +1096,7 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv) atkbd->dev = dev; ps2_init(&atkbd->ps2dev, serio); INIT_DELAYED_WORK(&atkbd->event_work, atkbd_event_work); - mutex_init(&atkbd->event_mutex); + mutex_init(&atkbd->mutex); switch (serio->id.type) { @@ -1159,19 +1169,23 @@ static int atkbd_reconnect(struct serio *serio) { struct atkbd *atkbd = serio_get_drvdata(serio); struct serio_driver *drv = serio->drv; + int retval = -1; if (!atkbd || !drv) { printk(KERN_DEBUG "atkbd: reconnect request, but serio is disconnected, ignoring...\n"); return -1; } + mutex_lock(&atkbd->mutex); + atkbd_disable(atkbd); if (atkbd->write) { if (atkbd_probe(atkbd)) - return -1; + goto out; + if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra)) - return -1; + goto out; atkbd_activate(atkbd); @@ -1189,8 +1203,11 @@ static int atkbd_reconnect(struct serio *serio) } atkbd_enable(atkbd); + retval = 0; - return 0; + out: + mutex_unlock(&atkbd->mutex); + return retval; } static struct serio_device_id atkbd_serio_ids[] = { @@ -1234,47 +1251,28 @@ static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf, ssize_t (*handler)(struct atkbd *, char *)) { struct serio *serio = to_serio_port(dev); - int retval; - - retval = serio_pin_driver(serio); - if (retval) - return retval; - - if (serio->drv != &atkbd_drv) { - retval = -ENODEV; - goto out; - } - - retval = handler((struct atkbd *)serio_get_drvdata(serio), buf); + struct atkbd *atkbd = serio_get_drvdata(serio); -out: - serio_unpin_driver(serio); - return retval; + return handler(atkbd, buf); } static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count, ssize_t (*handler)(struct atkbd *, const char *, size_t)) { struct serio *serio = to_serio_port(dev); - struct atkbd *atkbd; + struct atkbd *atkbd = serio_get_drvdata(serio); int retval; - retval = serio_pin_driver(serio); + retval = mutex_lock_interruptible(&atkbd->mutex); if (retval) return retval; - if (serio->drv != &atkbd_drv) { - retval = -ENODEV; - goto out; - } - - atkbd = serio_get_drvdata(serio); atkbd_disable(atkbd); retval = handler(atkbd, buf, count); atkbd_enable(atkbd); -out: - serio_unpin_driver(serio); + mutex_unlock(&atkbd->mutex); + return retval; } diff --git a/drivers/input/keyboard/davinci_keyscan.c b/drivers/input/keyboard/davinci_keyscan.c index 6e52d855f637..d410d7a52f1d 100644 --- a/drivers/input/keyboard/davinci_keyscan.c +++ b/drivers/input/keyboard/davinci_keyscan.c @@ -174,6 +174,14 @@ static int __init davinci_ks_probe(struct platform_device *pdev) struct davinci_ks_platform_data *pdata = pdev->dev.platform_data; int error, i; + if (pdata->device_enable) { + error = pdata->device_enable(dev); + if (error < 0) { + dev_dbg(dev, "device enable function failed\n"); + return error; + } + } + if (!pdata->keymap) { dev_dbg(dev, "no keymap from pdata\n"); return -EINVAL; diff --git a/drivers/input/keyboard/ep93xx_keypad.c b/drivers/input/keyboard/ep93xx_keypad.c index 181d30e3018e..e45740429f7e 100644 --- a/drivers/input/keyboard/ep93xx_keypad.c +++ b/drivers/input/keyboard/ep93xx_keypad.c @@ -22,11 +22,11 @@ #include <linux/platform_device.h> #include <linux/interrupt.h> -#include <linux/input.h> #include <linux/clk.h> +#include <linux/io.h> +#include <linux/input/matrix_keypad.h> #include <mach/hardware.h> -#include <mach/gpio.h> #include <mach/ep93xx_keypad.h> /* @@ -60,38 +60,37 @@ #define KEY_REG_KEY1_MASK (0x0000003f) #define KEY_REG_KEY1_SHIFT (0) -#define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) -#define keypad_writel(v, off) __raw_writel((v), keypad->mmio_base + (off)) - -#define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS) +#define EP93XX_MATRIX_SIZE (EP93XX_MATRIX_ROWS * EP93XX_MATRIX_COLS) struct ep93xx_keypad { struct ep93xx_keypad_platform_data *pdata; - - struct clk *clk; struct input_dev *input_dev; + struct clk *clk; + void __iomem *mmio_base; - int irq; - int enabled; + unsigned int matrix_keycodes[EP93XX_MATRIX_SIZE]; int key1; int key2; - unsigned int matrix_keycodes[MAX_MATRIX_KEY_NUM]; + int irq; + + bool enabled; }; static void ep93xx_keypad_build_keycode(struct ep93xx_keypad *keypad) { struct ep93xx_keypad_platform_data *pdata = keypad->pdata; struct input_dev *input_dev = keypad->input_dev; + unsigned int *key; int i; - for (i = 0; i < pdata->matrix_key_map_size; i++) { - unsigned int key = pdata->matrix_key_map[i]; - int row = (key >> 28) & 0xf; - int col = (key >> 24) & 0xf; - int code = key & 0xffffff; + key = &pdata->matrix_key_map[0]; + for (i = 0; i < pdata->matrix_key_map_size; i++, key++) { + int row = KEY_ROW(*key); + int col = KEY_COL(*key); + int code = KEY_VAL(*key); keypad->matrix_keycodes[(row << 3) + col] = code; __set_bit(code, input_dev->keybit); @@ -102,9 +101,11 @@ static irqreturn_t ep93xx_keypad_irq_handler(int irq, void *dev_id) { struct ep93xx_keypad *keypad = dev_id; struct input_dev *input_dev = keypad->input_dev; - unsigned int status = keypad_readl(KEY_REG); + unsigned int status; int keycode, key1, key2; + status = __raw_readl(keypad->mmio_base + KEY_REG); + keycode = (status & KEY_REG_KEY1_MASK) >> KEY_REG_KEY1_SHIFT; key1 = keypad->matrix_keycodes[keycode]; @@ -152,7 +153,10 @@ static void ep93xx_keypad_config(struct ep93xx_keypad *keypad) struct ep93xx_keypad_platform_data *pdata = keypad->pdata; unsigned int val = 0; - clk_set_rate(keypad->clk, pdata->flags & EP93XX_KEYPAD_KDIV); + if (pdata->flags & EP93XX_KEYPAD_KDIV) + clk_set_rate(keypad->clk, EP93XX_KEYTCHCLK_DIV4); + else + clk_set_rate(keypad->clk, EP93XX_KEYTCHCLK_DIV16); if (pdata->flags & EP93XX_KEYPAD_DISABLE_3_KEY) val |= KEY_INIT_DIS3KY; @@ -167,7 +171,7 @@ static void ep93xx_keypad_config(struct ep93xx_keypad *keypad) val |= ((pdata->prescale << KEY_INIT_PRSCL_SHIFT) & KEY_INIT_PRSCL_MASK); - keypad_writel(val, KEY_INIT); + __raw_writel(val, keypad->mmio_base + KEY_INIT); } static int ep93xx_keypad_open(struct input_dev *pdev) @@ -177,7 +181,7 @@ static int ep93xx_keypad_open(struct input_dev *pdev) if (!keypad->enabled) { ep93xx_keypad_config(keypad); clk_enable(keypad->clk); - keypad->enabled = 1; + keypad->enabled = true; } return 0; @@ -189,7 +193,7 @@ static void ep93xx_keypad_close(struct input_dev *pdev) if (keypad->enabled) { clk_disable(keypad->clk); - keypad->enabled = 0; + keypad->enabled = false; } } @@ -211,7 +215,7 @@ static int ep93xx_keypad_suspend(struct platform_device *pdev, if (keypad->enabled) { clk_disable(keypad->clk); - keypad->enabled = 0; + keypad->enabled = false; } mutex_unlock(&input_dev->mutex); @@ -236,7 +240,7 @@ static int ep93xx_keypad_resume(struct platform_device *pdev) if (!keypad->enabled) { ep93xx_keypad_config(keypad); clk_enable(keypad->clk); - keypad->enabled = 1; + keypad->enabled = true; } } @@ -252,88 +256,56 @@ static int ep93xx_keypad_resume(struct platform_device *pdev) static int __devinit ep93xx_keypad_probe(struct platform_device *pdev) { struct ep93xx_keypad *keypad; - struct ep93xx_keypad_platform_data *pdata = pdev->dev.platform_data; struct input_dev *input_dev; struct resource *res; - int irq, err, i, gpio; - - if (!pdata || - !pdata->matrix_key_rows || - pdata->matrix_key_rows > MAX_MATRIX_KEY_ROWS || - !pdata->matrix_key_cols || - pdata->matrix_key_cols > MAX_MATRIX_KEY_COLS) { - dev_err(&pdev->dev, "invalid or missing platform data\n"); - return -EINVAL; - } + int err; keypad = kzalloc(sizeof(struct ep93xx_keypad), GFP_KERNEL); - if (!keypad) { - dev_err(&pdev->dev, "failed to allocate driver data\n"); + if (!keypad) return -ENOMEM; - } - keypad->pdata = pdata; + keypad->pdata = pdev->dev.platform_data; + if (!keypad->pdata) { + err = -EINVAL; + goto failed_free; + } - irq = platform_get_irq(pdev, 0); - if (irq < 0) { - dev_err(&pdev->dev, "failed to get keypad irq\n"); + keypad->irq = platform_get_irq(pdev, 0); + if (!keypad->irq) { err = -ENXIO; goto failed_free; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { - dev_err(&pdev->dev, "failed to get I/O memory\n"); err = -ENXIO; goto failed_free; } res = request_mem_region(res->start, resource_size(res), pdev->name); if (!res) { - dev_err(&pdev->dev, "failed to request I/O memory\n"); err = -EBUSY; goto failed_free; } keypad->mmio_base = ioremap(res->start, resource_size(res)); if (keypad->mmio_base == NULL) { - dev_err(&pdev->dev, "failed to remap I/O memory\n"); err = -ENXIO; goto failed_free_mem; } - /* Request the needed GPIO's */ - gpio = EP93XX_GPIO_LINE_ROW0; - for (i = 0; i < keypad->pdata->matrix_key_rows; i++, gpio++) { - err = gpio_request(gpio, pdev->name); - if (err) { - dev_err(&pdev->dev, "failed to request gpio-%d\n", - gpio); - goto failed_free_rows; - } - } - - gpio = EP93XX_GPIO_LINE_COL0; - for (i = 0; i < keypad->pdata->matrix_key_cols; i++, gpio++) { - err = gpio_request(gpio, pdev->name); - if (err) { - dev_err(&pdev->dev, "failed to request gpio-%d\n", - gpio); - goto failed_free_cols; - } - } + err = ep93xx_keypad_acquire_gpio(pdev); + if (err) + goto failed_free_io; - keypad->clk = clk_get(&pdev->dev, "key_clk"); + keypad->clk = clk_get(&pdev->dev, NULL); if (IS_ERR(keypad->clk)) { - dev_err(&pdev->dev, "failed to get keypad clock\n"); err = PTR_ERR(keypad->clk); - goto failed_free_io; + goto failed_free_gpio; } - /* Create and register the input driver */ input_dev = input_allocate_device(); if (!input_dev) { - dev_err(&pdev->dev, "failed to allocate input device\n"); err = -ENOMEM; goto failed_put_clk; } @@ -358,44 +330,29 @@ static int __devinit ep93xx_keypad_probe(struct platform_device *pdev) ep93xx_keypad_build_keycode(keypad); platform_set_drvdata(pdev, keypad); - err = request_irq(irq, ep93xx_keypad_irq_handler, IRQF_DISABLED, - pdev->name, keypad); - if (err) { - dev_err(&pdev->dev, "failed to request IRQ\n"); + err = request_irq(keypad->irq, ep93xx_keypad_irq_handler, + IRQF_DISABLED, pdev->name, keypad); + if (err) goto failed_free_dev; - } - - keypad->irq = irq; - /* Register the input device */ err = input_register_device(input_dev); - if (err) { - dev_err(&pdev->dev, "failed to register input device\n"); + if (err) goto failed_free_irq; - } device_init_wakeup(&pdev->dev, 1); return 0; failed_free_irq: - free_irq(irq, pdev); + free_irq(keypad->irq, pdev); platform_set_drvdata(pdev, NULL); failed_free_dev: input_free_device(input_dev); failed_put_clk: clk_put(keypad->clk); +failed_free_gpio: + ep93xx_keypad_release_gpio(pdev); failed_free_io: - i = keypad->pdata->matrix_key_cols - 1; - gpio = EP93XX_GPIO_LINE_COL0 + i; -failed_free_cols: - for ( ; i >= 0; i--, gpio--) - gpio_free(gpio); - i = keypad->pdata->matrix_key_rows - 1; - gpio = EP93XX_GPIO_LINE_ROW0 + i; -failed_free_rows: - for ( ; i >= 0; i--, gpio--) - gpio_free(gpio); iounmap(keypad->mmio_base); failed_free_mem: release_mem_region(res->start, resource_size(res)); @@ -408,7 +365,6 @@ static int __devexit ep93xx_keypad_remove(struct platform_device *pdev) { struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); struct resource *res; - int i, gpio; free_irq(keypad->irq, pdev); @@ -420,15 +376,7 @@ static int __devexit ep93xx_keypad_remove(struct platform_device *pdev) input_unregister_device(keypad->input_dev); - i = keypad->pdata->matrix_key_cols - 1; - gpio = EP93XX_GPIO_LINE_COL0 + i; - for ( ; i >= 0; i--, gpio--) - gpio_free(gpio); - - i = keypad->pdata->matrix_key_rows - 1; - gpio = EP93XX_GPIO_LINE_ROW0 + i; - for ( ; i >= 0; i--, gpio--) - gpio_free(gpio); + ep93xx_keypad_release_gpio(pdev); iounmap(keypad->mmio_base); diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 34f4a29d4973..d3c8b61a941d 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -29,11 +29,13 @@ struct matrix_keypad { unsigned short *keycodes; unsigned int row_shift; + DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS); + uint32_t last_key_state[MATRIX_MAX_COLS]; struct delayed_work work; + spinlock_t lock; bool scan_pending; bool stopped; - spinlock_t lock; }; /* @@ -222,9 +224,16 @@ static int matrix_keypad_suspend(struct device *dev) matrix_keypad_stop(keypad->input_dev); - if (device_may_wakeup(&pdev->dev)) - for (i = 0; i < pdata->num_row_gpios; i++) - enable_irq_wake(gpio_to_irq(pdata->row_gpios[i])); + if (device_may_wakeup(&pdev->dev)) { + for (i = 0; i < pdata->num_row_gpios; i++) { + if (!test_bit(i, keypad->disabled_gpios)) { + unsigned int gpio = pdata->row_gpios[i]; + + if (enable_irq_wake(gpio_to_irq(gpio)) == 0) + __set_bit(i, keypad->disabled_gpios); + } + } + } return 0; } @@ -236,9 +245,15 @@ static int matrix_keypad_resume(struct device *dev) const struct matrix_keypad_platform_data *pdata = keypad->pdata; int i; - if (device_may_wakeup(&pdev->dev)) - for (i = 0; i < pdata->num_row_gpios; i++) - disable_irq_wake(gpio_to_irq(pdata->row_gpios[i])); + if (device_may_wakeup(&pdev->dev)) { + for (i = 0; i < pdata->num_row_gpios; i++) { + if (test_and_clear_bit(i, keypad->disabled_gpios)) { + unsigned int gpio = pdata->row_gpios[i]; + + disable_irq_wake(gpio_to_irq(gpio)); + } + } + } matrix_keypad_start(keypad->input_dev); diff --git a/drivers/input/keyboard/twl4030_keypad.c b/drivers/input/keyboard/twl4030_keypad.c index eeaa7acb9cfc..21d6184efa96 100644 --- a/drivers/input/keyboard/twl4030_keypad.c +++ b/drivers/input/keyboard/twl4030_keypad.c @@ -253,14 +253,6 @@ static irqreturn_t do_kp_irq(int irq, void *_kp) u8 reg; int ret; -#ifdef CONFIG_LOCKDEP - /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which - * we don't want and can't tolerate. Although it might be - * friendlier not to borrow this thread context... - */ - local_irq_enable(); -#endif - /* Read & Clear TWL4030 pending interrupt */ ret = twl4030_kpread(kp, ®, KEYP_ISR1, 1); @@ -403,7 +395,8 @@ static int __devinit twl4030_kp_probe(struct platform_device *pdev) * * NOTE: we assume this host is wired to TWL4040 INT1, not INT2 ... */ - error = request_irq(kp->irq, do_kp_irq, 0, pdev->name, kp); + error = request_threaded_irq(kp->irq, NULL, do_kp_irq, + 0, pdev->name, kp); if (error) { dev_info(kp->dbg_dev, "request_irq failed for irq no=%d\n", kp->irq); |