mtd: spi-nor: Introduce the concept of bank
authorMiquel Raynal <miquel.raynal@bootlin.com>
Tue, 28 Mar 2023 15:40:58 +0000 (17:40 +0200)
committerTudor Ambarus <tudor.ambarus@linaro.org>
Wed, 29 Mar 2023 10:46:07 +0000 (13:46 +0300)
SPI NOR chips are made of pages, which gathered in small groups make
(erase) sectors. Sectors, gathered together, make banks inside the
chip. Until now, there was only one bank per device supported, but we
are about to introduce support for new chips featuring several banks (up
to 4 so far) where different operations may happen in parallel.

Let's allow describing these additional bank parameters, and let's do
this independently of any other value (like the number of sectors) with
an absolute value.

By default we consider that all chips have a single bank.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Link: https://lore.kernel.org/r/20230328154105.448540-2-miquel.raynal@bootlin.com
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
drivers/mtd/spi-nor/core.c
drivers/mtd/spi-nor/core.h
drivers/mtd/spi-nor/xilinx.c

index 0a78045..7d9ca79 100644 (file)
@@ -2583,6 +2583,7 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
        /* Set SPI NOR sizes. */
        params->writesize = 1;
        params->size = (u64)info->sector_size * info->n_sectors;
+       params->bank_size = div64_u64(params->size, info->n_banks);
        params->page_size = info->page_size;
 
        if (!(info->flags & SPI_NOR_NO_FR)) {
index 2542322..db0e458 100644 (file)
@@ -336,7 +336,8 @@ struct spi_nor_otp {
  * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216
  * Serial Flash Discoverable Parameters (SFDP) tables.
  *
- * @size:              the flash memory density in bytes.
+ * @bank_size:         the flash memory bank density in bytes.
+ * @size:              the total flash memory density in bytes.
  * @writesize          Minimal writable flash unit size. Defaults to 1. Set to
  *                     ECC unit size for ECC-ed flashes.
  * @page_size:         the page size of the SPI NOR flash memory.
@@ -374,6 +375,7 @@ struct spi_nor_otp {
  * @locking_ops:       SPI NOR locking methods.
  */
 struct spi_nor_flash_parameter {
+       u64                             bank_size;
        u64                             size;
        u32                             writesize;
        u32                             page_size;
@@ -435,6 +437,7 @@ struct spi_nor_fixups {
  * @sector_size:    the size listed here is what works with SPINOR_OP_SE, which
  *                  isn't necessarily called a "sector" by the vendor.
  * @n_sectors:      the number of sectors.
+ * @n_banks:        the number of banks.
  * @page_size:      the flash's page size.
  * @addr_nbytes:    number of address bytes to send.
  *
@@ -495,6 +498,7 @@ struct flash_info {
        unsigned sector_size;
        u16 n_sectors;
        u16 page_size;
+       u8 n_banks;
        u8 addr_nbytes;
 
        bool parse_sfdp;
@@ -540,24 +544,26 @@ struct flash_info {
        .id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \
        .id_len = 6
 
-#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors)                     \
+#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors, _n_banks)           \
        .sector_size = (_sector_size),                                  \
        .n_sectors = (_n_sectors),                                      \
-       .page_size = 256
+       .page_size = 256,                                               \
+       .n_banks = (_n_banks)
 
 /* Used when the "_ext_id" is two bytes at most */
 #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors)             \
        SPI_NOR_ID((_jedec_id), (_ext_id)),                             \
-       SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
+       SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),
 
 #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors)            \
        SPI_NOR_ID6((_jedec_id), (_ext_id)),                            \
-       SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
+       SPI_NOR_GEOMETRY((_sector_size), (_n_sectors), 1),
 
 #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes) \
                .sector_size = (_sector_size),                          \
                .n_sectors = (_n_sectors),                              \
                .page_size = (_page_size),                              \
+               .n_banks = 1,                                           \
                .addr_nbytes = (_addr_nbytes),                          \
                .flags = SPI_NOR_NO_ERASE | SPI_NOR_NO_FR,              \
 
index 5723157..7175de8 100644 (file)
@@ -31,6 +31,7 @@
                .sector_size = (8 * (_page_size)),                      \
                .n_sectors = (_n_sectors),                              \
                .page_size = (_page_size),                              \
+               .n_banks = 1,                                           \
                .addr_nbytes = 3,                                       \
                .flags = SPI_NOR_NO_FR