mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: lst@pengutronix.de, ukl@pengutronix.de,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 06/10] nvmem: import Linux nvmem_cell_read_variable_le_u32
Date: Thu, 18 Aug 2022 07:19:51 +0200	[thread overview]
Message-ID: <20220818051955.2088238-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220818051955.2088238-1-a.fatoum@pengutronix.de>

We already have nvmem_cell_get_and_read(), so add its Linux sibling
nvmem_cell_read_variable_le_u32 as well, which additionally takes care
of conversion to little-endian.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/nvmem/core.c           | 33 +++++++++++++++++++++++++++++++++
 include/linux/nvmem-consumer.h |  9 +++++++++
 2 files changed, 42 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index fed387c43a26..c5fe5f6b767a 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -803,3 +803,36 @@ void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
 	return value;
 }
 EXPORT_SYMBOL_GPL(nvmem_cell_get_and_read);
+
+/**
+ * nvmem_cell_read_variable_le_u32() - Read up to 32-bits of data as a little endian number.
+ *
+ * @dev: Device that requests the nvmem cell.
+ * @cell_id: Name of nvmem cell to read.
+ * @val: pointer to output value.
+ *
+ * Return: 0 on success or negative errno.
+ */
+int nvmem_cell_read_variable_le_u32(struct device_d *dev, const char *cell_id,
+				    u32 *val)
+{
+	size_t len;
+	const u8 *buf;
+	int i;
+
+	len = sizeof(*val);
+
+	buf = nvmem_cell_get_and_read(dev->device_node, cell_id, len);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
+
+	/* Copy w/ implicit endian conversion */
+	*val = 0;
+	for (i = 0; i < len; i++)
+		*val |= buf[i] << (8 * i);
+
+	kfree(buf);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nvmem_cell_read_variable_le_u32);
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index b979f23372a6..b461f840957e 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -34,6 +34,8 @@ void nvmem_cell_put(struct nvmem_cell *cell);
 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
 void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
 			      size_t bytes);
+int nvmem_cell_read_variable_le_u32(struct device_d *dev, const char *cell_id,
+				    u32 *val);
 
 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
 
@@ -75,6 +77,13 @@ static inline void *nvmem_cell_get_and_read(struct device_node *np,
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
+static inline int nvmem_cell_read_variable_le_u32(struct device_d *dev,
+						  const char *cell_id,
+						  u32 *val)
+{
+	return ERR_PTR(-EOPNOTSUPP);
+}
+
 static inline int nvmem_cell_write(struct nvmem_cell *cell,
 				    void *buf, size_t len)
 {
-- 
2.30.2




  parent reply	other threads:[~2022-08-18  5:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18  5:19 [PATCH 00/10] Add new feature controller framework Ahmad Fatoum
2022-08-18  5:19 ` [PATCH 01/10] driver: add " Ahmad Fatoum
2022-08-18  5:19 ` [PATCH 02/10] driver: consult feature controller prior to device probe Ahmad Fatoum
2022-08-18  8:19   ` Philipp Zabel
2022-08-18  8:34     ` Ahmad Fatoum
2022-08-18  5:19 ` [PATCH 03/10] driver: featctrl: fixup kernel device tree Ahmad Fatoum
2022-08-18  5:19 ` [PATCH 04/10] dt-bindings: add i.MX8M feature controller bindings Ahmad Fatoum
2022-08-18  5:19 ` [PATCH 05/10] soc: imx: add i.MX8M feature controller driver Ahmad Fatoum
2022-08-18  5:19 ` Ahmad Fatoum [this message]
2022-08-18  5:19 ` [PATCH 07/10] nvmem: ocotp: add i.MX8M[MN] feature controller support Ahmad Fatoum
2022-08-18  5:19 ` [PATCH 08/10] ARM: dts: i.MX8MN: describe feature controller Ahmad Fatoum
2022-08-18  5:19 ` [PATCH 09/10] RFC: soc: imx: imx8m-featctrl: add i.MX8M[MN] stand-alone driver Ahmad Fatoum
2022-08-18  5:19 ` [PATCH 10/10] RFC: ARM: dts: i.MX8MM: describe standlone feature controller Ahmad Fatoum
2022-08-30  7:32 ` [PATCH 00/10] Add new feature controller framework Sascha Hauer
2022-08-30  7:38   ` Ahmad Fatoum
2022-08-31  6:06     ` Sascha Hauer

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=20220818051955.2088238-7-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=lst@pengutronix.de \
    --cc=ukl@pengutronix.de \
    /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