This source file includes following definitions.
- mouse_interrupt
- fasync_mouse
- close_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- amiga_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 #include <linux/module.h>
32
33 #include <linux/types.h>
34 #include <linux/kernel.h>
35 #include <linux/sched.h>
36 #include <linux/mm.h>
37 #include <linux/signal.h>
38 #include <linux/errno.h>
39 #include <linux/miscdevice.h>
40 #include <linux/random.h>
41
42 #include <asm/system.h>
43 #include <asm/segment.h>
44 #include <asm/irq.h>
45 #include <asm/amigamouse.h>
46 #include <asm/amigahw.h>
47 #include <asm/amigaints.h>
48 #include <asm/bootinfo.h>
49
50 #define MSE_INT_ON() mouseint_allowed = 1
51 #define MSE_INT_OFF() mouseint_allowed = 0
52
53
54 static struct mouse_status mouse;
55
56 static int mouseint_allowed;
57
58 static void mouse_interrupt(int irq, struct pt_regs *fp, void *dummy)
59 {
60 static int lastx=0, lasty=0;
61 int dx, dy;
62 int nx, ny;
63 unsigned char buttons;
64
65 unsigned short joy0dat, potgor;
66
67 if(!mouseint_allowed)
68 return;
69 MSE_INT_OFF();
70
71
72
73
74
75
76 joy0dat = custom.joy0dat;
77
78 nx = joy0dat & 0xff;
79 ny = joy0dat >> 8;
80
81 dx = nx - lastx;
82 if (dx < - 127)
83 dx = (256 + nx) - lastx;
84
85 if (dx > 127)
86 dx = (nx - 256) - lastx;
87
88 dy = ny - lasty;
89 if (dy < - 127)
90 dy = (256 + ny) - lasty;
91
92 if (dy > 127)
93 dy = (ny - 256) - lasty;
94
95 lastx = nx;
96 lasty = ny;
97
98 #if 0
99 dx = -lastdx;
100 dx += (lastdx = joy0dat & 0xff);
101 if (dx < -127)
102 dx = -255-dx;
103 else
104 if (dx > 127)
105 dx = 255-dx;
106
107 dy = -lastdy;
108 dy += (lastdy = joy0dat >> 8);
109 if (dy < -127)
110 dy = -255-dy;
111 else
112 if (dy > 127)
113 dy = 255-dy;
114 #endif
115
116
117 potgor = custom.potgor;
118 buttons = (ciaa.pra & 0x40 ? 4 : 0) |
119 #if 1
120 (potgor & 0x0100 ? 2 : 0) |
121 #endif
122 (potgor & 0x0400 ? 1 : 0);
123
124
125 if (dx != 0 || dy != 0 || buttons != mouse.buttons) {
126 add_mouse_randomness((buttons << 16) + (dy << 8) + dx);
127 mouse.buttons = buttons;
128 mouse.dx += dx;
129 mouse.dy -= dy;
130 mouse.ready = 1;
131 wake_up_interruptible(&mouse.wait);
132
133
134
135
136
137
138 if (mouse.dx < -2048)
139 mouse.dx = -2048;
140 else
141 if (mouse.dx > 2048)
142 mouse.dx = 2048;
143
144 if (mouse.dy < -2048)
145 mouse.dy = -2048;
146 else
147 if (mouse.dy > 2048)
148 mouse.dy = 2048;
149
150 if (mouse.fasyncptr)
151 kill_fasync(mouse.fasyncptr, SIGIO);
152 }
153 MSE_INT_ON();
154 }
155
156 static int fasync_mouse(struct inode *inode, struct file *filp, int on)
157 {
158 int retval;
159
160 retval = fasync_helper(inode, filp, on, &mouse.fasyncptr);
161 if (retval < 0)
162 return retval;
163 return 0;
164 }
165
166
167
168
169
170 static void close_mouse(struct inode * inode, struct file * file)
171 {
172 fasync_mouse(inode, file, 0);
173 if (--mouse.active)
174 return;
175 MSE_INT_OFF();
176 MOD_DEC_USE_COUNT;
177 }
178
179
180
181
182
183
184 static int open_mouse(struct inode * inode, struct file * file)
185 {
186 if (!mouse.present)
187 return -EINVAL;
188 if (mouse.active++)
189 return 0;
190 mouse.ready = 0;
191 mouse.dx = 0;
192 mouse.dy = 0;
193 mouse.buttons = 0x87;
194 mouse.active = 1;
195 MOD_INC_USE_COUNT;
196 MSE_INT_ON();
197 return 0;
198 }
199
200
201
202
203
204 static int write_mouse(struct inode * inode, struct file * file, const char * buffer, int count)
205 {
206 return -EINVAL;
207 }
208
209
210
211
212
213 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
214 {
215 int r;
216 int dx;
217 int dy;
218 unsigned char buttons;
219
220 if (count < 3)
221 return -EINVAL;
222 if ((r = verify_area(VERIFY_WRITE, buffer, count)))
223 return r;
224 if (!mouse.ready)
225 return -EAGAIN;
226
227
228
229
230
231
232
233
234 MSE_INT_OFF();
235 dx = mouse.dx;
236 dy = mouse.dy;
237 if (dx < -127)
238 dx = -127;
239 else
240 if (dx > 127)
241 dx = 127;
242 if (dy < -127)
243 dy = -127;
244 else
245 if (dy > 127)
246 dy = 127;
247 buttons = mouse.buttons;
248 mouse.dx -= dx;
249 mouse.dy -= dy;
250 mouse.ready = 0;
251 MSE_INT_ON();
252
253 put_fs_byte(buttons | 0x80, buffer);
254 put_fs_byte((char)dx, buffer + 1);
255 put_fs_byte((char)dy, buffer + 2);
256 for (r = 3; r < count; r++)
257 put_fs_byte(0x00, buffer + r);
258 return r;
259 }
260
261
262
263
264
265 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
266 {
267 if (sel_type == SEL_IN) {
268 if (mouse.ready)
269 return 1;
270 select_wait(&mouse.wait, wait);
271 }
272 return 0;
273 }
274
275 struct file_operations amiga_mouse_fops = {
276 NULL,
277 read_mouse,
278 write_mouse,
279 NULL,
280 mouse_select,
281 NULL,
282 NULL,
283 open_mouse,
284 close_mouse,
285 NULL,
286 fasync_mouse,
287 };
288
289 static struct miscdevice amiga_mouse = {
290 AMIGAMOUSE_MINOR, "amigamouse", &amiga_mouse_fops
291 };
292
293 int amiga_mouse_init(void)
294 {
295 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
296 return -ENODEV;
297
298 custom.joytest = 0;
299
300 MSE_INT_OFF();
301
302 mouse.active = 0;
303 mouse.ready = 0;
304 mouse.buttons = 0x87;
305 mouse.dx = 0;
306 mouse.dy = 0;
307 mouse.wait = NULL;
308
309
310
311
312
313 if(!add_isr(IRQ_AMIGA_VERTB, mouse_interrupt, 0, NULL, "Amiga mouse"))
314 {
315 mouse.present = 0;
316 printk(KERN_INFO "Installing Amiga mouse failed.\n");
317 return -EIO;
318 }
319
320 mouse.present = 1;
321
322 printk(KERN_INFO "Amiga mouse installed.\n");
323 misc_register(&amiga_mouse);
324 return 0;
325 }
326
327 #ifdef MODULE
328 #include <asm/bootinfo.h>
329
330 int init_module(void)
331 {
332 return amiga_mouse_init();
333 }
334
335 void cleanup_module(void)
336 {
337 remove_isr(IRQ_AMIGA_VERTB, mouse_interrupt);
338 misc_deregister(&amiga_mouse);
339 }
340 #endif