return 0;
}
+
+static int spi_flash_bank(struct spi_flash *flash, u32 offset)
+{
+ u8 bank_sel;
+ int ret;
+
+ bank_sel = offset / SPI_FLASH_16MB_BOUN;
+
+ ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
+ if (ret) {
+ debug("SF: fail to set bank%d\n", bank_sel);
+ return ret;
+ }
+
+ return 0;
+}
#endif
int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
cmd[0] = flash->erase_cmd;
while (len) {
#ifdef CONFIG_SPI_FLASH_BAR
- u8 bank_sel;
-
- bank_sel = offset / SPI_FLASH_16MB_BOUN;
-
- ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
- if (ret) {
- debug("SF: fail to set bank%d\n", bank_sel);
+ ret = spi_flash_bank(flash, offset);
+ if (ret < 0)
return ret;
- }
#endif
spi_flash_addr(offset, cmd);
cmd[0] = CMD_PAGE_PROGRAM;
for (actual = 0; actual < len; actual += chunk_len) {
#ifdef CONFIG_SPI_FLASH_BAR
- u8 bank_sel;
-
- bank_sel = offset / SPI_FLASH_16MB_BOUN;
-
- ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
- if (ret) {
- debug("SF: fail to set bank%d\n", bank_sel);
+ ret = spi_flash_bank(flash, offset);
+ if (ret < 0)
return ret;
- }
#endif
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);