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, buttons;
46
47 MSE_INT_OFF();
48 outb(MSE_READ_X_LOW, MSE_CONTROL_PORT);
49 dx = (inb(MSE_DATA_PORT) & 0xf);
50 outb(MSE_READ_X_HIGH, MSE_CONTROL_PORT);
51 dx |= (inb(MSE_DATA_PORT) & 0xf) << 4;
52 outb(MSE_READ_Y_LOW, MSE_CONTROL_PORT );
53 dy = (inb(MSE_DATA_PORT) & 0xf);
54 outb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT);
55 buttons = inb(MSE_DATA_PORT);
56 dy |= (buttons & 0xf) << 4;
57 buttons = ((buttons >> 5) & 0x07);
58 if (dx != 0 || dy != 0 || buttons != mouse.buttons) {
59 mouse.buttons = buttons;
60 mouse.dx += dx;
61 mouse.dy += dy;
62 mouse.ready = 1;
63 wake_up_interruptible(&mouse.wait);
64 }
65 MSE_INT_ON();
66 }
67
68 static void release_mouse(struct inode * inode, struct file * file)
69 {
70 MSE_INT_OFF();
71 mouse.active = 0;
72 mouse.ready = 0;
73 free_irq(mouse_irq);
74 }
75
76 static int open_mouse(struct inode * inode, struct file * file)
77 {
78 if (!mouse.present)
79 return -EINVAL;
80 if (mouse.active)
81 return -EBUSY;
82 mouse.active = 1;
83 mouse.ready = 0;
84 mouse.dx = 0;
85 mouse.dy = 0;
86 mouse.buttons = 0x87;
87 if (request_irq(mouse_irq, mouse_interrupt)) {
88 mouse.active = 0;
89 return -EBUSY;
90 }
91 MSE_INT_ON();
92 return 0;
93 }
94
95
96 static int write_mouse(struct inode * inode, struct file * file, char * buffer, int count)
97 {
98 return -EINVAL;
99 }
100
101 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
102 {
103 int i;
104
105 if (count < 3)
106 return -EINVAL;
107 if (!mouse.ready)
108 return -EAGAIN;
109 MSE_INT_OFF();
110 put_fs_byte(mouse.buttons | 0x80, buffer);
111 if (mouse.dx < -127)
112 mouse.dx = -127;
113 if (mouse.dx > 127)
114 mouse.dx = 127;
115 put_fs_byte((char)mouse.dx, buffer + 1);
116 if (mouse.dy < -127)
117 mouse.dy = -127;
118 if (mouse.dy > 127)
119 mouse.dy = 127;
120 put_fs_byte((char) -mouse.dy, buffer + 2);
121 for (i = 3; i < count; i++)
122 put_fs_byte(0x00, buffer + i);
123 mouse.dx = 0;
124 mouse.dy = 0;
125 mouse.ready = 0;
126 MSE_INT_ON();
127 return i;
128 }
129
130 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
131 {
132 if (sel_type != SEL_IN)
133 return 0;
134 if (mouse.ready)
135 return 1;
136 select_wait(&mouse.wait, wait);
137 return 0;
138 }
139
140 struct file_operations bus_mouse_fops = {
141 NULL,
142 read_mouse,
143 write_mouse,
144 NULL,
145 mouse_select,
146 NULL,
147 NULL,
148 open_mouse,
149 release_mouse,
150 };
151
152 unsigned long bus_mouse_init(unsigned long kmem_start)
153 {
154 int i;
155
156 outb(MSE_CONFIG_BYTE, MSE_CONFIG_PORT);
157 outb(MSE_SIGNATURE_BYTE, MSE_SIGNATURE_PORT);
158 for (i = 0; i < 100000; i++)
159 ;
160 if (inb(MSE_SIGNATURE_PORT) != MSE_SIGNATURE_BYTE) {
161 mouse.present = 0;
162 return kmem_start;
163 }
164 outb(MSE_DEFAULT_MODE, MSE_CONFIG_PORT);
165 MSE_INT_OFF();
166 mouse.present = 1;
167 mouse.active = 0;
168 mouse.ready = 0;
169 mouse.buttons = 0x87;
170 mouse.dx = 0;
171 mouse.dy = 0;
172 mouse.wait = NULL;
173 printk("Logitech Bus mouse detected and installed.\n");
174 return kmem_start;
175 }