From nobody Mon Apr 6 12:11:32 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 9EE54313543 for ; Thu, 5 Mar 2026 07:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772694775; cv=none; b=kKUnHpoXquo4YHbKdzXbqo44rkRpsJvOZZs7gKeG/31nNLavGXjqSvZZ/QzNkznzIn3eoYhLYRZUJfjPHZJPNEnqbacfsR5Nhio1UJdhkXPD76sTTii6hsMnsj1Ws3j8Q4se+X7CQXLalRGU0eBEp6A+SF0tioLIY1qKK7ql2Bc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772694775; c=relaxed/simple; bh=A0cKTP/NcPWurRQx3wyGtZw1VFNDkseDTGwzrhDZmHE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i6d4u97VzpFruF7tJx1WjT5mEykw9wNBBuQOPnS4PUekCjMPUiLWaLImnRVccomafxyoecU4bI3jlgbhWcQl4nMil4d8xEtc30ku9LRpJWnqq4slqP0yq2DS4Umixx5jOv94kDvzMTvZGmvFrhxac4l+p7B/hPB8ZWnsg7g8jDo= 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=QAZDvYvq; arc=none smtp.client-ip=209.85.214.179 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="QAZDvYvq" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2ad9516a653so32114465ad.0 for ; Wed, 04 Mar 2026 23:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772694773; x=1773299573; 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=nILoW48W9hqLRwmHITphjoIJRhEY+2JRSNwPbSj3wbI=; b=QAZDvYvqeK9boCHTvE1AcCc29dsBfWcVnSf3yzXNxuGohAp2fxjD/E5v8kK/kbyZj7 5sS+oP/OB3W70hnZY9jxPuEvUxU9q0Z8vBeMQtc3Q9rjicCWgFUmlQG2PVzou8YCxxV1 TmjFMOtjmotjVQwubwZFWuWO9YNf98ypsLd3VkpBLyBlU3efJ3q6hUR/8vWiUUhwATSZ VIUHEUcYkg6LnT8+Fbw/ZNvj6SQ/uhxgKhWUMbsU4c15HP68MNqEEqs72oY9mIvYgu8a 17RTOZ+PWCM8ruxUSS831kLRJqkG828IzpyCeKzky5F0JCIL5mp9eCBX65v7X8Qp8ADG G/CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772694773; x=1773299573; 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=nILoW48W9hqLRwmHITphjoIJRhEY+2JRSNwPbSj3wbI=; b=kOQM14ECfC1whH8/Zrf+DDcXiBax8HIs77Pb60911sgXyDkYSNHobKVg79FofCMGXW ms+hb/XEdygq/tjRVc/e3dm30eyNFNQIYVVUP8Qy8Pe5QNkGDGuz0HuiXBwGC1ec4FcS aUiMzHCkD1Cb/4FzWO7ZISfXYB9gIX3h/wuQ2njDozpJnh7G6LdNVYi55FTwonKno28b OZIPiDxdCxTXXde3pKrabky2ErGyMC2SHYJCQR9IAzV4lMBnrGR3CYR9itlgZuGUrrCG kOZKNUaC5SqOq/9jh3GOApBX8rEN/hdl40ejzNjOGKqhPlxHlz/TTZBX+dXdV25ZCopI ZrIA== X-Forwarded-Encrypted: i=1; AJvYcCXfR/DgxX5TFGVdertjXf8+yW2orrnmD+W0ljjiiSOSNVH4z16t5IEELIlRy3GZw20yKTOrCWCQ01bymeQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzvCuLXm0ngeGn1NONlIoF/nBYdJhTnUifrc02REeQoAdf6MXed sYKjAvpt47qQpXzK8/CPUGzPTQNDiFOCWcHXo/yopblQSME+bmrlXJc0 X-Gm-Gg: ATEYQzxw2a+3ra6oUPUQOgFzCcaxKA5NgihjkcU3gTj5PsXY0LnSJrAPt96uuOA+jfh x3HMKLu89vhz2VjHAlHnGVrsE9/RavZyJ2KkzhBNeXD2Rw1AE6lcf1Dn3h4pvq9jMBv352oo37p FLBdwGUxtaoH7G0eOOc9dz33+pOhopffsWHlGKKsD7s2Jt49lNe8EMOABxMKWBTbvvUL8QUpkFs ra8+E0KgB6BJHwMKa1LyGdtiAVGAY7ZcU0XdmtqWbOVN6zb3/CjqxVfc3e7i+mAGVIRMO6Fq8rp 6ddftOdbQFq9Xo/lXjouRPODvYdIk8Uts1gg9zfcNkbm5LKPZajE56U5bc4jK/nDn1alGAX+KU0 W4TExGJamSHwhaOl5uXBYyhOYrhhmlguTCe/LcRVhTZWK85QE+aFoTKY+XAiOOYwHLrRd9jaAfU fEJY1lUDm5p6GDyqUfnYIFgyj3kU21miBkAhtSFPGbRBhlxQ== X-Received: by 2002:a17:902:db0f:b0:2ae:57e6:616c with SMTP id d9443c01a7336-2ae6a9c6eecmr45501805ad.3.1772694772962; Wed, 04 Mar 2026 23:12:52 -0800 (PST) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2adfb69ef1csm227491785ad.53.2026.03.04.23.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 23:12:52 -0800 (PST) Received: from hqs-appsw-a2o.mp600.macronix.com (unknown [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id B91B74163B71; Thu, 5 Mar 2026 15:12:50 +0800 (CST) From: Cheng Ming Lin 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@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alvinzhou@mxic.com.tw, Cheng Ming Lin Subject: [PATCH v8 2/3] mtd: spi-nand: Add support for randomizer Date: Thu, 5 Mar 2026 15:10:41 +0800 Message-Id: <20260305071042.1193522-3-linchengming884@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260305071042.1193522-1-linchengming884@gmail.com> References: <20260305071042.1193522-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 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 8aa3753aaaa1..77a0371010c4 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1307,6 +1307,29 @@ static int spinand_create_dirmaps(struct spinand_dev= ice *spinand) return 0; } =20 +static int spinand_randomizer_init(struct spinand_device *spinand) +{ + struct device_node *np =3D spinand->spimem->spi->dev.of_node; + bool enable =3D false; + int ret; + + if (!spinand->set_randomizer) + return 0; + + if (of_property_read_bool(np, "nand-enable-randomizer")) + enable =3D true; + else if (of_property_read_bool(np, "nand-disable-randomizer")) + enable =3D false; + else + return 0; + + ret =3D spinand->set_randomizer(spinand, enable); + if (ret) + return ret; + + return 0; +} + static const struct nand_ops spinand_ops =3D { .erase =3D spinand_erase, .markbad =3D spinand_markbad, @@ -1594,6 +1617,7 @@ int spinand_match_and_init(struct spinand_device *spi= nand, spinand->user_otp =3D &table[i].user_otp; spinand->read_retries =3D table[i].read_retries; spinand->set_read_retry =3D table[i].set_read_retry; + spinand->set_randomizer =3D table[i].set_randomizer; =20 /* I/O variants selection with single-spi SDR commands */ =20 @@ -1881,6 +1905,9 @@ static int spinand_init(struct spinand_device *spinan= d) * ECC initialization must have happened previously. */ spinand_cont_read_init(spinand); + ret =3D spinand_randomizer_init(spinand); + if (ret) + goto err_cleanup_nanddev; =20 mtd->_read_oob =3D spinand_mtd_read; mtd->_write_oob =3D spinand_mtd_write; diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h index 6a024cf1c53a..6a68a6c3866a 100644 --- a/include/linux/mtd/spinand.h +++ b/include/linux/mtd/spinand.h @@ -584,6 +584,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. @@ -612,6 +613,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); }; =20 #define SPINAND_ID(__method, ...) \ @@ -668,6 +671,9 @@ struct spinand_info { .read_retries =3D __read_retries, \ .set_read_retry =3D __set_read_retry =20 +#define SPINAND_RANDOMIZER(__set_randomizer) \ + .set_randomizer =3D __set_randomizer + #define SPINAND_INFO(__model, __id, __memorg, __eccreq, __op_variants, \ __flags, ...) \ { \ @@ -753,6 +759,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; @@ -786,6 +793,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); =20 const struct spinand_fact_otp *fact_otp; const struct spinand_user_otp *user_otp; --=20 2.25.1