2 * input/touchscreen/omap/omap_ts.c
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>
9 * Assembled using driver code copyright the companies above.
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.
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.
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
25 * 12/12/2004 Srinath Modified and intergrated code for H2 and H3
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>
40 #include <asm/mach-types.h>
46 #define OMAP_TS_NAME "omap_ts"
48 static struct ts_device *__initdata ts_devs[] = {
49 #if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3)
52 #ifdef CONFIG_MACH_OMAP_OSK
55 #if defined(CONFIG_MACH_OMAP_INNOVATOR) && defined(CONFIG_ARCH_OMAP15XX)
60 static struct omap_ts_t ts_omap;
62 static int omap_ts_read(void)
64 u16 data[4] = { 0, 0, 0, 0 };
66 ts_omap.dev->read(data);
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);
73 DEBUG_TS("omap_ts_read: read x=%d,y=%d,p=%d\n", data[0], data[1],
79 static void omap_ts_timer(unsigned long data)
83 spin_lock_irqsave(&ts_omap.lock, flags);
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);
92 ts_omap.ts_timer.expires = jiffies + HZ / 100;
93 add_timer(&(ts_omap.ts_timer));
95 if (ts_omap.touched) {
96 DEBUG_TS("omap_ts_timer: pen up\n");
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,
102 input_sync(ts_omap.inputdevice);
103 input_report_key(ts_omap.inputdevice, BTN_TOUCH, 0);
105 if (!ts_omap.irq_enabled) {
106 ts_omap.irq_enabled = 1;
107 enable_irq(ts_omap.irq);
111 spin_unlock_irqrestore(&ts_omap.lock, flags);
114 static irqreturn_t omap_ts_handler(int irq, void *dev_id, struct pt_regs *regs)
116 spin_lock(&ts_omap.lock);
118 if (ts_omap.irq_enabled) {
119 ts_omap.irq_enabled = 0;
123 mod_timer(&ts_omap.ts_timer, jiffies + HZ / 100);
125 spin_unlock(&ts_omap.lock);
130 static int __init omap_ts_probe(struct platform_device *pdev)
133 int status = -ENODEV;
135 memset(&ts_omap, 0, sizeof(ts_omap));
137 ts_omap.inputdevice = input_allocate_device();
138 if (!ts_omap.inputdevice) {
142 spin_lock_init(&ts_omap.lock);
144 for (i = 0; i < ARRAY_SIZE(ts_devs); i++) {
145 if (!ts_devs[i] || !ts_devs[i]->probe)
147 status = ts_devs[i]->probe(&ts_omap);
149 ts_omap.dev = ts_devs[i];
155 input_free_device(ts_omap.inputdevice);
159 // Init acquisition timer function
160 init_timer(&ts_omap.ts_timer);
161 ts_omap.ts_timer.function = omap_ts_timer;
164 if (ts_omap.irq != -1) {
165 if (request_irq(ts_omap.irq, omap_ts_handler, ts_omap.irq_type,
166 OMAP_TS_NAME, &ts_omap)) {
168 "omap_ts.c: Could not allocate touchscreen IRQ!\n");
170 ts_omap.dev->remove();
171 input_free_device(ts_omap.inputdevice);
174 ts_omap.irq_enabled = 1;
176 printk(KERN_ERR "omap_ts.c: No touchscreen IRQ assigned!\n");
177 ts_omap.dev->remove();
178 input_free_device(ts_omap.inputdevice);
182 ts_omap.inputdevice->name = OMAP_TS_NAME;
183 ts_omap.inputdevice->dev = &pdev->dev;
184 ts_omap.inputdevice->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
185 ts_omap.inputdevice->keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
186 ts_omap.inputdevice->absbit[0] =
187 BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
188 input_register_device(ts_omap.inputdevice);
190 ts_omap.dev->enable();
192 printk("OMAP touchscreen driver initialized\n");
197 static int omap_ts_remove(struct platform_device *pdev)
199 ts_omap.dev->disable();
200 input_unregister_device(ts_omap.inputdevice);
201 if (ts_omap.irq != -1)
202 free_irq(ts_omap.irq, &ts_omap);
204 ts_omap.dev->remove();
209 static int omap_ts_suspend(struct platform_device *pdev, pm_message_t state)
211 ts_omap.dev->disable();
215 static int omap_ts_resume(struct platform_device *pdev)
217 ts_omap.dev->enable();
221 static void omap_ts_device_release(struct device *dev)
225 static struct platform_driver omap_ts_driver = {
226 .probe = omap_ts_probe,
227 .remove = omap_ts_remove,
228 .suspend = omap_ts_suspend,
229 .resume = omap_ts_resume,
231 .name = OMAP_TS_NAME,
235 static struct platform_device omap_ts_device = {
236 .name = OMAP_TS_NAME,
239 .release = omap_ts_device_release,
243 static int __init omap_ts_init(void)
247 ret = platform_device_register(&omap_ts_device);
251 ret = platform_driver_register(&omap_ts_driver);
253 platform_device_unregister(&omap_ts_device);
260 static void __exit omap_ts_exit(void)
262 platform_driver_unregister(&omap_ts_driver);
263 platform_device_unregister(&omap_ts_device);
266 module_init(omap_ts_init);
267 module_exit(omap_ts_exit);
269 MODULE_LICENSE("GPL");