From: Marek Vasut <marek.vasut@gmail.com>
To: Cyrille Pitchen <cyrille.pitchen@atmel.com>,
linux-mtd@lists.infradead.org, kdasu.kdev@gmail.com
Cc: computersforpeace@gmail.com, dwmw2@infradead.org,
boris.brezillon@free-electrons.com, richard@nod.at,
linux-kernel@vger.kernel.org, jartur@cadence.com,
mar.krzeminski@gmail.com
Subject: Re: [RFC PATCH v6 4/4] mtd: spi-nor: add spi_nor_init() function
Date: Mon, 17 Apr 2017 00:31:30 +0200 [thread overview]
Message-ID: <7c5abf12-380c-8c46-731c-950d90c89dbd@gmail.com> (raw)
In-Reply-To: <c1284f6bbb0284fccd1254066e1daeae6f95dc12.1492374675.git.cyrille.pitchen@atmel.com>
On 04/16/2017 11:41 PM, Cyrille Pitchen wrote:
> This patch extracts some chunks from spi_nor_scan() and moves them into
> a new spi_nor_init() function.
>
> Indeed, spi_nor_init() regroups all the required SPI flash commands to be
> sent to the SPI flash memory before performing any runtime operations
> (Fast Read, Page Program, Sector Erase, ...). Hence spi_nor_init():
> 1) removes the flash protection if applicable for certain vendors.
> 2) sets the Quad Enable bit, if needed, before using Quad SPI protocols.
> 3) makes the memory enter its (stateful) 4-byte address mode, if needed,
> for SPI flash memory > 128Mbits not supporting the 4-byte address
> instruction set.
>
> spi_nor_scan() now ends by calling spi_nor_init() once the probe phase has
> completed. Further patches could also use spi_nor_init() to implement the
> mtd->_resume() handler for the spi-nor framework.
>
> Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
> Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
> ---
> drivers/mtd/spi-nor/spi-nor.c | 71 ++++++++++++++++++++++++++++---------------
> include/linux/mtd/spi-nor.h | 8 +++++
> 2 files changed, 55 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 2377fe54f8b9..523fd9d85f57 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -255,6 +255,8 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor,
> nor->read_opcode = spi_nor_convert_3to4_read(nor->read_opcode);
> nor->program_opcode = spi_nor_convert_3to4_program(nor->program_opcode);
> nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode);
> +
> + nor->flags |= SNOR_F_4B_OPCODES;
> }
>
> /* Enable/disable 4-byte addressing mode. */
> @@ -1836,6 +1838,45 @@ static int spi_nor_setup(struct spi_nor *nor, const struct flash_info *info,
> return 0;
> }
>
> +static int spi_nor_init(struct spi_nor *nor)
> +{
> + const struct flash_info *info = nor->info;
> + struct device *dev = nor->dev;
> + int ret;
> +
> + /*
> + * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up
> + * with the software protection bits set
> + */
> +
> + if (JEDEC_MFR(info) == SNOR_MFR_ATMEL ||
> + JEDEC_MFR(info) == SNOR_MFR_INTEL ||
> + JEDEC_MFR(info) == SNOR_MFR_SST ||
> + info->flags & SPI_NOR_HAS_LOCK) {
> + write_enable(nor);
> + write_sr(nor, 0);
> + spi_nor_wait_till_ready(nor);
> + }
> +
> + /* Set the Quad Enable bit, if needed. */
> + if (nor->flash_quad_enable) {
> + ret = nor->flash_quad_enable(nor);
> + if (ret) {
> + dev_err(dev, "quad mode not supported\n");
Do we care about undoing changes (like doing write_disable()) in case of
failure ?
Also, if we have flash_quad_enable() and it fails, should we fall back
to 1-1-1 or something ?
> + return ret;
> + }
> + }
> +
> + /*
> + * For SPI flash memories above 128Mib, enter the 4-byte address mode
> + * only if the 4-byte address instruction set is not supported.
> + */
> + if (nor->addr_width == 4 && !(nor->flags & SNOR_F_4B_OPCODES))
> + set_4byte(nor, info, 1);
> +
> + return 0;
> +}
> +
[...]
--
Best regards,
Marek Vasut
prev parent reply other threads:[~2017-04-16 22:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-16 21:41 [PATCH v6 0/4] mtd: spi-nor: parse SFDP tables to setup (Q)SPI memories Cyrille Pitchen
2017-04-16 21:41 ` [PATCH v6 1/4] mtd: spi-nor: introduce more SPI protocols and the Dual Transfer Mode Cyrille Pitchen
2017-04-16 22:26 ` Marek Vasut
2017-04-16 21:41 ` [PATCH v6 2/4] mtd: m25p80: add support of SPI 1-2-2 and 1-4-4 protocols Cyrille Pitchen
2017-04-16 22:28 ` Marek Vasut
2017-04-16 21:41 ` [RFC PATCH v6 3/4] mtd: spi-nor: transitional patch Cyrille Pitchen
2017-04-16 21:41 ` [RFC PATCH v6 4/4] mtd: spi-nor: add spi_nor_init() function Cyrille Pitchen
2017-04-16 22:31 ` Marek Vasut [this message]
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=7c5abf12-380c-8c46-731c-950d90c89dbd@gmail.com \
--to=marek.vasut@gmail.com \
--cc=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@atmel.com \
--cc=dwmw2@infradead.org \
--cc=jartur@cadence.com \
--cc=kdasu.kdev@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=mar.krzeminski@gmail.com \
--cc=richard@nod.at \
/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
all inboxes | Powered by JetHome®