public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/3] mtd: spi-nand: Add support for randomizer feature
@ 2026-02-11 10:05 Cheng Ming Lin
  2026-02-11 10:05 ` [PATCH v5 1/3] dt-bindings: mtd: spinand: Add randomizer enable/disable properties Cheng Ming Lin
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Cheng Ming Lin @ 2026-02-11 10:05 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Tudor Ambarus, Mikhail Kshevetskiy, Pablo Martin-Gomez,
	Tianling Shen, Pratyush Yadav, linux-mtd, devicetree,
	linux-kernel, alvinzhou, Cheng Ming Lin

From: Cheng Ming Lin <chengminglin@mxic.com.tw>

This patch series introduces randomizer support for SPI NAND devices.

- Patch 1: add the nand-randomizer-enable and nand-randomizer-disable
           boolean properties to the generic nand-chip.yaml bindings.
- Patch 2: add the initialization logic and the set_randomizer callback
           to the core framework. The core will now parse the device tree
           properties and enable or disable the randomizer accordingly
           during spinand_init.
- Patch 3: implement the set_randomizer callback specifically for Macronix
           chips (MX35LF/UF series) to handle the vendor-specific register
           operations.

v5:
* Promoted the randomizer configuration to use generic NAND properties
  (nand-randomizer-enable and nand-randomizer-disable) instead of
  vendor-specific bindings.
* Refactored the initialization architecture in core.c. The core framework
  is now responsible for parsing the device tree properties and deciding
  whether to enable or disable the randomizer.

v4:
* Fix a build error in spinand_randomizer_init() where a value was
  returned from a void function. (Reported by kernel test robot)
* Update the return type to int.

v3:
* Revert the device tree property to the vendor-specific
  "mxic,randomizer-enable" to strictly follow vendor-specific bindings.

* Update the 'set_randomizer' callback signature to accept a boolean
  'enable' argument, allowing the feature to be explicitly enabled or
  disabled.

* Switch the implementation to use the standard SET_FEATURE command
  to modify the Configuration Register (0x10), replacing the previous
  special program command method.

v2:
* Create a global NAND DT property
Cheng Ming Lin (3):
  dt-bindings: mtd: spinand: Add randomizer enable/disable properties
  mtd: spi-nand: Add support for randomizer
  mtd: spi-nand: macronix: Enable randomizer support

 .../devicetree/bindings/mtd/nand-chip.yaml    |  8 ++++
 drivers/mtd/nand/spi/core.c                   | 27 +++++++++++
 drivers/mtd/nand/spi/macronix.c               | 46 ++++++++++++++-----
 include/linux/mtd/spinand.h                   |  9 ++++
 4 files changed, 79 insertions(+), 11 deletions(-)

-- 
2.25.1


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

* [PATCH v5 1/3] dt-bindings: mtd: spinand: Add randomizer enable/disable properties
  2026-02-11 10:05 [PATCH v5 0/3] mtd: spi-nand: Add support for randomizer feature Cheng Ming Lin
@ 2026-02-11 10:05 ` Cheng Ming Lin
  2026-02-12  7:33   ` Krzysztof Kozlowski
  2026-02-11 10:05 ` [PATCH v5 2/3] mtd: spi-nand: Add support for randomizer Cheng Ming Lin
  2026-02-11 10:05 ` [PATCH v5 3/3] mtd: spi-nand: macronix: Enable randomizer support Cheng Ming Lin
  2 siblings, 1 reply; 8+ messages in thread
From: Cheng Ming Lin @ 2026-02-11 10:05 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Tudor Ambarus, Mikhail Kshevetskiy, Pablo Martin-Gomez,
	Tianling Shen, Pratyush Yadav, linux-mtd, devicetree,
	linux-kernel, alvinzhou, Cheng Ming Lin

From: Cheng Ming Lin <chengminglin@mxic.com.tw>

Add "nand-randomizer-enable" and "nand-randomizer-disable" boolean
properties.

These properties allow enabling or disabling the randomizer feature
via the device tree.

According to JEDEC standard JESD22-A117E, no single data pattern
represents a universal worst-case for all NAND flash failure mechanisms.
Different patterns, such as fully programmed, checkerboard, or mostly
erased, can disproportionately stress specific cells (e.g., programmed,
erased, or those influenced by adjacent states).

Given that no fixed pattern can cover all scenarios, the use of a
randomized data pattern is a practical and effective mitigation strategy.
Our hardware implements a randomizer feature that scrambles user data
before it is written to the flash and restores the original data upon read.

This ensures the data stored on the media is more evenly distributed,
thus reducing pattern-dependent degradation. This is especially crucial
for preventing errors caused by unbalanced data (e.g., all zeros or
all ones) in blocks with high program/erase (P/E) cycle counts.
Ultimately, the randomizer improves the long-term reliability and
endurance of the flash device.

Please refer to the following link for randomizer feature:
Link: https://www.mxic.com.tw/Lists/ApplicationNote/Attachments/2151/AN1051V1-The%20Introduction%20of%20Randomizer%20Feature%20on%20MX30xFxG28AD_MX35xFxG24AD.

Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
---
 Documentation/devicetree/bindings/mtd/nand-chip.yaml | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/mtd/nand-chip.yaml b/Documentation/devicetree/bindings/mtd/nand-chip.yaml
index 609d4a4ddd80..2fcbc4b73e95 100644
--- a/Documentation/devicetree/bindings/mtd/nand-chip.yaml
+++ b/Documentation/devicetree/bindings/mtd/nand-chip.yaml
@@ -67,6 +67,14 @@ properties:
       the secure regions present.
     $ref: /schemas/types.yaml#/definitions/uint64-matrix
 
+  nand-randomizer-enable:
+    description: Enable the randomizer feature.
+    type: boolean
+
+  nand-randomizer-disable:
+    description: Disable the randomizer feature.
+    type: boolean
+
 required:
   - reg
 
-- 
2.25.1


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

* [PATCH v5 2/3] mtd: spi-nand: Add support for randomizer
  2026-02-11 10:05 [PATCH v5 0/3] mtd: spi-nand: Add support for randomizer feature Cheng Ming Lin
  2026-02-11 10:05 ` [PATCH v5 1/3] dt-bindings: mtd: spinand: Add randomizer enable/disable properties Cheng Ming Lin
@ 2026-02-11 10:05 ` Cheng Ming Lin
  2026-02-11 10:05 ` [PATCH v5 3/3] mtd: spi-nand: macronix: Enable randomizer support Cheng Ming Lin
  2 siblings, 0 replies; 8+ messages in thread
From: Cheng Ming Lin @ 2026-02-11 10:05 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Tudor Ambarus, Mikhail Kshevetskiy, Pablo Martin-Gomez,
	Tianling Shen, Pratyush Yadav, linux-mtd, devicetree,
	linux-kernel, alvinzhou, Cheng Ming Lin

From: Cheng Ming Lin <chengminglin@mxic.com.tw>

This patch adds support for the randomizer feature.

It introduces a 'set_randomizer' callback in 'struct spinand_info' and
'struct spinand_device'.

If a driver implements this callback, the core will invoke it during
device initialization (spinand_init) to enable or disable the randomizer
feature based on the device tree configuration.

Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
---
 drivers/mtd/nand/spi/core.c | 27 +++++++++++++++++++++++++++
 include/linux/mtd/spinand.h |  9 +++++++++
 2 files changed, 36 insertions(+)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index d207286572d8..d6b12d05c346 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -1218,6 +1218,29 @@ static int spinand_create_dirmaps(struct spinand_device *spinand)
 	return 0;
 }
 
+static int spinand_randomizer_init(struct spinand_device *spinand)
+{
+	struct device_node *np = spinand->spimem->spi->dev.of_node;
+	bool enable = false;
+	int ret;
+
+	if (!spinand->set_randomizer)
+		return 0;
+
+	if (of_property_read_bool(np, "nand-enable-randomizer"))
+		enable = true;
+	else if (of_property_read_bool(np, "nand-disable-randomizer"))
+		enable = false;
+	else
+		return 0;
+
+	ret = spinand->set_randomizer(spinand, enable);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 static const struct nand_ops spinand_ops = {
 	.erase = spinand_erase,
 	.markbad = spinand_markbad,
@@ -1412,6 +1435,7 @@ int spinand_match_and_init(struct spinand_device *spinand,
 		spinand->user_otp = &table[i].user_otp;
 		spinand->read_retries = table[i].read_retries;
 		spinand->set_read_retry = table[i].set_read_retry;
+		spinand->set_randomizer = table[i].set_randomizer;
 
 		op = spinand_select_op_variant(spinand,
 					       info->op_variants.read_cache);
@@ -1588,6 +1612,9 @@ static int spinand_init(struct spinand_device *spinand)
 	 * ECC initialization must have happened previously.
 	 */
 	spinand_cont_read_init(spinand);
+	ret = spinand_randomizer_init(spinand);
+	if (ret)
+		goto err_cleanup_nanddev;
 
 	mtd->_read_oob = spinand_mtd_read;
 	mtd->_write_oob = spinand_mtd_write;
diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h
index ce76f5c632e1..e01315a71222 100644
--- a/include/linux/mtd/spinand.h
+++ b/include/linux/mtd/spinand.h
@@ -501,6 +501,7 @@ struct spinand_user_otp {
  * @user_otp: SPI NAND user OTP info.
  * @read_retries: the number of read retry modes supported
  * @set_read_retry: enable/disable read retry for data recovery
+ * @set_randomizer: enable/disable randomizer support
  *
  * Each SPI NAND manufacturer driver should have a spinand_info table
  * describing all the chips supported by the driver.
@@ -527,6 +528,8 @@ struct spinand_info {
 	unsigned int read_retries;
 	int (*set_read_retry)(struct spinand_device *spinand,
 			     unsigned int read_retry);
+	int (*set_randomizer)(struct spinand_device *spinand,
+			      bool enable);
 };
 
 #define SPINAND_ID(__method, ...)					\
@@ -580,6 +583,9 @@ struct spinand_info {
 	.read_retries = __read_retries,					\
 	.set_read_retry = __set_read_retry
 
+#define SPINAND_RANDOMIZER(__set_randomizer)				\
+	.set_randomizer = __set_randomizer
+
 #define SPINAND_INFO(__model, __id, __memorg, __eccreq, __op_variants,	\
 		     __flags, ...)					\
 	{								\
@@ -635,6 +641,7 @@ struct spinand_dirmap {
  * @user_otp: SPI NAND user OTP info.
  * @read_retries: the number of read retry modes supported
  * @set_read_retry: Enable/disable the read retry feature
+ * @set_randomizer: Enable/disable the randomizer feature
  */
 struct spinand_device {
 	struct nand_device base;
@@ -668,6 +675,8 @@ struct spinand_device {
 	bool cont_read_possible;
 	int (*set_cont_read)(struct spinand_device *spinand,
 			     bool enable);
+	int (*set_randomizer)(struct spinand_device *spinand,
+			      bool enable);
 
 	const struct spinand_fact_otp *fact_otp;
 	const struct spinand_user_otp *user_otp;
-- 
2.25.1


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

* [PATCH v5 3/3] mtd: spi-nand: macronix: Enable randomizer support
  2026-02-11 10:05 [PATCH v5 0/3] mtd: spi-nand: Add support for randomizer feature Cheng Ming Lin
  2026-02-11 10:05 ` [PATCH v5 1/3] dt-bindings: mtd: spinand: Add randomizer enable/disable properties Cheng Ming Lin
  2026-02-11 10:05 ` [PATCH v5 2/3] mtd: spi-nand: Add support for randomizer Cheng Ming Lin
@ 2026-02-11 10:05 ` Cheng Ming Lin
  2026-02-12 10:55   ` Miquel Raynal
  2 siblings, 1 reply; 8+ messages in thread
From: Cheng Ming Lin @ 2026-02-11 10:05 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: Tudor Ambarus, Mikhail Kshevetskiy, Pablo Martin-Gomez,
	Tianling Shen, Pratyush Yadav, linux-mtd, devicetree,
	linux-kernel, alvinzhou, Cheng Ming Lin

From: Cheng Ming Lin <chengminglin@mxic.com.tw>

Implement the 'set_randomizer' callback for Macronix SPI NAND chips.
The randomizer is enabled by setting bit 1 of the Configuration Register
(address 0x10).

This patch adds support for the following chips:
  - MX35LFxG24AD series
  - MX35UFxG24AD series

When the randomizer is enabled, data is scrambled internally during
program operations and automatically descrambled during read operations.
This helps reduce bit errors caused by program disturbance.

Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
---
 drivers/mtd/nand/spi/macronix.c | 46 +++++++++++++++++++++++++--------
 1 file changed, 35 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
index edf63b9996cf..3a9ab146426b 100644
--- a/drivers/mtd/nand/spi/macronix.c
+++ b/drivers/mtd/nand/spi/macronix.c
@@ -14,6 +14,8 @@
 #define MACRONIX_ECCSR_BF_LAST_PAGE(eccsr) FIELD_GET(GENMASK(3, 0), eccsr)
 #define MACRONIX_ECCSR_BF_ACCUMULATED_PAGES(eccsr) FIELD_GET(GENMASK(7, 4), eccsr)
 #define MACRONIX_CFG_CONT_READ         BIT(2)
+#define MACRONIX_CFG_RANDOMIZER_EN     BIT(1)
+#define MACRONIX_FEATURE_ADDR_RANDOMIZER 0x10
 #define MACRONIX_FEATURE_ADDR_READ_RETRY 0x70
 #define MACRONIX_NUM_READ_RETRY_MODES 5
 
@@ -146,7 +148,7 @@ static int macronix_set_cont_read(struct spinand_device *spinand, bool enable)
  * Return: 0 on success, a negative error code otherwise.
  */
 static int macronix_set_read_retry(struct spinand_device *spinand,
-					     unsigned int retry_mode)
+				   unsigned int retry_mode)
 {
 	struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(MACRONIX_FEATURE_ADDR_READ_RETRY,
 							       spinand->scratchbuf);
@@ -155,6 +157,18 @@ static int macronix_set_read_retry(struct spinand_device *spinand,
 	return spi_mem_exec_op(spinand->spimem, &op);
 }
 
+static int macronix_set_randomizer(struct spinand_device *spinand, bool enable)
+{
+	int ret;
+
+	ret = spinand_write_reg_op(spinand, MACRONIX_FEATURE_ADDR_RANDOMIZER,
+				   enable ? MACRONIX_CFG_RANDOMIZER_EN : 0);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 static const struct spinand_info macronix_spinand_table[] = {
 	SPINAND_INFO("MX35LF1GE4AB",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x12),
@@ -213,7 +227,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_HAS_QE_BIT,
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35LF2G24AD",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x24, 0x03),
 		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
@@ -225,7 +240,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_HAS_PROG_PLANE_SELECT_BIT,
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35LF2G24AD-Z4I8",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x64, 0x03),
 		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
@@ -236,7 +252,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_HAS_QE_BIT,
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35LF4G24AD",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35, 0x03),
 		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 2, 1, 1),
@@ -248,7 +265,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_HAS_PROG_PLANE_SELECT_BIT,
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35LF4G24AD-Z4I8",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x75, 0x03),
 		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
@@ -259,7 +277,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_HAS_QE_BIT,
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX31LF1GE4BC",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x1e),
 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
@@ -305,7 +324,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 				     macronix_ecc_get_status),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35UF4G24AD-Z4I8",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xf5, 0x03),
 		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
@@ -317,7 +337,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 				     macronix_ecc_get_status),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35UF4GE4AD",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xb7, 0x03),
 		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
@@ -355,7 +376,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 				     macronix_ecc_get_status),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35UF2G24AD-Z4I8",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xe4, 0x03),
 		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
@@ -367,7 +389,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 				     macronix_ecc_get_status),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35UF2GE4AD",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa6, 0x03),
 		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
@@ -413,7 +436,8 @@ static const struct spinand_info macronix_spinand_table[] = {
 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 				     macronix_ecc_get_status),
 		     SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
-					macronix_set_read_retry)),
+					macronix_set_read_retry),
+		     SPINAND_RANDOMIZER(macronix_set_randomizer)),
 	SPINAND_INFO("MX35UF1GE4AD",
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x96, 0x03),
 		     NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
-- 
2.25.1


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

* Re: [PATCH v5 1/3] dt-bindings: mtd: spinand: Add randomizer enable/disable properties
  2026-02-11 10:05 ` [PATCH v5 1/3] dt-bindings: mtd: spinand: Add randomizer enable/disable properties Cheng Ming Lin
@ 2026-02-12  7:33   ` Krzysztof Kozlowski
  2026-02-23  5:49     ` Cheng Ming Lin
  0 siblings, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2026-02-12  7:33 UTC (permalink / raw)
  To: Cheng Ming Lin
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Tudor Ambarus,
	Mikhail Kshevetskiy, Pablo Martin-Gomez, Tianling Shen,
	Pratyush Yadav, linux-mtd, devicetree, linux-kernel, alvinzhou,
	Cheng Ming Lin

On Wed, Feb 11, 2026 at 06:05:51PM +0800, Cheng Ming Lin wrote:
> diff --git a/Documentation/devicetree/bindings/mtd/nand-chip.yaml b/Documentation/devicetree/bindings/mtd/nand-chip.yaml
> index 609d4a4ddd80..2fcbc4b73e95 100644
> --- a/Documentation/devicetree/bindings/mtd/nand-chip.yaml
> +++ b/Documentation/devicetree/bindings/mtd/nand-chip.yaml
> @@ -67,6 +67,14 @@ properties:
>        the secure regions present.
>      $ref: /schemas/types.yaml#/definitions/uint64-matrix
>  
> +  nand-randomizer-enable:
> +    description: Enable the randomizer feature.
> +    type: boolean
> +
> +  nand-randomizer-disable:
> +    description: Disable the randomizer feature.
> +    type: boolean

Read again feedback from Miquel - two EXCLUSIVE properties. You miss
"not" with "required":
https://lore.kernel.org/all/20230118163208.GA117919-robh@kernel.org/

Best regards,
Krzysztof


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

* Re: [PATCH v5 3/3] mtd: spi-nand: macronix: Enable randomizer support
  2026-02-11 10:05 ` [PATCH v5 3/3] mtd: spi-nand: macronix: Enable randomizer support Cheng Ming Lin
@ 2026-02-12 10:55   ` Miquel Raynal
  2026-02-23  5:50     ` Cheng Ming Lin
  0 siblings, 1 reply; 8+ messages in thread
From: Miquel Raynal @ 2026-02-12 10:55 UTC (permalink / raw)
  To: Cheng Ming Lin
  Cc: Richard Weinberger, Vignesh Raghavendra, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Tudor Ambarus,
	Mikhail Kshevetskiy, Pablo Martin-Gomez, Tianling Shen,
	Pratyush Yadav, linux-mtd, devicetree, linux-kernel, alvinzhou,
	Cheng Ming Lin

On 11/02/2026 at 18:05:53 +08, Cheng Ming Lin <linchengming884@gmail.com> wrote:

> From: Cheng Ming Lin <chengminglin@mxic.com.tw>
>
> Implement the 'set_randomizer' callback for Macronix SPI NAND chips.
> The randomizer is enabled by setting bit 1 of the Configuration Register
> (address 0x10).
>
> This patch adds support for the following chips:
>   - MX35LFxG24AD series
>   - MX35UFxG24AD series
>
> When the randomizer is enabled, data is scrambled internally during
> program operations and automatically descrambled during read operations.
> This helps reduce bit errors caused by program disturbance.
>
> Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
> ---
>  drivers/mtd/nand/spi/macronix.c | 46 +++++++++++++++++++++++++--------
>  1 file changed, 35 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
> index edf63b9996cf..3a9ab146426b 100644
> --- a/drivers/mtd/nand/spi/macronix.c
> +++ b/drivers/mtd/nand/spi/macronix.c
> @@ -14,6 +14,8 @@
>  #define MACRONIX_ECCSR_BF_LAST_PAGE(eccsr) FIELD_GET(GENMASK(3, 0), eccsr)
>  #define MACRONIX_ECCSR_BF_ACCUMULATED_PAGES(eccsr) FIELD_GET(GENMASK(7, 4), eccsr)
>  #define MACRONIX_CFG_CONT_READ         BIT(2)
> +#define MACRONIX_CFG_RANDOMIZER_EN     BIT(1)
> +#define MACRONIX_FEATURE_ADDR_RANDOMIZER 0x10
>  #define MACRONIX_FEATURE_ADDR_READ_RETRY 0x70
>  #define MACRONIX_NUM_READ_RETRY_MODES 5
>  
> @@ -146,7 +148,7 @@ static int macronix_set_cont_read(struct spinand_device *spinand, bool enable)
>   * Return: 0 on success, a negative error code otherwise.
>   */
>  static int macronix_set_read_retry(struct spinand_device *spinand,
> -					     unsigned int retry_mode)
> +				   unsigned int retry_mode)

This is unrelated, it should be in an other commit.

>  {
>  	struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(MACRONIX_FEATURE_ADDR_READ_RETRY,
>  							       spinand->scratchbuf);
> @@ -155,6 +157,18 @@ static int macronix_set_read_retry(struct spinand_device *spinand,
>  	return spi_mem_exec_op(spinand->spimem, &op);
>  }
>  
> +static int macronix_set_randomizer(struct spinand_device *spinand, bool enable)
> +{
> +	int ret;
> +
> +	ret = spinand_write_reg_op(spinand, MACRONIX_FEATURE_ADDR_RANDOMIZER,
> +				   enable ? MACRONIX_CFG_RANDOMIZER_EN :
> 0);

You can directly return. Same in the core BTW.

Otherwise with this and the binding document fixed, looks ok.

Thanks,
Miquèl

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

* Re: [PATCH v5 1/3] dt-bindings: mtd: spinand: Add randomizer enable/disable properties
  2026-02-12  7:33   ` Krzysztof Kozlowski
@ 2026-02-23  5:49     ` Cheng Ming Lin
  0 siblings, 0 replies; 8+ messages in thread
From: Cheng Ming Lin @ 2026-02-23  5:49 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Tudor Ambarus,
	Mikhail Kshevetskiy, Pablo Martin-Gomez, Tianling Shen,
	Pratyush Yadav, linux-mtd, devicetree, linux-kernel, alvinzhou,
	Cheng Ming Lin

Hi Krzysztof,

Krzysztof Kozlowski <krzk@kernel.org> 於 2026年2月12日週四 下午3:33寫道:
>
> On Wed, Feb 11, 2026 at 06:05:51PM +0800, Cheng Ming Lin wrote:
> > diff --git a/Documentation/devicetree/bindings/mtd/nand-chip.yaml b/Documentation/devicetree/bindings/mtd/nand-chip.yaml
> > index 609d4a4ddd80..2fcbc4b73e95 100644
> > --- a/Documentation/devicetree/bindings/mtd/nand-chip.yaml
> > +++ b/Documentation/devicetree/bindings/mtd/nand-chip.yaml
> > @@ -67,6 +67,14 @@ properties:
> >        the secure regions present.
> >      $ref: /schemas/types.yaml#/definitions/uint64-matrix
> >
> > +  nand-randomizer-enable:
> > +    description: Enable the randomizer feature.
> > +    type: boolean
> > +
> > +  nand-randomizer-disable:
> > +    description: Disable the randomizer feature.
> > +    type: boolean
>
> Read again feedback from Miquel - two EXCLUSIVE properties. You miss
> "not" with "required":
> https://lore.kernel.org/all/20230118163208.GA117919-robh@kernel.org/

Thank you for the review and the reference link.

I understand now. I will add the "not" with "required" constraints to
properly enforce the mutual exclusivity for these two properties.
This will be updated in the upcoming v6.

>
> Best regards,
> Krzysztof
>

Thanks,
Cheng Ming Lin

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

* Re: [PATCH v5 3/3] mtd: spi-nand: macronix: Enable randomizer support
  2026-02-12 10:55   ` Miquel Raynal
@ 2026-02-23  5:50     ` Cheng Ming Lin
  0 siblings, 0 replies; 8+ messages in thread
From: Cheng Ming Lin @ 2026-02-23  5:50 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Richard Weinberger, Vignesh Raghavendra, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Tudor Ambarus,
	Mikhail Kshevetskiy, Pablo Martin-Gomez, Tianling Shen,
	Pratyush Yadav, linux-mtd, devicetree, linux-kernel, alvinzhou,
	Cheng Ming Lin

Hi Miquel,

Miquel Raynal <miquel.raynal@bootlin.com> 於 2026年2月12日週四 下午6:55寫道:
>
> On 11/02/2026 at 18:05:53 +08, Cheng Ming Lin <linchengming884@gmail.com> wrote:
>
> > From: Cheng Ming Lin <chengminglin@mxic.com.tw>
> >
> > Implement the 'set_randomizer' callback for Macronix SPI NAND chips.
> > The randomizer is enabled by setting bit 1 of the Configuration Register
> > (address 0x10).
> >
> > This patch adds support for the following chips:
> >   - MX35LFxG24AD series
> >   - MX35UFxG24AD series
> >
> > When the randomizer is enabled, data is scrambled internally during
> > program operations and automatically descrambled during read operations.
> > This helps reduce bit errors caused by program disturbance.
> >
> > Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
> > ---
> >  drivers/mtd/nand/spi/macronix.c | 46 +++++++++++++++++++++++++--------
> >  1 file changed, 35 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c
> > index edf63b9996cf..3a9ab146426b 100644
> > --- a/drivers/mtd/nand/spi/macronix.c
> > +++ b/drivers/mtd/nand/spi/macronix.c
> > @@ -14,6 +14,8 @@
> >  #define MACRONIX_ECCSR_BF_LAST_PAGE(eccsr) FIELD_GET(GENMASK(3, 0), eccsr)
> >  #define MACRONIX_ECCSR_BF_ACCUMULATED_PAGES(eccsr) FIELD_GET(GENMASK(7, 4), eccsr)
> >  #define MACRONIX_CFG_CONT_READ         BIT(2)
> > +#define MACRONIX_CFG_RANDOMIZER_EN     BIT(1)
> > +#define MACRONIX_FEATURE_ADDR_RANDOMIZER 0x10
> >  #define MACRONIX_FEATURE_ADDR_READ_RETRY 0x70
> >  #define MACRONIX_NUM_READ_RETRY_MODES 5
> >
> > @@ -146,7 +148,7 @@ static int macronix_set_cont_read(struct spinand_device *spinand, bool enable)
> >   * Return: 0 on success, a negative error code otherwise.
> >   */
> >  static int macronix_set_read_retry(struct spinand_device *spinand,
> > -                                          unsigned int retry_mode)
> > +                                unsigned int retry_mode)
>
> This is unrelated, it should be in an other commit.
>
> >  {
> >       struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(MACRONIX_FEATURE_ADDR_READ_RETRY,
> >                                                              spinand->scratchbuf);
> > @@ -155,6 +157,18 @@ static int macronix_set_read_retry(struct spinand_device *spinand,
> >       return spi_mem_exec_op(spinand->spimem, &op);
> >  }
> >
> > +static int macronix_set_randomizer(struct spinand_device *spinand, bool enable)
> > +{
> > +     int ret;
> > +
> > +     ret = spinand_write_reg_op(spinand, MACRONIX_FEATURE_ADDR_RANDOMIZER,
> > +                                enable ? MACRONIX_CFG_RANDOMIZER_EN :
> > 0);
>
> You can directly return. Same in the core BTW.

Sure, I will fix it and send v6.

>
> Otherwise with this and the binding document fixed, looks ok.
>
> Thanks,
> Miquèl

Thanks,
Cheng Ming Lin

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

end of thread, other threads:[~2026-02-23  5:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-11 10:05 [PATCH v5 0/3] mtd: spi-nand: Add support for randomizer feature Cheng Ming Lin
2026-02-11 10:05 ` [PATCH v5 1/3] dt-bindings: mtd: spinand: Add randomizer enable/disable properties Cheng Ming Lin
2026-02-12  7:33   ` Krzysztof Kozlowski
2026-02-23  5:49     ` Cheng Ming Lin
2026-02-11 10:05 ` [PATCH v5 2/3] mtd: spi-nand: Add support for randomizer Cheng Ming Lin
2026-02-11 10:05 ` [PATCH v5 3/3] mtd: spi-nand: macronix: Enable randomizer support Cheng Ming Lin
2026-02-12 10:55   ` Miquel Raynal
2026-02-23  5:50     ` Cheng Ming Lin

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