Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Registration for chip drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/mtd/map.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static DEFINE_SPINLOCK(chip_drvs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static LIST_HEAD(chip_drvs_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) void register_mtd_chip_driver(struct mtd_chip_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	spin_lock(&chip_drvs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	list_add(&drv->list, &chip_drvs_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	spin_unlock(&chip_drvs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) void unregister_mtd_chip_driver(struct mtd_chip_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	spin_lock(&chip_drvs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	list_del(&drv->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	spin_unlock(&chip_drvs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static struct mtd_chip_driver *get_mtd_chip_driver (const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct list_head *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct mtd_chip_driver *ret = NULL, *this;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	spin_lock(&chip_drvs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	list_for_each(pos, &chip_drvs_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		this = list_entry(pos, typeof(*this), list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		if (!strcmp(this->name, name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			ret = this;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (ret && !try_module_get(ret->module))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	spin_unlock(&chip_drvs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/* Hide all the horrid details, like some silly person taking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	   get_module_symbol() away from us, from the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) struct mtd_info *do_map_probe(const char *name, struct map_info *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct mtd_chip_driver *drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct mtd_info *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	drv = get_mtd_chip_driver(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (!drv && !request_module("%s", name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		drv = get_mtd_chip_driver(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (!drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	ret = drv->probe(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* We decrease the use count here. It may have been a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	   probe-only module, which is no longer required from this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	   point, having given us a handle on (and increased the use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	   count of) the actual driver code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	module_put(drv->module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * Destroy an MTD device which was created for a map device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * Make sure the MTD device is already unregistered before calling this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) void map_destroy(struct mtd_info *mtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct map_info *map = mtd->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (map->fldrv->destroy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		map->fldrv->destroy(mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	module_put(map->fldrv->module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	kfree(mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) EXPORT_SYMBOL(register_mtd_chip_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) EXPORT_SYMBOL(unregister_mtd_chip_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) EXPORT_SYMBOL(do_map_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) EXPORT_SYMBOL(map_destroy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) MODULE_DESCRIPTION("Core routines for registering and invoking MTD chip drivers");