[PATCH v2 6/8] mtd: spi-nor: spansion: Add a new ->ready() hook for multi-chip device

Tudor Ambarus tudor.ambarus at linaro.org
Wed Mar 1 22:27:27 PST 2023



On 08.02.2023 07:53, tkuw584924 at gmail.com wrote:
> From: Takahiro Kuwano <Takahiro.Kuwano at infineon.com>
> 
> For multi-chip devices, we need to make sure the all dice in the device
> are ready. The cypress_nor_sr_ready_and_clear() reads SR in each die and
> returns true only when all dice are ready. This function also takes care
> for program or erase error handling by reusing spansion_nor_clear_sr().
> To do that, spansion_nor_clear_sr() is moved to top.
> 
> Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano at infineon.com>
> ---
>   drivers/mtd/spi-nor/spansion.c | 96 ++++++++++++++++++++++++++--------
>   1 file changed, 73 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
> index 33c8a5afcb76..45377566ecbd 100644
> --- a/drivers/mtd/spi-nor/spansion.c
> +++ b/drivers/mtd/spi-nor/spansion.c
> @@ -14,6 +14,7 @@
>   #define SPINOR_OP_CLSR		0x30	/* Clear status register 1 */
>   #define SPINOR_OP_RD_ANY_REG			0x65	/* Read any register */
>   #define SPINOR_OP_WR_ANY_REG			0x71	/* Write any register */
> +#define SPINOR_REG_CYPRESS_STR1			0x0
>   #define SPINOR_REG_CYPRESS_CFR1			0x2
>   #define SPINOR_REG_CYPRESS_CFR1_QUAD_EN		BIT(1)	/* Quad Enable */
>   #define SPINOR_REG_CYPRESS_CFR2V		0x00800003
> @@ -49,6 +50,74 @@
>   		   SPI_MEM_OP_NO_DUMMY,					\
>   		   SPI_MEM_OP_NO_DATA)
>   
> +/**
> + * spansion_nor_clear_sr() - Clear the Status Register.
> + * @nor:	pointer to 'struct spi_nor'.
> + */
> +static void spansion_nor_clear_sr(struct spi_nor *nor)
> +{
> +	int ret;
> +
> +	if (nor->spimem) {
> +		struct spi_mem_op op = SPANSION_CLSR_OP;
> +
> +		spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
> +
> +		ret = spi_mem_exec_op(nor->spimem, &op);
> +	} else {
> +		ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_CLSR,
> +						       NULL, 0);
> +	}
> +
> +	if (ret)
> +		dev_dbg(nor->dev, "error %d clearing SR\n", ret);
> +}
> +
> +/**
> + * cypress_nor_sr_ready_and_clear() - Query the Status Register of each die by
> + * using Read Any Register command to see if the whole flash is ready for new
> + * commands and clear it if there are any errors.
> + * @nor:	pointer to 'struct spi_nor'.
> + *
> + * Return: 1 if ready, 0 if not ready, -errno on errors.
> + */
> +static int cypress_nor_sr_ready_and_clear(struct spi_nor *nor)

we could rename this to cypress_nor_md_sr_ready_and_clear to indicate
it's solely used for multi die devices.

> +{
> +	struct spi_mem_op op =
> +		CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes, 0,
> +					  nor->bouncebuf);
> +	int ret;
> +	u8 i;
> +
> +	for (i = 0; i < nor->params->num_of_dice; i++) {

as long as you rollback the num of dice to 1 in case of errors in the
sccr tables, this should be fine.

Looks fine.



More information about the linux-mtd mailing list