1 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
2 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
4 #include <linux/slab.h>
5 #include <linux/delay.h>
6 #include <linux/interrupt.h>
7 +#include <linux/notifier.h>
8 +#include <linux/reboot.h>
9 #include <linux/mtd/map.h>
10 #include <linux/mtd/cfi.h>
11 #include <linux/mtd/compatmac.h>
14 +#define container_of(ptr, type, member) ({ \
15 + const typeof( ((type *)0)->member ) *__mptr = (ptr); \
16 + (type *)( (char *)__mptr - offsetof(type,member) );})
19 // debugging, turns off buffer write mode #define FORCE_WORD_WRITE
21 static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
22 @@ -45,6 +53,7 @@ static int cfi_intelext_lock(struct mtd_
23 static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len);
24 static int cfi_intelext_suspend (struct mtd_info *);
25 static void cfi_intelext_resume (struct mtd_info *);
26 +static int cfi_intelext_reboot(struct notifier_block *nb, unsigned long val, void *v);
28 static void cfi_intelext_destroy(struct mtd_info *);
30 @@ -288,6 +297,9 @@ static struct mtd_info *cfi_intelext_set
31 map->fldrv = &cfi_intelext_chipdrv;
33 mtd->name = map->name;
34 + mtd->reboot_notifier.notifier_call = cfi_intelext_reboot;
35 + register_reboot_notifier(&mtd->reboot_notifier);
40 @@ -1961,10 +1973,40 @@ static void cfi_intelext_resume(struct m
45 +static void cfi_intelext_reset(struct mtd_info *mtd)
47 + struct map_info *map = mtd->priv;
48 + struct cfi_private *cfi = map->fldrv_priv;
50 + struct flchip *chip;
52 + cfi_intelext_sync(mtd);
53 + for (i=0; i<cfi->numchips; i++) {
54 + chip = &cfi->chips[i];
56 + spin_lock(chip->mutex);
57 + cfi_write(map, CMD(0xFF), 0);
58 + chip->state = FL_READY;
59 + spin_unlock(chip->mutex);
63 +static int cfi_intelext_reboot(struct notifier_block *nb, unsigned long val, void *v)
65 + struct mtd_info *mtd;
67 + mtd = container_of(nb, struct mtd_info, reboot_notifier);
68 + cfi_intelext_reset(mtd);
72 static void cfi_intelext_destroy(struct mtd_info *mtd)
74 struct map_info *map = mtd->priv;
75 struct cfi_private *cfi = map->fldrv_priv;
76 + cfi_intelext_reset(mtd);
77 + unregister_reboot_notifier(&mtd->reboot_notifier);
78 kfree(cfi->cmdset_priv);
81 --- a/include/linux/mtd/mtd.h
82 +++ b/include/linux/mtd/mtd.h
84 #include <linux/version.h>
85 #include <linux/types.h>
86 #include <linux/mtd/compatmac.h>
87 +#include <linux/notifier.h>
88 #include <linux/module.h>
89 #include <linux/uio.h>
91 @@ -217,6 +218,8 @@ struct mtd_info {
92 int (*suspend) (struct mtd_info *mtd);
93 void (*resume) (struct mtd_info *mtd);
95 + struct notifier_block reboot_notifier;