From: <Tudor.Ambarus@microchip.com>
To: <michael@walle.cc>, <linux-mtd@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Cc: <miquel.raynal@bootlin.com>, <richard@nod.at>, <vigneshr@ti.com>,
<boris.brezillon@collabora.com>
Subject: Re: [PATCH v7 6/7] mtd: spi-nor: atmel: fix unlock_all() for AT25FS010/040
Date: Thu, 3 Dec 2020 14:44:54 +0000 [thread overview]
Message-ID: <9338f65d-ff5e-ade8-8beb-986445996da0@microchip.com> (raw)
In-Reply-To: <20201202230040.14009-7-michael@walle.cc>
On 12/3/20 1:00 AM, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> These flashes have some weird BP bits mapping which aren't supported in
> the current locking code. Just add a simple unlock op to unprotect the
> entire flash array which is needed for legacy behavior.
>
> Signed-off-by: Michael Walle <michael@walle.cc>
With fixes tag added, one can add:
Reviewed-by: Tudor Ambarus <tudor.ambarus@microchip.com>
> ---
> changes since v6:
> - use spi_nor_write_sr_and_check() and log a debug message if writing
> fails
>
> changes since v5:
> - new patch
>
> drivers/mtd/spi-nor/atmel.c | 53 +++++++++++++++++++++++++++++++++++--
> drivers/mtd/spi-nor/core.c | 2 +-
> drivers/mtd/spi-nor/core.h | 1 +
> 3 files changed, 53 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/atmel.c b/drivers/mtd/spi-nor/atmel.c
> index 49d392c6c8bc..ee382a44bd0f 100644
> --- a/drivers/mtd/spi-nor/atmel.c
> +++ b/drivers/mtd/spi-nor/atmel.c
> @@ -8,10 +8,59 @@
>
> #include "core.h"
>
> +/*
> + * The Atmel AT25FS010/AT25FS040 parts have some weird configuration for the
> + * block protection bits. We don't support them. But legacy behavior in linux
> + * is to unlock the whole flash array on startup. Therefore, we have to support
> + * exactly this operation.
> + */
> +static int atmel_at25fs_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +static int atmel_at25fs_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
> +{
> + int ret;
> +
> + /* We only support unlocking the whole flash array */
> + if (ofs || len != nor->params->size)
> + return -EINVAL;
> +
> + /* Write 0x00 to the status register to disable write protection */
> + ret = spi_nor_write_sr_and_check(nor, 0);
> + if (ret)
> + dev_dbg(nor->dev, "unable to clear BP bits, WP# asserted?\n");
> +
> + return ret;
> +}
> +
> +static int atmel_at25fs_is_locked(struct spi_nor *nor, loff_t ofs, uint64_t len)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> +static const struct spi_nor_locking_ops atmel_at25fs_locking_ops = {
> + .lock = atmel_at25fs_lock,
> + .unlock = atmel_at25fs_unlock,
> + .is_locked = atmel_at25fs_is_locked,
> +};
> +
> +static void atmel_at25fs_default_init(struct spi_nor *nor)
> +{
> + nor->params->locking_ops = &atmel_at25fs_locking_ops;
> +}
> +
> +static const struct spi_nor_fixups atmel_at25fs_fixups = {
> + .default_init = atmel_at25fs_default_init,
> +};
> +
> static const struct flash_info atmel_parts[] = {
> /* Atmel -- some are (confusingly) marketed as "DataFlash" */
> - { "at25fs010", INFO(0x1f6601, 0, 32 * 1024, 4, SECT_4K | SPI_NOR_HAS_LOCK) },
> - { "at25fs040", INFO(0x1f6604, 0, 64 * 1024, 8, SECT_4K | SPI_NOR_HAS_LOCK) },
> + { "at25fs010", INFO(0x1f6601, 0, 32 * 1024, 4, SECT_4K | SPI_NOR_HAS_LOCK)
> + .fixups = &atmel_at25fs_fixups },
> + { "at25fs040", INFO(0x1f6604, 0, 64 * 1024, 8, SECT_4K | SPI_NOR_HAS_LOCK)
> + .fixups = &atmel_at25fs_fixups },
>
> { "at25df041a", INFO(0x1f4401, 0, 64 * 1024, 8, SECT_4K | SPI_NOR_HAS_LOCK) },
> { "at25df321", INFO(0x1f4700, 0, 64 * 1024, 64, SECT_4K | SPI_NOR_HAS_LOCK) },
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 013198abe929..6afcb99e9741 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1049,7 +1049,7 @@ static int spi_nor_write_16bit_cr_and_check(struct spi_nor *nor, u8 cr)
> *
> * Return: 0 on success, -errno otherwise.
> */
> -static int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 sr1)
> +int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 sr1)
> {
> if (nor->flags & SNOR_F_HAS_16BIT_SR)
> return spi_nor_write_16bit_sr_and_check(nor, sr1);
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> index 0a775a7b5606..7780169d485b 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -430,6 +430,7 @@ void spi_nor_unlock_and_unprep(struct spi_nor *nor);
> int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor);
> int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor);
> int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor);
> +int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 sr1);
>
> int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr);
> ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len,
> --
> 2.20.1
>
next prev parent reply other threads:[~2020-12-03 14:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-02 23:00 [PATCH v7 0/7] mtd: spi-nor: keep lock bits if they are non-volatile Michael Walle
2020-12-02 23:00 ` [PATCH v7 1/7] mtd: spi-nor: sst: fix BPn bits for the SST25VF064C Michael Walle
2020-12-03 14:34 ` Tudor.Ambarus
2020-12-03 14:39 ` Michael Walle
2020-12-03 15:08 ` Tudor.Ambarus
2020-12-03 18:24 ` Greg KH
2020-12-03 14:40 ` Tudor.Ambarus
2020-12-03 14:41 ` Michael Walle
2020-12-02 23:00 ` [PATCH v7 2/7] mtd: spi-nor: ignore errors in spi_nor_unlock_all() Michael Walle
2020-12-03 14:36 ` Tudor.Ambarus
2020-12-02 23:00 ` [PATCH v7 3/7] mtd: spi-nor: atmel: remove global protection flag Michael Walle
2020-12-02 23:00 ` [PATCH v7 4/7] mtd: spi-nor: sst: " Michael Walle
2020-12-02 23:00 ` [PATCH v7 5/7] mtd: spi-nor: intel: " Michael Walle
2020-12-02 23:00 ` [PATCH v7 6/7] mtd: spi-nor: atmel: fix unlock_all() for AT25FS010/040 Michael Walle
2020-12-03 14:44 ` Tudor.Ambarus [this message]
2020-12-02 23:00 ` [PATCH v7 7/7] mtd: spi-nor: keep lock bits if they are non-volatile Michael Walle
2020-12-03 14:51 ` Tudor.Ambarus
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=9338f65d-ff5e-ade8-8beb-986445996da0@microchip.com \
--to=tudor.ambarus@microchip.com \
--cc=boris.brezillon@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=michael@walle.cc \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/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