mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/mtd_spi_nor: power up MTD on init
This commit is contained in:
parent
8a256eba12
commit
61eecf6fe0
@ -54,6 +54,7 @@ static const mtd_spi_nor_params_t mulle_nor_params = {
|
||||
.wait_sector_erase = 40LU * US_PER_MS,
|
||||
.wait_32k_erase = 20LU * US_PER_MS,
|
||||
.wait_4k_erase = 10LU * US_PER_MS,
|
||||
.wait_chip_wake_up = 1LU * US_PER_MS,
|
||||
.spi = MULLE_NOR_SPI_DEV,
|
||||
.cs = MULLE_NOR_SPI_CS,
|
||||
.addr_width = 3,
|
||||
|
@ -36,6 +36,7 @@ static const mtd_spi_nor_params_t _pinetime_nor_params = {
|
||||
.wait_32k_erase = 160LU *US_PER_MS,
|
||||
.wait_sector_erase = 70LU * US_PER_MS,
|
||||
.wait_4k_erase = 70LU * US_PER_MS,
|
||||
.wait_chip_wake_up = 1LU * US_PER_MS,
|
||||
.clk = PINETIME_NOR_SPI_CLK,
|
||||
.flag = PINETIME_NOR_FLAGS,
|
||||
.spi = PINETIME_NOR_SPI_DEV,
|
||||
|
@ -92,6 +92,7 @@ typedef struct {
|
||||
uint32_t wait_sector_erase; /**< Sector erase wait time in µs */
|
||||
uint32_t wait_32k_erase; /**< 32KB page erase wait time in µs */
|
||||
uint32_t wait_4k_erase; /**< 4KB page erase wait time in µs */
|
||||
uint32_t wait_chip_wake_up; /**< Chip wake up time in µs */
|
||||
spi_clk_t clk; /**< SPI clock */
|
||||
uint16_t flag; /**< Config flags */
|
||||
spi_t spi; /**< SPI bus the device is connected to */
|
||||
|
@ -44,6 +44,11 @@
|
||||
#define TRACE(...)
|
||||
#endif
|
||||
|
||||
/* after power up, on an invalid JEDEC ID, wait and read N times */
|
||||
#ifndef MTD_POWER_UP_WAIT_FOR_ID
|
||||
#define MTD_POWER_UP_WAIT_FOR_ID (0x0F)
|
||||
#endif
|
||||
|
||||
#define MTD_32K (32768ul)
|
||||
#define MTD_32K_ADDR_MASK (0x7FFF)
|
||||
#define MTD_4K (4096ul)
|
||||
@ -349,6 +354,13 @@ static int mtd_spi_nor_init(mtd_dev_t *mtd)
|
||||
DEBUG("mtd_spi_nor_init: CS init\n");
|
||||
spi_init_cs(dev->params->spi, dev->params->cs);
|
||||
|
||||
/* power up the MTD device*/
|
||||
DEBUG("mtd_spi_nor_init: power up MTD device");
|
||||
if (mtd_spi_nor_power(mtd, MTD_POWER_UP)) {
|
||||
DEBUG("mtd_spi_nor_init: failed to power up MTD device");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
mtd_spi_acquire(dev);
|
||||
int res = mtd_spi_read_jedec_id(dev, &dev->jedec_id);
|
||||
if (res < 0) {
|
||||
@ -544,6 +556,20 @@ static int mtd_spi_nor_power(mtd_dev_t *mtd, enum mtd_power_state power)
|
||||
switch (power) {
|
||||
case MTD_POWER_UP:
|
||||
mtd_spi_cmd(dev, dev->params->opcode->wake);
|
||||
#if defined(MODULE_XTIMER)
|
||||
/* No sense in trying multiple times if no xtimer to wait between
|
||||
reads */
|
||||
uint8_t retries = 0;
|
||||
int res = 0;
|
||||
do {
|
||||
xtimer_usleep(dev->params->wait_chip_wake_up);
|
||||
res = mtd_spi_read_jedec_id(dev, &dev->jedec_id);
|
||||
retries++;
|
||||
} while (res < 0 || retries < MTD_POWER_UP_WAIT_FOR_ID);
|
||||
if (res < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case MTD_POWER_DOWN:
|
||||
mtd_spi_cmd(dev, dev->params->opcode->sleep);
|
||||
|
Loading…
Reference in New Issue
Block a user