This source file includes following definitions.
- mouse_open
- mouse_register
- mouse_deregister
- mouse_init
- 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 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)
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 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)
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)
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 }
130
131 #ifdef MODULE
132 void cleanup_module(void)
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