summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/mtd/spi-nor/spi-nor.c36
1 files changed, 9 insertions, 27 deletions
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index b62d9d00c30e..93cd1043ef4f 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -231,15 +231,8 @@ static int wait_till_ready(struct spi_nor *nor)
231 */ 231 */
232static int erase_chip(struct spi_nor *nor) 232static int erase_chip(struct spi_nor *nor)
233{ 233{
234 int ret;
235
236 dev_dbg(nor->dev, " %lldKiB\n", (long long)(nor->mtd->size >> 10)); 234 dev_dbg(nor->dev, " %lldKiB\n", (long long)(nor->mtd->size >> 10));
237 235
238 /* Wait until finished previous write command. */
239 ret = wait_till_ready(nor);
240 if (ret)
241 return ret;
242
243 /* Send write enable, then erase commands. */ 236 /* Send write enable, then erase commands. */
244 write_enable(nor); 237 write_enable(nor);
245 238
@@ -302,6 +295,10 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
302 goto erase_err; 295 goto erase_err;
303 } 296 }
304 297
298 ret = spi_nor_wait_till_ready(nor);
299 if (ret)
300 goto erase_err;
301
305 /* REVISIT in some cases we could speed up erasing large regions 302 /* REVISIT in some cases we could speed up erasing large regions
306 * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up 303 * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up
307 * to use "small sector erase", but that's not always optimal. 304 * to use "small sector erase", but that's not always optimal.
@@ -317,6 +314,10 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
317 314
318 addr += mtd->erasesize; 315 addr += mtd->erasesize;
319 len -= mtd->erasesize; 316 len -= mtd->erasesize;
317
318 ret = spi_nor_wait_till_ready(nor);
319 if (ret)
320 goto erase_err;
320 } 321 }
321 } 322 }
322 323
@@ -344,11 +345,6 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
344 if (ret) 345 if (ret)
345 return ret; 346 return ret;
346 347
347 /* Wait until finished previous command */
348 ret = wait_till_ready(nor);
349 if (ret)
350 goto err;
351
352 status_old = read_sr(nor); 348 status_old = read_sr(nor);
353 349
354 if (offset < mtd->size - (mtd->size / 2)) 350 if (offset < mtd->size - (mtd->size / 2))
@@ -391,11 +387,6 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
391 if (ret) 387 if (ret)
392 return ret; 388 return ret;
393 389
394 /* Wait until finished previous command */
395 ret = wait_till_ready(nor);
396 if (ret)
397 goto err;
398
399 status_old = read_sr(nor); 390 status_old = read_sr(nor);
400 391
401 if (offset+len > mtd->size - (mtd->size / 64)) 392 if (offset+len > mtd->size - (mtd->size / 64))
@@ -706,11 +697,6 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
706 if (ret) 697 if (ret)
707 return ret; 698 return ret;
708 699
709 /* Wait until finished previous write command. */
710 ret = wait_till_ready(nor);
711 if (ret)
712 goto time_out;
713
714 write_enable(nor); 700 write_enable(nor);
715 701
716 nor->sst_write_second = false; 702 nor->sst_write_second = false;
@@ -782,11 +768,6 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
782 if (ret) 768 if (ret)
783 return ret; 769 return ret;
784 770
785 /* Wait until finished previous write command. */
786 ret = wait_till_ready(nor);
787 if (ret)
788 goto write_err;
789
790 write_enable(nor); 771 write_enable(nor);
791 772
792 page_offset = to & (nor->page_size - 1); 773 page_offset = to & (nor->page_size - 1);
@@ -815,6 +796,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
815 } 796 }
816 } 797 }
817 798
799 ret = spi_nor_wait_till_ready(nor);
818write_err: 800write_err:
819 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE); 801 spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_WRITE);
820 return ret; 802 return ret;