root/drivers/char/msbusmouse.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ms_mouse_interrupt
  2. fasync_mouse
  3. release_mouse
  4. open_mouse
  5. write_mouse
  6. read_mouse
  7. mouse_select
  8. init_module
  9. cleanup_module

   1 /*
   2  * Microsoft busmouse driver based on Logitech driver (see busmouse.c)
   3  *
   4  * Microsoft BusMouse support by Teemu Rantanen (tvr@cs.hut.fi) (02AUG92)
   5  *
   6  * Microsoft Bus Mouse support modified by Derrick Cole (cole@concert.net)
   7  *    8/28/92
   8  *
   9  * Microsoft Bus Mouse support folded into 0.97pl4 code
  10  *    by Peter Cervasio (pete%q106fm.uucp@wupost.wustl.edu) (08SEP92)
  11  * Changes:  Logitech and Microsoft support in the same kernel.
  12  *           Defined new constants in busmouse.h for MS mice.
  13  *           Added int mse_busmouse_type to distinguish busmouse types
  14  *           Added a couple of new functions to handle differences in using
  15  *             MS vs. Logitech (where the int variable wasn't appropriate).
  16  *
  17  * Modified by Peter Cervasio (address above) (26SEP92)
  18  * Changes:  Included code to (properly?) detect when a Microsoft mouse is
  19  *           really attached to the machine.  Don't know what this does to
  20  *           Logitech bus mice, but all it does is read ports.
  21  *
  22  * Modified by Christoph Niemann (niemann@rubdv15.etdv.ruhr-uni-bochum.de)
  23  * Changes:  Better interrupt-handler (like in busmouse.c).
  24  *           Some changes to reduce code-size.
  25  *           Changed detection code to use inb_p() instead of doing empty
  26  *           loops to delay i/o.
  27  *
  28  * Modularised 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk>
  29  *
  30  * version 0.3b
  31  */
  32 
  33 #ifdef MODULE
  34 #include <linux/module.h>
  35 #include <linux/version.h>
  36 #else
  37 #define MOD_INC_USE_COUNT
  38 #define MOD_DEC_USE_COUNT
  39 #endif
  40 
  41 #include <linux/kernel.h>
  42 #include <linux/sched.h>
  43 #include <linux/busmouse.h>
  44 #include <linux/signal.h>
  45 #include <linux/errno.h>
  46 #include <linux/mouse.h>
  47 
  48 #include <asm/io.h>
  49 #include <asm/segment.h>
  50 #include <asm/system.h>
  51 #include <asm/irq.h>
  52 
  53 static struct mouse_status mouse;
  54 
  55 static void ms_mouse_interrupt(int irq, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  56 {
  57         char dx, dy;
  58         unsigned char buttons;
  59 
  60         outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
  61         outb((inb(MS_MSE_DATA_PORT) | 0x20), MS_MSE_DATA_PORT);
  62 
  63         outb(MS_MSE_READ_X, MS_MSE_CONTROL_PORT);
  64         dx = inb(MS_MSE_DATA_PORT);
  65 
  66         outb(MS_MSE_READ_Y, MS_MSE_CONTROL_PORT);
  67         dy = inb(MS_MSE_DATA_PORT);
  68 
  69         outb(MS_MSE_READ_BUTTONS, MS_MSE_CONTROL_PORT);
  70         buttons = ~(inb(MS_MSE_DATA_PORT)) & 0x07;
  71 
  72         outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
  73         outb((inb(MS_MSE_DATA_PORT) & 0xdf), MS_MSE_DATA_PORT);
  74 
  75         if (dx != 0 || dy != 0 || buttons != mouse.buttons || ((~buttons) & 0x07)) {
  76                 mouse.buttons = buttons;
  77                 mouse.dx += dx;
  78                 mouse.dy += dy;
  79                 mouse.ready = 1;
  80                 wake_up_interruptible(&mouse.wait);
  81                 if (mouse.fasyncptr)
  82                         kill_fasync(mouse.fasyncptr, SIGIO);
  83         }
  84 }
  85 
  86 static int fasync_mouse(struct inode *inode, struct file *filp, int on)
     /* [previous][next][first][last][top][bottom][index][help] */
  87 {
  88         int retval;
  89 
  90         retval = fasync_helper(inode, filp, on, &mouse.fasyncptr);
  91         if (retval < 0)
  92                 return retval;
  93         return 0;
  94 }
  95 
  96 static void release_mouse(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  97 {
  98         MS_MSE_INT_OFF();
  99         mouse.active = mouse.ready = 0; 
 100         free_irq(MOUSE_IRQ);
 101         fasync_mouse(inode, file, 0);
 102 }
 103 
 104 static int open_mouse(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
 105 {
 106         if (!mouse.present)
 107                 return -EINVAL;
 108         if (mouse.active)
 109                 return -EBUSY;
 110         mouse.active = 1;
 111         mouse.ready = mouse.dx = mouse.dy = 0;  
 112         mouse.buttons = 0x80;
 113         if (request_irq(MOUSE_IRQ, ms_mouse_interrupt, 0, "MS Busmouse")) {
 114                 mouse.active = 0;
 115                 return -EBUSY;
 116         }
 117         outb(MS_MSE_START, MS_MSE_CONTROL_PORT);
 118         MS_MSE_INT_ON();        
 119         return 0;
 120 }
 121 
 122 
 123 static int write_mouse(struct inode * inode, struct file * file, const char * buffer, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 124 {
 125         return -EINVAL;
 126 }
 127 
 128 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 129 {
 130         int i, dx, dy;
 131 
 132         if (count < 3)
 133                 return -EINVAL;
 134         if (!mouse.ready)
 135                 return -EAGAIN;
 136         put_user(mouse.buttons | 0x80, buffer);
 137         dx = mouse.dx < -127 ? -127 : mouse.dx > 127 ?  127 :  mouse.dx;
 138         dy = mouse.dy < -127 ?  127 : mouse.dy > 127 ? -127 : -mouse.dy;
 139         put_user((char)dx, buffer + 1);
 140         put_user((char)dy, buffer + 2);
 141         for (i = 3; i < count; i++)
 142                 put_user(0x00, buffer + i);
 143         mouse.dx -= dx;
 144         mouse.dy += dy;
 145         mouse.ready = 0;
 146         return i;       
 147 }
 148 
 149 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 {
 151         if (sel_type != SEL_IN)
 152                 return 0;
 153         if (mouse.ready) 
 154                 return 1;
 155         select_wait(&mouse.wait,wait);
 156         return 0;
 157 }
 158 
 159 struct file_operations ms_bus_mouse_fops = {
 160         NULL,           /* mouse_seek */
 161         read_mouse,
 162         write_mouse,
 163         NULL,           /* mouse_readdir */
 164         mouse_select,   /* mouse_select */
 165         NULL,           /* mouse_ioctl */
 166         NULL,           /* mouse_mmap */
 167         open_mouse,
 168         release_mouse,
 169         NULL,
 170         fasync_mouse,
 171 };
 172 
 173 static struct mouse ms_bus_mouse = {
 174         MICROSOFT_BUSMOUSE, "msbusmouse", &ms_bus_mouse_fops
 175 };
 176 
 177 #ifdef MODULE
 178 char kernel_version[] = UTS_RELEASE;
 179 
 180 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 181 #else
 182 unsigned long ms_bus_mouse_init(unsigned long kmem_start)
 183 #endif
 184 {
 185         int mse_byte, i;
 186 
 187         mouse.present = mouse.active = mouse.ready = 0;
 188         mouse.buttons = 0x80;
 189         mouse.dx = mouse.dy = 0;
 190         mouse.wait = NULL;
 191         if (inb_p(MS_MSE_SIGNATURE_PORT) == 0xde) {
 192 
 193                 mse_byte = inb_p(MS_MSE_SIGNATURE_PORT);
 194 
 195                 for (i = 0; i < 4; i++) {
 196                         if (inb_p(MS_MSE_SIGNATURE_PORT) == 0xde) {
 197                                 if (inb_p(MS_MSE_SIGNATURE_PORT) == mse_byte)
 198                                         mouse.present = 1;
 199                                 else
 200                                         mouse.present = 0;
 201                         } else
 202                                 mouse.present = 0;
 203                 }
 204         }
 205         if (mouse.present == 0) {
 206 #ifdef MODULE
 207           return -EIO;
 208 #else
 209                 return kmem_start;
 210 #endif
 211         }
 212         MS_MSE_INT_OFF();
 213         printk("Microsoft BusMouse detected and installed.\n");
 214         mouse_register(&ms_bus_mouse);
 215 #ifdef MODULE
 216         return 0;
 217 #else
 218         return kmem_start;
 219 #endif
 220 }
 221 
 222 #ifdef MODULE
 223 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 224 {
 225         if (MOD_IN_USE)
 226                 printk("msbusmouse: in use, remove delayed\n");
 227         mouse_deregister(&ms_bus_mouse);
 228 }
 229 #endif
 230 

/* [previous][next][first][last][top][bottom][index][help] */