[PATCH 5/6] Driver for WM97xx touchscreens in streaming mode on Mainstone

2008-02-26 Thread Mark Brown
Signed-off-by: Liam Girdwood <[EMAIL PROTECTED]>
Signed-off-by: Graeme Gregory <[EMAIL PROTECTED]>
Signed-off-by: Mike Arthur <[EMAIL PROTECTED]>
Signed-off-by: Mark Brown <[EMAIL PROTECTED]>
Cc: Dmitry Baryshkov <[EMAIL PROTECTED]>
Cc: Stanley Cai <[EMAIL PROTECTED]>
Cc: Rodolfo Giometti <[EMAIL PROTECTED]>
Cc: Russell King <[EMAIL PROTECTED]>
Cc: Marc Kleine-Budde <[EMAIL PROTECTED]>
Cc: Pete MacKay <[EMAIL PROTECTED]>
Cc: Ian Molton <[EMAIL PROTECTED]>
Cc: Vince Sanders <[EMAIL PROTECTED]>
Cc: Andrew Zabolotny <[EMAIL PROTECTED]>
---
 drivers/input/touchscreen/mainstone-wm97xx.c |  298 ++
 1 files changed, 298 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/mainstone-wm97xx.c

diff --git a/drivers/input/touchscreen/mainstone-wm97xx.c 
b/drivers/input/touchscreen/mainstone-wm97xx.c
new file mode 100644
index 000..8e1c35d
--- /dev/null
+++ b/drivers/input/touchscreen/mainstone-wm97xx.c
@@ -0,0 +1,298 @@
+/*
+ * mainstone-wm97xx.c  --  Mainstone Continuous Touch screen driver for
+ * Wolfson WM97xx AC97 Codecs.
+ *
+ * Copyright 2004, 2007 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ * [EMAIL PROTECTED] or [EMAIL PROTECTED]
+ * Parts Copyright : Ian Molton <[EMAIL PROTECTED]>
+ *   Andrew Zabolotny <[EMAIL PROTECTED]>
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ * Notes:
+ * This is a wm97xx extended touch driver to capture touch
+ * data in a continuous manner on the Intel XScale archictecture
+ *
+ *  Features:
+ *   - codecs supported:- WM9705, WM9712, WM9713
+ *   - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define VERSION"0.13"
+
+struct continuous {
+   u16 id;/* codec id */
+   u8 code;   /* continuous code */
+   u8 reads;  /* number of coord reads per read cycle */
+   u32 speed; /* number of coords per second */
+};
+
+#define WM_READS(sp) ((sp / HZ) + 1)
+
+static const struct continuous cinfo[] = {
+   {WM9705_ID2, 0, WM_READS(94), 94},
+   {WM9705_ID2, 1, WM_READS(188), 188},
+   {WM9705_ID2, 2, WM_READS(375), 375},
+   {WM9705_ID2, 3, WM_READS(750), 750},
+   {WM9712_ID2, 0, WM_READS(94), 94},
+   {WM9712_ID2, 1, WM_READS(188), 188},
+   {WM9712_ID2, 2, WM_READS(375), 375},
+   {WM9712_ID2, 3, WM_READS(750), 750},
+   {WM9713_ID2, 0, WM_READS(94), 94},
+   {WM9713_ID2, 1, WM_READS(120), 120},
+   {WM9713_ID2, 2, WM_READS(154), 154},
+   {WM9713_ID2, 3, WM_READS(188), 188},
+};
+
+/* continuous speed index */
+static int sp_idx;
+static u16 last, tries;
+
+/*
+ * Pen sampling frequency (Hz) in continuous mode.
+ */
+static int cont_rate = 200;
+module_param(cont_rate, int, 0);
+MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");
+
+/*
+ * Pen down detection.
+ *
+ * This driver can either poll or use an interrupt to indicate a pen down
+ * event. If the irq request fails then it will fall back to polling mode.
+ */
+static int pen_int;
+module_param(pen_int, int, 0);
+MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)");
+
+/*
+ * Pressure readback.
+ *
+ * Set to 1 to read back pen down pressure
+ */
+static int pressure;
+module_param(pressure, int, 0);
+MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no 
pressure)");
+
+/*
+ * AC97 touch data slot.
+ *
+ * Touch screen readback data ac97 slot
+ */
+static int ac97_touch_slot = 5;
+module_param(ac97_touch_slot, int, 0);
+MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number");
+
+
+/* flush AC97 slot 5 FIFO on pxa machines */
+#ifdef CONFIG_PXA27x
+static void wm97xx_acc_pen_up(struct wm97xx *wm)
+{
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule_timeout(1);
+
+   while (MISR & (1 << 2))
+   MODR;
+}
+#else
+static void wm97xx_acc_pen_up(struct wm97xx *wm)
+{
+   int count = 16;
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule_timeout(1);
+
+   while (count < 16) {
+   MODR;
+   count--;
+   }
+}
+#endif
+
+static int wm97xx_acc_pen_down(struct wm97xx *wm)
+{
+   u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;
+   int reads = 0;
+
+   /* data is never immediately available after pen down irq */
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule_timeout(1);
+
+   if (tries > 5) {
+   tries = 0;
+   return RC_PENUP;
+   }
+
+   x = MODR;
+   if (x == last) {
+   tries++;
+   return RC_AGAIN;
+   }
+   last = x;

[PATCH 5/6] Driver for WM97xx touchscreens in streaming mode on Mainstone

2008-02-13 Thread Mark Brown
Signed-off-by: Liam Girdwood <[EMAIL PROTECTED]>
Signed-off-by: Graeme Gregory <[EMAIL PROTECTED]>
Signed-off-by: Mike Arthur <[EMAIL PROTECTED]>
Signed-off-by: Mark Brown <[EMAIL PROTECTED]>
Cc: Dmitry Baryshkov <[EMAIL PROTECTED]>
Cc: Stanley Cai <[EMAIL PROTECTED]>
Cc: Rodolfo Giometti <[EMAIL PROTECTED]>
Cc: Russell King <[EMAIL PROTECTED]>
Cc: Marc Kleine-Budde <[EMAIL PROTECTED]>
Cc: Pete MacKay <[EMAIL PROTECTED]>
Cc: Ian Molton <[EMAIL PROTECTED]>
Cc: Vince Sanders <[EMAIL PROTECTED]>
Cc: Andrew Zabolotny <[EMAIL PROTECTED]>
---
 drivers/input/touchscreen/mainstone-wm97xx.c |  298 ++
 1 files changed, 298 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/mainstone-wm97xx.c

diff --git a/drivers/input/touchscreen/mainstone-wm97xx.c 
b/drivers/input/touchscreen/mainstone-wm97xx.c
new file mode 100644
index 000..8e1c35d
--- /dev/null
+++ b/drivers/input/touchscreen/mainstone-wm97xx.c
@@ -0,0 +1,298 @@
+/*
+ * mainstone-wm97xx.c  --  Mainstone Continuous Touch screen driver for
+ * Wolfson WM97xx AC97 Codecs.
+ *
+ * Copyright 2004, 2007 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ * [EMAIL PROTECTED] or [EMAIL PROTECTED]
+ * Parts Copyright : Ian Molton <[EMAIL PROTECTED]>
+ *   Andrew Zabolotny <[EMAIL PROTECTED]>
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ * Notes:
+ * This is a wm97xx extended touch driver to capture touch
+ * data in a continuous manner on the Intel XScale archictecture
+ *
+ *  Features:
+ *   - codecs supported:- WM9705, WM9712, WM9713
+ *   - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define VERSION"0.13"
+
+struct continuous {
+   u16 id;/* codec id */
+   u8 code;   /* continuous code */
+   u8 reads;  /* number of coord reads per read cycle */
+   u32 speed; /* number of coords per second */
+};
+
+#define WM_READS(sp) ((sp / HZ) + 1)
+
+static const struct continuous cinfo[] = {
+   {WM9705_ID2, 0, WM_READS(94), 94},
+   {WM9705_ID2, 1, WM_READS(188), 188},
+   {WM9705_ID2, 2, WM_READS(375), 375},
+   {WM9705_ID2, 3, WM_READS(750), 750},
+   {WM9712_ID2, 0, WM_READS(94), 94},
+   {WM9712_ID2, 1, WM_READS(188), 188},
+   {WM9712_ID2, 2, WM_READS(375), 375},
+   {WM9712_ID2, 3, WM_READS(750), 750},
+   {WM9713_ID2, 0, WM_READS(94), 94},
+   {WM9713_ID2, 1, WM_READS(120), 120},
+   {WM9713_ID2, 2, WM_READS(154), 154},
+   {WM9713_ID2, 3, WM_READS(188), 188},
+};
+
+/* continuous speed index */
+static int sp_idx;
+static u16 last, tries;
+
+/*
+ * Pen sampling frequency (Hz) in continuous mode.
+ */
+static int cont_rate = 200;
+module_param(cont_rate, int, 0);
+MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");
+
+/*
+ * Pen down detection.
+ *
+ * This driver can either poll or use an interrupt to indicate a pen down
+ * event. If the irq request fails then it will fall back to polling mode.
+ */
+static int pen_int;
+module_param(pen_int, int, 0);
+MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)");
+
+/*
+ * Pressure readback.
+ *
+ * Set to 1 to read back pen down pressure
+ */
+static int pressure;
+module_param(pressure, int, 0);
+MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no 
pressure)");
+
+/*
+ * AC97 touch data slot.
+ *
+ * Touch screen readback data ac97 slot
+ */
+static int ac97_touch_slot = 5;
+module_param(ac97_touch_slot, int, 0);
+MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number");
+
+
+/* flush AC97 slot 5 FIFO on pxa machines */
+#ifdef CONFIG_PXA27x
+static void wm97xx_acc_pen_up(struct wm97xx *wm)
+{
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule_timeout(1);
+
+   while (MISR & (1 << 2))
+   MODR;
+}
+#else
+static void wm97xx_acc_pen_up(struct wm97xx *wm)
+{
+   int count = 16;
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule_timeout(1);
+
+   while (count < 16) {
+   MODR;
+   count--;
+   }
+}
+#endif
+
+static int wm97xx_acc_pen_down(struct wm97xx *wm)
+{
+   u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;
+   int reads = 0;
+
+   /* data is never immediately available after pen down irq */
+   set_current_state(TASK_INTERRUPTIBLE);
+   schedule_timeout(1);
+
+   if (tries > 5) {
+   tries = 0;
+   return RC_PENUP;
+   }
+
+   x = MODR;
+   if (x == last) {
+   tries++;
+   return RC_AGAIN;
+   }
+   last = x;