[PATCH 12/13] spi: airoha: set custom sector size equal to flash page size
From: Mikhail Kshevetskiy <hidden>
Date: 2025-08-14 23:12:38
Also in:
linux-spi, lkml
Subsystem:
airoha spi snfi driver, spi subsystem, the rest · Maintainers:
Lorenzo Bianconi, Ray Liu, Mark Brown, Linus Torvalds
Set custom sector size equal to flash page size including oob. Thus we will always read a single sector. The maximum custom sector size is 8187, so all possible flash sector sizes are supported. This patch is a necessary step to avoid reading flash page settings from SNFI registers during driver startup. Signed-off-by: Mikhail Kshevetskiy <redacted> --- drivers/spi/spi-airoha-snfi.c | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index bda85866d1ae..a96c87f01f52 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c@@ -629,10 +629,14 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc, u8 *txrx_buf = spi_get_ctldata(spi); dma_addr_t dma_addr; u32 val, rd_mode, opcode; + size_t bytes; int err; as_ctrl = spi_controller_get_devdata(spi->controller); + bytes = as_ctrl->nfi_cfg.sec_num * + (as_ctrl->nfi_cfg.sec_size + as_ctrl->nfi_cfg.spare_size); + /* * DUALIO and QUADIO opcodes are not supported by the spi controller, * replace them with supported opcodes.
@@ -690,18 +694,17 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc, FIELD_PREP(SPI_NFI_OPMODE, 6)); /* Set number of sector will be read */ - val = FIELD_PREP(SPI_NFI_SEC_NUM, as_ctrl->nfi_cfg.sec_num); err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, - SPI_NFI_SEC_NUM, val); + SPI_NFI_SEC_NUM, + FIELD_PREP(SPI_NFI_SEC_NUM, 1)); if (err) goto error_dma_mode_off; /* Set custom sector size */ - val = as_ctrl->nfi_cfg.sec_size + as_ctrl->nfi_cfg.spare_size; err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SECCUS_SIZE, SPI_NFI_CUS_SEC_SIZE | SPI_NFI_CUS_SEC_SIZE_EN, - FIELD_PREP(SPI_NFI_CUS_SEC_SIZE, val) | + FIELD_PREP(SPI_NFI_CUS_SEC_SIZE, bytes) | SPI_NFI_CUS_SEC_SIZE_EN); if (err) goto error_dma_mode_off;
@@ -719,12 +722,10 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc, goto error_dma_unmap; /* number of bytes to read via dma (whole flash page + oob) */ - val = (as_ctrl->nfi_cfg.sec_size + as_ctrl->nfi_cfg.spare_size) * - as_ctrl->nfi_cfg.sec_num; - val = FIELD_PREP(SPI_NFI_READ_DATA_BYTE_NUM, val); err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_MISC_CTL2, - SPI_NFI_READ_DATA_BYTE_NUM, val); + SPI_NFI_READ_DATA_BYTE_NUM, + FIELD_PREP(SPI_NFI_READ_DATA_BYTE_NUM, bytes)); if (err) goto error_dma_unmap;
@@ -813,10 +814,14 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc, struct airoha_snand_ctrl *as_ctrl; dma_addr_t dma_addr; u32 wr_mode, val, opcode; + size_t bytes; int err; as_ctrl = spi_controller_get_devdata(spi->controller); + bytes = as_ctrl->nfi_cfg.sec_num * + (as_ctrl->nfi_cfg.sec_size + as_ctrl->nfi_cfg.spare_size); + opcode = desc->info.op_tmpl.cmd.opcode; switch (opcode) { case SPI_NAND_OP_PROGRAM_LOAD_SINGLE:
@@ -832,9 +837,7 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc, return -EOPNOTSUPP; } - memset(txrx_buf, 0xff, - (as_ctrl->nfi_cfg.sec_size + as_ctrl->nfi_cfg.spare_size) * - as_ctrl->nfi_cfg.sec_num); + memset(txrx_buf, 0xff, bytes); memcpy(txrx_buf + offs, buf, len); err = airoha_snand_set_mode(as_ctrl, SPI_MODE_DMA);
@@ -870,18 +873,17 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc, goto error_dma_mode_off; /* Set number of sector will be written */ - val = FIELD_PREP(SPI_NFI_SEC_NUM, as_ctrl->nfi_cfg.sec_num); err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_CON, - SPI_NFI_SEC_NUM, val); + SPI_NFI_SEC_NUM, + FIELD_PREP(SPI_NFI_SEC_NUM, 1)); if (err) goto error_dma_mode_off; /* Set custom sector size */ - val = as_ctrl->nfi_cfg.sec_size + as_ctrl->nfi_cfg.spare_size; err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SECCUS_SIZE, SPI_NFI_CUS_SEC_SIZE | SPI_NFI_CUS_SEC_SIZE_EN, - FIELD_PREP(SPI_NFI_CUS_SEC_SIZE, val) | + FIELD_PREP(SPI_NFI_CUS_SEC_SIZE, bytes) | SPI_NFI_CUS_SEC_SIZE_EN); if (err) goto error_dma_mode_off;
@@ -898,12 +900,10 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc, goto error_dma_unmap; /* number of bytes to write via dma (whole flash page + oob) */ - val = (as_ctrl->nfi_cfg.sec_size + as_ctrl->nfi_cfg.spare_size) * - as_ctrl->nfi_cfg.sec_num; - val = FIELD_PREP(SPI_NFI_PROG_LOAD_BYTE_NUM, val); err = regmap_update_bits(as_ctrl->regmap_nfi, REG_SPI_NFI_SNF_MISC_CTL2, - SPI_NFI_PROG_LOAD_BYTE_NUM, val); + SPI_NFI_PROG_LOAD_BYTE_NUM, + FIELD_PREP(SPI_NFI_PROG_LOAD_BYTE_NUM, bytes)); if (err) goto error_dma_unmap;
--
2.50.1