diff options
author | Todd Poynor <tpoynor@mvista.com> | 2005-06-29 20:23:27 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@mtd.linutronix.de> | 2005-07-01 05:05:46 -0400 |
commit | 9bc7b38731dd1cc1635ab12f8de48866f603b06e (patch) | |
tree | 080932fb759f2f122ed81c88d15b336c025a2ff4 /drivers/mtd | |
parent | bd7bcf52dabba9c391142fd515221fcb87b7c712 (diff) |
[MTD] mtdchar.c: Replace DEVFS by udev
Switch from DEVFS to udev for dynamic creation of device nodes for mtd
char devices.
Creates a new LDM class "mtd" with writeable and read-only devices
registered for each mtdchar device.
From: Paolo Galtieri <pgaltieri@mvista.com>
Signed-off-by: Todd Poynor <tpoynor@mvista.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/mtdchar.c | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index da3f1a8f756e..b606f811eeb4 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: mtdchar.c,v 1.70 2005/04/01 15:36:11 nico Exp $ | 2 | * $Id: mtdchar.c,v 1.72 2005/06/30 00:23:24 tpoynor Exp $ |
3 | * | 3 | * |
4 | * Character-device access to raw MTD devices. | 4 | * Character-device access to raw MTD devices. |
5 | * | 5 | * |
@@ -15,27 +15,30 @@ | |||
15 | #include <linux/fs.h> | 15 | #include <linux/fs.h> |
16 | #include <asm/uaccess.h> | 16 | #include <asm/uaccess.h> |
17 | 17 | ||
18 | #ifdef CONFIG_DEVFS_FS | 18 | #include <linux/device.h> |
19 | #include <linux/devfs_fs_kernel.h> | 19 | |
20 | static struct class *mtd_class; | ||
20 | 21 | ||
21 | static void mtd_notify_add(struct mtd_info* mtd) | 22 | static void mtd_notify_add(struct mtd_info* mtd) |
22 | { | 23 | { |
23 | if (!mtd) | 24 | if (!mtd) |
24 | return; | 25 | return; |
25 | 26 | ||
26 | devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2), | 27 | class_device_create(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), |
27 | S_IFCHR | S_IRUGO | S_IWUGO, "mtd/%d", mtd->index); | 28 | NULL, "mtd%d", mtd->index); |
28 | 29 | ||
29 | devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), | 30 | class_device_create(mtd_class, |
30 | S_IFCHR | S_IRUGO, "mtd/%dro", mtd->index); | 31 | MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), |
32 | NULL, "mtd%dro", mtd->index); | ||
31 | } | 33 | } |
32 | 34 | ||
33 | static void mtd_notify_remove(struct mtd_info* mtd) | 35 | static void mtd_notify_remove(struct mtd_info* mtd) |
34 | { | 36 | { |
35 | if (!mtd) | 37 | if (!mtd) |
36 | return; | 38 | return; |
37 | devfs_remove("mtd/%d", mtd->index); | 39 | |
38 | devfs_remove("mtd/%dro", mtd->index); | 40 | class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2)); |
41 | class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1)); | ||
39 | } | 42 | } |
40 | 43 | ||
41 | static struct mtd_notifier notifier = { | 44 | static struct mtd_notifier notifier = { |
@@ -43,22 +46,6 @@ static struct mtd_notifier notifier = { | |||
43 | .remove = mtd_notify_remove, | 46 | .remove = mtd_notify_remove, |
44 | }; | 47 | }; |
45 | 48 | ||
46 | static inline void mtdchar_devfs_init(void) | ||
47 | { | ||
48 | devfs_mk_dir("mtd"); | ||
49 | register_mtd_user(¬ifier); | ||
50 | } | ||
51 | |||
52 | static inline void mtdchar_devfs_exit(void) | ||
53 | { | ||
54 | unregister_mtd_user(¬ifier); | ||
55 | devfs_remove("mtd"); | ||
56 | } | ||
57 | #else /* !DEVFS */ | ||
58 | #define mtdchar_devfs_init() do { } while(0) | ||
59 | #define mtdchar_devfs_exit() do { } while(0) | ||
60 | #endif | ||
61 | |||
62 | /* | 49 | /* |
63 | * We use file->private_data to store a pointer to the MTDdevice. | 50 | * We use file->private_data to store a pointer to the MTDdevice. |
64 | * Since alighment is at least 32 bits, we have 2 bits free for OTP | 51 | * Since alighment is at least 32 bits, we have 2 bits free for OTP |
@@ -657,13 +644,22 @@ static int __init init_mtdchar(void) | |||
657 | return -EAGAIN; | 644 | return -EAGAIN; |
658 | } | 645 | } |
659 | 646 | ||
660 | mtdchar_devfs_init(); | 647 | mtd_class = class_create(THIS_MODULE, "mtd"); |
648 | |||
649 | if (IS_ERR(mtd_class)) { | ||
650 | printk(KERN_ERR "Error creating mtd class.\n"); | ||
651 | unregister_chrdev(MTD_CHAR_MAJOR, "mtd"); | ||
652 | return 1; | ||
653 | } | ||
654 | |||
655 | register_mtd_user(¬ifier); | ||
661 | return 0; | 656 | return 0; |
662 | } | 657 | } |
663 | 658 | ||
664 | static void __exit cleanup_mtdchar(void) | 659 | static void __exit cleanup_mtdchar(void) |
665 | { | 660 | { |
666 | mtdchar_devfs_exit(); | 661 | unregister_mtd_user(¬ifier); |
662 | class_destroy(mtd_class); | ||
667 | unregister_chrdev(MTD_CHAR_MAJOR, "mtd"); | 663 | unregister_chrdev(MTD_CHAR_MAJOR, "mtd"); |
668 | } | 664 | } |
669 | 665 | ||