From: Erez Geva <erezgeva@nwtime.org>
To: linux-mtd@lists.infradead.org,
Tudor Ambarus <tudor.ambarus@linaro.org>,
Pratyush Yadav <pratyush@kernel.org>,
Michael Walle <mwalle@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
devicetree@vger.kernel.org, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Esben Haabendal <esben@geanix.com>,
Erez Geva <ErezGeva2@gmail.com>
Subject: [PATCH v5 1/5] mtd: spi-nor: core: add manufacturer flags
Date: Fri, 20 Sep 2024 20:12:27 +0200 [thread overview]
Message-ID: <20240920181231.20542-2-erezgeva@nwtime.org> (raw)
In-Reply-To: <20240920181231.20542-1-erezgeva@nwtime.org>
From: Erez Geva <ErezGeva2@gmail.com>
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 patch series we use the new flags with Macronix.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
---
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 9d6e85bf227b..0238475059f0 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_TRY_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, "otp-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..c862e42c844f 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_TRY_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 9f7ce5763e71..b60df00e43b9 100644
--- a/drivers/mtd/spi-nor/winbond.c
+++ b/drivers/mtd/spi-nor/winbond.c
@@ -333,7 +333,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;
/*
--
2.39.5
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2024-09-20 18:22 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-20 18:12 [PATCH v5 0/5] Add support for SPI-NOR Macronix OTP Erez Geva
2024-09-20 18:12 ` Erez Geva [this message]
2024-09-23 6:04 ` [PATCH v5 1/5] mtd: spi-nor: core: add manufacturer flags Tudor Ambarus
2024-09-23 10:31 ` Erez
2024-09-23 10:46 ` Michael Walle
2024-09-23 13:25 ` Erez
2024-09-23 16:19 ` Michael Walle
2024-09-23 16:31 ` Erez
2024-09-23 18:04 ` Tudor Ambarus
2024-09-23 18:21 ` Tudor Ambarus
2024-09-26 7:46 ` Esben Haabendal
2024-09-26 11:08 ` Erez
2024-09-26 11:37 ` Esben Haabendal
2024-09-26 13:16 ` Erez
2024-09-23 12:07 ` Tudor Ambarus
2024-09-23 13:01 ` Erez
2024-09-23 14:18 ` Tudor Ambarus
2024-09-23 14:51 ` Erez
2024-09-23 17:52 ` Tudor Ambarus
2024-09-23 19:30 ` Erez
2024-09-23 21:41 ` Erez
2024-09-24 6:04 ` Tudor Ambarus
2024-09-24 6:01 ` Tudor Ambarus
2024-09-20 18:12 ` [PATCH v5 2/5] mtd: spi-nor: core: add generic functions Erez Geva
2024-09-20 18:12 ` [PATCH v5 3/5] dt-bindings: mtd: spi-nor: add OTP parameters Erez Geva
2024-09-22 20:40 ` Krzysztof Kozlowski
2024-09-23 9:21 ` Erez
2024-09-23 15:42 ` Krzysztof Kozlowski
2024-09-23 15:49 ` Erez
2024-09-20 18:12 ` [PATCH v5 4/5] mtd: spi-nor: macronix: add support for OTP Erez Geva
2024-09-20 18:12 ` [PATCH v5 5/5] mtd: spi-nor: macronix: add manufacturer flags Erez Geva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240920181231.20542-2-erezgeva@nwtime.org \
--to=erezgeva@nwtime.org \
--cc=ErezGeva2@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=esben@geanix.com \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=robh@kernel.org \
--cc=tudor.ambarus@linaro.org \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox