blob: 7b02b652e267e016a60c69f1c47e31689332a07b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (c) 2000-2001 Vojtech Pavlik
3 *
4 * Based on the work of:
Dmitry Torokhov968ac842005-05-29 02:28:29 -05005 * Alan Cox Robin O'Leary
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8/*
9 * IBM PC110 touchpad driver for Linux
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
29 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
30 */
31
32#include <linux/module.h>
33#include <linux/kernel.h>
34#include <linux/errno.h>
35#include <linux/ioport.h>
36#include <linux/input.h>
37#include <linux/init.h>
38#include <linux/interrupt.h>
39#include <linux/pci.h>
Ingo Molnar41e191e2008-01-30 13:31:24 +010040#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#include <asm/io.h>
43#include <asm/irq.h>
44
45MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
46MODULE_DESCRIPTION("IBM PC110 touchpad driver");
47MODULE_LICENSE("GPL");
48
49#define PC110PAD_OFF 0x30
50#define PC110PAD_ON 0x38
51
52static int pc110pad_irq = 10;
53static int pc110pad_io = 0x15e0;
54
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050055static struct input_dev *pc110pad_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static int pc110pad_data[3];
57static int pc110pad_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
David Howells7d12e782006-10-05 14:55:46 +010059static irqreturn_t pc110pad_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 int value = inb_p(pc110pad_io);
62 int handshake = inb_p(pc110pad_io + 2);
63
Ingo Molnar41e191e2008-01-30 13:31:24 +010064 outb(handshake | 1, pc110pad_io + 2);
65 udelay(2);
66 outb(handshake & ~1, pc110pad_io + 2);
67 udelay(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 inb_p(0x64);
69
70 pc110pad_data[pc110pad_count++] = value;
71
72 if (pc110pad_count < 3)
73 return IRQ_HANDLED;
Dmitry Torokhov968ac842005-05-29 02:28:29 -050074
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050075 input_report_key(pc110pad_dev, BTN_TOUCH,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 pc110pad_data[0] & 0x01);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050077 input_report_abs(pc110pad_dev, ABS_X,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050079 input_report_abs(pc110pad_dev, ABS_Y,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050081 input_sync(pc110pad_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 pc110pad_count = 0;
84 return IRQ_HANDLED;
85}
86
87static void pc110pad_close(struct input_dev *dev)
88{
Dmitry Torokhov3108d422005-05-29 02:29:30 -050089 outb(PC110PAD_OFF, pc110pad_io + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92static int pc110pad_open(struct input_dev *dev)
93{
David Howells7d12e782006-10-05 14:55:46 +010094 pc110pad_interrupt(0, NULL);
95 pc110pad_interrupt(0, NULL);
96 pc110pad_interrupt(0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 outb(PC110PAD_ON, pc110pad_io + 2);
98 pc110pad_count = 0;
99
100 return 0;
101}
102
103/*
104 * We try to avoid enabling the hardware if it's not
105 * there, but we don't know how to test. But we do know
106 * that the PC110 is not a PCI system. So if we find any
107 * PCI devices in the machine, we don't have a PC110.
108 */
109static int __init pc110pad_init(void)
110{
Dmitry Torokhov72155612006-11-05 22:40:19 -0500111 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Roel Kluinb0ee0d32009-01-29 22:56:08 -0800113 if (!no_pci_devices())
Akinobu Mita65a2d222006-12-21 00:42:55 -0500114 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 if (!request_region(pc110pad_io, 4, "pc110pad")) {
117 printk(KERN_ERR "pc110pad: I/O area %#x-%#x in use.\n",
118 pc110pad_io, pc110pad_io + 4);
119 return -EBUSY;
120 }
121
122 outb(PC110PAD_OFF, pc110pad_io + 2);
123
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500124 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
Dmitry Torokhov72155612006-11-05 22:40:19 -0500126 err = -EBUSY;
127 goto err_release_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129
Dmitry Torokhov72155612006-11-05 22:40:19 -0500130 pc110pad_dev = input_allocate_device();
131 if (!pc110pad_dev) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500132 printk(KERN_ERR "pc110pad: Not enough memory.\n");
Dmitry Torokhov72155612006-11-05 22:40:19 -0500133 err = -ENOMEM;
134 goto err_free_irq;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500137 pc110pad_dev->name = "IBM PC110 TouchPad";
138 pc110pad_dev->phys = "isa15e0/input0";
139 pc110pad_dev->id.bustype = BUS_ISA;
140 pc110pad_dev->id.vendor = 0x0003;
141 pc110pad_dev->id.product = 0x0001;
142 pc110pad_dev->id.version = 0x0100;
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500143
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700144 pc110pad_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
145 pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
146 pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Daniel Mack987a6c02010-08-02 20:15:17 -0700148 input_abs_set_max(pc110pad_dev, ABS_X, 0x1ff);
149 input_abs_set_max(pc110pad_dev, ABS_Y, 0x0ff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500151 pc110pad_dev->open = pc110pad_open;
152 pc110pad_dev->close = pc110pad_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Dmitry Torokhov72155612006-11-05 22:40:19 -0500154 err = input_register_device(pc110pad_dev);
155 if (err)
156 goto err_free_dev;
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return 0;
Dmitry Torokhov72155612006-11-05 22:40:19 -0500159
160 err_free_dev:
161 input_free_device(pc110pad_dev);
162 err_free_irq:
163 free_irq(pc110pad_irq, NULL);
164 err_release_region:
165 release_region(pc110pad_io, 4);
166
167 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170static void __exit pc110pad_exit(void)
171{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 outb(PC110PAD_OFF, pc110pad_io + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 free_irq(pc110pad_irq, NULL);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500174 input_unregister_device(pc110pad_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 release_region(pc110pad_io, 4);
176}
177
178module_init(pc110pad_init);
179module_exit(pc110pad_exit);