drivers: flash: spi_nor: support serial flash API

Expose the internal JESD216 function used to read data from the SFDP
region, and another function to read the JEDEC ID.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2020-06-03 19:57:27 -05:00 committed by Anas Nashif
commit 368cf2fc45
2 changed files with 24 additions and 1 deletions

View file

@ -25,6 +25,7 @@ config FLASH_JESD216
config FLASH_JESD216_API
bool "Provide API to read JESD216 flash parameters"
depends on FLASH_JESD216
help
This option extends the Zephyr flash API with the ability
to access the Serial Flash Discoverable Parameter section

View file

@ -304,7 +304,7 @@ static int spi_nor_access(const struct device *const dev,
#define spi_nor_cmd_addr_write(dev, opcode, addr, src, length) \
spi_nor_access(dev, opcode, true, addr, (void *)src, length, true)
#if CONFIG_SPI_NOR_SFDP_RUNTIME
#if defined(CONFIG_SPI_NOR_SFDP_RUNTIME) || defined(CONFIG_FLASH_JESD216_API)
/*
* @brief Read content from the SFDP hierarchy
*
@ -599,6 +599,24 @@ static int spi_nor_write_protection_set(struct device *dev, bool write_protect)
return ret;
}
#if defined(CONFIG_FLASH_JESD216_API)
static int spi_nor_sfdp_read(struct device *dev, off_t addr,
void *dest, size_t size)
{
acquire_device(dev);
spi_nor_wait_until_ready(dev);
int ret = read_sfdp(dev, addr, dest, size);
release_device(dev);
return ret;
}
#endif /* CONFIG_FLASH_JESD216_API */
static int spi_nor_read_jedec_id(struct device *dev,
uint8_t *id)
{
@ -948,6 +966,10 @@ static const struct flash_driver_api spi_nor_api = {
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
.page_layout = spi_nor_pages_layout,
#endif
#if defined(CONFIG_FLASH_JESD216_API)
.sfdp_read = spi_nor_sfdp_read,
.read_jedec_id = spi_nor_read_jedec_id,
#endif
};
#ifndef CONFIG_SPI_NOR_SFDP_RUNTIME