2 * $Id: chipreg.c,v 1.17 2004/11/16 18:29:00 dwmw2 Exp $
4 * Registration for chip drivers
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/kmod.h>
11 #include <linux/spinlock.h>
12 #include <linux/slab.h>
13 #include <linux/mtd/map.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/compatmac.h>
17 static DEFINE_SPINLOCK(chip_drvs_lock
);
18 static LIST_HEAD(chip_drvs_list
);
20 void register_mtd_chip_driver(struct mtd_chip_driver
*drv
)
22 spin_lock(&chip_drvs_lock
);
23 list_add(&drv
->list
, &chip_drvs_list
);
24 spin_unlock(&chip_drvs_lock
);
27 void unregister_mtd_chip_driver(struct mtd_chip_driver
*drv
)
29 spin_lock(&chip_drvs_lock
);
31 spin_unlock(&chip_drvs_lock
);
34 static struct mtd_chip_driver
*get_mtd_chip_driver (const char *name
)
36 struct list_head
*pos
;
37 struct mtd_chip_driver
*ret
= NULL
, *this;
39 spin_lock(&chip_drvs_lock
);
41 list_for_each(pos
, &chip_drvs_list
) {
42 this = list_entry(pos
, typeof(*this), list
);
44 if (!strcmp(this->name
, name
)) {
49 if (ret
&& !try_module_get(ret
->module
))
52 spin_unlock(&chip_drvs_lock
);
57 static int mtd_generic_point(struct mtd_info
*mtd
, loff_t from
, size_t len
,
58 size_t *retlen
, u_char
**mtdbuf
)
60 struct map_info
*map
= (struct map_info
*) mtd
->priv
;
61 *mtdbuf
= (u_char
*) (map
->virt
+ ((int) from
));
66 static void mtd_generic_unpoint (struct mtd_info
*mtd
, u_char
*addr
,
67 loff_t from
, size_t len
)
69 /* I don't know what we should do here */
72 /* Hide all the horrid details, like some silly person taking
73 get_module_symbol() away from us, from the caller. */
75 struct mtd_info
*do_map_probe(const char *name
, struct map_info
*map
)
77 struct mtd_chip_driver
*drv
;
80 drv
= get_mtd_chip_driver(name
);
82 if (!drv
&& !request_module("%s", name
))
83 drv
= get_mtd_chip_driver(name
);
88 ret
= drv
->probe(map
);
90 /* We decrease the use count here. It may have been a
91 probe-only module, which is no longer required from this
92 point, having given us a handle on (and increased the use
93 count of) the actual driver code.
95 module_put(drv
->module
);
99 ret
->point
= mtd_generic_point
;
101 ret
->unpoint
= mtd_generic_unpoint
;
108 * Destroy an MTD device which was created for a map device.
109 * Make sure the MTD device is already unregistered before calling this
111 void map_destroy(struct mtd_info
*mtd
)
113 struct map_info
*map
= mtd
->priv
;
115 if (map
->fldrv
->destroy
)
116 map
->fldrv
->destroy(mtd
);
118 module_put(map
->fldrv
->module
);
123 EXPORT_SYMBOL(register_mtd_chip_driver
);
124 EXPORT_SYMBOL(unregister_mtd_chip_driver
);
125 EXPORT_SYMBOL(do_map_probe
);
126 EXPORT_SYMBOL(map_destroy
);
128 MODULE_LICENSE("GPL");
129 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
130 MODULE_DESCRIPTION("Core routines for registering and invoking MTD chip drivers");