mtd: spi-nor: fix spi_nor_spimem_setup_op() call in spi_nor_erase_{sector,chip}()

Tudor.Ambarus at microchip.com Tudor.Ambarus at microchip.com
Mon Jul 18 09:47:34 PDT 2022


On 6/29/22 16:30, patrice.chotard at foss.st.com wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> From: Patrice Chotard <patrice.chotard at foss.st.com>
> 
> For erase operations, reg_proto must be used as indicated in
> struct spi_nor description in spi-nor.h.
> 
> This issue was found when DT property spi-tx-bus-width is set to 4.
> In this case the spi_mem_op->addr.buswidth is set to 4 for erase command
> which is not correct.
> 
> Tested on stm32mp157c-ev1 board with mx66l51235f spi-nor.
> 
> Fixes: 0e30f47232ab ("mtd: spi-nor: add support for DTR protocol")
> Signed-off-by: Patrice Chotard <patrice.chotard at foss.st.com>
> ---
>  drivers/mtd/spi-nor/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 502967c76c5f..61027330848f 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -972,7 +972,7 @@ static int spi_nor_erase_chip(struct spi_nor *nor)
>         if (nor->spimem) {
>                 struct spi_mem_op op = SPI_NOR_CHIP_ERASE_OP;
> 
> -               spi_nor_spimem_setup_op(nor, &op, nor->write_proto);
> +               spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
> 
>                 ret = spi_mem_exec_op(nor->spimem, &op);
>         } else {
> @@ -1115,7 +1115,7 @@ int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
>                         SPI_NOR_SECTOR_ERASE_OP(nor->erase_opcode,
>                                                 nor->addr_width, addr);
> 
> -               spi_nor_spimem_setup_op(nor, &op, nor->write_proto);
> +               spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
> 
>                 return spi_mem_exec_op(nor->spimem, &op);
>         } else if (nor->controller_ops->erase) {
> --
> 2.25.1
> 

should you also update the following?

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index ce5d69317d46..23487e9a9282 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -177,7 +177,7 @@ int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
 
 static int spi_nor_controller_ops_erase(struct spi_nor *nor, loff_t offs)
 {
-       if (spi_nor_protocol_is_dtr(nor->write_proto))
+       if (spi_nor_protocol_is_dtr(nor->reg_proto))
                return -EOPNOTSUPP;
 
        return nor->controller_ops->erase(nor, offs);


More information about the linux-mtd mailing list