Skip to content

Commit

Permalink
drivers: flash: 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 controller access the flash chip
in a shared mode.

Signed-off-by: Deepti Deshatty <[email protected]>
  • Loading branch information
Deepti Deshatty committed Oct 16, 2023
1 parent 90b9809 commit 800678c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doc/releases/release-notes-3.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Kernel
* Added support for :c:func:`k_spin_trylock`
* Added :c:func:`k_object_is_valid` to check if a kernel object is valid. This replaces
code that has been duplicated throughout the tree.
* Introduced :c:func:`flash_reset` function. This allows to send SPI commands
to flash device for its reset.
Support for extra operations is enabled by
:kconfig:option:`CONFIG_FLASH_RESET`selected by driver.
Architectures
*************
Expand Down Expand Up @@ -352,6 +356,12 @@ Drivers and Sensors
* STM32 QSPI driver now supports Jedec SFDP parameter reading.
* STM32 OSPI driver now supports both Low and High ports of IO manager.

* Introduced new flash API call :c:func:`flash_reset` which calls
:c:func:`send_flash_reset` callback provided by a flash driver. This allows to send
SPI commands to flash device for its reset. Support for extra operations is
enabled by
:kconfig:option:`CONFIG_FLASH_RESET`selected by driver.
* FPGA
* Fuel Gauge
Expand Down
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 device"
default n
help
Enables API for for resetting the flash device to the power on state.

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

#if defined(CONFIG_FLASH_RESET)
static int spi_nor_send_flash_reset(const struct device *dev)
{
int ret = 0;
acquire_device(dev);

ret = spi_nor_cmd_write(dev, SPI_NOR_CMD_RESET_EN);
if (!ret)
ret = spi_nor_cmd_write(dev, SPI_NOR_CMD_RESET_MEM);

release_device(dev);
return ret;
}
#endif

static int spi_nor_write(const struct device *dev, off_t addr,
const void *src,
size_t size)
Expand Down Expand Up @@ -1426,6 +1441,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
32 changes: 32 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 int (*flash_api_send_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_reset send_flash_reset;
#endif
};

/**
Expand Down Expand Up @@ -249,6 +256,31 @@ 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 int flash_reset(const struct device *dev);

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

if (api->send_flash_reset == NULL) {
return -ENOTSUP;
}

return (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 800678c

Please sign in to comment.