From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752427AbcCAQ7l (ORCPT ); Tue, 1 Mar 2016 11:59:41 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:32908 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752215AbcCAQ7j (ORCPT ); Tue, 1 Mar 2016 11:59:39 -0500 From: Andrey Smirnov To: linux-kernel@vger.kernel.org Cc: srinivas.kandagatla@linaro.org, maxime.ripard@free-electrons.com, Andrey Smirnov Subject: [RESEND RFC 1/3] nvmem: Add 'of_nvmem_cell_from_device_node()' Date: Tue, 1 Mar 2016 08:59:10 -0800 Message-Id: <1456851552-15913-2-git-send-email-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456851552-15913-1-git-send-email-andrew.smirnov@gmail.com> References: <1456851552-15913-1-git-send-email-andrew.smirnov@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add 'of_nvmem_cell_from_device_node()' -- a function that allows to obtain 'struct nvmem_cell' from a device tree node representing it. One use-case for such a function would be to access nvmem cells with known phandles. Signed-off-by: Andrey Smirnov --- drivers/nvmem/core.c | 44 +++++++++++++++++++++++++++++------------- include/linux/nvmem-consumer.h | 7 +++++++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 6fd4e5a..08550dd 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -601,29 +601,21 @@ 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_from_device_node() - Get a nvmem cell from device node representation * - * @dev node: Device tree node that uses the nvmem cell - * @id: nvmem cell name from nvmem-cell-names property. + * @np node: Device tree node representing 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_from_device_node(struct device_node *cell_np) { - struct device_node *cell_np, *nvmem_np; + struct device_node *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); - - cell_np = of_parse_phandle(np, "nvmem-cells", index); - if (!cell_np) - return ERR_PTR(-EINVAL); + int rval, len; nvmem_np = of_get_next_parent(cell_np); if (!nvmem_np) @@ -682,6 +674,32 @@ err_mem: return ERR_PTR(rval); } +EXPORT_SYMBOL_GPL(of_nvmem_cell_from_device_node); + +/** + * of_nvmem_cell_get() - Get a nvmem cell from given device node referencing it 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 *name) +{ + struct device_node *cell_np; + int index; + + index = of_property_match_string(np, "nvmem-cell-names", name); + + cell_np = of_parse_phandle(np, "nvmem-cells", index); + if (!cell_np) + return ERR_PTR(-EINVAL); + + return of_nvmem_cell_from_device_node(cell_np); +} EXPORT_SYMBOL_GPL(of_nvmem_cell_get); #endif diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 9bb77d3..ff0abb0 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -136,11 +136,18 @@ static inline int nvmem_device_write(struct nvmem_device *nvmem, #endif /* CONFIG_NVMEM */ #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) +struct nvmem_cell *of_nvmem_cell_from_device_node(struct device_node *np); struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *name); struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *name); #else + +static inline struct nvmem_cell * +of_nvmem_cell_from_device_node(struct device_node *np) +{ + return ERR_PTR(-ENOSYS); +} static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *name) { -- 2.5.0