Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[deliverable/linux.git] / drivers / mtd / chips / chipreg.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Registration for chip drivers
3 *
4 */
5
6#include <linux/kernel.h>
1da177e4
LT
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>
1da177e4
LT
13
14static DEFINE_SPINLOCK(chip_drvs_lock);
15static LIST_HEAD(chip_drvs_list);
16
17void register_mtd_chip_driver(struct mtd_chip_driver *drv)
18{
19 spin_lock(&chip_drvs_lock);
20 list_add(&drv->list, &chip_drvs_list);
21 spin_unlock(&chip_drvs_lock);
22}
23
24void unregister_mtd_chip_driver(struct mtd_chip_driver *drv)
25{
26 spin_lock(&chip_drvs_lock);
27 list_del(&drv->list);
28 spin_unlock(&chip_drvs_lock);
29}
30
31static struct mtd_chip_driver *get_mtd_chip_driver (const char *name)
32{
33 struct list_head *pos;
34 struct mtd_chip_driver *ret = NULL, *this;
35
36 spin_lock(&chip_drvs_lock);
37
38 list_for_each(pos, &chip_drvs_list) {
39 this = list_entry(pos, typeof(*this), list);
1f948b43 40
1da177e4
LT
41 if (!strcmp(this->name, name)) {
42 ret = this;
43 break;
44 }
45 }
46 if (ret && !try_module_get(ret->module))
47 ret = NULL;
48
49 spin_unlock(&chip_drvs_lock);
50
51 return ret;
52}
53
54 /* Hide all the horrid details, like some silly person taking
55 get_module_symbol() away from us, from the caller. */
56
57struct mtd_info *do_map_probe(const char *name, struct map_info *map)
58{
59 struct mtd_chip_driver *drv;
60 struct mtd_info *ret;
61
62 drv = get_mtd_chip_driver(name);
63
64 if (!drv && !request_module("%s", name))
65 drv = get_mtd_chip_driver(name);
66
67 if (!drv)
68 return NULL;
69
70 ret = drv->probe(map);
71
1f948b43 72 /* We decrease the use count here. It may have been a
1da177e4
LT
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.
76 */
77 module_put(drv->module);
78
79 if (ret)
80 return ret;
1f948b43 81
1da177e4
LT
82 return NULL;
83}
84/*
85 * Destroy an MTD device which was created for a map device.
86 * Make sure the MTD device is already unregistered before calling this
87 */
88void map_destroy(struct mtd_info *mtd)
89{
90 struct map_info *map = mtd->priv;
91
92 if (map->fldrv->destroy)
93 map->fldrv->destroy(mtd);
94
95 module_put(map->fldrv->module);
96
97 kfree(mtd);
98}
99
100EXPORT_SYMBOL(register_mtd_chip_driver);
101EXPORT_SYMBOL(unregister_mtd_chip_driver);
102EXPORT_SYMBOL(do_map_probe);
103EXPORT_SYMBOL(map_destroy);
104
105MODULE_LICENSE("GPL");
106MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
107MODULE_DESCRIPTION("Core routines for registering and invoking MTD chip drivers");
This page took 0.561931 seconds and 5 git commands to generate.