This source file includes following definitions.
- ms_mouse_interrupt
- release_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- ms_bus_mouse_init
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/kernel.h>
32 #include <linux/sched.h>
33 #include <linux/busmouse.h>
34 #include <linux/tty.h>
35 #include <linux/signal.h>
36 #include <linux/errno.h>
37
38 #include <asm/io.h>
39 #include <asm/segment.h>
40 #include <asm/system.h>
41 #include <asm/irq.h>
42
43 static struct mouse_status mouse;
44
45 static void ms_mouse_interrupt(int unused)
46 {
47 char dx, dy, buttons;
48
49 outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
50 outb((inb(MS_MSE_DATA_PORT) | 0x20), MS_MSE_DATA_PORT);
51
52 outb(MS_MSE_READ_X, MS_MSE_CONTROL_PORT);
53 dx = inb(MS_MSE_DATA_PORT);
54
55 outb(MS_MSE_READ_Y, MS_MSE_CONTROL_PORT);
56 dy = inb(MS_MSE_DATA_PORT);
57
58 outb(MS_MSE_READ_BUTTONS, MS_MSE_CONTROL_PORT);
59 buttons = ~(inb(MS_MSE_DATA_PORT)) & 0x07;
60
61 outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
62 outb((inb(MS_MSE_DATA_PORT) & 0xdf), MS_MSE_DATA_PORT);
63
64 if (dx != 0 || dy != 0 || buttons != mouse.buttons) {
65 mouse.buttons = buttons;
66 mouse.dx += dx;
67 mouse.dy += dy;
68 mouse.ready = 1;
69 wake_up_interruptible(&mouse.wait);
70 }
71 }
72
73 static void release_mouse(struct inode * inode, struct file * file)
74 {
75 MS_MSE_INT_OFF();
76 mouse.active = mouse.ready = 0;
77 free_irq(MOUSE_IRQ);
78 }
79
80 static int open_mouse(struct inode * inode, struct file * file)
81 {
82 if (!mouse.present)
83 return -EINVAL;
84 if (mouse.active)
85 return -EBUSY;
86 mouse.active = 1;
87 mouse.ready = mouse.dx = mouse.dy = 0;
88 mouse.buttons = 0x80;
89 if (request_irq(MOUSE_IRQ, ms_mouse_interrupt)) {
90 mouse.active = 0;
91 return -EBUSY;
92 }
93 outb(MS_MSE_START, MS_MSE_CONTROL_PORT);
94 MS_MSE_INT_ON();
95 return 0;
96 }
97
98
99 static int write_mouse(struct inode * inode, struct file * file, char * buffer, int count)
100 {
101 return -EINVAL;
102 }
103
104 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
105 {
106 int i;
107
108 if (count < 3)
109 return -EINVAL;
110 if (!mouse.ready)
111 return -EAGAIN;
112 put_fs_byte(mouse.buttons | 0x80, buffer);
113 put_fs_byte((char)(mouse.dx<-127 ? -127 : mouse.dx>127 ? 127 : mouse.dx), buffer + 1);
114 put_fs_byte((char)(mouse.dy<-127 ? 127 : mouse.dy>127 ? -127 : -mouse.dy), buffer + 2);
115 for (i = 3; i < count; i++)
116 put_fs_byte(0x00, buffer + i);
117 mouse.dx = mouse.dy = mouse.ready = 0;
118 return i;
119 }
120
121 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
122 {
123 if (sel_type != SEL_IN)
124 return 0;
125 if (mouse.ready)
126 return 1;
127 select_wait(&mouse.wait,wait);
128 return 0;
129 }
130
131 struct file_operations ms_bus_mouse_fops = {
132 NULL,
133 read_mouse,
134 write_mouse,
135 NULL,
136 mouse_select,
137 NULL,
138 NULL,
139 open_mouse,
140 release_mouse,
141 };
142
143 unsigned long ms_bus_mouse_init(unsigned long kmem_start)
144 {
145 int mse_byte, i;
146
147 mouse.present = mouse.active = mouse.ready = 0;
148 mouse.buttons = 0x80;
149 mouse.dx = mouse.dy = 0;
150 mouse.wait = NULL;
151 if (inb_p(MS_MSE_SIGNATURE_PORT) == 0xde) {
152
153 mse_byte = inb_p(MS_MSE_SIGNATURE_PORT);
154
155 for (i = 0; i < 4; i++) {
156 if (inb_p(MS_MSE_SIGNATURE_PORT) == 0xde) {
157 if (inb_p(MS_MSE_SIGNATURE_PORT) == mse_byte)
158 mouse.present = 1;
159 else
160 mouse.present = 0;
161 } else
162 mouse.present = 0;
163 }
164 }
165 if (mouse.present == 0) {
166 return kmem_start;
167 }
168 MS_MSE_INT_OFF();
169 printk("Microsoft BusMouse detected and installed.\n");
170 return kmem_start;
171 }