Loading...
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | /* * ATI XL Bus Mouse Driver for Linux * by Bob Harris (rth@sparta.com) * * Uses VFS interface for linux 0.98 (01OCT92) * * Modified by Chris Colohan (colohan@eecg.toronto.edu) * Modularised 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk> * * version 0.3a */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/signal.h> #include <linux/errno.h> #include <linux/miscdevice.h> #include <linux/random.h> #include <linux/poll.h> #include <linux/init.h> #include <asm/io.h> #include <asm/uaccess.h> #include <asm/system.h> #include <asm/irq.h> #define ATIXL_MOUSE_IRQ 5 /* H/W interrupt # set up on ATIXL board */ #define ATIXL_BUSMOUSE 3 /* Minor device # (mknod c 10 3 /dev/bm) */ /* ATI XL Inport Busmouse Definitions */ #define ATIXL_MSE_DATA_PORT 0x23d #define ATIXL_MSE_SIGNATURE_PORT 0x23e #define ATIXL_MSE_CONTROL_PORT 0x23c #define ATIXL_MSE_READ_BUTTONS 0x00 #define ATIXL_MSE_READ_X 0x01 #define ATIXL_MSE_READ_Y 0x02 /* Some nice ATI XL macros */ /* Select IR7, HOLD UPDATES (INT ENABLED), save X,Y */ #define ATIXL_MSE_DISABLE_UPDATE() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \ outb( (0x20 | inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); } /* Select IR7, Enable updates (INT ENABLED) */ #define ATIXL_MSE_ENABLE_UPDATE() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \ outb( (0xdf & inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); } /* Select IR7 - Mode Register, NO INTERRUPTS */ #define ATIXL_MSE_INT_OFF() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \ outb( (0xe7 & inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); } /* Select IR7 - Mode Register, DATA INTERRUPTS ENABLED */ #define ATIXL_MSE_INT_ON() { outb( 0x07, ATIXL_MSE_CONTROL_PORT ); \ outb( (0x08 | inb( ATIXL_MSE_DATA_PORT )), ATIXL_MSE_DATA_PORT ); } /* Same general mouse structure */ static struct mouse_status { char buttons; char latch_buttons; int dx; int dy; int present; int ready; int active; struct wait_queue *wait; struct fasync_struct *fasync; } mouse; void mouse_interrupt(int irq, void *dev_id, struct pt_regs * regs) { char dx, dy, buttons; ATIXL_MSE_DISABLE_UPDATE(); /* Note that interrupts are still enabled */ outb(ATIXL_MSE_READ_X, ATIXL_MSE_CONTROL_PORT); /* Select IR1 - X movement */ dx = inb( ATIXL_MSE_DATA_PORT); outb(ATIXL_MSE_READ_Y, ATIXL_MSE_CONTROL_PORT); /* Select IR2 - Y movement */ dy = inb( ATIXL_MSE_DATA_PORT); outb(ATIXL_MSE_READ_BUTTONS, ATIXL_MSE_CONTROL_PORT); /* Select IR0 - Button Status */ buttons = inb( ATIXL_MSE_DATA_PORT); if (dx != 0 || dy != 0 || buttons != mouse.latch_buttons) { add_mouse_randomness((buttons << 16) + (dy << 8) + dx); mouse.latch_buttons |= buttons; mouse.dx += dx; mouse.dy += dy; mouse.ready = 1; wake_up_interruptible(&mouse.wait); if (mouse.fasync) kill_fasync(mouse.fasync, SIGIO); } ATIXL_MSE_ENABLE_UPDATE(); } static int fasync_mouse(struct file *filp, int on) { int retval; retval = fasync_helper(filp, on, &mouse.fasync); if (retval < 0) return retval; return 0; } static int release_mouse(struct inode * inode, struct file * file) { fasync_mouse(file, 0); if (--mouse.active) return 0; ATIXL_MSE_INT_OFF(); /* Interrupts are really shut down here */ mouse.ready = 0; free_irq(ATIXL_MOUSE_IRQ, NULL); MOD_DEC_USE_COUNT; return 0; } static int open_mouse(struct inode * inode, struct file * file) { if (!mouse.present) return -EINVAL; if (mouse.active++) return 0; if (request_irq(ATIXL_MOUSE_IRQ, mouse_interrupt, 0, "ATIXL mouse", NULL)) { mouse.active--; return -EBUSY; } mouse.ready = 0; mouse.dx = 0; mouse.dy = 0; mouse.buttons = mouse.latch_buttons = 0; ATIXL_MSE_INT_ON(); /* Interrupts are really enabled here */ MOD_INC_USE_COUNT; return 0; } static ssize_t write_mouse(struct file * file, const char * buffer, size_t count, loff_t *ppos) { return -EINVAL; } static ssize_t read_mouse(struct file * file, char * buffer, size_t count, loff_t *ppos) { ssize_t i; if (count < 3) return -EINVAL; if (!mouse.ready) return -EAGAIN; ATIXL_MSE_DISABLE_UPDATE(); /* Allowed interrupts to occur during data gathering - shouldn't hurt */ put_user((char)(~mouse.latch_buttons&7) | 0x80 , buffer); if (mouse.dx < -127) mouse.dx = -127; if (mouse.dx > 127) mouse.dx = 127; put_user((char)mouse.dx, buffer + 1); if (mouse.dy < -127) mouse.dy = -127; if (mouse.dy > 127) mouse.dy = 127; put_user((char)-mouse.dy, buffer + 2); for(i = 3; i < count; i++) put_user(0x00, buffer + i); mouse.dx = 0; mouse.dy = 0; mouse.latch_buttons = mouse.buttons; mouse.ready = 0; ATIXL_MSE_ENABLE_UPDATE(); return i; /* i data bytes returned */ } static unsigned int mouse_poll(struct file *file, poll_table * wait) { poll_wait(file, &mouse.wait, wait); if (mouse.ready) return POLLIN | POLLRDNORM; return 0; } struct file_operations atixl_busmouse_fops = { NULL, /* mouse_seek */ read_mouse, write_mouse, NULL, /* mouse_readdir */ mouse_poll, /* mouse_poll */ NULL, /* mouse_ioctl */ NULL, /* mouse_mmap */ open_mouse, release_mouse, NULL, fasync_mouse, }; static struct miscdevice atixl_mouse = { ATIXL_BUSMOUSE, "atixl", &atixl_busmouse_fops }; __initfunc(int atixl_busmouse_init(void)) { unsigned char a,b,c; a = inb( ATIXL_MSE_SIGNATURE_PORT ); /* Get signature */ b = inb( ATIXL_MSE_SIGNATURE_PORT ); c = inb( ATIXL_MSE_SIGNATURE_PORT ); if (( a != b ) && ( a == c )) printk(KERN_INFO "\nATI Inport "); else{ mouse.present = 0; return -EIO; } outb(0x80, ATIXL_MSE_CONTROL_PORT); /* Reset the Inport device */ outb(0x07, ATIXL_MSE_CONTROL_PORT); /* Select Internal Register 7 */ outb(0x0a, ATIXL_MSE_DATA_PORT); /* Data Interrupts 8+, 1=30hz, 2=50hz, 3=100hz, 4=200hz rate */ mouse.present = 1; mouse.active = 0; mouse.ready = 0; mouse.buttons = mouse.latch_buttons = 0; mouse.dx = mouse.dy = 0; mouse.wait = NULL; printk("Bus mouse detected and installed.\n"); misc_register(&atixl_mouse); return 0; } #ifdef MODULE int init_module(void) { return atixl_busmouse_init(); } void cleanup_module(void) { misc_deregister(&atixl_mouse); } #endif |