This source file includes following definitions.
- bmouse_setup
- mouse_interrupt
- release_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- 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 #include <linux/kernel.h>
23 #include <linux/sched.h>
24 #include <linux/busmouse.h>
25 #include <linux/tty.h>
26 #include <linux/signal.h>
27 #include <linux/errno.h>
28
29 #include <asm/io.h>
30 #include <asm/segment.h>
31 #include <asm/system.h>
32 #include <asm/irq.h>
33
34 static struct mouse_status mouse;
35 static int mouse_irq = MOUSE_IRQ;
36
37 void bmouse_setup(char *str, int *ints)
38 {
39 if (ints[0] > 0)
40 mouse_irq=ints[1];
41 }
42
43 static void mouse_interrupt(int unused)
44 {
45 char dx, dy;
46 unsigned char buttons;
47
48 MSE_INT_OFF();
49 outb(MSE_READ_X_LOW, MSE_CONTROL_PORT);
50 dx = (inb(MSE_DATA_PORT) & 0xf);
51 outb(MSE_READ_X_HIGH, MSE_CONTROL_PORT);
52 dx |= (inb(MSE_DATA_PORT) & 0xf) << 4;
53 outb(MSE_READ_Y_LOW, MSE_CONTROL_PORT );
54 dy = (inb(MSE_DATA_PORT) & 0xf);
55 outb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT);
56 buttons = inb(MSE_DATA_PORT);
57 dy |= (buttons & 0xf) << 4;
58 buttons = ((buttons >> 5) & 0x07);
59 if (dx != 0 || dy != 0 || buttons != mouse.buttons) {
60 mouse.buttons = buttons;
61 mouse.dx += dx;
62 mouse.dy += dy;
63 mouse.ready = 1;
64 wake_up_interruptible(&mouse.wait);
65 }
66 MSE_INT_ON();
67 }
68
69 static void release_mouse(struct inode * inode, struct file * file)
70 {
71 MSE_INT_OFF();
72 mouse.active = 0;
73 mouse.ready = 0;
74 free_irq(mouse_irq);
75 }
76
77 static int open_mouse(struct inode * inode, struct file * file)
78 {
79 if (!mouse.present)
80 return -EINVAL;
81 if (mouse.active)
82 return -EBUSY;
83 mouse.active = 1;
84 mouse.ready = 0;
85 mouse.dx = 0;
86 mouse.dy = 0;
87 mouse.buttons = 0x87;
88 if (request_irq(mouse_irq, mouse_interrupt)) {
89 mouse.active = 0;
90 return -EBUSY;
91 }
92 MSE_INT_ON();
93 return 0;
94 }
95
96
97 static int write_mouse(struct inode * inode, struct file * file, char * buffer, int count)
98 {
99 return -EINVAL;
100 }
101
102 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
103 {
104 int i;
105
106 if (count < 3)
107 return -EINVAL;
108 if (!mouse.ready)
109 return -EAGAIN;
110 MSE_INT_OFF();
111 put_fs_byte(mouse.buttons | 0x80, buffer);
112 if (mouse.dx < -127)
113 mouse.dx = -127;
114 if (mouse.dx > 127)
115 mouse.dx = 127;
116 put_fs_byte((char)mouse.dx, buffer + 1);
117 if (mouse.dy < -127)
118 mouse.dy = -127;
119 if (mouse.dy > 127)
120 mouse.dy = 127;
121 put_fs_byte((char) -mouse.dy, buffer + 2);
122 for (i = 3; i < count; i++)
123 put_fs_byte(0x00, buffer + i);
124 mouse.dx = 0;
125 mouse.dy = 0;
126 mouse.ready = 0;
127 MSE_INT_ON();
128 return i;
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 return 0;
135 if (mouse.ready)
136 return 1;
137 select_wait(&mouse.wait, wait);
138 return 0;
139 }
140
141 struct file_operations bus_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 };
152
153 unsigned long bus_mouse_init(unsigned long kmem_start)
154 {
155 int i;
156
157 outb(MSE_CONFIG_BYTE, MSE_CONFIG_PORT);
158 outb(MSE_SIGNATURE_BYTE, MSE_SIGNATURE_PORT);
159 for (i = 0; i < 100000; i++)
160 ;
161 if (inb(MSE_SIGNATURE_PORT) != MSE_SIGNATURE_BYTE) {
162 mouse.present = 0;
163 return kmem_start;
164 }
165 outb(MSE_DEFAULT_MODE, MSE_CONFIG_PORT);
166 MSE_INT_OFF();
167 mouse.present = 1;
168 mouse.active = 0;
169 mouse.ready = 0;
170 mouse.buttons = 0x87;
171 mouse.dx = 0;
172 mouse.dy = 0;
173 mouse.wait = NULL;
174 printk("Logitech Bus mouse detected and installed.\n");
175 return kmem_start;
176 }