|
|
|
@ -36,9 +36,7 @@ static void spi_flash_write_enable(struct flash_dev *dev) |
|
|
|
|
char cmd[1] = { SPI_FLASH_WRITE_ENABLE }; |
|
|
|
|
struct spi_dev *spi_dev = dev->priv; |
|
|
|
|
|
|
|
|
|
spi_set_cs_level(spi_dev, 0); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, cmd, sizeof cmd); |
|
|
|
|
spi_set_cs_level(spi_dev, 1); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, 0, cmd, sizeof cmd); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void spi_flash_write_disable(struct flash_dev *dev) |
|
|
|
@ -46,23 +44,19 @@ static void spi_flash_write_disable(struct flash_dev *dev) |
|
|
|
|
char cmd[1] = { SPI_FLASH_WRITE_DISABLE }; |
|
|
|
|
struct spi_dev *spi_dev = dev->priv; |
|
|
|
|
|
|
|
|
|
spi_set_cs_level(spi_dev, 0); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, cmd, sizeof cmd); |
|
|
|
|
spi_set_cs_level(spi_dev, 1); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, 0, cmd, sizeof cmd); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static size_t spi_flash_get_jedec_id(struct flash_dev *dev, uint8_t *jedec_id, |
|
|
|
|
size_t len) |
|
|
|
|
{ |
|
|
|
|
uint8_t cmd[5] = { SPI_FLASH_JEDEC_ID, 0, 0, 0, 0 }; |
|
|
|
|
uint8_t buf[5]; |
|
|
|
|
uint8_t cmd[1] = { SPI_FLASH_JEDEC_ID }; |
|
|
|
|
uint8_t buf[6]; |
|
|
|
|
struct spi_dev *spi_dev = dev->priv; |
|
|
|
|
|
|
|
|
|
spi_set_cs_level(spi_dev, 0); |
|
|
|
|
spi_tx_rx(spi_dev, buf, cmd, sizeof cmd); |
|
|
|
|
spi_set_cs_level(spi_dev, 1); |
|
|
|
|
spi_tx_rx(spi_dev, buf, sizeof buf, cmd, sizeof cmd); |
|
|
|
|
|
|
|
|
|
memcpy(jedec_id, buf + 1, min(4, len)); |
|
|
|
|
memcpy(jedec_id, buf + 1, min(sizeof buf, len)); |
|
|
|
|
|
|
|
|
|
return len; |
|
|
|
|
} |
|
|
|
@ -87,8 +81,7 @@ static size_t spi_flash_read(struct flash_dev *dev, uint32_t addr, void *data, |
|
|
|
|
spi_flash_addr(cmd, addr); |
|
|
|
|
|
|
|
|
|
spi_set_cs_level(spi_dev, 0); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, cmd, sizeof cmd); |
|
|
|
|
spi_tx_rx(spi_dev, data, NULL, len); |
|
|
|
|
spi_tx_rx(spi_dev, data, len, cmd, sizeof cmd); |
|
|
|
|
spi_set_cs_level(spi_dev, 1); |
|
|
|
|
|
|
|
|
|
return len; |
|
|
|
@ -97,15 +90,17 @@ static size_t spi_flash_read(struct flash_dev *dev, uint32_t addr, void *data, |
|
|
|
|
static size_t spi_flash_write(struct flash_dev *dev, uint32_t addr, |
|
|
|
|
const void *data, size_t len) |
|
|
|
|
{ |
|
|
|
|
char cmd[4] = { SPI_FLASH_PAGE_PROGRAM }; |
|
|
|
|
char cmd[4 + len]; |
|
|
|
|
struct spi_dev *spi_dev = dev->priv; |
|
|
|
|
|
|
|
|
|
spi_flash_write_enable(dev); |
|
|
|
|
|
|
|
|
|
cmd[0] = SPI_FLASH_PAGE_PROGRAM; |
|
|
|
|
spi_flash_addr(cmd, addr); |
|
|
|
|
memcpy(cmd + 4, data, len); |
|
|
|
|
|
|
|
|
|
spi_set_cs_level(spi_dev, 0); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, cmd, sizeof cmd); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, data, len); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, 0, cmd, sizeof cmd); |
|
|
|
|
spi_set_cs_level(spi_dev, 1); |
|
|
|
|
|
|
|
|
|
spi_flash_write_disable(dev); |
|
|
|
@ -124,7 +119,7 @@ static int spi_flash_erase(struct flash_dev *dev, uint32_t addr) |
|
|
|
|
spi_flash_addr(cmd, addr << dev->log2_block_size); |
|
|
|
|
|
|
|
|
|
spi_set_cs_level(spi_dev, 0); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, cmd, sizeof cmd); |
|
|
|
|
spi_tx_rx(spi_dev, NULL, 0, cmd, sizeof cmd); |
|
|
|
|
spi_set_cs_level(spi_dev, 1); |
|
|
|
|
|
|
|
|
|
spi_flash_write_disable(dev); |
|
|
|
|