]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mtd: spinand: Add support for randomizer
authorCheng Ming Lin <chengminglin@mxic.com.tw>
Tue, 5 May 2026 01:34:52 +0000 (09:34 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Wed, 27 May 2026 09:07:06 +0000 (11:07 +0200)
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>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/nand/spi/core.c
include/linux/mtd/spinand.h

index f1084d5e04b9797702a3a35d1a735ee18e05abcd..f86786344d52b0fa8914d348c4a23a7e8dc38e29 100644 (file)
@@ -1328,6 +1328,22 @@ 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;
+       u32 rand_val;
+       int ret;
+
+       if (!spinand->set_randomizer)
+               return 0;
+
+       ret = of_property_read_u32(np, "nand-randomizer", &rand_val);
+       if (ret)
+               return 0;
+
+       return spinand->set_randomizer(spinand, rand_val);
+}
+
 static const struct nand_ops spinand_ops = {
        .erase = spinand_erase,
        .markbad = spinand_markbad,
@@ -1619,6 +1635,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;
 
                /* I/O variants selection with single-spi SDR commands */
 
@@ -1942,6 +1959,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;
index 44f4347104d661f9d48b0786afb44b91ba9b5c95..ec6efcfeef8344863f7c483c8e82d5dd24bf51f2 100644 (file)
@@ -593,6 +593,7 @@ enum spinand_bus_interface {
  * @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.
@@ -622,6 +623,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, ...)                                      \
@@ -686,6 +689,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, ...)                                      \
        {                                                               \
@@ -771,6 +777,7 @@ struct spinand_mem_ops {
  * @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;
@@ -804,6 +811,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;