Commit 3efe41be authored by Brian Norris's avatar Brian Norris

mtd: implement common reboot notifier boilerplate

cfi_cmdset_000{1,2}.c already implement their own reboot notifiers, and
we're going to add one for NAND. Let's put the boilerplate in one place.
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
Tested-by: default avatarScott Branden <sbranden@broadcom.com>
parent 362376a7
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/reboot.h>
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h> #include <linux/mtd/partitions.h>
...@@ -365,6 +366,17 @@ static struct device_type mtd_devtype = { ...@@ -365,6 +366,17 @@ static struct device_type mtd_devtype = {
.release = mtd_release, .release = mtd_release,
}; };
static int mtd_reboot_notifier(struct notifier_block *n, unsigned long state,
void *cmd)
{
struct mtd_info *mtd;
mtd = container_of(n, struct mtd_info, reboot_notifier);
mtd->_reboot(mtd);
return NOTIFY_DONE;
}
/** /**
* add_mtd_device - register an MTD device * add_mtd_device - register an MTD device
* @mtd: pointer to new MTD device info structure * @mtd: pointer to new MTD device info structure
...@@ -565,6 +577,11 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, ...@@ -565,6 +577,11 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
err = -ENODEV; err = -ENODEV;
} }
if (mtd->_reboot) {
mtd->reboot_notifier.notifier_call = mtd_reboot_notifier;
register_reboot_notifier(&mtd->reboot_notifier);
}
return err; return err;
} }
EXPORT_SYMBOL_GPL(mtd_device_parse_register); EXPORT_SYMBOL_GPL(mtd_device_parse_register);
...@@ -579,6 +596,9 @@ int mtd_device_unregister(struct mtd_info *master) ...@@ -579,6 +596,9 @@ int mtd_device_unregister(struct mtd_info *master)
{ {
int err; int err;
if (master->_reboot)
unregister_reboot_notifier(&master->reboot_notifier);
err = del_mtd_partitions(master); err = del_mtd_partitions(master);
if (err) if (err)
return err; return err;
......
...@@ -227,6 +227,7 @@ struct mtd_info { ...@@ -227,6 +227,7 @@ struct mtd_info {
int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs); int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
int (*_suspend) (struct mtd_info *mtd); int (*_suspend) (struct mtd_info *mtd);
void (*_resume) (struct mtd_info *mtd); void (*_resume) (struct mtd_info *mtd);
void (*_reboot) (struct mtd_info *mtd);
/* /*
* If the driver is something smart, like UBI, it may need to maintain * If the driver is something smart, like UBI, it may need to maintain
* its own reference counting. The below functions are only for driver. * its own reference counting. The below functions are only for driver.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment