Skip to content

Commit 4019d17

Browse files
Jordan Yatesdleach02
authored andcommitted
flash: spi_nor: different wait_until_ready delays
Provide different loop delays to `wait_until_ready` based upon the operation that we are waiting for. Signed-off-by: Jordan Yates <[email protected]>
1 parent a7ba06b commit 4019d17

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

drivers/flash/spi_nor.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ static const struct jesd216_erase_type minimal_erase_types[JESD216_NUM_ERASE_TYP
186186
};
187187
#endif /* CONFIG_SPI_NOR_SFDP_MINIMAL */
188188

189+
/* Register writes should be ready extremely quickly */
190+
#define WAIT_READY_REGISTER K_NO_WAIT
191+
/* Page writes range from sub-ms to 10ms */
192+
#define WAIT_READY_WRITE K_TICKS(1)
193+
/* Erases can range from 45ms to 240sec */
194+
#define WAIT_READY_ERASE K_MSEC(50)
195+
189196
static int spi_nor_write_protection_set(const struct device *dev,
190197
bool write_protect);
191198

@@ -395,9 +402,10 @@ static int spi_nor_access(const struct device *const dev,
395402
* in the code.
396403
*
397404
* @param dev The device structure
405+
* @param poll_delay Duration between polls of status register
398406
* @return 0 on success, negative errno code otherwise
399407
*/
400-
static int spi_nor_wait_until_ready(const struct device *dev)
408+
static int spi_nor_wait_until_ready(const struct device *dev, k_timeout_t poll_delay)
401409
{
402410
int ret;
403411
uint8_t reg;
@@ -412,7 +420,7 @@ static int spi_nor_wait_until_ready(const struct device *dev)
412420
}
413421
#ifdef CONFIG_SPI_NOR_SLEEP_WHILE_WAITING_UNTIL_READY
414422
/* Don't monopolise the CPU while waiting for ready */
415-
k_sleep(K_TICKS(1));
423+
k_sleep(poll_delay);
416424
#endif /* CONFIG_SPI_NOR_SLEEP_WHILE_WAITING_UNTIL_READY */
417425
}
418426
return ret;
@@ -567,7 +575,7 @@ static int spi_nor_wrsr(const struct device *dev,
567575
if (ret == 0) {
568576
ret = spi_nor_access(dev, SPI_NOR_CMD_WRSR, NOR_ACCESS_WRITE, 0, &sr,
569577
sizeof(sr));
570-
spi_nor_wait_until_ready(dev);
578+
spi_nor_wait_until_ready(dev, WAIT_READY_REGISTER);
571579
}
572580

573581
return ret;
@@ -635,7 +643,7 @@ static int mxicy_wrcr(const struct device *dev,
635643

636644
ret = spi_nor_access(dev, SPI_NOR_CMD_WRSR, NOR_ACCESS_WRITE, 0, data,
637645
sizeof(data));
638-
spi_nor_wait_until_ready(dev);
646+
spi_nor_wait_until_ready(dev, WAIT_READY_REGISTER);
639647
}
640648

641649
return ret;
@@ -781,7 +789,7 @@ static int spi_nor_write(const struct device *dev, off_t addr,
781789
src = (const uint8_t *)src + to_write;
782790
addr += to_write;
783791

784-
spi_nor_wait_until_ready(dev);
792+
spi_nor_wait_until_ready(dev, WAIT_READY_WRITE);
785793
}
786794
}
787795

@@ -863,7 +871,7 @@ static int spi_nor_erase(const struct device *dev, off_t addr, size_t size)
863871
*/
864872
volatile int xcc_ret =
865873
#endif
866-
spi_nor_wait_until_ready(dev);
874+
spi_nor_wait_until_ready(dev, WAIT_READY_ERASE);
867875
}
868876

869877
int ret2 = spi_nor_write_protection_set(dev, true);
@@ -1248,7 +1256,7 @@ static int spi_nor_configure(const struct device *dev)
12481256
rc = spi_nor_rdsr(dev);
12491257
if (rc > 0 && (rc & SPI_NOR_WIP_BIT)) {
12501258
LOG_WRN("Waiting until flash is ready");
1251-
spi_nor_wait_until_ready(dev);
1259+
spi_nor_wait_until_ready(dev, WAIT_READY_REGISTER);
12521260
}
12531261
release_device(dev);
12541262

0 commit comments

Comments
 (0)