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 20, 2023
1 parent 90b9809 commit 6d0c9e0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/flash/Kconfig.nor
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ menuconfig SPI_NOR
select FLASH_HAS_DRIVER_ENABLED
select FLASH_HAS_PAGE_LAYOUT
select FLASH_JESD216
select FLASH_HAS_EX_OP
select SPI

if SPI_NOR
Expand Down
31 changes: 31 additions & 0 deletions drivers/flash/spi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,34 @@ static int spi_nor_read(const struct device *dev, off_t addr, void *dest,
return ret;
}

#if defined(CONFIG_FLASH_EX_OP_ENABLED)
static int flash_spi_nor_ex_op(const struct device *dev, uint16_t code,
const uintptr_t in, void *out)
{
int ret;

ARG_UNUSED(in);
ARG_UNUSED(out);

acquire_device(dev);

switch (code) {
case FLASH_EX_OP_RESET:
ret = spi_nor_cmd_write(dev, SPI_NOR_CMD_RESET_EN);
if (ret == 0) {
ret = spi_nor_cmd_write(dev, SPI_NOR_CMD_RESET_MEM);
}
break;
default:
ret = -ENOTSUP;
break;
}

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 +1454,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_EX_OP_ENABLED)
.ex_op = flash_spi_nor_ex_op,
#endif
};

#ifndef CONFIG_SPI_NOR_SFDP_RUNTIME
Expand Down
10 changes: 10 additions & 0 deletions include/zephyr/drivers/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,16 @@ __syscall int flash_ex_op(const struct device *dev, uint16_t code,
#define FLASH_EX_OP_VENDOR_BASE 0x8000
#define FLASH_EX_OP_IS_VENDOR(c) ((c) & FLASH_EX_OP_VENDOR_BASE)

/**
* @brief Enumeration for extra flash operations
*/
enum flash_ex_op_types {
/*
* Reset flash device.
*/
FLASH_EX_OP_RESET = 0,
};

static inline int z_impl_flash_ex_op(const struct device *dev, uint16_t code,
const uintptr_t in, void *out)
{
Expand Down

0 comments on commit 6d0c9e0

Please sign in to comment.