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 18, 2023
1 parent 90b9809 commit 7048e48
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions drivers/flash/spi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,33 @@ 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 = 0;

ARG_UNUSED(in);
ARG_UNUSED(out);

acquire_device(dev);

switch (code) {
case FLASH_SPI_NOR_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 +1453,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
8 changes: 8 additions & 0 deletions drivers/flash/spi_nor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
#ifndef __SPI_NOR_H__
#define __SPI_NOR_H__

#include <zephyr/drivers/flash.h>
#include <zephyr/sys/util.h>

enum flash_spi_nor_ops {
/*
* Sends Flash reset SPI commands to reset the flash device.
*/
FLASH_SPI_NOR_RESET = FLASH_EX_OP_VENDOR_BASE,
};

#define SPI_NOR_MAX_ID_LEN 3

/* Status register bits */
Expand Down

0 comments on commit 7048e48

Please sign in to comment.