This source file includes following definitions.
- bmouse_setup
- mouse_interrupt
- fasync_mouse
- close_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- bus_mouse_init
- init_module
- cleanup_module
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 #include <linux/module.h>
36
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/busmouse.h>
40 #include <linux/signal.h>
41 #include <linux/errno.h>
42 #include <linux/mm.h>
43 #include <linux/mouse.h>
44 #include <linux/random.h>
45 #include <linux/delay.h>
46
47 #include <asm/io.h>
48 #include <asm/segment.h>
49 #include <asm/system.h>
50 #include <asm/irq.h>
51
52 static struct mouse_status mouse;
53 static int mouse_irq = MOUSE_IRQ;
54
55 void bmouse_setup(char *str, int *ints)
56 {
57 if (ints[0] > 0)
58 mouse_irq=ints[1];
59 }
60
61 static void mouse_interrupt(int irq, struct pt_regs *regs)
62 {
63 char dx, dy;
64 unsigned char buttons;
65
66 MSE_INT_OFF();
67 outb(MSE_READ_X_LOW, MSE_CONTROL_PORT);
68 dx = (inb(MSE_DATA_PORT) & 0xf);
69 outb(MSE_READ_X_HIGH, MSE_CONTROL_PORT);
70 dx |= (inb(MSE_DATA_PORT) & 0xf) << 4;
71 outb(MSE_READ_Y_LOW, MSE_CONTROL_PORT );
72 dy = (inb(MSE_DATA_PORT) & 0xf);
73 outb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT);
74 buttons = inb(MSE_DATA_PORT);
75 dy |= (buttons & 0xf) << 4;
76 buttons = ((buttons >> 5) & 0x07);
77 if (dx != 0 || dy != 0 || buttons != mouse.buttons) {
78 add_mouse_randomness((buttons << 16) + (dy << 8) + dx);
79 mouse.buttons = buttons;
80 mouse.dx += dx;
81 mouse.dy -= dy;
82 mouse.ready = 1;
83 wake_up_interruptible(&mouse.wait);
84
85
86
87
88
89
90 if (mouse.dx < -2048)
91 mouse.dx = -2048;
92 if (mouse.dx > 2048)
93 mouse.dx = 2048;
94
95 if (mouse.dy < -2048)
96 mouse.dy = -2048;
97 if (mouse.dy > 2048)
98 mouse.dy = 2048;
99
100 if (mouse.fasyncptr)
101 kill_fasync(mouse.fasyncptr, SIGIO);
102 }
103 MSE_INT_ON();
104 }
105
106 static int fasync_mouse(struct inode *inode, struct file *filp, int on)
107 {
108 int retval;
109
110 retval = fasync_helper(inode, filp, on, &mouse.fasyncptr);
111 if (retval < 0)
112 return retval;
113 return 0;
114 }
115
116
117
118
119
120 static void close_mouse(struct inode * inode, struct file * file)
121 {
122 fasync_mouse(inode, file, 0);
123 if (--mouse.active)
124 return;
125 MSE_INT_OFF();
126 free_irq(mouse_irq);
127 MOD_DEC_USE_COUNT;
128 }
129
130
131
132
133
134 static int open_mouse(struct inode * inode, struct file * file)
135 {
136 if (!mouse.present)
137 return -EINVAL;
138 if (mouse.active++)
139 return 0;
140 if (request_irq(mouse_irq, mouse_interrupt, 0, "Busmouse")) {
141 mouse.active--;
142 return -EBUSY;
143 }
144 mouse.ready = 0;
145 mouse.dx = 0;
146 mouse.dy = 0;
147 mouse.buttons = 0x87;
148 MOD_INC_USE_COUNT;
149 MSE_INT_ON();
150 return 0;
151 }
152
153
154
155
156
157 static int write_mouse(struct inode * inode, struct file * file, const char * buffer, int count)
158 {
159 return -EINVAL;
160 }
161
162
163
164
165
166 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
167 {
168 int r;
169 int dx;
170 int dy;
171 unsigned char buttons;
172
173 if (count < 3)
174 return -EINVAL;
175 if ((r = verify_area(VERIFY_WRITE, buffer, count)))
176 return r;
177 if (!mouse.ready)
178 return -EAGAIN;
179
180
181
182
183
184
185
186
187 MSE_INT_OFF();
188 dx = mouse.dx;
189 dy = mouse.dy;
190 if (dx < -127)
191 dx = -127;
192 if (dx > 127)
193 dx = 127;
194 if (dy < -127)
195 dy = -127;
196 if (dy > 127)
197 dy = 127;
198 buttons = mouse.buttons;
199 mouse.dx -= dx;
200 mouse.dy -= dy;
201 mouse.ready = 0;
202 MSE_INT_ON();
203
204 put_user(buttons | 0x80, buffer);
205 put_user((char)dx, buffer + 1);
206 put_user((char)dy, buffer + 2);
207 for (r = 3; r < count; r++)
208 put_user(0x00, buffer + r);
209 return r;
210 }
211
212
213
214
215 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
216 {
217 if (sel_type == SEL_IN) {
218 if (mouse.ready)
219 return 1;
220 select_wait(&mouse.wait, wait);
221 }
222 return 0;
223 }
224
225 struct file_operations bus_mouse_fops = {
226 NULL,
227 read_mouse,
228 write_mouse,
229 NULL,
230 mouse_select,
231 NULL,
232 NULL,
233 open_mouse,
234 close_mouse,
235 NULL,
236 fasync_mouse,
237 };
238
239 static struct mouse bus_mouse = {
240 LOGITECH_BUSMOUSE, "busmouse", &bus_mouse_fops
241 };
242
243 int bus_mouse_init(void)
244 {
245 int i;
246
247 outb(MSE_CONFIG_BYTE, MSE_CONFIG_PORT);
248 outb(MSE_SIGNATURE_BYTE, MSE_SIGNATURE_PORT);
249 udelay(100L);
250 if (inb(MSE_SIGNATURE_PORT) != MSE_SIGNATURE_BYTE) {
251 mouse.present = 0;
252 return -EIO;
253 }
254 outb(MSE_DEFAULT_MODE, MSE_CONFIG_PORT);
255 MSE_INT_OFF();
256 mouse.present = 1;
257 mouse.active = 0;
258 mouse.ready = 0;
259 mouse.buttons = 0x87;
260 mouse.dx = 0;
261 mouse.dy = 0;
262 mouse.wait = NULL;
263 printk("Logitech Bus mouse detected and installed with IRQ %d.\n",
264 mouse_irq);
265 mouse_register(&bus_mouse);
266 return 0;
267 }
268
269 #ifdef MODULE
270
271 int init_module(void)
272 {
273 return bus_mouse_init();
274 }
275
276 void cleanup_module(void)
277 {
278 mouse_deregister(&bus_mouse);
279 }
280 #endif