From nobody Mon Feb 9 16:18:01 2026 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 F1F692BD597 for ; Fri, 30 Jan 2026 09:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769765140; cv=none; b=N+3sht2BHj0sjzXEZu/iTmqArRgckxD9KBjvUFpK6dwNJEZyUrofY21ttnDK3qBuObLKxnmEkrmkGLp711k0MiXxwu1vSgK6NPtfTKyDgBv8q/uU1X1DoPCujDtI7UAVE3jkq8DbexjvomTEIJdDAymHgaFx4Mf61TUXZ15Dl+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769765140; c=relaxed/simple; bh=7f620Q+NHVypE0C4PkboRWanEGkowOnYs85p4FQRP3U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rCvMHfpT51PjesbakZ+OclwOHTsFkssTZ53Adc1m6V9iRe75rCa16m2QtEn3IMrsqGckM8/HPI0kvgsxlaZLcABjHlbOcIJW9RQMfQTlWQQRvNydAFdTNWj47Th1K0nD4vJz2SZGPGwvRwz3WFIRXItLPDh+6ruJJhHY+E5qDDA= 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=SC1qSiAY; arc=none smtp.client-ip=209.85.216.41 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="SC1qSiAY" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-34ab8e0df53so1593429a91.3 for ; Fri, 30 Jan 2026 01:25:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769765138; x=1770369938; 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=A6GlYVoagWgHxL70iH3i0+bpomJ0J/vOUXSulmlnz4o=; b=SC1qSiAYYOM8JJzCsuvjxT2wDZXPYo9HXMX8P69fxmKEhPUdXuXTuN7xbJp9BUrc+D j8UpT+imcrc8wGDQeaKW9OxyDuhZJP8qjTc7+uO0Mo18ZFQbQYg5/stpTw7dowWWOP+E 4aPVldR99MqwtkDduV/lYs/HpHxO9VHzBnx3ICoJq5FsVmguaOm24ncxccegwPW26obM ibODSW6pqtwgEthAnDOkLc3zAO28D7VcjmBQdoAPrncbdd+J/xHKs5eitqo2T0AEdfAG YsLTTJRUfI+v3sfqVNutNp6nROYCRtvT8IYjRQP13tvOgPwrtyjF/2uxXkaJFUQNRpO4 dYwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769765138; x=1770369938; 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=A6GlYVoagWgHxL70iH3i0+bpomJ0J/vOUXSulmlnz4o=; b=i6tnaA39X/ITBHfo6w7IizvLg5s02YOVVl2LmC7dzBNubbCUUcv7Ay8HTTyvwXicKV NXwx1CcndzCicP0NNSBo0Ciah5lR+4pgfOu73yI3sQPSXDfmSd7x/ofWldwFHTg1gH2D 3UnYw+Plm5MDPkrWcUFUd0eQ+0+UMslmtCBvwOraE/uCvoKppkVW4vNgHXJCqMtauUbG wxRrdc1P3J5CyEstBDEV4IzBP6wRsqke2K9AlQCzskSTE8QW0jpo6mE7MpLELUrX9eJQ 7v10DlxHz3X0GgIf49DOgg/okPVpjheGEx27020oQYvat99CkAp9UMi4dBszK2DkVNuC VVBg== X-Forwarded-Encrypted: i=1; AJvYcCUeileCg0KsPPdu4BISmV2n+CFQaGxg2NPeOrUpBaTOb80Ku3Ch2O8un0icdJeN+rEsX07XEiO568rF88o=@vger.kernel.org X-Gm-Message-State: AOJu0YxIC0zFFldQi2C451sZX8myusXldfm044ltjyqxMvyIytKsO3tn Z727YRZ31hO8moaUvL72UST0OtgFEjFELZqyJckCwW1XJMhQ7D/571S6 X-Gm-Gg: AZuq6aLex4p8reen6Lo2drxvoAHF9AciK1Miqt7EZSr8t7hCqoV3g6yujLW+kIZ2fyR /2fw9jCu+Lbtx5EFlYtdF2yATtYHcijK76VjxIM8/xuloiT82IbCNa4erZK/SNQKmdkY3kCp24I /DLepGnJgHRTqzicMSrB6472v4y+a8UjpYqWw4BIqUVKGF/ndTUe6/FGhDZ7xampkb/eFWz/hFO WHP6qP3j2itqtV9O6Le9XQFmOKsl6glRdzJJt28ivNg4vLQ5rLXRk5t6lSu5Q80r59Z0Ci89W08 wke6vi7VZ6ibpjJNhdSB3PqrlnEa2tDZqqAPkMKXDt9X6erbYvT+hpirugrV62SZVkPCCWpvPGD zEas+xVO1Qr/DI9k076mMamTSP2MmuPww0ZRdeatwf87LM+M7GXrZaQEj1ZNpJPyo2gk7mM/8OS IGGS/PE2JHcurYLtGOAPJz1qFPscXm05jU52faItud9hCz X-Received: by 2002:a17:90b:5101:b0:340:ff7d:c26 with SMTP id 98e67ed59e1d1-3543b313a60mr2954738a91.16.1769765138282; Fri, 30 Jan 2026 01:25:38 -0800 (PST) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3540f3f0872sm7433405a91.16.2026.01.30.01.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 01:25:37 -0800 (PST) Received: from hqs-appsw-a2o.mp600.macronix.com (unknown [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id 1D0944136074; Fri, 30 Jan 2026 17:25:36 +0800 (CST) From: Cheng Ming Lin To: Miquel Raynal , Vignesh Raghavendra Cc: Richard Weinberger , Tudor Ambarus , Martin Kurbanov , Mikhail Kshevetskiy , Pratyush Yadav , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Cheng Ming Lin Subject: [PATCH v3 1/2] mtd: spi-nand: Add support for randomizer Date: Fri, 30 Jan 2026 17:23:48 +0800 Message-Id: <20260130092349.621034-2-linchengming884@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260130092349.621034-1-linchengming884@gmail.com> References: <20260130092349.621034-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 call it during device initialization (spinand_init) to enable the randomizer. Signed-off-by: Cheng Ming Lin --- drivers/mtd/nand/spi/core.c | 21 +++++++++++++++++++++ include/linux/mtd/spinand.h | 9 +++++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index d207286572d8..3bf99776cbf5 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -206,6 +206,12 @@ static int spinand_cont_read_enable(struct spinand_dev= ice *spinand, return spinand->set_cont_read(spinand, enable); } =20 +static int spinand_randomizer_enable(struct spinand_device *spinand, + bool enable) +{ + return spinand->set_randomizer(spinand, enable); +} + static int spinand_check_ecc_status(struct spinand_device *spinand, u8 sta= tus) { struct nand_device *nand =3D spinand_to_nand(spinand); @@ -1218,6 +1224,19 @@ static int spinand_create_dirmaps(struct spinand_dev= ice *spinand) return 0; } =20 +static void spinand_randomizer_init(struct spinand_device *spinand) +{ + int ret; + + if (spinand->set_randomizer) { + ret =3D spinand_randomizer_enable(spinand, true); + if (ret) + return ret; + } + + return 0; +} + static const struct nand_ops spinand_ops =3D { .erase =3D spinand_erase, .markbad =3D spinand_markbad, @@ -1412,6 +1431,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 op =3D spinand_select_op_variant(spinand, info->op_variants.read_cache); @@ -1588,6 +1608,7 @@ static int spinand_init(struct spinand_device *spinan= d) * ECC initialization must have happened previously. */ spinand_cont_read_init(spinand); + spinand_randomizer_init(spinand); =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 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); }; =20 #define SPINAND_ID(__method, ...) \ @@ -580,6 +583,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, ...) \ { \ @@ -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); =20 const struct spinand_fact_otp *fact_otp; const struct spinand_user_otp *user_otp; --=20 2.25.1