blob: 05d992e514f0bd5452dc0a6f0c9161b01a01c753 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * $Id: pc110pad.c,v 1.12 2001/09/25 10:12:07 vojtech Exp $
3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 *
6 * Based on the work of:
Dmitry Torokhov968ac842005-05-29 02:28:29 -05007 * Alan Cox Robin O'Leary
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10/*
11 * IBM PC110 touchpad driver for Linux
12 */
13
14/*
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 * Should you need to contact me, the author, you can do so either by
30 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
31 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
32 */
33
34#include <linux/module.h>
35#include <linux/kernel.h>
36#include <linux/errno.h>
37#include <linux/ioport.h>
38#include <linux/input.h>
39#include <linux/init.h>
40#include <linux/interrupt.h>
41#include <linux/pci.h>
42
43#include <asm/io.h>
44#include <asm/irq.h>
45
46MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
47MODULE_DESCRIPTION("IBM PC110 touchpad driver");
48MODULE_LICENSE("GPL");
49
50#define PC110PAD_OFF 0x30
51#define PC110PAD_ON 0x38
52
53static int pc110pad_irq = 10;
54static int pc110pad_io = 0x15e0;
55
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050056static struct input_dev *pc110pad_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static int pc110pad_data[3];
58static int pc110pad_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
David Howells7d12e782006-10-05 14:55:46 +010060static irqreturn_t pc110pad_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
62 int value = inb_p(pc110pad_io);
63 int handshake = inb_p(pc110pad_io + 2);
64
65 outb_p(handshake | 1, pc110pad_io + 2);
66 outb_p(handshake & ~1, pc110pad_io + 2);
67 inb_p(0x64);
68
69 pc110pad_data[pc110pad_count++] = value;
70
71 if (pc110pad_count < 3)
72 return IRQ_HANDLED;
Dmitry Torokhov968ac842005-05-29 02:28:29 -050073
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050074 input_report_key(pc110pad_dev, BTN_TOUCH,
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 pc110pad_data[0] & 0x01);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050076 input_report_abs(pc110pad_dev, ABS_X,
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050078 input_report_abs(pc110pad_dev, ABS_Y,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050080 input_sync(pc110pad_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 pc110pad_count = 0;
83 return IRQ_HANDLED;
84}
85
86static void pc110pad_close(struct input_dev *dev)
87{
Dmitry Torokhov3108d422005-05-29 02:29:30 -050088 outb(PC110PAD_OFF, pc110pad_io + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
91static int pc110pad_open(struct input_dev *dev)
92{
David Howells7d12e782006-10-05 14:55:46 +010093 pc110pad_interrupt(0, NULL);
94 pc110pad_interrupt(0, NULL);
95 pc110pad_interrupt(0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 outb(PC110PAD_ON, pc110pad_io + 2);
97 pc110pad_count = 0;
98
99 return 0;
100}
101
102/*
103 * We try to avoid enabling the hardware if it's not
104 * there, but we don't know how to test. But we do know
105 * that the PC110 is not a PCI system. So if we find any
106 * PCI devices in the machine, we don't have a PC110.
107 */
108static int __init pc110pad_init(void)
109{
110 struct pci_dev *dev;
Dmitry Torokhov72155612006-11-05 22:40:19 -0500111 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
114 if (dev) {
115 pci_dev_put(dev);
Akinobu Mita65a2d222006-12-21 00:42:55 -0500116 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
119 if (!request_region(pc110pad_io, 4, "pc110pad")) {
120 printk(KERN_ERR "pc110pad: I/O area %#x-%#x in use.\n",
121 pc110pad_io, pc110pad_io + 4);
122 return -EBUSY;
123 }
124
125 outb(PC110PAD_OFF, pc110pad_io + 2);
126
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500127 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
Dmitry Torokhov72155612006-11-05 22:40:19 -0500129 err = -EBUSY;
130 goto err_release_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
Dmitry Torokhov72155612006-11-05 22:40:19 -0500133 pc110pad_dev = input_allocate_device();
134 if (!pc110pad_dev) {
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500135 printk(KERN_ERR "pc110pad: Not enough memory.\n");
Dmitry Torokhov72155612006-11-05 22:40:19 -0500136 err = -ENOMEM;
137 goto err_free_irq;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500140 pc110pad_dev->name = "IBM PC110 TouchPad";
141 pc110pad_dev->phys = "isa15e0/input0";
142 pc110pad_dev->id.bustype = BUS_ISA;
143 pc110pad_dev->id.vendor = 0x0003;
144 pc110pad_dev->id.product = 0x0001;
145 pc110pad_dev->id.version = 0x0100;
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500146
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500147 pc110pad_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
148 pc110pad_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
149 pc110pad_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500151 pc110pad_dev->absmax[ABS_X] = 0x1ff;
152 pc110pad_dev->absmax[ABS_Y] = 0x0ff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500154 pc110pad_dev->open = pc110pad_open;
155 pc110pad_dev->close = pc110pad_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Dmitry Torokhov72155612006-11-05 22:40:19 -0500157 err = input_register_device(pc110pad_dev);
158 if (err)
159 goto err_free_dev;
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return 0;
Dmitry Torokhov72155612006-11-05 22:40:19 -0500162
163 err_free_dev:
164 input_free_device(pc110pad_dev);
165 err_free_irq:
166 free_irq(pc110pad_irq, NULL);
167 err_release_region:
168 release_region(pc110pad_io, 4);
169
170 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
Dmitry Torokhov968ac842005-05-29 02:28:29 -0500172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173static void __exit pc110pad_exit(void)
174{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 outb(PC110PAD_OFF, pc110pad_io + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 free_irq(pc110pad_irq, NULL);
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500177 input_unregister_device(pc110pad_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 release_region(pc110pad_io, 4);
179}
180
181module_init(pc110pad_init);
182module_exit(pc110pad_exit);