Commit 51983b7d authored by Brian Norris's avatar Brian Norris

mtd: spi-nor: eliminate duplicate spi_nor_wait_till_{, fsr}_ready() code

These functions were near-carbon-copies due to a small per-flash quirk.
Let's add a new spi_nor::flags bitfield to support these types of
quirks.
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
Reviewed-by: default avatarMarek Vasut <marex@denx.de>
Cc: Graham Moore <grmoore@altera.com>
Cc: Huang Shijie <shijie8@gmail.com>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent e7606446
...@@ -165,48 +165,51 @@ static inline int set_4byte(struct spi_nor *nor, u32 jedec_id, int enable) ...@@ -165,48 +165,51 @@ static inline int set_4byte(struct spi_nor *nor, u32 jedec_id, int enable)
return nor->write_reg(nor, SPINOR_OP_BRWR, nor->cmd_buf, 1, 0); return nor->write_reg(nor, SPINOR_OP_BRWR, nor->cmd_buf, 1, 0);
} }
} }
static inline int spi_nor_sr_ready(struct spi_nor *nor)
static int spi_nor_wait_till_ready(struct spi_nor *nor)
{ {
unsigned long deadline; int sr = read_sr(nor);
int sr; if (sr < 0)
return sr;
deadline = jiffies + MAX_READY_WAIT_JIFFIES; else
return !(sr & SR_WIP);
do { }
cond_resched();
sr = read_sr(nor); static inline int spi_nor_fsr_ready(struct spi_nor *nor)
if (sr < 0) {
break; int fsr = read_fsr(nor);
else if (!(sr & SR_WIP)) if (fsr < 0)
return 0; return fsr;
} while (!time_after_eq(jiffies, deadline)); else
return fsr & FSR_READY;
}
return -ETIMEDOUT; static int spi_nor_ready(struct spi_nor *nor)
{
int sr, fsr;
sr = spi_nor_sr_ready(nor);
if (sr < 0)
return sr;
fsr = nor->flags & SNOR_F_USE_FSR ? spi_nor_fsr_ready(nor) : 1;
if (fsr < 0)
return fsr;
return sr && fsr;
} }
static int spi_nor_wait_till_fsr_ready(struct spi_nor *nor) static int spi_nor_wait_till_ready(struct spi_nor *nor)
{ {
unsigned long deadline; unsigned long deadline;
int sr; int ret;
int fsr;
deadline = jiffies + MAX_READY_WAIT_JIFFIES; deadline = jiffies + MAX_READY_WAIT_JIFFIES;
do { do {
cond_resched(); cond_resched();
sr = read_sr(nor); ret = spi_nor_ready(nor);
if (sr < 0) { if (ret < 0)
break; return ret;
} else if (!(sr & SR_WIP)) { if (ret)
fsr = read_fsr(nor); return 0;
if (fsr < 0)
break;
if (fsr & FSR_READY)
return 0;
}
} while (!time_after_eq(jiffies, deadline)); } while (!time_after_eq(jiffies, deadline));
return -ETIMEDOUT; return -ETIMEDOUT;
...@@ -986,9 +989,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) ...@@ -986,9 +989,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode)
else else
mtd->_write = spi_nor_write; mtd->_write = spi_nor_write;
if ((info->flags & USE_FSR) && if (info->flags & USE_FSR)
nor->wait_till_ready == spi_nor_wait_till_ready) nor->flags |= SNOR_F_USE_FSR;
nor->wait_till_ready = spi_nor_wait_till_fsr_ready;
#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS #ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
/* prefer "small sector" erase if possible */ /* prefer "small sector" erase if possible */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment