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
36
37
38 static struct mouse mouse_list = { 0, "head", NULL, &mouse_list, &mouse_list };
39
40 #ifndef MODULE
41 extern unsigned long bus_mouse_init(unsigned long);
42 extern unsigned long psaux_init(unsigned long);
43 extern unsigned long ms_bus_mouse_init(unsigned long);
44 extern unsigned long atixl_busmouse_init(unsigned long);
45 #endif
46
47 static int mouse_open(struct inode * inode, struct file * file)
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,
68 NULL,
69 NULL,
70 NULL,
71 NULL,
72 NULL,
73 NULL,
74 mouse_open,
75 NULL
76 };
77
78 int mouse_register(struct mouse * mouse)
79 {
80 if (mouse->next || mouse->prev)
81 return -EBUSY;
82 mouse->next = &mouse_list;
83 mouse->prev = mouse_list.prev;
84 mouse->prev->next = mouse;
85 mouse->next->prev = mouse;
86 return 0;
87 }
88
89 int mouse_deregister(struct mouse * mouse)
90 {
91 if (!mouse->next || !mouse->prev)
92 return -EINVAL;
93 mouse->prev->next = mouse->next;
94 mouse->next->prev = mouse->prev;
95 mouse->next = NULL;
96 mouse->prev = NULL;
97 return 0;
98 }
99
100 #ifdef MODULE
101 char kernel_version[] = UTS_RELEASE;
102
103 int init_module(void)
104 #else
105 unsigned long mouse_init(unsigned long kmem_start)
106 #endif
107 {
108 #ifndef MODULE
109 #ifdef CONFIG_BUSMOUSE
110 kmem_start = bus_mouse_init(kmem_start);
111 #endif
112 #if defined CONFIG_PSMOUSE || defined CONFIG_82C710_MOUSE
113 kmem_start = psaux_init(kmem_start);
114 #endif
115 #ifdef CONFIG_MS_BUSMOUSE
116 kmem_start = ms_bus_mouse_init(kmem_start);
117 #endif
118 #ifdef CONFIG_ATIXL_BUSMOUSE
119 kmem_start = atixl_busmouse_init(kmem_start);
120 #endif
121 #endif
122 if (register_chrdev(MOUSE_MAJOR,"mouse",&mouse_fops)) {
123 printk("unable to get major %d for mouse devices\n",
124 MOUSE_MAJOR);
125 #ifdef MODULE
126 return -EIO;
127 #endif
128 }
129 #ifdef MODULE
130 return 0;
131 #else
132 return kmem_start;
133 #endif
134 }
135
136 #ifdef MODULE
137 void cleanup_module(void)
138 {
139 mouse_data *c = mouse_list, *n;
140 if (MOD_IN_USE) {
141 printk("mouse: in use, remove delayed\n");
142 return;
143 }
144 unregister_chrdev(MOUSE_MAJOR, "mouse");
145 while (c) {
146 n = c->next;
147 kfree(c);
148 c = n;
149 }
150 }
151 #endif