Merge branch 'msm-video' of git://codeaurora.org/quic/kernel/dwalker/linux-msm
[safe/jmp/linux-2.6] / drivers / input / touchscreen / mainstone-wm97xx.c
index 590a137..b6b8b1c 100644 (file)
@@ -3,8 +3,7 @@
  *                         Wolfson WM97xx AC97 Codecs.
  *
  * Copyright 2004, 2007 Wolfson Microelectronics PLC.
- * Author: Liam Girdwood
- *         liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
+ * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  * Parts Copyright : Ian Molton <spyro@f2s.com>
  *                   Andrew Zabolotny <zap@homelink.ru>
  *
@@ -15,7 +14,7 @@
  *
  * Notes:
  *     This is a wm97xx extended touch driver to capture touch
- *     data in a continuous manner on the Intel XScale archictecture
+ *     data in a continuous manner on the Intel XScale architecture
  *
  *  Features:
  *       - codecs supported:- WM9705, WM9712, WM9713
@@ -25,7 +24,6 @@
 
 #include <linux/module.h>
 #include <linux/moduleparam.h>
-#include <linux/version.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/wm97xx.h>
 #include <linux/io.h>
-#include <asm/arch/pxa-regs.h>
+#include <linux/gpio.h>
 
-#define VERSION                "0.13"
+#include <mach/regs-ac97.h>
+
+#include <asm/mach-types.h>
 
 struct continuous {
        u16 id;    /* codec id */
@@ -64,6 +64,7 @@ static const struct continuous cinfo[] = {
 /* continuous speed index */
 static int sp_idx;
 static u16 last, tries;
+static int irq;
 
 /*
  * Pen sampling frequency (Hz) in continuous mode.
@@ -113,13 +114,12 @@ static void wm97xx_acc_pen_up(struct wm97xx *wm)
 #else
 static void wm97xx_acc_pen_up(struct wm97xx *wm)
 {
-       int count = 16;
+       unsigned int count;
+
        schedule_timeout_uninterruptible(1);
 
-       while (count < 16) {
+       for (count = 0; count < 16; count++)
                MODR;
-               count--;
-       }
 }
 #endif
 
@@ -131,7 +131,7 @@ static int wm97xx_acc_pen_down(struct wm97xx *wm)
        /* When the AC97 queue has been drained we need to allow time
         * to buffer up samples otherwise we end up spinning polling
         * for samples.  The controller can't have a suitably low
-        * threashold set to use the notifications it gives.
+        * threshold set to use the notifications it gives.
         */
        schedule_timeout_uninterruptible(1);
 
@@ -153,6 +153,9 @@ static int wm97xx_acc_pen_down(struct wm97xx *wm)
                if (pressure)
                        p = MODR;
 
+               dev_dbg(wm->dev, "Raw coordinates: x=%x, y=%x, p=%x\n",
+                       x, y, p);
+
                /* are samples valid */
                if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X ||
                    (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y ||
@@ -164,6 +167,7 @@ static int wm97xx_acc_pen_down(struct wm97xx *wm)
                input_report_abs(wm->input_dev, ABS_X, x & 0xfff);
                input_report_abs(wm->input_dev, ABS_Y, y & 0xfff);
                input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff);
+               input_report_key(wm->input_dev, BTN_TOUCH, (p != 0));
                input_sync(wm->input_dev);
                reads++;
        } while (reads < cinfo[sp_idx].reads);
@@ -173,7 +177,7 @@ up:
 
 static int wm97xx_acc_startup(struct wm97xx *wm)
 {
-       int idx = 0;
+       int idx = 0, ret = 0;
 
        /* check we have a codec */
        if (wm->ac97 == NULL)
@@ -193,18 +197,40 @@ static int wm97xx_acc_startup(struct wm97xx *wm)
                 "mainstone accelerated touchscreen driver, %d samples/sec\n",
                 cinfo[sp_idx].speed);
 
+       /* IRQ driven touchscreen is used on Palm hardware */
+       if (machine_is_palmt5() || machine_is_palmtx() || machine_is_palmld()) {
+               pen_int = 1;
+               irq = 27;
+               /* There is some obscure mutant of WM9712 interbred with WM9713
+                * used on Palm HW */
+               wm->variant = WM97xx_WM1613;
+       } else if (machine_is_mainstone() && pen_int)
+               irq = 4;
+
+       if (irq) {
+               ret = gpio_request(irq, "Touchscreen IRQ");
+               if (ret)
+                       goto out;
+
+               ret = gpio_direction_input(irq);
+               if (ret) {
+                       gpio_free(irq);
+                       goto out;
+               }
+
+               wm->pen_irq = gpio_to_irq(irq);
+               set_irq_type(wm->pen_irq, IRQ_TYPE_EDGE_BOTH);
+       } else /* pen irq not supported */
+               pen_int = 0;
+
        /* codec specific irq config */
        if (pen_int) {
                switch (wm->id) {
                case WM9705_ID2:
-                       wm->pen_irq = IRQ_GPIO(4);
-                       set_irq_type(IRQ_GPIO(4), IRQ_TYPE_EDGE_BOTH);
                        break;
                case WM9712_ID2:
                case WM9713_ID2:
-                       /* enable pen down interrupt */
                        /* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */
-                       wm->pen_irq = MAINSTONE_AC97_IRQ;
                        wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,
                                           WM97XX_GPIO_POL_HIGH,
                                           WM97XX_GPIO_STICKY,
@@ -222,23 +248,17 @@ static int wm97xx_acc_startup(struct wm97xx *wm)
                }
        }
 
-       return 0;
+out:
+       return ret;
 }
 
 static void wm97xx_acc_shutdown(struct wm97xx *wm)
 {
        /* codec specific deconfig */
        if (pen_int) {
-               switch (wm->id & 0xffff) {
-               case WM9705_ID2:
-                       wm->pen_irq = 0;
-                       break;
-               case WM9712_ID2:
-               case WM9713_ID2:
-                       /* disable interrupt */
-                       wm->pen_irq = 0;
-                       break;
-               }
+               if (irq)
+                       gpio_free(irq);
+               wm->pen_irq = 0;
        }
 }
 
@@ -247,7 +267,7 @@ static void wm97xx_irq_enable(struct wm97xx *wm, int enable)
        if (enable)
                enable_irq(wm->pen_irq);
        else
-               disable_irq(wm->pen_irq);
+               disable_irq_nosync(wm->pen_irq);
 }
 
 static struct wm97xx_mach_ops mainstone_mach_ops = {
@@ -297,6 +317,6 @@ module_init(mainstone_wm97xx_init);
 module_exit(mainstone_wm97xx_exit);
 
 /* Module information */
-MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
+MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
 MODULE_DESCRIPTION("wm97xx continuous touch driver for mainstone");
 MODULE_LICENSE("GPL");