This source file includes following definitions.
- mouse_open
- mouse_register
- mouse_deregister
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 #include "mouse.h"
36
37
38
39
40 static struct mouse mouse_list = { 0, "head", NULL, &mouse_list, &mouse_list };
41
42 #ifndef MODULE
43 extern unsigned long bus_mouse_init(unsigned long);
44 extern unsigned long psaux_init(unsigned long);
45 extern unsigned long ms_bus_mouse_init(unsigned long);
46 extern unsigned long atixl_busmouse_init(unsigned long);
47 #endif
48
49 static int mouse_open(struct inode * inode, struct file * file)
50 {
51 int minor = MINOR(inode->i_rdev);
52 struct mouse *c = mouse_list.next;
53 file->f_op = NULL;
54
55 while (c != &mouse_list) {
56 if (c->minor == minor) {
57 file->f_op = c->fops;
58 break;
59 }
60 c = c->next;
61 }
62
63 if (file->f_op == NULL)
64 return -ENODEV;
65 return file->f_op->open(inode,file);
66 }
67
68 static struct file_operations mouse_fops = {
69 NULL,
70 NULL,
71 NULL,
72 NULL,
73 NULL,
74 NULL,
75 NULL,
76 mouse_open,
77 NULL
78 };
79
80 int mouse_register(struct mouse * mouse)
81 {
82 if (mouse->next || mouse->prev)
83 return -EBUSY;
84 mouse->next = &mouse_list;
85 mouse->prev = mouse_list.prev;
86 mouse->prev->next = mouse;
87 mouse->next->prev = mouse;
88 return 0;
89 }
90
91 int mouse_deregister(struct mouse * mouse)
92 {
93 if (!mouse->next || !mouse->prev)
94 return -EINVAL;
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
105 int init_module(void)
106 #else
107 unsigned long mouse_init(unsigned long kmem_start)
108 #endif
109 {
110 #ifndef MODULE
111 #ifdef CONFIG_BUSMOUSE
112 kmem_start = bus_mouse_init(kmem_start);
113 #endif
114 #if defined CONFIG_PSMOUSE || defined CONFIG_82C710_MOUSE
115 kmem_start = psaux_init(kmem_start);
116 #endif
117 #ifdef CONFIG_MS_BUSMOUSE
118 kmem_start = ms_bus_mouse_init(kmem_start);
119 #endif
120 #ifdef CONFIG_ATIXL_BUSMOUSE
121 kmem_start = atixl_busmouse_init(kmem_start);
122 #endif
123 #endif
124 if (register_chrdev(MOUSE_MAJOR,"mouse",&mouse_fops)) {
125 printk("unable to get major %d for mouse devices\n",
126 MOUSE_MAJOR);
127 #ifdef MODULE
128 return -EIO;
129 #endif
130 }
131 #ifdef MODULE
132 return 0;
133 #else
134 return kmem_start;
135 #endif
136 }
137
138 #ifdef MODULE
139 void cleanup_module(void)
140 {
141 mouse_data *c = mouse_list, *n;
142 if (MOD_IN_USE) {
143 printk("mouse: in use, remove delayed\n");
144 return;
145 }
146 unregister_chrdev(MOUSE_MAJOR, "mouse");
147 while (c) {
148 n = c->next;
149 kfree(c);
150 c = n;
151 }
152 }
153 #endif