diff mbox

[U-Boot,v3,1/5] sf: disable write protection for Macronix flash

Message ID 1304329121-16245-2-git-send-email-simon.guinot@sequanux.org
State Changes Requested
Headers show

Commit Message

Simon Guinot May 2, 2011, 9:38 a.m. UTC
From: Simon Guinot <sguinot@lacie.com>

Signed-off-by: Simon Guinot <sguinot@lacie.com>
---
 drivers/mtd/spi/macronix.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

Comments

Mike Frysinger May 2, 2011, 4:50 p.m. UTC | #1
On Mon, May 2, 2011 at 05:38, Simon Guinot wrote:
> --- a/drivers/mtd/spi/macronix.c
> +++ b/drivers/mtd/spi/macronix.c
> @@ -120,6 +120,45 @@
>        },
>  };
>
> +static int macronix_write_status(struct spi_flash *flash, u8 sr)
> +{
> +       u8 cmd;
> +       int ret;
> +
> +       ret = spi_flash_cmd(flash->spi, CMD_MX25XX_WREN, NULL, 0);

this is spi_flash_cmd_write_enable() now
-mike
Simon Guinot May 2, 2011, 8:11 p.m. UTC | #2
Hi Mike,

On Mon, May 02, 2011 at 12:50:13PM -0400, Mike Frysinger wrote:
> On Mon, May 2, 2011 at 05:38, Simon Guinot wrote:
> > --- a/drivers/mtd/spi/macronix.c
> > +++ b/drivers/mtd/spi/macronix.c
> > @@ -120,6 +120,45 @@
> >        },
> >  };
> >
> > +static int macronix_write_status(struct spi_flash *flash, u8 sr)
> > +{
> > +       u8 cmd;
> > +       int ret;
> > +
> > +       ret = spi_flash_cmd(flash->spi, CMD_MX25XX_WREN, NULL, 0);
> 
> this is spi_flash_cmd_write_enable() now

I will rebase this patch against your sf branch.

Simon
diff mbox

Patch

diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c
index 8e4d71c..9a3895d 100644
--- a/drivers/mtd/spi/macronix.c
+++ b/drivers/mtd/spi/macronix.c
@@ -120,6 +120,45 @@  static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
 	},
 };
 
+static int macronix_write_status(struct spi_flash *flash, u8 sr)
+{
+	u8 cmd;
+	int ret;
+
+	ret = spi_flash_cmd(flash->spi, CMD_MX25XX_WREN, NULL, 0);
+	if (ret < 0) {
+		debug("SF: enabling write failed\n");
+		return ret;
+	}
+
+	cmd = CMD_MX25XX_WRSR;
+	ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &sr, 1);
+	if (ret) {
+		debug("SF: fail to write status register\n");
+		return ret;
+	}
+
+	ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
+	if (ret < 0) {
+		debug("SF: write status register timed out\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int macronix_unlock(struct spi_flash *flash)
+{
+	int ret;
+
+	/* Enable status register writing and clear BP# bits */
+	ret = macronix_write_status(flash, 0);
+	if (ret)
+		debug("SF: fail to disable write protection\n");
+
+	return ret;
+}
+
 static int macronix_write(struct spi_flash *flash,
 			  u32 offset, size_t len, const void *buf)
 {
@@ -223,5 +262,8 @@  struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
 		* params->sectors_per_block;
 	mcx->flash.size = mcx->flash.sector_size * params->nr_blocks;
 
+	/* Clear BP# bits for read-only flash */
+	macronix_unlock(&mcx->flash);
+
 	return &mcx->flash;
 }