This source file includes following definitions.
- bmouse_setup
- mouse_interrupt
- close_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- 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 #include <linux/kernel.h>
27 #include <linux/sched.h>
28 #include <linux/busmouse.h>
29 #include <linux/tty.h>
30 #include <linux/signal.h>
31 #include <linux/errno.h>
32
33 #include <asm/io.h>
34 #include <asm/segment.h>
35 #include <asm/system.h>
36 #include <asm/irq.h>
37
38 static struct mouse_status mouse;
39 static int mouse_irq = MOUSE_IRQ;
40
41 void bmouse_setup(char *str, int *ints)
42 {
43 if (ints[0] > 0)
44 mouse_irq=ints[1];
45 }
46
47 static void mouse_interrupt(int unused)
48 {
49 char dx, dy;
50 unsigned char buttons;
51
52 MSE_INT_OFF();
53 outb(MSE_READ_X_LOW, MSE_CONTROL_PORT);
54 dx = (inb(MSE_DATA_PORT) & 0xf);
55 outb(MSE_READ_X_HIGH, MSE_CONTROL_PORT);
56 dx |= (inb(MSE_DATA_PORT) & 0xf) << 4;
57 outb(MSE_READ_Y_LOW, MSE_CONTROL_PORT );
58 dy = (inb(MSE_DATA_PORT) & 0xf);
59 outb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT);
60 buttons = inb(MSE_DATA_PORT);
61 dy |= (buttons & 0xf) << 4;
62 buttons = ((buttons >> 5) & 0x07);
63 if (dx != 0 || dy != 0 || buttons != mouse.buttons) {
64 mouse.buttons = buttons;
65 mouse.dx += dx;
66 mouse.dy -= dy;
67 mouse.ready = 1;
68 wake_up_interruptible(&mouse.wait);
69
70
71
72
73
74
75 if (mouse.dx < -2048)
76 mouse.dx = -2048;
77 if (mouse.dx > 2048)
78 mouse.dx = 2048;
79
80 if (mouse.dy < -2048)
81 mouse.dy = -2048;
82 if (mouse.dy > 2048)
83 mouse.dy = 2048;
84 }
85 MSE_INT_ON();
86 }
87
88
89
90
91
92
93 static void close_mouse(struct inode * inode, struct file * file)
94 {
95 if (--mouse.active == 0) {
96 MSE_INT_OFF();
97 free_irq(mouse_irq);
98 }
99 }
100
101
102
103
104
105
106 static int open_mouse(struct inode * inode, struct file * file)
107 {
108 if (!mouse.present)
109 return -EINVAL;
110 if (mouse.active)
111 return -EBUSY;
112 mouse.ready = 0;
113 mouse.dx = 0;
114 mouse.dy = 0;
115 mouse.buttons = 0x87;
116 if (request_irq(mouse_irq, mouse_interrupt))
117 return -EBUSY;
118 mouse.active = 1;
119 MSE_INT_ON();
120 return 0;
121 }
122
123
124
125
126
127 static int write_mouse(struct inode * inode, struct file * file, char * buffer, int count)
128 {
129 return -EINVAL;
130 }
131
132
133
134
135
136 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
137 {
138 int r;
139 int dx;
140 int dy;
141 unsigned char buttons;
142
143 if (count < 3)
144 return -EINVAL;
145 if ((r = verify_area(VERIFY_WRITE, buffer, count)))
146 return r;
147 if (!mouse.ready)
148 return -EAGAIN;
149
150
151
152
153
154
155
156
157 MSE_INT_OFF();
158 dx = mouse.dx;
159 dy = mouse.dy;
160 if (dx < -127)
161 dx = -127;
162 if (dx > 127)
163 dx = 127;
164 if (dy < -127)
165 dy = -127;
166 if (dy > 127)
167 dy = 127;
168 buttons = mouse.buttons;
169 mouse.dx -= dx;
170 mouse.dy -= dy;
171 mouse.ready = 0;
172 MSE_INT_ON();
173
174 put_fs_byte(buttons | 0x80, buffer);
175 put_fs_byte((char)dx, buffer + 1);
176 put_fs_byte((char)dy, buffer + 2);
177 for (r = 3; r < count; r++)
178 put_fs_byte(0x00, buffer + r);
179 return r;
180 }
181
182
183
184
185
186
187
188
189 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
190 {
191 int r = 0;
192
193 if (sel_type == SEL_IN) {
194 MSE_INT_OFF();
195 if (mouse.ready) {
196 r = 1;
197 } else {
198 select_wait(&mouse.wait, wait);
199 }
200 MSE_INT_ON();
201 }
202 return(r);
203 }
204
205 struct file_operations bus_mouse_fops = {
206 NULL,
207 read_mouse,
208 write_mouse,
209 NULL,
210 mouse_select,
211 NULL,
212 NULL,
213 open_mouse,
214 close_mouse,
215 };
216
217 unsigned long bus_mouse_init(unsigned long kmem_start)
218 {
219 int i;
220
221 outb(MSE_CONFIG_BYTE, MSE_CONFIG_PORT);
222 outb(MSE_SIGNATURE_BYTE, MSE_SIGNATURE_PORT);
223 for (i = 0; i < 100000; i++)
224 ;
225 if (inb(MSE_SIGNATURE_PORT) != MSE_SIGNATURE_BYTE) {
226 mouse.present = 0;
227 return kmem_start;
228 }
229 outb(MSE_DEFAULT_MODE, MSE_CONFIG_PORT);
230 MSE_INT_OFF();
231 mouse.present = 1;
232 mouse.active = 0;
233 mouse.ready = 0;
234 mouse.buttons = 0x87;
235 mouse.dx = 0;
236 mouse.dy = 0;
237 mouse.wait = NULL;
238 printk("Logitech Bus mouse detected and installed.\n");
239 return kmem_start;
240 }