Skip to content
Permalink
Browse files

drivers/spi_nor: allow application control of flash layout page size

The driver historically used the erase block size (64 KiBy) as the page
size.  There are other viable "sector" sizes, and for some applications
this one may be too large.  Allow the application to specify the desired
flash page size.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
  • Loading branch information...
pabigot authored and galak committed Jul 20, 2019
1 parent 50550e0 commit eb3858cbbdcd70ffd44762a9a8387b28308c5a08
Showing with 25 additions and 4 deletions.
  1. +9 −0 drivers/flash/Kconfig.nor
  2. +16 −4 drivers/flash/spi_nor.c
@@ -26,6 +26,15 @@ config SPI_NOR_CS_WAIT_DELAY
help
This is the wait delay (in us) to allow for CS switching to take effect

config SPI_NOR_FLASH_LAYOUT_PAGE_SIZE
int "Page size to use for FLASH_LAYOUT feature"
default 65536
help
When CONFIG_FLASH_PAGE_LAYOUT is used this driver will support
that API. By default the page size corresponds to the block
size (65536). Other options include the 32K-byte erase size
(32768), and the sector size (4096).

config SPI_NOR_PAGE_SIZE
int "Page size of SPI flash"
default 0
@@ -358,14 +358,26 @@ static int spi_nor_init(struct device *dev)
}

#if defined(CONFIG_FLASH_PAGE_LAYOUT)

/* instance 0 size in bytes */
#define INST_0_BYTES (DT_INST_0_JEDEC_SPI_NOR_SIZE / 8)

/* instance 0 page count */
#define LAYOUT_PAGES_COUNT (INST_0_BYTES / CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE)

BUILD_ASSERT_MSG((CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE * LAYOUT_PAGES_COUNT)
== INST_0_BYTES,
"SPI_NOR_FLASH_LAYOUT_PAGE_SIZE incompatible with flash size");

static const struct flash_pages_layout dev_layout = {
.pages_count = DT_INST_0_JEDEC_SPI_NOR_SIZE / 8 / SPI_NOR_BLOCK_SIZE,
.pages_size = SPI_NOR_BLOCK_SIZE,
.pages_count = LAYOUT_PAGES_COUNT,
.pages_size = CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE,
};
#undef LAYOUT_PAGES_COUNT

static void spi_nor_pages_layout(struct device *dev,
const struct flash_pages_layout **layout,
size_t *layout_size)
const struct flash_pages_layout **layout,
size_t *layout_size)
{
*layout = &dev_layout;
*layout_size = 1;

0 comments on commit eb3858c

Please sign in to comment.
You can’t perform that action at this time.