1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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>
40#include <linux/delay.h>
41
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
55static struct input_dev *pc110pad_dev;
56static int pc110pad_data[3];
57static int pc110pad_count;
58
59static irqreturn_t pc110pad_interrupt(int irq, void *ptr)
60{
61 int value = inb_p(pc110pad_io);
62 int handshake = inb_p(pc110pad_io + 2);
63
64 outb(handshake | 1, pc110pad_io + 2);
65 udelay(2);
66 outb(handshake & ~1, pc110pad_io + 2);
67 udelay(2);
68 inb_p(0x64);
69
70 pc110pad_data[pc110pad_count++] = value;
71
72 if (pc110pad_count < 3)
73 return IRQ_HANDLED;
74
75 input_report_key(pc110pad_dev, BTN_TOUCH,
76 pc110pad_data[0] & 0x01);
77 input_report_abs(pc110pad_dev, ABS_X,
78 pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
79 input_report_abs(pc110pad_dev, ABS_Y,
80 pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
81 input_sync(pc110pad_dev);
82
83 pc110pad_count = 0;
84 return IRQ_HANDLED;
85}
86
87static void pc110pad_close(struct input_dev *dev)
88{
89 outb(PC110PAD_OFF, pc110pad_io + 2);
90}
91
92static int pc110pad_open(struct input_dev *dev)
93{
94 pc110pad_interrupt(0, NULL);
95 pc110pad_interrupt(0, NULL);
96 pc110pad_interrupt(0, NULL);
97 outb(PC110PAD_ON, pc110pad_io + 2);
98 pc110pad_count = 0;
99
100 return 0;
101}
102
103
104
105
106
107
108
109static int __init pc110pad_init(void)
110{
111 int err;
112
113 if (!no_pci_devices())
114 return -ENODEV;
115
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
124 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
125 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
126 err = -EBUSY;
127 goto err_release_region;
128 }
129
130 pc110pad_dev = input_allocate_device();
131 if (!pc110pad_dev) {
132 printk(KERN_ERR "pc110pad: Not enough memory.\n");
133 err = -ENOMEM;
134 goto err_free_irq;
135 }
136
137 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;
143
144 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);
147
148 input_abs_set_max(pc110pad_dev, ABS_X, 0x1ff);
149 input_abs_set_max(pc110pad_dev, ABS_Y, 0x0ff);
150
151 pc110pad_dev->open = pc110pad_open;
152 pc110pad_dev->close = pc110pad_close;
153
154 err = input_register_device(pc110pad_dev);
155 if (err)
156 goto err_free_dev;
157
158 return 0;
159
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;
168}
169
170static void __exit pc110pad_exit(void)
171{
172 outb(PC110PAD_OFF, pc110pad_io + 2);
173 free_irq(pc110pad_irq, NULL);
174 input_unregister_device(pc110pad_dev);
175 release_region(pc110pad_io, 4);
176}
177
178module_init(pc110pad_init);
179module_exit(pc110pad_exit);
180