2 * mainstone-wm97xx.c -- Mainstone Continuous Touch screen driver for
3 * Wolfson WM97xx AC97 Codecs.
5 * Copyright 2004, 2007 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 * This is a wm97xx extended touch driver to capture touch
18 * data in a continuous manner on the Intel XScale archictecture
21 * - codecs supported:- WM9705, WM9712, WM9713
22 * - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/version.h>
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/delay.h>
32 #include <linux/irq.h>
33 #include <linux/interrupt.h>
34 #include <linux/wm97xx.h>
36 #include <mach/pxa-regs.h>
38 #define VERSION "0.13"
41 u16 id; /* codec id */
42 u8 code; /* continuous code */
43 u8 reads; /* number of coord reads per read cycle */
44 u32 speed; /* number of coords per second */
47 #define WM_READS(sp) ((sp / HZ) + 1)
49 static const struct continuous cinfo[] = {
50 {WM9705_ID2, 0, WM_READS(94), 94},
51 {WM9705_ID2, 1, WM_READS(188), 188},
52 {WM9705_ID2, 2, WM_READS(375), 375},
53 {WM9705_ID2, 3, WM_READS(750), 750},
54 {WM9712_ID2, 0, WM_READS(94), 94},
55 {WM9712_ID2, 1, WM_READS(188), 188},
56 {WM9712_ID2, 2, WM_READS(375), 375},
57 {WM9712_ID2, 3, WM_READS(750), 750},
58 {WM9713_ID2, 0, WM_READS(94), 94},
59 {WM9713_ID2, 1, WM_READS(120), 120},
60 {WM9713_ID2, 2, WM_READS(154), 154},
61 {WM9713_ID2, 3, WM_READS(188), 188},
64 /* continuous speed index */
66 static u16 last, tries;
69 * Pen sampling frequency (Hz) in continuous mode.
71 static int cont_rate = 200;
72 module_param(cont_rate, int, 0);
73 MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");
78 * This driver can either poll or use an interrupt to indicate a pen down
79 * event. If the irq request fails then it will fall back to polling mode.
82 module_param(pen_int, int, 0);
83 MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)");
88 * Set to 1 to read back pen down pressure
91 module_param(pressure, int, 0);
92 MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)");
95 * AC97 touch data slot.
97 * Touch screen readback data ac97 slot
99 static int ac97_touch_slot = 5;
100 module_param(ac97_touch_slot, int, 0);
101 MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number");
104 /* flush AC97 slot 5 FIFO on pxa machines */
106 static void wm97xx_acc_pen_up(struct wm97xx *wm)
108 schedule_timeout_uninterruptible(1);
110 while (MISR & (1 << 2))
114 static void wm97xx_acc_pen_up(struct wm97xx *wm)
117 schedule_timeout_uninterruptible(1);
126 static int wm97xx_acc_pen_down(struct wm97xx *wm)
128 u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;
131 /* When the AC97 queue has been drained we need to allow time
132 * to buffer up samples otherwise we end up spinning polling
133 * for samples. The controller can't have a suitably low
134 * threashold set to use the notifications it gives.
136 schedule_timeout_uninterruptible(1);
156 /* are samples valid */
157 if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X ||
158 (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y ||
159 (p & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_PRES)
162 /* coordinate is good */
164 input_report_abs(wm->input_dev, ABS_X, x & 0xfff);
165 input_report_abs(wm->input_dev, ABS_Y, y & 0xfff);
166 input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff);
167 input_sync(wm->input_dev);
169 } while (reads < cinfo[sp_idx].reads);
171 return RC_PENDOWN | RC_AGAIN;
174 static int wm97xx_acc_startup(struct wm97xx *wm)
178 /* check we have a codec */
179 if (wm->ac97 == NULL)
182 /* Go you big red fire engine */
183 for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) {
184 if (wm->id != cinfo[idx].id)
187 if (cont_rate <= cinfo[idx].speed)
190 wm->acc_rate = cinfo[sp_idx].code;
191 wm->acc_slot = ac97_touch_slot;
193 "mainstone accelerated touchscreen driver, %d samples/sec\n",
194 cinfo[sp_idx].speed);
196 /* codec specific irq config */
200 wm->pen_irq = IRQ_GPIO(4);
201 set_irq_type(IRQ_GPIO(4), IRQ_TYPE_EDGE_BOTH);
205 /* enable pen down interrupt */
206 /* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */
207 wm->pen_irq = MAINSTONE_AC97_IRQ;
208 wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,
209 WM97XX_GPIO_POL_HIGH,
212 wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT,
213 WM97XX_GPIO_POL_HIGH,
214 WM97XX_GPIO_NOTSTICKY,
219 "pen down irq not supported on this device\n");
228 static void wm97xx_acc_shutdown(struct wm97xx *wm)
230 /* codec specific deconfig */
232 switch (wm->id & 0xffff) {
238 /* disable interrupt */
245 static void wm97xx_irq_enable(struct wm97xx *wm, int enable)
248 enable_irq(wm->pen_irq);
250 disable_irq(wm->pen_irq);
253 static struct wm97xx_mach_ops mainstone_mach_ops = {
255 .acc_pen_up = wm97xx_acc_pen_up,
256 .acc_pen_down = wm97xx_acc_pen_down,
257 .acc_startup = wm97xx_acc_startup,
258 .acc_shutdown = wm97xx_acc_shutdown,
259 .irq_enable = wm97xx_irq_enable,
260 .irq_gpio = WM97XX_GPIO_2,
263 static int mainstone_wm97xx_probe(struct platform_device *pdev)
265 struct wm97xx *wm = platform_get_drvdata(pdev);
267 return wm97xx_register_mach_ops(wm, &mainstone_mach_ops);
270 static int mainstone_wm97xx_remove(struct platform_device *pdev)
272 struct wm97xx *wm = platform_get_drvdata(pdev);
274 wm97xx_unregister_mach_ops(wm);
278 static struct platform_driver mainstone_wm97xx_driver = {
279 .probe = mainstone_wm97xx_probe,
280 .remove = mainstone_wm97xx_remove,
282 .name = "wm97xx-touch",
286 static int __init mainstone_wm97xx_init(void)
288 return platform_driver_register(&mainstone_wm97xx_driver);
291 static void __exit mainstone_wm97xx_exit(void)
293 platform_driver_unregister(&mainstone_wm97xx_driver);
296 module_init(mainstone_wm97xx_init);
297 module_exit(mainstone_wm97xx_exit);
299 /* Module information */
300 MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
301 MODULE_DESCRIPTION("wm97xx continuous touch driver for mainstone");
302 MODULE_LICENSE("GPL");