mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module
@ 2026-12-02 20:40 Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 1/7] spi: spi-qpic-snand: use the common qcom_nandc_check_flash_errors() function Gabor Juhos
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Gabor Juhos @ 2026-12-02 20:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Md Sadre Alam, Sricharan Ramabadhran, Varadarajan Narayanan,
	linux-spi, linux-mtd, linux-kernel, Gabor Juhos

Since commit cfae2182fa7b ("mtd: rawnand: qcom: move common code to the
'qpic_common' module"), the 'qpic_common' module provides several generic
functions which can be utilized from the 'spi-qpic-snand' driver instead
of the locally implemented code.

This series converts the driver to use the common code to reduce code
duplication.

In order to make review easier, there are separate patches for each
functions and another one for reusing the 'qcom_nandc_read_stats'
structure.

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
Changes in v2:
- rebase on tip of spi/for-7.5
- rework patch 2/7 to remove dependency of change-id:
  '20260922-qpic-snand-fix-singlecw-readloc-c4c89b4369f5:v2', so the series
  can be applied without that specific change
- Link to v1: https://lore.kernel.org/r/20261109-qpic-snand-use-common-functions-v1-0-1e8601e2db84@gmail.com

---
Gabor Juhos (7):
      spi: spi-qpic-snand: use the common qcom_nandc_check_flash_errors() function
      spi: spi-qpic-snand: use the common qcom_nandc_config_page_read() function
      spi: spi-qpic-snand: use the common qcom_nandc_config_page_write() function
      spi: spi-qpic-snand: use the common qcom_nandc_config_cw_write() function
      spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_first() function
      spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_last() function
      spi: spi-qpic-snand: use the common 'qcom_nandc_read_stats' structure

 drivers/spi/spi-qpic-snand.c | 137 ++++++++-----------------------------------
 1 file changed, 24 insertions(+), 113 deletions(-)
---
base-commit: 1ce9be23c0e4ab6dc0df8aca2a526b9aed435032
change-id: 20261028-qpic-snand-use-common-functions-12b18fc7a1e5

Best regards,
-- 
Gabor Juhos <j4g8y7@gmail.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/7] spi: spi-qpic-snand: use the common qcom_nandc_check_flash_errors() function
  2026-12-02 20:40 [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module Gabor Juhos
@ 2026-12-02 20:40 ` Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 2/7] spi: spi-qpic-snand: use the common qcom_nandc_config_page_read() function Gabor Juhos
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Gabor Juhos @ 2026-12-02 20:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Md Sadre Alam, Sricharan Ramabadhran, Varadarajan Narayanan,
	linux-spi, linux-mtd, linux-kernel, Gabor Juhos

The common function from the 'qpic_common' module provides the same
functionality as the locally implemented counterpart.

Use the common function and remove the local one in order to reduce
code duplication.

No functional changes intended.

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
Changes in v2:
- No change.
---
 drivers/spi/spi-qpic-snand.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index 6cb6e02d2498b..1f5d67c9be36d 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -603,22 +603,6 @@ static void qcom_spi_config_single_cw_page_read(struct qcom_nand_controller *sna
 	qcom_read_reg_dma(snandc, NAND_FLASH_STATUS, 1, 0);
 }
 
-static int qcom_spi_check_raw_flash_errors(struct qcom_nand_controller *snandc, int cw_cnt)
-{
-	int i;
-
-	qcom_nandc_dev_to_mem(snandc, true);
-
-	for (i = 0; i < cw_cnt; i++) {
-		u32 flash = le32_to_cpu(snandc->reg_read_buf[i]);
-
-		if (flash & (FS_OP_ERR | FS_MPU_ERR))
-			return -EIO;
-	}
-
-	return 0;
-}
-
 static int qcom_spi_read_last_cw(struct qcom_nand_controller *snandc,
 				 const struct spi_mem_op *op)
 {
@@ -662,7 +646,7 @@ static int qcom_spi_read_last_cw(struct qcom_nand_controller *snandc,
 		return ret;
 	}
 
-	ret = qcom_spi_check_raw_flash_errors(snandc, 1);
+	ret = qcom_nandc_check_flash_errors(snandc, 1);
 	if (ret)
 		return ret;
 
@@ -830,7 +814,7 @@ static int qcom_spi_read_cw_raw(struct qcom_nand_controller *snandc, u8 *data_bu
 		return ret;
 	}
 
-	return qcom_spi_check_raw_flash_errors(snandc, 1);
+	return qcom_nandc_check_flash_errors(snandc, 1);
 }
 
 static int qcom_spi_read_page_raw(struct qcom_nand_controller *snandc,

-- 
2.56.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 2/7] spi: spi-qpic-snand: use the common qcom_nandc_config_page_read() function
  2026-12-02 20:40 [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 1/7] spi: spi-qpic-snand: use the common qcom_nandc_check_flash_errors() function Gabor Juhos
@ 2026-12-02 20:40 ` Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 3/7] spi: spi-qpic-snand: use the common qcom_nandc_config_page_write() function Gabor Juhos
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Gabor Juhos @ 2026-12-02 20:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Md Sadre Alam, Sricharan Ramabadhran, Varadarajan Narayanan,
	linux-spi, linux-mtd, linux-kernel, Gabor Juhos

The common function from the 'qpic_common' module provides the same
functionality as the locally implemented counterpart.

Use the common function and remove the local one in order to reduce
code duplication.

No functional changes intended.

Note: in comparison to the local version, the generic function runs
additional code when the 'nandc->props->qpic_version2' flag is not
set, but that does not affect the behaviour of the current driver,
because the respective flag is set since commit 52efc89ccf66 ("spi:
spi-qpic-snand: set 'qpic_version2' flag").

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
Changes in v2:
- rework to avoid depedency of change-id:
  '20260922-qpic-snand-fix-singlecw-readloc-c4c89b4369f5:v2'
---
 drivers/spi/spi-qpic-snand.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index 1f5d67c9be36d..23bf86396445f 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -518,17 +518,6 @@ static void qcom_spi_set_read_loc(struct qcom_nand_controller *snandc, int cw, i
 						   read_size, is_last_read_loc);
 }
 
-static void qcom_spi_config_page_read(struct qcom_nand_controller *snandc)
-{
-	qcom_write_reg_dma(snandc, &snandc->regs->addr0, NAND_ADDR0, 2, 0);
-	qcom_write_reg_dma(snandc, &snandc->regs->cfg0, NAND_DEV0_CFG0, 3, 0);
-	qcom_write_reg_dma(snandc, &snandc->regs->erased_cw_detect_cfg_clr,
-			   NAND_ERASED_CW_DETECT_CFG, 1, 0);
-	qcom_write_reg_dma(snandc, &snandc->regs->erased_cw_detect_cfg_set,
-			   NAND_ERASED_CW_DETECT_CFG, 1,
-			   NAND_ERASED_CW_SET | NAND_BAM_NEXT_SGL);
-}
-
 static void
 qcom_spi_config_cw_read(struct qcom_nand_controller *snandc, bool use_ecc, int cw)
 {
@@ -591,7 +580,7 @@ static void qcom_spi_config_single_cw_page_read(struct qcom_nand_controller *sna
 	__le32 *reg = &snandc->regs->read_location0;
 	int num_cw = snandc->qspi->num_cw;
 
-	qcom_spi_config_page_read(snandc);
+	qcom_nandc_config_page_read(snandc);
 
 	if (cw == (num_cw - 1)) {
 		reg = &snandc->regs->read_location_last0;
@@ -769,7 +758,7 @@ static int qcom_spi_read_cw_raw(struct qcom_nand_controller *snandc, u8 *data_bu
 	snandc->regs->exec = cpu_to_le32(1);
 
 	qcom_spi_set_read_loc(snandc, raw_cw, 0, 0, ecc_cfg->cw_size, 1);
-	qcom_spi_config_page_read(snandc);
+	qcom_nandc_config_page_read(snandc);
 
 	data_size1 = mtd->writesize - ecc_cfg->cw_size * (num_cw - 1);
 	oob_size1 = ecc_cfg->bbm_size;
@@ -874,7 +863,7 @@ static int qcom_spi_read_page_ecc(struct qcom_nand_controller *snandc,
 	snandc->regs->exec = cpu_to_le32(1);
 
 	qcom_clear_bam_transaction(snandc);
-	qcom_spi_config_page_read(snandc);
+	qcom_nandc_config_page_read(snandc);
 
 	for (i = 0; i < num_cw; i++) {
 		int data_size, oob_size;
@@ -955,7 +944,7 @@ static int qcom_spi_read_page_oob(struct qcom_nand_controller *snandc,
 	snandc->regs->ecc_bch_cfg = cpu_to_le32(ecc_bch_cfg);
 	snandc->regs->exec = cpu_to_le32(1);
 
-	qcom_spi_config_page_read(snandc);
+	qcom_nandc_config_page_read(snandc);
 
 	for (i = 0; i < num_cw; i++) {
 		int data_size, oob_size;

-- 
2.56.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 3/7] spi: spi-qpic-snand: use the common qcom_nandc_config_page_write() function
  2026-12-02 20:40 [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 1/7] spi: spi-qpic-snand: use the common qcom_nandc_check_flash_errors() function Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 2/7] spi: spi-qpic-snand: use the common qcom_nandc_config_page_read() function Gabor Juhos
@ 2026-12-02 20:40 ` Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 4/7] spi: spi-qpic-snand: use the common qcom_nandc_config_cw_write() function Gabor Juhos
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Gabor Juhos @ 2026-12-02 20:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Md Sadre Alam, Sricharan Ramabadhran, Varadarajan Narayanan,
	linux-spi, linux-mtd, linux-kernel, Gabor Juhos

The common function from the 'qpic_common' module provides the same
functionality as the locally implemented counterpart.

Use the common function and remove the local one in order to reduce
code duplication.

No functional changes intended.

Note: in comparison to the local version, the generic function runs
additional code when the 'nandc->props->qpic_version2' flag is not
set, but that does not affect the behaviour of the current driver,
because the respective flag is set since commit 52efc89ccf66 ("spi:
spi-qpic-snand: set 'qpic_version2' flag").

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
Changes in v2:
- No change.
---
 drivers/spi/spi-qpic-snand.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index 23bf86396445f..a3c921f4ff146 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -1074,12 +1074,6 @@ static int qcom_spi_read_page(struct qcom_nand_controller *snandc,
 	return 0;
 }
 
-static void qcom_spi_config_page_write(struct qcom_nand_controller *snandc)
-{
-	qcom_write_reg_dma(snandc, &snandc->regs->addr0, NAND_ADDR0, 2, 0);
-	qcom_write_reg_dma(snandc, &snandc->regs->cfg0, NAND_DEV0_CFG0, 3, 0);
-}
-
 static void qcom_spi_config_cw_write(struct qcom_nand_controller *snandc)
 {
 	qcom_write_reg_dma(snandc, &snandc->regs->cmd, NAND_FLASH_CMD, 1, NAND_BAM_NEXT_SGL);
@@ -1124,7 +1118,7 @@ static int qcom_spi_program_raw(struct qcom_nand_controller *snandc,
 	snandc->regs->ecc_bch_cfg = cpu_to_le32(ecc_bch_cfg);
 	snandc->regs->exec = cpu_to_le32(1);
 
-	qcom_spi_config_page_write(snandc);
+	qcom_nandc_config_page_write(snandc);
 
 	for (i = 0; i < num_cw; i++) {
 		int data_size1, data_size2, oob_size1, oob_size2;
@@ -1205,7 +1199,7 @@ static int qcom_spi_program_ecc(struct qcom_nand_controller *snandc,
 	snandc->regs->ecc_bch_cfg = cpu_to_le32(ecc_bch_cfg);
 	snandc->regs->exec = cpu_to_le32(1);
 
-	qcom_spi_config_page_write(snandc);
+	qcom_nandc_config_page_write(snandc);
 
 	for (i = 0; i < num_cw; i++) {
 		int data_size, oob_size;
@@ -1286,7 +1280,7 @@ static int qcom_spi_program_oob(struct qcom_nand_controller *snandc,
 	/* override new oob content to last codeword */
 	mtd_ooblayout_get_databytes(snandc->qspi->mtd, snandc->data_buffer + data_size,
 				    oob_buf, 0, snandc->qspi->mtd->oobavail);
-	qcom_spi_config_page_write(snandc);
+	qcom_nandc_config_page_write(snandc);
 	qcom_write_data_dma(snandc, FLASH_BUF_ACC, snandc->data_buffer, data_size + oob_size, 0);
 	qcom_spi_config_cw_write(snandc);
 

-- 
2.56.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 4/7] spi: spi-qpic-snand: use the common qcom_nandc_config_cw_write() function
  2026-12-02 20:40 [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module Gabor Juhos
                   ` (2 preceding siblings ...)
  2026-12-02 20:40 ` [PATCH v2 3/7] spi: spi-qpic-snand: use the common qcom_nandc_config_page_write() function Gabor Juhos
@ 2026-12-02 20:40 ` Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 5/7] spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_first() function Gabor Juhos
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Gabor Juhos @ 2026-12-02 20:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Md Sadre Alam, Sricharan Ramabadhran, Varadarajan Narayanan,
	linux-spi, linux-mtd, linux-kernel, Gabor Juhos

The common function from the 'qpic_common' module provides the same
functionality as the locally implemented counterpart.

Use the common function and remove the local one in order to reduce
code duplication.

No functional changes intended.

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
Changes in v2:
- No change.
---
 drivers/spi/spi-qpic-snand.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index a3c921f4ff146..e9c1acc328eff 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -1074,17 +1074,6 @@ static int qcom_spi_read_page(struct qcom_nand_controller *snandc,
 	return 0;
 }
 
-static void qcom_spi_config_cw_write(struct qcom_nand_controller *snandc)
-{
-	qcom_write_reg_dma(snandc, &snandc->regs->cmd, NAND_FLASH_CMD, 1, NAND_BAM_NEXT_SGL);
-	qcom_write_reg_dma(snandc, &snandc->regs->exec, NAND_EXEC_CMD, 1, NAND_BAM_NEXT_SGL);
-	qcom_read_reg_dma(snandc, NAND_FLASH_STATUS, 1, NAND_BAM_NEXT_SGL);
-
-	qcom_write_reg_dma(snandc, &snandc->regs->clrflashstatus, NAND_FLASH_STATUS, 1, 0);
-	qcom_write_reg_dma(snandc, &snandc->regs->clrreadstatus, NAND_READ_STATUS, 1,
-			   NAND_BAM_NEXT_SGL);
-}
-
 static int qcom_spi_program_raw(struct qcom_nand_controller *snandc,
 				const struct spi_mem_op *op)
 {
@@ -1155,7 +1144,7 @@ static int qcom_spi_program_raw(struct qcom_nand_controller *snandc,
 		qcom_write_data_dma(snandc, reg_off, oob_buf, oob_size2, 0);
 		oob_buf += oob_size2;
 
-		qcom_spi_config_cw_write(snandc);
+		qcom_nandc_config_cw_write(snandc);
 	}
 
 	ret = qcom_submit_descs(snandc);
@@ -1225,7 +1214,7 @@ static int qcom_spi_program_ecc(struct qcom_nand_controller *snandc,
 			}
 		}
 
-		qcom_spi_config_cw_write(snandc);
+		qcom_nandc_config_cw_write(snandc);
 
 		if (data_buf)
 			data_buf += data_size;
@@ -1282,7 +1271,7 @@ static int qcom_spi_program_oob(struct qcom_nand_controller *snandc,
 				    oob_buf, 0, snandc->qspi->mtd->oobavail);
 	qcom_nandc_config_page_write(snandc);
 	qcom_write_data_dma(snandc, FLASH_BUF_ACC, snandc->data_buffer, data_size + oob_size, 0);
-	qcom_spi_config_cw_write(snandc);
+	qcom_nandc_config_cw_write(snandc);
 
 	ret = qcom_submit_descs(snandc);
 	if (ret) {

-- 
2.56.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 5/7] spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_first() function
  2026-12-02 20:40 [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module Gabor Juhos
                   ` (3 preceding siblings ...)
  2026-12-02 20:40 ` [PATCH v2 4/7] spi: spi-qpic-snand: use the common qcom_nandc_config_cw_write() function Gabor Juhos
@ 2026-12-02 20:40 ` Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 6/7] spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_last() function Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 7/7] spi: spi-qpic-snand: use the common 'qcom_nandc_read_stats' structure Gabor Juhos
  6 siblings, 0 replies; 8+ messages in thread
From: Gabor Juhos @ 2026-12-02 20:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Md Sadre Alam, Sricharan Ramabadhran, Varadarajan Narayanan,
	linux-spi, linux-mtd, linux-kernel, Gabor Juhos

The common function from the 'qpic_common' module provides the same
functionality as the locally implemented counterpart.

Use the common function and remove the local one in order to reduce
code duplication.

No functional changes intended.

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
Changes in v2:
- No change.
---
 drivers/spi/spi-qpic-snand.c | 27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index e9c1acc328eff..67e8062107a51 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -122,27 +122,6 @@ struct qpic_spi_nand {
 	bool quad_mode;
 };
 
-static void qcom_spi_set_read_loc_first(struct qcom_nand_controller *snandc,
-					int reg, int cw_offset, int read_size,
-					int is_last_read_loc)
-{
-	__le32 locreg_val;
-	u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
-		  FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
-		  FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
-
-	locreg_val = cpu_to_le32(val);
-
-	if (reg == NAND_READ_LOCATION_0)
-		snandc->regs->read_location0 = locreg_val;
-	else if (reg == NAND_READ_LOCATION_1)
-		snandc->regs->read_location1 = locreg_val;
-	else if (reg == NAND_READ_LOCATION_2)
-		snandc->regs->read_location2 = locreg_val;
-	else if (reg == NAND_READ_LOCATION_3)
-		snandc->regs->read_location3 = locreg_val;
-}
-
 static void qcom_spi_set_read_loc_last(struct qcom_nand_controller *snandc,
 				       int reg, int cw_offset, int read_size,
 				       int is_last_read_loc)
@@ -514,8 +493,10 @@ static void qcom_spi_set_read_loc(struct qcom_nand_controller *snandc, int cw, i
 		return qcom_spi_set_read_loc_last(snandc, reg_base, cw_offset,
 						  read_size, is_last_read_loc);
 	else
-		return qcom_spi_set_read_loc_first(snandc, reg_base, cw_offset,
-						   read_size, is_last_read_loc);
+		return qcom_nandc_set_read_loc_first(snandc, reg_base,
+						     cw_offset,
+						     read_size,
+						     is_last_read_loc);
 }
 
 static void

-- 
2.56.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 6/7] spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_last() function
  2026-12-02 20:40 [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module Gabor Juhos
                   ` (4 preceding siblings ...)
  2026-12-02 20:40 ` [PATCH v2 5/7] spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_first() function Gabor Juhos
@ 2026-12-02 20:40 ` Gabor Juhos
  2026-12-02 20:40 ` [PATCH v2 7/7] spi: spi-qpic-snand: use the common 'qcom_nandc_read_stats' structure Gabor Juhos
  6 siblings, 0 replies; 8+ messages in thread
From: Gabor Juhos @ 2026-12-02 20:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Md Sadre Alam, Sricharan Ramabadhran, Varadarajan Narayanan,
	linux-spi, linux-mtd, linux-kernel, Gabor Juhos

The common function from the 'qpic_common' module provides the same
functionality as the locally implemented counterpart.

Use the common function and remove the local one in order to reduce
code duplication.

No functional changes intended.

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
Changes in v2:
- No change.
---
 drivers/spi/spi-qpic-snand.c | 26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index 67e8062107a51..12a0f0bdcfdf6 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -122,27 +122,6 @@ struct qpic_spi_nand {
 	bool quad_mode;
 };
 
-static void qcom_spi_set_read_loc_last(struct qcom_nand_controller *snandc,
-				       int reg, int cw_offset, int read_size,
-				       int is_last_read_loc)
-{
-	__le32 locreg_val;
-	u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
-		  FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
-		  FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
-
-	locreg_val = cpu_to_le32(val);
-
-	if (reg == NAND_READ_LOCATION_LAST_CW_0)
-		snandc->regs->read_location_last0 = locreg_val;
-	else if (reg == NAND_READ_LOCATION_LAST_CW_1)
-		snandc->regs->read_location_last1 = locreg_val;
-	else if (reg == NAND_READ_LOCATION_LAST_CW_2)
-		snandc->regs->read_location_last2 = locreg_val;
-	else if (reg == NAND_READ_LOCATION_LAST_CW_3)
-		snandc->regs->read_location_last3 = locreg_val;
-}
-
 static struct qcom_nand_controller *nand_to_qcom_snand(struct nand_device *nand)
 {
 	struct nand_ecc_engine *eng = nand->ecc.engine;
@@ -490,8 +469,9 @@ static void qcom_spi_set_read_loc(struct qcom_nand_controller *snandc, int cw, i
 	reg_base += reg * 4;
 
 	if (cw == (num_cw - 1))
-		return qcom_spi_set_read_loc_last(snandc, reg_base, cw_offset,
-						  read_size, is_last_read_loc);
+		return qcom_nandc_set_read_loc_last(snandc, reg_base, cw_offset,
+						    read_size,
+						    is_last_read_loc);
 	else
 		return qcom_nandc_set_read_loc_first(snandc, reg_base,
 						     cw_offset,

-- 
2.56.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 7/7] spi: spi-qpic-snand: use the common 'qcom_nandc_read_stats' structure
  2026-12-02 20:40 [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module Gabor Juhos
                   ` (5 preceding siblings ...)
  2026-12-02 20:40 ` [PATCH v2 6/7] spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_last() function Gabor Juhos
@ 2026-12-02 20:40 ` Gabor Juhos
  6 siblings, 0 replies; 8+ messages in thread
From: Gabor Juhos @ 2026-12-02 20:40 UTC (permalink / raw)
  To: Mark Brown
  Cc: Md Sadre Alam, Sricharan Ramabadhran, Varadarajan Narayanan,
	linux-spi, linux-mtd, linux-kernel, Gabor Juhos

The 'qcom_nandc_read_stats' structure defined in the 'nand-qpic-common.h'
header and the locally defined 'snandc_read_status' structure are
identical type wise and both are serving the same purpose.

Drop the local structure and use the global one instead to reduce
duplication.

No functional changes.

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
Changes in v2:
- No change.
---
 drivers/spi/spi-qpic-snand.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index 12a0f0bdcfdf6..36bbcf30313c7 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -64,12 +64,6 @@
 #define BAD_BLOCK_MARKER_SIZE		0x2
 #define OOB_BUF_SIZE			128
 
-struct snandc_read_status {
-	__le32 snandc_flash;
-	__le32 snandc_buffer;
-	__le32 snandc_erased_cw;
-};
-
 /*
  * ECC state struct
  * @corrected:		ECC corrected
@@ -621,7 +615,7 @@ static int qcom_spi_read_last_cw(struct qcom_nand_controller *snandc,
 
 static int qcom_spi_check_error(struct qcom_nand_controller *snandc)
 {
-	struct snandc_read_status *buf;
+	struct qcom_nandc_read_stats *buf;
 	struct qpic_ecc *ecc_cfg = snandc->qspi->ecc;
 	int i, num_cw = snandc->qspi->num_cw;
 	bool flash_op_err = false, erased;
@@ -632,14 +626,14 @@ static int qcom_spi_check_error(struct qcom_nand_controller *snandc)
 	snandc->qspi->ecc_stats.corrected = 0;
 
 	qcom_nandc_dev_to_mem(snandc, true);
-	buf = (struct snandc_read_status *)snandc->reg_read_buf;
+	buf = (struct qcom_nandc_read_stats *)snandc->reg_read_buf;
 
 	for (i = 0; i < num_cw; i++, buf++) {
 		u32 flash, buffer, erased_cw;
 
-		flash = le32_to_cpu(buf->snandc_flash);
-		buffer = le32_to_cpu(buf->snandc_buffer);
-		erased_cw = le32_to_cpu(buf->snandc_erased_cw);
+		flash = le32_to_cpu(buf->flash);
+		buffer = le32_to_cpu(buf->buffer);
+		erased_cw = le32_to_cpu(buf->erased_cw);
 
 		if ((flash & FS_OP_ERR) && (buffer & BS_UNCORRECTABLE_BIT)) {
 			if (ecc_cfg->bch_enabled)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-02 20:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 20:40 [PATCH v2 0/7] spi: spi-qpic-snand: use generic code from the 'qpic_common' module Gabor Juhos
2026-12-02 20:40 ` [PATCH v2 1/7] spi: spi-qpic-snand: use the common qcom_nandc_check_flash_errors() function Gabor Juhos
2026-12-02 20:40 ` [PATCH v2 2/7] spi: spi-qpic-snand: use the common qcom_nandc_config_page_read() function Gabor Juhos
2026-12-02 20:40 ` [PATCH v2 3/7] spi: spi-qpic-snand: use the common qcom_nandc_config_page_write() function Gabor Juhos
2026-12-02 20:40 ` [PATCH v2 4/7] spi: spi-qpic-snand: use the common qcom_nandc_config_cw_write() function Gabor Juhos
2026-12-02 20:40 ` [PATCH v2 5/7] spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_first() function Gabor Juhos
2026-12-02 20:40 ` [PATCH v2 6/7] spi: spi-qpic-snand: use the common qcom_nandc_set_read_loc_last() function Gabor Juhos
2026-12-02 20:40 ` [PATCH v2 7/7] spi: spi-qpic-snand: use the common 'qcom_nandc_read_stats' structure Gabor Juhos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®