This source file includes following definitions.
- mouse_interrupt
- release_mouse
- open_mouse
- write_mouse
- read_mouse
- mouse_select
- atixl_busmouse_init
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/tty.h>
15 #include <linux/signal.h>
16 #include <linux/errno.h>
17
18 #include <asm/io.h>
19 #include <asm/segment.h>
20 #include <asm/system.h>
21 #include <asm/irq.h>
22
23 #define ATIXL_MOUSE_IRQ 5
24 #define ATIXL_BUSMOUSE 3
25
26
27
28 #define ATIXL_MSE_DATA_PORT 0x23d
29 #define ATIXL_MSE_SIGNATURE_PORT 0x23e
30 #define ATIXL_MSE_CONTROL_PORT 0x23c
31
32 #define ATIXL_MSE_READ_BUTTONS 0x00
33 #define ATIXL_MSE_READ_X 0x01
34 #define ATIXL_MSE_READ_Y 0x02
35
36
37
38
39 #define ATIXL_MSE_DISABLE_UPDATE() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \
40 outb( (0x20 | inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); }
41
42
43 #define ATIXL_MSE_ENABLE_UPDATE() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \
44 outb( (0xdf & inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); }
45
46
47 #define ATIXL_MSE_INT_OFF() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \
48 outb( (0xe7 & inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); }
49
50
51 #define ATIXL_MSE_INT_ON() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \
52 outb( (0x08 | inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); }
53
54
55
56 static struct mouse_status {
57 char buttons;
58 char latch_buttons;
59 int dx;
60 int dy;
61 int present;
62 int ready;
63 int active;
64 struct wait_queue *wait;
65 } mouse;
66
67 void mouse_interrupt(int unused)
68 {
69 char dx, dy, buttons;
70
71 ATIXL_MSE_DISABLE_UPDATE();
72 outb(ATIXL_MSE_READ_X, ATIXL_MSE_CONTROL_PORT);
73 dx = inb( ATIXL_MSE_DATA_PORT);
74 outb(ATIXL_MSE_READ_Y, ATIXL_MSE_CONTROL_PORT);
75 dy = inb( ATIXL_MSE_DATA_PORT);
76 outb(ATIXL_MSE_READ_BUTTONS, ATIXL_MSE_CONTROL_PORT);
77 buttons = inb( ATIXL_MSE_DATA_PORT);
78 if (dx != 0 || dy != 0 || buttons != mouse.latch_buttons) {
79 mouse.latch_buttons |= buttons;
80 mouse.dx += dx;
81 mouse.dy += dy;
82 mouse.ready = 1;
83 wake_up_interruptible(&mouse.wait);
84 }
85 ATIXL_MSE_ENABLE_UPDATE();
86 }
87
88 static void release_mouse(struct inode * inode, struct file * file)
89 {
90 ATIXL_MSE_INT_OFF();
91 mouse.active = 0;
92 mouse.ready = 0;
93 free_irq(ATIXL_MOUSE_IRQ);
94 }
95
96
97 static int open_mouse(struct inode * inode, struct file * file)
98 {
99 if (!mouse.present)
100 return -EINVAL;
101 if (mouse.active)
102 return -EBUSY;
103 mouse.active = 1;
104 mouse.ready = 0;
105 mouse.dx = 0;
106 mouse.dy = 0;
107 mouse.buttons = mouse.latch_buttons = 0;
108 if (request_irq(ATIXL_MOUSE_IRQ, mouse_interrupt)) {
109 mouse.active = 0;
110 return -EBUSY;
111 }
112 ATIXL_MSE_INT_ON();
113 return 0;
114 }
115
116
117 static int write_mouse(struct inode * inode, struct file * file, char * buffer, int count)
118 {
119 return -EINVAL;
120 }
121
122 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
123 {
124 int i;
125
126 if (count < 3)
127 return -EINVAL;
128 if (!mouse.ready)
129 return -EAGAIN;
130 ATIXL_MSE_DISABLE_UPDATE();
131
132 put_fs_byte((char)(~mouse.latch_buttons&7) | 0x80 , buffer);
133 if (mouse.dx < -127)
134 mouse.dx = -127;
135 if (mouse.dx > 127)
136 mouse.dx = 127;
137 put_fs_byte((char)mouse.dx, buffer + 1);
138 if (mouse.dy < -127)
139 mouse.dy = -127;
140 if (mouse.dy > 127)
141 mouse.dy = 127;
142 put_fs_byte((char)-mouse.dy, buffer + 2);
143 for(i = 3; i < count; i++)
144 put_fs_byte(0x00, buffer + i);
145 mouse.dx = 0;
146 mouse.dy = 0;
147 mouse.latch_buttons = mouse.buttons;
148 mouse.ready = 0;
149 ATIXL_MSE_ENABLE_UPDATE();
150 return i;
151 }
152
153 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
154 {
155 if (sel_type != SEL_IN)
156 return 0;
157 if (mouse.ready)
158 return 1;
159 select_wait(&mouse.wait,wait);
160 return 0;
161 }
162
163 struct file_operations atixl_busmouse_fops = {
164 NULL,
165 read_mouse,
166 write_mouse,
167 NULL,
168 mouse_select,
169 NULL,
170 NULL,
171 open_mouse,
172 release_mouse,
173 };
174
175 unsigned long atixl_busmouse_init(unsigned long kmem_start)
176 {
177 unsigned char a,b,c;
178
179 a = inb( ATIXL_MSE_SIGNATURE_PORT );
180 b = inb( ATIXL_MSE_SIGNATURE_PORT );
181 c = inb( ATIXL_MSE_SIGNATURE_PORT );
182 if (( a != b ) && ( a == c ))
183 printk("\nATI Inport ");
184 else{
185 mouse.present = 0;
186 return kmem_start;
187 }
188 outb(0x80, ATIXL_MSE_CONTROL_PORT);
189 outb(0x07, ATIXL_MSE_CONTROL_PORT);
190 outb(0x0a, ATIXL_MSE_DATA_PORT);
191 mouse.present = 1;
192 mouse.active = 0;
193 mouse.ready = 0;
194 mouse.buttons = mouse.latch_buttons = 0;
195 mouse.dx = mouse.dy = 0;
196 mouse.wait = NULL;
197 printk("Bus mouse detected and installed.\n");
198 return kmem_start;
199 }