aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdchar.c
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2009-03-26 03:42:41 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2009-04-04 09:29:07 -0400
commit1f24b5a8ecbb2a3c7080f418974d40e3ffedb221 (patch)
tree07dfc44f62dac78bdf4a8cdb4d91d60f73c04ff4 /drivers/mtd/mtdchar.c
parent9d63287a461c269edb39941744f4ff22223cf349 (diff)
[MTD] driver model updates
Update driver model support in the MTD framework, so it fits better into the current udev-based hotplug framework: - Each mtd_info now has a device node. MTD drivers should set the dev.parent field to point to the physical device, before setting up partitions or otherwise declaring MTDs. - Those device nodes always map to /sys/class/mtdX device nodes, which no longer depend on MTD_CHARDEV. - Those mtdX sysfs nodes have a "starter set" of attributes; it's not yet sufficient to replace /proc/mtd. - Enabling MTD_CHARDEV provides /sys/class/mtdXro/ nodes and the /sys/class/mtd*/dev attributes (for udev, mdev, etc). - Include a MODULE_ALIAS_CHARDEV_MAJOR macro. It'll work with udev creating the /dev/mtd* nodes, not just a static rootfs. So the sysfs structure is pretty much what you'd expect, except that readonly chardev nodes are a bit quirky. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/mtdchar.c')
-rw-r--r--drivers/mtd/mtdchar.c47
1 files changed, 6 insertions, 41 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index f478f1fc3949..763d3f0a1f42 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -20,33 +20,6 @@
20 20
21#include <asm/uaccess.h> 21#include <asm/uaccess.h>
22 22
23static struct class *mtd_class;
24
25static void mtd_notify_add(struct mtd_info* mtd)
26{
27 if (!mtd)
28 return;
29
30 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
31 NULL, "mtd%d", mtd->index);
32
33 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
34 NULL, "mtd%dro", mtd->index);
35}
36
37static void mtd_notify_remove(struct mtd_info* mtd)
38{
39 if (!mtd)
40 return;
41
42 device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2));
43 device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1));
44}
45
46static struct mtd_notifier notifier = {
47 .add = mtd_notify_add,
48 .remove = mtd_notify_remove,
49};
50 23
51/* 24/*
52 * Data structure to hold the pointer to the mtd device as well 25 * Data structure to hold the pointer to the mtd device as well
@@ -854,34 +827,26 @@ static const struct file_operations mtd_fops = {
854 827
855static int __init init_mtdchar(void) 828static int __init init_mtdchar(void)
856{ 829{
857 if (register_chrdev(MTD_CHAR_MAJOR, "mtd", &mtd_fops)) { 830 int status;
831
832 status = register_chrdev(MTD_CHAR_MAJOR, "mtd", &mtd_fops);
833 if (status < 0) {
858 printk(KERN_NOTICE "Can't allocate major number %d for Memory Technology Devices.\n", 834 printk(KERN_NOTICE "Can't allocate major number %d for Memory Technology Devices.\n",
859 MTD_CHAR_MAJOR); 835 MTD_CHAR_MAJOR);
860 return -EAGAIN;
861 }
862
863 mtd_class = class_create(THIS_MODULE, "mtd");
864
865 if (IS_ERR(mtd_class)) {
866 printk(KERN_ERR "Error creating mtd class.\n");
867 unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
868 return PTR_ERR(mtd_class);
869 } 836 }
870 837
871 register_mtd_user(&notifier); 838 return status;
872 return 0;
873} 839}
874 840
875static void __exit cleanup_mtdchar(void) 841static void __exit cleanup_mtdchar(void)
876{ 842{
877 unregister_mtd_user(&notifier);
878 class_destroy(mtd_class);
879 unregister_chrdev(MTD_CHAR_MAJOR, "mtd"); 843 unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
880} 844}
881 845
882module_init(init_mtdchar); 846module_init(init_mtdchar);
883module_exit(cleanup_mtdchar); 847module_exit(cleanup_mtdchar);
884 848
849MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR);
885 850
886MODULE_LICENSE("GPL"); 851MODULE_LICENSE("GPL");
887MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 852MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");