linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] nvmem: core: Support to get nvmem cell using index
@ 2016-12-23 10:59 Vivek Gautam
  2016-12-23 10:59 ` [PATCH 1/2] nvmem: core: Allow getting cell by index in phandle Vivek Gautam
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vivek Gautam @ 2016-12-23 10:59 UTC (permalink / raw)
  To: srinivas.kandagatla, maxime.ripard
  Cc: robh, sboyd, linux-kernel, linux-arm-msm, Vivek Gautam

Couple of patches to support getting nvmem cell using cell index.
Usually when we have only one nvmem cell for a device, we may not
want to add a nvmem-cell-names property to the device node.
With these patches, we can now get a cell using phandle and the cell
index.

 - Based on torvald's master branch.
 - Tested with next-20161223 tag and a revert to patch [1], to fix
   build issue on arm64, on db410c target. Able to read temperatures
   from thermal sensors.

Vivek Gautam (2):
  nvmem: core: Allow getting cell by index in phandle
  nvmem: core: Add a resource managed API to get cell by index

 drivers/nvmem/core.c           | 68 +++++++++++++++++++++++++++++++++++++-----
 include/linux/nvmem-consumer.h | 19 +++++++++++-
 2 files changed, 79 insertions(+), 8 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] nvmem: core: Allow getting cell by index in phandle
  2016-12-23 10:59 [PATCH 0/2] nvmem: core: Support to get nvmem cell using index Vivek Gautam
@ 2016-12-23 10:59 ` Vivek Gautam
  2016-12-23 10:59 ` [PATCH 2/2] nvmem: core: Add a resource managed API to get cell by index Vivek Gautam
  2016-12-23 11:06 ` [PATCH RESEND 0/2] nvmem: core: Support to get nvmem cell using index Vivek Gautam
  2 siblings, 0 replies; 4+ messages in thread
From: Vivek Gautam @ 2016-12-23 10:59 UTC (permalink / raw)
  To: srinivas.kandagatla, maxime.ripard
  Cc: robh, sboyd, linux-kernel, linux-arm-msm, Vivek Gautam

Fork out a method to get nvmem cell using cell index
in the phandle for the cell.
This helps in getting the lone cell given in the phandle,
without mentioning the cell name in device tree.

Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
---
 drivers/nvmem/core.c           | 35 ++++++++++++++++++++++++++++-------
 include/linux/nvmem-consumer.h | 11 ++++++++++-
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 4c3884266afe..f46b8f667571 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -743,25 +743,24 @@ static struct nvmem_cell *nvmem_cell_get_from_list(const char *cell_id)
 
 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
 /**
- * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id
+ * of_nvmem_cell_get_by_index() - Get a nvmem cell from given device node and
+				  cell index
  *
  * @dev node: Device tree node that uses the nvmem cell
- * @id: nvmem cell name from nvmem-cell-names property.
+ * @index: index of nvmem cell
  *
  * Return: Will be an ERR_PTR() on error or a valid pointer
  * to a struct nvmem_cell.  The nvmem_cell will be freed by the
  * nvmem_cell_put().
  */
-struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
-					    const char *name)
+struct nvmem_cell *of_nvmem_cell_get_by_index(struct device_node *np,
+							int index)
 {
 	struct device_node *cell_np, *nvmem_np;
 	struct nvmem_cell *cell;
 	struct nvmem_device *nvmem;
 	const __be32 *addr;
-	int rval, len, index;
-
-	index = of_property_match_string(np, "nvmem-cell-names", name);
+	int rval, len;
 
 	cell_np = of_parse_phandle(np, "nvmem-cells", index);
 	if (!cell_np)
@@ -824,6 +823,28 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
 
 	return ERR_PTR(rval);
 }
+EXPORT_SYMBOL_GPL(of_nvmem_cell_get_by_index);
+
+/**
+ * of_nvmem_cell_get() - Get a nvmem cell from given device node and
+ *				cell id.
+ *
+ * @dev node: Device tree node that uses the nvmem cell
+ * @id: nvmem cell name from nvmem-cell-names property
+ *
+ * Return: Will be an ERR_PTR() on error or a valid pointer
+ * to a struct nvmem_cell.  The nvmem_cell will be freed by the
+ * nvmem_cell_put().
+ */
+struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
+					    const char *id)
+{
+	int index;
+
+	index = of_property_match_string(np, "nvmem-cell-names", id);
+
+	return of_nvmem_cell_get_by_index(np, index);
+}
 EXPORT_SYMBOL_GPL(of_nvmem_cell_get);
 #endif
 
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index c2256d746543..0dd9ef837a32 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -138,11 +138,20 @@ static inline int nvmem_device_write(struct nvmem_device *nvmem,
 #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
 struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
 				     const char *name);
+struct nvmem_cell *of_nvmem_cell_get_by_index(struct device_node *np,
+					      int index);
 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
 					 const char *name);
 #else
+static inline
+struct nvmem_cell *of_nvmem_cell_get_by_index(struct device_node *np,
+					      int index)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
 static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
-				     const char *name)
+						   const char *name)
 {
 	return ERR_PTR(-ENOSYS);
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] nvmem: core: Add a resource managed API to get cell by index
  2016-12-23 10:59 [PATCH 0/2] nvmem: core: Support to get nvmem cell using index Vivek Gautam
  2016-12-23 10:59 ` [PATCH 1/2] nvmem: core: Allow getting cell by index in phandle Vivek Gautam
@ 2016-12-23 10:59 ` Vivek Gautam
  2016-12-23 11:06 ` [PATCH RESEND 0/2] nvmem: core: Support to get nvmem cell using index Vivek Gautam
  2 siblings, 0 replies; 4+ messages in thread
From: Vivek Gautam @ 2016-12-23 10:59 UTC (permalink / raw)
  To: srinivas.kandagatla, maxime.ripard
  Cc: robh, sboyd, linux-kernel, linux-arm-msm, Vivek Gautam

Adding a resource managed method to obtain nvmem cell
using cell index.

Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
---
 drivers/nvmem/core.c           | 33 +++++++++++++++++++++++++++++++++
 include/linux/nvmem-consumer.h |  8 ++++++++
 2 files changed, 41 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index f46b8f667571..3d0eca689931 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -907,6 +907,39 @@ struct nvmem_cell *devm_nvmem_cell_get(struct device *dev, const char *id)
 }
 EXPORT_SYMBOL_GPL(devm_nvmem_cell_get);
 
+#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
+/**
+ * devm_nvmem_cell_get_by_index() - Get nvmem cell of device from cell index;
+ *				    resource managed.
+ *
+ * @dev node: Device tree node that uses the nvmem cell
+ * @index: index of nvmem cell
+ *
+ * Return: Will be an ERR_PTR() on error or a valid pointer
+ * to a struct nvmem_cell.  The nvmem_cell will be freed by the
+ * automatically once the device is freed.
+ */
+struct nvmem_cell *devm_nvmem_cell_get_by_index(struct device *dev, int index)
+{
+	struct nvmem_cell **ptr, *cell;
+
+	ptr = devres_alloc(devm_nvmem_cell_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	cell = of_nvmem_cell_get_by_index(dev->of_node, index);
+	if (!IS_ERR(cell)) {
+		*ptr = cell;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return cell;
+}
+EXPORT_SYMBOL_GPL(devm_nvmem_cell_get_by_index);
+#endif
+
 static int devm_nvmem_cell_match(struct device *dev, void *res, void *data)
 {
 	struct nvmem_cell **c = res;
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 0dd9ef837a32..065647b5143e 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -142,6 +142,8 @@ struct nvmem_cell *of_nvmem_cell_get_by_index(struct device_node *np,
 					      int index);
 struct nvmem_device *of_nvmem_device_get(struct device_node *np,
 					 const char *name);
+struct nvmem_cell *devm_nvmem_cell_get_by_index(struct device *dev,
+						   int index);
 #else
 static inline
 struct nvmem_cell *of_nvmem_cell_get_by_index(struct device_node *np,
@@ -161,6 +163,12 @@ static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np,
 {
 	return ERR_PTR(-ENOSYS);
 }
+
+static inline
+struct nvmem_cell *devm_nvmem_cell_get_by_index(struct device *dev, int index)
+{
+	return ERR_PTR(-ENOSYS);
+}
 #endif /* CONFIG_NVMEM && CONFIG_OF */
 
 #endif  /* ifndef _LINUX_NVMEM_CONSUMER_H */
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH RESEND 0/2] nvmem: core: Support to get nvmem cell using index
  2016-12-23 10:59 [PATCH 0/2] nvmem: core: Support to get nvmem cell using index Vivek Gautam
  2016-12-23 10:59 ` [PATCH 1/2] nvmem: core: Allow getting cell by index in phandle Vivek Gautam
  2016-12-23 10:59 ` [PATCH 2/2] nvmem: core: Add a resource managed API to get cell by index Vivek Gautam
@ 2016-12-23 11:06 ` Vivek Gautam
  2 siblings, 0 replies; 4+ messages in thread
From: Vivek Gautam @ 2016-12-23 11:06 UTC (permalink / raw)
  To: srinivas.kandagatla, maxime.ripard
  Cc: robh, sboyd, linux-kernel, linux-arm-msm, Vivek Gautam

Couple of patches to support getting nvmem cell using cell index.
Usually when we have only one nvmem cell for a device, we may not
want to add a nvmem-cell-names property to the device node.
With these patches, we can now get a cell using phandle and the cell
index.

Updated the links to patch and thread in [1] and [2]. Missed them
earlier. The patches 1/2 and 2/2 remain unchanged.

 - Based on torvald's master branch.
 - Tested with next-20161223 tag and a revert to patch [1], to fix
   build issue on arm64 (as indicated in the thread [2]), on
   db410c target. Able to read temperatures from thermal sensors.

[1] 1a339a14b1f2 arm64: setup: introduce kaslr_offset()
[2] https://lkml.org/lkml/2016/12/22/217

Vivek Gautam (2):
  nvmem: core: Allow getting cell by index in phandle
  nvmem: core: Add a resource managed API to get cell by index

 drivers/nvmem/core.c           | 68 +++++++++++++++++++++++++++++++++++++-----
 include/linux/nvmem-consumer.h | 19 +++++++++++-
 2 files changed, 79 insertions(+), 8 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-12-23 11:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-23 10:59 [PATCH 0/2] nvmem: core: Support to get nvmem cell using index Vivek Gautam
2016-12-23 10:59 ` [PATCH 1/2] nvmem: core: Allow getting cell by index in phandle Vivek Gautam
2016-12-23 10:59 ` [PATCH 2/2] nvmem: core: Add a resource managed API to get cell by index Vivek Gautam
2016-12-23 11:06 ` [PATCH RESEND 0/2] nvmem: core: Support to get nvmem cell using index Vivek Gautam

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).