From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Sebastian Reichel <sre@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
kernel@pengutronix.de, linux-kernel@vger.kernel.org,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Daniel Lezcano" <daniel.lezcano@linaro.org>,
"Zhang Rui" <rui.zhang@intel.com>,
"Lukasz Luba" <lukasz.luba@arm.com>,
linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
"Søren Andersen" <san@skov.dk>
Subject: [PATCH v2 5/8] nvmem: provide consumer access to cell size metrics
Date: Wed, 24 Jan 2024 13:22:01 +0100 [thread overview]
Message-ID: <20240124122204.730370-6-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20240124122204.730370-1-o.rempel@pengutronix.de>
Add nvmem_cell_get_size() function to provide access to cell size
metrics. In some cases we may get cell size less as consumer would
expect it. So, nvmem_cell_write() would fail with incorrect buffer size.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/nvmem/core.c | 25 +++++++++++++++++++++++++
include/linux/nvmem-consumer.h | 7 +++++++
2 files changed, 32 insertions(+)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 980123fb4dde..a21e5649fcda 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1790,6 +1790,31 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
EXPORT_SYMBOL_GPL(nvmem_cell_write);
+/**
+ * nvmem_cell_get_size() - Get the size of a given nvmem cell
+ * @cell: nvmem cell to be queried.
+ * @bytes: Pointer to store the size of the cell in bytes. Can be NULL.
+ * @bits: Pointer to store the size of the cell in bits. Can be NULL.
+ *
+ * Return: 0 on success or negative on failure.
+ */
+int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, size_t *bits)
+{
+ struct nvmem_cell_entry *entry = cell->entry;
+
+ if (!entry->nvmem)
+ return -EINVAL;
+
+ if (bytes)
+ *bytes = entry->bytes;
+
+ if (bits)
+ *bits = entry->nbits;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(nvmem_cell_get_size);
+
static int nvmem_cell_read_common(struct device *dev, const char *cell_id,
void *val, size_t count)
{
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 34c0e58dfa26..bcb0e17e415d 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -56,6 +56,7 @@ void nvmem_cell_put(struct nvmem_cell *cell);
void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell);
void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
+int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, size_t *bits);
int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val);
int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val);
int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val);
@@ -128,6 +129,12 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell,
return -EOPNOTSUPP;
}
+static inline int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes,
+ size_t *bits)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int nvmem_cell_read_u8(struct device *dev,
const char *cell_id, u8 *val)
{
--
2.39.2
next prev parent reply other threads:[~2024-01-24 12:22 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 12:21 [RFC PATCH v1 0/8] Introduction of PSCR Framework and Related Components Oleksij Rempel
2024-01-24 12:21 ` [PATCH v2 1/8] power: Extend power_on_reason.h for upcoming PSCRR framework Oleksij Rempel
2024-01-24 12:21 ` [PATCH v2 2/8] dt-bindings: power: reset: add generic PSCRR binding trackers Oleksij Rempel
2024-01-25 10:54 ` Krzysztof Kozlowski
2024-01-24 12:21 ` [PATCH v2 3/8] power: reset: Introduce PSCR Recording Framework for Non-Volatile Storage Oleksij Rempel
2024-01-28 9:05 ` kernel test robot
2024-01-24 12:22 ` [PATCH v2 4/8] dt-bindings: power: reset: add bindings for NVMEM hardware storing PSCR Data Oleksij Rempel
2024-01-25 10:57 ` Krzysztof Kozlowski
2024-01-25 17:11 ` Oleksij Rempel
2024-01-26 9:03 ` Krzysztof Kozlowski
2024-01-26 16:51 ` Oleksij Rempel
2024-01-29 7:43 ` Krzysztof Kozlowski
2024-01-24 12:22 ` Oleksij Rempel [this message]
2024-01-24 12:22 ` [PATCH v2 6/8] power: reset: add PSCR NVMEM Driver for Recording Power State Change Reasons Oleksij Rempel
2024-01-28 6:38 ` kernel test robot
2024-01-24 12:22 ` [PATCH v2 7/8] regulator: set Power State Change Reason before hw_protection_shutdown() Oleksij Rempel
2024-01-24 12:22 ` [PATCH v2 8/8] thermal: core: Record PSCR " Oleksij Rempel
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=20240124122204.730370-6-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=kernel@pengutronix.de \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=rui.zhang@intel.com \
--cc=san@skov.dk \
--cc=sre@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
/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).