From patchwork Fri Dec 23 10:59:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 9487355 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF2B4601C0 for ; Fri, 23 Dec 2016 11:00:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B193027AB2 for ; Fri, 23 Dec 2016 11:00:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A645027C05; Fri, 23 Dec 2016 11:00:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5090627AB2 for ; Fri, 23 Dec 2016 11:00:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764407AbcLWLAC (ORCPT ); Fri, 23 Dec 2016 06:00:02 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:41464 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030315AbcLWLAA (ORCPT ); Fri, 23 Dec 2016 06:00:00 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id AF87E61695; Fri, 23 Dec 2016 10:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1482490799; bh=FiU0+F6p7JOyaNo2rDlh56C6fg1mtVSCOK8eIJeo3As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JmvjZJ3jpLpjoOS/wDeuvUApgUn82fBiru48Zoo6QBX8Wc19fH1KEiY4kE95js1+H tu6W8P41Qr+QqI7fol54F/CTWt2jHU2rRkpiCHmdKJ7HmuwoFgg92Gwm0AViYRnNWq Ik9/9fkll26VlBYfTRi36Yu0NSAnfRQPZ6yAmTFo= Received: from blr-ubuntu-41.ap.qualcomm.com (unknown [202.46.23.61]) (using TLSv1.1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1C7C961695; Fri, 23 Dec 2016 10:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1482490798; bh=FiU0+F6p7JOyaNo2rDlh56C6fg1mtVSCOK8eIJeo3As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DeiBsCuHVyQCsZrwelk30OnGAbxqaflsFh+tBD40o1J17+W7KO1uo29aXgAHzz1Sd 8s/eo41K/aMi6IQEqFhX2QwYU5vxP+rF056GWg4EEiI6PaBG12nIngc03NWfQJ0QDc dFyoFXDTVtCxV4PGqRHEInOHCmxvlszLJBooA5/4= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 1C7C961695 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 1/2] nvmem: core: Allow getting cell by index in phandle Date: Fri, 23 Dec 2016 16:29:43 +0530 Message-Id: <1482490784-4821-2-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-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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); }