From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1 2/4] mtd: spi-nor: add UNLOCK_GLOBAL_BLOCK support
Date: Tue, 20 Aug 2019 09:06:38 +0200 [thread overview]
Message-ID: <20190820070640.3526-3-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20190820070640.3526-1-o.rempel@pengutronix.de>
Ported from linux-4.19-at91 linux4sam_6.1 and needed for
SAMA5D27 SOM1 EK.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/mtd/spi-nor/spi-nor.c | 25 ++++++++++++++++++++++++-
include/linux/mtd/spi-nor.h | 1 +
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 43bd402f9f..c506e62a62 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -57,7 +57,7 @@ struct flash_info {
u16 page_size;
u16 addr_width;
- u16 flags;
+ u32 flags;
#define SECT_4K BIT(0) /* SPINOR_OP_BE_4K works uniformly */
#define SPI_NOR_NO_ERASE BIT(1) /* No erase command needed */
#define SST_WRITE BIT(2) /* use SST byte programming */
@@ -86,6 +86,7 @@ struct flash_info {
#define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */
#define USE_CLSR BIT(14) /* use CLSR command */
#define SPI_NOR_OCTAL_READ BIT(15) /* Flash supports Octal Read */
+#define UNLOCK_GLOBAL_BLOCK BIT(16) /* Unlock global block protection */
};
enum spi_nor_read_command_index {
@@ -1045,6 +1046,17 @@ spi_nor_set_pp_settings(struct spi_nor_pp_command *pp,
pp->proto = proto;
}
+static int spi_nor_unlock_global_block_protection(struct spi_nor *nor)
+{
+ int ret;
+
+ write_enable(nor);
+ ret = nor->write_reg(nor, SPINOR_OP_GBULK, NULL, 0);
+ if (ret < 0)
+ return ret;
+ return spi_nor_wait_till_ready(nor);
+}
+
static int spi_nor_init_params(struct spi_nor *nor,
const struct flash_info *info,
struct spi_nor_flash_parameter *params)
@@ -1088,6 +1100,17 @@ static int spi_nor_init_params(struct spi_nor *nor,
spi_nor_set_pp_settings(¶ms->page_programs[SNOR_CMD_PP],
SPINOR_OP_PP, SNOR_PROTO_1_1_1);
+ if (info->flags & UNLOCK_GLOBAL_BLOCK) {
+ int err;
+
+ err = spi_nor_unlock_global_block_protection(nor);
+ if (err) {
+ dev_err(nor->dev,
+ "Cannot unlock the global block protection\n");
+ return err;
+ }
+ }
+
/* Select the procedure to set the Quad Enable bit. */
if (params->hwcaps.mask & (SNOR_HWCAPS_READ_QUAD |
SNOR_HWCAPS_PP_QUAD))
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 33413ff955..105f381ada 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -64,6 +64,7 @@
#define SPINOR_OP_CLFSR 0x50 /* Clear flag status register */
#define SPINOR_OP_RDEAR 0xc8 /* Read Extended Address Register */
#define SPINOR_OP_WREAR 0xc5 /* Write Extended Address Register */
+#define SPINOR_OP_GBULK 0x98 /* Global Block Unlock Protection */
/* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
#define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-08-20 7:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-20 7:06 [PATCH v1 0/4] extend support for SAMA5D27 SOM1 EK Oleksij Rempel
2019-08-20 7:06 ` [PATCH v1 1/4] serial: atmel: set linux_console_name Oleksij Rempel
2019-08-20 7:06 ` Oleksij Rempel [this message]
2019-08-20 7:06 ` [PATCH v1 3/4] mtd: spi-nor: add support for sst26vf series Oleksij Rempel
2019-08-20 7:06 ` [PATCH v1 4/4] spi: add atmel-quadspi support Oleksij Rempel
2019-08-21 6:43 ` Sascha Hauer
2019-08-21 6:48 ` Oleksij Rempel
2019-08-21 6:52 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190820070640.3526-3-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox