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