This source file includes following definitions.
- mouse_interrupt
- ms_mouse_interrupt
- release_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- bus_mouse_init
- ms_bus_mouse_init
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
33
34
35
36
37
38
39
40
41
42 #include <linux/kernel.h>
43 #include <linux/sched.h>
44 #include <linux/busmouse.h>
45 #include <linux/tty.h>
46 #include <linux/signal.h>
47 #include <linux/errno.h>
48
49 #include <asm/io.h>
50 #include <asm/segment.h>
51 #include <asm/system.h>
52 #include <asm/irq.h>
53
54
55 static struct mouse_status mouse;
56
57 static void mouse_interrupt(int unused)
58 {
59 char dx, dy, buttons;
60
61 MSE_INT_OFF();
62
63 outb(MSE_READ_X_LOW, MSE_CONTROL_PORT);
64 dx = (inb(MSE_DATA_PORT) & 0xf);
65
66 outb(MSE_READ_X_HIGH, MSE_CONTROL_PORT);
67 dx |= (inb(MSE_DATA_PORT) & 0xf) << 4;
68
69 outb(MSE_READ_Y_LOW, MSE_CONTROL_PORT );
70 dy = (inb(MSE_DATA_PORT) & 0xf);
71
72 outb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT);
73 buttons = inb(MSE_DATA_PORT);
74
75 dy |= (buttons & 0xf) << 4;
76 buttons = ((buttons >> 5) & 0x07);
77
78 mouse.buttons = buttons;
79 mouse.latch_buttons |= buttons;
80 mouse.dx += dx;
81 mouse.dy += dy;
82 mouse.ready = 1;
83 if (mouse.inode && mouse.inode->i_wait)
84 wake_up(&mouse.inode->i_wait);
85
86 MSE_INT_ON();
87
88 }
89
90
91 static void ms_mouse_interrupt(int unused)
92 {
93 char dx, dy, buttons;
94
95 outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
96 outb((inb(MS_MSE_DATA_PORT) | 0x20), MS_MSE_DATA_PORT);
97
98 outb(MS_MSE_READ_X, MS_MSE_CONTROL_PORT);
99 dx = inb(MS_MSE_DATA_PORT);
100
101 outb(MS_MSE_READ_Y, MS_MSE_CONTROL_PORT);
102 dy = inb(MS_MSE_DATA_PORT);
103
104 outb(MS_MSE_READ_BUTTONS, MS_MSE_CONTROL_PORT);
105 buttons = ~(inb(MS_MSE_DATA_PORT)) & 0x07;
106
107 outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
108 outb((inb(MS_MSE_DATA_PORT) & 0xdf), MS_MSE_DATA_PORT);
109
110 mouse.buttons = buttons;
111 mouse.latch_buttons |= buttons;
112 mouse.dx += dx;
113 mouse.dy += dy;
114 mouse.ready = 1;
115 if (mouse.inode && mouse.inode->i_wait)
116 wake_up(&mouse.inode->i_wait);
117
118 }
119
120 static void release_mouse(struct inode * inode, struct file * file)
121 {
122 if (mse_busmouse_type == LOGITECH_BUSMOUSE) {
123 MSE_INT_OFF();
124 } else if (mse_busmouse_type == MICROSOFT_BUSMOUSE) {
125 MS_MSE_INT_OFF();
126 }
127
128 mouse.active = 0;
129 mouse.ready = 0;
130 mouse.inode = NULL;
131 free_irq(MOUSE_IRQ);
132 }
133
134 static int open_mouse(struct inode * inode, struct file * file)
135 {
136 if (mouse.active)
137 return -EBUSY;
138 if (!mouse.present)
139 return -EINVAL;
140 mouse.active = 1;
141 mouse.ready = 0;
142 mouse.inode = inode;
143 mouse.dx = 0;
144 mouse.dy = 0;
145 mouse.buttons = mouse.latch_buttons = 0x80;
146
147 if (mse_busmouse_type == LOGITECH_BUSMOUSE) {
148 if (request_irq(MOUSE_IRQ, mouse_interrupt)) {
149
150 mouse.active = 0;
151 return -EBUSY;
152 }
153 MSE_INT_ON();
154
155 } else if (mse_busmouse_type == MICROSOFT_BUSMOUSE) {
156
157 if (request_irq(MOUSE_IRQ, ms_mouse_interrupt)) {
158
159 mouse.active = 0;
160 return -EBUSY;
161 }
162 outb(MS_MSE_START, MS_MSE_CONTROL_PORT);
163 MS_MSE_INT_ON();
164
165 }
166
167 return 0;
168 }
169
170
171 static int write_mouse(struct inode * inode, struct file * file, char * buffer, int count)
172 {
173 return -EINVAL;
174 }
175
176 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
177 {
178 int i;
179
180 if (count < 3) return -EINVAL;
181 if (!mouse.ready) return -EAGAIN;
182
183 if (mse_busmouse_type == LOGITECH_BUSMOUSE) {
184 MSE_INT_OFF();
185 }
186
187 put_fs_byte(mouse.latch_buttons | 0x80, buffer);
188
189 if (mouse.dx < -127) mouse.dx = -127;
190 if (mouse.dx > 127) mouse.dx = 127;
191
192 put_fs_byte((char)mouse.dx, buffer + 1);
193
194 if (mouse.dy < -127) mouse.dy = -127;
195 if (mouse.dy > 127) mouse.dy = 127;
196
197 put_fs_byte((char) -mouse.dy, buffer + 2);
198
199 for (i = 3; i < count; i++)
200 put_fs_byte(0x00, buffer + i);
201
202 mouse.dx = 0;
203 mouse.dy = 0;
204 mouse.latch_buttons = mouse.buttons;
205 mouse.ready = 0;
206
207 if (mse_busmouse_type == LOGITECH_BUSMOUSE) {
208 MSE_INT_ON();
209 }
210
211 return i;
212 }
213
214 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
215 {
216 if (sel_type != SEL_IN)
217 return 0;
218 if (mouse.ready)
219 return 1;
220 select_wait(&inode->i_wait,wait);
221 return 0;
222 }
223
224 struct file_operations bus_mouse_fops = {
225 NULL,
226 read_mouse,
227 write_mouse,
228 NULL,
229 mouse_select,
230 NULL,
231 open_mouse,
232 release_mouse,
233 };
234
235 long bus_mouse_init(long kmem_start)
236 {
237 int i;
238
239 outb(MSE_CONFIG_BYTE, MSE_CONFIG_PORT);
240 outb(MSE_SIGNATURE_BYTE, MSE_SIGNATURE_PORT);
241
242 for (i = 0; i < 100000; i++);
243 if (inb(MSE_SIGNATURE_PORT) != MSE_SIGNATURE_BYTE) {
244 printk("No Logitech bus mouse detected.\n");
245 mouse.present = 0;
246 return kmem_start;
247 }
248 outb(MSE_DEFAULT_MODE, MSE_CONFIG_PORT);
249
250 MSE_INT_OFF();
251
252 mouse.present = 1;
253 mouse.active = 0;
254 mouse.ready = 0;
255 mouse.buttons = mouse.latch_buttons = 0x80;
256 mouse.dx = 0;
257 mouse.dy = 0;
258 printk("Logitech Bus mouse detected and installed.\n");
259 return kmem_start;
260 }
261
262 #define MS_DELAY 100000
263
264 long ms_bus_mouse_init(long kmem_start)
265 {
266 register int mse_byte;
267 int i, delay_val, msfound = 1;
268
269 if (inb(MS_MSE_SIGNATURE_PORT) == 0xde) {
270 for (delay_val=0; delay_val<MS_DELAY;) delay_val++;
271
272 mse_byte = inb(MS_MSE_SIGNATURE_PORT);
273 for (delay_val=0; delay_val<MS_DELAY; ) delay_val++;
274
275 for (i = 0; i < 4; i++) {
276 for (delay_val=0; delay_val<MS_DELAY;) delay_val++;
277 if (inb(MS_MSE_SIGNATURE_PORT) == 0xde) {
278
279 for (delay_val=0; delay_val<MS_DELAY; ) delay_val++;
280 if (inb(MS_MSE_SIGNATURE_PORT) == mse_byte)
281 msfound = 0;
282 else
283 msfound = 1;
284 }
285 else
286 msfound = 1;
287 }
288 }
289
290 if (msfound == 1) {
291 printk("No Microsoft bus mouse detected.\n");
292 mouse.present = 0;
293 return kmem_start;
294 }
295
296 MS_MSE_INT_OFF();
297
298 mouse.present = 1;
299 mouse.active = mouse.ready = 0;
300 mouse.buttons = mouse.latch_buttons = 0x80;
301 mouse.dx = mouse.dy = 0;
302 printk("Microsoft Bus mouse detected and installed.\n");
303 return kmem_start;
304 }