From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] sf: ensure flash device is in 3-byte address mode
Date: Wed, 18 Oct 2017 22:42:36 +0200 [thread overview]
Message-ID: <20171018224236.5a9c5a43@jawa> (raw)
In-Reply-To: <FD897F46D140444CAB8DC80B08F0742B0185ABE4E4@PFDE-MX11.EU.P-F.BIZ>
Hi Simon,
> On some boards where the spi flash is not reset during warm reboot,
> the chip has to be manually set into 3-byte address mode.
>
> Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
> ---
> drivers/mtd/spi/sf_internal.h | 2 ++
> drivers/mtd/spi/spi_flash.c | 53
> +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55
> insertions(+)
>
> diff --git a/drivers/mtd/spi/sf_internal.h
> b/drivers/mtd/spi/sf_internal.h index 839cdbe1b0..06dee0a4ea 100644
> --- a/drivers/mtd/spi/sf_internal.h
> +++ b/drivers/mtd/spi/sf_internal.h
> @@ -62,6 +62,8 @@ enum spi_nor_option_flags {
> #define CMD_READ_STATUS1 0x35
> #define CMD_READ_CONFIG 0x35
> #define CMD_FLAG_STATUS 0x70
> +#define CMD_EN4B 0xB7
> +#define CMD_EX4B 0xE9
>
> /* Bank addr access commands */
> #ifdef CONFIG_SPI_FLASH_BAR
> diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
> index 34f68881ed..8db2882075 100644
> --- a/drivers/mtd/spi/spi_flash.c
> +++ b/drivers/mtd/spi/spi_flash.c
> @@ -165,6 +165,55 @@ bar_end:
> }
> #endif
>
> +static int set_4byte(struct spi_flash *flash, const struct
> spi_flash_info *info,
> + u8 enable)
> +{
> + int ret;
> + bool need_wren = false;
> + u8 cmd;
> +
> + if (flash->size <= SPI_FLASH_16MB_BOUN)
> + return 0;
> +
> + switch (JEDEC_MFR(info)) {
> + case SPI_FLASH_CFI_MFR_STMICRO:
> + /* Some Micron need WREN command; all will accept it
> */
> + need_wren = true;
> + case SPI_FLASH_CFI_MFR_MACRONIX:
> + case SPI_FLASH_CFI_MFR_WINBOND:
> + ret = spi_claim_bus(flash->spi);
> + if (ret) {
> + debug("SF: Unable to claim SPI bus\n");
> + return ret;
> + }
> +
> + if (need_wren) {
> + ret = spi_flash_cmd_write_enable(flash);
> + if (ret < 0) {
> + debug("SF: enabling write failed\n");
> + spi_release_bus(flash->spi);
> + return ret;
> + }
> + }
> +
> + cmd = enable ? CMD_EN4B : CMD_EX4B;
> + ret = spi_flash_cmd_write(flash->spi, &cmd, 1, NULL,
> 0);
> + if (ret) {
> + debug("SF: fail to %s 4-byte address mode\n",
> + enable ? "enter" : "exit");
> + }
> + if (need_wren)
> + if (spi_flash_cmd_write_disable(flash) < 0)
> + debug("SF: disabling write
> failed\n");
> + spi_release_bus(flash->spi);
> + return ret;
> + default:
> + /* Spansion style handled by bar_write */
> + break;
> + }
> + return 0;
> +}
> +
> #ifdef CONFIG_SF_DUAL_FLASH
> static void spi_flash_dual(struct spi_flash *flash, u32 *addr)
> {
> @@ -1086,6 +1135,10 @@ int spi_flash_scan(struct spi_flash *flash)
> flash->flags |= SNOR_F_USE_FSR;
> #endif
>
> + /* disable 4-byte addressing if the device exceeds 16MiB */
> + if (flash->size > SPI_FLASH_16MB_BOUN)
> + set_4byte(flash, info, 0);
> +
> /* Configure the BAR - discover bank cmds and read current
> bank */ #ifdef CONFIG_SPI_FLASH_BAR
> ret = read_bar(flash, info);
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
next prev parent reply other threads:[~2017-10-18 20:42 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-17 11:47 [U-Boot] [PATCH] sf: ensure flash device is in 3-byte address mode Goldschmidt Simon
2017-10-18 20:42 ` Lukasz Majewski [this message]
2017-10-30 6:26 ` Jagan Teki
-- strict thread matches above, loose matches on Subject: below --
2017-11-10 6:41 Goldschmidt Simon
2017-11-10 7:03 ` Jagan Teki
2017-11-30 8:41 Goldschmidt Simon
2017-12-04 7:20 ` Jagan Teki
2017-12-05 6:20 Goldschmidt Simon
2017-12-07 5:49 ` Jagan Teki
2017-12-07 8:23 ` Prabhakar Kushwaha
2018-05-14 7:04 ` Simon Goldschmidt
2018-05-14 7:22 ` Jagan Teki
2018-05-14 7:47 ` Simon Goldschmidt
2018-05-18 7:18 ` Simon Goldschmidt
2018-05-21 15:09 ` Jagan Teki
2018-05-22 4:29 ` Simon Goldschmidt
2018-05-30 5:10 ` Jagan Teki
2018-05-30 8:12 ` Simon Goldschmidt
2018-05-30 11:25 ` Jagan Teki
2018-05-30 11:27 ` Marek Vasut
2018-05-30 11:54 ` Simon Goldschmidt
2018-05-30 11:41 ` Simon Goldschmidt
2018-05-30 9:56 ` Marek Vasut
2018-05-30 11:18 ` Simon Goldschmidt
2018-05-30 11:23 ` Marek Vasut
2018-06-02 11:58 ` Prabhakar Kushwaha
2017-12-07 10:00 Goldschmidt Simon
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=20171018224236.5a9c5a43@jawa \
--to=lukma@denx.de \
--cc=u-boot@lists.denx.de \
/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