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. release_mouse
  3. open_mouse
  4. write_mouse
  5. read_mouse
  6. mouse_select
  7. ms_bus_mouse_init

   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 dectection code to use inb_p() instead of doing empty
  26  *           loops to delay i/o.
  27  *
  28  * version 0.3a
  29  */
  30 
  31 #include <linux/kernel.h>
  32 #include <linux/sched.h>
  33 #include <linux/busmouse.h>
  34 #include <linux/tty.h>
  35 #include <linux/signal.h>
  36 #include <linux/errno.h>
  37 
  38 #include <asm/io.h>
  39 #include <asm/segment.h>
  40 #include <asm/system.h>
  41 #include <asm/irq.h>
  42 
  43 static struct mouse_status mouse;
  44 
  45 static void ms_mouse_interrupt(int unused)
     /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47         char dx, dy;
  48         unsigned char buttons;
  49 
  50         outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
  51         outb((inb(MS_MSE_DATA_PORT) | 0x20), MS_MSE_DATA_PORT);
  52 
  53         outb(MS_MSE_READ_X, MS_MSE_CONTROL_PORT);
  54         dx = inb(MS_MSE_DATA_PORT);
  55 
  56         outb(MS_MSE_READ_Y, MS_MSE_CONTROL_PORT);
  57         dy = inb(MS_MSE_DATA_PORT);
  58 
  59         outb(MS_MSE_READ_BUTTONS, MS_MSE_CONTROL_PORT);
  60         buttons = ~(inb(MS_MSE_DATA_PORT)) & 0x07;
  61 
  62         outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
  63         outb((inb(MS_MSE_DATA_PORT) & 0xdf), MS_MSE_DATA_PORT);
  64 
  65         if (dx != 0 || dy != 0 || buttons != mouse.buttons || ((~buttons) & 0x07)) {
  66                 mouse.buttons = buttons;
  67                 mouse.dx += dx;
  68                 mouse.dy += dy;
  69                 mouse.ready = 1;
  70                 wake_up_interruptible(&mouse.wait);
  71         }
  72 }
  73 
  74 static void release_mouse(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         MS_MSE_INT_OFF();
  77         mouse.active = mouse.ready = 0; 
  78         free_irq(MOUSE_IRQ);
  79 }
  80 
  81 static int open_mouse(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  82 {
  83         if (!mouse.present)
  84                 return -EINVAL;
  85         if (mouse.active)
  86                 return -EBUSY;
  87         mouse.active = 1;
  88         mouse.ready = mouse.dx = mouse.dy = 0;  
  89         mouse.buttons = 0x80;
  90         if (request_irq(MOUSE_IRQ, ms_mouse_interrupt)) {
  91                 mouse.active = 0;
  92                 return -EBUSY;
  93         }
  94         outb(MS_MSE_START, MS_MSE_CONTROL_PORT);
  95         MS_MSE_INT_ON();        
  96         return 0;
  97 }
  98 
  99 
 100 static int write_mouse(struct inode * inode, struct file * file, char * buffer, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102         return -EINVAL;
 103 }
 104 
 105 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 106 {
 107         int i, dx, dy;
 108 
 109         if (count < 3)
 110                 return -EINVAL;
 111         if (!mouse.ready)
 112                 return -EAGAIN;
 113         put_fs_byte(mouse.buttons | 0x80, buffer);
 114         dx = mouse.dx < -127 ? -127 : mouse.dx > 127 ?  127 :  mouse.dx;
 115         dy = mouse.dy < -127 ?  127 : mouse.dy > 127 ? -127 : -mouse.dy;
 116         put_fs_byte((char)dx, buffer + 1);
 117         put_fs_byte((char)dy, buffer + 2);
 118         for (i = 3; i < count; i++)
 119                 put_fs_byte(0x00, buffer + i);
 120         mouse.dx -= dx;
 121         mouse.dy += dy;
 122         mouse.ready = 0;
 123         return i;       
 124 }
 125 
 126 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128         if (sel_type != SEL_IN)
 129                 return 0;
 130         if (mouse.ready) 
 131                 return 1;
 132         select_wait(&mouse.wait,wait);
 133         return 0;
 134 }
 135 
 136 struct file_operations ms_bus_mouse_fops = {
 137         NULL,           /* mouse_seek */
 138         read_mouse,
 139         write_mouse,
 140         NULL,           /* mouse_readdir */
 141         mouse_select,   /* mouse_select */
 142         NULL,           /* mouse_ioctl */
 143         NULL,           /* mouse_mmap */
 144         open_mouse,
 145         release_mouse,
 146 };
 147 
 148 unsigned long ms_bus_mouse_init(unsigned long kmem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
 149 {
 150         int mse_byte, i;
 151 
 152         mouse.present = mouse.active = mouse.ready = 0;
 153         mouse.buttons = 0x80;
 154         mouse.dx = mouse.dy = 0;
 155         mouse.wait = NULL;
 156         if (inb_p(MS_MSE_SIGNATURE_PORT) == 0xde) {
 157 
 158                 mse_byte = inb_p(MS_MSE_SIGNATURE_PORT);
 159 
 160                 for (i = 0; i < 4; i++) {
 161                         if (inb_p(MS_MSE_SIGNATURE_PORT) == 0xde) {
 162                                 if (inb_p(MS_MSE_SIGNATURE_PORT) == mse_byte)
 163                                         mouse.present = 1;
 164                                 else
 165                                         mouse.present = 0;
 166                         } else
 167                                 mouse.present = 0;
 168                 }
 169         }
 170         if (mouse.present == 0) {
 171                 return kmem_start;
 172         }
 173         MS_MSE_INT_OFF();
 174         printk("Microsoft BusMouse detected and installed.\n");
 175         return kmem_start;
 176 }

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