2 * Atari Mouse Driver for Linux
3 * by Robert de Vries (robert@and.nl) 19Jul93
5 * 16 Nov 1994 Andreas Schwab
6 * Compatibility with busmouse
7 * Support for three button mouse (shamelessly stolen from MiNT)
8 * third button wired to one of the joystick directions on joystick 1
10 * 1996/02/11 Andreas Schwab
12 * Allow multiple open's
15 #include <linux/module.h>
17 #include <linux/sched.h>
18 #include <linux/errno.h>
19 #include <linux/miscdevice.h>
21 #include <linux/random.h>
22 #include <linux/poll.h>
23 #include <linux/init.h>
24 #include <linux/busmouse.h>
26 #include <asm/setup.h>
27 #include <asm/atarikb.h>
28 #include <asm/uaccess.h>
30 static struct mouse_status mouse
;
31 static int mouse_threshold
[2] = {2,2};
32 MODULE_PARM(mouse_threshold
, "2i");
33 extern int atari_mouse_buttons
;
35 static void atari_mouse_interrupt(char *buf
)
39 /* ikbd_mouse_disable(); */
41 buttons
= ((buf
[0] & 1 ? 1 : 0)
42 | (buf
[0] & 2 ? 4 : 0)
43 | (atari_mouse_buttons
& 2));
44 atari_mouse_buttons
= buttons
;
45 add_mouse_randomness((buttons
<< 16) + (buf
[2] << 8) + buf
[1]);
46 mouse
.buttons
= ~buttons
& 7;
50 wake_up_interruptible(&mouse
.wait
);
52 kill_fasync(mouse
.fasyncptr
, SIGIO
);
54 /* ikbd_mouse_rel_pos(); */
57 static int fasync_mouse(int fd
, struct file
*filp
, int on
)
60 retval
= fasync_helper(fd
, filp
, on
, &mouse
.fasyncptr
);
66 static int release_mouse(struct inode
*inode
, struct file
*file
)
68 fasync_mouse(-1, file
, 0);
73 atari_mouse_interrupt_hook
= NULL
;
78 static int open_mouse(struct inode
*inode
, struct file
*file
)
83 mouse
.dx
= mouse
.dy
= 0;
84 atari_mouse_buttons
= 0;
86 ikbd_mouse_thresh (mouse_threshold
[0], mouse_threshold
[1]);
89 atari_mouse_interrupt_hook
= atari_mouse_interrupt
;
93 static ssize_t
write_mouse(struct file
*file
, const char *buffer
,
94 size_t count
, loff_t
*ppos
)
99 static ssize_t
read_mouse(struct file
* file
, char * buffer
,
100 size_t count
, loff_t
*ppos
)
108 /* ikbd_mouse_disable */
111 buttons
= mouse
.buttons
;
122 if (mouse
.dx
== 0 && mouse
.dy
== 0)
124 /* ikbd_mouse_rel_pos(); */
125 if (put_user(buttons
| 0x80, buffer
++) ||
126 put_user((char) dx
, buffer
++) ||
127 put_user((char) dy
, buffer
++))
130 if (clear_user(buffer
, count
- 3))
135 static unsigned int mouse_poll(struct file
*file
, poll_table
*wait
)
137 poll_wait(file
, &mouse
.wait
, wait
);
139 return POLLIN
| POLLRDNORM
;
143 struct file_operations atari_mouse_fops
= {
144 NULL
, /* mouse_seek */
147 NULL
, /* mouse_readdir */
149 NULL
, /* mouse_ioctl */
150 NULL
, /* mouse_mmap */
158 static struct miscdevice atari_mouse
= {
159 ATARIMOUSE_MINOR
, "atarimouse", &atari_mouse_fops
162 __initfunc(int atari_mouse_init(void))
173 r
= misc_register(&atari_mouse
);
177 printk(KERN_INFO
"Atari mouse installed.\n");
182 #define MIN_THRESHOLD 1
183 #define MAX_THRESHOLD 20 /* more seems not reasonable... */
185 __initfunc(void atari_mouse_setup( char *str
, int *ints
))
188 printk( "atari_mouse_setup: no arguments!\n" );
191 else if (ints
[0] > 2) {
192 printk( "atari_mouse_setup: too many arguments\n" );
195 if (ints
[1] < MIN_THRESHOLD
|| ints
[1] > MAX_THRESHOLD
)
196 printk( "atari_mouse_setup: bad threshold value (ignored)\n" );
198 mouse_threshold
[0] = ints
[1];
199 mouse_threshold
[1] = ints
[1];
201 if (ints
[2] < MIN_THRESHOLD
|| ints
[2] > MAX_THRESHOLD
)
202 printk("atari_mouse_setup: bad threshold value (ignored)\n" );
204 mouse_threshold
[1] = ints
[2];
211 int init_module(void)
213 return atari_mouse_init();
216 void cleanup_module(void)
218 misc_deregister(&atari_mouse
);