generic: 6.1: backport support for generic spi-nor from SFDP data
authorChristian Marangi <ansuelsmth@gmail.com>
Sat, 2 Mar 2024 14:40:00 +0000 (15:40 +0100)
committerChristian Marangi <ansuelsmth@gmail.com>
Sun, 21 Apr 2024 16:02:40 +0000 (18:02 +0200)
Backport patches for support of generic spi-nor from SFDP data for
kernel 6.1.

Kernel 5.15 have major rework of the info flags and it's not trustable
to backport this amount of changes and expect correct function of it.

All affected patches automatically refreshed using make
target/linux/refresh.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
target/linux/ath79/patches-6.1/400-mtd-nor-support-mtd-name-from-device-tree.patch
target/linux/generic/backport-6.1/410-v6.2-mtd-spi-nor-add-generic-flash-driver.patch [new file with mode: 0644]
target/linux/generic/pending-6.1/402-mtd-spi-nor-write-support-for-minor-aligned-partitions.patch
target/linux/generic/pending-6.1/479-mtd-spi-nor-add-xtx-xt25f128b.patch
target/linux/mediatek/patches-6.1/436-drivers-mtd-spi-nor-Add-calibration-support-for-spi-.patch

index 119868eddb33bb7b8b12f46edd11d4d7c092bf87..ebb240d4ae5e7e289c686929df01bb0255646668 100644 (file)
@@ -10,7 +10,7 @@ Signed-off-by: Abhimanyu Vishwakarma <Abhimanyu.Vishwakarma@imgtec.com>
 
 --- a/drivers/mtd/spi-nor/core.c
 +++ b/drivers/mtd/spi-nor/core.c
-@@ -2942,12 +2942,19 @@ static void spi_nor_set_mtd_info(struct
+@@ -2964,12 +2964,19 @@ static void spi_nor_set_mtd_info(struct
  {
        struct mtd_info *mtd = &nor->mtd;
        struct device *dev = nor->dev;
diff --git a/target/linux/generic/backport-6.1/410-v6.2-mtd-spi-nor-add-generic-flash-driver.patch b/target/linux/generic/backport-6.1/410-v6.2-mtd-spi-nor-add-generic-flash-driver.patch
new file mode 100644 (file)
index 0000000..4978dce
--- /dev/null
@@ -0,0 +1,117 @@
+From 773bbe10449731c9525457873e0c2342e5cf883b Mon Sep 17 00:00:00 2001
+From: Michael Walle <michael@walle.cc>
+Date: Thu, 11 Aug 2022 00:06:53 +0200
+Subject: [PATCH] mtd: spi-nor: add generic flash driver
+
+Our SFDP parsing is everything we need to support all basic operations
+of a flash device. If the flash isn't found in our in-kernel flash
+database, gracefully fall back to a driver described solely by its SFDP
+tables.
+
+Signed-off-by: Michael Walle <michael@walle.cc>
+Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
+Tested-by: Tudor Ambarus <tudor.ambarus@microchip.com>
+Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
+Link: https://lore.kernel.org/r/20220810220654.1297699-7-michael@walle.cc
+---
+ drivers/mtd/spi-nor/core.c | 26 ++++++++++++++++++++++++--
+ drivers/mtd/spi-nor/core.h |  1 +
+ drivers/mtd/spi-nor/sfdp.c | 27 +++++++++++++++++++++++++++
+ 3 files changed, 52 insertions(+), 2 deletions(-)
+
+--- a/drivers/mtd/spi-nor/core.c
++++ b/drivers/mtd/spi-nor/core.c
+@@ -1636,6 +1636,16 @@ static const struct spi_nor_manufacturer
+       &spi_nor_xmc,
+ };
++static const struct flash_info spi_nor_generic_flash = {
++      .name = "spi-nor-generic",
++      /*
++       * JESD216 rev A doesn't specify the page size, therefore we need a
++       * sane default.
++       */
++      .page_size = 256,
++      .parse_sfdp = true,
++};
++
+ static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
+                                                const u8 *id)
+ {
+@@ -1669,6 +1679,14 @@ static const struct flash_info *spi_nor_
+       }
+       info = spi_nor_match_id(nor, id);
++
++      /* Fallback to a generic flash described only by its SFDP data. */
++      if (!info) {
++              ret = spi_nor_check_sfdp_signature(nor);
++              if (!ret)
++                      info = &spi_nor_generic_flash;
++      }
++
+       if (!info) {
+               dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
+                       SPI_NOR_MAX_ID_LEN, id);
+@@ -2105,8 +2123,12 @@ static int spi_nor_select_pp(struct spi_
+  * spi_nor_select_uniform_erase() - select optimum uniform erase type
+  * @map:              the erase map of the SPI NOR
+  * @wanted_size:      the erase type size to search for. Contains the value of
+- *                    info->sector_size or of the "small sector" size in case
+- *                    CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined.
++ *                    info->sector_size, the "small sector" size in case
++ *                    CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined or 0 if
++ *                    there is no information about the sector size. The
++ *                    latter is the case if the flash parameters are parsed
++ *                    solely by SFDP, then the largest supported erase type
++ *                    is selected.
+  *
+  * Once the optimum uniform sector erase command is found, disable all the
+  * other.
+--- a/drivers/mtd/spi-nor/core.h
++++ b/drivers/mtd/spi-nor/core.h
+@@ -708,6 +708,8 @@ int spi_nor_controller_ops_read_reg(stru
+ int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
+                                    const u8 *buf, size_t len);
++int spi_nor_check_sfdp_signature(struct spi_nor *nor);
++
+ static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
+ {
+       return container_of(mtd, struct spi_nor, mtd);
+--- a/drivers/mtd/spi-nor/sfdp.c
++++ b/drivers/mtd/spi-nor/sfdp.c
+@@ -1250,6 +1250,33 @@ static void spi_nor_post_sfdp_fixups(str
+ }
+ /**
++ * spi_nor_check_sfdp_signature() - check for a valid SFDP signature
++ * @nor:      pointer to a 'struct spi_nor'
++ *
++ * Used to detect if the flash supports the RDSFDP command as well as the
++ * presence of a valid SFDP table.
++ *
++ * Return: 0 on success, -errno otherwise.
++ */
++int spi_nor_check_sfdp_signature(struct spi_nor *nor)
++{
++      u32 signature;
++      int err;
++
++      /* Get the SFDP header. */
++      err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature),
++                                         &signature);
++      if (err < 0)
++              return err;
++
++      /* Check the SFDP signature. */
++      if (le32_to_cpu(signature) != SFDP_SIGNATURE)
++              return -EINVAL;
++
++      return 0;
++}
++
++/**
+  * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters.
+  * @nor:              pointer to a 'struct spi_nor'
+  *
index c7da2f883435fe7f694e7e8d7e5450d2d4adec83..66a6feff6065f6b1fed31ff44ad2381c5272ad29 100644 (file)
@@ -202,7 +202,7 @@ Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
        return !!nor->params->erase_map.uniform_erase_type;
  }
  
-@@ -2158,6 +2160,7 @@ static int spi_nor_select_erase(struct s
+@@ -2180,6 +2182,7 @@ static int spi_nor_select_erase(struct s
  {
        struct spi_nor_erase_map *map = &nor->params->erase_map;
        const struct spi_nor_erase_type *erase = NULL;
@@ -210,7 +210,7 @@ Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
        struct mtd_info *mtd = &nor->mtd;
        u32 wanted_size = nor->info->sector_size;
        int i;
-@@ -2190,8 +2193,9 @@ static int spi_nor_select_erase(struct s
+@@ -2212,8 +2215,9 @@ static int spi_nor_select_erase(struct s
         */
        for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
                if (map->erase_type[i].size) {
@@ -222,7 +222,7 @@ Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
                }
        }
  
-@@ -2199,6 +2203,9 @@ static int spi_nor_select_erase(struct s
+@@ -2221,6 +2225,9 @@ static int spi_nor_select_erase(struct s
                return -EINVAL;
  
        mtd->erasesize = erase->size;
index d2a9fb34365d7ffdcaf2e2d6afd54e1d250940f9..371f1a72769412adfd9559eb79292ac640eeccd8 100644 (file)
@@ -68,7 +68,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
 +      &spi_nor_xtx,
  };
  
- static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
+ static const struct flash_info spi_nor_generic_flash = {
 --- a/drivers/mtd/spi-nor/core.h
 +++ b/drivers/mtd/spi-nor/core.h
 @@ -633,6 +633,7 @@ extern const struct spi_nor_manufacturer
index 1f747d1f4fd696dedad64d485f2f9b6c95b057b8..ac8a55e1879e7d6571433c229b697ccb53009cea 100644 (file)
@@ -26,7 +26,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
  
 --- a/drivers/mtd/spi-nor/core.c
 +++ b/drivers/mtd/spi-nor/core.c
-@@ -2900,6 +2900,18 @@ static const struct flash_info *spi_nor_
+@@ -2922,6 +2922,18 @@ static const struct flash_info *spi_nor_
        return NULL;
  }
  
@@ -45,7 +45,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
  static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
                                                       const char *name)
  {
-@@ -3003,6 +3015,9 @@ int spi_nor_scan(struct spi_nor *nor, co
+@@ -3025,6 +3037,9 @@ int spi_nor_scan(struct spi_nor *nor, co
        if (!nor->bouncebuf)
                return -ENOMEM;