Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * $Id: inport.c,v 1.11 2001/09/25 10:12:07 vojtech Exp $ | |
3 | * | |
4 | * Copyright (c) 1999-2001 Vojtech Pavlik | |
5 | * | |
6 | * Based on the work of: | |
7 | * Teemu Rantanen Derrick Cole | |
8 | * Peter Cervasio Christoph Niemann | |
9 | * Philip Blundell Russell King | |
10 | * Bob Harris | |
11 | */ | |
12 | ||
13 | /* | |
14 | * Inport (ATI XL and Microsoft) busmouse driver for Linux | |
15 | */ | |
16 | ||
17 | /* | |
18 | * This program is free software; you can redistribute it and/or modify | |
19 | * it under the terms of the GNU General Public License as published by | |
968ac842 | 20 | * the Free Software Foundation; either version 2 of the License, or |
1da177e4 | 21 | * (at your option) any later version. |
968ac842 | 22 | * |
1da177e4 LT |
23 | * This program is distributed in the hope that it will be useful, |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 | * GNU General Public License for more details. | |
968ac842 | 27 | * |
1da177e4 LT |
28 | * You should have received a copy of the GNU General Public License |
29 | * along with this program; if not, write to the Free Software | |
30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
968ac842 | 31 | * |
1da177e4 LT |
32 | * Should you need to contact me, the author, you can do so either by |
33 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: | |
34 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic | |
35 | */ | |
36 | ||
37 | #include <linux/module.h> | |
38 | #include <linux/moduleparam.h> | |
1da177e4 LT |
39 | #include <linux/ioport.h> |
40 | #include <linux/init.h> | |
41 | #include <linux/interrupt.h> | |
42 | #include <linux/input.h> | |
43 | ||
44 | #include <asm/io.h> | |
45 | #include <asm/irq.h> | |
46 | ||
47 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); | |
48 | MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver"); | |
49 | MODULE_LICENSE("GPL"); | |
50 | ||
51 | #define INPORT_BASE 0x23c | |
52 | #define INPORT_EXTENT 4 | |
53 | ||
54 | #define INPORT_CONTROL_PORT INPORT_BASE + 0 | |
55 | #define INPORT_DATA_PORT INPORT_BASE + 1 | |
56 | #define INPORT_SIGNATURE_PORT INPORT_BASE + 2 | |
57 | ||
58 | #define INPORT_REG_BTNS 0x00 | |
59 | #define INPORT_REG_X 0x01 | |
60 | #define INPORT_REG_Y 0x02 | |
61 | #define INPORT_REG_MODE 0x07 | |
62 | #define INPORT_RESET 0x80 | |
63 | ||
8370a643 | 64 | #ifdef CONFIG_MOUSE_ATIXL |
1da177e4 LT |
65 | #define INPORT_NAME "ATI XL Mouse" |
66 | #define INPORT_VENDOR 0x0002 | |
67 | #define INPORT_SPEED_30HZ 0x01 | |
68 | #define INPORT_SPEED_50HZ 0x02 | |
69 | #define INPORT_SPEED_100HZ 0x03 | |
70 | #define INPORT_SPEED_200HZ 0x04 | |
71 | #define INPORT_MODE_BASE INPORT_SPEED_100HZ | |
72 | #define INPORT_MODE_IRQ 0x08 | |
73 | #else | |
74 | #define INPORT_NAME "Microsoft InPort Mouse" | |
75 | #define INPORT_VENDOR 0x0001 | |
76 | #define INPORT_MODE_BASE 0x10 | |
77 | #define INPORT_MODE_IRQ 0x01 | |
78 | #endif | |
79 | #define INPORT_MODE_HOLD 0x20 | |
80 | ||
81 | #define INPORT_IRQ 5 | |
82 | ||
83 | static int inport_irq = INPORT_IRQ; | |
84 | module_param_named(irq, inport_irq, uint, 0); | |
85 | MODULE_PARM_DESC(irq, "IRQ number (5=default)"); | |
86 | ||
2e5b636b | 87 | static struct input_dev *inport_dev; |
1da177e4 | 88 | |
7d12e780 | 89 | static irqreturn_t inport_interrupt(int irq, void *dev_id) |
1da177e4 LT |
90 | { |
91 | unsigned char buttons; | |
92 | ||
93 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | |
94 | outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); | |
95 | ||
1da177e4 | 96 | outb(INPORT_REG_X, INPORT_CONTROL_PORT); |
2e5b636b | 97 | input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT)); |
1da177e4 LT |
98 | |
99 | outb(INPORT_REG_Y, INPORT_CONTROL_PORT); | |
2e5b636b | 100 | input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT)); |
1da177e4 LT |
101 | |
102 | outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT); | |
103 | buttons = inb(INPORT_DATA_PORT); | |
104 | ||
2e5b636b DT |
105 | input_report_key(inport_dev, BTN_MIDDLE, buttons & 1); |
106 | input_report_key(inport_dev, BTN_LEFT, buttons & 2); | |
107 | input_report_key(inport_dev, BTN_RIGHT, buttons & 4); | |
1da177e4 LT |
108 | |
109 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | |
110 | outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); | |
111 | ||
2e5b636b | 112 | input_sync(inport_dev); |
1da177e4 LT |
113 | return IRQ_HANDLED; |
114 | } | |
115 | ||
2e5b636b DT |
116 | static int inport_open(struct input_dev *dev) |
117 | { | |
118 | if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL)) | |
119 | return -EBUSY; | |
120 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | |
121 | outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); | |
122 | ||
123 | return 0; | |
124 | } | |
125 | ||
126 | static void inport_close(struct input_dev *dev) | |
127 | { | |
128 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | |
129 | outb(INPORT_MODE_BASE, INPORT_DATA_PORT); | |
130 | free_irq(inport_irq, NULL); | |
131 | } | |
132 | ||
1da177e4 LT |
133 | static int __init inport_init(void) |
134 | { | |
2e5b636b | 135 | unsigned char a, b, c; |
72155615 | 136 | int err; |
1da177e4 LT |
137 | |
138 | if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) { | |
139 | printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE); | |
140 | return -EBUSY; | |
141 | } | |
142 | ||
143 | a = inb(INPORT_SIGNATURE_PORT); | |
144 | b = inb(INPORT_SIGNATURE_PORT); | |
145 | c = inb(INPORT_SIGNATURE_PORT); | |
2e5b636b | 146 | if (a == b || a != c) { |
1da177e4 | 147 | printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE); |
72155615 DT |
148 | err = -ENODEV; |
149 | goto err_release_region; | |
1da177e4 LT |
150 | } |
151 | ||
72155615 DT |
152 | inport_dev = input_allocate_device(); |
153 | if (!inport_dev) { | |
2e5b636b | 154 | printk(KERN_ERR "inport.c: Not enough memory for input device\n"); |
72155615 DT |
155 | err = -ENOMEM; |
156 | goto err_release_region; | |
2e5b636b DT |
157 | } |
158 | ||
159 | inport_dev->name = INPORT_NAME; | |
160 | inport_dev->phys = "isa023c/input0"; | |
161 | inport_dev->id.bustype = BUS_ISA; | |
162 | inport_dev->id.vendor = INPORT_VENDOR; | |
163 | inport_dev->id.product = 0x0001; | |
164 | inport_dev->id.version = 0x0100; | |
165 | ||
166 | inport_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); | |
167 | inport_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); | |
168 | inport_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y); | |
169 | ||
170 | inport_dev->open = inport_open; | |
171 | inport_dev->close = inport_close; | |
172 | ||
1da177e4 LT |
173 | outb(INPORT_RESET, INPORT_CONTROL_PORT); |
174 | outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); | |
175 | outb(INPORT_MODE_BASE, INPORT_DATA_PORT); | |
176 | ||
72155615 DT |
177 | err = input_register_device(inport_dev); |
178 | if (err) | |
179 | goto err_free_dev; | |
1da177e4 LT |
180 | |
181 | return 0; | |
72155615 DT |
182 | |
183 | err_free_dev: | |
184 | input_free_device(inport_dev); | |
185 | err_release_region: | |
186 | release_region(INPORT_BASE, INPORT_EXTENT); | |
187 | ||
188 | return err; | |
1da177e4 LT |
189 | } |
190 | ||
191 | static void __exit inport_exit(void) | |
192 | { | |
2e5b636b | 193 | input_unregister_device(inport_dev); |
1da177e4 LT |
194 | release_region(INPORT_BASE, INPORT_EXTENT); |
195 | } | |
196 | ||
197 | module_init(inport_init); | |
198 | module_exit(inport_exit); |