Skip to content

Commit a604ab3

Browse files
ambarusPratyush Yadav
authored andcommitted
mtd: spi-nor: core: Add helpers to read/write any register
There are manufacturers that use registers indexed by address. Some of them support "read/write any register" opcodes. Provide core methods that can be used by all manufacturers. SPI NOR controller ops are intentionally not supported as we intend to move all the SPI NOR controller drivers under the SPI subsystem. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Signed-off-by: Pratyush Yadav <p.yadav@ti.com> Tested-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com> Reviewed-by: Pratyush Yadav <p.yadav@ti.com> Reviewed-by: Michael Walle <michael@walle.cc> Link: https://lore.kernel.org/r/20220420103427.47867-7-tudor.ambarus@microchip.com
1 parent a007d81 commit a604ab3

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

drivers/mtd/spi-nor/core.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,52 @@ ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
307307
return nor->controller_ops->write(nor, to, len, buf);
308308
}
309309

310+
/**
311+
* spi_nor_read_any_reg() - read any register from flash memory, nonvolatile or
312+
* volatile.
313+
* @nor: pointer to 'struct spi_nor'.
314+
* @op: SPI memory operation. op->data.buf must be DMA-able.
315+
* @proto: SPI protocol to use for the register operation.
316+
*
317+
* Return: zero on success, -errno otherwise
318+
*/
319+
int spi_nor_read_any_reg(struct spi_nor *nor, struct spi_mem_op *op,
320+
enum spi_nor_protocol proto)
321+
{
322+
if (!nor->spimem)
323+
return -EOPNOTSUPP;
324+
325+
spi_nor_spimem_setup_op(nor, op, proto);
326+
return spi_nor_spimem_exec_op(nor, op);
327+
}
328+
329+
/**
330+
* spi_nor_write_any_volatile_reg() - write any volatile register to flash
331+
* memory.
332+
* @nor: pointer to 'struct spi_nor'
333+
* @op: SPI memory operation. op->data.buf must be DMA-able.
334+
* @proto: SPI protocol to use for the register operation.
335+
*
336+
* Writing volatile registers are instant according to some manufacturers
337+
* (Cypress, Micron) and do not need any status polling.
338+
*
339+
* Return: zero on success, -errno otherwise
340+
*/
341+
int spi_nor_write_any_volatile_reg(struct spi_nor *nor, struct spi_mem_op *op,
342+
enum spi_nor_protocol proto)
343+
{
344+
int ret;
345+
346+
if (!nor->spimem)
347+
return -EOPNOTSUPP;
348+
349+
ret = spi_nor_write_enable(nor);
350+
if (ret)
351+
return ret;
352+
spi_nor_spimem_setup_op(nor, op, proto);
353+
return spi_nor_spimem_exec_op(nor, op);
354+
}
355+
310356
/**
311357
* spi_nor_write_enable() - Set write enable latch with Write Enable command.
312358
* @nor: pointer to 'struct spi_nor'.

drivers/mtd/spi-nor/core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len,
554554
u8 *buf);
555555
ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
556556
const u8 *buf);
557+
int spi_nor_read_any_reg(struct spi_nor *nor, struct spi_mem_op *op,
558+
enum spi_nor_protocol proto);
559+
int spi_nor_write_any_volatile_reg(struct spi_nor *nor, struct spi_mem_op *op,
560+
enum spi_nor_protocol proto);
557561
int spi_nor_erase_sector(struct spi_nor *nor, u32 addr);
558562

559563
int spi_nor_otp_read_secr(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf);

0 commit comments

Comments
 (0)