This source file includes following definitions.
- atari_mouse_interrupt
- fasync_mouse
- release_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- atari_mouse_init
- atari_mouse_setup
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include <linux/module.h>
16
17 #include <linux/sched.h>
18 #include <linux/errno.h>
19 #include <linux/miscdevice.h>
20 #include <linux/mm.h>
21 #include <linux/random.h>
22
23 #include <asm/atarikb.h>
24 #include <asm/atari_mouse.h>
25 #include <asm/segment.h>
26 #include <asm/bootinfo.h>
27
28 static struct mouse_status mouse;
29 static int atari_mouse_x_threshold = 2, atari_mouse_y_threshold = 2;
30 extern int atari_mouse_buttons;
31
32 static void atari_mouse_interrupt(char *buf)
33 {
34 int buttons;
35
36
37
38 buttons = ((buf[0] & 1 ? 1 : 0)
39 | (buf[0] & 2 ? 4 : 0)
40 | (atari_mouse_buttons & 2));
41 atari_mouse_buttons = buttons;
42 add_mouse_randomness((buttons << 16) + (buf[2] << 8) + buf[1]);
43 mouse.buttons = ~buttons & 7;
44 mouse.dx += buf[1];
45 mouse.dy -= buf[2];
46 mouse.ready = 1;
47 wake_up_interruptible(&mouse.wait);
48 if (mouse.fasyncptr)
49 kill_fasync(mouse.fasyncptr, SIGIO);
50
51
52 }
53
54 static int fasync_mouse(struct inode *inode, struct file *filp, int on)
55 {
56 int retval;
57
58 retval = fasync_helper(inode, filp, on, &mouse.fasyncptr);
59 if (retval < 0)
60 return retval;
61 return 0;
62 }
63
64 static void release_mouse(struct inode *inode, struct file *file)
65 {
66 fasync_mouse(inode, file, 0);
67 if (--mouse.active)
68 return;
69 ikbd_mouse_disable();
70
71 atari_mouse_interrupt_hook = NULL;
72 MOD_DEC_USE_COUNT;
73 }
74
75 static int open_mouse(struct inode *inode, struct file *file)
76 {
77 if (mouse.active++)
78 return 0;
79 mouse.ready = 0;
80 mouse.dx = mouse.dy = 0;
81 atari_mouse_buttons = 0;
82 ikbd_mouse_y0_top ();
83 ikbd_mouse_thresh (atari_mouse_x_threshold, atari_mouse_y_threshold);
84 ikbd_mouse_rel_pos();
85 MOD_INC_USE_COUNT;
86 atari_mouse_interrupt_hook = atari_mouse_interrupt;
87 return 0;
88 }
89
90 static int write_mouse(struct inode *inode, struct file *file, const char *buffer, int count)
91 {
92 return -EINVAL;
93 }
94
95 static int read_mouse(struct inode *inode, struct file *file, char *buffer, int count)
96 {
97 int dx, dy, buttons;
98 int r;
99
100 if (count < 3)
101 return -EINVAL;
102 if ((r = verify_area(VERIFY_WRITE, buffer, count)))
103 return r;
104 if (!mouse.ready)
105 return -EAGAIN;
106
107 dx = mouse.dx;
108 dy = mouse.dy;
109 buttons = mouse.buttons;
110 if (dx > 127)
111 dx = 127;
112 else if (dx < -128)
113 dx = -128;
114 if (dy > 127)
115 dy = 127;
116 else if (dy < -128)
117 dy = -128;
118 mouse.dx -= dx;
119 mouse.dy -= dy;
120 if (mouse.dx == 0 && mouse.dy == 0)
121 mouse.ready = 0;
122
123 put_user(buttons | 0x80, buffer);
124 put_user((char) dx, buffer + 1);
125 put_user((char) dy, buffer + 2);
126 for (r = 3; r < count; r++)
127 put_user (0, buffer + r);
128 return r;
129 }
130
131 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table *wait)
132 {
133 if (sel_type == SEL_IN) {
134 if (mouse.ready)
135 return 1;
136 select_wait(&mouse.wait, wait);
137 }
138 return 0;
139 }
140
141 struct file_operations atari_mouse_fops = {
142 NULL,
143 read_mouse,
144 write_mouse,
145 NULL,
146 mouse_select,
147 NULL,
148 NULL,
149 open_mouse,
150 release_mouse,
151 NULL,
152 fasync_mouse,
153 };
154
155 static struct miscdevice atari_mouse = {
156 ATARIMOUSE_MINOR, "atarimouse", &atari_mouse_fops
157 };
158
159 int atari_mouse_init(void)
160 {
161 mouse.active = 0;
162 mouse.ready = 0;
163 mouse.wait = NULL;
164
165 if (!MACH_IS_ATARI)
166 return -ENODEV;
167 printk(KERN_INFO "Atari mouse installed.\n");
168 misc_register(&atari_mouse);
169 return 0;
170 }
171
172
173 #define MIN_THRESHOLD 1
174 #define MAX_THRESHOLD 20
175
176 void atari_mouse_setup( char *str, int *ints )
177 {
178 if (ints[0] < 1) {
179 printk( "atari_mouse_setup: no arguments!\n" );
180 return;
181 }
182 else if (ints[0] > 2) {
183 printk( "atari_mouse_setup: too many arguments\n" );
184 }
185
186 if (ints[1] < MIN_THRESHOLD || ints[1] > MAX_THRESHOLD)
187 printk( "atari_mouse_setup: bad threshold value (ignored)\n" );
188 else {
189 atari_mouse_x_threshold = ints[1];
190 atari_mouse_y_threshold = ints[1];
191 if (ints[0] > 1) {
192 if (ints[2] < MIN_THRESHOLD || ints[2] > MAX_THRESHOLD)
193 printk("atari_mouse_setup: bad threshold value (ignored)\n" );
194 else
195 atari_mouse_y_threshold = ints[2];
196 }
197 }
198
199 }
200
201 #ifdef MODULE
202 #include <asm/bootinfo.h>
203
204 int init_module(void)
205 {
206 return atari_mouse_init();
207 }
208
209 void cleanup_module(void)
210 {
211 misc_deregister(&atari_mouse);
212 }
213 #endif