From patchwork Thu Jul 7 06:39:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanchayan X-Patchwork-Id: 9217859 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 736A660467 for ; Thu, 7 Jul 2016 06:48:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6636B2873C for ; Thu, 7 Jul 2016 06:48:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AD0628741; Thu, 7 Jul 2016 06:48:54 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E3D272873C for ; Thu, 7 Jul 2016 06:48:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bL362-0003Ah-PQ; Thu, 07 Jul 2016 06:47:38 +0000 Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bL35n-000308-Ec for linux-arm-kernel@lists.infradead.org; Thu, 07 Jul 2016 06:47:24 +0000 Received: by mail-pa0-x241.google.com with SMTP id ib6so980016pad.3 for ; Wed, 06 Jul 2016 23:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=BMYjfsHKUMz000ttO7JJarA8T80hFHqojSxo4jfQm8s=; b=qIAsE09IzKvhgsTSRg3OwOOGM83w2kwp8UED0JOp+CGtFxBF5px8Okr05Ov+iRZbHb Ao2uEdWYQR46CLmVz6bz4eKZyu06fHHVOHtJGuOK40nY5dHWbMs5CVyXF0rSfki1ZOD2 mQgqHvw/5BsWf0ZeqXq7MbPBvpH69rAd1VzSI43HGeHQ8J8zrWQL29qZAOY9CipH6PgR wcyJ4EnsvbSsCxuegnf1cYjSAedGcqGUrWFEsomD0SE2cFWtFDROUG22v3R9unRPQzuf 4ivdHTNS5ebxk8NHBgz7BTLLFQP+oOKNTMuokIbrxgptVRispj1Cuu1h076Bu9t5v9OO HIHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=BMYjfsHKUMz000ttO7JJarA8T80hFHqojSxo4jfQm8s=; b=M4+PE8exEbFUH3sDa8v/EDnB5kjPLQ9W2xTA1UjDASQrEQhlbZAAgQ4XpBpLkuA4EW OhkfWagKgFmA6Trwef4Lg9AadeWNo8YX0Mgs/vEWT11tkmQe7c/L7GAsqAgAVbUWIoSg lZKYB7diEueCoRfurMG6WWLvGvZOECry59591Z1/zitIHqrUXDvi2RVKbVSX9tZthZ0S L8pm5X5yIakBI6+5ubicErIR1QRAGKGLl+jTLI/krX4sHjRZZoXPd9Y2k7pcPkFuztFa HSltU6nEqap9Y4+XwQjsV5kh+t61oC3Qvxv7AmuSaXiBXnK/PCXxfP24SZ/zzT0xx0J8 mv1w== X-Gm-Message-State: ALyK8tLERY9AVo+oVY6GOT3fuOXBN8wyWYOMXiaMdmtOAdT/J5h4C8scOgajAuCNu75wUQ== X-Received: by 10.66.167.16 with SMTP id zk16mr33625228pab.146.1467874022244; Wed, 06 Jul 2016 23:47:02 -0700 (PDT) Received: from localhost ([115.115.243.34]) by smtp.gmail.com with ESMTPSA id s3sm1653825pfb.87.2016.07.06.23.47.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Jul 2016 23:47:01 -0700 (PDT) From: Sanchayan Maity To: arnd@arndb.de, shawnguo@kernel.org Subject: [PATCH v4 3/5] nvmem: core: Add consumer API to get nvmem cell from node Date: Thu, 7 Jul 2016 12:09:28 +0530 Message-Id: <0e6294d931bf181376a6f4e1a86df3f6c6a5d575.1467872014.git.maitysanchayan@gmail.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160706_234723_649925_2737F81E X-CRM114-Status: GOOD ( 13.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, stefan@agner.ch, Sanchayan Maity , robh+dt@kernel.org, srinivas.kandagatla@linaro.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Stefan Agner The existing NVMEM consumer API's do not allow to get a NVMEM cell directly given a device tree node. This patch adds a function to provide this functionality. Assuming the nvmem cell id name is known, this can be used as follows struct device_node *cell_np; struct nvmem_cell *foo_cell; cell_np = of_find_node_by_name(parent, "foo"); foo_cell = of_nvmem_cell_get_direct(cell_np); Parent node can also be the of_node of the main SoC device node. Signed-off-by: Sanchayan Maity --- drivers/nvmem/core.c | 44 +++++++++++++++++++++++++++++------------- include/linux/nvmem-consumer.h | 1 + 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 965911d..470abee 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -743,29 +743,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_get_direct() - Get a nvmem cell from given device node * - * @dev node: Device tree node that uses the nvmem cell - * @id: nvmem cell name from nvmem-cell-names property. + * @dev node: Device tree node that uses 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_direct(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) @@ -824,6 +816,32 @@ err_mem: return ERR_PTR(rval); } +EXPORT_SYMBOL_GPL(of_nvmem_cell_get_direct); + +/** + * 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 *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_get_direct(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..bf879fc 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -136,6 +136,7 @@ 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_get_direct(struct device_node *cell_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,