diff options
author | Wan ZongShun <mcuos.com@gmail.com> | 2009-06-11 02:27:22 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2009-06-11 05:03:39 -0400 |
commit | 7e3f73754e489e8c7742eaba15b608757b5bbb28 (patch) | |
tree | 88a5910cb5aa11bc6e7515baa479d6b3b4296a87 /drivers/input | |
parent | 4894e4aca82aca927d0404ce61f021f790de4b1e (diff) |
Input: add support for touchscreen on W90P910 ARM platform
The touchscreen works in two modes, wait trigger mode and auto-semi
mode. The device starts in wait trigger mode and waits until pressure
is detected, then device sets WT_INT bit and raises an interrupt.
The driver should put the device into auto-semi mode and prepare for
reading first X and then Y coordinates. When coordinate data is ready
the driver sets ADC_INT bit and raises interrupt again.
[dtor@mail.ru: various cleanups]
Signed-off-by: Wan ZongShun <mcuos.com@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 8 | ||||
-rw-r--r-- | drivers/input/touchscreen/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/touchscreen/w90p910_ts.c | 350 |
3 files changed, 359 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 1b4a1675cbc8..72e2712c7e2a 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -490,4 +490,12 @@ config TOUCHSCREEN_TSC2007 | |||
490 | To compile this driver as a module, choose M here: the | 490 | To compile this driver as a module, choose M here: the |
491 | module will be called tsc2007. | 491 | module will be called tsc2007. |
492 | 492 | ||
493 | config TOUCHSCREEN_W90X900 | ||
494 | tristate "W90P910 touchscreen driver" | ||
495 | help | ||
496 | Say Y here if you have a W90P910 based touchscreen. | ||
497 | |||
498 | To compile this driver as a module, choose M here: the | ||
499 | module will be called w90p910_ts. | ||
500 | |||
493 | endif | 501 | endif |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 10e0be6cea43..3e1c5e0b952f 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -39,3 +39,4 @@ wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9713) += wm9713.o | |||
39 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_ATMEL) += atmel-wm97xx.o | 39 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_ATMEL) += atmel-wm97xx.o |
40 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o | 40 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o |
41 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o | 41 | obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o |
42 | obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o | ||
diff --git a/drivers/input/touchscreen/w90p910_ts.c b/drivers/input/touchscreen/w90p910_ts.c new file mode 100644 index 000000000000..6071f5882572 --- /dev/null +++ b/drivers/input/touchscreen/w90p910_ts.c | |||
@@ -0,0 +1,350 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Nuvoton technology corporation. | ||
3 | * | ||
4 | * Wan ZongShun <mcuos.com@gmail.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation;version 2 of the License. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/delay.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/input.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | |||
19 | /* ADC controller bit defines */ | ||
20 | #define ADC_DELAY 0xf00 | ||
21 | #define ADC_DOWN 0x01 | ||
22 | #define ADC_TSC_Y (0x01 << 8) | ||
23 | #define ADC_TSC_X (0x00 << 8) | ||
24 | #define TSC_FOURWIRE (~(0x03 << 1)) | ||
25 | #define ADC_CLK_EN (0x01 << 28) /* ADC clock enable */ | ||
26 | #define ADC_READ_CON (0x01 << 12) | ||
27 | #define ADC_CONV (0x01 << 13) | ||
28 | #define ADC_SEMIAUTO (0x01 << 14) | ||
29 | #define ADC_WAITTRIG (0x03 << 14) | ||
30 | #define ADC_RST1 (0x01 << 16) | ||
31 | #define ADC_RST0 (0x00 << 16) | ||
32 | #define ADC_EN (0x01 << 17) | ||
33 | #define ADC_INT (0x01 << 18) | ||
34 | #define WT_INT (0x01 << 20) | ||
35 | #define ADC_INT_EN (0x01 << 21) | ||
36 | #define LVD_INT_EN (0x01 << 22) | ||
37 | #define WT_INT_EN (0x01 << 23) | ||
38 | #define ADC_DIV (0x04 << 1) /* div = 6 */ | ||
39 | |||
40 | enum ts_state { | ||
41 | TS_WAIT_NEW_PACKET, /* We are waiting next touch report */ | ||
42 | TS_WAIT_X_COORD, /* We are waiting for ADC to report X coord */ | ||
43 | TS_WAIT_Y_COORD, /* We are waiting for ADC to report Y coord */ | ||
44 | TS_IDLE, /* Input device is closed, don't do anything */ | ||
45 | }; | ||
46 | |||
47 | struct w90p910_ts { | ||
48 | struct input_dev *input; | ||
49 | struct timer_list timer; | ||
50 | int irq_num; | ||
51 | void __iomem *clocken; | ||
52 | void __iomem *ts_reg; | ||
53 | spinlock_t lock; | ||
54 | enum ts_state state; | ||
55 | }; | ||
56 | |||
57 | static void w90p910_report_event(struct w90p910_ts *w90p910_ts, bool down) | ||
58 | { | ||
59 | struct input_dev *dev = w90p910_ts->input; | ||
60 | |||
61 | if (down) { | ||
62 | input_report_abs(dev, ABS_X, | ||
63 | __raw_readl(w90p910_ts->ts_reg + 0x0c)); | ||
64 | input_report_abs(dev, ABS_Y, | ||
65 | __raw_readl(w90p910_ts->ts_reg + 0x10)); | ||
66 | } | ||
67 | |||
68 | input_report_key(dev, BTN_TOUCH, down); | ||
69 | input_sync(dev); | ||
70 | } | ||
71 | |||
72 | static void w90p910_prepare_x_reading(struct w90p910_ts *w90p910_ts) | ||
73 | { | ||
74 | unsigned long ctlreg; | ||
75 | |||
76 | __raw_writel(ADC_TSC_X, w90p910_ts->ts_reg + 0x04); | ||
77 | ctlreg = __raw_readl(w90p910_ts->ts_reg); | ||
78 | ctlreg &= ~(ADC_WAITTRIG | WT_INT | WT_INT_EN); | ||
79 | ctlreg |= ADC_SEMIAUTO | ADC_INT_EN | ADC_CONV; | ||
80 | __raw_writel(ctlreg, w90p910_ts->ts_reg); | ||
81 | |||
82 | w90p910_ts->state = TS_WAIT_X_COORD; | ||
83 | } | ||
84 | |||
85 | static void w90p910_prepare_y_reading(struct w90p910_ts *w90p910_ts) | ||
86 | { | ||
87 | unsigned long ctlreg; | ||
88 | |||
89 | __raw_writel(ADC_TSC_Y, w90p910_ts->ts_reg + 0x04); | ||
90 | ctlreg = __raw_readl(w90p910_ts->ts_reg); | ||
91 | ctlreg &= ~(ADC_WAITTRIG | ADC_INT | WT_INT_EN); | ||
92 | ctlreg |= ADC_SEMIAUTO | ADC_INT_EN | ADC_CONV; | ||
93 | __raw_writel(ctlreg, w90p910_ts->ts_reg); | ||
94 | |||
95 | w90p910_ts->state = TS_WAIT_Y_COORD; | ||
96 | } | ||
97 | |||
98 | static void w90p910_prepare_next_packet(struct w90p910_ts *w90p910_ts) | ||
99 | { | ||
100 | unsigned long ctlreg; | ||
101 | |||
102 | ctlreg = __raw_readl(w90p910_ts->ts_reg); | ||
103 | ctlreg &= ~(ADC_INT | ADC_INT_EN | ADC_SEMIAUTO | ADC_CONV); | ||
104 | ctlreg |= ADC_WAITTRIG | WT_INT_EN; | ||
105 | __raw_writel(ctlreg, w90p910_ts->ts_reg); | ||
106 | |||
107 | w90p910_ts->state = TS_WAIT_NEW_PACKET; | ||
108 | } | ||
109 | |||
110 | static irqreturn_t w90p910_ts_interrupt(int irq, void *dev_id) | ||
111 | { | ||
112 | struct w90p910_ts *w90p910_ts = dev_id; | ||
113 | unsigned long flags; | ||
114 | |||
115 | spin_lock_irqsave(&w90p910_ts->lock, flags); | ||
116 | |||
117 | switch (w90p910_ts->state) { | ||
118 | case TS_WAIT_NEW_PACKET: | ||
119 | /* | ||
120 | * The controller only generates interrupts when pen | ||
121 | * is down. | ||
122 | */ | ||
123 | del_timer(&w90p910_ts->timer); | ||
124 | w90p910_prepare_x_reading(w90p910_ts); | ||
125 | break; | ||
126 | |||
127 | |||
128 | case TS_WAIT_X_COORD: | ||
129 | w90p910_prepare_y_reading(w90p910_ts); | ||
130 | break; | ||
131 | |||
132 | case TS_WAIT_Y_COORD: | ||
133 | w90p910_report_event(w90p910_ts, true); | ||
134 | w90p910_prepare_next_packet(w90p910_ts); | ||
135 | mod_timer(&w90p910_ts->timer, jiffies + msecs_to_jiffies(100)); | ||
136 | break; | ||
137 | |||
138 | case TS_IDLE: | ||
139 | break; | ||
140 | } | ||
141 | |||
142 | spin_unlock_irqrestore(&w90p910_ts->lock, flags); | ||
143 | |||
144 | return IRQ_HANDLED; | ||
145 | } | ||
146 | |||
147 | static void w90p910_check_pen_up(unsigned long data) | ||
148 | { | ||
149 | struct w90p910_ts *w90p910_ts = (struct w90p910_ts *) data; | ||
150 | unsigned long flags; | ||
151 | |||
152 | spin_lock_irqsave(&w90p910_ts->lock, flags); | ||
153 | |||
154 | if (w90p910_ts->state == TS_WAIT_NEW_PACKET && | ||
155 | !(__raw_readl(w90p910_ts->ts_reg + 0x04) & ADC_DOWN)) { | ||
156 | |||
157 | w90p910_report_event(w90p910_ts, false); | ||
158 | } | ||
159 | |||
160 | spin_unlock_irqrestore(&w90p910_ts->lock, flags); | ||
161 | } | ||
162 | |||
163 | static int w90p910_open(struct input_dev *dev) | ||
164 | { | ||
165 | struct w90p910_ts *w90p910_ts = input_get_drvdata(dev); | ||
166 | unsigned long val; | ||
167 | |||
168 | /* enable the ADC clock */ | ||
169 | val = __raw_readl(w90p910_ts->clocken); | ||
170 | __raw_writel(val | ADC_CLK_EN, w90p910_ts->clocken); | ||
171 | |||
172 | __raw_writel(ADC_RST1, w90p910_ts->ts_reg); | ||
173 | msleep(1); | ||
174 | __raw_writel(ADC_RST0, w90p910_ts->ts_reg); | ||
175 | msleep(1); | ||
176 | |||
177 | /* set delay and screen type */ | ||
178 | val = __raw_readl(w90p910_ts->ts_reg + 0x04); | ||
179 | __raw_writel(val & TSC_FOURWIRE, w90p910_ts->ts_reg + 0x04); | ||
180 | __raw_writel(ADC_DELAY, w90p910_ts->ts_reg + 0x08); | ||
181 | |||
182 | w90p910_ts->state = TS_WAIT_NEW_PACKET; | ||
183 | wmb(); | ||
184 | |||
185 | /* set trigger mode */ | ||
186 | val = __raw_readl(w90p910_ts->ts_reg); | ||
187 | val |= ADC_WAITTRIG | ADC_DIV | ADC_EN | WT_INT_EN; | ||
188 | __raw_writel(val, w90p910_ts->ts_reg); | ||
189 | |||
190 | return 0; | ||
191 | } | ||
192 | |||
193 | static void w90p910_close(struct input_dev *dev) | ||
194 | { | ||
195 | struct w90p910_ts *w90p910_ts = input_get_drvdata(dev); | ||
196 | unsigned long val; | ||
197 | |||
198 | /* disable trigger mode */ | ||
199 | |||
200 | spin_lock_irq(&w90p910_ts->lock); | ||
201 | |||
202 | w90p910_ts->state = TS_IDLE; | ||
203 | |||
204 | val = __raw_readl(w90p910_ts->ts_reg); | ||
205 | val &= ~(ADC_WAITTRIG | ADC_DIV | ADC_EN | WT_INT_EN | ADC_INT_EN); | ||
206 | __raw_writel(val, w90p910_ts->ts_reg); | ||
207 | |||
208 | spin_unlock_irq(&w90p910_ts->lock); | ||
209 | |||
210 | /* Now that interrupts are shut off we can safely delete timer */ | ||
211 | del_timer_sync(&w90p910_ts->timer); | ||
212 | |||
213 | /* stop the ADC clock */ | ||
214 | val = __raw_readl(w90p910_ts->clocken); | ||
215 | __raw_writel(val & ~ADC_CLK_EN, w90p910_ts->clocken); | ||
216 | } | ||
217 | |||
218 | static int __devinit w90x900ts_probe(struct platform_device *pdev) | ||
219 | { | ||
220 | struct w90p910_ts *w90p910_ts; | ||
221 | struct input_dev *input_dev; | ||
222 | struct resource *res; | ||
223 | int err; | ||
224 | |||
225 | w90p910_ts = kzalloc(sizeof(struct w90p910_ts), GFP_KERNEL); | ||
226 | input_dev = input_allocate_device(); | ||
227 | if (!w90p910_ts || !input_dev) { | ||
228 | err = -ENOMEM; | ||
229 | goto fail1; | ||
230 | } | ||
231 | |||
232 | w90p910_ts->input = input_dev; | ||
233 | w90p910_ts->state = TS_IDLE; | ||
234 | spin_lock_init(&w90p910_ts->lock); | ||
235 | setup_timer(&w90p910_ts->timer, w90p910_check_pen_up, | ||
236 | (unsigned long)&w90p910_ts); | ||
237 | |||
238 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
239 | if (!res) { | ||
240 | err = -ENXIO; | ||
241 | goto fail1; | ||
242 | } | ||
243 | |||
244 | if (!request_mem_region(res->start, res->end - res->start + 1, | ||
245 | pdev->name)) { | ||
246 | err = -EBUSY; | ||
247 | goto fail1; | ||
248 | } | ||
249 | |||
250 | w90p910_ts->ts_reg = ioremap(res->start, res->end - res->start + 1); | ||
251 | if (!w90p910_ts->ts_reg) { | ||
252 | err = -ENOMEM; | ||
253 | goto fail2; | ||
254 | } | ||
255 | |||
256 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
257 | if (!res) { | ||
258 | err = -ENXIO; | ||
259 | goto fail3; | ||
260 | } | ||
261 | |||
262 | w90p910_ts->clocken = (void __iomem *)res->start; | ||
263 | |||
264 | input_dev->name = "W90P910 TouchScreen"; | ||
265 | input_dev->phys = "w90p910ts/event0"; | ||
266 | input_dev->id.bustype = BUS_HOST; | ||
267 | input_dev->id.vendor = 0x0005; | ||
268 | input_dev->id.product = 0x0001; | ||
269 | input_dev->id.version = 0x0100; | ||
270 | input_dev->dev.parent = &pdev->dev; | ||
271 | input_dev->open = w90p910_open; | ||
272 | input_dev->close = w90p910_close; | ||
273 | |||
274 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); | ||
275 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | ||
276 | |||
277 | input_set_abs_params(input_dev, ABS_X, 0, 0x400, 0, 0); | ||
278 | input_set_abs_params(input_dev, ABS_Y, 0, 0x400, 0, 0); | ||
279 | |||
280 | input_set_drvdata(input_dev, w90p910_ts); | ||
281 | |||
282 | w90p910_ts->irq_num = platform_get_irq(pdev, 0); | ||
283 | if (request_irq(w90p910_ts->irq_num, w90p910_ts_interrupt, | ||
284 | IRQF_DISABLED, "w90p910ts", w90p910_ts)) { | ||
285 | err = -EBUSY; | ||
286 | goto fail3; | ||
287 | } | ||
288 | |||
289 | err = input_register_device(w90p910_ts->input); | ||
290 | if (err) | ||
291 | goto fail4; | ||
292 | |||
293 | platform_set_drvdata(pdev, w90p910_ts); | ||
294 | |||
295 | return 0; | ||
296 | |||
297 | fail4: free_irq(w90p910_ts->irq_num, w90p910_ts); | ||
298 | fail3: iounmap(w90p910_ts->ts_reg); | ||
299 | fail2: release_mem_region(res->start, res->end - res->start + 1); | ||
300 | fail1: input_free_device(input_dev); | ||
301 | kfree(w90p910_ts); | ||
302 | return err; | ||
303 | } | ||
304 | |||
305 | static int __devexit w90x900ts_remove(struct platform_device *pdev) | ||
306 | { | ||
307 | struct w90p910_ts *w90p910_ts = platform_get_drvdata(pdev); | ||
308 | struct resource *res; | ||
309 | |||
310 | free_irq(w90p910_ts->irq_num, w90p910_ts); | ||
311 | del_timer_sync(&w90p910_ts->timer); | ||
312 | iounmap(w90p910_ts->ts_reg); | ||
313 | |||
314 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
315 | release_mem_region(res->start, res->end - res->start + 1); | ||
316 | |||
317 | input_unregister_device(w90p910_ts->input); | ||
318 | kfree(w90p910_ts); | ||
319 | |||
320 | platform_set_drvdata(pdev, NULL); | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | static struct platform_driver w90x900ts_driver = { | ||
326 | .probe = w90x900ts_probe, | ||
327 | .remove = __devexit_p(w90x900ts_remove), | ||
328 | .driver = { | ||
329 | .name = "w90x900-ts", | ||
330 | .owner = THIS_MODULE, | ||
331 | }, | ||
332 | }; | ||
333 | |||
334 | static int __init w90x900ts_init(void) | ||
335 | { | ||
336 | return platform_driver_register(&w90x900ts_driver); | ||
337 | } | ||
338 | |||
339 | static void __exit w90x900ts_exit(void) | ||
340 | { | ||
341 | platform_driver_unregister(&w90x900ts_driver); | ||
342 | } | ||
343 | |||
344 | module_init(w90x900ts_init); | ||
345 | module_exit(w90x900ts_exit); | ||
346 | |||
347 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); | ||
348 | MODULE_DESCRIPTION("w90p910 touch screen driver!"); | ||
349 | MODULE_LICENSE("GPL"); | ||
350 | MODULE_ALIAS("platform:w90p910-ts"); | ||