Skip to content

Commit

Permalink
drivers: flash: add a generic spi nor flash driver
Browse files Browse the repository at this point in the history
This driver is inspired from the w25qxxdv SPI NOR flash driver which was
already implementing the CFI (Common Flash Interface) for its purpose.
To handle other NOR flash a flash id table (as Linux do) which contains
the geometry for a few SPI NOR flash based on their JEDEC ID has been
introduced.
We currently support the following flash:
 - W25Q80
 - W25Q16
 - W25Q32
 - S25FL216K
 - MX25UM512

The read and write functions are able to handle more then one page at a
time and return the number of bytes read or write.
Also because every NOR flash expect to disable the write protection
before writing or erasing, the write enable command is now part of the
write and erase functions.

Signed-off-by: Sebastien Bourdelin <[email protected]>
Signed-off-by: Savinay Dharmappa <[email protected]>
  • Loading branch information
SavinayDharmappa authored and nashif committed Nov 13, 2018
1 parent 128fef2 commit 87e5493
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/flash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
zephyr_library()

zephyr_library_sources_ifdef(CONFIG_SPI_NOR spi_nor.c)
zephyr_library_sources_ifdef(CONFIG_SPI_FLASH_W25QXXDV spi_flash_w25qxxdv.c)
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_QMSI soc_flash_qmsi.c)
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_NRF soc_flash_nrf.c)
Expand Down
2 changes: 2 additions & 0 deletions drivers/flash/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ config SOC_FLASH_NIOS2_QSPI_DEV_NAME

source "drivers/flash/Kconfig.gecko"

source "drivers/flash/Kconfig.nor"

source "drivers/flash/Kconfig.qmsi"

source "drivers/flash/Kconfig.stm32"
Expand Down
76 changes: 76 additions & 0 deletions drivers/flash/Kconfig.nor
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# Copyright (c) 2018 Savoir-Faire Linux.
#
# SPDX-License-Identifier: Apache-2.0
#


menuconfig SPI_NOR
bool
prompt "SPI NOR Flash"
select FLASH_HAS_DRIVER_ENABLED
depends on SPI && FLASH

if SPI_NOR

config SPI_NOR_INIT_PRIORITY
int
default 80
help
Device driver initialization priority.
Device is connected to SPI bus, it has to
be initialized after SPI driver.

config SPI_NOR_JEDEC_ID
hex "Unique Id to identify SPI flash"
default 0
help
This is a unique id to identify SPI flash

config SPI_NOR_PAGE_SIZE
int "Page size of SPI flash"
default 0
help
This option specifies page size of SPI flash

config SPI_NOR_SECTOR_SIZE
int "Sector size of SPI flash"
default 0
help
This option specifies sector size of SPI flash

config SPI_NOR_SECTORS
int "Number of sectors in SPI flash"
default 0
help
This option specifies number of sector present
in SPI flash

config SPI_NOR_BLOCK_SIZE
int "Block size of SPI flash"
default 0
help
This option specifies block size of SPI flash

choice SPI_NOR_BLOCK_ERASE_SIZE
prompt "Select Block size for erasing"

config SPI_NOR_BLOCK_ERASE_32K
bool "Select 32K block erase"
help
This Enables 32K Block erase

config SPI_NOR_BLOCK_ERASE_64K
bool "Select 64K block erase"
help
This Enables 64K Block erase

endchoice

config SPI_NOR_BLOCK_ERASE_SIZE
int
default 2 if SPI_NOR_BLOCK_ERASE_32K
default 4 if SPI_NOR_BLOCK_ERASE_64K
help
This option specifies block size of SPI flash
endif # SPI_NOR
Loading

0 comments on commit 87e5493

Please sign in to comment.