generic: mtd: backport SPI_NOR_HAS_LOCK
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.4 / 0072-mtd-backport-v4.7-0day-patches-from-Boris.patch
index e4c8bc36e548174b33d2c85c1e4ab4a76866148b..b45d3aa57919b1193af83610793cfee4d70c7187 100644 (file)
@@ -31,11 +31,6 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  drivers/mtd/tests/mtd_nandecctest.c |    2 +-
  drivers/mtd/tests/oobtest.c         |   49 ++-
  drivers/mtd/tests/pagetest.c        |    3 +-
- drivers/mtd/ubi/cdev.c              |    4 +-
- drivers/mtd/ubi/misc.c              |   49 +++
- drivers/mtd/ubi/ubi.h               |   16 +-
- drivers/mtd/ubi/upd.c               |    2 +-
- drivers/mtd/ubi/wl.c                |   21 +-
  include/linux/mtd/bbm.h             |    1 -
  include/linux/mtd/fsmc.h            |   18 --
  include/linux/mtd/inftl.h           |    1 -
@@ -55,7 +50,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 
 --- a/drivers/mtd/Kconfig
 +++ b/drivers/mtd/Kconfig
-@@ -131,7 +131,7 @@
+@@ -131,7 +131,7 @@ config MTD_CMDLINE_PARTS
  
  config MTD_AFS_PARTS
        tristate "ARM Firmware Suite partition parsing"
@@ -64,7 +59,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        ---help---
          The ARM Firmware Suite allows the user to divide flash devices into
          multiple 'images'. Each such image has a header containing its name
-@@ -161,7 +161,7 @@
+@@ -161,7 +161,7 @@ config MTD_AR7_PARTS
  
  config MTD_BCM63XX_PARTS
        tristate "BCM63XX CFE partitioning support"
@@ -75,7 +70,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
          This provides partions parsing for BCM63xx devices with CFE
 --- a/drivers/mtd/cmdlinepart.c
 +++ b/drivers/mtd/cmdlinepart.c
-@@ -304,7 +304,7 @@
+@@ -304,7 +304,7 @@ static int mtdpart_setup_real(char *s)
   * the first one in the chain if a NULL mtd_id is passed in.
   */
  static int parse_cmdline_partitions(struct mtd_info *master,
@@ -84,7 +79,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                                    struct mtd_part_parser_data *data)
  {
        unsigned long long offset;
-@@ -382,7 +382,6 @@
+@@ -382,7 +382,6 @@ static int __init mtdpart_setup(char *s)
  __setup("mtdparts=", mtdpart_setup);
  
  static struct mtd_part_parser cmdline_parser = {
@@ -94,7 +89,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  };
 --- a/drivers/mtd/devices/m25p80.c
 +++ b/drivers/mtd/devices/m25p80.c
-@@ -174,22 +174,6 @@
+@@ -174,22 +174,6 @@ static int m25p80_read(struct spi_nor *n
        return 0;
  }
  
@@ -117,7 +112,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  /*
   * board specific setup should have ensured the SPI clock used here
   * matches what the READ command supports, at least until this driver
-@@ -197,12 +181,11 @@
+@@ -197,12 +181,11 @@ static int m25p80_erase(struct spi_nor *
   */
  static int m25p_probe(struct spi_device *spi)
  {
@@ -131,7 +126,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int ret;
  
        data = dev_get_platdata(&spi->dev);
-@@ -216,12 +199,11 @@
+@@ -216,12 +199,11 @@ static int m25p_probe(struct spi_device
        /* install the hooks */
        nor->read = m25p80_read;
        nor->write = m25p80_write;
@@ -145,7 +140,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        nor->priv = flash;
  
        spi_set_drvdata(spi, flash);
-@@ -242,6 +224,8 @@
+@@ -242,6 +224,8 @@ static int m25p_probe(struct spi_device
         */
        if (data && data->type)
                flash_name = data->type;
@@ -154,7 +149,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        else
                flash_name = spi->modalias;
  
-@@ -249,11 +233,8 @@
+@@ -249,11 +233,8 @@ static int m25p_probe(struct spi_device
        if (ret)
                return ret;
  
@@ -168,7 +163,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  }
  
  
-@@ -279,14 +260,21 @@
+@@ -279,14 +260,21 @@ static int m25p_remove(struct spi_device
   */
  static const struct spi_device_id m25p_ids[] = {
        /*
@@ -195,7 +190,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        {"mr25h256"},
 --- a/drivers/mtd/maps/physmap_of.c
 +++ b/drivers/mtd/maps/physmap_of.c
-@@ -128,7 +128,6 @@
+@@ -128,7 +128,6 @@ static int of_flash_probe(struct platfor
        int reg_tuple_size;
        struct mtd_info **mtd_list = NULL;
        resource_size_t res_size;
@@ -203,7 +198,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        bool map_indirect;
        const char *mtd_name = NULL;
  
-@@ -272,8 +271,9 @@
+@@ -272,8 +271,9 @@ static int of_flash_probe(struct platfor
        if (err)
                goto err_out;
  
@@ -217,7 +212,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        kfree(mtd_list);
 --- a/drivers/mtd/mtdchar.c
 +++ b/drivers/mtd/mtdchar.c
-@@ -465,38 +465,111 @@
+@@ -465,38 +465,111 @@ static int mtdchar_readoob(struct file *
  }
  
  /*
@@ -346,7 +341,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  static int mtdchar_blkpg_ioctl(struct mtd_info *mtd,
                               struct blkpg_ioctl_arg *arg)
  {
-@@ -815,16 +888,12 @@
+@@ -815,16 +888,12 @@ static int mtdchar_ioctl(struct file *fi
        {
                struct nand_oobinfo oi;
  
@@ -367,7 +362,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
                if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
                        return -EFAULT;
-@@ -913,14 +982,14 @@
+@@ -913,14 +982,14 @@ static int mtdchar_ioctl(struct file *fi
        {
                struct nand_ecclayout_user *usrlay;
  
@@ -386,7 +381,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                        ret = -EFAULT;
 --- a/drivers/mtd/mtdconcat.c
 +++ b/drivers/mtd/mtdconcat.c
-@@ -777,7 +777,7 @@
+@@ -777,7 +777,7 @@ struct mtd_info *mtd_concat_create(struc
  
        }
  
@@ -405,7 +400,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  #include <linux/proc_fs.h>
  #include <linux/idr.h>
  #include <linux/backing-dev.h>
-@@ -446,6 +447,7 @@
+@@ -446,6 +447,7 @@ int add_mtd_device(struct mtd_info *mtd)
        mtd->dev.devt = MTD_DEVT(i);
        dev_set_name(&mtd->dev, "mtd%d", i);
        dev_set_drvdata(&mtd->dev, mtd);
@@ -413,7 +408,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        error = device_register(&mtd->dev);
        if (error)
                goto fail_added;
-@@ -477,6 +479,7 @@
+@@ -477,6 +479,7 @@ int add_mtd_device(struct mtd_info *mtd)
        return 0;
  
  fail_added:
@@ -421,7 +416,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        idr_remove(&mtd_idr, i);
  fail_locked:
        mutex_unlock(&mtd_table_mutex);
-@@ -518,6 +521,7 @@
+@@ -518,6 +521,7 @@ int del_mtd_device(struct mtd_info *mtd)
                device_unregister(&mtd->dev);
  
                idr_remove(&mtd_idr, mtd->index);
@@ -429,7 +424,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
                module_put(THIS_MODULE);
                ret = 0;
-@@ -529,9 +533,10 @@
+@@ -529,9 +533,10 @@ out_error:
  }
  
  static int mtd_add_device_partitions(struct mtd_info *mtd,
@@ -442,7 +437,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int ret;
  
        if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) {
-@@ -600,29 +605,29 @@
+@@ -600,29 +605,29 @@ int mtd_device_parse_register(struct mtd
                              const struct mtd_partition *parts,
                              int nr_parts)
  {
@@ -483,11 +478,11 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        }
  
 -      ret = mtd_add_device_partitions(mtd, real_parts, ret);
-+      ret = mtd_add_device_partitions(mtd, ret);
++      ret = mtd_add_device_partitions(mtd, &parsed);
        if (ret)
                goto out;
  
-@@ -642,7 +647,8 @@
+@@ -642,7 +647,8 @@ int mtd_device_parse_register(struct mtd
        }
  
  out:
@@ -497,7 +492,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return ret;
  }
  EXPORT_SYMBOL_GPL(mtd_device_parse_register);
-@@ -767,7 +773,6 @@
+@@ -767,7 +773,6 @@ out:
  }
  EXPORT_SYMBOL_GPL(get_mtd_device);
  
@@ -505,7 +500,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  int __get_mtd_device(struct mtd_info *mtd)
  {
        int err;
-@@ -1001,6 +1006,366 @@
+@@ -1001,6 +1006,366 @@ int mtd_read_oob(struct mtd_info *mtd, l
  }
  EXPORT_SYMBOL_GPL(mtd_read_oob);
  
@@ -874,7 +869,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * devices. The user data is one time programmable but the factory data is read
 --- a/drivers/mtd/mtdcore.h
 +++ b/drivers/mtd/mtdcore.h
-@@ -10,10 +10,15 @@
+@@ -10,10 +10,15 @@ int add_mtd_device(struct mtd_info *mtd)
  int del_mtd_device(struct mtd_info *mtd);
  int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
  int del_mtd_partitions(struct mtd_info *);
@@ -893,7 +888,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
 --- a/drivers/mtd/mtdpart.c
 +++ b/drivers/mtd/mtdpart.c
-@@ -55,9 +55,12 @@
+@@ -55,9 +55,12 @@ static void mtd_partition_split(struct m
  
  /*
   * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
@@ -908,7 +903,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
  
  /*
-@@ -68,7 +71,7 @@
+@@ -68,7 +71,7 @@ static void mtd_partition_split(struct m
  static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
                size_t *retlen, u_char *buf)
  {
@@ -917,7 +912,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct mtd_ecc_stats stats;
        int res;
  
-@@ -87,7 +90,7 @@
+@@ -87,7 +90,7 @@ static int part_read(struct mtd_info *mt
  static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
                size_t *retlen, void **virt, resource_size_t *phys)
  {
@@ -926,7 +921,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        return part->master->_point(part->master, from + part->offset, len,
                                    retlen, virt, phys);
-@@ -95,7 +98,7 @@
+@@ -95,7 +98,7 @@ static int part_point(struct mtd_info *m
  
  static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
  {
@@ -935,7 +930,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        return part->master->_unpoint(part->master, from + part->offset, len);
  }
-@@ -105,7 +108,7 @@
+@@ -105,7 +108,7 @@ static unsigned long part_get_unmapped_a
                                            unsigned long offset,
                                            unsigned long flags)
  {
@@ -944,7 +939,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        offset += part->offset;
        return part->master->_get_unmapped_area(part->master, len, offset,
-@@ -115,7 +118,7 @@
+@@ -115,7 +118,7 @@ static unsigned long part_get_unmapped_a
  static int part_read_oob(struct mtd_info *mtd, loff_t from,
                struct mtd_oob_ops *ops)
  {
@@ -953,7 +948,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int res;
  
        if (from >= mtd->size)
-@@ -130,10 +133,7 @@
+@@ -130,10 +133,7 @@ static int part_read_oob(struct mtd_info
        if (ops->oobbuf) {
                size_t len, pages;
  
@@ -965,7 +960,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                pages = mtd_div_by_ws(mtd->size, mtd);
                pages -= mtd_div_by_ws(from, mtd);
                if (ops->ooboffs + ops->ooblen > pages * len)
-@@ -153,7 +153,7 @@
+@@ -153,7 +153,7 @@ static int part_read_oob(struct mtd_info
  static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
                size_t len, size_t *retlen, u_char *buf)
  {
@@ -974,7 +969,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return part->master->_read_user_prot_reg(part->master, from, len,
                                                 retlen, buf);
  }
-@@ -161,7 +161,7 @@
+@@ -161,7 +161,7 @@ static int part_read_user_prot_reg(struc
  static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
                                   size_t *retlen, struct otp_info *buf)
  {
@@ -983,7 +978,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return part->master->_get_user_prot_info(part->master, len, retlen,
                                                 buf);
  }
-@@ -169,7 +169,7 @@
+@@ -169,7 +169,7 @@ static int part_get_user_prot_info(struc
  static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
                size_t len, size_t *retlen, u_char *buf)
  {
@@ -992,7 +987,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return part->master->_read_fact_prot_reg(part->master, from, len,
                                                 retlen, buf);
  }
-@@ -177,7 +177,7 @@
+@@ -177,7 +177,7 @@ static int part_read_fact_prot_reg(struc
  static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
                                   size_t *retlen, struct otp_info *buf)
  {
@@ -1001,7 +996,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return part->master->_get_fact_prot_info(part->master, len, retlen,
                                                 buf);
  }
-@@ -185,7 +185,7 @@
+@@ -185,7 +185,7 @@ static int part_get_fact_prot_info(struc
  static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
                size_t *retlen, const u_char *buf)
  {
@@ -1010,7 +1005,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return part->master->_write(part->master, to + part->offset, len,
                                    retlen, buf);
  }
-@@ -193,7 +193,7 @@
+@@ -193,7 +193,7 @@ static int part_write(struct mtd_info *m
  static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
                size_t *retlen, const u_char *buf)
  {
@@ -1019,7 +1014,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return part->master->_panic_write(part->master, to + part->offset, len,
                                          retlen, buf);
  }
-@@ -201,7 +201,7 @@
+@@ -201,7 +201,7 @@ static int part_panic_write(struct mtd_i
  static int part_write_oob(struct mtd_info *mtd, loff_t to,
                struct mtd_oob_ops *ops)
  {
@@ -1028,7 +1023,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        if (to >= mtd->size)
                return -EINVAL;
-@@ -213,7 +213,7 @@
+@@ -213,7 +213,7 @@ static int part_write_oob(struct mtd_inf
  static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
                size_t len, size_t *retlen, u_char *buf)
  {
@@ -1037,7 +1032,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return part->master->_write_user_prot_reg(part->master, from, len,
                                                  retlen, buf);
  }
-@@ -221,21 +221,21 @@
+@@ -221,21 +221,21 @@ static int part_write_user_prot_reg(stru
  static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
                size_t len)
  {
@@ -1062,7 +1057,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int ret;
  
  
-@@ -299,7 +299,7 @@
+@@ -299,7 +299,7 @@ static int part_erase(struct mtd_info *m
  void mtd_erase_callback(struct erase_info *instr)
  {
        if (instr->mtd->_erase == part_erase) {
@@ -1071,7 +1066,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                size_t wrlen = 0;
  
                if (instr->mtd->flags & MTD_ERASE_PARTIAL) {
-@@ -330,13 +330,13 @@
+@@ -330,13 +330,13 @@ EXPORT_SYMBOL_GPL(mtd_erase_callback);
  
  static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
  {
@@ -1087,7 +1082,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        ofs += part->offset;
        if (mtd->flags & MTD_ERASE_PARTIAL) {
-@@ -349,45 +349,45 @@
+@@ -349,45 +349,45 @@ static int part_unlock(struct mtd_info *
  
  static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
  {
@@ -1140,7 +1135,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int res;
  
        ofs += part->offset;
-@@ -397,6 +397,27 @@
+@@ -397,6 +397,27 @@ static int part_block_markbad(struct mtd
        return res;
  }
  
@@ -1168,7 +1163,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  static inline void free_partition(struct mtd_part *p)
  {
        kfree(p->mtd.name);
-@@ -614,7 +635,7 @@
+@@ -614,7 +635,7 @@ static struct mtd_part *allocate_partiti
                        slave->mtd.erasesize = slave->mtd.size;
        }
  
@@ -1177,7 +1172,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        slave->mtd.ecc_step_size = master->ecc_step_size;
        slave->mtd.ecc_strength = master->ecc_strength;
        slave->mtd.bitflip_threshold = master->bitflip_threshold;
-@@ -639,7 +660,7 @@
+@@ -639,7 +660,7 @@ static ssize_t mtd_partition_offset_show
                struct device_attribute *attr, char *buf)
  {
        struct mtd_info *mtd = dev_get_drvdata(dev);
@@ -1186,7 +1181,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return snprintf(buf, PAGE_SIZE, "%lld\n", part->offset);
  }
  
-@@ -677,11 +698,10 @@
+@@ -677,11 +698,10 @@ int mtd_add_partition(struct mtd_info *m
        if (length <= 0)
                return -EINVAL;
  
@@ -1199,7 +1194,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        new = allocate_partition(master, &part, -1, offset);
        if (IS_ERR(new))
-@@ -845,7 +865,7 @@
+@@ -845,7 +865,7 @@ int add_mtd_partitions(struct mtd_info *
  static DEFINE_SPINLOCK(part_parser_lock);
  static LIST_HEAD(part_parsers);
  
@@ -1208,7 +1203,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  {
        struct mtd_part_parser *p, *ret = NULL;
  
-@@ -862,7 +882,20 @@
+@@ -862,7 +882,20 @@ static struct mtd_part_parser *get_parti
        return ret;
  }
  
@@ -1230,7 +1225,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
  static struct mtd_part_parser *
  get_partition_parser_by_type(enum mtd_parser_type type,
-@@ -874,7 +907,7 @@
+@@ -874,7 +907,7 @@ get_partition_parser_by_type(enum mtd_pa
  
        p = list_prepare_entry(start, &part_parsers, list);
        if (start)
@@ -1239,7 +1234,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        list_for_each_entry_continue(p, &part_parsers, list) {
                if (p->type == type && try_module_get(p->owner)) {
-@@ -888,13 +921,19 @@
+@@ -888,13 +921,19 @@ get_partition_parser_by_type(enum mtd_pa
        return ret;
  }
  
@@ -1262,7 +1257,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
  void deregister_mtd_parser(struct mtd_part_parser *p)
  {
-@@ -954,7 +993,7 @@
+@@ -954,7 +993,7 @@ static const char * const default_mtd_pa
   * parse_mtd_partitions - parse MTD partitions
   * @master: the master partition (describes whole MTD device)
   * @types: names of partition parsers to try or %NULL
@@ -1271,7 +1266,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * @data: MTD partition parser-specific data
   *
   * This function tries to find partition on MTD device @master. It uses MTD
-@@ -966,45 +1005,42 @@
+@@ -966,45 +1005,42 @@ static const char * const default_mtd_pa
   *
   * This function may return:
   * o a negative error code in case of failure
@@ -1329,7 +1324,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                /*
                 * Stash the first error we see; only report it if no parser
                 * succeeds
-@@ -1034,7 +1070,7 @@
+@@ -1034,7 +1070,7 @@ int parse_mtd_partitions_by_type(struct
                ret = (*parser->parse_fn)(master, pparts, data);
  
                if (ret > 0) {
@@ -1338,7 +1333,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                        printk(KERN_NOTICE
                               "%d %s partitions found on MTD device %s\n",
                               ret, parser->name, master->name);
-@@ -1048,6 +1084,22 @@
+@@ -1048,6 +1084,22 @@ int parse_mtd_partitions_by_type(struct
  }
  EXPORT_SYMBOL_GPL(parse_mtd_partitions_by_type);
  
@@ -1361,7 +1356,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  int mtd_is_partition(const struct mtd_info *mtd)
  {
        struct mtd_part *part;
-@@ -1070,7 +1122,7 @@
+@@ -1070,7 +1122,7 @@ struct mtd_info *mtdpart_get_master(cons
        if (!mtd_is_partition(mtd))
                return (struct mtd_info *)mtd;
  
@@ -1370,7 +1365,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  }
  EXPORT_SYMBOL_GPL(mtdpart_get_master);
  
-@@ -1079,7 +1131,7 @@
+@@ -1079,7 +1131,7 @@ uint64_t mtdpart_get_offset(const struct
        if (!mtd_is_partition(mtd))
                return 0;
  
@@ -1379,7 +1374,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  }
  EXPORT_SYMBOL_GPL(mtdpart_get_offset);
  
-@@ -1089,6 +1141,6 @@
+@@ -1089,6 +1141,6 @@ uint64_t mtd_get_device_size(const struc
        if (!mtd_is_partition(mtd))
                return mtd->size;
  
@@ -1389,7 +1384,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  EXPORT_SYMBOL_GPL(mtd_get_device_size);
 --- a/drivers/mtd/mtdswap.c
 +++ b/drivers/mtd/mtdswap.c
-@@ -346,7 +346,7 @@
+@@ -346,7 +346,7 @@ static int mtdswap_read_markers(struct m
        if (mtd_can_have_bb(d->mtd) && mtd_block_isbad(d->mtd, offset))
                return MTDSWAP_SCANNED_BAD;
  
@@ -1398,7 +1393,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        ops.oobbuf = d->oob_buf;
        ops.ooboffs = 0;
        ops.datbuf = NULL;
-@@ -359,7 +359,7 @@
+@@ -359,7 +359,7 @@ static int mtdswap_read_markers(struct m
  
        data = (struct mtdswap_oobdata *)d->oob_buf;
        data2 = (struct mtdswap_oobdata *)
@@ -1407,7 +1402,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        if (le16_to_cpu(data->magic) == MTDSWAP_MAGIC_CLEAN) {
                eb->erase_count = le32_to_cpu(data->count);
-@@ -933,7 +933,7 @@
+@@ -933,7 +933,7 @@ static unsigned int mtdswap_eblk_passes(
  
        ops.mode = MTD_OPS_AUTO_OOB;
        ops.len = mtd->writesize;
@@ -1416,7 +1411,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        ops.ooboffs = 0;
        ops.datbuf = d->page_buf;
        ops.oobbuf = d->oob_buf;
-@@ -945,7 +945,7 @@
+@@ -945,7 +945,7 @@ static unsigned int mtdswap_eblk_passes(
                for (i = 0; i < mtd_pages; i++) {
                        patt = mtdswap_test_patt(test + i);
                        memset(d->page_buf, patt, mtd->writesize);
@@ -1425,7 +1420,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                        ret = mtd_write_oob(mtd, pos, &ops);
                        if (ret)
                                goto error;
-@@ -964,7 +964,7 @@
+@@ -964,7 +964,7 @@ static unsigned int mtdswap_eblk_passes(
                                if (p1[j] != patt)
                                        goto error;
  
@@ -1434,7 +1429,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                                if (p2[j] != (unsigned char)patt)
                                        goto error;
  
-@@ -1387,7 +1387,7 @@
+@@ -1387,7 +1387,7 @@ static int mtdswap_init(struct mtdswap_d
        if (!d->page_buf)
                goto page_buf_fail;
  
@@ -1443,7 +1438,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        if (!d->oob_buf)
                goto oob_buf_fail;
  
-@@ -1417,7 +1417,6 @@
+@@ -1417,7 +1417,6 @@ static void mtdswap_add_mtd(struct mtd_b
        unsigned long part;
        unsigned int eblocks, eavailable, bad_blocks, spare_cnt;
        uint64_t swap_size, use_size, size_limit;
@@ -1451,7 +1446,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int ret;
  
        parts = &partitions[0];
-@@ -1447,17 +1446,10 @@
+@@ -1447,17 +1446,10 @@ static void mtdswap_add_mtd(struct mtd_b
                return;
        }
  
@@ -1473,7 +1468,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
 --- a/drivers/mtd/nand/Kconfig
 +++ b/drivers/mtd/nand/Kconfig
-@@ -55,7 +55,7 @@
+@@ -55,7 +55,7 @@ config MTD_NAND_DENALI_PCI
  config MTD_NAND_DENALI_DT
        tristate "Support Denali NAND controller as a DT device"
        select MTD_NAND_DENALI
@@ -1482,7 +1477,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        help
          Enable the driver for NAND flash on platforms using a Denali NAND
          controller as a DT device.
-@@ -74,6 +74,7 @@
+@@ -74,6 +74,7 @@ config MTD_NAND_DENALI_SCRATCH_REG_ADDR
  config MTD_NAND_GPIO
        tristate "GPIO assisted NAND Flash driver"
        depends on GPIOLIB || COMPILE_TEST
@@ -1490,7 +1485,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        help
          This enables a NAND flash driver where control signals are
          connected to GPIO pins, and commands and data are communicated
-@@ -310,6 +311,7 @@
+@@ -310,6 +311,7 @@ config MTD_NAND_CAFE
  config MTD_NAND_CS553X
        tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)"
        depends on X86_32
@@ -1498,7 +1493,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        help
          The CS553x companion chips for the AMD Geode processor
          include NAND flash controllers with built-in hardware ECC
-@@ -463,6 +465,7 @@
+@@ -463,6 +465,7 @@ config MTD_NAND_MPC5121_NFC
  config MTD_NAND_VF610_NFC
        tristate "Support for Freescale NFC for VF610/MPC5125"
        depends on (SOC_VF610 || COMPILE_TEST)
@@ -1506,7 +1501,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        help
          Enables support for NAND Flash Controller on some Freescale
          processors like the VF610, MPC5125, MCF54418 or Kinetis K70.
-@@ -480,7 +483,7 @@
+@@ -480,7 +483,7 @@ config MTD_NAND_MXC
  
  config MTD_NAND_SH_FLCTL
        tristate "Support for NAND on Renesas SuperH FLCTL"
@@ -1515,7 +1510,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        depends on HAS_IOMEM
        depends on HAS_DMA
        help
-@@ -519,6 +522,13 @@
+@@ -519,6 +522,13 @@ config MTD_NAND_JZ4740
        help
                Enables support for NAND Flash on JZ4740 SoC based boards.
  
@@ -1529,7 +1524,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  config MTD_NAND_FSMC
        tristate "Support for NAND on ST Micros FSMC"
        depends on PLAT_SPEAR || ARCH_NOMADIK || ARCH_U8500 || MACH_U300
-@@ -546,4 +556,11 @@
+@@ -546,4 +556,11 @@ config MTD_NAND_HISI504
        help
          Enables support for NAND controller on Hisilicon SoC Hip04.
  
@@ -1543,7 +1538,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  endif # MTD_NAND
 --- a/drivers/mtd/nand/Makefile
 +++ b/drivers/mtd/nand/Makefile
-@@ -49,11 +49,13 @@
+@@ -49,11 +49,13 @@ obj-$(CONFIG_MTD_NAND_MPC5121_NFC) += mp
  obj-$(CONFIG_MTD_NAND_VF610_NFC)      += vf610_nfc.o
  obj-$(CONFIG_MTD_NAND_RICOH)          += r852.o
  obj-$(CONFIG_MTD_NAND_JZ4740)         += jz4740_nand.o
@@ -1610,7 +1605,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  static int nand_get_device(struct mtd_info *mtd, int new_state);
  
  static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
-@@ -103,10 +59,96 @@
+@@ -103,10 +59,96 @@ static int nand_do_write_oob(struct mtd_
   */
  DEFINE_LED_TRIGGER(nand_led_trigger);
  
@@ -1708,7 +1703,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int ret = 0;
  
        /* Start address must align on block boundary */
-@@ -132,7 +174,7 @@
+@@ -132,7 +174,7 @@ static int check_offs_len(struct mtd_inf
   */
  static void nand_release_device(struct mtd_info *mtd)
  {
@@ -1717,7 +1712,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Release the controller and the chip */
        spin_lock(&chip->controller->lock);
-@@ -150,7 +192,7 @@
+@@ -150,7 +192,7 @@ static void nand_release_device(struct m
   */
  static uint8_t nand_read_byte(struct mtd_info *mtd)
  {
@@ -1726,7 +1721,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return readb(chip->IO_ADDR_R);
  }
  
-@@ -163,7 +205,7 @@
+@@ -163,7 +205,7 @@ static uint8_t nand_read_byte(struct mtd
   */
  static uint8_t nand_read_byte16(struct mtd_info *mtd)
  {
@@ -1735,7 +1730,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return (uint8_t) cpu_to_le16(readw(chip->IO_ADDR_R));
  }
  
-@@ -175,7 +217,7 @@
+@@ -175,7 +217,7 @@ static uint8_t nand_read_byte16(struct m
   */
  static u16 nand_read_word(struct mtd_info *mtd)
  {
@@ -1744,7 +1739,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return readw(chip->IO_ADDR_R);
  }
  
-@@ -188,7 +230,7 @@
+@@ -188,7 +230,7 @@ static u16 nand_read_word(struct mtd_inf
   */
  static void nand_select_chip(struct mtd_info *mtd, int chipnr)
  {
@@ -1753,7 +1748,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        switch (chipnr) {
        case -1:
-@@ -211,7 +253,7 @@
+@@ -211,7 +253,7 @@ static void nand_select_chip(struct mtd_
   */
  static void nand_write_byte(struct mtd_info *mtd, uint8_t byte)
  {
@@ -1762,7 +1757,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        chip->write_buf(mtd, &byte, 1);
  }
-@@ -225,7 +267,7 @@
+@@ -225,7 +267,7 @@ static void nand_write_byte(struct mtd_i
   */
  static void nand_write_byte16(struct mtd_info *mtd, uint8_t byte)
  {
@@ -1771,7 +1766,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        uint16_t word = byte;
  
        /*
-@@ -257,7 +299,7 @@
+@@ -257,7 +299,7 @@ static void nand_write_byte16(struct mtd
   */
  static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  {
@@ -1780,7 +1775,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        iowrite8_rep(chip->IO_ADDR_W, buf, len);
  }
-@@ -272,7 +314,7 @@
+@@ -272,7 +314,7 @@ static void nand_write_buf(struct mtd_in
   */
  static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  {
@@ -1789,7 +1784,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        ioread8_rep(chip->IO_ADDR_R, buf, len);
  }
-@@ -287,7 +329,7 @@
+@@ -287,7 +329,7 @@ static void nand_read_buf(struct mtd_inf
   */
  static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
  {
@@ -1798,7 +1793,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        u16 *p = (u16 *) buf;
  
        iowrite16_rep(chip->IO_ADDR_W, p, len >> 1);
-@@ -303,7 +345,7 @@
+@@ -303,7 +345,7 @@ static void nand_write_buf16(struct mtd_
   */
  static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
  {
@@ -1807,7 +1802,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        u16 *p = (u16 *) buf;
  
        ioread16_rep(chip->IO_ADDR_R, p, len >> 1);
-@@ -313,14 +355,13 @@
+@@ -313,14 +355,13 @@ static void nand_read_buf16(struct mtd_i
   * nand_block_bad - [DEFAULT] Read bad block marker from the chip
   * @mtd: MTD device structure
   * @ofs: offset from device start
@@ -1825,7 +1820,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        u16 bad;
  
        if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
-@@ -328,15 +369,6 @@
+@@ -328,15 +369,6 @@ static int nand_block_bad(struct mtd_inf
  
        page = (int)(ofs >> chip->page_shift) & chip->pagemask;
  
@@ -1841,7 +1836,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        do {
                if (chip->options & NAND_BUSWIDTH_16) {
                        chip->cmdfunc(mtd, NAND_CMD_READOOB,
-@@ -361,11 +393,6 @@
+@@ -361,11 +393,6 @@ static int nand_block_bad(struct mtd_inf
                i++;
        } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE));
  
@@ -1853,7 +1848,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return res;
  }
  
-@@ -380,7 +407,7 @@
+@@ -380,7 +407,7 @@ static int nand_block_bad(struct mtd_inf
   */
  static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
  {
@@ -1862,7 +1857,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct mtd_oob_ops ops;
        uint8_t buf[2] = { 0, 0 };
        int ret = 0, res, i = 0;
-@@ -430,7 +457,7 @@
+@@ -430,7 +457,7 @@ static int nand_default_block_markbad(st
  */
  static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs)
  {
@@ -1871,7 +1866,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int res, ret = 0;
  
        if (!(chip->bbt_options & NAND_BBT_NO_OOB_BBM)) {
-@@ -471,7 +498,7 @@
+@@ -471,7 +498,7 @@ static int nand_block_markbad_lowlevel(s
   */
  static int nand_check_wp(struct mtd_info *mtd)
  {
@@ -1880,7 +1875,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Broken xD cards report WP despite being writable */
        if (chip->options & NAND_BROKEN_XD)
-@@ -491,7 +518,7 @@
+@@ -491,7 +518,7 @@ static int nand_check_wp(struct mtd_info
   */
  static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs)
  {
@@ -1889,7 +1884,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        if (!chip->bbt)
                return 0;
-@@ -503,19 +530,17 @@
+@@ -503,19 +530,17 @@ static int nand_block_isreserved(struct
   * nand_block_checkbad - [GENERIC] Check if a block is marked bad
   * @mtd: MTD device structure
   * @ofs: offset from device start
@@ -1912,7 +1907,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Return info from the table */
        return nand_isbad_bbt(mtd, ofs, allowbbt);
-@@ -531,7 +556,7 @@
+@@ -531,7 +556,7 @@ static int nand_block_checkbad(struct mt
   */
  static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo)
  {
@@ -1921,7 +1916,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int i;
  
        /* Wait for the device to get ready */
-@@ -551,7 +576,7 @@
+@@ -551,7 +576,7 @@ static void panic_nand_wait_ready(struct
   */
  void nand_wait_ready(struct mtd_info *mtd)
  {
@@ -1930,7 +1925,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        unsigned long timeo = 400;
  
        if (in_interrupt() || oops_in_progress)
-@@ -566,8 +591,8 @@
+@@ -566,8 +591,8 @@ void nand_wait_ready(struct mtd_info *mt
                cond_resched();
        } while (time_before(jiffies, timeo));
  
@@ -1941,7 +1936,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  out:
        led_trigger_event(nand_led_trigger, LED_OFF);
  }
-@@ -582,7 +607,7 @@
+@@ -582,7 +607,7 @@ EXPORT_SYMBOL_GPL(nand_wait_ready);
   */
  static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo)
  {
@@ -1950,7 +1945,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        timeo = jiffies + msecs_to_jiffies(timeo);
        do {
-@@ -605,7 +630,7 @@
+@@ -605,7 +630,7 @@ static void nand_wait_status_ready(struc
  static void nand_command(struct mtd_info *mtd, unsigned int command,
                         int column, int page_addr)
  {
@@ -1959,7 +1954,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE;
  
        /* Write out the command to the device */
-@@ -708,7 +733,7 @@
+@@ -708,7 +733,7 @@ static void nand_command(struct mtd_info
  static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
                            int column, int page_addr)
  {
@@ -1968,7 +1963,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Emulate NAND_CMD_READOOB */
        if (command == NAND_CMD_READOOB) {
-@@ -832,7 +857,7 @@
+@@ -832,7 +857,7 @@ static void panic_nand_get_device(struct
  static int
  nand_get_device(struct mtd_info *mtd, int new_state)
  {
@@ -1977,7 +1972,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        spinlock_t *lock = &chip->controller->lock;
        wait_queue_head_t *wq = &chip->controller->wq;
        DECLARE_WAITQUEUE(wait, current);
-@@ -952,7 +977,7 @@
+@@ -952,7 +977,7 @@ static int __nand_unlock(struct mtd_info
  {
        int ret = 0;
        int status, page;
@@ -1986,7 +1981,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Submit address of first page to unlock */
        page = ofs >> chip->page_shift;
-@@ -987,7 +1012,7 @@
+@@ -987,7 +1012,7 @@ int nand_unlock(struct mtd_info *mtd, lo
  {
        int ret = 0;
        int chipnr;
@@ -1995,7 +1990,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
                        __func__, (unsigned long long)ofs, len);
-@@ -1050,7 +1075,7 @@
+@@ -1050,7 +1075,7 @@ int nand_lock(struct mtd_info *mtd, loff
  {
        int ret = 0;
        int chipnr, status, page;
@@ -2004,7 +1999,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
                        __func__, (unsigned long long)ofs, len);
-@@ -1309,13 +1334,12 @@
+@@ -1309,13 +1334,12 @@ static int nand_read_page_raw_syndrome(s
  static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
                                uint8_t *buf, int oob_required, int page)
  {
@@ -2019,7 +2014,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        unsigned int max_bitflips = 0;
  
        chip->ecc.read_page_raw(mtd, chip, buf, 1, page);
-@@ -1323,8 +1347,10 @@
+@@ -1323,8 +1347,10 @@ static int nand_read_page_swecc(struct m
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize)
                chip->ecc.calculate(mtd, p, &ecc_calc[i]);
  
@@ -2032,7 +2027,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        eccsteps = chip->ecc.steps;
        p = buf;
-@@ -1356,14 +1382,14 @@
+@@ -1356,14 +1382,14 @@ static int nand_read_subpage(struct mtd_
                        uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi,
                        int page)
  {
@@ -2050,7 +2045,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Column address within the page aligned to ECC size (256bytes) */
        start_step = data_offs / chip->ecc.size;
-@@ -1391,12 +1417,13 @@
+@@ -1391,12 +1417,13 @@ static int nand_read_subpage(struct mtd_
         * The performance is faster if we position offsets according to
         * ecc.pos. Let's make sure that there are no gaps in ECC positions.
         */
@@ -2070,7 +2065,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        if (gaps) {
                chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
                chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
-@@ -1405,20 +1432,23 @@
+@@ -1405,20 +1432,23 @@ static int nand_read_subpage(struct mtd_
                 * Send the command to read the particular ECC bytes take care
                 * about buswidth alignment in read_buf.
                 */
@@ -2100,7 +2095,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        p = bufpoi + data_col_addr;
        for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) {
-@@ -1426,6 +1456,16 @@
+@@ -1426,6 +1456,16 @@ static int nand_read_subpage(struct mtd_
  
                stat = chip->ecc.correct(mtd, p,
                        &chip->buffers->ecccode[i], &chip->buffers->ecccalc[i]);
@@ -2117,7 +2112,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                if (stat < 0) {
                        mtd->ecc_stats.failed++;
                } else {
-@@ -1449,13 +1489,12 @@
+@@ -1449,13 +1489,12 @@ static int nand_read_subpage(struct mtd_
  static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
                                uint8_t *buf, int oob_required, int page)
  {
@@ -2132,7 +2127,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        unsigned int max_bitflips = 0;
  
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
-@@ -1465,8 +1504,10 @@
+@@ -1465,8 +1504,10 @@ static int nand_read_page_hwecc(struct m
        }
        chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
  
@@ -2145,7 +2140,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        eccsteps = chip->ecc.steps;
        p = buf;
-@@ -1475,6 +1516,15 @@
+@@ -1475,6 +1516,15 @@ static int nand_read_page_hwecc(struct m
                int stat;
  
                stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
@@ -2161,7 +2156,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                if (stat < 0) {
                        mtd->ecc_stats.failed++;
                } else {
-@@ -1502,12 +1552,11 @@
+@@ -1502,12 +1552,11 @@ static int nand_read_page_hwecc(struct m
  static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
        struct nand_chip *chip, uint8_t *buf, int oob_required, int page)
  {
@@ -2175,7 +2170,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        uint8_t *ecc_calc = chip->buffers->ecccalc;
        unsigned int max_bitflips = 0;
  
-@@ -1516,8 +1565,10 @@
+@@ -1516,8 +1565,10 @@ static int nand_read_page_hwecc_oob_firs
        chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
        chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
  
@@ -2188,7 +2183,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
                int stat;
-@@ -1527,6 +1578,15 @@
+@@ -1527,6 +1578,15 @@ static int nand_read_page_hwecc_oob_firs
                chip->ecc.calculate(mtd, p, &ecc_calc[i]);
  
                stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL);
@@ -2204,7 +2199,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                if (stat < 0) {
                        mtd->ecc_stats.failed++;
                } else {
-@@ -1554,6 +1614,7 @@
+@@ -1554,6 +1614,7 @@ static int nand_read_page_syndrome(struc
        int i, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
        int eccsteps = chip->ecc.steps;
@@ -2212,7 +2207,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        uint8_t *p = buf;
        uint8_t *oob = chip->oob_poi;
        unsigned int max_bitflips = 0;
-@@ -1573,19 +1634,29 @@
+@@ -1573,19 +1634,29 @@ static int nand_read_page_syndrome(struc
                chip->read_buf(mtd, oob, eccbytes);
                stat = chip->ecc.correct(mtd, p, oob, NULL);
  
@@ -2249,7 +2244,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        }
  
        /* Calculate remaining oob bytes */
-@@ -1598,14 +1669,17 @@
+@@ -1598,14 +1669,17 @@ static int nand_read_page_syndrome(struc
  
  /**
   * nand_transfer_oob - [INTERN] Transfer oob to client buffer
@@ -2269,7 +2264,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        switch (ops->mode) {
  
        case MTD_OPS_PLACE_OOB:
-@@ -1613,31 +1687,12 @@
+@@ -1613,31 +1687,12 @@ static uint8_t *nand_transfer_oob(struct
                memcpy(oob, chip->oob_poi + ops->ooboffs, len);
                return oob + len;
  
@@ -2307,7 +2302,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        default:
                BUG();
        }
-@@ -1655,7 +1710,7 @@
+@@ -1655,7 +1710,7 @@ static uint8_t *nand_transfer_oob(struct
   */
  static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode)
  {
@@ -2316,7 +2311,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        pr_debug("setting READ RETRY mode %d\n", retry_mode);
  
-@@ -1680,12 +1735,11 @@
+@@ -1680,12 +1735,11 @@ static int nand_do_read_ops(struct mtd_i
                            struct mtd_oob_ops *ops)
  {
        int chipnr, page, realpage, col, bytes, aligned, oob_required;
@@ -2331,7 +2326,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        uint8_t *bufpoi, *oob, *buf;
        int use_bufpoi;
-@@ -1772,7 +1826,7 @@
+@@ -1772,7 +1826,7 @@ read_retry:
                                int toread = min(oobreadlen, max_oobsize);
  
                                if (toread) {
@@ -2340,7 +2335,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                                                oob, ops, toread);
                                        oobreadlen -= toread;
                                }
-@@ -2024,7 +2078,7 @@
+@@ -2024,7 +2078,7 @@ static int nand_do_read_oob(struct mtd_i
                            struct mtd_oob_ops *ops)
  {
        int page, realpage, chipnr;
@@ -2349,7 +2344,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct mtd_ecc_stats stats;
        int readlen = ops->ooblen;
        int len;
-@@ -2036,10 +2090,7 @@
+@@ -2036,10 +2090,7 @@ static int nand_do_read_oob(struct mtd_i
  
        stats = mtd->ecc_stats;
  
@@ -2361,7 +2356,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        if (unlikely(ops->ooboffs >= len)) {
                pr_debug("%s: attempt to start read outside oob\n",
-@@ -2073,7 +2124,7 @@
+@@ -2073,7 +2124,7 @@ static int nand_do_read_oob(struct mtd_i
                        break;
  
                len = min(len, readlen);
@@ -2370,7 +2365,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
                if (chip->options & NAND_NEED_READRDY) {
                        /* Apply delay or wait for ready/busy pin */
-@@ -2232,19 +2283,20 @@
+@@ -2232,19 +2283,20 @@ static int nand_write_page_swecc(struct
                                 const uint8_t *buf, int oob_required,
                                 int page)
  {
@@ -2395,7 +2390,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        return chip->ecc.write_page_raw(mtd, chip, buf, 1, page);
  }
-@@ -2261,12 +2313,11 @@
+@@ -2261,12 +2313,11 @@ static int nand_write_page_hwecc(struct
                                  const uint8_t *buf, int oob_required,
                                  int page)
  {
@@ -2409,7 +2404,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
                chip->ecc.hwctl(mtd, NAND_ECC_WRITE);
-@@ -2274,8 +2325,10 @@
+@@ -2274,8 +2325,10 @@ static int nand_write_page_hwecc(struct
                chip->ecc.calculate(mtd, p, &ecc_calc[i]);
        }
  
@@ -2422,7 +2417,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
  
-@@ -2303,11 +2356,10 @@
+@@ -2303,11 +2356,10 @@ static int nand_write_subpage_hwecc(stru
        int ecc_size      = chip->ecc.size;
        int ecc_bytes     = chip->ecc.bytes;
        int ecc_steps     = chip->ecc.steps;
@@ -2435,7 +2430,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        for (step = 0; step < ecc_steps; step++) {
                /* configure controller for WRITE access */
-@@ -2335,8 +2387,10 @@
+@@ -2335,8 +2387,10 @@ static int nand_write_subpage_hwecc(stru
        /* copy calculated ECC for whole page to chip->buffer->oob */
        /* this include masked-value(0xFF) for unwritten subpages */
        ecc_calc = chip->buffers->ecccalc;
@@ -2448,7 +2443,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* write OOB buffer to NAND device */
        chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
-@@ -2472,7 +2526,8 @@
+@@ -2472,7 +2526,8 @@ static int nand_write_page(struct mtd_in
  static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len,
                              struct mtd_oob_ops *ops)
  {
@@ -2458,7 +2453,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /*
         * Initialise to all 0xFF, to avoid the possibility of left over OOB
-@@ -2487,31 +2542,12 @@
+@@ -2487,31 +2542,12 @@ static uint8_t *nand_fill_oob(struct mtd
                memcpy(chip->oob_poi + ops->ooboffs, oob, len);
                return oob + len;
  
@@ -2496,7 +2491,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        default:
                BUG();
        }
-@@ -2532,12 +2568,11 @@
+@@ -2532,12 +2568,11 @@ static int nand_do_write_ops(struct mtd_
                             struct mtd_oob_ops *ops)
  {
        int chipnr, realpage, page, blockmask, column;
@@ -2511,7 +2506,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        uint8_t *oob = ops->oobbuf;
        uint8_t *buf = ops->datbuf;
-@@ -2662,7 +2697,7 @@
+@@ -2662,7 +2697,7 @@ err_out:
  static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
                            size_t *retlen, const uint8_t *buf)
  {
@@ -2520,7 +2515,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct mtd_oob_ops ops;
        int ret;
  
-@@ -2722,15 +2757,12 @@
+@@ -2722,15 +2757,12 @@ static int nand_do_write_oob(struct mtd_
                             struct mtd_oob_ops *ops)
  {
        int chipnr, page, status, len;
@@ -2538,7 +2533,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Do not allow write past end of page */
        if ((ops->ooboffs + ops->ooblen) > len) {
-@@ -2847,7 +2879,7 @@
+@@ -2847,7 +2879,7 @@ out:
   */
  static int single_erase(struct mtd_info *mtd, int page)
  {
@@ -2547,7 +2542,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        /* Send commands to erase a block */
        chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
        chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
-@@ -2879,7 +2911,7 @@
+@@ -2879,7 +2911,7 @@ int nand_erase_nand(struct mtd_info *mtd
                    int allowbbt)
  {
        int page, status, pages_per_block, ret, chipnr;
@@ -2556,7 +2551,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        loff_t len;
  
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
-@@ -2918,7 +2950,7 @@
+@@ -2918,7 +2950,7 @@ int nand_erase_nand(struct mtd_info *mtd
        while (len) {
                /* Check if we have a bad block, we do not erase bad blocks! */
                if (nand_block_checkbad(mtd, ((loff_t) page) <<
@@ -2565,7 +2560,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                        pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
                                    __func__, page);
                        instr->state = MTD_ERASE_FAILED;
-@@ -3005,7 +3037,20 @@
+@@ -3005,7 +3037,20 @@ static void nand_sync(struct mtd_info *m
   */
  static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
  {
@@ -2587,7 +2582,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  }
  
  /**
-@@ -3094,7 +3139,7 @@
+@@ -3094,7 +3139,7 @@ static int nand_suspend(struct mtd_info
   */
  static void nand_resume(struct mtd_info *mtd)
  {
@@ -2596,7 +2591,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        if (chip->state == FL_PM_SUSPENDED)
                nand_release_device(mtd);
-@@ -3266,7 +3311,7 @@
+@@ -3266,7 +3311,7 @@ ext_out:
  
  static int nand_setup_read_retry_micron(struct mtd_info *mtd, int retry_mode)
  {
@@ -2605,7 +2600,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        uint8_t feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode};
  
        return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY,
-@@ -3937,10 +3982,13 @@
+@@ -3937,10 +3982,13 @@ ident_done:
        return type;
  }
  
@@ -2622,7 +2617,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        if (of_get_nand_bus_width(dn) == 16)
                chip->options |= NAND_BUSWIDTH_16;
-@@ -3949,6 +3997,7 @@
+@@ -3949,6 +3997,7 @@ static int nand_dt_init(struct mtd_info
                chip->bbt_options |= NAND_BBT_USE_FLASH;
  
        ecc_mode = of_get_nand_ecc_mode(dn);
@@ -2630,7 +2625,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        ecc_strength = of_get_nand_ecc_strength(dn);
        ecc_step = of_get_nand_ecc_step_size(dn);
  
-@@ -3961,6 +4010,9 @@
+@@ -3961,6 +4010,9 @@ static int nand_dt_init(struct mtd_info
        if (ecc_mode >= 0)
                chip->ecc.mode = ecc_mode;
  
@@ -2640,7 +2635,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        if (ecc_strength >= 0)
                chip->ecc.strength = ecc_strength;
  
-@@ -3984,15 +4036,16 @@
+@@ -3984,15 +4036,16 @@ int nand_scan_ident(struct mtd_info *mtd
                    struct nand_flash_dev *table)
  {
        int i, nand_maf_id, nand_dev_id;
@@ -2663,7 +2658,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        if (!mtd->name && mtd->dev.parent)
                mtd->name = dev_name(mtd->dev.parent);
-@@ -4055,7 +4108,7 @@
+@@ -4055,7 +4108,7 @@ EXPORT_SYMBOL(nand_scan_ident);
   */
  static bool nand_ecc_strength_good(struct mtd_info *mtd)
  {
@@ -2672,7 +2667,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        int corr, ds_corr;
  
-@@ -4083,10 +4136,10 @@
+@@ -4083,10 +4136,10 @@ static bool nand_ecc_strength_good(struc
   */
  int nand_scan_tail(struct mtd_info *mtd)
  {
@@ -2685,7 +2680,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* New bad blocks should be marked in OOB, flash-based BBT, or both */
        BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
-@@ -4113,19 +4166,15 @@
+@@ -4113,19 +4166,15 @@ int nand_scan_tail(struct mtd_info *mtd)
        /*
         * If no default placement scheme is given, select an appropriate one.
         */
@@ -2708,7 +2703,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                        break;
                default:
                        pr_warn("No oob scheme defined for oobsize %d\n",
-@@ -4168,7 +4217,7 @@
+@@ -4168,7 +4217,7 @@ int nand_scan_tail(struct mtd_info *mtd)
                        ecc->write_oob = nand_write_oob_std;
                if (!ecc->read_subpage)
                        ecc->read_subpage = nand_read_subpage;
@@ -2717,7 +2712,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                        ecc->write_subpage = nand_write_subpage_hwecc;
  
        case NAND_ECC_HW_SYNDROME:
-@@ -4246,10 +4295,8 @@
+@@ -4246,10 +4295,8 @@ int nand_scan_tail(struct mtd_info *mtd)
                }
  
                /* See nand_bch_init() for details. */
@@ -2730,7 +2725,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                if (!ecc->priv) {
                        pr_warn("BCH ECC initialization failed!\n");
                        BUG();
-@@ -4280,20 +4327,9 @@
+@@ -4280,20 +4327,9 @@ int nand_scan_tail(struct mtd_info *mtd)
        if (!ecc->write_oob_raw)
                ecc->write_oob_raw = ecc->write_oob;
  
@@ -2754,7 +2749,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /*
         * Set the number of read / write steps for one page depending on ECC
-@@ -4306,6 +4342,21 @@
+@@ -4306,6 +4342,21 @@ int nand_scan_tail(struct mtd_info *mtd)
        }
        ecc->total = ecc->steps * ecc->bytes;
  
@@ -2776,7 +2771,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
        if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && nand_is_slc(chip)) {
                switch (ecc->steps) {
-@@ -4362,10 +4413,6 @@
+@@ -4362,10 +4413,6 @@ int nand_scan_tail(struct mtd_info *mtd)
        mtd->_block_markbad = nand_block_markbad;
        mtd->writebufsize = mtd->writesize;
  
@@ -2787,7 +2782,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        /*
         * Initialize bitflip_threshold to its default prior scan_bbt() call.
         * scan_bbt() might invoke mtd_read(), thus bitflip_threshold must be
-@@ -4421,7 +4468,7 @@
+@@ -4421,7 +4468,7 @@ EXPORT_SYMBOL(nand_scan);
   */
  void nand_release(struct mtd_info *mtd)
  {
@@ -2798,7 +2793,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
 --- a/drivers/mtd/nand/nand_bbt.c
 +++ b/drivers/mtd/nand/nand_bbt.c
-@@ -172,7 +172,7 @@
+@@ -172,7 +172,7 @@ static int read_bbt(struct mtd_info *mtd
                struct nand_bbt_descr *td, int offs)
  {
        int res, ret = 0, i, j, act = 0;
@@ -2807,7 +2802,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        size_t retlen, len, totlen;
        loff_t from;
        int bits = td->options & NAND_BBT_NRBITS_MSK;
-@@ -263,7 +263,7 @@
+@@ -263,7 +263,7 @@ static int read_bbt(struct mtd_info *mtd
   */
  static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
  {
@@ -2816,7 +2811,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int res = 0, i;
  
        if (td->options & NAND_BBT_PERCHIP) {
-@@ -388,7 +388,7 @@
+@@ -388,7 +388,7 @@ static u32 bbt_get_ver_offs(struct mtd_i
  static void read_abs_bbts(struct mtd_info *mtd, uint8_t *buf,
                          struct nand_bbt_descr *td, struct nand_bbt_descr *md)
  {
@@ -2825,7 +2820,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Read the primary version, if available */
        if (td->options & NAND_BBT_VERSION) {
-@@ -454,7 +454,7 @@
+@@ -454,7 +454,7 @@ static int scan_block_fast(struct mtd_in
  static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
        struct nand_bbt_descr *bd, int chip)
  {
@@ -2834,7 +2829,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int i, numblocks, numpages;
        int startblock;
        loff_t from;
-@@ -523,7 +523,7 @@
+@@ -523,7 +523,7 @@ static int create_bbt(struct mtd_info *m
   */
  static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
  {
@@ -2843,7 +2838,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int i, chips;
        int startblock, block, dir;
        int scanlen = mtd->writesize + mtd->oobsize;
-@@ -618,7 +618,7 @@
+@@ -618,7 +618,7 @@ static int write_bbt(struct mtd_info *mt
                     struct nand_bbt_descr *td, struct nand_bbt_descr *md,
                     int chipsel)
  {
@@ -2852,7 +2847,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct erase_info einfo;
        int i, res, chip = 0;
        int bits, startblock, dir, page, offs, numblocks, sft, sftmsk;
-@@ -819,7 +819,7 @@
+@@ -819,7 +819,7 @@ static int write_bbt(struct mtd_info *mt
   */
  static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
  {
@@ -2861,7 +2856,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        return create_bbt(mtd, this->buffers->databuf, bd, -1);
  }
-@@ -838,7 +838,7 @@
+@@ -838,7 +838,7 @@ static inline int nand_memory_bbt(struct
  static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
  {
        int i, chips, writeops, create, chipsel, res, res2;
@@ -2870,7 +2865,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct nand_bbt_descr *td = this->bbt_td;
        struct nand_bbt_descr *md = this->bbt_md;
        struct nand_bbt_descr *rd, *rd2;
-@@ -962,7 +962,7 @@
+@@ -962,7 +962,7 @@ static int check_create(struct mtd_info
   */
  static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
  {
@@ -2879,7 +2874,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int i, j, chips, block, nrblocks, update;
        uint8_t oldval;
  
-@@ -1022,7 +1022,7 @@
+@@ -1022,7 +1022,7 @@ static void mark_bbt_region(struct mtd_i
   */
  static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd)
  {
@@ -2888,7 +2883,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        u32 pattern_len;
        u32 bits;
        u32 table_size;
-@@ -1074,7 +1074,7 @@
+@@ -1074,7 +1074,7 @@ static void verify_bbt_descr(struct mtd_
   */
  static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
  {
@@ -2897,7 +2892,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int len, res;
        uint8_t *buf;
        struct nand_bbt_descr *td = this->bbt_td;
-@@ -1147,7 +1147,7 @@
+@@ -1147,7 +1147,7 @@ err:
   */
  static int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
  {
@@ -2906,7 +2901,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int len, res = 0;
        int chip, chipsel;
        uint8_t *buf;
-@@ -1281,7 +1281,7 @@
+@@ -1281,7 +1281,7 @@ static int nand_create_badblock_pattern(
   */
  int nand_default_bbt(struct mtd_info *mtd)
  {
@@ -2915,7 +2910,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int ret;
  
        /* Is a flash based bad block table requested? */
-@@ -1317,7 +1317,7 @@
+@@ -1317,7 +1317,7 @@ int nand_default_bbt(struct mtd_info *mt
   */
  int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs)
  {
@@ -2924,7 +2919,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int block;
  
        block = (int)(offs >> this->bbt_erase_shift);
-@@ -1332,7 +1332,7 @@
+@@ -1332,7 +1332,7 @@ int nand_isreserved_bbt(struct mtd_info
   */
  int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
  {
@@ -2933,7 +2928,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int block, res;
  
        block = (int)(offs >> this->bbt_erase_shift);
-@@ -1359,7 +1359,7 @@
+@@ -1359,7 +1359,7 @@ int nand_isbad_bbt(struct mtd_info *mtd,
   */
  int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs)
  {
@@ -2942,7 +2937,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int block, ret = 0;
  
        block = (int)(offs >> this->bbt_erase_shift);
-@@ -1373,5 +1373,3 @@
+@@ -1373,5 +1373,3 @@ int nand_markbad_bbt(struct mtd_info *mt
  
        return ret;
  }
@@ -2964,7 +2959,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        unsigned int         *errloc;
        unsigned char        *eccmask;
  };
-@@ -52,7 +50,7 @@
+@@ -52,7 +50,7 @@ struct nand_bch_control {
  int nand_bch_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
                           unsigned char *code)
  {
@@ -2973,7 +2968,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct nand_bch_control *nbc = chip->ecc.priv;
        unsigned int i;
  
-@@ -79,7 +77,7 @@
+@@ -79,7 +77,7 @@ EXPORT_SYMBOL(nand_bch_calculate_ecc);
  int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
                          unsigned char *read_ecc, unsigned char *calc_ecc)
  {
@@ -2982,7 +2977,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct nand_bch_control *nbc = chip->ecc.priv;
        unsigned int *errloc = nbc->errloc;
        int i, count;
-@@ -98,7 +96,7 @@
+@@ -98,7 +96,7 @@ int nand_bch_correct_data(struct mtd_inf
                }
        } else if (count < 0) {
                printk(KERN_ERR "ecc unrecoverable error\n");
@@ -2991,7 +2986,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        }
        return count;
  }
-@@ -107,9 +105,6 @@
+@@ -107,9 +105,6 @@ EXPORT_SYMBOL(nand_bch_correct_data);
  /**
   * nand_bch_init - [NAND Interface] Initialize NAND BCH error correction
   * @mtd:      MTD block structure
@@ -3001,7 +2996,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   *
   * Returns:
   *  a pointer to a new NAND BCH control structure, or NULL upon failure
-@@ -123,14 +118,20 @@
+@@ -123,14 +118,20 @@ EXPORT_SYMBOL(nand_bch_correct_data);
   * @eccsize = 512  (thus, m=13 is the smallest integer such that 2^m-1 > 512*8)
   * @eccbytes = 7   (7 bytes are required to store m*t = 13*4 = 52 bits)
   */
@@ -3026,7 +3021,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        if (!eccsize || !eccbytes) {
                printk(KERN_WARNING "ecc parameters not supplied\n");
-@@ -158,7 +159,7 @@
+@@ -158,7 +159,7 @@ nand_bch_init(struct mtd_info *mtd, unsi
        eccsteps = mtd->writesize/eccsize;
  
        /* if no ecc placement scheme was provided, build one */
@@ -3035,7 +3030,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
                /* handle large page devices only */
                if (mtd->oobsize < 64) {
-@@ -167,24 +168,7 @@
+@@ -167,24 +168,7 @@ nand_bch_init(struct mtd_info *mtd, unsi
                        goto fail;
                }
  
@@ -3061,7 +3056,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        }
  
        /* sanity checks */
-@@ -192,7 +176,8 @@
+@@ -192,7 +176,8 @@ nand_bch_init(struct mtd_info *mtd, unsi
                printk(KERN_WARNING "eccsize %u is too large\n", eccsize);
                goto fail;
        }
@@ -3071,7 +3066,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                printk(KERN_WARNING "invalid ecc layout\n");
                goto fail;
        }
-@@ -216,6 +201,9 @@
+@@ -216,6 +201,9 @@ nand_bch_init(struct mtd_info *mtd, unsi
        for (i = 0; i < eccbytes; i++)
                nbc->eccmask[i] ^= 0xff;
  
@@ -3083,7 +3078,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        nand_bch_free(nbc);
 --- a/drivers/mtd/nand/nand_ecc.c
 +++ b/drivers/mtd/nand/nand_ecc.c
-@@ -424,7 +424,7 @@
+@@ -424,7 +424,7 @@ int nand_calculate_ecc(struct mtd_info *
                       unsigned char *code)
  {
        __nand_calculate_ecc(buf,
@@ -3092,7 +3087,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        return 0;
  }
-@@ -524,7 +524,7 @@
+@@ -524,7 +524,7 @@ int nand_correct_data(struct mtd_info *m
                      unsigned char *read_ecc, unsigned char *calc_ecc)
  {
        return __nand_correct_data(buf, read_ecc, calc_ecc,
@@ -3103,7 +3098,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
 --- a/drivers/mtd/nand/nand_ids.c
 +++ b/drivers/mtd/nand/nand_ids.c
-@@ -50,8 +50,8 @@
+@@ -50,8 +50,8 @@ struct nand_flash_dev nand_flash_ids[] =
                  SZ_16K, SZ_8K, SZ_4M, 0, 6, 1280, NAND_ECC_INFO(40, SZ_1K) },
        {"H27UCG8T2ATR-BC 64G 3.3V 8-bit",
                { .id = {0xad, 0xde, 0x94, 0xda, 0x74, 0xc4} },
@@ -3116,7 +3111,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        LEGACY_ID_NAND("NAND 4MiB 3,3V 8-bit", 0xE3, 4, SZ_8K, SP_OPTIONS),
 --- a/drivers/mtd/nand/nandsim.c
 +++ b/drivers/mtd/nand/nandsim.c
-@@ -666,8 +666,8 @@
+@@ -666,8 +666,8 @@ static char *get_partition_name(int i)
   */
  static int init_nandsim(struct mtd_info *mtd)
  {
@@ -3127,7 +3122,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int i, ret = 0;
        uint64_t remains;
        uint64_t next_offset;
-@@ -1908,7 +1908,8 @@
+@@ -1908,7 +1908,8 @@ static void switch_state(struct nandsim
  
  static u_char ns_nand_read_byte(struct mtd_info *mtd)
  {
@@ -3137,7 +3132,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        u_char outb = 0x00;
  
        /* Sanity and correctness checks */
-@@ -1969,7 +1970,8 @@
+@@ -1969,7 +1970,8 @@ static u_char ns_nand_read_byte(struct m
  
  static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
  {
@@ -3147,7 +3142,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Sanity and correctness checks */
        if (!ns->lines.ce) {
-@@ -2123,7 +2125,8 @@
+@@ -2123,7 +2125,8 @@ static void ns_nand_write_byte(struct mt
  
  static void ns_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int bitmask)
  {
@@ -3157,7 +3152,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        ns->lines.cle = bitmask & NAND_CLE ? 1 : 0;
        ns->lines.ale = bitmask & NAND_ALE ? 1 : 0;
-@@ -2141,7 +2144,7 @@
+@@ -2141,7 +2144,7 @@ static int ns_device_ready(struct mtd_in
  
  static uint16_t ns_nand_read_word(struct mtd_info *mtd)
  {
@@ -3166,7 +3161,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        NS_DBG("read_word\n");
  
-@@ -2150,7 +2153,8 @@
+@@ -2150,7 +2153,8 @@ static uint16_t ns_nand_read_word(struct
  
  static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
  {
@@ -3176,7 +3171,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Check that chip is expecting data input */
        if (!(ns->state & STATE_DATAIN_MASK)) {
-@@ -2177,7 +2181,8 @@
+@@ -2177,7 +2181,8 @@ static void ns_nand_write_buf(struct mtd
  
  static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  {
@@ -3186,7 +3181,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Sanity and correctness checks */
        if (!ns->lines.ce) {
-@@ -2198,7 +2203,7 @@
+@@ -2198,7 +2203,7 @@ static void ns_nand_read_buf(struct mtd_
                int i;
  
                for (i = 0; i < len; i++)
@@ -3195,7 +3190,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
                return;
        }
-@@ -2236,16 +2241,15 @@
+@@ -2236,16 +2241,15 @@ static int __init ns_init_module(void)
        }
  
        /* Allocate and initialize mtd_info, nand_chip and nandsim structures */
@@ -3217,7 +3212,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /*
         * Register simulator's callbacks.
-@@ -2257,6 +2261,7 @@
+@@ -2257,6 +2261,7 @@ static int __init ns_init_module(void)
        chip->read_buf   = ns_nand_read_buf;
        chip->read_word  = ns_nand_read_word;
        chip->ecc.mode   = NAND_ECC_SOFT;
@@ -3225,7 +3220,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        /* The NAND_SKIP_BBTSCAN option is necessary for 'overridesize' */
        /* and 'badblocks' parameters to work */
        chip->options   |= NAND_SKIP_BBTSCAN;
-@@ -2335,6 +2340,7 @@
+@@ -2335,6 +2340,7 @@ static int __init ns_init_module(void)
                        goto error;
                }
                chip->ecc.mode = NAND_ECC_SOFT_BCH;
@@ -3233,7 +3228,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                chip->ecc.size = 512;
                chip->ecc.strength = bch;
                chip->ecc.bytes = eccbytes;
-@@ -2392,7 +2398,7 @@
+@@ -2392,7 +2398,7 @@ err_exit:
        for (i = 0;i < ARRAY_SIZE(nand->partitions); ++i)
                kfree(nand->partitions[i].name);
  error:
@@ -3242,7 +3237,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        free_lists();
  
        return retval;
-@@ -2405,7 +2411,8 @@
+@@ -2405,7 +2411,8 @@ module_init(ns_init_module);
   */
  static void __exit ns_cleanup_module(void)
  {
@@ -3252,7 +3247,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int i;
  
        nandsim_debugfs_remove(ns);
-@@ -2413,7 +2420,7 @@
+@@ -2413,7 +2420,7 @@ static void __exit ns_cleanup_module(voi
        nand_release(nsmtd); /* Unregister driver */
        for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i)
                kfree(ns->partitions[i].name);
@@ -3263,7 +3258,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
 --- a/drivers/mtd/ofpart.c
 +++ b/drivers/mtd/ofpart.c
-@@ -26,9 +26,10 @@
+@@ -26,9 +26,10 @@ static bool node_has_compatible(struct d
  }
  
  static int parse_ofpart_partitions(struct mtd_info *master,
@@ -3275,7 +3270,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct device_node *mtd_node;
        struct device_node *ofpart_node;
        const char *partname;
-@@ -37,10 +38,8 @@
+@@ -37,10 +38,8 @@ static int parse_ofpart_partitions(struc
        bool dedicated = true;
  
  
@@ -3288,7 +3283,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        if (!mtd_node)
                return 0;
  
-@@ -72,8 +71,8 @@
+@@ -72,8 +71,8 @@ static int parse_ofpart_partitions(struc
        if (nr_parts == 0)
                return 0;
  
@@ -3299,7 +3294,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                return -ENOMEM;
  
        i = 0;
-@@ -107,19 +106,19 @@
+@@ -107,19 +106,19 @@ static int parse_ofpart_partitions(struc
                        goto ofpart_fail;
                }
  
@@ -3324,7 +3319,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
                i++;
        }
-@@ -127,6 +126,7 @@
+@@ -127,6 +126,7 @@ static int parse_ofpart_partitions(struc
        if (!nr_parts)
                goto ofpart_none;
  
@@ -3332,7 +3327,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        return nr_parts;
  
  ofpart_fail:
-@@ -135,21 +135,20 @@
+@@ -135,21 +135,20 @@ ofpart_fail:
        ret = -EINVAL;
  ofpart_none:
        of_node_put(pp);
@@ -3357,7 +3352,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        struct device_node *dp;
        int i, plen, nr_parts;
        const struct {
-@@ -157,10 +156,8 @@
+@@ -157,10 +156,8 @@ static int parse_ofoldpart_partitions(st
        } *part;
        const char *names;
  
@@ -3370,7 +3365,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        if (!dp)
                return 0;
  
-@@ -173,37 +170,37 @@
+@@ -173,37 +170,37 @@ static int parse_ofoldpart_partitions(st
  
        nr_parts = plen / sizeof(part[0]);
  
@@ -3418,7 +3413,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  };
 --- a/drivers/mtd/spi-nor/Kconfig
 +++ b/drivers/mtd/spi-nor/Kconfig
-@@ -7,6 +7,14 @@
+@@ -7,6 +7,14 @@ menuconfig MTD_SPI_NOR
  
  if MTD_SPI_NOR
  
@@ -3433,7 +3428,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  config MTD_SPI_NOR_USE_4K_SECTORS
        bool "Use small 4096 B erase sectors"
        default y
-@@ -23,7 +31,7 @@
+@@ -23,7 +31,7 @@ config MTD_SPI_NOR_USE_4K_SECTORS
  
  config SPI_FSL_QUADSPI
        tristate "Freescale Quad SPI controller"
@@ -3947,7 +3942,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
  struct flash_info {
        char            *name;
-@@ -60,14 +61,20 @@
+@@ -60,15 +61,20 @@ struct flash_info {
        u16             addr_width;
  
        u16             flags;
@@ -3959,6 +3954,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
 -#define       SPI_NOR_DUAL_READ       0x20    /* Flash supports Dual Read */
 -#define       SPI_NOR_QUAD_READ       0x40    /* Flash supports Quad Read */
 -#define       USE_FSR                 0x80    /* use flag status register */
+-#define       SPI_NOR_HAS_LOCK        0x100   /* Flash supports lock/unlock via SR */
 +#define SECT_4K                       BIT(0)  /* SPINOR_OP_BE_4K works uniformly */
 +#define SPI_NOR_NO_ERASE      BIT(1)  /* No erase command needed */
 +#define SST_WRITE             BIT(2)  /* use SST byte programming */
@@ -3976,7 +3972,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  };
  
  #define JEDEC_MFR(info)       ((info)->id[0])
-@@ -313,6 +320,29 @@
+@@ -314,6 +320,29 @@ static void spi_nor_unlock_and_unprep(st
  }
  
  /*
@@ -4006,7 +4002,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * Erase an address range on the nor chip.  The address range may extend
   * one or more erase sectors.  Return an error is there is a problem erasing.
   */
-@@ -371,10 +401,9 @@
+@@ -372,10 +401,9 @@ static int spi_nor_erase(struct mtd_info
                while (len) {
                        write_enable(nor);
  
@@ -4019,7 +4015,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
                        addr += mtd->erasesize;
                        len -= mtd->erasesize;
-@@ -387,17 +416,13 @@
+@@ -388,17 +416,13 @@ static int spi_nor_erase(struct mtd_info
  
        write_disable(nor);
  
@@ -4039,7 +4035,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  }
  
  static void stm_get_locked_range(struct spi_nor *nor, u8 sr, loff_t *ofs,
-@@ -415,32 +440,58 @@
+@@ -416,32 +440,58 @@ static void stm_get_locked_range(struct
        } else {
                pow = ((sr & mask) ^ mask) >> shift;
                *len = mtd->size >> pow;
@@ -4105,7 +4101,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * Sample table portion for 8MB flash (Winbond w25q64fw):
   *
   *   SEC  |  TB   |  BP2  |  BP1  |  BP0  |  Prot Length  | Protected Portion
-@@ -453,26 +504,55 @@
+@@ -454,26 +504,55 @@ static int stm_is_locked_sr(struct spi_n
   *    0   |   0   |   1   |   0   |   1   |  2 MB         | Upper 1/4
   *    0   |   0   |   1   |   1   |   0   |  4 MB         | Upper 1/2
   *    X   |   X   |   1   |   1   |   1   |  8 MB         | ALL
@@ -4170,7 +4166,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /*
         * Need smallest pow such that:
-@@ -483,7 +563,7 @@
+@@ -484,7 +563,7 @@ static int stm_lock(struct spi_nor *nor,
         *
         *   pow = ceil(log2(size / len)) = log2(size) - floor(log2(len))
         */
@@ -4179,7 +4175,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        val = mask - (pow << shift);
        if (val & ~mask)
                return -EINVAL;
-@@ -491,14 +571,27 @@
+@@ -492,14 +571,27 @@ static int stm_lock(struct spi_nor *nor,
        if (!(val & mask))
                return -EINVAL;
  
@@ -4210,7 +4206,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  }
  
  /*
-@@ -509,17 +602,43 @@
+@@ -510,17 +602,43 @@ static int stm_lock(struct spi_nor *nor,
  static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
  {
        struct mtd_info *mtd = &nor->mtd;
@@ -4258,7 +4254,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        /*
         * Need largest pow such that:
         *
-@@ -529,8 +648,8 @@
+@@ -530,8 +648,8 @@ static int stm_unlock(struct spi_nor *no
         *
         *   pow = floor(log2(size / len)) = log2(size) - ceil(log2(len))
         */
@@ -4269,7 +4265,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                val = 0; /* fully unlocked */
        } else {
                val = mask - (pow << shift);
-@@ -539,14 +658,28 @@
+@@ -540,14 +658,28 @@ static int stm_unlock(struct spi_nor *no
                        return -EINVAL;
        }
  
@@ -4301,19 +4297,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  }
  
  /*
-@@ -715,9 +848,9 @@
-       { "mx25l4005a",  INFO(0xc22013, 0, 64 * 1024,   8, SECT_4K) },
-       { "mx25l8005",   INFO(0xc22014, 0, 64 * 1024,  16, 0) },
-       { "mx25l1606e",  INFO(0xc22015, 0, 64 * 1024,  32, SECT_4K) },
--      { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, 0) },
-+      { "mx25l3205d",  INFO(0xc22016, 0, 64 * 1024,  64, SECT_4K) },
-       { "mx25l3255e",  INFO(0xc29e16, 0, 64 * 1024,  64, SECT_4K) },
--      { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, 0) },
-+      { "mx25l6405d",  INFO(0xc22017, 0, 64 * 1024, 128, SECT_4K) },
-       { "mx25u6435f",  INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) },
-       { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
-       { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
-@@ -731,8 +864,8 @@
+@@ -737,8 +869,8 @@ static const struct flash_info spi_nor_i
        { "n25q032a",    INFO(0x20bb16, 0, 64 * 1024,   64, SPI_NOR_QUAD_READ) },
        { "n25q064",     INFO(0x20ba17, 0, 64 * 1024,  128, SECT_4K | SPI_NOR_QUAD_READ) },
        { "n25q064a",    INFO(0x20bb17, 0, 64 * 1024,  128, SECT_4K | SPI_NOR_QUAD_READ) },
@@ -4324,7 +4308,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        { "n25q256a",    INFO(0x20ba19, 0, 64 * 1024,  512, SECT_4K | SPI_NOR_QUAD_READ) },
        { "n25q512a",    INFO(0x20bb20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
        { "n25q512ax3",  INFO(0x20ba20, 0, 64 * 1024, 1024, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
-@@ -766,6 +899,7 @@
+@@ -772,6 +904,7 @@ static const struct flash_info spi_nor_i
        { "s25fl008k",  INFO(0xef4014,      0,  64 * 1024,  16, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
        { "s25fl016k",  INFO(0xef4015,      0,  64 * 1024,  32, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
        { "s25fl064k",  INFO(0xef4017,      0,  64 * 1024, 128, SECT_4K) },
@@ -4332,7 +4316,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        { "s25fl132k",  INFO(0x014016,      0,  64 * 1024,  64, SECT_4K) },
        { "s25fl164k",  INFO(0x014017,      0,  64 * 1024, 128, SECT_4K) },
        { "s25fl204k",  INFO(0x014013,      0,  64 * 1024,   8, SECT_4K | SPI_NOR_DUAL_READ) },
-@@ -829,11 +963,23 @@
+@@ -835,11 +968,23 @@ static const struct flash_info spi_nor_i
        { "w25x16", INFO(0xef3015, 0, 64 * 1024,  32, SECT_4K) },
        { "w25x32", INFO(0xef3016, 0, 64 * 1024,  64, SECT_4K) },
        { "w25q32", INFO(0xef4016, 0, 64 * 1024,  64, SECT_4K) },
@@ -4359,7 +4343,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        { "w25q80", INFO(0xef5014, 0, 64 * 1024,  16, SECT_4K) },
        { "w25q80bl", INFO(0xef4014, 0, 64 * 1024,  16, SECT_4K) },
        { "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
-@@ -856,7 +1002,7 @@
+@@ -862,7 +1007,7 @@ static const struct flash_info *spi_nor_
  
        tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
        if (tmp < 0) {
@@ -4368,7 +4352,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                return ERR_PTR(tmp);
        }
  
-@@ -867,7 +1013,7 @@
+@@ -873,7 +1018,7 @@ static const struct flash_info *spi_nor_
                                return &spi_nor_ids[tmp];
                }
        }
@@ -4377,7 +4361,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                id[0], id[1], id[2]);
        return ERR_PTR(-ENODEV);
  }
-@@ -1013,6 +1159,8 @@
+@@ -1019,6 +1164,8 @@ static int macronix_quad_enable(struct s
        int ret, val;
  
        val = read_sr(nor);
@@ -4386,7 +4370,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        write_enable(nor);
  
        write_sr(nor, val | SR_QUAD_EN_MX);
-@@ -1094,7 +1242,7 @@
+@@ -1100,7 +1247,7 @@ static int set_quad_mode(struct spi_nor
  static int spi_nor_check(struct spi_nor *nor)
  {
        if (!nor->dev || !nor->read || !nor->write ||
@@ -4395,7 +4379,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                pr_err("spi-nor: please fill all the necessary fields!\n");
                return -EINVAL;
        }
-@@ -1107,7 +1255,7 @@
+@@ -1113,7 +1260,7 @@ int spi_nor_scan(struct spi_nor *nor, co
        const struct flash_info *info = NULL;
        struct device *dev = nor->dev;
        struct mtd_info *mtd = &nor->mtd;
@@ -4404,30 +4388,15 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int ret;
        int i;
  
-@@ -1157,9 +1305,11 @@
-       if (JEDEC_MFR(info) == SNOR_MFR_ATMEL ||
-           JEDEC_MFR(info) == SNOR_MFR_INTEL ||
-           JEDEC_MFR(info) == SNOR_MFR_MACRONIX ||
--          JEDEC_MFR(info) == SNOR_MFR_SST) {
-+          JEDEC_MFR(info) == SNOR_MFR_SST ||
-+          info->flags & SPI_NOR_HAS_LOCK) {
+@@ -1167,6 +1314,7 @@ int spi_nor_scan(struct spi_nor *nor, co
+           info->flags & SPI_NOR_HAS_LOCK) {
                write_enable(nor);
                write_sr(nor, 0);
 +              spi_nor_wait_till_ready(nor);
        }
  
        if (!mtd->name)
-@@ -1173,7 +1323,8 @@
-       mtd->_read = spi_nor_read;
-       /* NOR protection support for STmicro/Micron chips and similar */
--      if (JEDEC_MFR(info) == SNOR_MFR_MICRON) {
-+      if (JEDEC_MFR(info) == SNOR_MFR_MICRON ||
-+                      info->flags & SPI_NOR_HAS_LOCK) {
-               nor->flash_lock = stm_lock;
-               nor->flash_unlock = stm_unlock;
-               nor->flash_is_locked = stm_is_locked;
-@@ -1193,6 +1344,8 @@
+@@ -1201,6 +1349,8 @@ int spi_nor_scan(struct spi_nor *nor, co
  
        if (info->flags & USE_FSR)
                nor->flags |= SNOR_F_USE_FSR;
@@ -4436,7 +4405,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
  #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
        /* prefer "small sector" erase if possible */
-@@ -1295,6 +1448,12 @@
+@@ -1303,6 +1453,12 @@ int spi_nor_scan(struct spi_nor *nor, co
                nor->addr_width = 3;
        }
  
@@ -4451,7 +4420,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        dev_info(dev, "%s (%lld Kbytes)\n", info->name,
 --- a/drivers/mtd/tests/mtd_nandecctest.c
 +++ b/drivers/mtd/tests/mtd_nandecctest.c
-@@ -187,7 +187,7 @@
+@@ -187,7 +187,7 @@ static int double_bit_error_detect(void
        __nand_calculate_ecc(error_data, size, calc_ecc);
        ret = __nand_correct_data(error_data, error_ecc, calc_ecc, size);
  
@@ -4462,7 +4431,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  static const struct nand_ecc_test nand_ecc_test[] = {
 --- a/drivers/mtd/tests/oobtest.c
 +++ b/drivers/mtd/tests/oobtest.c
-@@ -215,19 +215,19 @@
+@@ -215,19 +215,19 @@ static int verify_eraseblock(int ebnum)
                        pr_info("ignoring error as within bitflip_limit\n");
                }
  
@@ -4485,7 +4454,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                                pr_err("error: readoob failed at %#llx\n",
                                                (long long)addr);
                                errcnt += 1;
-@@ -244,7 +244,7 @@
+@@ -244,7 +244,7 @@ static int verify_eraseblock(int ebnum)
                        /* verify post-(use_offset + use_len) area for 0xff */
                        k = use_offset + use_len;
                        bitflips += memffshow(addr, k, readbuf + k,
@@ -4494,7 +4463,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
                        if (bitflips > bitflip_limit) {
                                pr_err("error: verify failed at %#llx\n",
-@@ -269,8 +269,8 @@
+@@ -269,8 +269,8 @@ static int verify_eraseblock_in_one_go(i
        struct mtd_oob_ops ops;
        int err = 0;
        loff_t addr = (loff_t)ebnum * mtd->erasesize;
@@ -4505,7 +4474,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        size_t bitflips;
        int i;
  
-@@ -394,8 +394,8 @@
+@@ -394,8 +394,8 @@ static int __init mtd_oobtest_init(void)
                goto out;
  
        use_offset = 0;
@@ -4516,7 +4485,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        vary_offset = 0;
  
        /* First test: write all OOB, read it back and verify */
-@@ -460,8 +460,8 @@
+@@ -460,8 +460,8 @@ static int __init mtd_oobtest_init(void)
  
        /* Write all eraseblocks */
        use_offset = 0;
@@ -4527,7 +4496,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        vary_offset = 1;
        prandom_seed_state(&rnd_state, 5);
  
-@@ -471,8 +471,8 @@
+@@ -471,8 +471,8 @@ static int __init mtd_oobtest_init(void)
  
        /* Check all eraseblocks */
        use_offset = 0;
@@ -4538,7 +4507,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        vary_offset = 1;
        prandom_seed_state(&rnd_state, 5);
        err = verify_all_eraseblocks();
-@@ -480,8 +480,8 @@
+@@ -480,8 +480,8 @@ static int __init mtd_oobtest_init(void)
                goto out;
  
        use_offset = 0;
@@ -4549,7 +4518,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        vary_offset = 0;
  
        /* Fourth test: try to write off end of device */
-@@ -501,7 +501,7 @@
+@@ -501,7 +501,7 @@ static int __init mtd_oobtest_init(void)
        ops.retlen    = 0;
        ops.ooblen    = 1;
        ops.oobretlen = 0;
@@ -4558,7 +4527,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        ops.datbuf    = NULL;
        ops.oobbuf    = writebuf;
        pr_info("attempting to start write past end of OOB\n");
-@@ -521,7 +521,7 @@
+@@ -521,7 +521,7 @@ static int __init mtd_oobtest_init(void)
        ops.retlen    = 0;
        ops.ooblen    = 1;
        ops.oobretlen = 0;
@@ -4567,7 +4536,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        ops.datbuf    = NULL;
        ops.oobbuf    = readbuf;
        pr_info("attempting to start read past end of OOB\n");
-@@ -543,7 +543,7 @@
+@@ -543,7 +543,7 @@ static int __init mtd_oobtest_init(void)
                ops.mode      = MTD_OPS_AUTO_OOB;
                ops.len       = 0;
                ops.retlen    = 0;
@@ -4576,7 +4545,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                ops.oobretlen = 0;
                ops.ooboffs   = 0;
                ops.datbuf    = NULL;
-@@ -563,7 +563,7 @@
+@@ -563,7 +563,7 @@ static int __init mtd_oobtest_init(void)
                ops.mode      = MTD_OPS_AUTO_OOB;
                ops.len       = 0;
                ops.retlen    = 0;
@@ -4585,7 +4554,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                ops.oobretlen = 0;
                ops.ooboffs   = 0;
                ops.datbuf    = NULL;
-@@ -587,7 +587,7 @@
+@@ -587,7 +587,7 @@ static int __init mtd_oobtest_init(void)
                ops.mode      = MTD_OPS_AUTO_OOB;
                ops.len       = 0;
                ops.retlen    = 0;
@@ -4594,7 +4563,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                ops.oobretlen = 0;
                ops.ooboffs   = 1;
                ops.datbuf    = NULL;
-@@ -607,7 +607,7 @@
+@@ -607,7 +607,7 @@ static int __init mtd_oobtest_init(void)
                ops.mode      = MTD_OPS_AUTO_OOB;
                ops.len       = 0;
                ops.retlen    = 0;
@@ -4603,7 +4572,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                ops.oobretlen = 0;
                ops.ooboffs   = 1;
                ops.datbuf    = NULL;
-@@ -638,7 +638,7 @@
+@@ -638,7 +638,7 @@ static int __init mtd_oobtest_init(void)
        for (i = 0; i < ebcnt - 1; ++i) {
                int cnt = 2;
                int pg;
@@ -4612,7 +4581,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                if (bbt[i] || bbt[i + 1])
                        continue;
                addr = (loff_t)(i + 1) * mtd->erasesize - mtd->writesize;
-@@ -673,13 +673,12 @@
+@@ -673,13 +673,12 @@ static int __init mtd_oobtest_init(void)
        for (i = 0; i < ebcnt - 1; ++i) {
                if (bbt[i] || bbt[i + 1])
                        continue;
@@ -4628,7 +4597,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                ops.oobretlen = 0;
                ops.ooboffs   = 0;
                ops.datbuf    = NULL;
-@@ -688,7 +687,7 @@
+@@ -688,7 +687,7 @@ static int __init mtd_oobtest_init(void)
                if (err)
                        goto out;
                if (memcmpshow(addr, readbuf, writebuf,
@@ -4639,7 +4608,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                        errcnt += 1;
 --- a/drivers/mtd/tests/pagetest.c
 +++ b/drivers/mtd/tests/pagetest.c
-@@ -127,13 +127,12 @@
+@@ -127,13 +127,12 @@ static int crosstest(void)
        unsigned char *pp1, *pp2, *pp3, *pp4;
  
        pr_info("crosstest\n");
@@ -4654,181 +4623,9 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        addr0 = 0;
        for (i = 0; i < ebcnt && bbt[i]; ++i)
---- a/drivers/mtd/ubi/cdev.c
-+++ b/drivers/mtd/ubi/cdev.c
-@@ -174,9 +174,9 @@
-       struct ubi_device *ubi = desc->vol->ubi;
-       struct inode *inode = file_inode(file);
-       int err;
--      mutex_lock(&inode->i_mutex);
-+      inode_lock(inode);
-       err = ubi_sync(ubi->ubi_num);
--      mutex_unlock(&inode->i_mutex);
-+      inode_unlock(inode);
-       return err;
- }
---- a/drivers/mtd/ubi/misc.c
-+++ b/drivers/mtd/ubi/misc.c
-@@ -153,3 +153,52 @@
-                       return 0;
-       return 1;
- }
-+
-+/* Normal UBI messages */
-+void ubi_msg(const struct ubi_device *ubi, const char *fmt, ...)
-+{
-+      struct va_format vaf;
-+      va_list args;
-+
-+      va_start(args, fmt);
-+
-+      vaf.fmt = fmt;
-+      vaf.va = &args;
-+
-+      pr_notice(UBI_NAME_STR "%d: %pV\n", ubi->ubi_num, &vaf);
-+
-+      va_end(args);
-+}
-+
-+/* UBI warning messages */
-+void ubi_warn(const struct ubi_device *ubi, const char *fmt, ...)
-+{
-+      struct va_format vaf;
-+      va_list args;
-+
-+      va_start(args, fmt);
-+
-+      vaf.fmt = fmt;
-+      vaf.va = &args;
-+
-+      pr_warn(UBI_NAME_STR "%d warning: %ps: %pV\n",
-+              ubi->ubi_num, __builtin_return_address(0), &vaf);
-+
-+      va_end(args);
-+}
-+
-+/* UBI error messages */
-+void ubi_err(const struct ubi_device *ubi, const char *fmt, ...)
-+{
-+      struct va_format vaf;
-+      va_list args;
-+
-+      va_start(args, fmt);
-+
-+      vaf.fmt = fmt;
-+      vaf.va = &args;
-+
-+      pr_err(UBI_NAME_STR "%d error: %ps: %pV\n",
-+             ubi->ubi_num, __builtin_return_address(0), &vaf);
-+      va_end(args);
-+}
---- a/drivers/mtd/ubi/ubi.h
-+++ b/drivers/mtd/ubi/ubi.h
-@@ -49,15 +49,19 @@
- /* UBI name used for character devices, sysfs, etc */
- #define UBI_NAME_STR "ubi"
-+struct ubi_device;
-+
- /* Normal UBI messages */
--#define ubi_msg(ubi, fmt, ...) pr_notice(UBI_NAME_STR "%d: " fmt "\n", \
--                                       ubi->ubi_num, ##__VA_ARGS__)
-+__printf(2, 3)
-+void ubi_msg(const struct ubi_device *ubi, const char *fmt, ...);
-+
- /* UBI warning messages */
--#define ubi_warn(ubi, fmt, ...) pr_warn(UBI_NAME_STR "%d warning: %s: " fmt "\n", \
--                                      ubi->ubi_num, __func__, ##__VA_ARGS__)
-+__printf(2, 3)
-+void ubi_warn(const struct ubi_device *ubi, const char *fmt, ...);
-+
- /* UBI error messages */
--#define ubi_err(ubi, fmt, ...) pr_err(UBI_NAME_STR "%d error: %s: " fmt "\n", \
--                                    ubi->ubi_num, __func__, ##__VA_ARGS__)
-+__printf(2, 3)
-+void ubi_err(const struct ubi_device *ubi, const char *fmt, ...);
- /* Background thread name pattern */
- #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd"
---- a/drivers/mtd/ubi/wl.c
-+++ b/drivers/mtd/ubi/wl.c
-@@ -628,6 +628,7 @@
-       return __erase_worker(ubi, &wl_wrk);
- }
-+static int ensure_wear_leveling(struct ubi_device *ubi, int nested);
- /**
-  * wear_leveling_worker - wear-leveling worker function.
-  * @ubi: UBI device description object
-@@ -649,6 +650,7 @@
- #endif
-       struct ubi_wl_entry *e1, *e2;
-       struct ubi_vid_hdr *vid_hdr;
-+      int dst_leb_clean = 0;
-       kfree(wrk);
-       if (shutdown)
-@@ -753,6 +755,7 @@
-       err = ubi_io_read_vid_hdr(ubi, e1->pnum, vid_hdr, 0);
-       if (err && err != UBI_IO_BITFLIPS) {
-+              dst_leb_clean = 1;
-               if (err == UBI_IO_FF) {
-                       /*
-                        * We are trying to move PEB without a VID header. UBI
-@@ -798,10 +801,12 @@
-                        * protection queue.
-                        */
-                       protect = 1;
-+                      dst_leb_clean = 1;
-                       goto out_not_moved;
-               }
-               if (err == MOVE_RETRY) {
-                       scrubbing = 1;
-+                      dst_leb_clean = 1;
-                       goto out_not_moved;
-               }
-               if (err == MOVE_TARGET_BITFLIPS || err == MOVE_TARGET_WR_ERR ||
-@@ -827,6 +832,7 @@
-                                       ubi->erroneous_peb_count);
-                               goto out_error;
-                       }
-+                      dst_leb_clean = 1;
-                       erroneous = 1;
-                       goto out_not_moved;
-               }
-@@ -897,15 +903,24 @@
-               wl_tree_add(e1, &ubi->scrub);
-       else
-               wl_tree_add(e1, &ubi->used);
-+      if (dst_leb_clean) {
-+              wl_tree_add(e2, &ubi->free);
-+              ubi->free_count++;
-+      }
-+
-       ubi_assert(!ubi->move_to_put);
-       ubi->move_from = ubi->move_to = NULL;
-       ubi->wl_scheduled = 0;
-       spin_unlock(&ubi->wl_lock);
-       ubi_free_vid_hdr(ubi, vid_hdr);
--      err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
--      if (err)
--              goto out_ro;
-+      if (dst_leb_clean) {
-+              ensure_wear_leveling(ubi, 1);
-+      } else {
-+              err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
-+              if (err)
-+                      goto out_ro;
-+      }
-       mutex_unlock(&ubi->move_mutex);
-       return 0;
 --- a/include/linux/mtd/bbm.h
 +++ b/include/linux/mtd/bbm.h
-@@ -166,7 +166,6 @@
+@@ -166,7 +166,6 @@ struct bbm_info {
  };
  
  /* OneNAND BBT interface */
@@ -4865,7 +4662,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        uint8_t tar;
 --- a/include/linux/mtd/inftl.h
 +++ b/include/linux/mtd/inftl.h
-@@ -44,7 +44,6 @@
+@@ -44,7 +44,6 @@ struct INFTLrecord {
        unsigned int nb_blocks;         /* number of physical blocks */
        unsigned int nb_boot_blocks;    /* number of blocks used by the bios */
        struct erase_info instr;
@@ -4885,7 +4682,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  static inline int map_bankwidth(void *map)
  {
        BUG();
-@@ -238,8 +240,11 @@
+@@ -238,8 +240,11 @@ struct map_info {
           If there is no cache to care about this can be set to NULL. */
        void (*inval_cache)(struct map_info *, unsigned long, ssize_t);
  
@@ -4901,7 +4698,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        unsigned long pfow_base;
 --- a/include/linux/mtd/mtd.h
 +++ b/include/linux/mtd/mtd.h
-@@ -100,17 +100,35 @@
+@@ -100,17 +100,35 @@ struct mtd_oob_ops {
  
  #define MTD_MAX_OOBFREE_ENTRIES_LARGE 32
  #define MTD_MAX_ECCPOS_ENTRIES_LARGE  640
@@ -4946,7 +4743,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  };
  
  struct module;        /* only needed for owner field in mtd_info */
-@@ -171,8 +189,8 @@
+@@ -171,8 +189,8 @@ struct mtd_info {
        const char *name;
        int index;
  
@@ -4957,7 +4754,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* the ecc step size. */
        unsigned int ecc_step_size;
-@@ -258,6 +276,46 @@
+@@ -258,6 +276,46 @@ struct mtd_info {
        int usecount;
  };
  
@@ -5006,7 +4803,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
              void **virt, resource_size_t *phys);
 --- a/include/linux/mtd/nand.h
 +++ b/include/linux/mtd/nand.h
-@@ -119,6 +119,12 @@
+@@ -119,6 +119,12 @@ typedef enum {
        NAND_ECC_SOFT_BCH,
  } nand_ecc_modes_t;
  
@@ -5019,7 +4816,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  /*
   * Constants for Hardware ECC
   */
-@@ -129,6 +135,14 @@
+@@ -129,6 +135,14 @@ typedef enum {
  /* Enable Hardware ECC before syndrome is read back from flash */
  #define NAND_ECC_READSYN      2
  
@@ -5034,7 +4831,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  /* Bit mask for flags passed to do_nand_read_ecc */
  #define NAND_GET_DEVICE               0x80
  
-@@ -160,6 +174,12 @@
+@@ -160,6 +174,12 @@ typedef enum {
  /* Device supports subpage reads */
  #define NAND_SUBPAGE_READ     0x00001000
  
@@ -5047,7 +4844,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  /* Options valid for Samsung large page devices */
  #define NAND_SAMSUNG_LP_OPTIONS NAND_CACHEPRG
  
-@@ -276,15 +296,15 @@
+@@ -276,15 +296,15 @@ struct nand_onfi_params {
        __le16 t_r;
        __le16 t_ccs;
        __le16 src_sync_timing_mode;
@@ -5066,7 +4863,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* vendor */
        __le16 vendor_revision;
-@@ -407,7 +427,7 @@
+@@ -407,7 +427,7 @@ struct nand_jedec_params {
        __le16 input_pin_capacitance_typ;
        __le16 clk_pin_capacitance_typ;
        u8 driver_strength_support;
@@ -5075,7 +4872,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        u8 reserved4[36];
  
        /* ECC and endurance block */
-@@ -444,6 +464,7 @@
+@@ -444,6 +464,7 @@ struct nand_hw_control {
  /**
   * struct nand_ecc_ctrl - Control structure for ECC
   * @mode:     ECC mode
@@ -5083,7 +4880,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * @steps:    number of ECC steps per page
   * @size:     data bytes per ECC step
   * @bytes:    ECC bytes per step
-@@ -451,12 +472,18 @@
+@@ -451,12 +472,18 @@ struct nand_hw_control {
   * @total:    total number of ECC bytes per page
   * @prepad:   padding information for syndrome based ECC generators
   * @postpad:  padding information for syndrome based ECC generators
@@ -5104,7 +4901,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * @read_page_raw:    function to read a raw page without ECC. This function
   *                    should hide the specific layout used by the ECC
   *                    controller and always return contiguous in-band and
-@@ -487,6 +514,7 @@
+@@ -487,6 +514,7 @@ struct nand_hw_control {
   */
  struct nand_ecc_ctrl {
        nand_ecc_modes_t mode;
@@ -5112,7 +4909,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int steps;
        int size;
        int bytes;
-@@ -494,7 +522,7 @@
+@@ -494,7 +522,7 @@ struct nand_ecc_ctrl {
        int strength;
        int prepad;
        int postpad;
@@ -5121,7 +4918,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        void *priv;
        void (*hwctl)(struct mtd_info *mtd, int mode);
        int (*calculate)(struct mtd_info *mtd, const uint8_t *dat,
-@@ -540,11 +568,11 @@
+@@ -540,11 +568,11 @@ struct nand_buffers {
  
  /**
   * struct nand_chip - NAND Private Flash Chip Data
@@ -5134,7 +4931,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * @read_byte:                [REPLACEABLE] read one byte from the chip
   * @read_word:                [REPLACEABLE] read one word from the chip
   * @write_byte:               [REPLACEABLE] write a single byte to the chip on the
-@@ -640,18 +668,17 @@
+@@ -640,18 +668,17 @@ struct nand_buffers {
   */
  
  struct nand_chip {
@@ -5155,7 +4952,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
        void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
        int (*dev_ready)(struct mtd_info *mtd);
-@@ -719,6 +746,40 @@
+@@ -719,6 +746,40 @@ struct nand_chip {
        void *priv;
  };
  
@@ -5196,7 +4993,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  /*
   * NAND Flash Manufacturer ID Codes
   */
-@@ -850,7 +911,6 @@
+@@ -850,7 +911,6 @@ extern int nand_do_read(struct mtd_info
   * @chip_delay:               R/B delay value in us
   * @options:          Option flags, e.g. 16bit buswidth
   * @bbt_options:      BBT option flags, e.g. NAND_BBT_USE_FLASH
@@ -5204,7 +5001,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * @part_probe_types: NULL-terminated array of probe types
   */
  struct platform_nand_chip {
-@@ -858,7 +918,6 @@
+@@ -858,7 +918,6 @@ struct platform_nand_chip {
        int chip_offset;
        int nr_partitions;
        struct mtd_partition *partitions;
@@ -5212,7 +5009,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        int chip_delay;
        unsigned int options;
        unsigned int bbt_options;
-@@ -908,15 +967,6 @@
+@@ -908,15 +967,6 @@ struct platform_nand_data {
        struct platform_nand_ctrl ctrl;
  };
  
@@ -5230,7 +5027,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  {
 --- a/include/linux/mtd/nand_bch.h
 +++ b/include/linux/mtd/nand_bch.h
-@@ -32,9 +32,7 @@
+@@ -32,9 +32,7 @@ int nand_bch_correct_data(struct mtd_inf
  /*
   * Initialize BCH encoder/decoder
   */
@@ -5241,7 +5038,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  /*
   * Release BCH encoder/decoder resources
   */
-@@ -55,12 +53,10 @@
+@@ -55,12 +53,10 @@ static inline int
  nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
                      unsigned char *read_ecc, unsigned char *calc_ecc)
  {
@@ -5258,7 +5055,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  }
 --- a/include/linux/mtd/nftl.h
 +++ b/include/linux/mtd/nftl.h
-@@ -50,7 +50,6 @@
+@@ -50,7 +50,6 @@ struct NFTLrecord {
          unsigned int nb_blocks;               /* number of physical blocks */
          unsigned int nb_boot_blocks;  /* number of blocks used by the bios */
          struct erase_info instr;
@@ -5268,7 +5065,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  int NFTL_mount(struct NFTLrecord *s);
 --- a/include/linux/mtd/onenand.h
 +++ b/include/linux/mtd/onenand.h
-@@ -80,7 +80,6 @@
+@@ -80,7 +80,6 @@ struct onenand_bufferram {
   * @page_buf:         [INTERN] page main data buffer
   * @oob_buf:          [INTERN] page oob data buffer
   * @subpagesize:      [INTERN] holds the subpagesize
@@ -5276,7 +5073,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
   * @bbm:              [REPLACEABLE] pointer to Bad Block Management
   * @priv:             [OPTIONAL] pointer to private chip date
   */
-@@ -134,7 +133,6 @@
+@@ -134,7 +133,6 @@ struct onenand_chip {
  #endif
  
        int                     subpagesize;
@@ -5286,7 +5083,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
 --- a/include/linux/mtd/partitions.h
 +++ b/include/linux/mtd/partitions.h
-@@ -42,7 +42,6 @@
+@@ -42,7 +42,6 @@ struct mtd_partition {
        uint64_t size;                  /* partition size */
        uint64_t offset;                /* offset within the master MTD space */
        uint32_t mask_flags;            /* master MTD flags to mask out for this partition */
@@ -5294,7 +5091,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  };
  
  #define MTDPART_OFS_RETAIN    (-3)
-@@ -56,11 +55,9 @@
+@@ -56,11 +55,9 @@ struct device_node;
  /**
   * struct mtd_part_parser_data - used to pass data to MTD partition parsers.
   * @origin: for RedBoot, start address of MTD device
@@ -5306,7 +5103,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  };
  
  
-@@ -78,14 +75,34 @@
+@@ -78,14 +75,34 @@ struct mtd_part_parser {
        struct list_head list;
        struct module *owner;
        const char *name;
@@ -5345,7 +5142,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
                      long long offset, long long length);
 --- a/include/linux/mtd/sh_flctl.h
 +++ b/include/linux/mtd/sh_flctl.h
-@@ -143,11 +143,11 @@
+@@ -143,11 +143,11 @@ enum flctl_ecc_res_t {
  struct dma_chan;
  
  struct sh_flctl {
@@ -5358,7 +5155,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        uint8_t done_buff[2048 + 64];   /* max size 2048 + 64 */
        int     read_bytes;
-@@ -186,7 +186,7 @@
+@@ -186,7 +186,7 @@ struct sh_flctl_platform_data {
  
  static inline struct sh_flctl *mtd_to_flctl(struct mtd_info *mtdinfo)
  {
@@ -5380,7 +5177,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  };
 --- a/include/uapi/mtd/mtd-abi.h
 +++ b/include/uapi/mtd/mtd-abi.h
-@@ -228,7 +228,7 @@
+@@ -228,7 +228,7 @@ struct nand_oobfree {
   * complete set of ECC information. The ioctl truncates the larger internal
   * structure to retain binary compatibility with the static declaration of the
   * ioctl. Note that the "MTD_MAX_..._ENTRIES" macros represent the max size of
@@ -5391,7 +5188,16 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        __u32 eccbytes;
 --- a/fs/jffs2/wbuf.c
 +++ b/fs/jffs2/wbuf.c
-@@ -1183,22 +1183,20 @@
+@@ -1153,7 +1153,7 @@ static struct jffs2_sb_info *work_to_sb(
+ {
+       struct delayed_work *dwork;
+-      dwork = container_of(work, struct delayed_work, work);
++      dwork = to_delayed_work(work);
+       return container_of(dwork, struct jffs2_sb_info, wbuf_dwork);
+ }
+@@ -1183,22 +1183,20 @@ void jffs2_dirty_trigger(struct jffs2_sb
  
  int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
  {
@@ -5404,7 +5210,7 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
        c->cleanmarker_size = 0;
  
 -      if (!oinfo || oinfo->oobavail == 0) {
-+      if (c->oobavail == 0) {
++      if (c->mtd->oobavail == 0) {
                pr_err("inconsistent device description\n");
                return -EINVAL;
        }
@@ -5416,3 +5222,65 @@ Signed-off-by: John Crispin <blogic@openwrt.org>
  
        /* Initialise write buffer */
        init_rwsem(&c->wbuf_sem);
+--- a/include/linux/mtd/spi-nor.h
++++ b/include/linux/mtd/spi-nor.h
+@@ -85,6 +85,7 @@
+ #define SR_BP0                        BIT(2)  /* Block protect 0 */
+ #define SR_BP1                        BIT(3)  /* Block protect 1 */
+ #define SR_BP2                        BIT(4)  /* Block protect 2 */
++#define SR_TB                 BIT(5)  /* Top/Bottom protect */
+ #define SR_SRWD                       BIT(7)  /* SR write protect */
+ #define SR_QUAD_EN_MX         BIT(6)  /* Macronix Quad I/O */
+@@ -116,6 +117,7 @@ enum spi_nor_ops {
+ enum spi_nor_option_flags {
+       SNOR_F_USE_FSR          = BIT(0),
++      SNOR_F_HAS_SR_TB        = BIT(1),
+ };
+ /**
+@@ -123,7 +125,6 @@ enum spi_nor_option_flags {
+  * @mtd:              point to a mtd_info structure
+  * @lock:             the lock for the read/write/erase/lock/unlock operations
+  * @dev:              point to a spi device, or a spi nor controller device.
+- * @flash_node:               point to a device node describing this flash instance.
+  * @page_size:                the page size of the SPI NOR
+  * @addr_width:               number of address bytes
+  * @erase_opcode:     the opcode for erasing a sector
+@@ -143,7 +144,8 @@ enum spi_nor_option_flags {
+  * @read:             [DRIVER-SPECIFIC] read data from the SPI NOR
+  * @write:            [DRIVER-SPECIFIC] write data to the SPI NOR
+  * @erase:            [DRIVER-SPECIFIC] erase a sector of the SPI NOR
+- *                    at the offset @offs
++ *                    at the offset @offs; if not provided by the driver,
++ *                    spi-nor will send the erase opcode via write_reg()
+  * @flash_lock:               [FLASH-SPECIFIC] lock a region of the SPI NOR
+  * @flash_unlock:     [FLASH-SPECIFIC] unlock a region of the SPI NOR
+  * @flash_is_locked:  [FLASH-SPECIFIC] check if a region of the SPI NOR is
+@@ -154,7 +156,6 @@ struct spi_nor {
+       struct mtd_info         mtd;
+       struct mutex            lock;
+       struct device           *dev;
+-      struct device_node      *flash_node;
+       u32                     page_size;
+       u8                      addr_width;
+       u8                      erase_opcode;
+@@ -184,6 +185,17 @@ struct spi_nor {
+       void *priv;
+ };
++static inline void spi_nor_set_flash_node(struct spi_nor *nor,
++                                        struct device_node *np)
++{
++      mtd_set_of_node(&nor->mtd, np);
++}
++
++static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor)
++{
++      return mtd_get_of_node(&nor->mtd);
++}
++
+ /**
+  * spi_nor_scan() - scan the SPI NOR
+  * @nor:      the spi_nor structure