[PATCH v4 3/6] mtd: spi-nor: spansion: Add support for Read/Write Any Register
Takahiro Kuwano
tkuw584924 at gmail.com
Tue Apr 20 06:48:09 BST 2021
On 3/19/2021 3:56 PM, tkuw584924 at gmail.com wrote:
> From: Takahiro Kuwano <Takahiro.Kuwano at infineon.com>
>
> Some of Spansion/Cypress chips support Read/Write Any Register commands.
> These commands are mainly used to write volatile registers and access to
> the registers in second and subsequent die for multi-die package parts.
>
> The Read Any Register instruction (65h) is followed by register address
> and dummy cycles, then the selected register byte is returned.
>
> The Write Any Register instruction (71h) is followed by register address
> and register byte to write.
>
> Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano at infineon.com>
> ---
> Changes in v4:
> - Fix dummy cycle calculation in spansion_read_any_reg()
> - Modify comment for spansion_write_any_reg()
>
> Changes in v3:
> - Cleanup implementation
>
> drivers/mtd/spi-nor/spansion.c | 106 +++++++++++++++++++++++++++++++++
> 1 file changed, 106 insertions(+)
>
> diff --git a/drivers/mtd/spi-nor/spansion.c b/drivers/mtd/spi-nor/spansion.c
> index b0c5521c1e27..52a427d0af02 100644
> --- a/drivers/mtd/spi-nor/spansion.c
> +++ b/drivers/mtd/spi-nor/spansion.c
> @@ -19,6 +19,112 @@
> #define SPINOR_REG_CYPRESS_CFR5V_OCT_DTR_DS 0
> #define SPINOR_OP_CYPRESS_RD_FAST 0xee
>
> +/**
> + * spansion_read_any_reg() - Read Any Register.
> + * @nor: pointer to a 'struct spi_nor'
> + * @reg_addr: register address
> + * @reg_dummy: number of dummy cycles for register read
> + * @reg_val: pointer to a buffer where the register value is copied into
> + *
> + * Return: 0 on success, -errno otherwise.
> + */
> +static int spansion_read_any_reg(struct spi_nor *nor, u32 reg_addr,
> + u8 reg_dummy, u8 *reg_val)
> +{
> + ssize_t ret;
> +
> + if (nor->spimem) {
> + struct spi_mem_op op =
> + SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RD_ANY_REG, 0),
> + SPI_MEM_OP_ADDR(nor->addr_width, reg_addr, 0),
> + SPI_MEM_OP_DUMMY(reg_dummy, 0),
> + SPI_MEM_OP_DATA_IN(1, reg_val, 0));
> +
> + spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
> +
> + op.dummy.nbytes = (reg_dummy * op.dummy.buswidth) / 8;
> + if (spi_nor_protocol_is_dtr(nor->reg_proto))
> + op.dummy.nbytes *= 2;
> +
> + ret = spi_mem_exec_op(nor->spimem, &op);
> + } else {
> + enum spi_nor_protocol proto = nor->read_proto;
> + u8 opcode = nor->read_opcode;
> + u8 dummy = nor->read_dummy;
> +
> + nor->read_opcode = SPINOR_OP_RD_ANY_REG;
> + nor->read_dummy = reg_dummy;
> + nor->read_proto = nor->reg_proto;
> +
> + ret = nor->controller_ops->read(nor, reg_addr, 1, reg_val);
> +
> + nor->read_opcode = opcode;
> + nor->read_dummy = dummy;
> + nor->read_proto = proto;
> +
> + if (ret == 1)
> + return ret;
This is wrong. Will fix this to
if (ret < 0)
return ret;
> + if (ret != 1)
> + return -EIO;
> +
> + ret = 0;
> + }
> +
> + return ret;
> +}
More information about the linux-mtd
mailing list