From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 4F390256C6C for ; Wed, 25 Feb 2026 01:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771984746; cv=none; b=Koh2JVE5nkm9HBMlwS8ysBsVREWlSuB8htfQ4n93O38CYa3d3uJ4RBKQOaXh145hCapo4SKOhK3p/PphCiBOKrOTNmPP1NqVl8wdYfCVvQZ8WeZWTDJN2Un0mHMof5scP4QnribwhbUTS66TKb5Q139F7ymCoQ8sWHoUj0iX/HU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771984746; c=relaxed/simple; bh=A0cKTP/NcPWurRQx3wyGtZw1VFNDkseDTGwzrhDZmHE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fVVcnzvgEqZ4kSKKm5NxONcfZyUvWjZCpJd3+0q1UJPcMdcfFCVY2RQTqq0QYWlVYanfqLnmLoAAlIiVdmWp7xWJIa3XzginMHkWsTeGslBPEuJPpTME9PU690UwAuhG19/hRWLCtbh89ZLL+HyZTG1yNmTA1TyR5Ys0b/Qsdek= 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=bIXmu1V9; arc=none smtp.client-ip=209.85.214.176 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="bIXmu1V9" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2ad3f12a496so1443855ad.1 for ; Tue, 24 Feb 2026 17:59:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771984745; x=1772589545; 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=bIXmu1V9pHXDmG2o91ouxeCqP8HoggOp0LNnh30KSAZJOQCkvUhrjG8zChpmYZ13GE ij6Ej2DFLMjYMpVyW6HcUr+Fw2uRfH5TPVRCcpb3yU/M8bMy8sj06Q0aLfTPmRHhNXsa EADFl2GveYMcbYM/aDuC5yRV3HzKeQxZor6MQ7zjoCfGUNmXmA4MdZUR3j9kKZ0E483b 3QO6eUxY5S3Ech4W5JrSNlhtVmNhhdmwATzWu7Pdb5y+jFuZIIJFEH/0Xj8gW0O2C4B9 +PnwqWpNMAsBU6Bk015TP06odteo0F4jH6/+IPYt2REm43ZY4g+U2bUX8gAjy4YXJPIy x1zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771984745; x=1772589545; 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=KOxiQD8/bfuvZEUPzgHUbQ9uNico6Atocb53GjPIKmG/+vPRrX4eNZQOkghbF+D5Fe kd9+88mzewfIuPlcgYK6gqStN029rbQLqsgNsqXbkUFoBWXkfy163/yzVlJTQ7GAqaSF JbZ5QGvI+MPe9fgne5Z2UYVm0AmUayFLTyYdgeek3AMiTTtJl1VmoyDZkBBmD2GeLSr7 8Oh8iFizx2ZH45Mz+7Cn8lA8JYFxLifqLseeArtnFklzLUaMhEF0Pj5mBOuIfrr7SI1X HXebk5IjgDBKalOtdWMkMjs5Z21kddkUVey8ffUSLI+6UiQR2+lqM39JbbizJxbgUbhJ emUw== X-Forwarded-Encrypted: i=1; AJvYcCXtvdRrS45zOFap0NYe6KFMkh5m5axIxBr2i7+OGB/4fxUV42T/kPqcjpik5ORF7aJrCV9bS4s4c34BdwU=@vger.kernel.org X-Gm-Message-State: AOJu0Yzi9K7asOKsGlqdqbALUqwAhKZdK4oeSVUFpi+EqbyPgGCxipB1 mKa04ghxj4ooctwDXZEq6gEpgFY7ym+87H15YI8cOI1OHvwLRaZEPq+4 X-Gm-Gg: ATEYQzzbqwIWwFZOsLsQuANKZb9qkyvb5QEG6+PjcZk0L4ihp5tJArZeF5TtJ/ILGOY HCiLRRwVRmZm/xtjWA8xYXfZA/ZhAt3fOjz7I/i+V3BzFV7Yl2iQcedNo9VAFi5851grEB+vhwV sele4lWN+3rL0wJGOuPmNhAxlqE491q15Ni3tv5Alym8DkZg5sAqpPd4eoZLHF1AugrriJz2xH8 fcx3dwzchDMc388WawgCfSMNvZBjSKIQ081cB7mjuZiQDJTqzirS4O343b2Ivj/sX4x7c9X4AO+ v7EZVaMlNsviccIGwCLaQgIZraqIexM4BVv4T7ca9n6YgICLQtC58re1JLkrCbmGWZ4iz0SinlV uCfnCur56oK3Pkx03U4C8TEiyXGppHbPLKayd3Wtc6B9Rt47rtPh1bxhBrhXqOffG4F9Z/uDRnE BfvPPjuj80gAktH6fVApv20n29tjRW4tx3Sbe1UnzrCqP+mw== X-Received: by 2002:a17:903:2350:b0:2aa:e238:e20c with SMTP id d9443c01a7336-2adbdcd8822mr19122275ad.19.1771984744512; Tue, 24 Feb 2026 17:59:04 -0800 (PST) Received: from twhmp6px (mxsmtp211.mxic.com.tw. [211.75.127.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ad7503fcc5sm118566325ad.76.2026.02.24.17.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 17:59:04 -0800 (PST) Received: from hqs-appsw-a2o.mp600.macronix.com (unknown [172.17.236.67]) by twhmp6px (Postfix) with ESMTPS id 93A694136075; Wed, 25 Feb 2026 09:59:02 +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 v7 2/3] mtd: spi-nand: Add support for randomizer Date: Wed, 25 Feb 2026 09:57:04 +0800 Message-Id: <20260225015705.1113199-3-linchengming884@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260225015705.1113199-1-linchengming884@gmail.com> References: <20260225015705.1113199-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 | 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_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, @@ -1594,6 +1617,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 +1905,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 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); }; #define SPINAND_ID(__method, ...) \ @@ -668,6 +671,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, ...) \ { \ @@ -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); const struct spinand_fact_otp *fact_otp; const struct spinand_user_otp *user_otp; -- 2.25.1