From patchwork Sat Aug 17 12:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erez Geva X-Patchwork-Id: 1973484 X-Patchwork-Delegate: tudor.ambarus@gmail.com 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=HsDPJarC; 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 4WmJZb06VBz1yXf for ; Sat, 17 Aug 2024 22:48:55 +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=PivT2GVu64eSpIaCfDS4U7M6NL4Gv0PwXc3AoMeOPS0=; b=HsDPJarCrCnMgB jqnIJG2cfo2imR6b4rzLf87GrxVK06/ob/3CP6jnQdPZJAq39nbzcS5DQ1RFA3H0by5gFOAmF+x7W SLNoJjlkXc4VZtgyW7amz4ufFifffI1mcKGoY8K9n/IAgLRqm4q0V/G1U3R7B02AY4RoFwp0pIRbe kwu2rTH8k7NbbfVj5VVULZKIVr87qk3Hm7iwT71rtHIjMW5G4BS8d612S+1k851BgOPH0VkiYmAIi x1ULgVWU2/Ts7RuOCBiYq5cPe7V+UwZD4NnP+65nzBYw/oUsmdmxfzZ8iZdBosCl2Uj+tKn0MVpdd XUxaL49a+axMUjyzu7yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfIrL-0000000FDT5-2I1o; Sat, 17 Aug 2024 12:48:43 +0000 Received: from chessie.fmt1.pfcs.com ([2001:470:1:205::234] helo=chessie.everett.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfIrH-0000000FDRn-3nyA for linux-mtd@lists.infradead.org; Sat, 17 Aug 2024 12:48:41 +0000 Received: from localhost.localdomain (ip1f10f85d.dynamic.kabel-deutschland.de [31.16.248.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by chessie.everett.org (Postfix) with ESMTPSA id 4WmJQq5n3hzMQsP; Sat, 17 Aug 2024 12:42:11 +0000 (UTC) From: Erez Geva To: linux-mtd@lists.infradead.org, Tudor Ambarus , Pratyush Yadav , Michael Walle Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Erez Geva Subject: [PATCH v3 1/4] mtd: spi-nor: core: add manufacturer flags Date: Sat, 17 Aug 2024 14:41:37 +0200 Message-Id: <20240817124140.800637-2-erezgeva@nwtime.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240817124140.800637-1-erezgeva@nwtime.org> References: <20240817124140.800637-1-erezgeva@nwtime.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240817_054839_996857_58F565F0 X-CRM114-Status: GOOD ( 19.41 ) X-Spam-Score: -1.9 (-) 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: From: Erez Geva Add flag for always trying reading SFDP: Some vendors reuse all JEDEC IDs on manufacture table with new chips that support SFDP. Add flag for reading OTP parameters from device tree. Some vendors reuse JEDEC IDs with several chips with different OTP parameters. Alternatively we read parameters from SFDP. But the OTP parameters [...] Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 From: Erez Geva Add flag for always trying reading SFDP: Some vendors reuse all JEDEC IDs on manufacture table with new chips that support SFDP. Add flag for reading OTP parameters from device tree. Some vendors reuse JEDEC IDs with several chips with different OTP parameters. Alternatively we read parameters from SFDP. But the OTP parameters are absent from the SFDP. So there is not other way but to add the OTP parameters in the device tree. In this series, we will use the flags with Macronix. Signed-off-by: Erez Geva --- drivers/mtd/spi-nor/core.c | 36 ++++++++++++++++++++++++++++++----- drivers/mtd/spi-nor/core.h | 7 ++++++- drivers/mtd/spi-nor/otp.c | 6 +++--- drivers/mtd/spi-nor/winbond.c | 2 +- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index e0c4efc424f4..af522c426ac9 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -2891,10 +2891,11 @@ static void spi_nor_init_params_deprecated(struct spi_nor *nor) spi_nor_manufacturer_init_params(nor); - if (nor->info->no_sfdp_flags & (SPI_NOR_DUAL_READ | - SPI_NOR_QUAD_READ | - SPI_NOR_OCTAL_READ | - SPI_NOR_OCTAL_DTR_READ)) + if ((nor->info->no_sfdp_flags & (SPI_NOR_DUAL_READ | + SPI_NOR_QUAD_READ | + SPI_NOR_OCTAL_READ | + SPI_NOR_OCTAL_DTR_READ)) || + nor->manufacturer->flags & SPI_NOR_MANUFACT_TTY_SFDP) spi_nor_sfdp_init_params_deprecated(nor); } @@ -2911,7 +2912,32 @@ static void spi_nor_init_default_params(struct spi_nor *nor) struct device_node *np = spi_nor_get_flash_node(nor); params->quad_enable = spi_nor_sr2_bit1_quad_enable; - params->otp.org = info->otp; + memset(¶ms->otp.org, 0, sizeof(struct spi_nor_otp_organization)); + if (info->otp) { + memcpy(¶ms->otp.org, info->otp, sizeof(struct spi_nor_otp_organization)); + } else if (nor->manufacturer->flags & SPI_NOR_MANUFACT_DT_OTP) { + /* Check for OTP information on device tree */ + u32 n_regions, len; + + if (!of_property_read_u32(np, "opt_n_regions", &n_regions) && + n_regions > 0 && + !of_property_read_u32(np, "otp_len", &len) && + len > 0) { + u32 base, offset = 0; + + if (n_regions > 1) { + /* If offset is not defined use length as offset */ + if (of_property_read_u32(np, "otp_offset", &offset)) + offset = len; + } + if (of_property_read_u32(np, "otp_base", &base)) + base = 0; + params->otp.org.n_regions = n_regions; + params->otp.org.offset = offset; + params->otp.org.base = base; + params->otp.org.len = len; + } + } /* Default to 16-bit Write Status (01h) Command */ nor->flags |= SNOR_F_HAS_16BIT_SR; diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 1516b6d0dc37..237196b908dd 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -326,7 +326,7 @@ struct spi_nor_otp_ops { * @ops: OTP access ops */ struct spi_nor_otp { - const struct spi_nor_otp_organization *org; + struct spi_nor_otp_organization org; const struct spi_nor_otp_ops *ops; }; @@ -560,12 +560,17 @@ struct flash_info { * @parts: array of parts supported by this manufacturer * @nparts: number of entries in the parts array * @fixups: hooks called at various points in time during spi_nor_scan() + * @flags: manufacturer flags */ struct spi_nor_manufacturer { const char *name; const struct flash_info *parts; unsigned int nparts; const struct spi_nor_fixups *fixups; + + u8 flags; +#define SPI_NOR_MANUFACT_TTY_SFDP BIT(0) +#define SPI_NOR_MANUFACT_DT_OTP BIT(0) }; /** diff --git a/drivers/mtd/spi-nor/otp.c b/drivers/mtd/spi-nor/otp.c index 9a729aa3452d..ffb7ffeb9030 100644 --- a/drivers/mtd/spi-nor/otp.c +++ b/drivers/mtd/spi-nor/otp.c @@ -11,8 +11,8 @@ #include "core.h" -#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org->len) -#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org->n_regions) +#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org.len) +#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org.n_regions) /** * spi_nor_otp_read_secr() - read security register @@ -222,7 +222,7 @@ int spi_nor_otp_is_locked_sr2(struct spi_nor *nor, unsigned int region) static loff_t spi_nor_otp_region_start(const struct spi_nor *nor, unsigned int region) { - const struct spi_nor_otp_organization *org = nor->params->otp.org; + const struct spi_nor_otp_organization *org = &nor->params->otp.org; return org->base + region * org->offset; } diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c index e065e4fd42a3..15af62aacc9a 100644 --- a/drivers/mtd/spi-nor/winbond.c +++ b/drivers/mtd/spi-nor/winbond.c @@ -307,7 +307,7 @@ static int winbond_nor_late_init(struct spi_nor *nor) { struct spi_nor_flash_parameter *params = nor->params; - if (params->otp.org) + if (params->otp.org.n_regions) params->otp.ops = &winbond_nor_otp_ops; /*