From patchwork Mon Jun 17 13:34:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kurbanov X-Patchwork-Id: 1948631 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=wpN3oB9/; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=salutedevices.com header.i=@salutedevices.com header.a=rsa-sha256 header.s=mail header.b=gaPSf/+c; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2rVn4y69z20XJ for ; Mon, 17 Jun 2024 23:35:45 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=80Wgazs9sD3ZvSmre64iKNXGs5hAAq75benAieKS2pc=; b=wpN3oB9/uaiMJU FcnSnoiDclgF+Y52RN6+IHEc3c1pCGEjxArDxe16ObAooMv9lQSgql6fe4X3RDhz2hsDYuZIXukd7 WllC9rXuYW6UGTjQ0yo/Muv8DYbgktVYEu99B158wI5dMQflJTgGZ9BpsnjcNTo0sIU6XXq8sHP28 1bULTWHbl2BNvb8v4+kvy6OBgt7Ve4hsa+uxIfROZ59dPXa6zkfmufqqLEvRmNeRQ84spH9volMPq fH9XINxJchqTiO1oAzp+79P8aAnWUbsb+yUKbcmmcy2YUCqajVpSDms8U3woITIzf8vDerzfZMO44 80yq1KAHkYUXiZDney0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCWG-0000000AsgL-0ACI; Mon, 17 Jun 2024 13:35:36 +0000 Received: from mx1.sberdevices.ru ([37.18.73.165]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCW8-0000000AsaP-3N4t for linux-mtd@lists.infradead.org; Mon, 17 Jun 2024 13:35:31 +0000 Received: from p-infra-ksmg-sc-msk01.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 65F13100007; Mon, 17 Jun 2024 16:35:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 65F13100007 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1718631322; bh=6/RL8IVZXxsdzvdm9UvKBkh1bDI5itnPbUoDhIDETh4=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=gaPSf/+cuRtm7oF3DuCWDQfBXa7rxFiBrGu1l85VOZhzHH0ScMfuL4FEikFv3fcHw tMTb4dW70EgkcQ5FBobWGQaH2i0jmQaX6e8CZyvIdWBgyISK0e6rZSFXrgArUlgClA sQlFISL7D1f+2BW2Wg9/0Mk8cTAOIPZiaJJjArdPA6NkOwjWHcuMTLLmNfPWFUqFA4 KMVPQq+6GSXLaxpCMAFpPCdGVepbfIXkfA87U8uVg96c1PSNN/74FXxhTrTkzmRjzW JReLwX7FiAZcS1ghc0auFpDvkXMW8hKwCMKUe5ZmvNNcoJj7SCrC4lTwUPtLokkHJB F4f6gdinvp/iw== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Mon, 17 Jun 2024 16:35:22 +0300 (MSK) Received: from CAB-WSD-0004828.sberdevices.ru (100.64.160.123) by p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 17 Jun 2024 16:35:21 +0300 From: Martin Kurbanov To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Michael Walle , Mark Brown , Chia-Lin Kao , Md Sadre Alam , Ezra Buehler , Sridharan S N , Frieder Schrempf , Alexey Romanov CC: , , , Martin Kurbanov Subject: [PATCH v1 1/5] mtd: spinand: make spinand_{read,write}_page global Date: Mon, 17 Jun 2024 16:34:53 +0300 Message-ID: <20240617133504.179705-2-mmkurbanov@salutedevices.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240617133504.179705-1-mmkurbanov@salutedevices.com> References: <20240617133504.179705-1-mmkurbanov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 185966 [Jun 17 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: mmkurbanov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 20 0.3.20 743589a8af6ec90b529f2124c2bbfc3ce1d2f20f, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;salutedevices.com:7.1.1;100.64.160.123:7.1.2;smtp.sberdevices.ru:5.0.1,7.1.1;127.0.0.199:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/06/17 11:22:00 #25639124 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_063529_238187_345E53A2 X-CRM114-Status: GOOD ( 13.75 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Change these functions from static to global so that to use them later in OTP operations. Since reading OTP pages is no different from reading pages from the main area. Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/core.c | 24 ++++++++++++++++++++---- include/linux/mtd/spinand.h | 6 ++++++ 2 files changed, 26 insertions(+), 4 [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Change these functions from static to global so that to use them later in OTP operations. Since reading OTP pages is no different from reading pages from the main area. Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/core.c | 24 ++++++++++++++++++++---- include/linux/mtd/spinand.h | 6 ++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index e0b6715e5dfed..807c24b0c7c4f 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -566,8 +566,16 @@ static int spinand_lock_block(struct spinand_device *spinand, u8 lock) return spinand_write_reg_op(spinand, REG_BLOCK_LOCK, lock); } -static int spinand_read_page(struct spinand_device *spinand, - const struct nand_page_io_req *req) +/** + * spinand_read_page() - Read the page + * @spinand: the spinand device + * @req: the I/O request + * + * Return: 0 or a positive number of bitflips corrected on success. + * A negative error code otherwise. + */ +int spinand_read_page(struct spinand_device *spinand, + const struct nand_page_io_req *req) { struct nand_device *nand = spinand_to_nand(spinand); u8 status; @@ -597,8 +605,16 @@ static int spinand_read_page(struct spinand_device *spinand, return nand_ecc_finish_io_req(nand, (struct nand_page_io_req *)req); } -static int spinand_write_page(struct spinand_device *spinand, - const struct nand_page_io_req *req) +/** + * spinand_write_page() - Write the page + * @spinand: the spinand device + * @req: the I/O request + * + * Return: 0 or a positive number of bitflips corrected on success. + * A negative error code otherwise. + */ +int spinand_write_page(struct spinand_device *spinand, + const struct nand_page_io_req *req) { struct nand_device *nand = spinand_to_nand(spinand); u8 status; diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h index 5c19ead604996..555846517faf6 100644 --- a/include/linux/mtd/spinand.h +++ b/include/linux/mtd/spinand.h @@ -519,4 +519,10 @@ int spinand_match_and_init(struct spinand_device *spinand, int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val); int spinand_select_target(struct spinand_device *spinand, unsigned int target); +int spinand_read_page(struct spinand_device *spinand, + const struct nand_page_io_req *req); + +int spinand_write_page(struct spinand_device *spinand, + const struct nand_page_io_req *req); + #endif /* __LINUX_MTD_SPINAND_H */ From patchwork Mon Jun 17 13:34:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kurbanov X-Patchwork-Id: 1948629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=uJNz2+Xb; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=salutedevices.com header.i=@salutedevices.com header.a=rsa-sha256 header.s=mail header.b=UTCLUCTB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2rVm53BYz20XJ for ; Mon, 17 Jun 2024 23:35:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MYT1d59EgmQQieDphY7VljxMnOX/8WQ0hVbqxsZor7A=; b=uJNz2+XbrpQF1L 1r/vycCAtIPnHZl7wmSOlGlulNQHxUhDCUvwWESgGn+ZmZCw4UqLUn3XspBSTeS/vE0pxpU7agqzr VrCZzTbolnBd1pm8fg8jYyH4jBN1DWcA2sNncMXAjpNUWk31fTJWNUCL2xNtXBgNNDGVgmMF8IiTV QVfbhrcptFrpcL7/wEP+TBQUVCxas2ZyFxYSHon0943rU/cS3cNuS7LzGjP8fbPBCbZyDmnjJz1gO eXsVeQcuv9TO+vxpsddGvT0G29TCK23IZQfcKa7mCrdO/rslTE0jA7ctNb92oN66afVr/Q9pb6VBc 3T9tyNnjWzjJQo3RYbgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCWD-0000000Asef-0gQy; Mon, 17 Jun 2024 13:35:33 +0000 Received: from mx2.sberdevices.ru ([45.89.224.132] helo=mx1.sberdevices.ru) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCW8-0000000Asao-3OAp for linux-mtd@lists.infradead.org; Mon, 17 Jun 2024 13:35:31 +0000 Received: from p-infra-ksmg-sc-msk02.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id B942412000B; Mon, 17 Jun 2024 16:35:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru B942412000B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1718631322; bh=WcL5BZZJWEHlfSbXCMuvF0QCupxulygIhNPX45T5o3s=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=UTCLUCTBoM1LCdwkUwSeYKSgzkZGnZR6ckMCJiHtPJiOmcIXhLiPxexwxyS+277QL AhuKHtCO30NzKNX72/k8dVQuGOcb/9FUp7Ki1WfaYMIGaChxPBWE5cFbiK92OznQLK GXL/LERi4tZ+y58WiSGVA484xOvXUEtO7ifIY3vcXfQpHigY2fn1u9Z9tDqsvQqUvc y3IOMgxCWPhwiJI9TdtTWsT6f9RKlmhBCHAxCpOEu46gPeh6yv+ugZwetYV2f8uYUZ F02RT+jw18S1J9f5Lt5YXGtQUfnpm/H1qd7+D+lOJAhaBDtMTydpmKFFDndKPY8I0G P5YiXBU74fmSg== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Mon, 17 Jun 2024 16:35:22 +0300 (MSK) Received: from CAB-WSD-0004828.sberdevices.ru (100.64.160.123) by p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 17 Jun 2024 16:35:22 +0300 From: Martin Kurbanov To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Michael Walle , Mark Brown , Chia-Lin Kao , Md Sadre Alam , Ezra Buehler , Sridharan S N , Frieder Schrempf , Alexey Romanov CC: , , , Martin Kurbanov Subject: [PATCH v1 2/5] mtd: spinand: add OTP support Date: Mon, 17 Jun 2024 16:34:54 +0300 Message-ID: <20240617133504.179705-3-mmkurbanov@salutedevices.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240617133504.179705-1-mmkurbanov@salutedevices.com> References: <20240617133504.179705-1-mmkurbanov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 185966 [Jun 17 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: mmkurbanov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 20 0.3.20 743589a8af6ec90b529f2124c2bbfc3ce1d2f20f, {Tracking_from_domain_doesnt_match_to}, 100.64.160.123:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;salutedevices.com:7.1.1;smtp.sberdevices.ru:7.1.1,5.0.1;127.0.0.199:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/06/17 12:47:00 #25641689 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_063529_276142_EDC01A80 X-CRM114-Status: GOOD ( 30.38 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The MTD subsystem already supports accessing two OTP areas: user and factory. User areas can be written by the user. This patch only adds support for the user areas. In this patch the OTP_INFO macro is provided to add parameters to spinand_info. To implement OTP operations, the client (flash driver) is provided with 5 callbacks: .read(), .write(), .info(), .lock() [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The MTD subsystem already supports accessing two OTP areas: user and factory. User areas can be written by the user. This patch only adds support for the user areas. In this patch the OTP_INFO macro is provided to add parameters to spinand_info. To implement OTP operations, the client (flash driver) is provided with 5 callbacks: .read(), .write(), .info(), .lock(), .erase(). Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/Makefile | 3 +- drivers/mtd/nand/spi/core.c | 3 + drivers/mtd/nand/spi/otp.c | 219 ++++++++++++++++++++++++++++++++++ include/linux/mtd/spinand.h | 56 +++++++++ 4 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 drivers/mtd/nand/spi/otp.c diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile index 19cc77288ebbc..60d2e830ffc6b 100644 --- a/drivers/mtd/nand/spi/Makefile +++ b/drivers/mtd/nand/spi/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -spinand-objs := core.o alliancememory.o ato.o esmt.o foresee.o gigadevice.o macronix.o +spinand-objs := core.o otp.o +spinand-objs += alliancememory.o ato.o esmt.o foresee.o gigadevice.o macronix.o spinand-objs += micron.o paragon.o toshiba.o winbond.o xtx.o obj-$(CONFIG_MTD_SPI_NAND) += spinand.o diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 807c24b0c7c4f..2cb825edd49d0 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1111,6 +1111,7 @@ int spinand_match_and_init(struct spinand_device *spinand, spinand->flags = table[i].flags; spinand->id.len = 1 + table[i].devid.len; spinand->select_target = table[i].select_target; + spinand->otp = &table[i].otp; op = spinand_select_op_variant(spinand, info->op_variants.read_cache); @@ -1292,6 +1293,8 @@ static int spinand_init(struct spinand_device *spinand) mtd->_max_bad_blocks = nanddev_mtd_max_bad_blocks; mtd->_resume = spinand_mtd_resume; + spinand_set_mtd_otp_ops(spinand); + if (nand->ecc.engine) { ret = mtd_ooblayout_count_freebytes(mtd); if (ret < 0) diff --git a/drivers/mtd/nand/spi/otp.c b/drivers/mtd/nand/spi/otp.c new file mode 100644 index 0000000000000..e1f96b1898dcb --- /dev/null +++ b/drivers/mtd/nand/spi/otp.c @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2024, SaluteDevices. All Rights Reserved. + * + * Author: Martin Kurbanov + */ + +#include +#include + +static size_t spinand_otp_size(struct spinand_device *spinand) +{ + struct nand_device *nand = spinand_to_nand(spinand); + size_t otp_pagesize = nanddev_page_size(nand) + + nanddev_per_page_oobsize(nand); + + return spinand->otp->layout.npages * otp_pagesize; +} + +static unsigned int spinand_otp_npages(const struct spinand_device *spinand) +{ + return spinand->otp->layout.npages; +} + +static int spinand_otp_rw(struct spinand_device *spinand, loff_t from, + size_t len, u8 *buf, size_t *retlen, bool is_write) +{ + struct nand_device *nand = spinand_to_nand(spinand); + struct nand_page_io_req req = { 0 }; + unsigned long long page; + size_t copied = 0; + size_t otp_pagesize = nanddev_page_size(nand) + + nanddev_per_page_oobsize(nand); + int ret = 0; + + page = from; + req.dataoffs = do_div(page, otp_pagesize); + req.pos.page = page; + req.type = is_write ? NAND_PAGE_WRITE : NAND_PAGE_READ; + req.mode = MTD_OPS_RAW; + req.databuf.in = buf; + + while (copied < len && req.pos.page < spinand_otp_npages(spinand)) { + req.datalen = min_t(unsigned int, + otp_pagesize - req.dataoffs, + len - copied); + + if (is_write) + ret = spinand_write_page(spinand, &req); + else + ret = spinand_read_page(spinand, &req); + + if (ret < 0) + break; + + req.dataoffs = 0; + copied += req.datalen; + req.pos.page++; + } + + *retlen = copied; + + return ret; +} + +/** + * spinand_otp_read() - Read from OTP area + * @spinand: the spinand device + * @from: the offset to read + * @len: the number of data bytes to read + * @buf: the buffer to store the read data + * @retlen: the pointer to variable to store the number of read bytes + * + * Return: 0 on success, an error code otherwise. + */ +int spinand_otp_read(struct spinand_device *spinand, loff_t from, size_t len, + u8 *buf, size_t *retlen) +{ + return spinand_otp_rw(spinand, from, len, buf, retlen, false); +} + +/** + * spinand_otp_write() - Write to OTP area + * @spinand: the spinand device + * @from: the offset to write to + * @len: the number of bytes to write + * @buf: the buffer with data to write + * @retlen: the pointer to variable to store the number of written bytes + * + * Return: 0 on success, an error code otherwise. + */ +int spinand_otp_write(struct spinand_device *spinand, loff_t from, size_t len, + const u8 *buf, size_t *retlen) +{ + return spinand_otp_rw(spinand, from, len, (u8 *)buf, retlen, true); +} + +static int spinand_mtd_otp_info(struct mtd_info *mtd, size_t len, + size_t *retlen, struct otp_info *buf) +{ + struct spinand_device *spinand = mtd_to_spinand(mtd); + const struct spinand_otp_ops *ops = spinand->otp->ops; + int ret; + + mutex_lock(&spinand->lock); + ret = ops->info(spinand, len, buf, retlen); + mutex_unlock(&spinand->lock); + + return ret; +} + +static int spinand_mtd_otp_rw(struct mtd_info *mtd, loff_t ofs, size_t len, + size_t *retlen, u8 *buf, bool is_write) +{ + struct spinand_device *spinand = mtd_to_spinand(mtd); + const struct spinand_otp_ops *ops = spinand->otp->ops; + size_t total_len = len; + int ret; + + if (ofs < 0 || ofs + len > spinand_otp_size(spinand)) + return -EINVAL; + + total_len = min_t(size_t, total_len, spinand_otp_size(spinand) - ofs); + if (!total_len) + return 0; + + mutex_lock(&spinand->lock); + + ret = spinand_upd_cfg(spinand, CFG_OTP_ENABLE, CFG_OTP_ENABLE); + if (ret) + goto out_unlock; + + if (is_write) + ret = ops->write(spinand, ofs, len, buf, retlen); + else + ret = ops->read(spinand, ofs, len, buf, retlen); + + if (spinand_upd_cfg(spinand, CFG_OTP_ENABLE, 0)) { + WARN(1, "Can not disable OTP mode\n"); + ret = -EIO; + } + +out_unlock: + mutex_unlock(&spinand->lock); + return ret; +} + +static int spinand_mtd_otp_read(struct mtd_info *mtd, loff_t from, size_t len, + size_t *retlen, u8 *buf) +{ + return spinand_mtd_otp_rw(mtd, from, len, retlen, buf, false); +} + +static int spinand_mtd_otp_write(struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, const u8 *buf) +{ + return spinand_mtd_otp_rw(mtd, to, len, retlen, (u8 *)buf, true); +} + +static int spinand_mtd_otp_erase(struct mtd_info *mtd, loff_t from, size_t len) +{ + struct spinand_device *spinand = mtd_to_spinand(mtd); + const struct spinand_otp_ops *ops = spinand->otp->ops; + int ret; + + if (!ops->erase) + return -EOPNOTSUPP; + + if (!len) + return 0; + + if (from < 0 || (from + len) > spinand_otp_size(spinand)) + return -EINVAL; + + mutex_lock(&spinand->lock); + ret = ops->erase(spinand, from, len); + mutex_unlock(&spinand->lock); + + return ret; +} + +static int spinand_mtd_otp_lock(struct mtd_info *mtd, loff_t from, size_t len) +{ + struct spinand_device *spinand = mtd_to_spinand(mtd); + const struct spinand_otp_ops *ops = spinand->otp->ops; + int ret; + + if (!ops->lock) + return -EOPNOTSUPP; + + if (from < 0 || (from + len) > spinand_otp_size(spinand)) + return -EINVAL; + + mutex_lock(&spinand->lock); + ret = ops->lock(spinand, from, len); + mutex_unlock(&spinand->lock); + + return ret; +} + +/** + * spinand_set_mtd_otp_ops() - Set up OTP methods + * @spinand: the spinand device + * + * Set up OTP methods. + */ +void spinand_set_mtd_otp_ops(struct spinand_device *spinand) +{ + struct mtd_info *mtd = spinand_to_mtd(spinand); + + if (!spinand->otp->ops) + return; + + mtd->_get_user_prot_info = spinand_mtd_otp_info; + mtd->_read_user_prot_reg = spinand_mtd_otp_read; + mtd->_write_user_prot_reg = spinand_mtd_otp_write; + mtd->_lock_user_prot_reg = spinand_mtd_otp_lock; + mtd->_erase_user_prot_reg = spinand_mtd_otp_erase; +} diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h index 555846517faf6..a0d42a9be333f 100644 --- a/include/linux/mtd/spinand.h +++ b/include/linux/mtd/spinand.h @@ -322,6 +322,43 @@ struct spinand_ondie_ecc_conf { u8 status; }; +/** + * struct spinand_otp_layout - structure to describe the SPI NAND OTP area + * @npages: number of pages in the OTP + */ +struct spinand_otp_layout { + unsigned int npages; +}; + +/** + * struct spinand_otp_ops - SPI NAND OTP methods + * @info: Get the OTP area information + * @lock: lock an OTP region + * @erase: erase an OTP region + * @read: read from the SPI NAND OTP area + * @write: write to the SPI NAND OTP area + */ +struct spinand_otp_ops { + int (*info)(struct spinand_device *spinand, size_t len, + struct otp_info *buf, size_t *retlen); + int (*lock)(struct spinand_device *spinand, loff_t from, size_t len); + int (*erase)(struct spinand_device *spinand, loff_t from, size_t len); + int (*read)(struct spinand_device *spinand, loff_t from, size_t len, + u8 *buf, size_t *retlen); + int (*write)(struct spinand_device *spinand, loff_t from, size_t len, + const u8 *buf, size_t *retlen); +}; + +/** + * struct spinand_otp - SPI NAND OTP grouping structure + * @layout: OTP region layout + * @ops: OTP access ops + */ +struct spinand_otp { + const struct spinand_otp_layout layout; + const struct spinand_otp_ops *ops; +}; + /** * struct spinand_info - Structure used to describe SPI NAND chips * @model: model name @@ -354,6 +391,7 @@ struct spinand_info { } op_variants; int (*select_target)(struct spinand_device *spinand, unsigned int target); + struct spinand_otp otp; }; #define SPINAND_ID(__method, ...) \ @@ -379,6 +417,14 @@ struct spinand_info { #define SPINAND_SELECT_TARGET(__func) \ .select_target = __func, +#define SPINAND_OTP_INFO(__npages, __ops) \ + .otp = { \ + .layout = { \ + .npages = __npages, \ + }, \ + .ops = __ops, \ + } + #define SPINAND_INFO(__model, __id, __memorg, __eccreq, __op_variants, \ __flags, ...) \ { \ @@ -422,6 +468,7 @@ struct spinand_dirmap { * passed in spi_mem_op be DMA-able, so we can't based the bufs on * the stack * @manufacturer: SPI NAND manufacturer information + * @otp: SPI NAND OTP info. * @priv: manufacturer private data */ struct spinand_device { @@ -450,6 +497,7 @@ struct spinand_device { u8 *oobbuf; u8 *scratchbuf; const struct spinand_manufacturer *manufacturer; + const struct spinand_otp *otp; void *priv; }; @@ -525,4 +573,12 @@ int spinand_read_page(struct spinand_device *spinand, int spinand_write_page(struct spinand_device *spinand, const struct nand_page_io_req *req); +void spinand_set_mtd_otp_ops(struct spinand_device *spinand); + +int spinand_otp_read(struct spinand_device *spinand, loff_t from, size_t len, + u8 *buf, size_t *retlen); + +int spinand_otp_write(struct spinand_device *spinand, loff_t from, size_t len, + const u8 *buf, size_t *retlen); + #endif /* __LINUX_MTD_SPINAND_H */ From patchwork Mon Jun 17 13:34:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kurbanov X-Patchwork-Id: 1948630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Dd1xovIY; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=salutedevices.com header.i=@salutedevices.com header.a=rsa-sha256 header.s=mail header.b=AmHPfDiT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2rVn2YlHz20Ws for ; Mon, 17 Jun 2024 23:35:45 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7Xu1XJi6d0JZaEJQPY5KP0lSGQFjcgbCHw5ZEKHM6To=; b=Dd1xovIYRJu3Kz v51/G2nM3nzpD8gyVb3/jmDv7KIa9Vm2gVIDJlYTCyPwEdIz6i/ijIVR4u+VqlavBG+3sxSDJoQZ0 9h0PXzyfkyVfIgv9rIJbnfOt2qpuduvGJFD84NmDEUoMpJekoTZPVhr320+M8lcVgQbhmB8Gdgf8g EMpa2jGIBO3PpRxdSKfJh9zvPOLcvNvJRyZU905fvnkWgJ1X07f8Dd0SQXbXjOXrW91whgAnb32P2 s4uRBCgPlnddOKiUZtzSMIR+sB1TFrSFkjNB3RCpVj78rZ7C8DsHD4w8iqsv5wEsqXByFLkGEzltP Crx++tkHIBHTcCZCOv5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCWE-0000000Asfc-28ks; Mon, 17 Jun 2024 13:35:34 +0000 Received: from mx1.sberdevices.ru ([37.18.73.165]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCW8-0000000AsaO-3c1k for linux-mtd@lists.infradead.org; Mon, 17 Jun 2024 13:35:31 +0000 Received: from p-infra-ksmg-sc-msk01.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 1D6CB100009; Mon, 17 Jun 2024 16:35:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 1D6CB100009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1718631323; bh=s3IdEpoU8Idriuk8g63QAeoI/TR/7zBrB1N7H/17w8U=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=AmHPfDiTxt1A03tynXh9e4ElOYSFwA3pboSyYhjiSNG8gKbnaYEZAZZMOSy6rwT1x y4WyLGydxdIAhK7mFXjCMFz0gCGChrXigonvXRyRzMmsCTESZyRjUc1uU40TgPhgxQ 7Rii47N1O2fy7bzmaP7fvLDGk3fcUpd/C1Pd2vLou5cx0GljRkqT7nvOXaKQQFfbUb dUGzzHs7Ot/Noyca2lt8U1joca4VAqTw5Z287f85cphupiZRAxk101WBU4vBUhRX2x QLs88HsEufe8DnBR+MWI7Vn1WnvCH/t8vuGlocrP4f98uhd2L2KJ7CPjcUM3ZTVw3F traq7Z2IKwx1g== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Mon, 17 Jun 2024 16:35:22 +0300 (MSK) Received: from CAB-WSD-0004828.sberdevices.ru (100.64.160.123) by p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 17 Jun 2024 16:35:22 +0300 From: Martin Kurbanov To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Michael Walle , Mark Brown , Chia-Lin Kao , Md Sadre Alam , Ezra Buehler , Sridharan S N , Frieder Schrempf , Alexey Romanov CC: , , , Martin Kurbanov Subject: [PATCH v1 3/5] mtd: spinand: make spinand_wait() global Date: Mon, 17 Jun 2024 16:34:55 +0300 Message-ID: <20240617133504.179705-4-mmkurbanov@salutedevices.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240617133504.179705-1-mmkurbanov@salutedevices.com> References: <20240617133504.179705-1-mmkurbanov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 185966 [Jun 17 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: mmkurbanov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 20 0.3.20 743589a8af6ec90b529f2124c2bbfc3ce1d2f20f, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;salutedevices.com:7.1.1;100.64.160.123:7.1.2;smtp.sberdevices.ru:5.0.1,7.1.1;127.0.0.199:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/06/17 11:22:00 #25639124 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_063529_283468_1194E2E5 X-CRM114-Status: GOOD ( 14.79 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Change the function spinand_wait() from static to global so that SPI NAND flash drivers don't duplicate it. Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/core.c | 18 ++++++++++++++---- include/linux/mtd/spinand.h | 3 +++ 2 files changed, 17 insertions(+), 4 deletions [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Change the function spinand_wait() from static to global so that SPI NAND flash drivers don't duplicate it. Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/core.c | 18 ++++++++++++++---- include/linux/mtd/spinand.h | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 2cb825edd49d0..c3e3d1e9599f1 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -496,10 +496,20 @@ static int spinand_erase_op(struct spinand_device *spinand, return spi_mem_exec_op(spinand->spimem, &op); } -static int spinand_wait(struct spinand_device *spinand, - unsigned long initial_delay_us, - unsigned long poll_delay_us, - u8 *s) +/** + * spinand_wait() - Poll memory device status + * @spinand: the spinand device + * @initial_delay_us: delay in us before starting to poll + * @poll_delay_us: time to sleep between reads in us + * @s: the pointer to variable to store the value of REG_STATUS + * + * This function polls a status register (REG_STATUS) and returns when + * the STATUS_READY bit is 0 or when the timeout has expired. + * + * Return: 0 on success, a negative error code otherwise. + */ +int spinand_wait(struct spinand_device *spinand, unsigned long initial_delay_us, + unsigned long poll_delay_us, u8 *s) { struct spi_mem_op op = SPINAND_GET_FEATURE_OP(REG_STATUS, spinand->scratchbuf); diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h index a0d42a9be333f..3b9e7ed32c81d 100644 --- a/include/linux/mtd/spinand.h +++ b/include/linux/mtd/spinand.h @@ -567,6 +567,9 @@ int spinand_match_and_init(struct spinand_device *spinand, int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val); int spinand_select_target(struct spinand_device *spinand, unsigned int target); +int spinand_wait(struct spinand_device *spinand, unsigned long initial_delay_us, + unsigned long poll_delay_us, u8 *s); + int spinand_read_page(struct spinand_device *spinand, const struct nand_page_io_req *req); From patchwork Mon Jun 17 13:34:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kurbanov X-Patchwork-Id: 1948633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=vWw3u1Du; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=salutedevices.com header.i=@salutedevices.com header.a=rsa-sha256 header.s=mail header.b=B42RruPx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2rVt10Wpz20Ws for ; Mon, 17 Jun 2024 23:35:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eFnNBBB1CxkpGNmsiLLWEHi5/jp5qWAAOxp5zNCdwo0=; b=vWw3u1DuYF13Wb GHkJ60cwMvAijPq8dCr4b3L5N/CgzL80RlIV6BlRT9GReq2mmqCe5nu0gEHVIazELO9Tb0yvHy6Nm +r2u/mK0aMARnf8L9dDL+bsrvqRvRquDJDP/y6h3MzusB1r/GsCZ3P50LwIg/njQH2fMig540TLob BVsjWQowgY7SjvSY80WjG7T2hMKLAREhkXLJKEUgL84ebuWh7TxdvC/4LfZD/e/rCEaykNbJ1wJuc IJOF1WfJK0r0A1JEKDJFdSYp6yUTQXhGpKXVU31p4c9Pe8m4Ea54fjBB0AT8wrEmGxP48HWWGDLyd n3UtBy804K8jU/9EsfRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCWJ-0000000AsiT-0upd; Mon, 17 Jun 2024 13:35:39 +0000 Received: from mx2.sberdevices.ru ([45.89.224.132] helo=mx1.sberdevices.ru) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCW8-0000000Asap-3ijW for linux-mtd@lists.infradead.org; Mon, 17 Jun 2024 13:35:32 +0000 Received: from p-infra-ksmg-sc-msk02.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 5913812000C; Mon, 17 Jun 2024 16:35:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 5913812000C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1718631323; bh=/PdmQDr5X1ZUQQlzbIxZZmM5eEFyv/yRCGrGua+f4yo=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=B42RruPxDcQ7Qnmb1F2d92k0TDLMQae2lgOBpkj0qKyN/yxq2T99FyelQKXt7Aa1n nIrmyq6gHFleC+UrmJC2ZIcTiBOZE4ItxeyTBP9UWBVSeDZ+mOrCaWPlPcE6YQi0vi VnlkiUgkBuTH3zDGc5AJM45SBO2kVark8wPT5wsUAUiU6axjcW3o/27xDTfsWJ5B7s OjtlYHnC3jm871sRUffltz8JB1sCyYvEQcF2vMD+5uZV/NoQ0YWFlWDJlspV1AgQql vkC5ajsTXkQAHa6+q2ZB6gYW9Prk3P8fEYD1Cm7DxBQrRl7xa2CAi5e+4RPFFF6aah R7f+j0wlL/TwA== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Mon, 17 Jun 2024 16:35:23 +0300 (MSK) Received: from CAB-WSD-0004828.sberdevices.ru (100.64.160.123) by p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 17 Jun 2024 16:35:22 +0300 From: Martin Kurbanov To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Michael Walle , Mark Brown , Chia-Lin Kao , Md Sadre Alam , Ezra Buehler , Sridharan S N , Frieder Schrempf , Alexey Romanov CC: , , , Martin Kurbanov Subject: [PATCH v1 4/5] mtd: spinand: micron: OTP access for MT29F2G01ABAGD Date: Mon, 17 Jun 2024 16:34:56 +0300 Message-ID: <20240617133504.179705-5-mmkurbanov@salutedevices.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240617133504.179705-1-mmkurbanov@salutedevices.com> References: <20240617133504.179705-1-mmkurbanov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 185966 [Jun 17 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: mmkurbanov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 20 0.3.20 743589a8af6ec90b529f2124c2bbfc3ce1d2f20f, {Tracking_from_domain_doesnt_match_to}, 100.64.160.123:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;salutedevices.com:7.1.1;smtp.sberdevices.ru:7.1.1,5.0.1;127.0.0.199:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/06/17 12:47:00 #25641689 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_063529_318231_7391CEAA X-CRM114-Status: GOOD ( 18.29 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Support for OTP area access on Micron MT29F2G01ABAGD chip. Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/micron.c | 117 +++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Support for OTP area access on Micron MT29F2G01ABAGD chip. Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/micron.c | 117 +++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/spi/micron.c b/drivers/mtd/nand/spi/micron.c index 8d741be6d5f3e..a538409db4ccd 100644 --- a/drivers/mtd/nand/spi/micron.c +++ b/drivers/mtd/nand/spi/micron.c @@ -9,6 +9,7 @@ #include #include #include +#include #define SPINAND_MFR_MICRON 0x2c @@ -28,6 +29,16 @@ #define MICRON_SELECT_DIE(x) ((x) << 6) +#define MICRON_MT29F2G01ABAGD_OTP_PAGES 12 +#define MICRON_MT29F2G01ABAGD_OTP_PAGE_SIZE 2176 +#define MICRON_MT29F2G01ABAGD_OTP_SIZE_BYTES \ + (MICRON_MT29F2G01ABAGD_OTP_PAGES * \ + MICRON_MT29F2G01ABAGD_OTP_PAGE_SIZE) + +#define MICRON_MT29F2G01ABAGD_CFG_OTP_STATE BIT(7) +#define MICRON_MT29F2G01ABAGD_CFG_OTP_LOCK \ + (CFG_OTP_ENABLE | MICRON_MT29F2G01ABAGD_CFG_OTP_STATE) + static SPINAND_OP_VARIANTS(quadio_read_cache_variants, //SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0), SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), @@ -182,6 +193,108 @@ static int micron_8_ecc_get_status(struct spinand_device *spinand, return -EINVAL; } +static int mt29f2g01abagd_otp_is_locked(struct spinand_device *spinand) +{ + size_t buf_size = MICRON_MT29F2G01ABAGD_OTP_PAGE_SIZE; + size_t retlen; + u8 *buf; + int ret; + + buf = kmalloc(buf_size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = spinand_upd_cfg(spinand, + MICRON_MT29F2G01ABAGD_CFG_OTP_LOCK, + MICRON_MT29F2G01ABAGD_CFG_OTP_STATE); + if (ret) + goto out; + + ret = spinand_otp_read(spinand, 0, buf_size, buf, &retlen); + + if (spinand_upd_cfg(spinand, MICRON_MT29F2G01ABAGD_CFG_OTP_LOCK, + 0)) { + WARN(1, "Can not disable OTP mode\n"); + ret = -EIO; + } + + if (!ret) { + size_t i = 0; + + /* If all zeros, then the OTP area is locked. */ + while (i < buf_size && *(uint32_t *)(&buf[i]) == 0) + i += 4; + + if (i == buf_size) + ret = 1; + } + +out: + kfree(buf); + return ret; +} + +static int mt29f2g01abagd_otp_info(struct spinand_device *spinand, size_t len, + struct otp_info *buf, size_t *retlen) +{ + int locked; + + if (len < sizeof(*buf)) + return -EINVAL; + + locked = mt29f2g01abagd_otp_is_locked(spinand); + if (locked < 0) + return locked; + + buf->locked = locked; + buf->start = 0; + buf->length = MICRON_MT29F2G01ABAGD_OTP_SIZE_BYTES; + + *retlen = sizeof(*buf); + return 0; +} + +static int mt29f2g01abagd_otp_lock(struct spinand_device *spinand, loff_t from, + size_t len) +{ + struct spi_mem_op write_op = SPINAND_WR_EN_DIS_OP(true); + struct spi_mem_op exec_op = SPINAND_PROG_EXEC_OP(0); + int ret; + + ret = spinand_upd_cfg(spinand, + MICRON_MT29F2G01ABAGD_CFG_OTP_LOCK, + MICRON_MT29F2G01ABAGD_CFG_OTP_LOCK); + if (!ret) + return ret; + + ret = spi_mem_exec_op(spinand->spimem, &write_op); + if (!ret) + goto out; + + ret = spi_mem_exec_op(spinand->spimem, &exec_op); + if (!ret) + goto out; + + ret = spinand_wait(spinand, 10, 5, NULL); + if (!ret) + goto out; + +out: + if (spinand_upd_cfg(spinand, MICRON_MT29F2G01ABAGD_CFG_OTP_LOCK, 0)) { + WARN(1, "Can not disable OTP mode\n"); + ret = -EIO; + } + + return ret; +} + +static const struct spinand_otp_ops mt29f2g01abagd_otp_ops = { + .info = mt29f2g01abagd_otp_info, + .lock = mt29f2g01abagd_otp_lock, + .read = spinand_otp_read, + .write = spinand_otp_write, +}; + static const struct spinand_info micron_spinand_table[] = { /* M79A 2Gb 3.3V */ SPINAND_INFO("MT29F2G01ABAGD", @@ -193,7 +306,9 @@ static const struct spinand_info micron_spinand_table[] = { &x4_update_cache_variants), 0, SPINAND_ECCINFO(µn_8_ooblayout, - micron_8_ecc_get_status)), + micron_8_ecc_get_status), + SPINAND_OTP_INFO(MICRON_MT29F2G01ABAGD_OTP_PAGES, + &mt29f2g01abagd_otp_ops)), /* M79A 2Gb 1.8V */ SPINAND_INFO("MT29F2G01ABBGD", SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x25), From patchwork Mon Jun 17 13:34:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kurbanov X-Patchwork-Id: 1948632 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=bTlctiIG; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=salutedevices.com header.i=@salutedevices.com header.a=rsa-sha256 header.s=mail header.b=oox7kvXC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W2rVn5R47z20Z6 for ; Mon, 17 Jun 2024 23:35:45 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HlkNGhhiJ1iXkXG83grdBWcFEm3Ev5eeAgbogszQRpI=; b=bTlctiIGO1koVt b2SQvqDKQwKy77sXRj1nhZR+Lsk7ThkPPOUBZzJnfTGqO2/BCkZOgCAFJGzgxM5Hz5yihPTaSIBdn AIUOHOOnIoN5T2UWdmjIuaJtlzr5CqlEXBi4b3yNaWGYlz0c1I12z8py7LHt0Il6+JaAR2z411L9z +Ez1TTKx22H2TJIKYmJAVMIw1Wb+Gt3DmU+0OndxbY6Wk26NAVgv2PW8PVJcEBLNVPsIwSxDr/Ot0 Kk4VQ0RUmgdRKbsuazI8aEf6r4AYXcPHdiffXAfwJuB7Hf2pUMEThdAWl96DnWAtIvaMauPk4V4Nz J8KvG8tbyyzkawitFmjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCWF-0000000Asg0-1hG1; Mon, 17 Jun 2024 13:35:35 +0000 Received: from mx1.sberdevices.ru ([37.18.73.165]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJCW8-0000000Asag-3K3U for linux-mtd@lists.infradead.org; Mon, 17 Jun 2024 13:35:30 +0000 Received: from p-infra-ksmg-sc-msk01.sberdevices.ru (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id A5BDA10000B; Mon, 17 Jun 2024 16:35:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru A5BDA10000B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1718631323; bh=YcHG6WWlH0ElSTuFNLEX2yBk3OYum4OtJYp6S6fudRY=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=oox7kvXCIibITAlHTmBPP+PQgiGmN+ytwo7GRD1FAakArfLHnuuCIONgRs7OnI5cb VKlgm6mTm0dfolhKJSvHLPdacW5HP9LsnV2gn3a+BXoIse8ooynrr4Bn6rVhuIlfhT 3eVYhBQpky9ptqMS9r8txCdeeoZq/2O2MXxBnpSUoLg8RSiguji0/gK2cYV3/cNtNE mtAK+9xaZH6kdtEFR4JvdOdYc16ikFCAPpw+E6djeq/3cWLaZs3dIdOoIkydH8rhUU rVOX/PYk5QExj5eXwC6vPOYQ+V3om3sq5LgsDaWRoT7Nk5o8ImYhxEfjQ0puNXtUy1 DlJNAdGsXuheg== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Mon, 17 Jun 2024 16:35:23 +0300 (MSK) Received: from CAB-WSD-0004828.sberdevices.ru (100.64.160.123) by p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 17 Jun 2024 16:35:23 +0300 From: Martin Kurbanov To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Michael Walle , Mark Brown , Chia-Lin Kao , Md Sadre Alam , Ezra Buehler , Sridharan S N , Frieder Schrempf , Alexey Romanov CC: , , , Martin Kurbanov Subject: [PATCH v1 5/5] mtd: spinand: esmt: OTP access for F50{L,D}1G41LB Date: Mon, 17 Jun 2024 16:34:57 +0300 Message-ID: <20240617133504.179705-6-mmkurbanov@salutedevices.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240617133504.179705-1-mmkurbanov@salutedevices.com> References: <20240617133504.179705-1-mmkurbanov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 185966 [Jun 17 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: mmkurbanov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 20 0.3.20 743589a8af6ec90b529f2124c2bbfc3ce1d2f20f, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;salutedevices.com:7.1.1;100.64.160.123:7.1.2;smtp.sberdevices.ru:5.0.1,7.1.1;127.0.0.199:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/06/17 11:22:00 #25639124 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_063529_230131_F14E5D91 X-CRM114-Status: GOOD ( 15.00 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Support for OTP area access on ESMT F50L1G41LB and F50D1G41LB chips. Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/esmt.c | 69 +++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Support for OTP area access on ESMT F50L1G41LB and F50D1G41LB chips. Signed-off-by: Martin Kurbanov --- drivers/mtd/nand/spi/esmt.c | 69 +++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/spi/esmt.c b/drivers/mtd/nand/spi/esmt.c index 4597a82de23a4..1806e9d48c176 100644 --- a/drivers/mtd/nand/spi/esmt.c +++ b/drivers/mtd/nand/spi/esmt.c @@ -12,6 +12,13 @@ /* ESMT uses GigaDevice 0xc8 JECDEC ID on some SPI NANDs */ #define SPINAND_MFR_ESMT_C8 0xc8 +#define ESMT_F50L1G41LB_CFG_OTP_PROTECT BIT(7) +#define ESMT_F50L1G41LB_CFG_OTP_LOCK \ + (CFG_OTP_ENABLE | ESMT_F50L1G41LB_CFG_OTP_PROTECT) + +#define ESMT_F50L1G41LB_PAGE_SIZE 2112 +#define ESMT_F50L1G41LB_OTP_PAGES 28 + static SPINAND_OP_VARIANTS(read_cache_variants, SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0), @@ -102,6 +109,60 @@ static const struct mtd_ooblayout_ops f50l1g41lb_ooblayout = { .free = f50l1g41lb_ooblayout_free, }; +static int f50l1g41lb_otp_info(struct spinand_device *spinand, size_t len, + struct otp_info *buf, size_t *retlen) +{ + if (len < sizeof(*buf)) + return -EINVAL; + + buf->locked = 0; + buf->start = 0; + buf->length = ESMT_F50L1G41LB_PAGE_SIZE * ESMT_F50L1G41LB_OTP_PAGES; + + *retlen = sizeof(*buf); + return 0; +} + +static int f50l1g41lb_otp_lock(struct spinand_device *spinand, loff_t from, + size_t len) +{ + struct spi_mem_op write_op = SPINAND_WR_EN_DIS_OP(true); + struct spi_mem_op exec_op = SPINAND_PROG_EXEC_OP(0); + int ret; + + ret = spinand_upd_cfg(spinand, ESMT_F50L1G41LB_CFG_OTP_LOCK, + ESMT_F50L1G41LB_CFG_OTP_LOCK); + if (!ret) + return ret; + + ret = spi_mem_exec_op(spinand->spimem, &write_op); + if (!ret) + goto out; + + ret = spi_mem_exec_op(spinand->spimem, &exec_op); + if (!ret) + goto out; + + ret = spinand_wait(spinand, 10, 5, NULL); + if (!ret) + goto out; + +out: + if (spinand_upd_cfg(spinand, ESMT_F50L1G41LB_CFG_OTP_LOCK, 0)) { + WARN(1, "Can not disable OTP mode\n"); + ret = -EIO; + } + + return ret; +} + +static const struct spinand_otp_ops f50l1g41lb_otp_ops = { + .info = f50l1g41lb_otp_info, + .lock = f50l1g41lb_otp_lock, + .read = spinand_otp_read, + .write = spinand_otp_write, +}; + static const struct spinand_info esmt_c8_spinand_table[] = { SPINAND_INFO("F50L1G41LB", SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x01, 0x7f, @@ -112,7 +173,9 @@ static const struct spinand_info esmt_c8_spinand_table[] = { &write_cache_variants, &update_cache_variants), 0, - SPINAND_ECCINFO(&f50l1g41lb_ooblayout, NULL)), + SPINAND_ECCINFO(&f50l1g41lb_ooblayout, NULL), + SPINAND_OTP_INFO(ESMT_F50L1G41LB_OTP_PAGES, + &f50l1g41lb_otp_ops)), SPINAND_INFO("F50D1G41LB", SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x11, 0x7f, 0x7f, 0x7f), @@ -122,7 +185,9 @@ static const struct spinand_info esmt_c8_spinand_table[] = { &write_cache_variants, &update_cache_variants), 0, - SPINAND_ECCINFO(&f50l1g41lb_ooblayout, NULL)), + SPINAND_ECCINFO(&f50l1g41lb_ooblayout, NULL), + SPINAND_OTP_INFO(ESMT_F50L1G41LB_OTP_PAGES, + &f50l1g41lb_otp_ops)), SPINAND_INFO("F50D2G41KA", SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x51, 0x7f, 0x7f, 0x7f),