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