2 * Telephony registration for Linux
4 * (c) Copyright 1999 Red Hat Software Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Author: Alan Cox, <alan@redhat.com>
13 * Fixes: Mar 01 2000 Thomas Sparr, <thomas.l.sparr@telia.com>
14 * phone_register_device now works with unit!=PHONE_UNIT_ANY
17 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/errno.h>
24 #include <linux/phonedev.h>
25 #include <linux/init.h>
26 #include <asm/uaccess.h>
27 #include <asm/system.h>
29 #include <linux/kmod.h>
30 #include <linux/sem.h>
31 #include <linux/devfs_fs_kernel.h>
33 #define PHONE_NUM_DEVICES 256
39 static struct phone_device
*phone_device
[PHONE_NUM_DEVICES
];
40 static DECLARE_MUTEX(phone_lock
);
43 * Open a phone device.
46 static int phone_open(struct inode
*inode
, struct file
*file
)
48 unsigned int minor
= iminor(inode
);
50 struct phone_device
*p
;
51 struct file_operations
*old_fops
, *new_fops
= NULL
;
53 if (minor
>= PHONE_NUM_DEVICES
)
57 p
= phone_device
[minor
];
59 new_fops
= fops_get(p
->f_op
);
62 request_module("char-major-%d-%d", PHONE_MAJOR
, minor
);
64 p
= phone_device
[minor
];
65 if (p
== NULL
|| (new_fops
= fops_get(p
->f_op
)) == NULL
)
71 old_fops
= file
->f_op
;
72 file
->f_op
= new_fops
;
74 err
= p
->open(p
, file
); /* Tell the device it is open */
77 file
->f_op
= fops_get(old_fops
);
86 * Telephony For Linux device drivers request registration here.
89 int phone_register_device(struct phone_device
*p
, int unit
)
96 end
= PHONE_NUM_DEVICES
- 1;
98 if (unit
!= PHONE_UNIT_ANY
) {
100 end
= unit
+ 1; /* enter the loop at least one time */
104 for (i
= base
; i
< end
; i
++) {
105 if (phone_device
[i
] == NULL
) {
108 devfs_mk_cdev(MKDEV(PHONE_MAJOR
,i
),
109 S_IFCHR
|S_IRUSR
|S_IWUSR
, "phone/%d", i
);
119 * Unregister an unused Telephony for linux device
122 void phone_unregister_device(struct phone_device
*pfd
)
125 if (phone_device
[pfd
->minor
] != pfd
)
126 panic("phone: bad unregister");
127 devfs_remove("phone/%d", pfd
->minor
);
128 phone_device
[pfd
->minor
] = NULL
;
133 static struct file_operations phone_fops
=
135 .owner
= THIS_MODULE
,
140 * Board init functions
145 * Initialise Telephony for linux
148 static int __init
telephony_init(void)
150 printk(KERN_INFO
"Linux telephony interface: v1.00\n");
151 if (register_chrdev(PHONE_MAJOR
, "telephony", &phone_fops
)) {
152 printk("phonedev: unable to get major %d\n", PHONE_MAJOR
);
159 static void __exit
telephony_exit(void)
161 unregister_chrdev(PHONE_MAJOR
, "telephony");
164 module_init(telephony_init
);
165 module_exit(telephony_exit
);
167 MODULE_LICENSE("GPL");
169 EXPORT_SYMBOL(phone_register_device
);
170 EXPORT_SYMBOL(phone_unregister_device
);