This source file includes following definitions.
- bmouse_setup
- mouse_interrupt
- fasync_mouse
- close_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- 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 #ifdef MODULE
32 #include <linux/module.h>
33 #include <linux/version.h>
34 #else
35 #define MOD_INC_USE_COUNT
36 #define MOD_DEC_USE_COUNT
37 #endif
38
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/busmouse.h>
42 #include <linux/signal.h>
43 #include <linux/errno.h>
44 #include <linux/mm.h>
45 #include <linux/mouse.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 mouse.buttons = buttons;
79 mouse.dx += dx;
80 mouse.dy -= dy;
81 mouse.ready = 1;
82 wake_up_interruptible(&mouse.wait);
83
84
85
86
87
88
89 if (mouse.dx < -2048)
90 mouse.dx = -2048;
91 if (mouse.dx > 2048)
92 mouse.dx = 2048;
93
94 if (mouse.dy < -2048)
95 mouse.dy = -2048;
96 if (mouse.dy > 2048)
97 mouse.dy = 2048;
98
99 if (mouse.fasyncptr)
100 kill_fasync(mouse.fasyncptr, SIGIO);
101 }
102 MSE_INT_ON();
103 }
104
105 static int fasync_mouse(struct inode *inode, struct file *filp, int on)
106 {
107 int retval;
108
109 retval = fasync_helper(inode, filp, on, &mouse.fasyncptr);
110 if (retval < 0)
111 return retval;
112 return 0;
113 }
114
115
116
117
118
119
120 static void close_mouse(struct inode * inode, struct file * file)
121 {
122 if (--mouse.active == 0) {
123 MSE_INT_OFF();
124 free_irq(mouse_irq);
125 }
126 fasync_mouse(inode, file, 0);
127 }
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 -EBUSY;
140 mouse.ready = 0;
141 mouse.dx = 0;
142 mouse.dy = 0;
143 mouse.buttons = 0x87;
144 if (request_irq(mouse_irq, mouse_interrupt, 0, "Busmouse"))
145 return -EBUSY;
146 mouse.active = 1;
147 MSE_INT_ON();
148 return 0;
149 }
150
151
152
153
154
155 static int write_mouse(struct inode * inode, struct file * file, const char * buffer, int count)
156 {
157 return -EINVAL;
158 }
159
160
161
162
163
164 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
165 {
166 int r;
167 int dx;
168 int dy;
169 unsigned char buttons;
170
171 if (count < 3)
172 return -EINVAL;
173 if ((r = verify_area(VERIFY_WRITE, buffer, count)))
174 return r;
175 if (!mouse.ready)
176 return -EAGAIN;
177
178
179
180
181
182
183
184
185 MSE_INT_OFF();
186 dx = mouse.dx;
187 dy = mouse.dy;
188 if (dx < -127)
189 dx = -127;
190 if (dx > 127)
191 dx = 127;
192 if (dy < -127)
193 dy = -127;
194 if (dy > 127)
195 dy = 127;
196 buttons = mouse.buttons;
197 mouse.dx -= dx;
198 mouse.dy -= dy;
199 mouse.ready = 0;
200 MSE_INT_ON();
201
202 put_user(buttons | 0x80, buffer);
203 put_user((char)dx, buffer + 1);
204 put_user((char)dy, buffer + 2);
205 for (r = 3; r < count; r++)
206 put_user(0x00, buffer + r);
207 return r;
208 }
209
210
211
212
213
214
215
216
217 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
218 {
219 int r = 0;
220
221 if (sel_type == SEL_IN) {
222 MSE_INT_OFF();
223 if (mouse.ready) {
224 r = 1;
225 } else {
226 select_wait(&mouse.wait, wait);
227 }
228 MSE_INT_ON();
229 }
230 return(r);
231 }
232
233 struct file_operations bus_mouse_fops = {
234 NULL,
235 read_mouse,
236 write_mouse,
237 NULL,
238 mouse_select,
239 NULL,
240 NULL,
241 open_mouse,
242 close_mouse,
243 NULL,
244 fasync_mouse,
245 };
246
247 static struct mouse bus_mouse = {
248 LOGITECH_BUSMOUSE, "busmouse", &bus_mouse_fops
249 };
250
251 #ifdef MODULE
252 char kernel_version[] = UTS_RELEASE;
253
254 int init_module(void)
255 #else
256 unsigned long bus_mouse_init(unsigned long kmem_start)
257 #endif
258 {
259 int i;
260
261 outb(MSE_CONFIG_BYTE, MSE_CONFIG_PORT);
262 outb(MSE_SIGNATURE_BYTE, MSE_SIGNATURE_PORT);
263 for (i = 0; i < 100000; i++)
264 ;
265 if (inb(MSE_SIGNATURE_PORT) != MSE_SIGNATURE_BYTE) {
266 mouse.present = 0;
267 #ifdef MODULE
268 return -EIO;
269 #else
270 return kmem_start;
271 #endif
272 }
273 outb(MSE_DEFAULT_MODE, MSE_CONFIG_PORT);
274 MSE_INT_OFF();
275 mouse.present = 1;
276 mouse.active = 0;
277 mouse.ready = 0;
278 mouse.buttons = 0x87;
279 mouse.dx = 0;
280 mouse.dy = 0;
281 mouse.wait = NULL;
282 printk("Logitech Bus mouse detected and installed with IRQ %d.\n",
283 mouse_irq);
284 mouse_register(&bus_mouse);
285 #ifdef MODULE
286 return 0;
287 #else
288 return kmem_start;
289 #endif
290 }
291
292 #ifdef MODULE
293 void cleanup_module(void)
294 {
295 if (MOD_IN_USE)
296 printk("busmouse: in use - remove delayed\n");
297 mouse_deregister(&bus_mouse);
298 }
299 #endif