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 /*
  36  * Head entry for the doubly linked mouse list
  37  */
  38 static struct mouse mouse_list = { 0, "head", NULL, &mouse_list, &mouse_list };
  39 
  40 #ifndef MODULE
  41 extern unsigned long bus_mouse_init(unsigned long);
  42 extern unsigned long psaux_init(unsigned long);
  43 extern unsigned long ms_bus_mouse_init(unsigned long);
  44 extern unsigned long atixl_busmouse_init(unsigned long);
  45 #endif
  46 
  47 static int mouse_open(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49         int minor = MINOR(inode->i_rdev);
  50         struct mouse *c = mouse_list.next;
  51         file->f_op = NULL;
  52 
  53         while (c != &mouse_list) {
  54                 if (c->minor == minor) {
  55                         file->f_op = c->fops;
  56                         break;
  57                 }
  58                 c = c->next;
  59         }
  60 
  61         if (file->f_op == NULL)
  62                 return -ENODEV;
  63         return file->f_op->open(inode,file);
  64 }
  65 
  66 static struct file_operations mouse_fops = {
  67         NULL,           /* seek */
  68         NULL,           /* read */
  69         NULL,           /* write */
  70         NULL,           /* readdir */
  71         NULL,           /* select */
  72         NULL,           /* ioctl */
  73         NULL,           /* mmap */
  74         mouse_open,
  75         NULL            /* release */
  76 };
  77 
  78 int mouse_register(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         if (mouse->next || mouse->prev)
  81                 return -EBUSY;
  82         mouse->next = &mouse_list;
  83         mouse->prev = mouse_list.prev;
  84         mouse->prev->next = mouse;
  85         mouse->next->prev = mouse;
  86         return 0;
  87 }
  88 
  89 int mouse_deregister(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91         if (!mouse->next || !mouse->prev)
  92                 return -EINVAL;
  93         mouse->prev->next = mouse->next;
  94         mouse->next->prev = mouse->prev;
  95         mouse->next = NULL;
  96         mouse->prev = NULL;
  97         return 0;
  98 }
  99 
 100 #ifdef MODULE
 101 char kernel_version[] = UTS_RELEASE;
 102 
 103 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 104 #else
 105 unsigned long mouse_init(unsigned long kmem_start)
 106 #endif
 107 {
 108 #ifndef MODULE
 109 #ifdef CONFIG_BUSMOUSE
 110         kmem_start = bus_mouse_init(kmem_start);
 111 #endif
 112 #if defined CONFIG_PSMOUSE || defined CONFIG_82C710_MOUSE
 113         kmem_start = psaux_init(kmem_start);
 114 #endif
 115 #ifdef CONFIG_MS_BUSMOUSE
 116         kmem_start = ms_bus_mouse_init(kmem_start);
 117 #endif
 118 #ifdef CONFIG_ATIXL_BUSMOUSE
 119         kmem_start = atixl_busmouse_init(kmem_start);
 120 #endif
 121 #endif /* !MODULE */
 122         if (register_chrdev(MOUSE_MAJOR,"mouse",&mouse_fops)) {
 123           printk("unable to get major %d for mouse devices\n",
 124                  MOUSE_MAJOR);
 125 #ifdef MODULE
 126                 return -EIO;
 127 #endif
 128         }
 129 #ifdef MODULE
 130         return 0;
 131 #else
 132         return kmem_start;
 133 #endif
 134 }
 135 
 136 #ifdef MODULE
 137 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 138 {
 139         mouse_data *c = mouse_list, *n;
 140         if (MOD_IN_USE) {
 141                 printk("mouse: in use, remove delayed\n");
 142                 return;
 143         }
 144         unregister_chrdev(MOUSE_MAJOR, "mouse");
 145         while (c) {
 146                 n = c->next;
 147                 kfree(c);
 148                 c = n;
 149         }
 150 }
 151 #endif

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