From: Michael Walle <michael@walle.cc>
To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org
Cc: Tudor Ambarus <tudor.ambarus@microchip.com>,
Pratyush Yadav <p.yadav@ti.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Michael Walle <michael@walle.cc>
Subject: [RFC PATCH 1/3] mtd: spi-nor: sfdp: remember sfdp_size
Date: Fri, 12 Mar 2021 20:05:46 +0100 [thread overview]
Message-ID: <20210312190548.6954-2-michael@walle.cc> (raw)
In-Reply-To: <20210312190548.6954-1-michael@walle.cc>
Save the sftp_size in the spi_nor struct so we can use it to dump the
SFDP table without parsing the headers again.
Signed-off-by: Michael Walle <michael@walle.cc>
---
drivers/mtd/spi-nor/sfdp.c | 12 ++++++++++++
include/linux/mtd/spi-nor.h | 1 +
2 files changed, 13 insertions(+)
diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
index 25142ec4737b..b1814afefc33 100644
--- a/drivers/mtd/spi-nor/sfdp.c
+++ b/drivers/mtd/spi-nor/sfdp.c
@@ -16,6 +16,7 @@
(((p)->parameter_table_pointer[2] << 16) | \
((p)->parameter_table_pointer[1] << 8) | \
((p)->parameter_table_pointer[0] << 0))
+#define SFDP_PARAM_HEADER_PARAM_LEN(p) ((p)->length * 4)
#define SFDP_BFPT_ID 0xff00 /* Basic Flash Parameter Table */
#define SFDP_SECTOR_MAP_ID 0xff81 /* Sector Map Table */
@@ -1263,6 +1264,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor,
struct sfdp_parameter_header *param_headers = NULL;
struct sfdp_header header;
struct device *dev = nor->dev;
+ size_t param_max_offset;
size_t psize;
int i, err;
@@ -1285,6 +1287,9 @@ int spi_nor_parse_sfdp(struct spi_nor *nor,
bfpt_header->major != SFDP_JESD216_MAJOR)
return -EINVAL;
+ nor->sfdp_size = SFDP_PARAM_HEADER_PTP(bfpt_header) +
+ SFDP_PARAM_HEADER_PARAM_LEN(bfpt_header);
+
/*
* Allocate memory then read all parameter headers with a single
* Read SFDP command. These parameter headers will actually be parsed
@@ -1311,6 +1316,13 @@ int spi_nor_parse_sfdp(struct spi_nor *nor,
}
}
+ for (i = 0; i < header.nph; i++) {
+ param_header = ¶m_headers[i];
+ param_max_offset = SFDP_PARAM_HEADER_PTP(param_header) +
+ SFDP_PARAM_HEADER_PARAM_LEN(param_header);
+ nor->sfdp_size = max(nor->sfdp_size, param_max_offset);
+ }
+
/*
* Check other parameter headers to get the latest revision of
* the basic flash parameter table.
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index a0d572855444..a58118b8b002 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -404,6 +404,7 @@ struct spi_nor {
bool sst_write_second;
u32 flags;
enum spi_nor_cmd_ext cmd_ext_type;
+ size_t sfdp_size;
const struct spi_nor_controller_ops *controller_ops;
--
2.20.1
next prev parent reply other threads:[~2021-03-12 19:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-12 19:05 [RFC PATCH 1/3] mtd: spi-nor: support dumping sfdp tables Michael Walle
2021-03-12 19:05 ` Michael Walle [this message]
2021-03-16 10:42 ` [RFC PATCH 1/3] mtd: spi-nor: sfdp: remember sfdp_size Pratyush Yadav
2021-03-16 11:01 ` Michael Walle
2021-03-16 11:06 ` Pratyush Yadav
2021-03-16 11:22 ` Michael Walle
2021-03-12 19:05 ` [RFC PATCH 2/3] mtd: spi-nor: sfdp: fix spi_nor_read_sfdp() Michael Walle
2021-03-16 11:04 ` Pratyush Yadav
2021-03-16 11:15 ` Michael Walle
2021-03-16 13:15 ` Pratyush Yadav
2021-03-12 19:05 ` [RFC PATCH 3/3] mtd: spi-nor: add sysfs and SFDP support Michael Walle
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=20210312190548.6954-2-michael@walle.cc \
--to=michael@walle.cc \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=p.yadav@ti.com \
--cc=richard@nod.at \
--cc=tudor.ambarus@microchip.com \
--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;
as well as URLs for NNTP newsgroup(s).