blob: 753d9cc1de1f8134b9368adbd652a46f30f14f54 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * ICS MK712 touchscreen controller driver
4 *
5 * Copyright (c) 1999-2002 Transmeta Corporation
6 * Copyright (c) 2005 Rick Koch <n1gp@hotmail.com>
7 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/*
12 * This driver supports the ICS MicroClock MK712 TouchScreen controller,
13 * found in Gateway AOL Connected Touchpad computers.
14 *
15 * Documentation for ICS MK712 can be found at:
Martin Kepplingercbd606e2018-05-29 15:56:29 -070016 * https://www.idt.com/general-parts/mk712-touch-screen-controller
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
19/*
20 * 1999-12-18: original version, Daniel Quinlan
21 * 1999-12-19: added anti-jitter code, report pen-up events, fixed mk712_poll
22 * to use queue_empty, Nathan Laredo
23 * 1999-12-20: improved random point rejection, Nathan Laredo
24 * 2000-01-05: checked in new anti-jitter code, changed mouse protocol, fixed
25 * queue code, added module options, other fixes, Daniel Quinlan
26 * 2002-03-15: Clean up for kernel merge <alan@redhat.com>
27 * Fixed multi open race, fixed memory checks, fixed resource
28 * allocation, fixed close/powerdown bug, switched to new init
29 * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch
30 * 2005-02-05: Rewritten for the input layer, Vojtech Pavlik
31 *
32 */
33
34#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/kernel.h>
36#include <linux/init.h>
37#include <linux/errno.h>
38#include <linux/delay.h>
39#include <linux/ioport.h>
40#include <linux/interrupt.h>
41#include <linux/input.h>
42#include <asm/io.h>
43
44MODULE_AUTHOR("Daniel Quinlan <quinlan@pathname.com>, Vojtech Pavlik <vojtech@suse.cz>");
45MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver");
46MODULE_LICENSE("GPL");
47
48static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */
David Howellsf6b12d02017-04-04 16:54:23 +010049module_param_hw_named(io, mk712_io, uint, ioport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller");
51
52static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */
David Howellsf6b12d02017-04-04 16:54:23 +010053module_param_hw_named(irq, mk712_irq, uint, irq, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
55
56/* eight 8-bit registers */
57#define MK712_STATUS 0
58#define MK712_X 2
59#define MK712_Y 4
60#define MK712_CONTROL 6
61#define MK712_RATE 7
62
63/* status */
64#define MK712_STATUS_TOUCH 0x10
65#define MK712_CONVERSION_COMPLETE 0x80
66
67/* control */
68#define MK712_ENABLE_INT 0x01
69#define MK712_INT_ON_CONVERSION_COMPLETE 0x02
70#define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS 0x04
71#define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
72#define MK712_READ_ONE_POINT 0x20
73#define MK712_POWERUP 0x40
74
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050075static struct input_dev *mk712_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076static DEFINE_SPINLOCK(mk712_lock);
77
David Howells7d12e782006-10-05 14:55:46 +010078static irqreturn_t mk712_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 unsigned char status;
81 static int debounce = 1;
82 static unsigned short last_x;
83 static unsigned short last_y;
84
85 spin_lock(&mk712_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 status = inb(mk712_io + MK712_STATUS);
88
89 if (~status & MK712_CONVERSION_COMPLETE) {
90 debounce = 1;
91 goto end;
92 }
93
Dmitry Torokhov52c1f572006-11-05 22:40:03 -050094 if (~status & MK712_STATUS_TOUCH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 debounce = 1;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050096 input_report_key(mk712_dev, BTN_TOUCH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 goto end;
98 }
99
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500100 if (debounce) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 debounce = 0;
102 goto end;
103 }
104
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500105 input_report_key(mk712_dev, BTN_TOUCH, 1);
106 input_report_abs(mk712_dev, ABS_X, last_x);
107 input_report_abs(mk712_dev, ABS_Y, last_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500109 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 last_x = inw(mk712_io + MK712_X) & 0x0fff;
111 last_y = inw(mk712_io + MK712_Y) & 0x0fff;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500112 input_sync(mk712_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 spin_unlock(&mk712_lock);
114 return IRQ_HANDLED;
115}
116
117static int mk712_open(struct input_dev *dev)
118{
119 unsigned long flags;
120
121 spin_lock_irqsave(&mk712_lock, flags);
122
Dmitry Torokhovaf246042005-05-29 02:29:45 -0500123 outb(0, mk712_io + MK712_CONTROL); /* Reset */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Dmitry Torokhovaf246042005-05-29 02:29:45 -0500125 outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
126 MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
127 MK712_ENABLE_PERIODIC_CONVERSIONS |
128 MK712_POWERUP, mk712_io + MK712_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Dmitry Torokhovaf246042005-05-29 02:29:45 -0500130 outb(10, mk712_io + MK712_RATE); /* 187 points per second */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 spin_unlock_irqrestore(&mk712_lock, flags);
133
134 return 0;
135}
136
137static void mk712_close(struct input_dev *dev)
138{
139 unsigned long flags;
140
141 spin_lock_irqsave(&mk712_lock, flags);
142
Dmitry Torokhovaf246042005-05-29 02:29:45 -0500143 outb(0, mk712_io + MK712_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 spin_unlock_irqrestore(&mk712_lock, flags);
146}
147
Adrian Bunkffc6b5292006-01-29 21:51:07 -0500148static int __init mk712_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500150 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500152 if (!request_region(mk712_io, 8, "mk712")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 printk(KERN_WARNING "mk712: unable to get IO region\n");
154 return -ENODEV;
155 }
156
157 outb(0, mk712_io + MK712_CONTROL);
158
159 if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
160 (inw(mk712_io + MK712_Y) & 0xf000) ||
161 (inw(mk712_io + MK712_STATUS) & 0xf333)) {
162 printk(KERN_WARNING "mk712: device not present\n");
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500163 err = -ENODEV;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500164 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500167 mk712_dev = input_allocate_device();
168 if (!mk712_dev) {
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500169 printk(KERN_ERR "mk712: not enough memory\n");
170 err = -ENOMEM;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500171 goto fail1;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500172 }
173
174 mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
175 mk712_dev->phys = "isa0260/input0";
176 mk712_dev->id.bustype = BUS_ISA;
177 mk712_dev->id.vendor = 0x0005;
178 mk712_dev->id.product = 0x0001;
179 mk712_dev->id.version = 0x0100;
180
181 mk712_dev->open = mk712_open;
182 mk712_dev->close = mk712_close;
183
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700184 mk712_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
185 mk712_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500186 input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0);
187 input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0);
188
189 if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 printk(KERN_WARNING "mk712: unable to get IRQ\n");
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500191 err = -EBUSY;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500192 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500195 err = input_register_device(mk712_dev);
196 if (err)
197 goto fail2;
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return 0;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500200
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500201 fail2: free_irq(mk712_irq, mk712_dev);
202 fail1: input_free_device(mk712_dev);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500203 release_region(mk712_io, 8);
204 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
207static void __exit mk712_exit(void)
208{
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500209 input_unregister_device(mk712_dev);
210 free_irq(mk712_irq, mk712_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 release_region(mk712_io, 8);
212}
213
214module_init(mk712_init);
215module_exit(mk712_exit);