[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1482490784-4821-2-git-send-email-vivek.gautam@codeaurora.org>
Date: Fri, 23 Dec 2016 16:29:43 +0530
From: Vivek Gautam <vivek.gautam@...eaurora.org>
To: srinivas.kandagatla@...aro.org, maxime.ripard@...e-electrons.com
Cc: robh@...nel.org, sboyd@...eaurora.org,
linux-kernel@...r.kernel.org, linux-arm-msm@...r.kernel.org,
Vivek Gautam <vivek.gautam@...eaurora.org>
Subject: [PATCH 1/2] nvmem: core: Allow getting cell by index in phandle
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@...eaurora.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
Powered by blists - more mailing lists