From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E667223D7E3 for ; Wed, 22 Apr 2026 07:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776841414; cv=none; b=Ao0QrdTQyUN1/6xMpf0tjNeaxuuOm99mmPjXHSWjPACjKBATf9n1TD38K+0ARRsqQpwV48ISg/wFvteZ6TJgy9QjqxdcphTjaT7jV7n79v/K9/v2D/2RbPSooOc4hvLqNlgvzGXqywnbv7d6D0xn2HBMttxyD3d6bLykq2AOZW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776841414; c=relaxed/simple; bh=jJBb87yqQMsI3Xcl8dXaK3nFLeADXXMejAQxTrLcVTY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p/NiGUsHNxYN4HE4OHr0/KwMuXX35HR0fQ9eGvH48aBtyJpXXj7YsXTuGNKcKDIraqUQqRgZnQ5AtoF8QX51iNcX3uoJcEcSIqiGfdtP8koYMerJeN3LBFaMzOOVi83oKwsAO4lT5s+t33qKR8hDaOkxCVAWKy9fJcFdkLcjSLE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=s52URz4/; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s52URz4/" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-82418b0178cso3179516b3a.1 for ; Wed, 22 Apr 2026 00:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776841412; x=1777446212; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mSXRoXNyL2G9tTF3pCq4QLzdSdaD1DteZMo7+cFocEo=; b=s52URz4/isWxI+rJOYDo9nXHx2zqPX95F3fwrpRyvrpv7tPwxd7UvvRsFoUwYOtzUv Mx4Kgi4GFSgmQAqT2+fLZc8LWnF5XlHxrlquD++WqLqxxxDQyGQ9upLnIs2jNwFiJ2il /+HnlmZQX1tmV0r1B2rzKrsKubq4Be7YQ8HZU34dETf50x13cuYYb0sE2HoISexX6VIk vBa4OddKqgpQcJCjE14El8Hw2NwodsUyaKuKMqMgUFLm6JPmD6VKwfKxz+dWN59gJjk5 nbjNP5R4maObLElycUJdl9VvFS0R58AmVB2kER4rEKn9elDu5S8dZh7zV4qCDgdhy+lh jvDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776841412; x=1777446212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=mSXRoXNyL2G9tTF3pCq4QLzdSdaD1DteZMo7+cFocEo=; b=OXnRo2jIdfNefDEv3MeQjBQ3u6ldS7/cuKSYjoi0vZrhAw9pqHnqUtn1Og7q8oeeVe 9USOhNrYmY8MM/ZSuJRdEfPyzEbsE2pJF9+15mrcBFiHYxH2x3TLwR1CFKSvbLtLv5kP lXgR8SH2iyZZPzXAjpCGa9mkb/iBOJAOVG9pH9yqzHJmnuyGNaLyrCL0gq2EcHJx8IM8 +1fIn6CUezCQB4IsXihTkgCs+TJ7bkgsmLBQ3O0+epce6aJwQHZc48KYQv48PhWM0dAO pFyF6mPpbzAQwt9QZoE5bxVJH/c96RqN6Su921i8PjOQ8m+w9nMLhidV6wYggiZQfNo6 wrMw== X-Forwarded-Encrypted: i=1; AFNElJ8NEShxoAFdXu3SHjAkdi02mOtNR+wgVzGBuLKnVtnia5pr19xKhTycRnuL2mkynGrLnToFdJC7lePth8k=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8ZH+UhhrVvsaFgTnRsr39T7EZR8miOuv4E4Di6XaDw1oYz18T jdC1tpzl1yvnOP6LxyxJ5pL3PAPsf9JxPmQyBxzueVEHpaJZk+VGjBOS X-Gm-Gg: AeBDieumAbo9x3SWpZ2dY0meu292/Tr+CmbeWKs9UdWPEYqATNJnQVeyhl6YmXWIBON pyLHtE7v0+d9v3vHhPIUfA1WjTrTRxktulnN/1urzrl2PF50pSbuNOXFNQ5pzrltTknfYhIKbKe Dlb9ZgKu5m0pmgYfo2WHyxRSR6oL74e+NJb5ZTod2VvDTgpr9RHfUJh+G0Yie1jlpZBN72N4HtP tsJu7RquH/A7A3f9qqn/JvRLbPi3P+m0Sb/U94v+gFDehP6XKVgV+x/fl8pqJptisifSCz3125C P2q2iU68dB2kN5lmh7gVFWJSS/2VB2+OpxNTvbiKp8fZMGoySsx6/Ur/N71G9+l4eUCNfuNAkFs 18SMMQTuhyt7CA2ByCsMcKoEffd5cqD+F+rq4Hk+slegtaVBuqcydUw0eH8BA20D4lCY0Rd+xxx bldTaeixlK8egzVB0Er8151ll/HttFV71+JBykuyad5DLuyTXmq0mhABdk X-Received: by 2002:a05:6a00:3498:b0:820:2f9b:fe31 with SMTP id d2e1a72fcca58-82f8c8bede5mr18881373b3a.30.1776841412109; Wed, 22 Apr 2026 00:03:32 -0700 (PDT) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8e981829sm19411466b3a.12.2026.04.22.00.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 00:03:30 -0700 (PDT) Received: from hqs-appsw-a2o.mp600.macronix.com (unknown [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id 23E63416A045; Wed, 22 Apr 2026 15:03:28 +0800 (CST) From: Cheng Ming Lin To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alvinzhou@mxic.com.tw, Cheng Ming Lin Subject: [PATCH v9 2/3] mtd: spi-nand: Add support for randomizer Date: Wed, 22 Apr 2026 15:02:02 +0800 Message-Id: <20260422070203.698716-3-linchengming884@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260422070203.698716-1-linchengming884@gmail.com> References: <20260422070203.698716-1-linchengming884@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Cheng Ming Lin 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 --- drivers/mtd/nand/spi/core.c | 20 ++++++++++++++++++++ include/linux/mtd/spinand.h | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 8aa3753aa..fee9a024d 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1307,6 +1307,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 == 1); +} + static const struct nand_ops spinand_ops = { .erase = spinand_erase, .markbad = spinand_markbad, @@ -1594,6 +1610,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 */ @@ -1881,6 +1898,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 58abd306e..9ec45b727 100644 --- a/include/linux/mtd/spinand.h +++ b/include/linux/mtd/spinand.h @@ -585,6 +585,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. @@ -613,6 +614,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, ...) \ @@ -669,6 +672,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, ...) \ { \ @@ -754,6 +760,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; @@ -787,6 +794,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