Input: make needlessly global code static
[linux-2.6/x86.git] / drivers / input / touchscreen / mk712.c
blob3226830eea08432d144a0c04e208039632cf8b83
1 /*
2 * ICS MK712 touchscreen controller driver
4 * Copyright (c) 1999-2002 Transmeta Corporation
5 * Copyright (c) 2005 Rick Koch <n1gp@hotmail.com>
6 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
7 */
9 /*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
16 * This driver supports the ICS MicroClock MK712 TouchScreen controller,
17 * found in Gateway AOL Connected Touchpad computers.
19 * Documentation for ICS MK712 can be found at:
20 * http://www.icst.com/pdf/mk712.pdf
24 * 1999-12-18: original version, Daniel Quinlan
25 * 1999-12-19: added anti-jitter code, report pen-up events, fixed mk712_poll
26 * to use queue_empty, Nathan Laredo
27 * 1999-12-20: improved random point rejection, Nathan Laredo
28 * 2000-01-05: checked in new anti-jitter code, changed mouse protocol, fixed
29 * queue code, added module options, other fixes, Daniel Quinlan
30 * 2002-03-15: Clean up for kernel merge <alan@redhat.com>
31 * Fixed multi open race, fixed memory checks, fixed resource
32 * allocation, fixed close/powerdown bug, switched to new init
33 * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch
34 * 2005-02-05: Rewritten for the input layer, Vojtech Pavlik
38 #include <linux/module.h>
39 #include <linux/moduleparam.h>
40 #include <linux/kernel.h>
41 #include <linux/init.h>
42 #include <linux/errno.h>
43 #include <linux/delay.h>
44 #include <linux/ioport.h>
45 #include <linux/interrupt.h>
46 #include <linux/input.h>
47 #include <asm/io.h>
49 MODULE_AUTHOR("Daniel Quinlan <quinlan@pathname.com>, Vojtech Pavlik <vojtech@suse.cz>");
50 MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver");
51 MODULE_LICENSE("GPL");
53 static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */
54 module_param_named(io, mk712_io, uint, 0);
55 MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller");
57 static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */
58 module_param_named(irq, mk712_irq, uint, 0);
59 MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
61 /* eight 8-bit registers */
62 #define MK712_STATUS 0
63 #define MK712_X 2
64 #define MK712_Y 4
65 #define MK712_CONTROL 6
66 #define MK712_RATE 7
68 /* status */
69 #define MK712_STATUS_TOUCH 0x10
70 #define MK712_CONVERSION_COMPLETE 0x80
72 /* control */
73 #define MK712_ENABLE_INT 0x01
74 #define MK712_INT_ON_CONVERSION_COMPLETE 0x02
75 #define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS 0x04
76 #define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
77 #define MK712_READ_ONE_POINT 0x20
78 #define MK712_POWERUP 0x40
80 static struct input_dev *mk712_dev;
81 static DEFINE_SPINLOCK(mk712_lock);
83 static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
85 unsigned char status;
86 static int debounce = 1;
87 static unsigned short last_x;
88 static unsigned short last_y;
90 spin_lock(&mk712_lock);
91 input_regs(mk712_dev, regs);
93 status = inb(mk712_io + MK712_STATUS);
95 if (~status & MK712_CONVERSION_COMPLETE) {
96 debounce = 1;
97 goto end;
100 if (~status & MK712_STATUS_TOUCH)
102 debounce = 1;
103 input_report_key(mk712_dev, BTN_TOUCH, 0);
104 goto end;
107 if (debounce)
109 debounce = 0;
110 goto end;
113 input_report_key(mk712_dev, BTN_TOUCH, 1);
114 input_report_abs(mk712_dev, ABS_X, last_x);
115 input_report_abs(mk712_dev, ABS_Y, last_y);
117 end:
119 last_x = inw(mk712_io + MK712_X) & 0x0fff;
120 last_y = inw(mk712_io + MK712_Y) & 0x0fff;
121 input_sync(mk712_dev);
122 spin_unlock(&mk712_lock);
123 return IRQ_HANDLED;
126 static int mk712_open(struct input_dev *dev)
128 unsigned long flags;
130 spin_lock_irqsave(&mk712_lock, flags);
132 outb(0, mk712_io + MK712_CONTROL); /* Reset */
134 outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
135 MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
136 MK712_ENABLE_PERIODIC_CONVERSIONS |
137 MK712_POWERUP, mk712_io + MK712_CONTROL);
139 outb(10, mk712_io + MK712_RATE); /* 187 points per second */
141 spin_unlock_irqrestore(&mk712_lock, flags);
143 return 0;
146 static void mk712_close(struct input_dev *dev)
148 unsigned long flags;
150 spin_lock_irqsave(&mk712_lock, flags);
152 outb(0, mk712_io + MK712_CONTROL);
154 spin_unlock_irqrestore(&mk712_lock, flags);
157 static int __init mk712_init(void)
159 int err;
161 if (!request_region(mk712_io, 8, "mk712")) {
162 printk(KERN_WARNING "mk712: unable to get IO region\n");
163 return -ENODEV;
166 outb(0, mk712_io + MK712_CONTROL);
168 if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
169 (inw(mk712_io + MK712_Y) & 0xf000) ||
170 (inw(mk712_io + MK712_STATUS) & 0xf333)) {
171 printk(KERN_WARNING "mk712: device not present\n");
172 err = -ENODEV;
173 goto fail;
176 if (!(mk712_dev = input_allocate_device())) {
177 printk(KERN_ERR "mk712: not enough memory\n");
178 err = -ENOMEM;
179 goto fail;
182 mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
183 mk712_dev->phys = "isa0260/input0";
184 mk712_dev->id.bustype = BUS_ISA;
185 mk712_dev->id.vendor = 0x0005;
186 mk712_dev->id.product = 0x0001;
187 mk712_dev->id.version = 0x0100;
189 mk712_dev->open = mk712_open;
190 mk712_dev->close = mk712_close;
192 mk712_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
193 mk712_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
194 input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0);
195 input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0);
197 if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
198 printk(KERN_WARNING "mk712: unable to get IRQ\n");
199 err = -EBUSY;
200 goto fail;
203 input_register_device(mk712_dev);
204 return 0;
206 fail: input_free_device(mk712_dev);
207 release_region(mk712_io, 8);
208 return err;
211 static void __exit mk712_exit(void)
213 input_unregister_device(mk712_dev);
214 free_irq(mk712_irq, mk712_dev);
215 release_region(mk712_io, 8);
218 module_init(mk712_init);
219 module_exit(mk712_exit);