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 
  19 #include <linux/module.h>
  20 
  21 #include <linux/fs.h>
  22 #include <linux/errno.h>
  23 #include <linux/mouse.h>
  24 #include <linux/config.h>
  25 #include <linux/kernel.h>
  26 #include <linux/major.h>
  27 #include <linux/malloc.h>
  28 
  29 /*
  30  * Head entry for the doubly linked mouse list
  31  */
  32 static struct mouse mouse_list = { 0, "head", NULL, &mouse_list, &mouse_list };
  33 
  34 #ifndef MODULE
  35 extern int bus_mouse_init(void);
  36 extern int psaux_init(void);
  37 extern int ms_bus_mouse_init(void);
  38 extern int atixl_busmouse_init(void);
  39 #endif
  40 
  41 static int mouse_open(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43         int minor = MINOR(inode->i_rdev);
  44         struct mouse *c = mouse_list.next;
  45         file->f_op = NULL;
  46 
  47         while (c != &mouse_list) {
  48                 if (c->minor == minor) {
  49                         file->f_op = c->fops;
  50                         break;
  51                 }
  52                 c = c->next;
  53         }
  54 
  55         if (file->f_op == NULL)
  56                 return -ENODEV;
  57         return file->f_op->open(inode,file);
  58 }
  59 
  60 static struct file_operations mouse_fops = {
  61         NULL,           /* seek */
  62         NULL,           /* read */
  63         NULL,           /* write */
  64         NULL,           /* readdir */
  65         NULL,           /* select */
  66         NULL,           /* ioctl */
  67         NULL,           /* mmap */
  68         mouse_open,
  69         NULL            /* release */
  70 };
  71 
  72 int mouse_register(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  73 {
  74         if (mouse->next || mouse->prev)
  75                 return -EBUSY;
  76         MOD_INC_USE_COUNT;
  77         mouse->next = &mouse_list;
  78         mouse->prev = mouse_list.prev;
  79         mouse->prev->next = mouse;
  80         mouse->next->prev = mouse;
  81         return 0;
  82 }
  83 
  84 int mouse_deregister(struct mouse * mouse)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86         if (!mouse->next || !mouse->prev)
  87                 return -EINVAL;
  88         MOD_DEC_USE_COUNT;
  89         mouse->prev->next = mouse->next;
  90         mouse->next->prev = mouse->prev;
  91         mouse->next = NULL;
  92         mouse->prev = NULL;
  93         return 0;
  94 }
  95 
  96 #ifdef MODULE
  97 
  98 #define mouse_init init_module
  99 
 100 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102         unregister_chrdev(MOUSE_MAJOR, "mouse");
 103 }
 104 
 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 }

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