2 * linux/drivers/char/misc.c
4 * Generic misc open routine by Johan Myreen
6 * Based on code from Linus
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.
13 * Made things a lot mode modular - easy to compile in just one or two
14 * of the misc drivers, as they are now completely independent. Linus.
16 * Support for loadable modules. 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk>
18 * Fixed a failing symbol register to free the device registration
19 * Alan Cox <alan@lxorguk.ukuu.org.uk> 21-Jan-96
21 * Dynamic minors and /proc/mice by Alessandro Rubini. 26-Mar-96
23 * Renamed to misc and miscdevice to be more accurate. Alan Cox 26-Mar-96
25 * Handling of mouse minor numbers for kerneld:
26 * Idea by Jacques Gelinas <jack@solucorp.qc.ca>,
27 * adapted by Bjorn Ekwall <bj0rn@blox.se>
28 * corrected by Alan Cox <alan@lxorguk.ukuu.org.uk>
30 * Changes for kmod (from kerneld):
31 Cyrus Durgin <cider@speakeasy.org>
34 #include <linux/config.h>
35 #include <linux/module.h>
38 #include <linux/errno.h>
39 #include <linux/miscdevice.h>
40 #include <linux/kernel.h>
41 #include <linux/major.h>
42 #include <linux/malloc.h>
43 #include <linux/proc_fs.h>
44 #include <linux/stat.h>
45 #include <linux/init.h>
47 #include <linux/apm_bios.h>
50 #include <linux/tty.h>
51 #include <linux/selection.h>
53 #include <linux/kmod.h>
57 * Head entry for the doubly linked miscdevice list
59 static struct miscdevice misc_list
= { 0, "head", NULL
, &misc_list
, &misc_list
};
62 * Assigned numbers, used for dynamic minors
64 #define DYNAMIC_MINORS 64 /* like dynamic majors */
65 static unsigned char misc_minors
[DYNAMIC_MINORS
/ 8];
68 extern int adbdev_init(void);
69 extern int bus_mouse_init(void);
70 extern int psaux_init(void);
71 extern int ms_bus_mouse_init(void);
72 extern int atixl_busmouse_init(void);
73 extern int amiga_mouse_init(void);
74 extern int atari_mouse_init(void);
75 extern int mac_mouse_init(void);
76 extern int sun_mouse_init(void);
77 extern int adb_mouse_init(void);
78 extern void watchdog_init(void);
79 extern void wdt_init(void);
80 extern void acq_init(void);
81 extern void pcwatchdog_init(void);
82 extern int rtc_init(void);
83 extern int dsp56k_init(void);
84 extern int nvram_init(void);
85 extern int radio_init(void);
86 extern void hfmodem_init(void);
87 extern int pc110pad_init(void);
88 extern int pmu_device_init(void);
91 static int misc_read_proc(char *buf
, char **start
, off_t offset
,
92 int len
, int *eof
, void *private)
97 for (p
= misc_list
.next
; p
!= &misc_list
&& len
< 4000; p
= p
->next
)
98 len
+= sprintf(buf
+len
, "%3i %s\n",p
->minor
, p
->name
?: "");
99 *start
= buf
+ offset
;
100 return len
> offset
? len
- offset
: 0;
106 static int misc_open(struct inode
* inode
, struct file
* file
)
108 int minor
= MINOR(inode
->i_rdev
);
109 struct miscdevice
*c
= misc_list
.next
;
112 while ((c
!= &misc_list
) && (c
->minor
!= minor
))
114 if (c
== &misc_list
) {
117 sprintf(modname
, "char-major-%d-%d", MISC_MAJOR
, minor
);
118 request_module(modname
);
120 while ((c
!= &misc_list
) && (c
->minor
!= minor
))
127 if ((file
->f_op
= c
->fops
) && file
->f_op
->open
)
128 return file
->f_op
->open(inode
,file
);
133 static struct file_operations misc_fops
= {
146 int misc_register(struct miscdevice
* misc
)
148 if (misc
->next
|| misc
->prev
)
150 if (misc
->minor
== MISC_DYNAMIC_MINOR
) {
151 int i
= DYNAMIC_MINORS
;
153 if ( (misc_minors
[i
>>3] & (1 << (i
&7))) == 0)
155 if (i
<0) return -EBUSY
;
158 if (misc
->minor
< DYNAMIC_MINORS
)
159 misc_minors
[misc
->minor
>> 3] |= 1 << (misc
->minor
& 7);
161 misc
->next
= &misc_list
;
162 misc
->prev
= misc_list
.prev
;
163 misc
->prev
->next
= misc
;
164 misc
->next
->prev
= misc
;
168 int misc_deregister(struct miscdevice
* misc
)
171 if (!misc
->next
|| !misc
->prev
)
174 misc
->prev
->next
= misc
->next
;
175 misc
->next
->prev
= misc
->prev
;
178 if (i
< DYNAMIC_MINORS
&& i
>0) {
179 misc_minors
[i
>>3] &= ~(1 << (misc
->minor
& 7));
186 #define misc_init init_module
188 void cleanup_module(void)
190 unregister_chrdev(MISC_MAJOR
, "misc");
195 EXPORT_SYMBOL(misc_register
);
196 EXPORT_SYMBOL(misc_deregister
);
198 #if defined(CONFIG_PROC_FS) && !defined(MODULE)
199 static struct proc_dir_entry
*proc_misc
;
202 __initfunc(int misc_init(void))
205 #ifdef CONFIG_PROC_FS
206 proc_misc
= create_proc_entry("misc", 0, 0);
208 proc_misc
->read_proc
= misc_read_proc
;
213 #ifdef CONFIG_BUSMOUSE
216 #if defined CONFIG_PSMOUSE
219 #ifdef CONFIG_MS_BUSMOUSE
222 #ifdef CONFIG_ATIXL_BUSMOUSE
223 atixl_busmouse_init();
225 #ifdef CONFIG_AMIGAMOUSE
228 #ifdef CONFIG_ATARIMOUSE
231 #ifdef CONFIG_MACMOUSE
234 #ifdef CONFIG_SUN_MOUSE
237 #ifdef CONFIG_MACMOUSE
240 #ifdef CONFIG_PC110_PAD
244 * Only one watchdog can succeed. We probe the pcwatchdog first,
245 * then the wdt cards and finally the software watchdog which always
246 * works. This means if your hardware watchdog dies or is 'borrowed'
247 * for some reason the software watchdog still gives you some cover.
249 #ifdef CONFIG_PCWATCHDOG
255 #ifdef CONFIG_ACQUIRE_WDT
258 #ifdef CONFIG_SOFT_WATCHDOG
267 #if defined(CONFIG_RTC) || defined(CONFIG_SUN_MOSTEK_RTC)
270 #ifdef CONFIG_ATARI_DSP56K
273 #ifdef CONFIG_HFMODEM
279 #ifdef CONFIG_MISC_RADIO
282 #ifdef CONFIG_HFMODEM
285 #ifdef CONFIG_PMAC_PBOOK
289 if (register_chrdev(MISC_MAJOR
,"misc",&misc_fops
)) {
290 printk("unable to get major %d for misc devices\n",