root/drivers/char/mouse.c

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

DEFINITIONS

This source file includes following definitions.
  1. mouse_open
  2. mouse_register
  3. mouse_deregister
  4. init_module
  5. cleanup_module

   1 /*
   2  * linux/drivers/char/mouse.c
   3  *
   4  * Generic mouse open routine by Johan Myreen
   5  *
   6  * Based on code from Linus
   7  *
   8  * Teemu Rantanen's Microsoft Busmouse support and Derrick Cole's
   9  *   changes incorporated into 0.97pl4
  10  *   by Peter Cervasio (pete%q106fm.uucp@wupost.wustl.edu) (08SEP92)
  11  *   See busmouse.c for particulars.
  12  *
  13  * Made things a lot mode modular - easy to compile in just one or two
  14  * of the mouse drivers, as they are now completely independent. Linus.
  15  *
  16  * Support for loadable modules. 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk>
  17  */
  18 
  19 #ifdef MODULE
  20 #include <linux/module.h>
  21 #include <linux/version.h>
  22 #else
  23 #define MOD_INC_USE_COUNT
  24 #define MOD_DEC_USE_COUNT
  25 #endif
  26 
  27 #include <linux/fs.h>
  28 #include <linux/errno.h>
  29 #include <linux/mouse.h>
  30 #include <linux/config.h>
  31 #include <linux/kernel.h>
  32 #include <linux/major.h>
  33 #include <linux/malloc.h>
  34 
  35 #include "mouse.h"
  36 
  37 /*
  38  * Head entry for the doubly linked mouse list
  39  */
  40 static struct mouse mouse_list = { 0, "head", NULL, &mouse_list, &mouse_list };
  41 
  42 #ifndef MODULE
  43 extern unsigned long bus_mouse_init(unsigned long);
  44 extern unsigned long psaux_init(unsigned long);
  45 extern unsigned long ms_bus_mouse_init(unsigned long);
  46 extern unsigned long atixl_busmouse_init(unsigned long);
  47 #endif
  48 
  49 static int mouse_open(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51         int minor = MINOR(inode->i_rdev);
  52         struct mouse *c = mouse_list.next;
  53         file->f_op = NULL;
  54 
  55         while (c != &mouse_list) {
  56                 if (c->minor == minor) {
  57                         file->f_op = c->fops;
  58                         break;
  59                 }
  60                 c = c->next;
  61         }
  62 
  63         if (file->f_op == NULL)
  64                 return -ENODEV;
  65         return file->f_op->open(inode,file);
  66 }
  67 
  68 static struct file_operations mouse_fops = {
  69         NULL,           /* seek */
  70         NULL,           /* read */
  71         NULL,           /* write */
  72         NULL,           /* readdir */
  73         NULL,           /* select */
  74         NULL,           /* ioctl */
  75         NULL,           /* mmap */
  76         mouse_open,
  77         NULL            /* release */
  78 };
  79 
  80 int mouse_register(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  81 {
  82         if (mouse->next || mouse->prev)
  83                 return -EBUSY;
  84         mouse->next = &mouse_list;
  85         mouse->prev = mouse_list.prev;
  86         mouse->prev->next = mouse;
  87         mouse->next->prev = mouse;
  88         return 0;
  89 }
  90 
  91 int mouse_deregister(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93         if (!mouse->next || !mouse->prev)
  94                 return -EINVAL;
  95         mouse->prev->next = mouse->next;
  96         mouse->next->prev = mouse->prev;
  97         mouse->next = NULL;
  98         mouse->prev = NULL;
  99         return 0;
 100 }
 101 
 102 #ifdef MODULE
 103 char kernel_version[] = UTS_RELEASE;
 104 
 105 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 106 #else
 107 unsigned long mouse_init(unsigned long kmem_start)
 108 #endif
 109 {
 110 #ifndef MODULE
 111 #ifdef CONFIG_BUSMOUSE
 112         kmem_start = bus_mouse_init(kmem_start);
 113 #endif
 114 #if defined CONFIG_PSMOUSE || defined CONFIG_82C710_MOUSE
 115         kmem_start = psaux_init(kmem_start);
 116 #endif
 117 #ifdef CONFIG_MS_BUSMOUSE
 118         kmem_start = ms_bus_mouse_init(kmem_start);
 119 #endif
 120 #ifdef CONFIG_ATIXL_BUSMOUSE
 121         kmem_start = atixl_busmouse_init(kmem_start);
 122 #endif
 123 #endif /* !MODULE */
 124         if (register_chrdev(MOUSE_MAJOR,"mouse",&mouse_fops)) {
 125           printk("unable to get major %d for mouse devices\n",
 126                  MOUSE_MAJOR);
 127 #ifdef MODULE
 128                 return -EIO;
 129 #endif
 130         }
 131 #ifdef MODULE
 132         return 0;
 133 #else
 134         return kmem_start;
 135 #endif
 136 }
 137 
 138 #ifdef MODULE
 139 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 140 {
 141         mouse_data *c = mouse_list, *n;
 142         if (MOD_IN_USE) {
 143                 printk("mouse: in use, remove delayed\n");
 144                 return;
 145         }
 146         unregister_chrdev(MOUSE_MAJOR, "mouse");
 147         while (c) {
 148                 n = c->next;
 149                 kfree(c);
 150                 c = n;
 151         }
 152 }
 153 #endif

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