]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/input/touchscreen/omap/omap_ts.c
[PATCH] ARM: OMAP: OMAP touchscreen timer BUG
[linux-2.6-omap-h63xx.git] / drivers / input / touchscreen / omap / omap_ts.c
1 /*
2  * input/touchscreen/omap/omap_ts.c
3  *
4  * touchscreen input device driver for various TI OMAP boards
5  * Copyright (c) 2002 MontaVista Software Inc.
6  * Copyright (c) 2004 Texas Instruments, Inc.
7  * Cleanup and modularization 2004 by Dirk Behme <dirk.behme@de.bosch.com>
8  *
9  * Assembled using driver code copyright the companies above.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  * History:
25  * 12/12/2004    Srinath Modified and intergrated code for H2 and H3
26  *
27  */
28
29 #include <linux/errno.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/input.h>
34 #include <linux/init.h>
35 #include <linux/wait.h>
36 #include <linux/interrupt.h>
37 #include <linux/suspend.h>
38 #include <linux/platform_device.h>
39
40 #include <asm/mach-types.h>
41
42 //#define DEBUG
43
44 #include "omap_ts.h"
45
46 #define OMAP_TS_NAME    "omap_ts"
47
48 static struct ts_device *__initdata ts_devs[] = {
49 #if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3)
50         &hx_ts,
51 #endif
52 #ifdef CONFIG_MACH_OMAP_OSK
53         &osk_ts,
54 #endif
55 #if defined(CONFIG_MACH_OMAP_INNOVATOR) && defined(CONFIG_ARCH_OMAP15XX)
56         &innovator1510_ts,
57 #endif
58 };
59
60 static struct omap_ts_t ts_omap;
61
62 static int omap_ts_read(void)
63 {
64         u16 data[4] = { 0, 0, 0, 0 };
65
66         ts_omap.dev->read(data);
67
68         input_report_abs(&(ts_omap.inputdevice), ABS_X, data[0]);
69         input_report_abs(&(ts_omap.inputdevice), ABS_Y, data[1]);
70         input_report_abs(&(ts_omap.inputdevice), ABS_PRESSURE, data[2]);
71         input_sync(&(ts_omap.inputdevice));
72
73         DEBUG_TS("omap_ts_read: read x=%d,y=%d,p=%d\n", data[0], data[1],
74                  data[2]);
75
76         return 0;
77 }
78
79 static void omap_ts_timer(unsigned long data)
80 {
81         unsigned long flags;
82
83         spin_lock_irqsave(&ts_omap.lock, flags);
84
85         if (!ts_omap.dev->penup()) {
86                 if (!ts_omap.touched) {
87                         DEBUG_TS("omap_ts_timer: pen down\n");
88                         input_report_key(&(ts_omap.inputdevice), BTN_TOUCH, 1);
89                 }
90                 ts_omap.touched = 1;
91                 omap_ts_read();
92                 ts_omap.ts_timer.expires = jiffies + HZ / 100;
93                 add_timer(&(ts_omap.ts_timer));
94         } else {
95                 if (ts_omap.touched) {
96                         DEBUG_TS("omap_ts_timer: pen up\n");
97                         ts_omap.touched = 0;
98                         input_report_abs(&(ts_omap.inputdevice), ABS_X, 0);
99                         input_report_abs(&(ts_omap.inputdevice), ABS_Y, 0);
100                         input_report_abs(&(ts_omap.inputdevice), ABS_PRESSURE,
101                                          0);
102                         input_sync(&(ts_omap.inputdevice));
103                         input_report_key(&(ts_omap.inputdevice), BTN_TOUCH, 0);
104                 }
105                 if (!ts_omap.irq_enabled) {
106                         ts_omap.irq_enabled = 1;
107                         enable_irq(ts_omap.irq);
108                 }
109         }
110
111         spin_unlock_irqrestore(&ts_omap.lock, flags);
112 }
113
114 static irqreturn_t omap_ts_handler(int irq, void *dev_id, struct pt_regs *regs)
115 {
116         spin_lock(&ts_omap.lock);
117
118         if (ts_omap.irq_enabled) {
119                 ts_omap.irq_enabled = 0;
120                 disable_irq(irq);
121         }
122         // restart acquire
123         mod_timer(&ts_omap.ts_timer, jiffies + HZ / 100);
124
125         spin_unlock(&ts_omap.lock);
126
127         return IRQ_HANDLED;
128 }
129
130 static int __init omap_ts_probe(struct platform_device *pdev)
131 {
132         int i;
133         int status = -ENODEV;
134
135         memset(&ts_omap, 0, sizeof(ts_omap));
136         spin_lock_init(&ts_omap.lock);
137
138         for (i = 0; i < ARRAY_SIZE(ts_devs); i++) {
139                 if (!ts_devs[i] || !ts_devs[i]->probe)
140                         continue;
141                 status = ts_devs[i]->probe(&ts_omap);
142                 if (status == 0) {
143                         ts_omap.dev = ts_devs[i];
144                         break;
145                 }
146         }
147
148         if (status != 0)
149                 return status;
150
151         // Init acquisition timer function
152         init_timer(&ts_omap.ts_timer);
153         ts_omap.ts_timer.function = omap_ts_timer;
154
155         /* request irq */
156         if (ts_omap.irq != -1) {
157                 if (request_irq(ts_omap.irq, omap_ts_handler, 0,
158                                 OMAP_TS_NAME, &ts_omap)) {
159                         printk(KERN_ERR
160           "omap_ts.c: Could not allocate touchscreen IRQ!\n");
161                         ts_omap.irq = -1;
162                         return -EINVAL;
163                 }
164                 ts_omap.irq_enabled = 1;
165         } else {
166                 printk(KERN_ERR "omap_ts.c: No touchscreen IRQ assigned!\n");
167                 return -EINVAL;
168         }
169
170         init_input_dev(&(ts_omap.inputdevice));
171         ts_omap.inputdevice.name = OMAP_TS_NAME;
172         ts_omap.inputdevice.dev = &pdev->dev;
173         ts_omap.inputdevice.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
174         ts_omap.inputdevice.keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
175         ts_omap.inputdevice.absbit[0] =
176             BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
177         input_register_device(&(ts_omap.inputdevice));
178
179         ts_omap.dev->enable();
180
181         printk("OMAP touchscreen driver initialized\n");
182
183         return 0;
184 }
185
186 static int omap_ts_remove(struct platform_device *pdev)
187 {
188         ts_omap.dev->disable();
189         input_unregister_device(&ts_omap.inputdevice);
190         if (ts_omap.irq != -1)
191                 free_irq(ts_omap.irq, &ts_omap);
192
193         ts_omap.dev->remove();
194
195         return 0;
196 }
197
198 static int omap_ts_suspend(struct platform_device *pdev, pm_message_t state)
199 {
200         ts_omap.dev->disable();
201         return 0;
202 }
203
204 static int omap_ts_resume(struct platform_device *pdev)
205 {
206         ts_omap.dev->enable();
207         return 0;
208 }
209
210 static void omap_ts_device_release(struct device *dev)
211 {
212         /* Nothing */
213 }
214 static struct platform_driver omap_ts_driver = {
215         .probe          = omap_ts_probe,
216         .remove         = omap_ts_remove,
217         .suspend        = omap_ts_suspend,
218         .resume         = omap_ts_resume,
219         .driver {
220                 .name   = OMAP_TS_NAME,
221         },
222 };
223
224 static struct platform_device omap_ts_device = {
225         .name           = OMAP_TS_NAME,
226         .id             = -1,
227         .dev = {
228                 .release        = omap_ts_device_release,
229         },
230 };
231
232 static int __init omap_ts_init(void)
233 {
234         int ret;
235
236         ret = platform_device_register(&omap_ts_device);
237         if (ret != 0)
238                 return -ENODEV;
239
240         ret = platform_driver_register(&omap_ts_driver);
241         if (ret != 0) {
242                 platform_device_unregister(&omap_ts_device);
243                 return -ENODEV;
244         }
245
246         return 0;
247 }
248
249 static void __exit omap_ts_exit(void)
250 {
251         platform_driver_unregister(&omap_ts_driver);
252         platform_device_unregister(&omap_ts_device);
253 }
254
255 module_init(omap_ts_init);
256 module_exit(omap_ts_exit);
257
258 MODULE_LICENSE("GPL");