Skip to content

Commit

Permalink
driver:flash:spi_nor: provide api to reset the flash registers
Browse files Browse the repository at this point in the history
changes enable flash driver to provide api interface to send reset memory
spi command to the spi flash. The reset memory command would bring the
spi flash to its default power-on state and loose all the volatile register
settings.
Flash reset is needed when more than one master access the flash chip
in a shared mode.

Signed-off-by: Deepti Deshatty <[email protected]>
  • Loading branch information
Deepti Deshatty committed Oct 13, 2023
1 parent 96bc04f commit 869dd8a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/flash/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ config FLASH_PAGE_LAYOUT
help
Enables API for retrieving the layout of flash memory pages.

config FLASH_RESET
bool "API for resetting the flash registers"
default n
help
Enables API for for resetting the flash registers to default power on state.

config FLASH_EX_OP_ENABLED
bool "API for extended flash operations"
depends on FLASH_HAS_EX_OP
Expand Down
15 changes: 15 additions & 0 deletions drivers/flash/spi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,18 @@ static int spi_nor_read(const struct device *dev, off_t addr, void *dest,
return ret;
}

#if defined(CONFIG_FLASH_RESET)
static void spi_nor_send_flash_reset(const struct device *dev)
{
acquire_device(dev);

spi_nor_cmd_write(dev, SPI_NOR_CMD_RESET_EN);
spi_nor_cmd_write(dev, SPI_NOR_CMD_RESET_MEM);

release_device(dev);
}
#endif

static int spi_nor_write(const struct device *dev, off_t addr,
const void *src,
size_t size)
Expand Down Expand Up @@ -1351,6 +1363,9 @@ static const struct flash_driver_api spi_nor_api = {
.sfdp_read = spi_nor_sfdp_read,
.read_jedec_id = spi_nor_read_jedec_id,
#endif
#if defined(CONFIG_FLASH_RESET)
.send_flash_reset = spi_nor_send_flash_reset,
#endif
};

#ifndef CONFIG_SPI_NOR_SFDP_RUNTIME
Expand Down
28 changes: 28 additions & 0 deletions include/zephyr/drivers/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ typedef int (*flash_api_read_jedec_id)(const struct device *dev, uint8_t *id);
typedef int (*flash_api_ex_op)(const struct device *dev, uint16_t code,
const uintptr_t in, void *out);

#if defined(CONFIG_FLASH_RESET)
typedef void (*flash_api_send_flash_reset)(const struct device *dev);
#endif

__subsystem struct flash_driver_api {
flash_api_read read;
flash_api_write write;
Expand All @@ -143,6 +147,9 @@ __subsystem struct flash_driver_api {
#if defined(CONFIG_FLASH_EX_OP_ENABLED)
flash_api_ex_op ex_op;
#endif /* CONFIG_FLASH_EX_OP_ENABLED */
#if defined(CONFIG_FLASH_RESET)
flash_api_send_flash_reset send_flash_reset;
#endif
};

/**
Expand Down Expand Up @@ -249,6 +256,27 @@ static inline int z_impl_flash_erase(const struct device *dev, off_t offset,
return rc;
}

#if defined(CONFIG_FLASH_RESET)
/*
* @brief Send SPI reset command.
*
* This api can be used to reset the SPI flash memory i.e volatile
* register configurations before SPI access.
* Command also aborts any ongoing internal SPI operations.
*
* @param dev : flash dev
*/
__syscall void flash_reset(const struct device *dev);

static inline void z_impl_flash_reset(const struct device *dev)
{
const struct flash_driver_api *api =
(const struct flash_driver_api *)dev->api;

api->send_flash_reset(dev);
}
#endif

struct flash_pages_info {
off_t start_offset; /* offset from the base of flash address */
size_t size;
Expand Down

0 comments on commit 869dd8a

Please sign in to comment.