All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leonard Crestez <leonard.crestez@nxp.com>
To: "Srinivas Kandagatla" <srinivas.kandagatla@linaro.org>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Zhang Rui" <rui.zhang@intel.com>,
	"Eduardo Valentin" <edubezval@gmail.com>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Lothar Waßmann" <LW@KARO-electronics.de>
Cc: Dong Aisheng <aisheng.dong@nxp.com>, Bai Ping <ping.bai@nxp.com>,
	Anson Huang <Anson.Huang@nxp.com>,
	Octavian Purdila <octavian.purdila@nxp.com>,
	Fabio Estevam <fabio.estevam@nxp.com>, <linux-pm@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 2/5] nvmem: core: Add nvmem_cell_read_u32
Date: Fri, 14 Jul 2017 17:11:07 +0300	[thread overview]
Message-ID: <eedf98ecb5d9d47f3c8b9ffbf58e03c7a2fb8db4.1500041281.git.leonard.crestez@nxp.com> (raw)
In-Reply-To: <cover.1500041281.git.leonard.crestez@nxp.com>

This function does a quick and easy read of an u32 value without any
kind of resource management code on the consumer side.

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
---
 drivers/nvmem/core.c           | 37 +++++++++++++++++++++++++++++++++++++
 include/linux/nvmem-consumer.h |  8 ++++++++
 2 files changed, 45 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 4c49285..cf2d645 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1111,6 +1111,43 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
 EXPORT_SYMBOL_GPL(nvmem_cell_write);
 
 /**
+ * nvmem_cell_read_u32() - Read a cell value as an u32
+ *
+ * @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_u32(struct device* dev, const char *cell_id, u32 *val)
+{
+	struct nvmem_cell *cell;
+	void *buf;
+	size_t len;
+
+	cell = nvmem_cell_get(dev, cell_id);
+	if (IS_ERR(cell))
+		return PTR_ERR(cell);
+
+	buf = nvmem_cell_read(cell, &len);
+	if (IS_ERR(buf)) {
+		nvmem_cell_put(cell);
+		return PTR_ERR(buf);
+	}
+	if (len != sizeof(*val)) {
+		kfree(buf);
+		nvmem_cell_put(cell);
+		return -EINVAL;
+	}
+	memcpy(val, buf, sizeof(*val));
+
+	kfree(buf);
+	nvmem_cell_put(cell);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nvmem_cell_read_u32);
+
+/**
  * nvmem_device_cell_read() - Read a given nvmem device and cell
  *
  * @nvmem: nvmem device to read from.
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index c2256d7..a402522 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -36,6 +36,8 @@ 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_read_u32(struct device* dev, const char *cell_id, u32 *val);
+
 /* direct nvmem device read/write interface */
 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
 struct nvmem_device *devm_nvmem_device_get(struct device *dev,
@@ -85,6 +87,12 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell,
 	return -ENOSYS;
 }
 
+static inline int nvmem_cell_read_u32(struct device* dev,
+				      const char *cell_id, u32 *val)
+{
+	return -ENOSYS;
+}
+
 static inline struct nvmem_device *nvmem_device_get(struct device *dev,
 						    const char *name)
 {
-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: Leonard Crestez <leonard.crestez@nxp.com>
To: "Srinivas Kandagatla" <srinivas.kandagatla@linaro.org>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Zhang Rui" <rui.zhang@intel.com>,
	"Eduardo Valentin" <edubezval@gmail.com>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Lothar Waßmann" <LW@KARO-electronics.de>
Cc: Dong Aisheng <aisheng.dong@nxp.com>, Bai Ping <ping.bai@nxp.com>,
	Anson Huang <Anson.Huang@nxp.com>,
	Octavian Purdila <octavian.purdila@nxp.com>,
	Fabio Estevam <fabio.estevam@nxp.com>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/5] nvmem: core: Add nvmem_cell_read_u32
Date: Fri, 14 Jul 2017 17:11:07 +0300	[thread overview]
Message-ID: <eedf98ecb5d9d47f3c8b9ffbf58e03c7a2fb8db4.1500041281.git.leonard.crestez@nxp.com> (raw)
In-Reply-To: <cover.1500041281.git.leonard.crestez@nxp.com>

This function does a quick and easy read of an u32 value without any
kind of resource management code on the consumer side.

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
---
 drivers/nvmem/core.c           | 37 +++++++++++++++++++++++++++++++++++++
 include/linux/nvmem-consumer.h |  8 ++++++++
 2 files changed, 45 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 4c49285..cf2d645 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1111,6 +1111,43 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
 EXPORT_SYMBOL_GPL(nvmem_cell_write);
 
 /**
+ * nvmem_cell_read_u32() - Read a cell value as an u32
+ *
+ * @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_u32(struct device* dev, const char *cell_id, u32 *val)
+{
+	struct nvmem_cell *cell;
+	void *buf;
+	size_t len;
+
+	cell = nvmem_cell_get(dev, cell_id);
+	if (IS_ERR(cell))
+		return PTR_ERR(cell);
+
+	buf = nvmem_cell_read(cell, &len);
+	if (IS_ERR(buf)) {
+		nvmem_cell_put(cell);
+		return PTR_ERR(buf);
+	}
+	if (len != sizeof(*val)) {
+		kfree(buf);
+		nvmem_cell_put(cell);
+		return -EINVAL;
+	}
+	memcpy(val, buf, sizeof(*val));
+
+	kfree(buf);
+	nvmem_cell_put(cell);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nvmem_cell_read_u32);
+
+/**
  * nvmem_device_cell_read() - Read a given nvmem device and cell
  *
  * @nvmem: nvmem device to read from.
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index c2256d7..a402522 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -36,6 +36,8 @@ 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_read_u32(struct device* dev, const char *cell_id, u32 *val);
+
 /* direct nvmem device read/write interface */
 struct nvmem_device *nvmem_device_get(struct device *dev, const char *name);
 struct nvmem_device *devm_nvmem_device_get(struct device *dev,
@@ -85,6 +87,12 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell,
 	return -ENOSYS;
 }
 
+static inline int nvmem_cell_read_u32(struct device* dev,
+				      const char *cell_id, u32 *val)
+{
+	return -ENOSYS;
+}
+
 static inline struct nvmem_device *nvmem_device_get(struct device *dev,
 						    const char *name)
 {
-- 
2.7.4

  parent reply	other threads:[~2017-07-14 14:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-14 14:11 [PATCH v2 0/5] thermal: imx: Add nvmem-cells binding on imx6sx Leonard Crestez
2017-07-14 14:11 ` Leonard Crestez
2017-07-14 14:11 ` [PATCH v2 1/5] thermal: imx: Add nvmem-cells alternate binding for OCOTP access Leonard Crestez
2017-07-14 14:11   ` Leonard Crestez
2017-07-17 18:57   ` Rob Herring
2017-07-14 14:11 ` Leonard Crestez [this message]
2017-07-14 14:11   ` [PATCH v2 2/5] nvmem: core: Add nvmem_cell_read_u32 Leonard Crestez
2017-07-25  8:07   ` Shawn Guo
2017-08-25  9:07   ` Srinivas Kandagatla
2017-08-25  9:07     ` Srinivas Kandagatla
2017-08-28 10:51     ` Leonard Crestez
2017-07-14 14:11 ` [PATCH v2 3/5] thermal: imx: Add support for reading OCOTP through nvmem Leonard Crestez
2017-07-14 14:11   ` Leonard Crestez
2017-07-25  8:08   ` Shawn Guo
2017-08-08  7:21     ` Zhang Rui
2017-08-08 11:00       ` Srinivas Kandagatla
2017-08-08 11:00         ` Srinivas Kandagatla
2017-08-08 11:38         ` Leonard Crestez
2017-08-08 11:44           ` Srinivas Kandagatla
2017-08-08 12:58             ` Zhang Rui
2017-08-16 15:33               ` Leonard Crestez
2017-08-16 15:33                 ` Leonard Crestez
2017-08-25  2:20                 ` Zhang Rui
2017-08-25  2:20                   ` Zhang Rui
2017-07-14 14:11 ` [PATCH v2 4/5] ARM: dts: imx6sx: Use nvmem-cells for tempmon Leonard Crestez
2017-07-14 14:11   ` Leonard Crestez
2017-07-25  8:11   ` Shawn Guo
2017-10-18  2:29   ` Shawn Guo
2017-10-18  2:29     ` Shawn Guo
2017-07-14 14:11 ` [PATCH v2 5/5] ARM: dts: imx6ul: Add imx6ul-tempmon Leonard Crestez
2017-07-14 14:11   ` Leonard Crestez
2017-07-17 14:00 ` [PATCH v2 0/5] thermal: imx: Add nvmem-cells binding on imx6sx Lothar Waßmann
2017-07-17 14:00   ` Lothar Waßmann
2017-08-31  8:48 ` Shawn Guo
2017-08-31 13:11   ` Zhang Rui
2017-08-31 13:11     ` Zhang Rui
2017-09-20  1:40     ` Zhang Rui
2017-09-20  1:40       ` Zhang Rui

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=eedf98ecb5d9d47f3c8b9ffbf58e03c7a2fb8db4.1500041281.git.leonard.crestez@nxp.com \
    --to=leonard.crestez@nxp.com \
    --cc=Anson.Huang@nxp.com \
    --cc=LW@KARO-electronics.de \
    --cc=aisheng.dong@nxp.com \
    --cc=devicetree@vger.kernel.org \
    --cc=edubezval@gmail.com \
    --cc=fabio.estevam@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=octavian.purdila@nxp.com \
    --cc=ping.bai@nxp.com \
    --cc=robh+dt@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=shawnguo@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.