public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Pratyush Yadav <p.yadav@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v4 6/9] mtd: spi-nor-core: Add overlaid sector erase feature
Date: Tue, 2 Feb 2021 00:26:35 +0530	[thread overview]
Message-ID: <20210201185633.ylopri7w2bbcoge6@ti.com> (raw)
In-Reply-To: <84277efd6f8e0e00f5dab00e92e4d37f701f144c.1611729896.git.Takahiro.Kuwano@infineon.com>

Hi Takahiro,

On 28/01/21 01:36PM, tkuw584924 at gmail.com wrote:
> From: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
> 
> Some of Spansion/Cypress chips have overlaid 4KB sectors at top and/or
> bottom, depending on the device configuration, while U-Boot supports
> uniform sector layout only. This patch adds an erase hook that emulates
> uniform sector layout.
> 
> Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
> ---
>  drivers/mtd/spi/spi-nor-core.c | 48 ++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)
> 
> diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
> index 1c0ba5abf9..70da0081b6 100644
> --- a/drivers/mtd/spi/spi-nor-core.c
> +++ b/drivers/mtd/spi/spi-nor-core.c
> @@ -788,6 +788,54 @@ erase_err:
>  	return ret;
>  }
>  
> +#ifdef CONFIG_SPI_FLASH_SPANSION
> +/*
> + * Erase for Spansion/Cypress Flash devices that has overlaid 4KB sectors at
> + * the top and/or bottom.
> + */
> +static int spansion_overlaid_erase(struct mtd_info *mtd,
> +				   struct erase_info *instr)
> +{
> +	struct spi_nor *nor = mtd_to_spi_nor(mtd);
> +	struct erase_info instr_4k;
> +	u8 opcode;
> +	u32 erasesize;
> +	int ret;
> +
> +	/* Perform default erase operation (non-overlaid portion is erased) */
> +	ret = spi_nor_erase(mtd, instr);
> +	if (ret)
> +		return ret;
> +
> +	/* Backup default erase opcode and size */
> +	opcode = nor->erase_opcode;
> +	erasesize = mtd->erasesize;
> +
> +	/*
> +	 * Erase 4KB sectors. Use the possible max length of 4KB sector region.
> +	 * The Flash just ignores the command if the address is not configured
> +	 * as 4KB sector and reports ready status immediately.
> +	 */
> +	instr_4k.len = SZ_128K;
> +	nor->erase_opcode = SPINOR_OP_BE_4K_4B;
> +	mtd->erasesize = SZ_4K;
> +	if (instr->addr == 0) {
> +		instr_4k.addr = 0;
> +		ret = spi_nor_erase(mtd, &instr_4k);
> +	}
> +	if (!ret && instr->addr + instr->len == mtd->size) {
> +		instr_4k.addr = mtd->size - instr_4k.len;
> +		ret = spi_nor_erase(mtd, &instr_4k);
> +	}

This feels like a hack to me. Does the flash datasheet explicitly say 
that erasing the overlaid area with the "normal" erase opcode is a 
no-op?

I don't see a big reason to run this hack. You are already in a 
flash-specific erase hook. Why not just directly issue the correct erase 
commands to the sectors? That is, why not issue 4k erase to overlaid 
sectors and normal erase to the rest? Why do you need to emulate uniform 
erase?

> +
> +	/* Restore erase opcode and size */
> +	nor->erase_opcode = opcode;
> +	mtd->erasesize = erasesize;
> +
> +	return ret;
> +}
> +#endif
> +
>  #if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST)
>  /* Write status register and ensure bits in mask match written values */
>  static int write_sr_and_check(struct spi_nor *nor, u8 status_new, u8 mask)
> -- 
> 2.25.1
> 

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

  reply	other threads:[~2021-02-01 18:56 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28  4:36 [PATCH v4 0/9] mtd: spi-nor: Add support for Cypress s25hl-t/s25hs-t tkuw584924 at gmail.com
2021-01-28  4:36 ` [PATCH v4 1/9] mtd: spi-nor: Add Cypress manufacturer ID tkuw584924 at gmail.com
2021-01-29 17:52   ` Pratyush Yadav
2021-01-28  4:36 ` [PATCH v4 2/9] mtd: spi-nor-ids: Add Cypress s25hl-t/s25hs-t tkuw584924 at gmail.com
2021-01-29 18:08   ` Pratyush Yadav
2021-02-09  5:44     ` Takahiro Kuwano
2021-01-28  4:36 ` [PATCH v4 3/9] mtd: spi-nor-core: Add support for Read/Write Any Register tkuw584924 at gmail.com
2021-01-29 18:17   ` Pratyush Yadav
2021-02-09  5:51     ` Takahiro Kuwano
2021-01-28  4:36 ` [PATCH v4 4/9] mtd: spi-nor-core: Add support for volatile QE bit tkuw584924 at gmail.com
2021-01-29 18:40   ` Pratyush Yadav
2021-02-09  5:57     ` Takahiro Kuwano
2021-01-28  4:36 ` [PATCH v4 5/9] mtd: spi-nor-core: Add the ->ready() hook tkuw584924 at gmail.com
2021-01-29 18:49   ` Pratyush Yadav
2021-02-09  6:10     ` Takahiro Kuwano
2021-01-28  4:36 ` [PATCH v4 6/9] mtd: spi-nor-core: Add overlaid sector erase feature tkuw584924 at gmail.com
2021-02-01 18:56   ` Pratyush Yadav [this message]
2021-02-10  2:37     ` Takahiro Kuwano
2021-01-28  4:37 ` [PATCH v4 7/9] mtd: spi-nor-core: Add Cypress manufacturer ID in set_4byte tkuw584924 at gmail.com
2021-01-28  4:37 ` [PATCH v4 8/9] mtd: spi-nor-core: Add fixups for Cypress s25hl-t/s25hs-t tkuw584924 at gmail.com
2021-02-01 19:22   ` Pratyush Yadav
2021-02-15  7:45     ` Takahiro Kuwano
2021-01-28  4:37 ` [PATCH v4 9/9] mtd: spi-nor-tiny: " tkuw584924 at gmail.com
2021-02-01 19:40   ` Pratyush Yadav
2021-02-10  9:20     ` Takahiro Kuwano

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=20210201185633.ylopri7w2bbcoge6@ti.com \
    --to=p.yadav@ti.com \
    --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