drivers/memory/spiflash: Add support to put SPI flash in sleep mode.

This commit is contained in:
Damien George 2019-07-03 01:03:25 +10:00
parent caabdd99c0
commit 8cde5faedd
2 changed files with 18 additions and 0 deletions

View File

@ -146,6 +146,10 @@ STATIC int mp_spiflash_wait_wip0(mp_spiflash_t *self) {
return mp_spiflash_wait_sr(self, 1, 0, WAIT_SR_TIMEOUT);
}
static inline void mp_spiflash_deepsleep_internal(mp_spiflash_t *self, int value) {
mp_spiflash_write_cmd(self, value ? 0xb9 : 0xab); // sleep/wake
}
void mp_spiflash_init(mp_spiflash_t *self) {
self->flags = 0;
@ -159,6 +163,9 @@ void mp_spiflash_init(mp_spiflash_t *self) {
mp_spiflash_acquire_bus(self);
// Ensure SPI flash is out of sleep mode
mp_spiflash_deepsleep_internal(self, 0);
#if defined(CHECK_DEVID)
// Validate device id
uint32_t devid = mp_spiflash_read_cmd(self, CMD_RD_DEVID, 3);
@ -182,6 +189,16 @@ void mp_spiflash_init(mp_spiflash_t *self) {
mp_spiflash_release_bus(self);
}
void mp_spiflash_deepsleep(mp_spiflash_t *self, int value) {
if (value) {
mp_spiflash_acquire_bus(self);
}
mp_spiflash_deepsleep_internal(self, value);
if (!value) {
mp_spiflash_release_bus(self);
}
}
STATIC int mp_spiflash_erase_block_internal(mp_spiflash_t *self, uint32_t addr) {
// enable writes
mp_spiflash_write_cmd(self, CMD_WREN);

View File

@ -68,6 +68,7 @@ typedef struct _mp_spiflash_t {
} mp_spiflash_t;
void mp_spiflash_init(mp_spiflash_t *self);
void mp_spiflash_deepsleep(mp_spiflash_t *self, int value);
// These functions go direct to the SPI flash device
int mp_spiflash_erase_block(mp_spiflash_t *self, uint32_t addr);