blob: 44140feeffc503428a54399b591f1628f3842010 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ICS MK712 touchscreen controller driver
3 *
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 */
8
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.
13 */
14
15/*
16 * This driver supports the ICS MicroClock MK712 TouchScreen controller,
17 * found in Gateway AOL Connected Touchpad computers.
18 *
19 * Documentation for ICS MK712 can be found at:
Dmitry Torokhovde1b9632005-05-29 02:28:50 -050020 * http://www.icst.com/pdf/mk712.pdf
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
22
23/*
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
35 *
36 */
37
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>
48
49MODULE_AUTHOR("Daniel Quinlan <quinlan@pathname.com>, Vojtech Pavlik <vojtech@suse.cz>");
50MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver");
51MODULE_LICENSE("GPL");
52
53static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */
54module_param_named(io, mk712_io, uint, 0);
55MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller");
56
57static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */
58module_param_named(irq, mk712_irq, uint, 0);
59MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
60
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
67
68/* status */
69#define MK712_STATUS_TOUCH 0x10
70#define MK712_CONVERSION_COMPLETE 0x80
71
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
79
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050080static struct input_dev *mk712_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081static DEFINE_SPINLOCK(mk712_lock);
82
David Howells7d12e782006-10-05 14:55:46 +010083static irqreturn_t mk712_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 unsigned char status;
86 static int debounce = 1;
87 static unsigned short last_x;
88 static unsigned short last_y;
89
90 spin_lock(&mk712_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 status = inb(mk712_io + MK712_STATUS);
93
94 if (~status & MK712_CONVERSION_COMPLETE) {
95 debounce = 1;
96 goto end;
97 }
98
Dmitry Torokhov52c1f572006-11-05 22:40:03 -050099 if (~status & MK712_STATUS_TOUCH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 debounce = 1;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500101 input_report_key(mk712_dev, BTN_TOUCH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 goto end;
103 }
104
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500105 if (debounce) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 debounce = 0;
107 goto end;
108 }
109
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500110 input_report_key(mk712_dev, BTN_TOUCH, 1);
111 input_report_abs(mk712_dev, ABS_X, last_x);
112 input_report_abs(mk712_dev, ABS_Y, last_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500114 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 last_x = inw(mk712_io + MK712_X) & 0x0fff;
116 last_y = inw(mk712_io + MK712_Y) & 0x0fff;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500117 input_sync(mk712_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 spin_unlock(&mk712_lock);
119 return IRQ_HANDLED;
120}
121
122static int mk712_open(struct input_dev *dev)
123{
124 unsigned long flags;
125
126 spin_lock_irqsave(&mk712_lock, flags);
127
Dmitry Torokhovaf246042005-05-29 02:29:45 -0500128 outb(0, mk712_io + MK712_CONTROL); /* Reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Dmitry Torokhovaf246042005-05-29 02:29:45 -0500130 outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
131 MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
132 MK712_ENABLE_PERIODIC_CONVERSIONS |
133 MK712_POWERUP, mk712_io + MK712_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Dmitry Torokhovaf246042005-05-29 02:29:45 -0500135 outb(10, mk712_io + MK712_RATE); /* 187 points per second */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 spin_unlock_irqrestore(&mk712_lock, flags);
138
139 return 0;
140}
141
142static void mk712_close(struct input_dev *dev)
143{
144 unsigned long flags;
145
146 spin_lock_irqsave(&mk712_lock, flags);
147
Dmitry Torokhovaf246042005-05-29 02:29:45 -0500148 outb(0, mk712_io + MK712_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 spin_unlock_irqrestore(&mk712_lock, flags);
151}
152
Adrian Bunkffc6b5292006-01-29 21:51:07 -0500153static int __init mk712_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500155 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500157 if (!request_region(mk712_io, 8, "mk712")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 printk(KERN_WARNING "mk712: unable to get IO region\n");
159 return -ENODEV;
160 }
161
162 outb(0, mk712_io + MK712_CONTROL);
163
164 if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
165 (inw(mk712_io + MK712_Y) & 0xf000) ||
166 (inw(mk712_io + MK712_STATUS) & 0xf333)) {
167 printk(KERN_WARNING "mk712: device not present\n");
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500168 err = -ENODEV;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500169 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500172 mk712_dev = input_allocate_device();
173 if (!mk712_dev) {
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500174 printk(KERN_ERR "mk712: not enough memory\n");
175 err = -ENOMEM;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500176 goto fail1;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500177 }
178
179 mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
180 mk712_dev->phys = "isa0260/input0";
181 mk712_dev->id.bustype = BUS_ISA;
182 mk712_dev->id.vendor = 0x0005;
183 mk712_dev->id.product = 0x0001;
184 mk712_dev->id.version = 0x0100;
185
186 mk712_dev->open = mk712_open;
187 mk712_dev->close = mk712_close;
188
189 mk712_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
190 mk712_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
191 input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0);
192 input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0);
193
194 if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 printk(KERN_WARNING "mk712: unable to get IRQ\n");
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500196 err = -EBUSY;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500197 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
199
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500200 err = input_register_device(mk712_dev);
201 if (err)
202 goto fail2;
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return 0;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500205
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500206 fail2: free_irq(mk712_irq, mk712_dev);
207 fail1: input_free_device(mk712_dev);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500208 release_region(mk712_io, 8);
209 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
212static void __exit mk712_exit(void)
213{
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500214 input_unregister_device(mk712_dev);
215 free_irq(mk712_irq, mk712_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 release_region(mk712_io, 8);
217}
218
219module_init(mk712_init);
220module_exit(mk712_exit);