root/drivers/char/atixlmouse.c

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

DEFINITIONS

This source file includes following definitions.
  1. mouse_interrupt
  2. release_mouse
  3. open_mouse
  4. write_mouse
  5. read_mouse
  6. mouse_select
  7. atixl_busmouse_init

   1 /*
   2  * ATI XL Bus Mouse Driver for Linux
   3  * by Bob Harris (rth@sparta.com)
   4  *
   5  * Uses VFS interface for linux 0.98 (01OCT92)
   6  *
   7  * Modified by Chris Colohan (colohan@eecg.toronto.edu)
   8  *
   9  * version 0.3
  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 /* H/W interrupt # set up on ATIXL board */
  24 #define ATIXL_BUSMOUSE          3 /* Minor device # (mknod c 10 3 /dev/bm) */
  25 
  26 /* ATI XL Inport Busmouse Definitions */
  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 /* Some nice ATI XL macros */
  37 
  38 /* Select IR7, HOLD UPDATES (INT ENABLED), save X,Y */
  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 /* Select IR7, Enable updates (INT ENABLED) */
  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 /* Select IR7 - Mode Register, NO INTERRUPTS */
  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 /* Select IR7 - Mode Register, DATA INTERRUPTS ENABLED */
  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 /* Same general mouse structure */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  68 {
  69         char dx, dy, buttons;
  70 
  71         ATIXL_MSE_DISABLE_UPDATE(); /* Note that interrupts are still enabled */
  72         outb(ATIXL_MSE_READ_X, ATIXL_MSE_CONTROL_PORT); /* Select IR1 - X movement */
  73         dx = inb( ATIXL_MSE_DATA_PORT);
  74         outb(ATIXL_MSE_READ_Y, ATIXL_MSE_CONTROL_PORT); /* Select IR2 - Y movement */
  75         dy = inb( ATIXL_MSE_DATA_PORT);
  76         outb(ATIXL_MSE_READ_BUTTONS, ATIXL_MSE_CONTROL_PORT); /* Select IR0 - Button Status */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  89 {
  90         ATIXL_MSE_INT_OFF(); /* Interrupts are really shut down here */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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(); /* Interrupts are really enabled here */
 113         return 0;
 114 }
 115 
 116 
 117 static int write_mouse(struct inode * inode, struct file * file, char * buffer, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 118 {
 119         return -EINVAL;
 120 }
 121 
 122 static int read_mouse(struct inode * inode, struct file * file, char * buffer, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 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         /* Allowed interrupts to occur during data gathering - shouldn't hurt */
 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; /* i data bytes returned */
 151 }
 152 
 153 static int mouse_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 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,           /* mouse_seek */
 165         read_mouse,
 166         write_mouse,
 167         NULL,           /* mouse_readdir */
 168         mouse_select,   /* mouse_select */
 169         NULL,           /* mouse_ioctl */
 170         NULL,           /* mouse_mmap */
 171         open_mouse,
 172         release_mouse,
 173 };
 174 
 175 unsigned long atixl_busmouse_init(unsigned long kmem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
 176 {
 177         unsigned char a,b,c;
 178 
 179         a = inb( ATIXL_MSE_SIGNATURE_PORT );    /* Get signature */
 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);     /* Reset the Inport device */
 189         outb(0x07, ATIXL_MSE_CONTROL_PORT);     /* Select Internal Register 7 */
 190         outb(0x0a, ATIXL_MSE_DATA_PORT);        /* Data Interrupts 8+, 1=30hz, 2=50hz, 3=100hz, 4=200hz rate */
 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 }

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