1 From 05b2a361eedb5461e902c73ebc6e30f9916b3a8a Mon Sep 17 00:00:00 2001
2 From: Mark Brown <broonie@opensource.wolfsonmicro.com>
3 Date: Sat, 26 Jan 2008 21:14:19 +0300
4 Subject: [PATCH 33/64] Add chip driver for WM9713 touchscreen
6 Signed-off-by: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
7 Signed-off-by: Graeme Gregory <gg@opensource.wolfsonmicro.com>
8 Signed-off-by: Mike Arthur <mike.arthur@wolfsonmicro.com>
9 Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
10 Cc: Dmitry Baryshkov <dbaryshkov@gmail.com>
11 Cc: Stanley Cai <stanley.cai@intel.com>
12 Cc: Rodolfo Giometti <giometti@enneenne.com>
13 Cc: Russell King <rmk@arm.linux.org.uk>
14 Cc: Marc Kleine-Budde <mkl@pengutronix.de>
15 Cc: Ian Molton <spyro@f2s.com>
16 Cc: Vince Sanders <vince@kyllikki.org>
17 Cc: Andrew Zabolotny <zap@homelink.ru>
19 drivers/input/touchscreen/wm9713.c | 459 ++++++++++++++++++++++++++++++++++++
20 1 files changed, 459 insertions(+), 0 deletions(-)
21 create mode 100644 drivers/input/touchscreen/wm9713.c
23 diff --git a/drivers/input/touchscreen/wm9713.c b/drivers/input/touchscreen/wm9713.c
25 index 0000000..5067e59
27 +++ b/drivers/input/touchscreen/wm9713.c
30 + * wm9713.c -- Codec touch driver for Wolfson WM9713 AC97 Codec.
32 + * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
33 + * Author: Liam Girdwood
34 + * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
35 + * Parts Copyright : Ian Molton <spyro@f2s.com>
36 + * Andrew Zabolotny <zap@homelink.ru>
37 + * Russell King <rmk@arm.linux.org.uk>
39 + * This program is free software; you can redistribute it and/or modify it
40 + * under the terms of the GNU General Public License as published by the
41 + * Free Software Foundation; either version 2 of the License, or (at your
42 + * option) any later version.
46 +#include <linux/module.h>
47 +#include <linux/moduleparam.h>
48 +#include <linux/version.h>
49 +#include <linux/kernel.h>
50 +#include <linux/input.h>
51 +#include <linux/delay.h>
52 +#include <linux/bitops.h>
53 +#include <linux/wm97xx.h>
55 +#define TS_NAME "wm97xx"
56 +#define WM9713_VERSION "0.53"
57 +#define DEFAULT_PRESSURE 0xb0c0
64 + * Set internal pull up for pen detect.
66 + * Pull up is in the range 1.02k (least sensitive) to 64k (most sensitive)
67 + * i.e. pull up resistance = 64k Ohms / rpu.
69 + * Adjust this value if you are having problems with pen detect not
70 + * detecting any down event.
73 +module_param(rpu, int, 0);
74 +MODULE_PARM_DESC(rpu, "Set internal pull up resitor for pen detect.");
77 + * Set current used for pressure measurement.
79 + * Set pil = 2 to use 400uA
80 + * pil = 1 to use 200uA and
81 + * pil = 0 to disable pressure measurement.
83 + * This is used to increase the range of values returned by the adc
84 + * when measureing touchpanel pressure.
87 +module_param(pil, int, 0);
88 +MODULE_PARM_DESC(pil, "Set current used for pressure measurement.");
91 + * Set threshold for pressure measurement.
93 + * Pen down pressure below threshold is ignored.
95 +static int pressure = DEFAULT_PRESSURE & 0xfff;
96 +module_param(pressure, int, 0);
97 +MODULE_PARM_DESC(pressure, "Set threshold for pressure measurement.");
100 + * Set adc sample delay.
102 + * For accurate touchpanel measurements, some settling time may be
103 + * required between the switch matrix applying a voltage across the
104 + * touchpanel plate and the ADC sampling the signal.
106 + * This delay can be set by setting delay = n, where n is the array
107 + * position of the delay in the array delay_table below.
108 + * Long delays > 1ms are supported for completeness, but are not
111 +static int delay = 4;
112 +module_param(delay, int, 0);
113 +MODULE_PARM_DESC(delay, "Set adc sample delay.");
116 + * Set adc mask function.
118 + * Sources of glitch noise, such as signals driving an LCD display, may feed
119 + * through to the touch screen plates and affect measurement accuracy. In
120 + * order to minimise this, a signal may be applied to the MASK pin to delay or
121 + * synchronise the sampling.
123 + * 0 = No delay or sync
124 + * 1 = High on pin stops conversions
125 + * 2 = Edge triggered, edge on pin delays conversion by delay param (above)
126 + * 3 = Edge triggered, edge on pin starts conversion after delay param
129 +module_param(mask, int, 0);
130 +MODULE_PARM_DESC(mask, "Set adc mask function.");
133 + * Coordinate Polling Enable.
135 + * Set to 1 to enable coordinate polling. e.g. x,y[,p] is sampled together
139 +module_param(coord, int, 0);
140 +MODULE_PARM_DESC(coord, "Polling coordinate mode");
143 + * ADC sample delay times in uS
145 +static const int delay_table[] = {
146 + 21, /* 1 AC97 Link frames */
161 + 0 /* No delay, switch matrix always on */
165 + * Delay after issuing a POLL command.
167 + * The delay is 3 AC97 link frames + the touchpanel settling delay
169 +static inline void poll_delay(int d)
171 + udelay(3 * AC97_LINK_FRAME + delay_table[d]);
175 + * set up the physical settings of the WM9713
177 +static void wm9713_phy_init(struct wm97xx *wm)
179 + u16 dig1 = 0, dig2, dig3;
181 + /* default values */
182 + dig2 = WM97XX_DELAY(4) | WM97XX_SLT(5);
183 + dig3 = WM9712_RPU(1);
188 + dig3 |= WM9712_RPU(rpu);
189 + dev_info(wm->dev, "setting pen detect pull-up to %d Ohms\n",
193 + /* touchpanel pressure */
195 + dig3 |= WM9712_PIL;
197 + "setting pressure measurement current to 400uA.");
200 + "setting pressure measurement current to 200uA.");
204 + /* sample settling delay */
205 + if (delay < 0 || delay > 15) {
206 + dev_info(wm->dev, "supplied delay out of range.");
208 + dev_info(wm->dev, "setting adc sample delay to %d u Secs.",
209 + delay_table[delay]);
212 + dig2 |= WM97XX_DELAY(delay);
215 + dig3 |= ((mask & 0x3) << 4);
217 + dig3 |= WM9713_WAIT;
219 + wm->misc = wm97xx_reg_read(wm, 0x5a);
221 + wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1);
222 + wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2);
223 + wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3);
224 + wm97xx_reg_write(wm, AC97_GPIO_STICKY, 0x0);
227 +static void wm9713_dig_enable(struct wm97xx *wm, int enable)
232 + val = wm97xx_reg_read(wm, AC97_EXTENDED_MID);
233 + wm97xx_reg_write(wm, AC97_EXTENDED_MID, val & 0x7fff);
234 + wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] |
235 + WM97XX_PRP_DET_DIG);
236 + wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD); /* dummy read */
238 + wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2] &
239 + ~WM97XX_PRP_DET_DIG);
240 + val = wm97xx_reg_read(wm, AC97_EXTENDED_MID);
241 + wm97xx_reg_write(wm, AC97_EXTENDED_MID, val | 0x8000);
245 +static void wm9713_dig_restore(struct wm97xx *wm)
247 + wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig_save[0]);
248 + wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig_save[1]);
249 + wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig_save[2]);
252 +static void wm9713_aux_prepare(struct wm97xx *wm)
254 + memcpy(wm->dig_save, wm->dig, sizeof(wm->dig));
255 + wm97xx_reg_write(wm, AC97_WM9713_DIG1, 0);
256 + wm97xx_reg_write(wm, AC97_WM9713_DIG2, 0);
257 + wm97xx_reg_write(wm, AC97_WM9713_DIG3, WM97XX_PRP_DET_DIG);
260 +static inline int is_pden(struct wm97xx *wm)
262 + return wm->dig[2] & WM9713_PDEN;
266 + * Read a sample from the WM9713 adc in polling mode.
268 +static int wm9713_poll_sample(struct wm97xx *wm, int adcsel, int *sample)
271 + int timeout = 5 * delay;
273 + if (!wm->pen_probably_down) {
274 + u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
275 + if (!(data & WM97XX_PEN_DOWN))
277 + wm->pen_probably_down = 1;
280 + /* set up digitiser */
281 + if (adcsel & 0x8000)
282 + adcsel = 1 << ((adcsel & 0x7fff) + 3);
284 + dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1);
285 + dig1 &= ~WM9713_ADCSEL_MASK;
287 + if (wm->mach_ops && wm->mach_ops->pre_sample)
288 + wm->mach_ops->pre_sample(adcsel);
289 + wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1 | adcsel | WM9713_POLL);
291 + /* wait 3 AC97 time slots + delay for conversion */
294 + /* wait for POLL to go low */
295 + while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL) &&
297 + udelay(AC97_LINK_FRAME);
301 + if (timeout <= 0) {
302 + /* If PDEN is set, we can get a timeout when pen goes up */
304 + wm->pen_probably_down = 0;
306 + dev_dbg(wm->dev, "adc sample timeout");
310 + *sample = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
311 + if (wm->mach_ops && wm->mach_ops->post_sample)
312 + wm->mach_ops->post_sample(adcsel);
314 + /* check we have correct sample */
315 + if ((*sample & WM97XX_ADCSRC_MASK) != ffs(adcsel >> 1) << 12) {
316 + dev_dbg(wm->dev, "adc wrong sample, read %x got %x", adcsel,
317 + *sample & WM97XX_ADCSRC_MASK);
321 + if (!(*sample & WM97XX_PEN_DOWN)) {
322 + wm->pen_probably_down = 0;
330 + * Read a coordinate from the WM9713 adc in polling mode.
332 +static int wm9713_poll_coord(struct wm97xx *wm, struct wm97xx_data *data)
335 + int timeout = 5 * delay;
337 + if (!wm->pen_probably_down) {
338 + u16 data = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
339 + if (!(data & WM97XX_PEN_DOWN))
341 + wm->pen_probably_down = 1;
344 + /* set up digitiser */
345 + dig1 = wm97xx_reg_read(wm, AC97_WM9713_DIG1);
346 + dig1 &= ~WM9713_ADCSEL_MASK;
348 + dig1 |= WM97XX_ADCSEL_PRES;
350 + if (wm->mach_ops && wm->mach_ops->pre_sample)
351 + wm->mach_ops->pre_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
352 + wm97xx_reg_write(wm, AC97_WM9713_DIG1,
353 + dig1 | WM9713_POLL | WM9713_COO);
355 + /* wait 3 AC97 time slots + delay for conversion */
357 + data->x = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
358 + /* wait for POLL to go low */
359 + while ((wm97xx_reg_read(wm, AC97_WM9713_DIG1) & WM9713_POLL)
361 + udelay(AC97_LINK_FRAME);
365 + if (timeout <= 0) {
366 + /* If PDEN is set, we can get a timeout when pen goes up */
368 + wm->pen_probably_down = 0;
370 + dev_dbg(wm->dev, "adc sample timeout");
374 + /* read back data */
375 + data->y = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
377 + data->p = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD);
379 + data->p = DEFAULT_PRESSURE;
381 + if (wm->mach_ops && wm->mach_ops->post_sample)
382 + wm->mach_ops->post_sample(WM97XX_ADCSEL_X | WM97XX_ADCSEL_Y);
384 + /* check we have correct sample */
385 + if (!(data->x & WM97XX_ADCSEL_X) || !(data->y & WM97XX_ADCSEL_Y))
387 + if (pil && !(data->p & WM97XX_ADCSEL_PRES))
390 + if (!(data->x & WM97XX_PEN_DOWN)) {
391 + wm->pen_probably_down = 0;
400 + * Sample the WM9713 touchscreen in polling mode
402 +static int wm9713_poll_touch(struct wm97xx *wm, struct wm97xx_data *data)
407 + rc = wm9713_poll_coord(wm, data);
408 + if (rc != RC_VALID)
411 + rc = wm9713_poll_sample(wm, WM9713_ADCSEL_X, &data->x);
412 + if (rc != RC_VALID)
414 + rc = wm9713_poll_sample(wm, WM9713_ADCSEL_Y, &data->y);
415 + if (rc != RC_VALID)
418 + rc = wm9713_poll_sample(wm, WM9713_ADCSEL_PRES,
420 + if (rc != RC_VALID)
423 + data->p = DEFAULT_PRESSURE;
429 + * Enable WM9713 continuous mode, i.e. touch data is streamed across
432 +static int wm9713_acc_enable(struct wm97xx *wm, int enable)
434 + u16 dig1, dig2, dig3;
442 + /* continous mode */
443 + if (wm->mach_ops->acc_startup &&
444 + (ret = wm->mach_ops->acc_startup(wm)) < 0)
447 + dig1 &= ~WM9713_ADCSEL_MASK;
448 + dig1 |= WM9713_CTC | WM9713_COO | WM9713_ADCSEL_X |
451 + dig1 |= WM9713_ADCSEL_PRES;
452 + dig2 &= ~(WM97XX_DELAY_MASK | WM97XX_SLT_MASK |
453 + WM97XX_CM_RATE_MASK);
454 + dig2 |= WM97XX_SLEN | WM97XX_DELAY(delay) |
455 + WM97XX_SLT(wm->acc_slot) | WM97XX_RATE(wm->acc_rate);
456 + dig3 |= WM9713_PDEN;
458 + dig1 &= ~(WM9713_CTC | WM9713_COO);
459 + dig2 &= ~WM97XX_SLEN;
460 + dig3 &= ~WM9713_PDEN;
461 + if (wm->mach_ops->acc_shutdown)
462 + wm->mach_ops->acc_shutdown(wm);
465 + wm97xx_reg_write(wm, AC97_WM9713_DIG1, dig1);
466 + wm97xx_reg_write(wm, AC97_WM9713_DIG2, dig2);
467 + wm97xx_reg_write(wm, AC97_WM9713_DIG3, dig3);
471 +struct wm97xx_codec_drv wm9713_codec = {
474 + .poll_sample = wm9713_poll_sample,
475 + .poll_touch = wm9713_poll_touch,
476 + .acc_enable = wm9713_acc_enable,
477 + .phy_init = wm9713_phy_init,
478 + .dig_enable = wm9713_dig_enable,
479 + .dig_restore = wm9713_dig_restore,
480 + .aux_prepare = wm9713_aux_prepare,
482 +EXPORT_SYMBOL_GPL(wm9713_codec);
484 +/* Module information */
485 +MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
486 +MODULE_DESCRIPTION("WM9713 Touch Screen Driver");
487 +MODULE_LICENSE("GPL");