|
|
|
@ -33,6 +33,24 @@ static void spi_flash_addr(char *cmd, uint32_t addr) |
|
|
|
|
cmd[3] = addr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static uint8_t spi_flash_get_status1(struct flash_dev *dev) |
|
|
|
|
{ |
|
|
|
|
struct spi_dev *spi_dev = dev->priv; |
|
|
|
|
uint8_t cmd = SPI_FLASH_READ_SR1; |
|
|
|
|
uint8_t ret; |
|
|
|
|
|
|
|
|
|
spi_tx_rx(spi_dev, &ret, sizeof ret, &cmd, sizeof cmd); |
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int spi_flash_wait(struct flash_dev *dev) |
|
|
|
|
{ |
|
|
|
|
while (spi_flash_get_status1(dev) & SPI_FLASH_SR1_BUSY); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void spi_flash_write_enable(struct flash_dev *dev) |
|
|
|
|
{ |
|
|
|
|
char cmd[1] = { SPI_FLASH_WRITE_ENABLE }; |
|
|
|
@ -98,6 +116,7 @@ static size_t spi_flash_write(struct flash_dev *dev, uint32_t addr, |
|
|
|
|
memcpy(cmd + 4, data, len); |
|
|
|
|
|
|
|
|
|
spi_tx_rx(spi_dev, NULL, 0, cmd, sizeof cmd); |
|
|
|
|
spi_flash_wait(dev); |
|
|
|
|
|
|
|
|
|
spi_flash_write_disable(dev); |
|
|
|
|
|
|
|
|
@ -115,6 +134,7 @@ static int spi_flash_erase(struct flash_dev *dev, uint32_t addr) |
|
|
|
|
spi_flash_addr(cmd, addr << dev->log2_block_size); |
|
|
|
|
|
|
|
|
|
spi_tx_rx(spi_dev, NULL, 0, cmd, sizeof cmd); |
|
|
|
|
spi_flash_wait(dev); |
|
|
|
|
|
|
|
|
|
spi_flash_write_disable(dev); |
|
|
|
|
|
|
|
|
|