Merge current mainline tree into linux-omap tree
[pandora-kernel.git] / drivers / input / keyboard / omap-keypad.c
index 10afd20..d57d2cb 100644 (file)
 #include <linux/delay.h>
 #include <linux/platform_device.h>
 #include <linux/mutex.h>
+#include <linux/spinlock.h>
 #include <linux/errno.h>
-#include <asm/arch/gpio.h>
-#include <asm/arch/keypad.h>
-#include <asm/arch/menelaus.h>
+#include <linux/i2c/menelaus.h>
+#include <mach/gpio.h>
+#include <mach/keypad.h>
 #include <asm/irq.h>
-#include <asm/hardware.h>
+#include <mach/hardware.h>
 #include <asm/io.h>
 #include <asm/mach-types.h>
-#include <asm/arch/mux.h>
+#include <mach/mux.h>
 
 #undef NEW_BOARD_LEARNING_MODE
 
@@ -61,9 +62,11 @@ struct omap_kp {
        unsigned int cols;
        unsigned long delay;
        unsigned int debounce;
+       int suspended;
+       spinlock_t suspend_lock;
 };
 
-DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0);
+static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0);
 
 static int *keymap;
 static unsigned int *row_gpios;
@@ -73,12 +76,9 @@ static unsigned int *col_gpios;
 static void set_col_gpio_val(struct omap_kp *omap_kp, u8 value)
 {
        int col;
-       for (col = 0; col < omap_kp->cols; col++) {
-               if (value & (1 << col))
-                       omap_set_gpio_dataout(col_gpios[col], 1);
-               else
-                       omap_set_gpio_dataout(col_gpios[col], 0);
-       }
+
+       for (col = 0; col < omap_kp->cols; col++)
+               gpio_set_value(col_gpios[col], value & (1 << col));
 }
 
 static u8 get_row_gpio_val(struct omap_kp *omap_kp)
@@ -87,7 +87,7 @@ static u8 get_row_gpio_val(struct omap_kp *omap_kp)
        u8 value = 0;
 
        for (row = 0; row < omap_kp->rows; row++) {
-               if (omap_get_gpio_datain(row_gpios[row]))
+               if (gpio_get_value(row_gpios[row]))
                        value |= (1 << row);
        }
        return value;
@@ -100,6 +100,14 @@ 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()) {
@@ -271,15 +279,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
@@ -292,7 +314,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");
@@ -309,7 +331,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())
@@ -334,23 +358,23 @@ static int __init omap_kp_probe(struct platform_device *pdev)
        if (cpu_is_omap24xx()) {
                /* Cols: outputs */
                for (col_idx = 0; col_idx < omap_kp->cols; col_idx++) {
-                       if (omap_request_gpio(col_gpios[col_idx]) < 0) {
+                       if (gpio_request(col_gpios[col_idx], "omap_kp_col") < 0) {
                                printk(KERN_ERR "Failed to request"
                                       "GPIO%d for keypad\n",
                                       col_gpios[col_idx]);
                                goto err1;
                        }
-                       omap_set_gpio_direction(col_gpios[col_idx], 0);
+                       gpio_direction_output(col_gpios[col_idx], 0);
                }
                /* Rows: inputs */
                for (row_idx = 0; row_idx < omap_kp->rows; row_idx++) {
-                       if (omap_request_gpio(row_gpios[row_idx]) < 0) {
+                       if (gpio_request(row_gpios[row_idx], "omap_kp_row") < 0) {
                                printk(KERN_ERR "Failed to request"
                                       "GPIO%d for keypad\n",
                                       row_gpios[row_idx]);
                                goto err2;
                        }
-                       omap_set_gpio_direction(row_gpios[row_idx], 1);
+                       gpio_direction_input(row_gpios[row_idx]);
                }
        } else {
                col_idx = 0;
@@ -419,10 +443,10 @@ err3:
        device_remove_file(&pdev->dev, &dev_attr_enable);
 err2:
        for (i = row_idx - 1; i >=0; i--)
-               omap_free_gpio(row_gpios[i]);
+               gpio_free(row_gpios[i]);
 err1:
        for (i = col_idx - 1; i >=0; i--)
-               omap_free_gpio(col_gpios[i]);
+               gpio_free(col_gpios[i]);
 
        kfree(omap_kp);
        input_free_device(input_dev);
@@ -439,9 +463,9 @@ static int omap_kp_remove(struct platform_device *pdev)
        if (cpu_is_omap24xx()) {
                int i;
                for (i = 0; i < omap_kp->cols; i++)
-                       omap_free_gpio(col_gpios[i]);
+                       gpio_free(col_gpios[i]);
                for (i = 0; i < omap_kp->rows; i++) {
-                       omap_free_gpio(row_gpios[i]);
+                       gpio_free(row_gpios[i]);
                        free_irq(OMAP_GPIO_IRQ(row_gpios[i]), 0);
                }
        } else {