PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / mtd / chips / chipreg.c
blob0bbc61ba9524ec7f89e1ffba7b0aaceb53c365ad
1 /*
2 * Registration for chip drivers
4 */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/kmod.h>
9 #include <linux/spinlock.h>
10 #include <linux/slab.h>
11 #include <linux/mtd/map.h>
12 #include <linux/mtd/mtd.h>
14 static DEFINE_SPINLOCK(chip_drvs_lock);
15 static LIST_HEAD(chip_drvs_list);
17 void register_mtd_chip_driver(struct mtd_chip_driver *drv)
19 spin_lock(&chip_drvs_lock);
20 list_add(&drv->list, &chip_drvs_list);
21 spin_unlock(&chip_drvs_lock);
24 void unregister_mtd_chip_driver(struct mtd_chip_driver *drv)
26 spin_lock(&chip_drvs_lock);
27 list_del(&drv->list);
28 spin_unlock(&chip_drvs_lock);
31 static struct mtd_chip_driver *get_mtd_chip_driver (const char *name)
33 struct list_head *pos;
34 struct mtd_chip_driver *ret = NULL, *this;
36 spin_lock(&chip_drvs_lock);
38 list_for_each(pos, &chip_drvs_list) {
39 this = list_entry(pos, typeof(*this), list);
41 if (!strcmp(this->name, name)) {
42 ret = this;
43 break;
46 if (ret && !try_module_get(ret->module))
47 ret = NULL;
49 spin_unlock(&chip_drvs_lock);
51 return ret;
54 /* Hide all the horrid details, like some silly person taking
55 get_module_symbol() away from us, from the caller. */
57 struct mtd_info *do_map_probe(const char *name, struct map_info *map)
59 struct mtd_chip_driver *drv;
60 struct mtd_info *ret;
62 drv = get_mtd_chip_driver(name);
64 if (!drv && !request_module("%s", name))
65 drv = get_mtd_chip_driver(name);
67 if (!drv)
68 return NULL;
70 ret = drv->probe(map);
72 /* We decrease the use count here. It may have been a
73 probe-only module, which is no longer required from this
74 point, having given us a handle on (and increased the use
75 count of) the actual driver code.
77 module_put(drv->module);
79 return ret;
82 * Destroy an MTD device which was created for a map device.
83 * Make sure the MTD device is already unregistered before calling this
85 void map_destroy(struct mtd_info *mtd)
87 struct map_info *map = mtd->priv;
89 if (map->fldrv->destroy)
90 map->fldrv->destroy(mtd);
92 module_put(map->fldrv->module);
94 kfree(mtd);
97 EXPORT_SYMBOL(register_mtd_chip_driver);
98 EXPORT_SYMBOL(unregister_mtd_chip_driver);
99 EXPORT_SYMBOL(do_map_probe);
100 EXPORT_SYMBOL(map_destroy);
102 MODULE_LICENSE("GPL");
103 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
104 MODULE_DESCRIPTION("Core routines for registering and invoking MTD chip drivers");