[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240124122204.730370-6-o.rempel@pengutronix.de>
Date: Wed, 24 Jan 2024 13:22:01 +0100
From: Oleksij Rempel <o.rempel@...gutronix.de>
To: Sebastian Reichel <sre@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Conor Dooley <conor+dt@...nel.org>,
Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
Cc: Oleksij Rempel <o.rempel@...gutronix.de>,
kernel@...gutronix.de,
linux-kernel@...r.kernel.org,
Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Zhang Rui <rui.zhang@...el.com>,
Lukasz Luba <lukasz.luba@....com>,
linux-pm@...r.kernel.org,
devicetree@...r.kernel.org,
Søren Andersen <san@...v.dk>
Subject: [PATCH v2 5/8] nvmem: provide consumer access to cell size metrics
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@...gutronix.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
Powered by blists - more mailing lists