diff --git a/doc/releases/release-notes-3.5.rst b/doc/releases/release-notes-3.5.rst index ac174f415e21fb0..d920013cef6aad0 100644 --- a/doc/releases/release-notes-3.5.rst +++ b/doc/releases/release-notes-3.5.rst @@ -49,6 +49,10 @@ Stable API changes in this release New APIs in this release ======================== +* 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. Kernel ****** @@ -179,6 +183,12 @@ Drivers and Sensors for better performance. * Added support for Nuvoton NuMaker M46x embedded flash +* Introduced new flash API call :c:func:`flash_reset` which calls + :c:func:`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 diff --git a/drivers/flash/Kconfig b/drivers/flash/Kconfig index 9d2192571f95fb9..e6bcf15b43596f5 100644 --- a/drivers/flash/Kconfig +++ b/drivers/flash/Kconfig @@ -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 diff --git a/drivers/flash/spi_nor.c b/drivers/flash/spi_nor.c index ddfdbd6c81d0d7e..946da0acd38ba54 100644 --- a/drivers/flash/spi_nor.c +++ b/drivers/flash/spi_nor.c @@ -679,6 +679,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) @@ -1351,6 +1366,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 diff --git a/include/zephyr/drivers/flash.h b/include/zephyr/drivers/flash.h index de5e7c2116e0379..595adab0590458b 100644 --- a/include/zephyr/drivers/flash.h +++ b/include/zephyr/drivers/flash.h @@ -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; @@ -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 }; /** @@ -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;