diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-04-08 03:00:33 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-04-08 03:00:33 -0400 |
commit | ba28f22e7cf16cb310bb491cbb3f7d0d5d1f5c5d (patch) | |
tree | 6d58e91731385281436da191e82c56cd1627482f /drivers/input/touchscreen | |
parent | 577c9c456f0e1371cbade38eaf91ae8e8a308555 (diff) | |
parent | 59cc1dd97ca9ac0363ef2f770901fbd86e2b970a (diff) |
Merge branch 'next' into for-linus
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 58 | ||||
-rw-r--r-- | drivers/input/touchscreen/Makefile | 3 | ||||
-rw-r--r-- | drivers/input/touchscreen/ad7877.c | 844 | ||||
-rw-r--r-- | drivers/input/touchscreen/ad7879.c | 782 | ||||
-rw-r--r-- | drivers/input/touchscreen/mainstone-wm97xx.c | 3 | ||||
-rw-r--r-- | drivers/input/touchscreen/ucb1400_ts.c | 5 | ||||
-rw-r--r-- | drivers/input/touchscreen/wm97xx-core.c | 13 | ||||
-rw-r--r-- | drivers/input/touchscreen/zylonite-wm97xx.c | 240 |
8 files changed, 1942 insertions, 6 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index bb6486a8c070..b01fd61dadcc 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -29,6 +29,51 @@ config TOUCHSCREEN_ADS7846 | |||
29 | To compile this driver as a module, choose M here: the | 29 | To compile this driver as a module, choose M here: the |
30 | module will be called ads7846. | 30 | module will be called ads7846. |
31 | 31 | ||
32 | config TOUCHSCREEN_AD7877 | ||
33 | tristate "AD7877 based touchscreens" | ||
34 | depends on SPI_MASTER | ||
35 | help | ||
36 | Say Y here if you have a touchscreen interface using the | ||
37 | AD7877 controller, and your board-specific initialization | ||
38 | code includes that in its table of SPI devices. | ||
39 | |||
40 | If unsure, say N (but it's safe to say "Y"). | ||
41 | |||
42 | To compile this driver as a module, choose M here: the | ||
43 | module will be called ad7877. | ||
44 | |||
45 | config TOUCHSCREEN_AD7879_I2C | ||
46 | tristate "AD7879 based touchscreens: AD7879-1 I2C Interface" | ||
47 | depends on I2C | ||
48 | select TOUCHSCREEN_AD7879 | ||
49 | help | ||
50 | Say Y here if you have a touchscreen interface using the | ||
51 | AD7879-1 controller, and your board-specific initialization | ||
52 | code includes that in its table of I2C devices. | ||
53 | |||
54 | If unsure, say N (but it's safe to say "Y"). | ||
55 | |||
56 | To compile this driver as a module, choose M here: the | ||
57 | module will be called ad7879. | ||
58 | |||
59 | config TOUCHSCREEN_AD7879_SPI | ||
60 | tristate "AD7879 based touchscreens: AD7879 SPI Interface" | ||
61 | depends on SPI_MASTER && TOUCHSCREEN_AD7879_I2C = n | ||
62 | select TOUCHSCREEN_AD7879 | ||
63 | help | ||
64 | Say Y here if you have a touchscreen interface using the | ||
65 | AD7879 controller, and your board-specific initialization | ||
66 | code includes that in its table of SPI devices. | ||
67 | |||
68 | If unsure, say N (but it's safe to say "Y"). | ||
69 | |||
70 | To compile this driver as a module, choose M here: the | ||
71 | module will be called ad7879. | ||
72 | |||
73 | config TOUCHSCREEN_AD7879 | ||
74 | tristate | ||
75 | default n | ||
76 | |||
32 | config TOUCHSCREEN_BITSY | 77 | config TOUCHSCREEN_BITSY |
33 | tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" | 78 | tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" |
34 | depends on SA1100_BITSY | 79 | depends on SA1100_BITSY |
@@ -308,6 +353,19 @@ config TOUCHSCREEN_WM97XX_MAINSTONE | |||
308 | To compile this driver as a module, choose M here: the | 353 | To compile this driver as a module, choose M here: the |
309 | module will be called mainstone-wm97xx. | 354 | module will be called mainstone-wm97xx. |
310 | 355 | ||
356 | config TOUCHSCREEN_WM97XX_ZYLONITE | ||
357 | tristate "Zylonite accelerated touch" | ||
358 | depends on TOUCHSCREEN_WM97XX && MACH_ZYLONITE | ||
359 | select TOUCHSCREEN_WM9713 | ||
360 | help | ||
361 | Say Y here for support for streaming mode with the touchscreen | ||
362 | on Zylonite systems. | ||
363 | |||
364 | If unsure, say N. | ||
365 | |||
366 | To compile this driver as a module, choose M here: the | ||
367 | module will be called zylonite-wm97xx. | ||
368 | |||
311 | config TOUCHSCREEN_USB_COMPOSITE | 369 | config TOUCHSCREEN_USB_COMPOSITE |
312 | tristate "USB Touchscreen Driver" | 370 | tristate "USB Touchscreen Driver" |
313 | depends on USB_ARCH_HAS_HCD | 371 | depends on USB_ARCH_HAS_HCD |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index d3375aff46fe..6700f7b9d165 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -6,6 +6,8 @@ | |||
6 | 6 | ||
7 | wm97xx-ts-y := wm97xx-core.o | 7 | wm97xx-ts-y := wm97xx-core.o |
8 | 8 | ||
9 | obj-$(CONFIG_TOUCHSCREEN_AD7877) += ad7877.o | ||
10 | obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o | ||
9 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o | 11 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o |
10 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o | 12 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o |
11 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o | 13 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o |
@@ -34,3 +36,4 @@ wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o | |||
34 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o | 36 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o |
35 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9713) += wm9713.o | 37 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9713) += wm9713.o |
36 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o | 38 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o |
39 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o | ||
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c new file mode 100644 index 000000000000..e4728a28f492 --- /dev/null +++ b/drivers/input/touchscreen/ad7877.c | |||
@@ -0,0 +1,844 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2006-2008 Michael Hennerich, Analog Devices Inc. | ||
3 | * | ||
4 | * Description: AD7877 based touchscreen, sensor (ADCs), DAC and GPIO driver | ||
5 | * Based on: ads7846.c | ||
6 | * | ||
7 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, see the file COPYING, or write | ||
21 | * to the Free Software Foundation, Inc., | ||
22 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
23 | * | ||
24 | * History: | ||
25 | * Copyright (c) 2005 David Brownell | ||
26 | * Copyright (c) 2006 Nokia Corporation | ||
27 | * Various changes: Imre Deak <imre.deak@nokia.com> | ||
28 | * | ||
29 | * Using code from: | ||
30 | * - corgi_ts.c | ||
31 | * Copyright (C) 2004-2005 Richard Purdie | ||
32 | * - omap_ts.[hc], ads7846.h, ts_osk.c | ||
33 | * Copyright (C) 2002 MontaVista Software | ||
34 | * Copyright (C) 2004 Texas Instruments | ||
35 | * Copyright (C) 2005 Dirk Behme | ||
36 | */ | ||
37 | |||
38 | |||
39 | #include <linux/device.h> | ||
40 | #include <linux/init.h> | ||
41 | #include <linux/delay.h> | ||
42 | #include <linux/input.h> | ||
43 | #include <linux/interrupt.h> | ||
44 | #include <linux/slab.h> | ||
45 | #include <linux/spi/spi.h> | ||
46 | #include <linux/spi/ad7877.h> | ||
47 | #include <asm/irq.h> | ||
48 | |||
49 | #define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50) | ||
50 | |||
51 | #define MAX_SPI_FREQ_HZ 20000000 | ||
52 | #define MAX_12BIT ((1<<12)-1) | ||
53 | |||
54 | #define AD7877_REG_ZEROS 0 | ||
55 | #define AD7877_REG_CTRL1 1 | ||
56 | #define AD7877_REG_CTRL2 2 | ||
57 | #define AD7877_REG_ALERT 3 | ||
58 | #define AD7877_REG_AUX1HIGH 4 | ||
59 | #define AD7877_REG_AUX1LOW 5 | ||
60 | #define AD7877_REG_BAT1HIGH 6 | ||
61 | #define AD7877_REG_BAT1LOW 7 | ||
62 | #define AD7877_REG_BAT2HIGH 8 | ||
63 | #define AD7877_REG_BAT2LOW 9 | ||
64 | #define AD7877_REG_TEMP1HIGH 10 | ||
65 | #define AD7877_REG_TEMP1LOW 11 | ||
66 | #define AD7877_REG_SEQ0 12 | ||
67 | #define AD7877_REG_SEQ1 13 | ||
68 | #define AD7877_REG_DAC 14 | ||
69 | #define AD7877_REG_NONE1 15 | ||
70 | #define AD7877_REG_EXTWRITE 15 | ||
71 | #define AD7877_REG_XPLUS 16 | ||
72 | #define AD7877_REG_YPLUS 17 | ||
73 | #define AD7877_REG_Z2 18 | ||
74 | #define AD7877_REG_aux1 19 | ||
75 | #define AD7877_REG_aux2 20 | ||
76 | #define AD7877_REG_aux3 21 | ||
77 | #define AD7877_REG_bat1 22 | ||
78 | #define AD7877_REG_bat2 23 | ||
79 | #define AD7877_REG_temp1 24 | ||
80 | #define AD7877_REG_temp2 25 | ||
81 | #define AD7877_REG_Z1 26 | ||
82 | #define AD7877_REG_GPIOCTRL1 27 | ||
83 | #define AD7877_REG_GPIOCTRL2 28 | ||
84 | #define AD7877_REG_GPIODATA 29 | ||
85 | #define AD7877_REG_NONE2 30 | ||
86 | #define AD7877_REG_NONE3 31 | ||
87 | |||
88 | #define AD7877_SEQ_YPLUS_BIT (1<<11) | ||
89 | #define AD7877_SEQ_XPLUS_BIT (1<<10) | ||
90 | #define AD7877_SEQ_Z2_BIT (1<<9) | ||
91 | #define AD7877_SEQ_AUX1_BIT (1<<8) | ||
92 | #define AD7877_SEQ_AUX2_BIT (1<<7) | ||
93 | #define AD7877_SEQ_AUX3_BIT (1<<6) | ||
94 | #define AD7877_SEQ_BAT1_BIT (1<<5) | ||
95 | #define AD7877_SEQ_BAT2_BIT (1<<4) | ||
96 | #define AD7877_SEQ_TEMP1_BIT (1<<3) | ||
97 | #define AD7877_SEQ_TEMP2_BIT (1<<2) | ||
98 | #define AD7877_SEQ_Z1_BIT (1<<1) | ||
99 | |||
100 | enum { | ||
101 | AD7877_SEQ_YPOS = 0, | ||
102 | AD7877_SEQ_XPOS = 1, | ||
103 | AD7877_SEQ_Z2 = 2, | ||
104 | AD7877_SEQ_AUX1 = 3, | ||
105 | AD7877_SEQ_AUX2 = 4, | ||
106 | AD7877_SEQ_AUX3 = 5, | ||
107 | AD7877_SEQ_BAT1 = 6, | ||
108 | AD7877_SEQ_BAT2 = 7, | ||
109 | AD7877_SEQ_TEMP1 = 8, | ||
110 | AD7877_SEQ_TEMP2 = 9, | ||
111 | AD7877_SEQ_Z1 = 10, | ||
112 | AD7877_NR_SENSE = 11, | ||
113 | }; | ||
114 | |||
115 | /* DAC Register Default RANGE 0 to Vcc, Volatge Mode, DAC On */ | ||
116 | #define AD7877_DAC_CONF 0x1 | ||
117 | |||
118 | /* If gpio3 is set AUX3/GPIO3 acts as GPIO Output */ | ||
119 | #define AD7877_EXTW_GPIO_3_CONF 0x1C4 | ||
120 | #define AD7877_EXTW_GPIO_DATA 0x200 | ||
121 | |||
122 | /* Control REG 2 */ | ||
123 | #define AD7877_TMR(x) ((x & 0x3) << 0) | ||
124 | #define AD7877_REF(x) ((x & 0x1) << 2) | ||
125 | #define AD7877_POL(x) ((x & 0x1) << 3) | ||
126 | #define AD7877_FCD(x) ((x & 0x3) << 4) | ||
127 | #define AD7877_PM(x) ((x & 0x3) << 6) | ||
128 | #define AD7877_ACQ(x) ((x & 0x3) << 8) | ||
129 | #define AD7877_AVG(x) ((x & 0x3) << 10) | ||
130 | |||
131 | /* Control REG 1 */ | ||
132 | #define AD7877_SER (1 << 11) /* non-differential */ | ||
133 | #define AD7877_DFR (0 << 11) /* differential */ | ||
134 | |||
135 | #define AD7877_MODE_NOC (0) /* Do not convert */ | ||
136 | #define AD7877_MODE_SCC (1) /* Single channel conversion */ | ||
137 | #define AD7877_MODE_SEQ0 (2) /* Sequence 0 in Slave Mode */ | ||
138 | #define AD7877_MODE_SEQ1 (3) /* Sequence 1 in Master Mode */ | ||
139 | |||
140 | #define AD7877_CHANADD(x) ((x&0xF)<<7) | ||
141 | #define AD7877_READADD(x) ((x)<<2) | ||
142 | #define AD7877_WRITEADD(x) ((x)<<12) | ||
143 | |||
144 | #define AD7877_READ_CHAN(x) (AD7877_WRITEADD(AD7877_REG_CTRL1) | AD7877_SER | \ | ||
145 | AD7877_MODE_SCC | AD7877_CHANADD(AD7877_REG_ ## x) | \ | ||
146 | AD7877_READADD(AD7877_REG_ ## x)) | ||
147 | |||
148 | #define AD7877_MM_SEQUENCE (AD7877_SEQ_YPLUS_BIT | AD7877_SEQ_XPLUS_BIT | \ | ||
149 | AD7877_SEQ_Z2_BIT | AD7877_SEQ_Z1_BIT) | ||
150 | |||
151 | /* | ||
152 | * Non-touchscreen sensors only use single-ended conversions. | ||
153 | */ | ||
154 | |||
155 | struct ser_req { | ||
156 | u16 reset; | ||
157 | u16 ref_on; | ||
158 | u16 command; | ||
159 | u16 sample; | ||
160 | struct spi_message msg; | ||
161 | struct spi_transfer xfer[6]; | ||
162 | }; | ||
163 | |||
164 | struct ad7877 { | ||
165 | struct input_dev *input; | ||
166 | char phys[32]; | ||
167 | |||
168 | struct spi_device *spi; | ||
169 | u16 model; | ||
170 | u16 vref_delay_usecs; | ||
171 | u16 x_plate_ohms; | ||
172 | u16 pressure_max; | ||
173 | |||
174 | u16 cmd_crtl1; | ||
175 | u16 cmd_crtl2; | ||
176 | u16 cmd_dummy; | ||
177 | u16 dac; | ||
178 | |||
179 | u8 stopacq_polarity; | ||
180 | u8 first_conversion_delay; | ||
181 | u8 acquisition_time; | ||
182 | u8 averaging; | ||
183 | u8 pen_down_acc_interval; | ||
184 | |||
185 | u16 conversion_data[AD7877_NR_SENSE]; | ||
186 | |||
187 | struct spi_transfer xfer[AD7877_NR_SENSE + 2]; | ||
188 | struct spi_message msg; | ||
189 | |||
190 | struct mutex mutex; | ||
191 | unsigned disabled:1; /* P: mutex */ | ||
192 | unsigned gpio3:1; /* P: mutex */ | ||
193 | unsigned gpio4:1; /* P: mutex */ | ||
194 | |||
195 | spinlock_t lock; | ||
196 | struct timer_list timer; /* P: lock */ | ||
197 | unsigned pending:1; /* P: lock */ | ||
198 | }; | ||
199 | |||
200 | static int gpio3; | ||
201 | module_param(gpio3, int, 0); | ||
202 | MODULE_PARM_DESC(gpio3, "If gpio3 is set to 1 AUX3 acts as GPIO3"); | ||
203 | |||
204 | /* | ||
205 | * ad7877_read/write are only used for initial setup and for sysfs controls. | ||
206 | * The main traffic is done using spi_async() in the interrupt handler. | ||
207 | */ | ||
208 | |||
209 | static int ad7877_read(struct spi_device *spi, u16 reg) | ||
210 | { | ||
211 | struct ser_req *req; | ||
212 | int status, ret; | ||
213 | |||
214 | req = kzalloc(sizeof *req, GFP_KERNEL); | ||
215 | if (!req) | ||
216 | return -ENOMEM; | ||
217 | |||
218 | spi_message_init(&req->msg); | ||
219 | |||
220 | req->command = (u16) (AD7877_WRITEADD(AD7877_REG_CTRL1) | | ||
221 | AD7877_READADD(reg)); | ||
222 | req->xfer[0].tx_buf = &req->command; | ||
223 | req->xfer[0].len = 2; | ||
224 | |||
225 | req->xfer[1].rx_buf = &req->sample; | ||
226 | req->xfer[1].len = 2; | ||
227 | |||
228 | spi_message_add_tail(&req->xfer[0], &req->msg); | ||
229 | spi_message_add_tail(&req->xfer[1], &req->msg); | ||
230 | |||
231 | status = spi_sync(spi, &req->msg); | ||
232 | ret = status ? : req->sample; | ||
233 | |||
234 | kfree(req); | ||
235 | |||
236 | return ret; | ||
237 | } | ||
238 | |||
239 | static int ad7877_write(struct spi_device *spi, u16 reg, u16 val) | ||
240 | { | ||
241 | struct ser_req *req; | ||
242 | int status; | ||
243 | |||
244 | req = kzalloc(sizeof *req, GFP_KERNEL); | ||
245 | if (!req) | ||
246 | return -ENOMEM; | ||
247 | |||
248 | spi_message_init(&req->msg); | ||
249 | |||
250 | req->command = (u16) (AD7877_WRITEADD(reg) | (val & MAX_12BIT)); | ||
251 | req->xfer[0].tx_buf = &req->command; | ||
252 | req->xfer[0].len = 2; | ||
253 | |||
254 | spi_message_add_tail(&req->xfer[0], &req->msg); | ||
255 | |||
256 | status = spi_sync(spi, &req->msg); | ||
257 | |||
258 | kfree(req); | ||
259 | |||
260 | return status; | ||
261 | } | ||
262 | |||
263 | static int ad7877_read_adc(struct spi_device *spi, unsigned command) | ||
264 | { | ||
265 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | ||
266 | struct ser_req *req; | ||
267 | int status; | ||
268 | int sample; | ||
269 | int i; | ||
270 | |||
271 | req = kzalloc(sizeof *req, GFP_KERNEL); | ||
272 | if (!req) | ||
273 | return -ENOMEM; | ||
274 | |||
275 | spi_message_init(&req->msg); | ||
276 | |||
277 | /* activate reference, so it has time to settle; */ | ||
278 | req->ref_on = AD7877_WRITEADD(AD7877_REG_CTRL2) | | ||
279 | AD7877_POL(ts->stopacq_polarity) | | ||
280 | AD7877_AVG(0) | AD7877_PM(2) | AD7877_TMR(0) | | ||
281 | AD7877_ACQ(ts->acquisition_time) | AD7877_FCD(0); | ||
282 | |||
283 | req->reset = AD7877_WRITEADD(AD7877_REG_CTRL1) | AD7877_MODE_NOC; | ||
284 | |||
285 | req->command = (u16) command; | ||
286 | |||
287 | req->xfer[0].tx_buf = &req->reset; | ||
288 | req->xfer[0].len = 2; | ||
289 | |||
290 | req->xfer[1].tx_buf = &req->ref_on; | ||
291 | req->xfer[1].len = 2; | ||
292 | req->xfer[1].delay_usecs = ts->vref_delay_usecs; | ||
293 | |||
294 | req->xfer[2].tx_buf = &req->command; | ||
295 | req->xfer[2].len = 2; | ||
296 | req->xfer[2].delay_usecs = ts->vref_delay_usecs; | ||
297 | |||
298 | req->xfer[3].rx_buf = &req->sample; | ||
299 | req->xfer[3].len = 2; | ||
300 | |||
301 | req->xfer[4].tx_buf = &ts->cmd_crtl2; /*REF OFF*/ | ||
302 | req->xfer[4].len = 2; | ||
303 | |||
304 | req->xfer[5].tx_buf = &ts->cmd_crtl1; /*DEFAULT*/ | ||
305 | req->xfer[5].len = 2; | ||
306 | |||
307 | /* group all the transfers together, so we can't interfere with | ||
308 | * reading touchscreen state; disable penirq while sampling | ||
309 | */ | ||
310 | for (i = 0; i < 6; i++) | ||
311 | spi_message_add_tail(&req->xfer[i], &req->msg); | ||
312 | |||
313 | status = spi_sync(spi, &req->msg); | ||
314 | sample = req->sample; | ||
315 | |||
316 | kfree(req); | ||
317 | |||
318 | return status ? : sample; | ||
319 | } | ||
320 | |||
321 | static void ad7877_rx(struct ad7877 *ts) | ||
322 | { | ||
323 | struct input_dev *input_dev = ts->input; | ||
324 | unsigned Rt; | ||
325 | u16 x, y, z1, z2; | ||
326 | |||
327 | x = ts->conversion_data[AD7877_SEQ_XPOS] & MAX_12BIT; | ||
328 | y = ts->conversion_data[AD7877_SEQ_YPOS] & MAX_12BIT; | ||
329 | z1 = ts->conversion_data[AD7877_SEQ_Z1] & MAX_12BIT; | ||
330 | z2 = ts->conversion_data[AD7877_SEQ_Z2] & MAX_12BIT; | ||
331 | |||
332 | /* | ||
333 | * The samples processed here are already preprocessed by the AD7877. | ||
334 | * The preprocessing function consists of an averaging filter. | ||
335 | * The combination of 'first conversion delay' and averaging provides a robust solution, | ||
336 | * discarding the spurious noise in the signal and keeping only the data of interest. | ||
337 | * The size of the averaging filter is programmable. (dev.platform_data, see linux/spi/ad7877.h) | ||
338 | * Other user-programmable conversion controls include variable acquisition time, | ||
339 | * and first conversion delay. Up to 16 averages can be taken per conversion. | ||
340 | */ | ||
341 | |||
342 | if (likely(x && z1)) { | ||
343 | /* compute touch pressure resistance using equation #1 */ | ||
344 | Rt = (z2 - z1) * x * ts->x_plate_ohms; | ||
345 | Rt /= z1; | ||
346 | Rt = (Rt + 2047) >> 12; | ||
347 | |||
348 | input_report_abs(input_dev, ABS_X, x); | ||
349 | input_report_abs(input_dev, ABS_Y, y); | ||
350 | input_report_abs(input_dev, ABS_PRESSURE, Rt); | ||
351 | input_sync(input_dev); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | static inline void ad7877_ts_event_release(struct ad7877 *ts) | ||
356 | { | ||
357 | struct input_dev *input_dev = ts->input; | ||
358 | |||
359 | input_report_abs(input_dev, ABS_PRESSURE, 0); | ||
360 | input_sync(input_dev); | ||
361 | } | ||
362 | |||
363 | static void ad7877_timer(unsigned long handle) | ||
364 | { | ||
365 | struct ad7877 *ts = (void *)handle; | ||
366 | |||
367 | ad7877_ts_event_release(ts); | ||
368 | } | ||
369 | |||
370 | static irqreturn_t ad7877_irq(int irq, void *handle) | ||
371 | { | ||
372 | struct ad7877 *ts = handle; | ||
373 | unsigned long flags; | ||
374 | int status; | ||
375 | |||
376 | /* | ||
377 | * The repeated conversion sequencer controlled by TMR kicked off | ||
378 | * too fast. We ignore the last and process the sample sequence | ||
379 | * currently in the queue. It can't be older than 9.4ms, and we | ||
380 | * need to avoid that ts->msg doesn't get issued twice while in work. | ||
381 | */ | ||
382 | |||
383 | spin_lock_irqsave(&ts->lock, flags); | ||
384 | if (!ts->pending) { | ||
385 | ts->pending = 1; | ||
386 | |||
387 | status = spi_async(ts->spi, &ts->msg); | ||
388 | if (status) | ||
389 | dev_err(&ts->spi->dev, "spi_sync --> %d\n", status); | ||
390 | } | ||
391 | spin_unlock_irqrestore(&ts->lock, flags); | ||
392 | |||
393 | return IRQ_HANDLED; | ||
394 | } | ||
395 | |||
396 | static void ad7877_callback(void *_ts) | ||
397 | { | ||
398 | struct ad7877 *ts = _ts; | ||
399 | |||
400 | spin_lock_irq(&ts->lock); | ||
401 | |||
402 | ad7877_rx(ts); | ||
403 | ts->pending = 0; | ||
404 | mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); | ||
405 | |||
406 | spin_unlock_irq(&ts->lock); | ||
407 | } | ||
408 | |||
409 | static void ad7877_disable(struct ad7877 *ts) | ||
410 | { | ||
411 | mutex_lock(&ts->mutex); | ||
412 | |||
413 | if (!ts->disabled) { | ||
414 | ts->disabled = 1; | ||
415 | disable_irq(ts->spi->irq); | ||
416 | |||
417 | /* Wait for spi_async callback */ | ||
418 | while (ts->pending) | ||
419 | msleep(1); | ||
420 | |||
421 | if (del_timer_sync(&ts->timer)) | ||
422 | ad7877_ts_event_release(ts); | ||
423 | } | ||
424 | |||
425 | /* we know the chip's in lowpower mode since we always | ||
426 | * leave it that way after every request | ||
427 | */ | ||
428 | |||
429 | mutex_unlock(&ts->mutex); | ||
430 | } | ||
431 | |||
432 | static void ad7877_enable(struct ad7877 *ts) | ||
433 | { | ||
434 | mutex_lock(&ts->mutex); | ||
435 | |||
436 | if (ts->disabled) { | ||
437 | ts->disabled = 0; | ||
438 | enable_irq(ts->spi->irq); | ||
439 | } | ||
440 | |||
441 | mutex_unlock(&ts->mutex); | ||
442 | } | ||
443 | |||
444 | #define SHOW(name) static ssize_t \ | ||
445 | name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ | ||
446 | { \ | ||
447 | struct ad7877 *ts = dev_get_drvdata(dev); \ | ||
448 | ssize_t v = ad7877_read_adc(ts->spi, \ | ||
449 | AD7877_READ_CHAN(name)); \ | ||
450 | if (v < 0) \ | ||
451 | return v; \ | ||
452 | return sprintf(buf, "%u\n", (unsigned) v); \ | ||
453 | } \ | ||
454 | static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL); | ||
455 | |||
456 | SHOW(aux1) | ||
457 | SHOW(aux2) | ||
458 | SHOW(aux3) | ||
459 | SHOW(bat1) | ||
460 | SHOW(bat2) | ||
461 | SHOW(temp1) | ||
462 | SHOW(temp2) | ||
463 | |||
464 | static ssize_t ad7877_disable_show(struct device *dev, | ||
465 | struct device_attribute *attr, char *buf) | ||
466 | { | ||
467 | struct ad7877 *ts = dev_get_drvdata(dev); | ||
468 | |||
469 | return sprintf(buf, "%u\n", ts->disabled); | ||
470 | } | ||
471 | |||
472 | static ssize_t ad7877_disable_store(struct device *dev, | ||
473 | struct device_attribute *attr, | ||
474 | const char *buf, size_t count) | ||
475 | { | ||
476 | struct ad7877 *ts = dev_get_drvdata(dev); | ||
477 | unsigned long val; | ||
478 | int error; | ||
479 | |||
480 | error = strict_strtoul(buf, 10, &val); | ||
481 | if (error) | ||
482 | return error; | ||
483 | |||
484 | if (val) | ||
485 | ad7877_disable(ts); | ||
486 | else | ||
487 | ad7877_enable(ts); | ||
488 | |||
489 | return count; | ||
490 | } | ||
491 | |||
492 | static DEVICE_ATTR(disable, 0664, ad7877_disable_show, ad7877_disable_store); | ||
493 | |||
494 | static ssize_t ad7877_dac_show(struct device *dev, | ||
495 | struct device_attribute *attr, char *buf) | ||
496 | { | ||
497 | struct ad7877 *ts = dev_get_drvdata(dev); | ||
498 | |||
499 | return sprintf(buf, "%u\n", ts->dac); | ||
500 | } | ||
501 | |||
502 | static ssize_t ad7877_dac_store(struct device *dev, | ||
503 | struct device_attribute *attr, | ||
504 | const char *buf, size_t count) | ||
505 | { | ||
506 | struct ad7877 *ts = dev_get_drvdata(dev); | ||
507 | unsigned long val; | ||
508 | int error; | ||
509 | |||
510 | error = strict_strtoul(buf, 10, &val); | ||
511 | if (error) | ||
512 | return error; | ||
513 | |||
514 | mutex_lock(&ts->mutex); | ||
515 | ts->dac = val & 0xFF; | ||
516 | ad7877_write(ts->spi, AD7877_REG_DAC, (ts->dac << 4) | AD7877_DAC_CONF); | ||
517 | mutex_unlock(&ts->mutex); | ||
518 | |||
519 | return count; | ||
520 | } | ||
521 | |||
522 | static DEVICE_ATTR(dac, 0664, ad7877_dac_show, ad7877_dac_store); | ||
523 | |||
524 | static ssize_t ad7877_gpio3_show(struct device *dev, | ||
525 | struct device_attribute *attr, char *buf) | ||
526 | { | ||
527 | struct ad7877 *ts = dev_get_drvdata(dev); | ||
528 | |||
529 | return sprintf(buf, "%u\n", ts->gpio3); | ||
530 | } | ||
531 | |||
532 | static ssize_t ad7877_gpio3_store(struct device *dev, | ||
533 | struct device_attribute *attr, | ||
534 | const char *buf, size_t count) | ||
535 | { | ||
536 | struct ad7877 *ts = dev_get_drvdata(dev); | ||
537 | unsigned long val; | ||
538 | int error; | ||
539 | |||
540 | error = strict_strtoul(buf, 10, &val); | ||
541 | if (error) | ||
542 | return error; | ||
543 | |||
544 | mutex_lock(&ts->mutex); | ||
545 | ts->gpio3 = !!val; | ||
546 | ad7877_write(ts->spi, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_DATA | | ||
547 | (ts->gpio4 << 4) | (ts->gpio3 << 5)); | ||
548 | mutex_unlock(&ts->mutex); | ||
549 | |||
550 | return count; | ||
551 | } | ||
552 | |||
553 | static DEVICE_ATTR(gpio3, 0664, ad7877_gpio3_show, ad7877_gpio3_store); | ||
554 | |||
555 | static ssize_t ad7877_gpio4_show(struct device *dev, | ||
556 | struct device_attribute *attr, char *buf) | ||
557 | { | ||
558 | struct ad7877 *ts = dev_get_drvdata(dev); | ||
559 | |||
560 | return sprintf(buf, "%u\n", ts->gpio4); | ||
561 | } | ||
562 | |||
563 | static ssize_t ad7877_gpio4_store(struct device *dev, | ||
564 | struct device_attribute *attr, | ||
565 | const char *buf, size_t count) | ||
566 | { | ||
567 | struct ad7877 *ts = dev_get_drvdata(dev); | ||
568 | unsigned long val; | ||
569 | int error; | ||
570 | |||
571 | error = strict_strtoul(buf, 10, &val); | ||
572 | if (error) | ||
573 | return error; | ||
574 | |||
575 | mutex_lock(&ts->mutex); | ||
576 | ts->gpio4 = !!val; | ||
577 | ad7877_write(ts->spi, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_DATA | | ||
578 | (ts->gpio4 << 4) | (ts->gpio3 << 5)); | ||
579 | mutex_unlock(&ts->mutex); | ||
580 | |||
581 | return count; | ||
582 | } | ||
583 | |||
584 | static DEVICE_ATTR(gpio4, 0664, ad7877_gpio4_show, ad7877_gpio4_store); | ||
585 | |||
586 | static struct attribute *ad7877_attributes[] = { | ||
587 | &dev_attr_temp1.attr, | ||
588 | &dev_attr_temp2.attr, | ||
589 | &dev_attr_aux1.attr, | ||
590 | &dev_attr_aux2.attr, | ||
591 | &dev_attr_bat1.attr, | ||
592 | &dev_attr_bat2.attr, | ||
593 | &dev_attr_disable.attr, | ||
594 | &dev_attr_dac.attr, | ||
595 | &dev_attr_gpio4.attr, | ||
596 | NULL | ||
597 | }; | ||
598 | |||
599 | static const struct attribute_group ad7877_attr_group = { | ||
600 | .attrs = ad7877_attributes, | ||
601 | }; | ||
602 | |||
603 | static void ad7877_setup_ts_def_msg(struct spi_device *spi, struct ad7877 *ts) | ||
604 | { | ||
605 | struct spi_message *m; | ||
606 | int i; | ||
607 | |||
608 | ts->cmd_crtl2 = AD7877_WRITEADD(AD7877_REG_CTRL2) | | ||
609 | AD7877_POL(ts->stopacq_polarity) | | ||
610 | AD7877_AVG(ts->averaging) | AD7877_PM(1) | | ||
611 | AD7877_TMR(ts->pen_down_acc_interval) | | ||
612 | AD7877_ACQ(ts->acquisition_time) | | ||
613 | AD7877_FCD(ts->first_conversion_delay); | ||
614 | |||
615 | ad7877_write(spi, AD7877_REG_CTRL2, ts->cmd_crtl2); | ||
616 | |||
617 | ts->cmd_crtl1 = AD7877_WRITEADD(AD7877_REG_CTRL1) | | ||
618 | AD7877_READADD(AD7877_REG_XPLUS-1) | | ||
619 | AD7877_MODE_SEQ1 | AD7877_DFR; | ||
620 | |||
621 | ad7877_write(spi, AD7877_REG_CTRL1, ts->cmd_crtl1); | ||
622 | |||
623 | ts->cmd_dummy = 0; | ||
624 | |||
625 | m = &ts->msg; | ||
626 | |||
627 | spi_message_init(m); | ||
628 | |||
629 | m->complete = ad7877_callback; | ||
630 | m->context = ts; | ||
631 | |||
632 | ts->xfer[0].tx_buf = &ts->cmd_crtl1; | ||
633 | ts->xfer[0].len = 2; | ||
634 | |||
635 | spi_message_add_tail(&ts->xfer[0], m); | ||
636 | |||
637 | ts->xfer[1].tx_buf = &ts->cmd_dummy; /* Send ZERO */ | ||
638 | ts->xfer[1].len = 2; | ||
639 | |||
640 | spi_message_add_tail(&ts->xfer[1], m); | ||
641 | |||
642 | for (i = 0; i < 11; i++) { | ||
643 | ts->xfer[i + 2].rx_buf = &ts->conversion_data[AD7877_SEQ_YPOS + i]; | ||
644 | ts->xfer[i + 2].len = 2; | ||
645 | spi_message_add_tail(&ts->xfer[i + 2], m); | ||
646 | } | ||
647 | } | ||
648 | |||
649 | static int __devinit ad7877_probe(struct spi_device *spi) | ||
650 | { | ||
651 | struct ad7877 *ts; | ||
652 | struct input_dev *input_dev; | ||
653 | struct ad7877_platform_data *pdata = spi->dev.platform_data; | ||
654 | int err; | ||
655 | u16 verify; | ||
656 | |||
657 | if (!spi->irq) { | ||
658 | dev_dbg(&spi->dev, "no IRQ?\n"); | ||
659 | return -ENODEV; | ||
660 | } | ||
661 | |||
662 | if (!pdata) { | ||
663 | dev_dbg(&spi->dev, "no platform data?\n"); | ||
664 | return -ENODEV; | ||
665 | } | ||
666 | |||
667 | /* don't exceed max specified SPI CLK frequency */ | ||
668 | if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) { | ||
669 | dev_dbg(&spi->dev, "SPI CLK %d Hz?\n",spi->max_speed_hz); | ||
670 | return -EINVAL; | ||
671 | } | ||
672 | |||
673 | ts = kzalloc(sizeof(struct ad7877), GFP_KERNEL); | ||
674 | input_dev = input_allocate_device(); | ||
675 | if (!ts || !input_dev) { | ||
676 | err = -ENOMEM; | ||
677 | goto err_free_mem; | ||
678 | } | ||
679 | |||
680 | dev_set_drvdata(&spi->dev, ts); | ||
681 | ts->spi = spi; | ||
682 | ts->input = input_dev; | ||
683 | |||
684 | setup_timer(&ts->timer, ad7877_timer, (unsigned long) ts); | ||
685 | mutex_init(&ts->mutex); | ||
686 | spin_lock_init(&ts->lock); | ||
687 | |||
688 | ts->model = pdata->model ? : 7877; | ||
689 | ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; | ||
690 | ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; | ||
691 | ts->pressure_max = pdata->pressure_max ? : ~0; | ||
692 | |||
693 | ts->stopacq_polarity = pdata->stopacq_polarity; | ||
694 | ts->first_conversion_delay = pdata->first_conversion_delay; | ||
695 | ts->acquisition_time = pdata->acquisition_time; | ||
696 | ts->averaging = pdata->averaging; | ||
697 | ts->pen_down_acc_interval = pdata->pen_down_acc_interval; | ||
698 | |||
699 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); | ||
700 | |||
701 | input_dev->name = "AD7877 Touchscreen"; | ||
702 | input_dev->phys = ts->phys; | ||
703 | input_dev->dev.parent = &spi->dev; | ||
704 | |||
705 | __set_bit(EV_ABS, input_dev->evbit); | ||
706 | __set_bit(ABS_X, input_dev->absbit); | ||
707 | __set_bit(ABS_Y, input_dev->absbit); | ||
708 | __set_bit(ABS_PRESSURE, input_dev->absbit); | ||
709 | |||
710 | input_set_abs_params(input_dev, ABS_X, | ||
711 | pdata->x_min ? : 0, | ||
712 | pdata->x_max ? : MAX_12BIT, | ||
713 | 0, 0); | ||
714 | input_set_abs_params(input_dev, ABS_Y, | ||
715 | pdata->y_min ? : 0, | ||
716 | pdata->y_max ? : MAX_12BIT, | ||
717 | 0, 0); | ||
718 | input_set_abs_params(input_dev, ABS_PRESSURE, | ||
719 | pdata->pressure_min, pdata->pressure_max, 0, 0); | ||
720 | |||
721 | ad7877_write(spi, AD7877_REG_SEQ1, AD7877_MM_SEQUENCE); | ||
722 | |||
723 | verify = ad7877_read(spi, AD7877_REG_SEQ1); | ||
724 | |||
725 | if (verify != AD7877_MM_SEQUENCE){ | ||
726 | dev_err(&spi->dev, "%s: Failed to probe %s\n", | ||
727 | dev_name(&spi->dev), input_dev->name); | ||
728 | err = -ENODEV; | ||
729 | goto err_free_mem; | ||
730 | } | ||
731 | |||
732 | if (gpio3) | ||
733 | ad7877_write(spi, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_3_CONF); | ||
734 | |||
735 | ad7877_setup_ts_def_msg(spi, ts); | ||
736 | |||
737 | /* Request AD7877 /DAV GPIO interrupt */ | ||
738 | |||
739 | err = request_irq(spi->irq, ad7877_irq, IRQF_TRIGGER_FALLING | | ||
740 | IRQF_SAMPLE_RANDOM, spi->dev.driver->name, ts); | ||
741 | if (err) { | ||
742 | dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); | ||
743 | goto err_free_mem; | ||
744 | } | ||
745 | |||
746 | err = sysfs_create_group(&spi->dev.kobj, &ad7877_attr_group); | ||
747 | if (err) | ||
748 | goto err_free_irq; | ||
749 | |||
750 | err = device_create_file(&spi->dev, | ||
751 | gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); | ||
752 | if (err) | ||
753 | goto err_remove_attr_group; | ||
754 | |||
755 | err = input_register_device(input_dev); | ||
756 | if (err) | ||
757 | goto err_remove_attr; | ||
758 | |||
759 | return 0; | ||
760 | |||
761 | err_remove_attr: | ||
762 | device_remove_file(&spi->dev, | ||
763 | gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); | ||
764 | err_remove_attr_group: | ||
765 | sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); | ||
766 | err_free_irq: | ||
767 | free_irq(spi->irq, ts); | ||
768 | err_free_mem: | ||
769 | input_free_device(input_dev); | ||
770 | kfree(ts); | ||
771 | dev_set_drvdata(&spi->dev, NULL); | ||
772 | return err; | ||
773 | } | ||
774 | |||
775 | static int __devexit ad7877_remove(struct spi_device *spi) | ||
776 | { | ||
777 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | ||
778 | |||
779 | sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); | ||
780 | device_remove_file(&spi->dev, | ||
781 | gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); | ||
782 | |||
783 | ad7877_disable(ts); | ||
784 | free_irq(ts->spi->irq, ts); | ||
785 | |||
786 | input_unregister_device(ts->input); | ||
787 | kfree(ts); | ||
788 | |||
789 | dev_dbg(&spi->dev, "unregistered touchscreen\n"); | ||
790 | dev_set_drvdata(&spi->dev, NULL); | ||
791 | |||
792 | return 0; | ||
793 | } | ||
794 | |||
795 | #ifdef CONFIG_PM | ||
796 | static int ad7877_suspend(struct spi_device *spi, pm_message_t message) | ||
797 | { | ||
798 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | ||
799 | |||
800 | ad7877_disable(ts); | ||
801 | |||
802 | return 0; | ||
803 | } | ||
804 | |||
805 | static int ad7877_resume(struct spi_device *spi) | ||
806 | { | ||
807 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | ||
808 | |||
809 | ad7877_enable(ts); | ||
810 | |||
811 | return 0; | ||
812 | } | ||
813 | #else | ||
814 | #define ad7877_suspend NULL | ||
815 | #define ad7877_resume NULL | ||
816 | #endif | ||
817 | |||
818 | static struct spi_driver ad7877_driver = { | ||
819 | .driver = { | ||
820 | .name = "ad7877", | ||
821 | .bus = &spi_bus_type, | ||
822 | .owner = THIS_MODULE, | ||
823 | }, | ||
824 | .probe = ad7877_probe, | ||
825 | .remove = __devexit_p(ad7877_remove), | ||
826 | .suspend = ad7877_suspend, | ||
827 | .resume = ad7877_resume, | ||
828 | }; | ||
829 | |||
830 | static int __init ad7877_init(void) | ||
831 | { | ||
832 | return spi_register_driver(&ad7877_driver); | ||
833 | } | ||
834 | module_init(ad7877_init); | ||
835 | |||
836 | static void __exit ad7877_exit(void) | ||
837 | { | ||
838 | spi_unregister_driver(&ad7877_driver); | ||
839 | } | ||
840 | module_exit(ad7877_exit); | ||
841 | |||
842 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | ||
843 | MODULE_DESCRIPTION("AD7877 touchscreen Driver"); | ||
844 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c new file mode 100644 index 000000000000..ea4c61d68683 --- /dev/null +++ b/drivers/input/touchscreen/ad7879.c | |||
@@ -0,0 +1,782 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008 Michael Hennerich, Analog Devices Inc. | ||
3 | * | ||
4 | * Description: AD7879 based touchscreen, and GPIO driver (I2C/SPI Interface) | ||
5 | * | ||
6 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, see the file COPYING, or write | ||
20 | * to the Free Software Foundation, Inc., | ||
21 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | * | ||
23 | * History: | ||
24 | * Copyright (c) 2005 David Brownell | ||
25 | * Copyright (c) 2006 Nokia Corporation | ||
26 | * Various changes: Imre Deak <imre.deak@nokia.com> | ||
27 | * | ||
28 | * Using code from: | ||
29 | * - corgi_ts.c | ||
30 | * Copyright (C) 2004-2005 Richard Purdie | ||
31 | * - omap_ts.[hc], ads7846.h, ts_osk.c | ||
32 | * Copyright (C) 2002 MontaVista Software | ||
33 | * Copyright (C) 2004 Texas Instruments | ||
34 | * Copyright (C) 2005 Dirk Behme | ||
35 | * - ad7877.c | ||
36 | * Copyright (C) 2006-2008 Analog Devices Inc. | ||
37 | */ | ||
38 | |||
39 | #include <linux/device.h> | ||
40 | #include <linux/init.h> | ||
41 | #include <linux/delay.h> | ||
42 | #include <linux/input.h> | ||
43 | #include <linux/interrupt.h> | ||
44 | #include <linux/irq.h> | ||
45 | #include <linux/slab.h> | ||
46 | #include <linux/workqueue.h> | ||
47 | #include <linux/spi/spi.h> | ||
48 | #include <linux/i2c.h> | ||
49 | |||
50 | #include <linux/spi/ad7879.h> | ||
51 | |||
52 | #define AD7879_REG_ZEROS 0 | ||
53 | #define AD7879_REG_CTRL1 1 | ||
54 | #define AD7879_REG_CTRL2 2 | ||
55 | #define AD7879_REG_CTRL3 3 | ||
56 | #define AD7879_REG_AUX1HIGH 4 | ||
57 | #define AD7879_REG_AUX1LOW 5 | ||
58 | #define AD7879_REG_TEMP1HIGH 6 | ||
59 | #define AD7879_REG_TEMP1LOW 7 | ||
60 | #define AD7879_REG_XPLUS 8 | ||
61 | #define AD7879_REG_YPLUS 9 | ||
62 | #define AD7879_REG_Z1 10 | ||
63 | #define AD7879_REG_Z2 11 | ||
64 | #define AD7879_REG_AUXVBAT 12 | ||
65 | #define AD7879_REG_TEMP 13 | ||
66 | #define AD7879_REG_REVID 14 | ||
67 | |||
68 | /* Control REG 1 */ | ||
69 | #define AD7879_TMR(x) ((x & 0xFF) << 0) | ||
70 | #define AD7879_ACQ(x) ((x & 0x3) << 8) | ||
71 | #define AD7879_MODE_NOC (0 << 10) /* Do not convert */ | ||
72 | #define AD7879_MODE_SCC (1 << 10) /* Single channel conversion */ | ||
73 | #define AD7879_MODE_SEQ0 (2 << 10) /* Sequence 0 in Slave Mode */ | ||
74 | #define AD7879_MODE_SEQ1 (3 << 10) /* Sequence 1 in Master Mode */ | ||
75 | #define AD7879_MODE_INT (1 << 15) /* PENIRQ disabled INT enabled */ | ||
76 | |||
77 | /* Control REG 2 */ | ||
78 | #define AD7879_FCD(x) ((x & 0x3) << 0) | ||
79 | #define AD7879_RESET (1 << 4) | ||
80 | #define AD7879_MFS(x) ((x & 0x3) << 5) | ||
81 | #define AD7879_AVG(x) ((x & 0x3) << 7) | ||
82 | #define AD7879_SER (1 << 9) /* non-differential */ | ||
83 | #define AD7879_DFR (0 << 9) /* differential */ | ||
84 | #define AD7879_GPIOPOL (1 << 10) | ||
85 | #define AD7879_GPIODIR (1 << 11) | ||
86 | #define AD7879_GPIO_DATA (1 << 12) | ||
87 | #define AD7879_GPIO_EN (1 << 13) | ||
88 | #define AD7879_PM(x) ((x & 0x3) << 14) | ||
89 | #define AD7879_PM_SHUTDOWN (0) | ||
90 | #define AD7879_PM_DYN (1) | ||
91 | #define AD7879_PM_FULLON (2) | ||
92 | |||
93 | /* Control REG 3 */ | ||
94 | #define AD7879_TEMPMASK_BIT (1<<15) | ||
95 | #define AD7879_AUXVBATMASK_BIT (1<<14) | ||
96 | #define AD7879_INTMODE_BIT (1<<13) | ||
97 | #define AD7879_GPIOALERTMASK_BIT (1<<12) | ||
98 | #define AD7879_AUXLOW_BIT (1<<11) | ||
99 | #define AD7879_AUXHIGH_BIT (1<<10) | ||
100 | #define AD7879_TEMPLOW_BIT (1<<9) | ||
101 | #define AD7879_TEMPHIGH_BIT (1<<8) | ||
102 | #define AD7879_YPLUS_BIT (1<<7) | ||
103 | #define AD7879_XPLUS_BIT (1<<6) | ||
104 | #define AD7879_Z1_BIT (1<<5) | ||
105 | #define AD7879_Z2_BIT (1<<4) | ||
106 | #define AD7879_AUX_BIT (1<<3) | ||
107 | #define AD7879_VBAT_BIT (1<<2) | ||
108 | #define AD7879_TEMP_BIT (1<<1) | ||
109 | |||
110 | enum { | ||
111 | AD7879_SEQ_XPOS = 0, | ||
112 | AD7879_SEQ_YPOS = 1, | ||
113 | AD7879_SEQ_Z1 = 2, | ||
114 | AD7879_SEQ_Z2 = 3, | ||
115 | AD7879_NR_SENSE = 4, | ||
116 | }; | ||
117 | |||
118 | #define MAX_12BIT ((1<<12)-1) | ||
119 | #define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50) | ||
120 | |||
121 | #if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE) | ||
122 | #define AD7879_DEVID 0x7A | ||
123 | typedef struct spi_device bus_device; | ||
124 | #elif defined(CONFIG_TOUCHSCREEN_AD7879_I2C) || defined(CONFIG_TOUCHSCREEN_AD7879_I2C_MODULE) | ||
125 | #define AD7879_DEVID 0x79 | ||
126 | typedef struct i2c_client bus_device; | ||
127 | #endif | ||
128 | |||
129 | struct ad7879 { | ||
130 | bus_device *bus; | ||
131 | struct input_dev *input; | ||
132 | struct work_struct work; | ||
133 | struct timer_list timer; | ||
134 | |||
135 | struct mutex mutex; | ||
136 | unsigned disabled:1; /* P: mutex */ | ||
137 | |||
138 | #if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE) | ||
139 | struct spi_message msg; | ||
140 | struct spi_transfer xfer[AD7879_NR_SENSE + 1]; | ||
141 | u16 cmd; | ||
142 | #endif | ||
143 | u16 conversion_data[AD7879_NR_SENSE]; | ||
144 | char phys[32]; | ||
145 | u8 first_conversion_delay; | ||
146 | u8 acquisition_time; | ||
147 | u8 averaging; | ||
148 | u8 pen_down_acc_interval; | ||
149 | u8 median; | ||
150 | u16 x_plate_ohms; | ||
151 | u16 pressure_max; | ||
152 | u16 gpio_init; | ||
153 | u16 cmd_crtl1; | ||
154 | u16 cmd_crtl2; | ||
155 | u16 cmd_crtl3; | ||
156 | unsigned gpio:1; | ||
157 | }; | ||
158 | |||
159 | static int ad7879_read(bus_device *, u8); | ||
160 | static int ad7879_write(bus_device *, u8, u16); | ||
161 | static void ad7879_collect(struct ad7879 *); | ||
162 | |||
163 | static void ad7879_report(struct ad7879 *ts) | ||
164 | { | ||
165 | struct input_dev *input_dev = ts->input; | ||
166 | unsigned Rt; | ||
167 | u16 x, y, z1, z2; | ||
168 | |||
169 | x = ts->conversion_data[AD7879_SEQ_XPOS] & MAX_12BIT; | ||
170 | y = ts->conversion_data[AD7879_SEQ_YPOS] & MAX_12BIT; | ||
171 | z1 = ts->conversion_data[AD7879_SEQ_Z1] & MAX_12BIT; | ||
172 | z2 = ts->conversion_data[AD7879_SEQ_Z2] & MAX_12BIT; | ||
173 | |||
174 | /* | ||
175 | * The samples processed here are already preprocessed by the AD7879. | ||
176 | * The preprocessing function consists of a median and an averaging filter. | ||
177 | * The combination of these two techniques provides a robust solution, | ||
178 | * discarding the spurious noise in the signal and keeping only the data of interest. | ||
179 | * The size of both filters is programmable. (dev.platform_data, see linux/spi/ad7879.h) | ||
180 | * Other user-programmable conversion controls include variable acquisition time, | ||
181 | * and first conversion delay. Up to 16 averages can be taken per conversion. | ||
182 | */ | ||
183 | |||
184 | if (likely(x && z1)) { | ||
185 | /* compute touch pressure resistance using equation #1 */ | ||
186 | Rt = (z2 - z1) * x * ts->x_plate_ohms; | ||
187 | Rt /= z1; | ||
188 | Rt = (Rt + 2047) >> 12; | ||
189 | |||
190 | input_report_abs(input_dev, ABS_X, x); | ||
191 | input_report_abs(input_dev, ABS_Y, y); | ||
192 | input_report_abs(input_dev, ABS_PRESSURE, Rt); | ||
193 | input_sync(input_dev); | ||
194 | } | ||
195 | } | ||
196 | |||
197 | static void ad7879_work(struct work_struct *work) | ||
198 | { | ||
199 | struct ad7879 *ts = container_of(work, struct ad7879, work); | ||
200 | |||
201 | /* use keventd context to read the result registers */ | ||
202 | ad7879_collect(ts); | ||
203 | ad7879_report(ts); | ||
204 | mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); | ||
205 | } | ||
206 | |||
207 | static void ad7879_ts_event_release(struct ad7879 *ts) | ||
208 | { | ||
209 | struct input_dev *input_dev = ts->input; | ||
210 | |||
211 | input_report_abs(input_dev, ABS_PRESSURE, 0); | ||
212 | input_sync(input_dev); | ||
213 | } | ||
214 | |||
215 | static void ad7879_timer(unsigned long handle) | ||
216 | { | ||
217 | struct ad7879 *ts = (void *)handle; | ||
218 | |||
219 | ad7879_ts_event_release(ts); | ||
220 | } | ||
221 | |||
222 | static irqreturn_t ad7879_irq(int irq, void *handle) | ||
223 | { | ||
224 | struct ad7879 *ts = handle; | ||
225 | |||
226 | /* The repeated conversion sequencer controlled by TMR kicked off too fast. | ||
227 | * We ignore the last and process the sample sequence currently in the queue. | ||
228 | * It can't be older than 9.4ms | ||
229 | */ | ||
230 | |||
231 | if (!work_pending(&ts->work)) | ||
232 | schedule_work(&ts->work); | ||
233 | |||
234 | return IRQ_HANDLED; | ||
235 | } | ||
236 | |||
237 | static void ad7879_setup(struct ad7879 *ts) | ||
238 | { | ||
239 | ts->cmd_crtl3 = AD7879_YPLUS_BIT | | ||
240 | AD7879_XPLUS_BIT | | ||
241 | AD7879_Z2_BIT | | ||
242 | AD7879_Z1_BIT | | ||
243 | AD7879_TEMPMASK_BIT | | ||
244 | AD7879_AUXVBATMASK_BIT | | ||
245 | AD7879_GPIOALERTMASK_BIT; | ||
246 | |||
247 | ts->cmd_crtl2 = AD7879_PM(AD7879_PM_DYN) | AD7879_DFR | | ||
248 | AD7879_AVG(ts->averaging) | | ||
249 | AD7879_MFS(ts->median) | | ||
250 | AD7879_FCD(ts->first_conversion_delay) | | ||
251 | ts->gpio_init; | ||
252 | |||
253 | ts->cmd_crtl1 = AD7879_MODE_INT | AD7879_MODE_SEQ1 | | ||
254 | AD7879_ACQ(ts->acquisition_time) | | ||
255 | AD7879_TMR(ts->pen_down_acc_interval); | ||
256 | |||
257 | ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); | ||
258 | ad7879_write(ts->bus, AD7879_REG_CTRL3, ts->cmd_crtl3); | ||
259 | ad7879_write(ts->bus, AD7879_REG_CTRL1, ts->cmd_crtl1); | ||
260 | } | ||
261 | |||
262 | static void ad7879_disable(struct ad7879 *ts) | ||
263 | { | ||
264 | mutex_lock(&ts->mutex); | ||
265 | |||
266 | if (!ts->disabled) { | ||
267 | |||
268 | ts->disabled = 1; | ||
269 | disable_irq(ts->bus->irq); | ||
270 | |||
271 | cancel_work_sync(&ts->work); | ||
272 | |||
273 | if (del_timer_sync(&ts->timer)) | ||
274 | ad7879_ts_event_release(ts); | ||
275 | |||
276 | ad7879_write(ts->bus, AD7879_REG_CTRL2, | ||
277 | AD7879_PM(AD7879_PM_SHUTDOWN)); | ||
278 | } | ||
279 | |||
280 | mutex_unlock(&ts->mutex); | ||
281 | } | ||
282 | |||
283 | static void ad7879_enable(struct ad7879 *ts) | ||
284 | { | ||
285 | mutex_lock(&ts->mutex); | ||
286 | |||
287 | if (ts->disabled) { | ||
288 | ad7879_setup(ts); | ||
289 | ts->disabled = 0; | ||
290 | enable_irq(ts->bus->irq); | ||
291 | } | ||
292 | |||
293 | mutex_unlock(&ts->mutex); | ||
294 | } | ||
295 | |||
296 | static ssize_t ad7879_disable_show(struct device *dev, | ||
297 | struct device_attribute *attr, char *buf) | ||
298 | { | ||
299 | struct ad7879 *ts = dev_get_drvdata(dev); | ||
300 | |||
301 | return sprintf(buf, "%u\n", ts->disabled); | ||
302 | } | ||
303 | |||
304 | static ssize_t ad7879_disable_store(struct device *dev, | ||
305 | struct device_attribute *attr, | ||
306 | const char *buf, size_t count) | ||
307 | { | ||
308 | struct ad7879 *ts = dev_get_drvdata(dev); | ||
309 | unsigned long val; | ||
310 | int error; | ||
311 | |||
312 | error = strict_strtoul(buf, 10, &val); | ||
313 | if (error) | ||
314 | return error; | ||
315 | |||
316 | if (val) | ||
317 | ad7879_disable(ts); | ||
318 | else | ||
319 | ad7879_enable(ts); | ||
320 | |||
321 | return count; | ||
322 | } | ||
323 | |||
324 | static DEVICE_ATTR(disable, 0664, ad7879_disable_show, ad7879_disable_store); | ||
325 | |||
326 | static ssize_t ad7879_gpio_show(struct device *dev, | ||
327 | struct device_attribute *attr, char *buf) | ||
328 | { | ||
329 | struct ad7879 *ts = dev_get_drvdata(dev); | ||
330 | |||
331 | return sprintf(buf, "%u\n", ts->gpio); | ||
332 | } | ||
333 | |||
334 | static ssize_t ad7879_gpio_store(struct device *dev, | ||
335 | struct device_attribute *attr, | ||
336 | const char *buf, size_t count) | ||
337 | { | ||
338 | struct ad7879 *ts = dev_get_drvdata(dev); | ||
339 | unsigned long val; | ||
340 | int error; | ||
341 | |||
342 | error = strict_strtoul(buf, 10, &val); | ||
343 | if (error) | ||
344 | return error; | ||
345 | |||
346 | mutex_lock(&ts->mutex); | ||
347 | ts->gpio = !!val; | ||
348 | error = ad7879_write(ts->bus, AD7879_REG_CTRL2, | ||
349 | ts->gpio ? | ||
350 | ts->cmd_crtl2 & ~AD7879_GPIO_DATA : | ||
351 | ts->cmd_crtl2 | AD7879_GPIO_DATA); | ||
352 | mutex_unlock(&ts->mutex); | ||
353 | |||
354 | return error ? : count; | ||
355 | } | ||
356 | |||
357 | static DEVICE_ATTR(gpio, 0664, ad7879_gpio_show, ad7879_gpio_store); | ||
358 | |||
359 | static struct attribute *ad7879_attributes[] = { | ||
360 | &dev_attr_disable.attr, | ||
361 | &dev_attr_gpio.attr, | ||
362 | NULL | ||
363 | }; | ||
364 | |||
365 | static const struct attribute_group ad7879_attr_group = { | ||
366 | .attrs = ad7879_attributes, | ||
367 | }; | ||
368 | |||
369 | static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts) | ||
370 | { | ||
371 | struct input_dev *input_dev; | ||
372 | struct ad7879_platform_data *pdata = bus->dev.platform_data; | ||
373 | int err; | ||
374 | u16 revid; | ||
375 | |||
376 | if (!bus->irq) { | ||
377 | dev_err(&bus->dev, "no IRQ?\n"); | ||
378 | return -ENODEV; | ||
379 | } | ||
380 | |||
381 | if (!pdata) { | ||
382 | dev_err(&bus->dev, "no platform data?\n"); | ||
383 | return -ENODEV; | ||
384 | } | ||
385 | |||
386 | input_dev = input_allocate_device(); | ||
387 | if (!input_dev) | ||
388 | return -ENOMEM; | ||
389 | |||
390 | ts->input = input_dev; | ||
391 | |||
392 | setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts); | ||
393 | INIT_WORK(&ts->work, ad7879_work); | ||
394 | mutex_init(&ts->mutex); | ||
395 | |||
396 | ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; | ||
397 | ts->pressure_max = pdata->pressure_max ? : ~0; | ||
398 | |||
399 | ts->first_conversion_delay = pdata->first_conversion_delay; | ||
400 | ts->acquisition_time = pdata->acquisition_time; | ||
401 | ts->averaging = pdata->averaging; | ||
402 | ts->pen_down_acc_interval = pdata->pen_down_acc_interval; | ||
403 | ts->median = pdata->median; | ||
404 | |||
405 | if (pdata->gpio_output) | ||
406 | ts->gpio_init = AD7879_GPIO_EN | | ||
407 | (pdata->gpio_default ? 0 : AD7879_GPIO_DATA); | ||
408 | else | ||
409 | ts->gpio_init = AD7879_GPIO_EN | AD7879_GPIODIR; | ||
410 | |||
411 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&bus->dev)); | ||
412 | |||
413 | input_dev->name = "AD7879 Touchscreen"; | ||
414 | input_dev->phys = ts->phys; | ||
415 | input_dev->dev.parent = &bus->dev; | ||
416 | |||
417 | __set_bit(EV_ABS, input_dev->evbit); | ||
418 | __set_bit(ABS_X, input_dev->absbit); | ||
419 | __set_bit(ABS_Y, input_dev->absbit); | ||
420 | __set_bit(ABS_PRESSURE, input_dev->absbit); | ||
421 | |||
422 | input_set_abs_params(input_dev, ABS_X, | ||
423 | pdata->x_min ? : 0, | ||
424 | pdata->x_max ? : MAX_12BIT, | ||
425 | 0, 0); | ||
426 | input_set_abs_params(input_dev, ABS_Y, | ||
427 | pdata->y_min ? : 0, | ||
428 | pdata->y_max ? : MAX_12BIT, | ||
429 | 0, 0); | ||
430 | input_set_abs_params(input_dev, ABS_PRESSURE, | ||
431 | pdata->pressure_min, pdata->pressure_max, 0, 0); | ||
432 | |||
433 | err = ad7879_write(bus, AD7879_REG_CTRL2, AD7879_RESET); | ||
434 | |||
435 | if (err < 0) { | ||
436 | dev_err(&bus->dev, "Failed to write %s\n", input_dev->name); | ||
437 | goto err_free_mem; | ||
438 | } | ||
439 | |||
440 | revid = ad7879_read(bus, AD7879_REG_REVID); | ||
441 | |||
442 | if ((revid & 0xFF) != AD7879_DEVID) { | ||
443 | dev_err(&bus->dev, "Failed to probe %s\n", input_dev->name); | ||
444 | err = -ENODEV; | ||
445 | goto err_free_mem; | ||
446 | } | ||
447 | |||
448 | ad7879_setup(ts); | ||
449 | |||
450 | err = request_irq(bus->irq, ad7879_irq, | ||
451 | IRQF_TRIGGER_FALLING | IRQF_SAMPLE_RANDOM, | ||
452 | bus->dev.driver->name, ts); | ||
453 | |||
454 | if (err) { | ||
455 | dev_err(&bus->dev, "irq %d busy?\n", bus->irq); | ||
456 | goto err_free_mem; | ||
457 | } | ||
458 | |||
459 | err = sysfs_create_group(&bus->dev.kobj, &ad7879_attr_group); | ||
460 | if (err) | ||
461 | goto err_free_irq; | ||
462 | |||
463 | err = input_register_device(input_dev); | ||
464 | if (err) | ||
465 | goto err_remove_attr; | ||
466 | |||
467 | dev_info(&bus->dev, "Rev.%d touchscreen, irq %d\n", | ||
468 | revid >> 8, bus->irq); | ||
469 | |||
470 | return 0; | ||
471 | |||
472 | err_remove_attr: | ||
473 | sysfs_remove_group(&bus->dev.kobj, &ad7879_attr_group); | ||
474 | err_free_irq: | ||
475 | free_irq(bus->irq, ts); | ||
476 | err_free_mem: | ||
477 | input_free_device(input_dev); | ||
478 | |||
479 | return err; | ||
480 | } | ||
481 | |||
482 | static int __devexit ad7879_destroy(bus_device *bus, struct ad7879 *ts) | ||
483 | { | ||
484 | ad7879_disable(ts); | ||
485 | sysfs_remove_group(&ts->bus->dev.kobj, &ad7879_attr_group); | ||
486 | free_irq(ts->bus->irq, ts); | ||
487 | input_unregister_device(ts->input); | ||
488 | dev_dbg(&bus->dev, "unregistered touchscreen\n"); | ||
489 | |||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | #ifdef CONFIG_PM | ||
494 | static int ad7879_suspend(bus_device *bus, pm_message_t message) | ||
495 | { | ||
496 | struct ad7879 *ts = dev_get_drvdata(&bus->dev); | ||
497 | |||
498 | ad7879_disable(ts); | ||
499 | |||
500 | return 0; | ||
501 | } | ||
502 | |||
503 | static int ad7879_resume(bus_device *bus) | ||
504 | { | ||
505 | struct ad7879 *ts = dev_get_drvdata(&bus->dev); | ||
506 | |||
507 | ad7879_enable(ts); | ||
508 | |||
509 | return 0; | ||
510 | } | ||
511 | #else | ||
512 | #define ad7879_suspend NULL | ||
513 | #define ad7879_resume NULL | ||
514 | #endif | ||
515 | |||
516 | #if defined(CONFIG_TOUCHSCREEN_AD7879_SPI) || defined(CONFIG_TOUCHSCREEN_AD7879_SPI_MODULE) | ||
517 | #define MAX_SPI_FREQ_HZ 5000000 | ||
518 | #define AD7879_CMD_MAGIC 0xE000 | ||
519 | #define AD7879_CMD_READ (1 << 10) | ||
520 | #define AD7879_WRITECMD(reg) (AD7879_CMD_MAGIC | (reg & 0xF)) | ||
521 | #define AD7879_READCMD(reg) (AD7879_CMD_MAGIC | AD7879_CMD_READ | (reg & 0xF)) | ||
522 | |||
523 | struct ser_req { | ||
524 | u16 command; | ||
525 | u16 data; | ||
526 | struct spi_message msg; | ||
527 | struct spi_transfer xfer[2]; | ||
528 | }; | ||
529 | |||
530 | /* | ||
531 | * ad7879_read/write are only used for initial setup and for sysfs controls. | ||
532 | * The main traffic is done in ad7879_collect(). | ||
533 | */ | ||
534 | |||
535 | static int ad7879_read(struct spi_device *spi, u8 reg) | ||
536 | { | ||
537 | struct ser_req *req; | ||
538 | int status, ret; | ||
539 | |||
540 | req = kzalloc(sizeof *req, GFP_KERNEL); | ||
541 | if (!req) | ||
542 | return -ENOMEM; | ||
543 | |||
544 | spi_message_init(&req->msg); | ||
545 | |||
546 | req->command = (u16) AD7879_READCMD(reg); | ||
547 | req->xfer[0].tx_buf = &req->command; | ||
548 | req->xfer[0].len = 2; | ||
549 | |||
550 | req->xfer[1].rx_buf = &req->data; | ||
551 | req->xfer[1].len = 2; | ||
552 | |||
553 | spi_message_add_tail(&req->xfer[0], &req->msg); | ||
554 | spi_message_add_tail(&req->xfer[1], &req->msg); | ||
555 | |||
556 | status = spi_sync(spi, &req->msg); | ||
557 | ret = status ? : req->data; | ||
558 | |||
559 | kfree(req); | ||
560 | |||
561 | return ret; | ||
562 | } | ||
563 | |||
564 | static int ad7879_write(struct spi_device *spi, u8 reg, u16 val) | ||
565 | { | ||
566 | struct ser_req *req; | ||
567 | int status; | ||
568 | |||
569 | req = kzalloc(sizeof *req, GFP_KERNEL); | ||
570 | if (!req) | ||
571 | return -ENOMEM; | ||
572 | |||
573 | spi_message_init(&req->msg); | ||
574 | |||
575 | req->command = (u16) AD7879_WRITECMD(reg); | ||
576 | req->xfer[0].tx_buf = &req->command; | ||
577 | req->xfer[0].len = 2; | ||
578 | |||
579 | req->data = val; | ||
580 | req->xfer[1].tx_buf = &req->data; | ||
581 | req->xfer[1].len = 2; | ||
582 | |||
583 | spi_message_add_tail(&req->xfer[0], &req->msg); | ||
584 | spi_message_add_tail(&req->xfer[1], &req->msg); | ||
585 | |||
586 | status = spi_sync(spi, &req->msg); | ||
587 | |||
588 | kfree(req); | ||
589 | |||
590 | return status; | ||
591 | } | ||
592 | |||
593 | static void ad7879_collect(struct ad7879 *ts) | ||
594 | { | ||
595 | int status = spi_sync(ts->bus, &ts->msg); | ||
596 | |||
597 | if (status) | ||
598 | dev_err(&ts->bus->dev, "spi_sync --> %d\n", status); | ||
599 | } | ||
600 | |||
601 | static void ad7879_setup_ts_def_msg(struct ad7879 *ts) | ||
602 | { | ||
603 | struct spi_message *m; | ||
604 | int i; | ||
605 | |||
606 | ts->cmd = (u16) AD7879_READCMD(AD7879_REG_XPLUS); | ||
607 | |||
608 | m = &ts->msg; | ||
609 | spi_message_init(m); | ||
610 | ts->xfer[0].tx_buf = &ts->cmd; | ||
611 | ts->xfer[0].len = 2; | ||
612 | |||
613 | spi_message_add_tail(&ts->xfer[0], m); | ||
614 | |||
615 | for (i = 0; i < AD7879_NR_SENSE; i++) { | ||
616 | ts->xfer[i + 1].rx_buf = &ts->conversion_data[i]; | ||
617 | ts->xfer[i + 1].len = 2; | ||
618 | spi_message_add_tail(&ts->xfer[i + 1], m); | ||
619 | } | ||
620 | } | ||
621 | |||
622 | static int __devinit ad7879_probe(struct spi_device *spi) | ||
623 | { | ||
624 | struct ad7879 *ts; | ||
625 | int error; | ||
626 | |||
627 | /* don't exceed max specified SPI CLK frequency */ | ||
628 | if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) { | ||
629 | dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz); | ||
630 | return -EINVAL; | ||
631 | } | ||
632 | |||
633 | ts = kzalloc(sizeof(struct ad7879), GFP_KERNEL); | ||
634 | if (!ts) | ||
635 | return -ENOMEM; | ||
636 | |||
637 | dev_set_drvdata(&spi->dev, ts); | ||
638 | ts->bus = spi; | ||
639 | |||
640 | ad7879_setup_ts_def_msg(ts); | ||
641 | |||
642 | error = ad7879_construct(spi, ts); | ||
643 | if (error) { | ||
644 | dev_set_drvdata(&spi->dev, NULL); | ||
645 | kfree(ts); | ||
646 | } | ||
647 | |||
648 | return 0; | ||
649 | } | ||
650 | |||
651 | static int __devexit ad7879_remove(struct spi_device *spi) | ||
652 | { | ||
653 | struct ad7879 *ts = dev_get_drvdata(&spi->dev); | ||
654 | |||
655 | ad7879_destroy(spi, ts); | ||
656 | dev_set_drvdata(&spi->dev, NULL); | ||
657 | kfree(ts); | ||
658 | |||
659 | return 0; | ||
660 | } | ||
661 | |||
662 | static struct spi_driver ad7879_driver = { | ||
663 | .driver = { | ||
664 | .name = "ad7879", | ||
665 | .bus = &spi_bus_type, | ||
666 | .owner = THIS_MODULE, | ||
667 | }, | ||
668 | .probe = ad7879_probe, | ||
669 | .remove = __devexit_p(ad7879_remove), | ||
670 | .suspend = ad7879_suspend, | ||
671 | .resume = ad7879_resume, | ||
672 | }; | ||
673 | |||
674 | static int __init ad7879_init(void) | ||
675 | { | ||
676 | return spi_register_driver(&ad7879_driver); | ||
677 | } | ||
678 | module_init(ad7879_init); | ||
679 | |||
680 | static void __exit ad7879_exit(void) | ||
681 | { | ||
682 | spi_unregister_driver(&ad7879_driver); | ||
683 | } | ||
684 | module_exit(ad7879_exit); | ||
685 | |||
686 | #elif defined(CONFIG_TOUCHSCREEN_AD7879_I2C) || defined(CONFIG_TOUCHSCREEN_AD7879_I2C_MODULE) | ||
687 | |||
688 | /* All registers are word-sized. | ||
689 | * AD7879 uses a high-byte first convention. | ||
690 | */ | ||
691 | static int ad7879_read(struct i2c_client *client, u8 reg) | ||
692 | { | ||
693 | return swab16(i2c_smbus_read_word_data(client, reg)); | ||
694 | } | ||
695 | |||
696 | static int ad7879_write(struct i2c_client *client, u8 reg, u16 val) | ||
697 | { | ||
698 | return i2c_smbus_write_word_data(client, reg, swab16(val)); | ||
699 | } | ||
700 | |||
701 | static void ad7879_collect(struct ad7879 *ts) | ||
702 | { | ||
703 | int i; | ||
704 | |||
705 | for (i = 0; i < AD7879_NR_SENSE; i++) | ||
706 | ts->conversion_data[i] = ad7879_read(ts->bus, | ||
707 | AD7879_REG_XPLUS + i); | ||
708 | } | ||
709 | |||
710 | static int __devinit ad7879_probe(struct i2c_client *client, | ||
711 | const struct i2c_device_id *id) | ||
712 | { | ||
713 | struct ad7879 *ts; | ||
714 | int error; | ||
715 | |||
716 | if (!i2c_check_functionality(client->adapter, | ||
717 | I2C_FUNC_SMBUS_WORD_DATA)) { | ||
718 | dev_err(&client->dev, "SMBUS Word Data not Supported\n"); | ||
719 | return -EIO; | ||
720 | } | ||
721 | |||
722 | ts = kzalloc(sizeof(struct ad7879), GFP_KERNEL); | ||
723 | if (!ts) | ||
724 | return -ENOMEM; | ||
725 | |||
726 | i2c_set_clientdata(client, ts); | ||
727 | ts->bus = client; | ||
728 | |||
729 | error = ad7879_construct(client, ts); | ||
730 | if (error) { | ||
731 | i2c_set_clientdata(client, NULL); | ||
732 | kfree(ts); | ||
733 | } | ||
734 | |||
735 | return 0; | ||
736 | } | ||
737 | |||
738 | static int __devexit ad7879_remove(struct i2c_client *client) | ||
739 | { | ||
740 | struct ad7879 *ts = dev_get_drvdata(&client->dev); | ||
741 | |||
742 | ad7879_destroy(client, ts); | ||
743 | i2c_set_clientdata(client, NULL); | ||
744 | kfree(ts); | ||
745 | |||
746 | return 0; | ||
747 | } | ||
748 | |||
749 | static const struct i2c_device_id ad7879_id[] = { | ||
750 | { "ad7879", 0 }, | ||
751 | { } | ||
752 | }; | ||
753 | MODULE_DEVICE_TABLE(i2c, ad7879_id); | ||
754 | |||
755 | static struct i2c_driver ad7879_driver = { | ||
756 | .driver = { | ||
757 | .name = "ad7879", | ||
758 | .owner = THIS_MODULE, | ||
759 | }, | ||
760 | .probe = ad7879_probe, | ||
761 | .remove = __devexit_p(ad7879_remove), | ||
762 | .suspend = ad7879_suspend, | ||
763 | .resume = ad7879_resume, | ||
764 | .id_table = ad7879_id, | ||
765 | }; | ||
766 | |||
767 | static int __init ad7879_init(void) | ||
768 | { | ||
769 | return i2c_add_driver(&ad7879_driver); | ||
770 | } | ||
771 | module_init(ad7879_init); | ||
772 | |||
773 | static void __exit ad7879_exit(void) | ||
774 | { | ||
775 | i2c_del_driver(&ad7879_driver); | ||
776 | } | ||
777 | module_exit(ad7879_exit); | ||
778 | #endif | ||
779 | |||
780 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | ||
781 | MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver"); | ||
782 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/mainstone-wm97xx.c b/drivers/input/touchscreen/mainstone-wm97xx.c index 1d11e2be9ef8..dfa6a84ab50a 100644 --- a/drivers/input/touchscreen/mainstone-wm97xx.c +++ b/drivers/input/touchscreen/mainstone-wm97xx.c | |||
@@ -162,6 +162,7 @@ static int wm97xx_acc_pen_down(struct wm97xx *wm) | |||
162 | input_report_abs(wm->input_dev, ABS_X, x & 0xfff); | 162 | input_report_abs(wm->input_dev, ABS_X, x & 0xfff); |
163 | input_report_abs(wm->input_dev, ABS_Y, y & 0xfff); | 163 | input_report_abs(wm->input_dev, ABS_Y, y & 0xfff); |
164 | input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff); | 164 | input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff); |
165 | input_report_key(wm->input_dev, BTN_TOUCH, (p != 0)); | ||
165 | input_sync(wm->input_dev); | 166 | input_sync(wm->input_dev); |
166 | reads++; | 167 | reads++; |
167 | } while (reads < cinfo[sp_idx].reads); | 168 | } while (reads < cinfo[sp_idx].reads); |
@@ -245,7 +246,7 @@ static void wm97xx_irq_enable(struct wm97xx *wm, int enable) | |||
245 | if (enable) | 246 | if (enable) |
246 | enable_irq(wm->pen_irq); | 247 | enable_irq(wm->pen_irq); |
247 | else | 248 | else |
248 | disable_irq(wm->pen_irq); | 249 | disable_irq_nosync(wm->pen_irq); |
249 | } | 250 | } |
250 | 251 | ||
251 | static struct wm97xx_mach_ops mainstone_mach_ops = { | 252 | static struct wm97xx_mach_ops mainstone_mach_ops = { |
diff --git a/drivers/input/touchscreen/ucb1400_ts.c b/drivers/input/touchscreen/ucb1400_ts.c index 54986627def0..e868264fe799 100644 --- a/drivers/input/touchscreen/ucb1400_ts.c +++ b/drivers/input/touchscreen/ucb1400_ts.c | |||
@@ -151,12 +151,14 @@ static void ucb1400_ts_evt_add(struct input_dev *idev, u16 pressure, u16 x, u16 | |||
151 | input_report_abs(idev, ABS_X, x); | 151 | input_report_abs(idev, ABS_X, x); |
152 | input_report_abs(idev, ABS_Y, y); | 152 | input_report_abs(idev, ABS_Y, y); |
153 | input_report_abs(idev, ABS_PRESSURE, pressure); | 153 | input_report_abs(idev, ABS_PRESSURE, pressure); |
154 | input_report_key(idev, BTN_TOUCH, 1); | ||
154 | input_sync(idev); | 155 | input_sync(idev); |
155 | } | 156 | } |
156 | 157 | ||
157 | static void ucb1400_ts_event_release(struct input_dev *idev) | 158 | static void ucb1400_ts_event_release(struct input_dev *idev) |
158 | { | 159 | { |
159 | input_report_abs(idev, ABS_PRESSURE, 0); | 160 | input_report_abs(idev, ABS_PRESSURE, 0); |
161 | input_report_key(idev, BTN_TOUCH, 0); | ||
160 | input_sync(idev); | 162 | input_sync(idev); |
161 | } | 163 | } |
162 | 164 | ||
@@ -377,7 +379,8 @@ static int ucb1400_ts_probe(struct platform_device *dev) | |||
377 | ucb->ts_idev->id.product = ucb->id; | 379 | ucb->ts_idev->id.product = ucb->id; |
378 | ucb->ts_idev->open = ucb1400_ts_open; | 380 | ucb->ts_idev->open = ucb1400_ts_open; |
379 | ucb->ts_idev->close = ucb1400_ts_close; | 381 | ucb->ts_idev->close = ucb1400_ts_close; |
380 | ucb->ts_idev->evbit[0] = BIT_MASK(EV_ABS); | 382 | ucb->ts_idev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); |
383 | ucb->ts_idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | ||
381 | 384 | ||
382 | ucb1400_adc_enable(ucb->ac97); | 385 | ucb1400_adc_enable(ucb->ac97); |
383 | x_res = ucb1400_ts_read_xres(ucb); | 386 | x_res = ucb1400_ts_read_xres(ucb); |
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c index d15aa11d7056..cec480bffe38 100644 --- a/drivers/input/touchscreen/wm97xx-core.c +++ b/drivers/input/touchscreen/wm97xx-core.c | |||
@@ -409,6 +409,7 @@ static int wm97xx_read_samples(struct wm97xx *wm) | |||
409 | wm->pen_is_down = 0; | 409 | wm->pen_is_down = 0; |
410 | dev_dbg(wm->dev, "pen up\n"); | 410 | dev_dbg(wm->dev, "pen up\n"); |
411 | input_report_abs(wm->input_dev, ABS_PRESSURE, 0); | 411 | input_report_abs(wm->input_dev, ABS_PRESSURE, 0); |
412 | input_report_key(wm->input_dev, BTN_TOUCH, 0); | ||
412 | input_sync(wm->input_dev); | 413 | input_sync(wm->input_dev); |
413 | } else if (!(rc & RC_AGAIN)) { | 414 | } else if (!(rc & RC_AGAIN)) { |
414 | /* We need high frequency updates only while | 415 | /* We need high frequency updates only while |
@@ -433,6 +434,7 @@ static int wm97xx_read_samples(struct wm97xx *wm) | |||
433 | input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff); | 434 | input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff); |
434 | input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff); | 435 | input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff); |
435 | input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff); | 436 | input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff); |
437 | input_report_key(wm->input_dev, BTN_TOUCH, 1); | ||
436 | input_sync(wm->input_dev); | 438 | input_sync(wm->input_dev); |
437 | wm->pen_is_down = 1; | 439 | wm->pen_is_down = 1; |
438 | wm->ts_reader_interval = wm->ts_reader_min_interval; | 440 | wm->ts_reader_interval = wm->ts_reader_min_interval; |
@@ -628,18 +630,21 @@ static int wm97xx_probe(struct device *dev) | |||
628 | wm->input_dev->phys = "wm97xx"; | 630 | wm->input_dev->phys = "wm97xx"; |
629 | wm->input_dev->open = wm97xx_ts_input_open; | 631 | wm->input_dev->open = wm97xx_ts_input_open; |
630 | wm->input_dev->close = wm97xx_ts_input_close; | 632 | wm->input_dev->close = wm97xx_ts_input_close; |
631 | set_bit(EV_ABS, wm->input_dev->evbit); | 633 | |
632 | set_bit(ABS_X, wm->input_dev->absbit); | 634 | __set_bit(EV_ABS, wm->input_dev->evbit); |
633 | set_bit(ABS_Y, wm->input_dev->absbit); | 635 | __set_bit(EV_KEY, wm->input_dev->evbit); |
634 | set_bit(ABS_PRESSURE, wm->input_dev->absbit); | 636 | __set_bit(BTN_TOUCH, wm->input_dev->keybit); |
637 | |||
635 | input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1], | 638 | input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1], |
636 | abs_x[2], 0); | 639 | abs_x[2], 0); |
637 | input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1], | 640 | input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1], |
638 | abs_y[2], 0); | 641 | abs_y[2], 0); |
639 | input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1], | 642 | input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1], |
640 | abs_p[2], 0); | 643 | abs_p[2], 0); |
644 | |||
641 | input_set_drvdata(wm->input_dev, wm); | 645 | input_set_drvdata(wm->input_dev, wm); |
642 | wm->input_dev->dev.parent = dev; | 646 | wm->input_dev->dev.parent = dev; |
647 | |||
643 | ret = input_register_device(wm->input_dev); | 648 | ret = input_register_device(wm->input_dev); |
644 | if (ret < 0) | 649 | if (ret < 0) |
645 | goto dev_alloc_err; | 650 | goto dev_alloc_err; |
diff --git a/drivers/input/touchscreen/zylonite-wm97xx.c b/drivers/input/touchscreen/zylonite-wm97xx.c new file mode 100644 index 000000000000..41e4359c277c --- /dev/null +++ b/drivers/input/touchscreen/zylonite-wm97xx.c | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | * zylonite-wm97xx.c -- Zylonite Continuous Touch screen driver | ||
3 | * | ||
4 | * Copyright 2004, 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
6 | * Parts Copyright : Ian Molton <spyro@f2s.com> | ||
7 | * Andrew Zabolotny <zap@homelink.ru> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the | ||
11 | * Free Software Foundation; either version 2 of the License, or (at your | ||
12 | * option) any later version. | ||
13 | * | ||
14 | * Notes: | ||
15 | * This is a wm97xx extended touch driver supporting interrupt driven | ||
16 | * and continuous operation on Marvell Zylonite development systems | ||
17 | * (which have a WM9713 on board). | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/moduleparam.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/irq.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/wm97xx.h> | ||
29 | |||
30 | #include <mach/hardware.h> | ||
31 | #include <mach/mfp.h> | ||
32 | #include <mach/regs-ac97.h> | ||
33 | |||
34 | struct continuous { | ||
35 | u16 id; /* codec id */ | ||
36 | u8 code; /* continuous code */ | ||
37 | u8 reads; /* number of coord reads per read cycle */ | ||
38 | u32 speed; /* number of coords per second */ | ||
39 | }; | ||
40 | |||
41 | #define WM_READS(sp) ((sp / HZ) + 1) | ||
42 | |||
43 | static const struct continuous cinfo[] = { | ||
44 | { WM9713_ID2, 0, WM_READS(94), 94 }, | ||
45 | { WM9713_ID2, 1, WM_READS(120), 120 }, | ||
46 | { WM9713_ID2, 2, WM_READS(154), 154 }, | ||
47 | { WM9713_ID2, 3, WM_READS(188), 188 }, | ||
48 | }; | ||
49 | |||
50 | /* continuous speed index */ | ||
51 | static int sp_idx; | ||
52 | |||
53 | /* | ||
54 | * Pen sampling frequency (Hz) in continuous mode. | ||
55 | */ | ||
56 | static int cont_rate = 200; | ||
57 | module_param(cont_rate, int, 0); | ||
58 | MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)"); | ||
59 | |||
60 | /* | ||
61 | * Pressure readback. | ||
62 | * | ||
63 | * Set to 1 to read back pen down pressure | ||
64 | */ | ||
65 | static int pressure; | ||
66 | module_param(pressure, int, 0); | ||
67 | MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)"); | ||
68 | |||
69 | /* | ||
70 | * AC97 touch data slot. | ||
71 | * | ||
72 | * Touch screen readback data ac97 slot | ||
73 | */ | ||
74 | static int ac97_touch_slot = 5; | ||
75 | module_param(ac97_touch_slot, int, 0); | ||
76 | MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number"); | ||
77 | |||
78 | |||
79 | /* flush AC97 slot 5 FIFO machines */ | ||
80 | static void wm97xx_acc_pen_up(struct wm97xx *wm) | ||
81 | { | ||
82 | int i; | ||
83 | |||
84 | msleep(1); | ||
85 | |||
86 | for (i = 0; i < 16; i++) | ||
87 | MODR; | ||
88 | } | ||
89 | |||
90 | static int wm97xx_acc_pen_down(struct wm97xx *wm) | ||
91 | { | ||
92 | u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES; | ||
93 | int reads = 0; | ||
94 | static u16 last, tries; | ||
95 | |||
96 | /* When the AC97 queue has been drained we need to allow time | ||
97 | * to buffer up samples otherwise we end up spinning polling | ||
98 | * for samples. The controller can't have a suitably low | ||
99 | * threashold set to use the notifications it gives. | ||
100 | */ | ||
101 | msleep(1); | ||
102 | |||
103 | if (tries > 5) { | ||
104 | tries = 0; | ||
105 | return RC_PENUP; | ||
106 | } | ||
107 | |||
108 | x = MODR; | ||
109 | if (x == last) { | ||
110 | tries++; | ||
111 | return RC_AGAIN; | ||
112 | } | ||
113 | last = x; | ||
114 | do { | ||
115 | if (reads) | ||
116 | x = MODR; | ||
117 | y = MODR; | ||
118 | if (pressure) | ||
119 | p = MODR; | ||
120 | |||
121 | /* are samples valid */ | ||
122 | if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X || | ||
123 | (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y || | ||
124 | (p & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_PRES) | ||
125 | goto up; | ||
126 | |||
127 | /* coordinate is good */ | ||
128 | tries = 0; | ||
129 | input_report_abs(wm->input_dev, ABS_X, x & 0xfff); | ||
130 | input_report_abs(wm->input_dev, ABS_Y, y & 0xfff); | ||
131 | input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff); | ||
132 | input_report_key(wm->input_dev, BTN_TOUCH, (p != 0)); | ||
133 | input_sync(wm->input_dev); | ||
134 | reads++; | ||
135 | } while (reads < cinfo[sp_idx].reads); | ||
136 | up: | ||
137 | return RC_PENDOWN | RC_AGAIN; | ||
138 | } | ||
139 | |||
140 | static int wm97xx_acc_startup(struct wm97xx *wm) | ||
141 | { | ||
142 | int idx; | ||
143 | |||
144 | /* check we have a codec */ | ||
145 | if (wm->ac97 == NULL) | ||
146 | return -ENODEV; | ||
147 | |||
148 | /* Go you big red fire engine */ | ||
149 | for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) { | ||
150 | if (wm->id != cinfo[idx].id) | ||
151 | continue; | ||
152 | sp_idx = idx; | ||
153 | if (cont_rate <= cinfo[idx].speed) | ||
154 | break; | ||
155 | } | ||
156 | wm->acc_rate = cinfo[sp_idx].code; | ||
157 | wm->acc_slot = ac97_touch_slot; | ||
158 | dev_info(wm->dev, | ||
159 | "zylonite accelerated touchscreen driver, %d samples/sec\n", | ||
160 | cinfo[sp_idx].speed); | ||
161 | |||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | static void wm97xx_irq_enable(struct wm97xx *wm, int enable) | ||
166 | { | ||
167 | if (enable) | ||
168 | enable_irq(wm->pen_irq); | ||
169 | else | ||
170 | disable_irq_nosync(wm->pen_irq); | ||
171 | } | ||
172 | |||
173 | static struct wm97xx_mach_ops zylonite_mach_ops = { | ||
174 | .acc_enabled = 1, | ||
175 | .acc_pen_up = wm97xx_acc_pen_up, | ||
176 | .acc_pen_down = wm97xx_acc_pen_down, | ||
177 | .acc_startup = wm97xx_acc_startup, | ||
178 | .irq_enable = wm97xx_irq_enable, | ||
179 | .irq_gpio = WM97XX_GPIO_2, | ||
180 | }; | ||
181 | |||
182 | static int zylonite_wm97xx_probe(struct platform_device *pdev) | ||
183 | { | ||
184 | struct wm97xx *wm = platform_get_drvdata(pdev); | ||
185 | int gpio_touch_irq; | ||
186 | |||
187 | if (cpu_is_pxa320()) | ||
188 | gpio_touch_irq = mfp_to_gpio(MFP_PIN_GPIO15); | ||
189 | else | ||
190 | gpio_touch_irq = mfp_to_gpio(MFP_PIN_GPIO26); | ||
191 | |||
192 | wm->pen_irq = IRQ_GPIO(gpio_touch_irq); | ||
193 | set_irq_type(IRQ_GPIO(gpio_touch_irq), IRQ_TYPE_EDGE_BOTH); | ||
194 | |||
195 | wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN, | ||
196 | WM97XX_GPIO_POL_HIGH, | ||
197 | WM97XX_GPIO_STICKY, | ||
198 | WM97XX_GPIO_WAKE); | ||
199 | wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT, | ||
200 | WM97XX_GPIO_POL_HIGH, | ||
201 | WM97XX_GPIO_NOTSTICKY, | ||
202 | WM97XX_GPIO_NOWAKE); | ||
203 | |||
204 | return wm97xx_register_mach_ops(wm, &zylonite_mach_ops); | ||
205 | } | ||
206 | |||
207 | static int zylonite_wm97xx_remove(struct platform_device *pdev) | ||
208 | { | ||
209 | struct wm97xx *wm = platform_get_drvdata(pdev); | ||
210 | |||
211 | wm97xx_unregister_mach_ops(wm); | ||
212 | |||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | static struct platform_driver zylonite_wm97xx_driver = { | ||
217 | .probe = zylonite_wm97xx_probe, | ||
218 | .remove = zylonite_wm97xx_remove, | ||
219 | .driver = { | ||
220 | .name = "wm97xx-touch", | ||
221 | }, | ||
222 | }; | ||
223 | |||
224 | static int __init zylonite_wm97xx_init(void) | ||
225 | { | ||
226 | return platform_driver_register(&zylonite_wm97xx_driver); | ||
227 | } | ||
228 | |||
229 | static void __exit zylonite_wm97xx_exit(void) | ||
230 | { | ||
231 | platform_driver_unregister(&zylonite_wm97xx_driver); | ||
232 | } | ||
233 | |||
234 | module_init(zylonite_wm97xx_init); | ||
235 | module_exit(zylonite_wm97xx_exit); | ||
236 | |||
237 | /* Module information */ | ||
238 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
239 | MODULE_DESCRIPTION("wm97xx continuous touch driver for Zylonite"); | ||
240 | MODULE_LICENSE("GPL"); | ||