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. mouse_init
  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 int bus_mouse_init(void);
  42 extern int psaux_init(void);
  43 extern int ms_bus_mouse_init(void);
  44 extern int atixl_busmouse_init(void);
  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         MOD_INC_USE_COUNT;
  83         mouse->next = &mouse_list;
  84         mouse->prev = mouse_list.prev;
  85         mouse->prev->next = mouse;
  86         mouse->next->prev = mouse;
  87         return 0;
  88 }
  89 
  90 int mouse_deregister(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92         if (!mouse->next || !mouse->prev)
  93                 return -EINVAL;
  94         MOD_DEC_USE_COUNT;
  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 #define mouse_init init_module
 105 #endif
 106 
 107 int mouse_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 108 {
 109 #ifndef MODULE
 110 #ifdef CONFIG_BUSMOUSE
 111         bus_mouse_init();
 112 #endif
 113 #if defined CONFIG_PSMOUSE || defined CONFIG_82C710_MOUSE
 114         psaux_init();
 115 #endif
 116 #ifdef CONFIG_MS_BUSMOUSE
 117         ms_bus_mouse_init();
 118 #endif
 119 #ifdef CONFIG_ATIXL_BUSMOUSE
 120         atixl_busmouse_init();
 121 #endif
 122 #endif /* !MODULE */
 123         if (register_chrdev(MOUSE_MAJOR,"mouse",&mouse_fops)) {
 124           printk("unable to get major %d for mouse devices\n",
 125                  MOUSE_MAJOR);
 126                 return -EIO;
 127         }
 128         return 0;
 129 }
 130 
 131 #ifdef MODULE
 132 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 133 {
 134         if (MOD_IN_USE) {
 135                 printk("mouse: in use, remove delayed\n");
 136                 return;
 137         }
 138         unregister_chrdev(MOUSE_MAJOR, "mouse");
 139 }
 140 #endif

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