Maemo patchset 20101501+0m5
[h-e-n] / drivers / input / keyboard / omap-keypad.c
index 69e674e..3c411b6 100644 (file)
 #include <linux/delay.h>
 #include <linux/platform_device.h>
 #include <linux/mutex.h>
+#include <linux/spinlock.h>
 #include <linux/errno.h>
+#include <linux/i2c/menelaus.h>
 #include <mach/gpio.h>
 #include <mach/keypad.h>
-#include <mach/menelaus.h>
 #include <asm/irq.h>
 #include <mach/hardware.h>
 #include <asm/io.h>
+#include <asm/mach-types.h>
 #include <mach/mux.h>
 
 #undef NEW_BOARD_LEARNING_MODE
@@ -60,6 +62,8 @@ struct omap_kp {
        unsigned int cols;
        unsigned long delay;
        unsigned int debounce;
+       int suspended;
+       spinlock_t suspend_lock;
 };
 
 static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0);
@@ -96,12 +100,20 @@ static u8 get_row_gpio_val(struct omap_kp *omap_kp)
 static irqreturn_t omap_kp_interrupt(int irq, void *dev_id)
 {
        struct omap_kp *omap_kp = dev_id;
+       unsigned long flags;
+
+       spin_lock_irqsave(&omap_kp->suspend_lock, flags);
+       if (omap_kp->suspended) {
+               spin_unlock_irqrestore(&omap_kp->suspend_lock, flags);
+               return IRQ_HANDLED;
+       }
+       spin_unlock_irqrestore(&omap_kp->suspend_lock, flags);
 
        /* disable keyboard interrupt and schedule for handling */
        if (cpu_is_omap24xx()) {
                int i;
                for (i = 0; i < omap_kp->rows; i++)
-                       disable_irq(OMAP_GPIO_IRQ(row_gpios[i]));
+                       disable_irq(gpio_to_irq(row_gpios[i]));
        } else
                /* disable keyboard interrupt and schedule for handling */
                omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
@@ -122,14 +134,10 @@ static void omap_kp_scan_keypad(struct omap_kp *omap_kp, unsigned char *state)
 
        /* read the keypad status */
        if (cpu_is_omap24xx()) {
-               int i;
-               for (i = 0; i < omap_kp->rows; i++)
-                       disable_irq(OMAP_GPIO_IRQ(row_gpios[i]));
-
                /* read the keypad status */
                for (col = 0; col < omap_kp->cols; col++) {
                        set_col_gpio_val(omap_kp, ~(1 << col));
-                       state[col] = ~(get_row_gpio_val(omap_kp)) & 0x3f;
+                       state[col] = ~(get_row_gpio_val(omap_kp)) & 0xff;
                }
                set_col_gpio_val(omap_kp, 0);
 
@@ -224,7 +232,7 @@ static void omap_kp_tasklet(unsigned long data)
                if (cpu_is_omap24xx()) {
                        int i;
                        for (i = 0; i < omap_kp_data->rows; i++)
-                               enable_irq(OMAP_GPIO_IRQ(row_gpios[i]));
+                               enable_irq(gpio_to_irq(row_gpios[i]));
                } else {
                        omap_writew(0, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
                        kp_cur_group = -1;
@@ -267,15 +275,29 @@ static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, omap_kp_enable_show, omap_kp_enabl
 #ifdef CONFIG_PM
 static int omap_kp_suspend(struct platform_device *dev, pm_message_t state)
 {
-       /* Nothing yet */
+       struct omap_kp *omap_kp = platform_get_drvdata(dev);
+       unsigned long flags;
+       spin_lock_irqsave(&omap_kp->suspend_lock, flags);
+
+       /*
+        * Re-enable the interrupt in case it has been masked by the
+        * handler and a key is still pressed.  We need the interrupt
+        * to wake us up from suspended.
+        */
+       if (cpu_class_is_omap1())
+               omap_writew(0, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
+
+       omap_kp->suspended = 1;
 
+       spin_unlock_irqrestore(&omap_kp->suspend_lock, flags);
        return 0;
 }
 
 static int omap_kp_resume(struct platform_device *dev)
 {
-       /* Nothing yet */
+       struct omap_kp *omap_kp = platform_get_drvdata(dev);
 
+       omap_kp->suspended = 0;
        return 0;
 }
 #else
@@ -288,7 +310,7 @@ static int __init omap_kp_probe(struct platform_device *pdev)
        struct omap_kp *omap_kp;
        struct input_dev *input_dev;
        struct omap_kp_platform_data *pdata =  pdev->dev.platform_data;
-       int i, col_idx, row_idx, irq_idx, ret;
+       int i, col_idx = 0, row_idx = 0, irq_idx, ret;
 
        if (!pdata->rows || !pdata->cols || !pdata->keymap) {
                printk(KERN_ERR "No rows, cols or keymap from pdata\n");
@@ -305,7 +327,9 @@ static int __init omap_kp_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, omap_kp);
 
+       spin_lock_init(&omap_kp->suspend_lock);
        omap_kp->input = input_dev;
+       omap_kp->suspended = 0;
 
        /* Disable the interrupt for the MPUIO keyboard */
        if (!cpu_is_omap24xx())
@@ -397,7 +421,7 @@ static int __init omap_kp_probe(struct platform_device *pdev)
                omap_writew(0, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
        } else {
                for (irq_idx = 0; irq_idx < omap_kp->rows; irq_idx++) {
-                       if (request_irq(OMAP_GPIO_IRQ(row_gpios[irq_idx]),
+                       if (request_irq(gpio_to_irq(row_gpios[irq_idx]),
                                        omap_kp_interrupt,
                                        IRQF_TRIGGER_FALLING,
                                        "omap-keypad", omap_kp) < 0)
@@ -438,7 +462,7 @@ static int omap_kp_remove(struct platform_device *pdev)
                        gpio_free(col_gpios[i]);
                for (i = 0; i < omap_kp->rows; i++) {
                        gpio_free(row_gpios[i]);
-                       free_irq(OMAP_GPIO_IRQ(row_gpios[i]), 0);
+                       free_irq(gpio_to_irq(row_gpios[i]), 0);
                }
        } else {
                omap_writew(1, OMAP_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);