From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030400AbcLWLAH (ORCPT ); Fri, 23 Dec 2016 06:00:07 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:41540 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030315AbcLWLAE (ORCPT ); Fri, 23 Dec 2016 06:00:04 -0500 DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 9D0F0616A5 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: srinivas.kandagatla@linaro.org, maxime.ripard@free-electrons.com Cc: robh@kernel.org, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Vivek Gautam Subject: [PATCH 2/2] nvmem: core: Add a resource managed API to get cell by index Date: Fri, 23 Dec 2016 16:29:44 +0530 Message-Id: <1482490784-4821-3-git-send-email-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1482490784-4821-1-git-send-email-vivek.gautam@codeaurora.org> References: <1482490784-4821-1-git-send-email-vivek.gautam@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding a resource managed method to obtain nvmem cell using cell index. Signed-off-by: Vivek Gautam --- 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