diff mbox

[7/8] mtd: spi-nor: factor out write_enable() for erase commands

Message ID 1407374222-8448-8-git-send-email-computersforpeace@gmail.com
State Superseded
Headers show

Commit Message

Brian Norris Aug. 7, 2014, 1:17 a.m. UTC
write_enable() was being duplicated to both m25p80.c and fsl-quadspi.c.
But this should be handled within the spi-nor abstraction layer.

At the same time, let's add write_disable() after erasing, so we don't
leave the flash in a write-enabled state afterward.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 drivers/mtd/devices/m25p80.c      | 5 -----
 drivers/mtd/spi-nor/fsl-quadspi.c | 5 -----
 drivers/mtd/spi-nor/spi-nor.c     | 7 ++++---
 3 files changed, 4 insertions(+), 13 deletions(-)

Comments

Marek Vasut Aug. 7, 2014, 2:25 p.m. UTC | #1
On Thursday, August 07, 2014 at 03:17:01 AM, Brian Norris wrote:
> write_enable() was being duplicated to both m25p80.c and fsl-quadspi.c.
> But this should be handled within the spi-nor abstraction layer.
> 
> At the same time, let's add write_disable() after erasing, so we don't
> leave the flash in a write-enabled state afterward.
> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>

Makes sense, thanks!

Reviewed-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut
Huang Shijie Aug. 9, 2014, 10:52 a.m. UTC | #2
On Wed, Aug 06, 2014 at 06:17:01PM -0700, Brian Norris wrote:
> write_enable() was being duplicated to both m25p80.c and fsl-quadspi.c.
> But this should be handled within the spi-nor abstraction layer.
> 
> At the same time, let's add write_disable() after erasing, so we don't
> leave the flash in a write-enabled state afterward.
> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> ---
>  drivers/mtd/devices/m25p80.c      | 5 -----
>  drivers/mtd/spi-nor/fsl-quadspi.c | 5 -----
>  drivers/mtd/spi-nor/spi-nor.c     | 7 ++++---
>  3 files changed, 4 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> index 96226ea69f90..116d979ffdb9 100644
> --- a/drivers/mtd/devices/m25p80.c
> +++ b/drivers/mtd/devices/m25p80.c
> @@ -158,11 +158,6 @@ static int m25p80_erase(struct spi_nor *nor, loff_t offset)
>  	dev_dbg(nor->dev, "%dKiB at 0x%08x\n",
>  		flash->mtd.erasesize / 1024, (u32)offset);
>  
> -	/* Send write enable, then erase commands. */
> -	ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
> -	if (ret)
> -		return ret;
> -
>  	/* Set up command buffer. */
>  	flash->command[0] = nor->erase_opcode;
>  	m25p_addr2cmd(nor, offset, flash->command);
> diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
> index 9c13622a0c7a..07fbfb0a7738 100644
> --- a/drivers/mtd/spi-nor/fsl-quadspi.c
> +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
> @@ -738,11 +738,6 @@ static int fsl_qspi_erase(struct spi_nor *nor, loff_t offs)
>  	dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n",
>  		nor->mtd->erasesize / 1024, q->chip_base_addr, (u32)offs);
>  
> -	/* Send write enable, then erase commands. */
> -	ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
> -	if (ret)
> -		return ret;
> -
This write-enable is used for per-sector-erase, not for the whole chip
erase.

So if you really want to remove this code, you should add an extra write-enable
in the spi_nor_erase.

thanks
Huang Shijie
Brian Norris Aug. 11, 2014, 6:48 p.m. UTC | #3
On Sat, Aug 09, 2014 at 06:52:34PM +0800, Huang Shijie wrote:
> On Wed, Aug 06, 2014 at 06:17:01PM -0700, Brian Norris wrote:
> > write_enable() was being duplicated to both m25p80.c and fsl-quadspi.c.
> > But this should be handled within the spi-nor abstraction layer.
> > 
> > At the same time, let's add write_disable() after erasing, so we don't
> > leave the flash in a write-enabled state afterward.
> > 
> > Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> > ---
> >  drivers/mtd/devices/m25p80.c      | 5 -----
> >  drivers/mtd/spi-nor/fsl-quadspi.c | 5 -----
> >  drivers/mtd/spi-nor/spi-nor.c     | 7 ++++---
> >  3 files changed, 4 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> > index 96226ea69f90..116d979ffdb9 100644
> > --- a/drivers/mtd/devices/m25p80.c
> > +++ b/drivers/mtd/devices/m25p80.c
> > @@ -158,11 +158,6 @@ static int m25p80_erase(struct spi_nor *nor, loff_t offset)
> >  	dev_dbg(nor->dev, "%dKiB at 0x%08x\n",
> >  		flash->mtd.erasesize / 1024, (u32)offset);
> >  
> > -	/* Send write enable, then erase commands. */
> > -	ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
> > -	if (ret)
> > -		return ret;
> > -
> >  	/* Set up command buffer. */
> >  	flash->command[0] = nor->erase_opcode;
> >  	m25p_addr2cmd(nor, offset, flash->command);
> > diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
> > index 9c13622a0c7a..07fbfb0a7738 100644
> > --- a/drivers/mtd/spi-nor/fsl-quadspi.c
> > +++ b/drivers/mtd/spi-nor/fsl-quadspi.c
> > @@ -738,11 +738,6 @@ static int fsl_qspi_erase(struct spi_nor *nor, loff_t offs)
> >  	dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n",
> >  		nor->mtd->erasesize / 1024, q->chip_base_addr, (u32)offs);
> >  
> > -	/* Send write enable, then erase commands. */
> > -	ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
> > -	if (ret)
> > -		return ret;
> > -
> This write-enable is used for per-sector-erase, not for the whole chip
> erase.
> 
> So if you really want to remove this code, you should add an extra write-enable
> in the spi_nor_erase.

I don't understand your comment.

Before this patch, there is a write-enable command in:
 * m25p80.c, per-sector erase
 * fsl-quadspi, per-sector erase
 * spi-nor.c, whole-chip erase

With this patch, I am factoring all of these out into spi_nor_erase().

What is the problem?

Brian
diff mbox

Patch

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 96226ea69f90..116d979ffdb9 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -158,11 +158,6 @@  static int m25p80_erase(struct spi_nor *nor, loff_t offset)
 	dev_dbg(nor->dev, "%dKiB at 0x%08x\n",
 		flash->mtd.erasesize / 1024, (u32)offset);
 
-	/* Send write enable, then erase commands. */
-	ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
-	if (ret)
-		return ret;
-
 	/* Set up command buffer. */
 	flash->command[0] = nor->erase_opcode;
 	m25p_addr2cmd(nor, offset, flash->command);
diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
index 9c13622a0c7a..07fbfb0a7738 100644
--- a/drivers/mtd/spi-nor/fsl-quadspi.c
+++ b/drivers/mtd/spi-nor/fsl-quadspi.c
@@ -738,11 +738,6 @@  static int fsl_qspi_erase(struct spi_nor *nor, loff_t offs)
 	dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n",
 		nor->mtd->erasesize / 1024, q->chip_base_addr, (u32)offs);
 
-	/* Send write enable, then erase commands. */
-	ret = nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0, 0);
-	if (ret)
-		return ret;
-
 	ret = fsl_qspi_runcmd(q, nor->erase_opcode, offs, 0);
 	if (ret)
 		return ret;
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 874e6d9a0b02..d08d9f8bb9bd 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -226,9 +226,6 @@  static int erase_chip(struct spi_nor *nor)
 {
 	dev_dbg(nor->dev, " %lldKiB\n", (long long)(nor->mtd->size >> 10));
 
-	/* Send write enable, then erase commands. */
-	write_enable(nor);
-
 	return nor->write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0, 0);
 }
 
@@ -281,6 +278,8 @@  static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	if (ret)
 		return ret;
 
+	write_enable(nor);
+
 	/* whole-chip erase? */
 	if (len == mtd->size) {
 		if (erase_chip(nor)) {
@@ -314,6 +313,8 @@  static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 		}
 	}
 
+	write_disable(nor);
+
 	spi_nor_unlock_and_unprep(nor, SPI_NOR_OPS_ERASE);
 
 	instr->state = MTD_ERASE_DONE;