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. cleanup_module
  5. mouse_init

   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  * Fixed a failing symbol register to free the device registration
  19  *              Alan Cox <alan@lxorguk.ukuu.org.uk> 21-Jan-96
  20  */
  21 
  22 #include <linux/module.h>
  23 
  24 #include <linux/fs.h>
  25 #include <linux/errno.h>
  26 #include <linux/mouse.h>
  27 #include <linux/config.h>
  28 #include <linux/kernel.h>
  29 #include <linux/major.h>
  30 #include <linux/malloc.h>
  31 
  32 /*
  33  * Head entry for the doubly linked mouse list
  34  */
  35 static struct mouse mouse_list = { 0, "head", NULL, &mouse_list, &mouse_list };
  36 
  37 #ifndef MODULE
  38 extern int bus_mouse_init(void);
  39 extern int psaux_init(void);
  40 extern int ms_bus_mouse_init(void);
  41 extern int atixl_busmouse_init(void);
  42 #endif
  43 
  44 static int mouse_open(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46         int minor = MINOR(inode->i_rdev);
  47         struct mouse *c = mouse_list.next;
  48         file->f_op = NULL;
  49 
  50         while (c != &mouse_list) {
  51                 if (c->minor == minor) {
  52                         file->f_op = c->fops;
  53                         break;
  54                 }
  55                 c = c->next;
  56         }
  57 
  58         if (file->f_op == NULL)
  59                 return -ENODEV;
  60         return file->f_op->open(inode,file);
  61 }
  62 
  63 static struct file_operations mouse_fops = {
  64         NULL,           /* seek */
  65         NULL,           /* read */
  66         NULL,           /* write */
  67         NULL,           /* readdir */
  68         NULL,           /* select */
  69         NULL,           /* ioctl */
  70         NULL,           /* mmap */
  71         mouse_open,
  72         NULL            /* release */
  73 };
  74 
  75 int mouse_register(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77         if (mouse->next || mouse->prev)
  78                 return -EBUSY;
  79         MOD_INC_USE_COUNT;
  80         mouse->next = &mouse_list;
  81         mouse->prev = mouse_list.prev;
  82         mouse->prev->next = mouse;
  83         mouse->next->prev = mouse;
  84         return 0;
  85 }
  86 
  87 int mouse_deregister(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  88 {
  89         if (!mouse->next || !mouse->prev)
  90                 return -EINVAL;
  91         MOD_DEC_USE_COUNT;
  92         mouse->prev->next = mouse->next;
  93         mouse->next->prev = mouse->prev;
  94         mouse->next = NULL;
  95         mouse->prev = NULL;
  96         return 0;
  97 }
  98 
  99 #ifdef MODULE
 100 
 101 #define mouse_init init_module
 102 
 103 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 104 {
 105         unregister_chrdev(MOUSE_MAJOR, "mouse");
 106 }
 107 
 108 #endif
 109 
 110 static struct symbol_table mouse_syms = {
 111 /* Should this be surrounded with "#ifdef CONFIG_MODULES" ? */
 112 #include <linux/symtab_begin.h>
 113         X(mouse_register),
 114         X(mouse_deregister),
 115 #include <linux/symtab_end.h>
 116 };
 117 
 118 int mouse_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 119 {
 120 #ifndef MODULE
 121 #ifdef CONFIG_BUSMOUSE
 122         bus_mouse_init();
 123 #endif
 124 #if defined CONFIG_PSMOUSE || defined CONFIG_82C710_MOUSE
 125         psaux_init();
 126 #endif
 127 #ifdef CONFIG_MS_BUSMOUSE
 128         ms_bus_mouse_init();
 129 #endif
 130 #ifdef CONFIG_ATIXL_BUSMOUSE
 131         atixl_busmouse_init();
 132 #endif
 133 #ifdef CONFIG_SOFT_WATCHDOG
 134         watchdog_init();
 135 #endif  
 136 #endif /* !MODULE */
 137         if (register_chrdev(MOUSE_MAJOR,"mouse",&mouse_fops)) {
 138           printk("unable to get major %d for mouse devices\n",
 139                  MOUSE_MAJOR);
 140                 return -EIO;
 141         }
 142 
 143         if(register_symtab(&mouse_syms)!=0)
 144         {
 145                 unregister_chrdev(MOUSE_MAJOR, "mouse");
 146                 return -EIO;
 147         }
 148         return 0;
 149 }

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