x86, UV: Fix RTC latency bug by reading replicated cachelines
[safe/jmp/linux-2.6] / drivers / input / keyboard / bf54x-keys.c
index 05e3494..fe376a2 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * Modified:
- *               Copyright 2007 Analog Devices Inc.
+ *               Copyright 2007-2008 Analog Devices Inc.
  *
  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
  *
@@ -29,7 +29,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/version.h>
 
 #include <linux/init.h>
 #include <linux/fs.h>
@@ -44,7 +43,7 @@
 #include <linux/input.h>
 
 #include <asm/portmux.h>
-#include <asm/mach/bf54x_keys.h>
+#include <mach/bf54x_keys.h>
 
 #define DRV_NAME       "bf54x-keys"
 #define TIME_SCALE     100     /* 100 ns */
@@ -82,6 +81,9 @@ struct bf54x_kpad {
        unsigned short *keycode;
        struct timer_list timer;
        unsigned int keyup_test_jiffies;
+       unsigned short kpad_msel;
+       unsigned short kpad_prescale;
+       unsigned short kpad_ctl;
 };
 
 static inline int bfin_kpad_find_key(struct bf54x_kpad *bf54x_kpad,
@@ -182,14 +184,13 @@ static int __devinit bfin_kpad_probe(struct platform_device *pdev)
        int i, error;
 
        if (!pdata->rows || !pdata->cols || !pdata->keymap) {
-               printk(KERN_ERR DRV_NAME
-                       ": No rows, cols or keymap from pdata\n");
+               dev_err(&pdev->dev, "no rows, cols or keymap from pdata\n");
                return -EINVAL;
        }
 
        if (!pdata->keymapsize ||
            pdata->keymapsize > (pdata->rows * pdata->cols)) {
-               printk(KERN_ERR DRV_NAME ": Invalid keymapsize\n");
+               dev_err(&pdev->dev, "invalid keymapsize\n");
                return -EINVAL;
        }
 
@@ -207,10 +208,10 @@ static int __devinit bfin_kpad_probe(struct platform_device *pdev)
                goto out;
        }
 
-       if (!pdata->debounce_time || !pdata->debounce_time > MAX_MULT ||
-           !pdata->coldrive_time || !pdata->coldrive_time > MAX_MULT) {
-               printk(KERN_ERR DRV_NAME
-                       ": Invalid Debounce/Columdrive Time from pdata\n");
+       if (!pdata->debounce_time || pdata->debounce_time > MAX_MULT ||
+           !pdata->coldrive_time || pdata->coldrive_time > MAX_MULT) {
+               dev_warn(&pdev->dev,
+                       "invalid platform debounce/columndrive time\n");
                bfin_write_KPAD_MSEL(0xFF0);    /* Default MSEL */
        } else {
                bfin_write_KPAD_MSEL(
@@ -229,16 +230,14 @@ static int __devinit bfin_kpad_probe(struct platform_device *pdev)
 
        if (peripheral_request_list((u16 *)&per_rows[MAX_RC - pdata->rows],
                                    DRV_NAME)) {
-               printk(KERN_ERR DRV_NAME
-                       ": Requesting Peripherals failed\n");
+               dev_err(&pdev->dev, "requesting peripherals failed\n");
                error = -EFAULT;
                goto out0;
        }
 
        if (peripheral_request_list((u16 *)&per_cols[MAX_RC - pdata->cols],
                                    DRV_NAME)) {
-               printk(KERN_ERR DRV_NAME
-                       ": Requesting Peripherals failed\n");
+               dev_err(&pdev->dev, "requesting peripherals failed\n");
                error = -EFAULT;
                goto out1;
        }
@@ -250,11 +249,10 @@ static int __devinit bfin_kpad_probe(struct platform_device *pdev)
        }
 
        error = request_irq(bf54x_kpad->irq, bfin_kpad_isr,
-                                IRQF_SAMPLE_RANDOM, DRV_NAME, pdev);
+                               0, DRV_NAME, pdev);
        if (error) {
-               printk(KERN_ERR DRV_NAME
-                       ": unable to claim irq %d; error %d\n",
-                       bf54x_kpad->irq, error);
+               dev_err(&pdev->dev, "unable to claim irq %d\n",
+                       bf54x_kpad->irq);
                goto out2;
        }
 
@@ -295,8 +293,7 @@ static int __devinit bfin_kpad_probe(struct platform_device *pdev)
 
        error = input_register_device(input);
        if (error) {
-               printk(KERN_ERR DRV_NAME
-                       ": Unable to register input device (%d)\n", error);
+               dev_err(&pdev->dev, "unable to register input device\n");
                goto out4;
        }
 
@@ -312,8 +309,7 @@ static int __devinit bfin_kpad_probe(struct platform_device *pdev)
 
        bfin_write_KPAD_CTL(bfin_read_KPAD_CTL() | KPAD_EN);
 
-       printk(KERN_ERR DRV_NAME
-               ": Blackfin BF54x Keypad registered IRQ %d\n", bf54x_kpad->irq);
+       device_init_wakeup(&pdev->dev, 1);
 
        return 0;
 
@@ -354,12 +350,48 @@ static int __devexit bfin_kpad_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int bfin_kpad_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
+
+       bf54x_kpad->kpad_msel = bfin_read_KPAD_MSEL();
+       bf54x_kpad->kpad_prescale = bfin_read_KPAD_PRESCALE();
+       bf54x_kpad->kpad_ctl = bfin_read_KPAD_CTL();
+
+       if (device_may_wakeup(&pdev->dev))
+               enable_irq_wake(bf54x_kpad->irq);
+
+       return 0;
+}
+
+static int bfin_kpad_resume(struct platform_device *pdev)
+{
+       struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
+
+       bfin_write_KPAD_MSEL(bf54x_kpad->kpad_msel);
+       bfin_write_KPAD_PRESCALE(bf54x_kpad->kpad_prescale);
+       bfin_write_KPAD_CTL(bf54x_kpad->kpad_ctl);
+
+       if (device_may_wakeup(&pdev->dev))
+               disable_irq_wake(bf54x_kpad->irq);
+
+       return 0;
+}
+#else
+# define bfin_kpad_suspend NULL
+# define bfin_kpad_resume  NULL
+#endif
+
 struct platform_driver bfin_kpad_device_driver = {
-       .probe          = bfin_kpad_probe,
-       .remove         = __devexit_p(bfin_kpad_remove),
        .driver         = {
                .name   = DRV_NAME,
-       }
+               .owner  = THIS_MODULE,
+       },
+       .probe          = bfin_kpad_probe,
+       .remove         = __devexit_p(bfin_kpad_remove),
+       .suspend        = bfin_kpad_suspend,
+       .resume         = bfin_kpad_resume,
 };
 
 static int __init bfin_kpad_init(void)
@@ -378,3 +410,4 @@ module_exit(bfin_kpad_exit);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
 MODULE_DESCRIPTION("Keypad driver for BF54x Processors");
+MODULE_ALIAS("platform:bf54x-keys");