This source file includes following definitions.
- mouse_open
- mouse_register
- mouse_deregister
- cleanup_module
- mouse_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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)
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,
62 NULL,
63 NULL,
64 NULL,
65 NULL,
66 NULL,
67 NULL,
68 mouse_open,
69 NULL
70 };
71
72 int mouse_register(struct mouse * mouse)
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)
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)
101 {
102 unregister_chrdev(MOUSE_MAJOR, "mouse");
103 }
104
105 #endif
106
107 int mouse_init(void)
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
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 }