From patchwork Fri Aug 23 14:36:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Crestez X-Patchwork-Id: 11111855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD31313A4 for ; Fri, 23 Aug 2019 14:37:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB8912054F for ; Fri, 23 Aug 2019 14:37:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sBJ7OfrO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB8912054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=RaxeliEWskiaQON+3bEegNqyOiP4CHFaKJwClTzGqYE=; b=sBJ7OfrOwIBHkqwdvJ3Ub5Sfue rvzftAf0C4S7E9vqRNCsaP8J2iRRGVmUa7eqmfsUIeA9tMi3j9P1RVwylCXnZsOzlOZz5P7c4NLyD TR0ONJvSNCYOGYUX0cLcjK1SHH9Xlnhjy43v+WrqRuXNEcwAM+SM8fxtmRfnhOgWiBk+2IpsHnVkl Su9cyby4YLjDc02R2OZARgeRCzKJYiINE5+F81JIGnGkMEtJyWyQxeHgRtbDzOgLKR0YZXVCo2D7A BZxML2bvpYlHLQa82WCyvDgx/RxhSJU2KCLehnOoDNeLlJnk+bdl0wQVugi9BQCnCd2+CP+dBXYkA ZgVg9Jyw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i1Agf-0001sm-F1; Fri, 23 Aug 2019 14:37:09 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i1Agb-0001qt-NU for linux-arm-kernel@lists.infradead.org; Fri, 23 Aug 2019 14:37:07 +0000 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 0CD751A06D9; Fri, 23 Aug 2019 16:37:04 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id E986B1A06D1; Fri, 23 Aug 2019 16:37:03 +0200 (CEST) Received: from fsr-ub1864-112.ea.freescale.net (fsr-ub1864-112.ea.freescale.net [10.171.82.98]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id D8C45205D9; Fri, 23 Aug 2019 16:37:02 +0200 (CEST) From: Leonard Crestez To: Georgi Djakov , Rob Herring , =?utf-8?b?QXJ0dXIgxZp3aWdvxYQ=?= , Chanwoo Choi Subject: [RFCv4 1/7] PM / devfreq: Add devfreq_get_devfreq_by_node Date: Fri, 23 Aug 2019 17:36:54 +0300 Message-Id: <71a13730eee8744d8468aee8fa355958706035dd.1566570260.git.leonard.crestez@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190823_073706_040999_41B25C63 X-CRM114-Status: GOOD ( 11.83 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [92.121.34.13 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Dong Aisheng , linux-arm-kernel@lists.infradead.org, Saravana Kannan , linux-pm@vger.kernel.org, Stephen Boyd , Viresh Kumar , Michael Turquette , Krzysztof Kozlowski , Kyungmin Park , MyungJoo Ham , Alexandre Bailon , kernel@pengutronix.de, Fabio Estevam , Shawn Guo , devicetree@vger.kernel.org, linux-imx@nxp.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Split off part of devfreq_get_devfreq_by_phandle into a separate function. This allows callers to fetch devfreq instances by enumerating devicetree instead of explicit phandles. Signed-off-by: Leonard Crestez --- drivers/devfreq/devfreq.c | 42 +++++++++++++++++++++++++++++---------- include/linux/devfreq.h | 1 + 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 687deadd08ed..57352a757d79 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -907,10 +907,33 @@ struct devfreq *devm_devfreq_add_device(struct device *dev, return devfreq; } EXPORT_SYMBOL(devm_devfreq_add_device); #ifdef CONFIG_OF +/* + * devfreq_get_devfreq_by_node - Get the devfreq device from devicetree + * @np - pointer to device_node + * + * return the instance of devfreq device + */ +struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node) +{ + struct devfreq *devfreq; + + mutex_lock(&devfreq_list_lock); + list_for_each_entry(devfreq, &devfreq_list, node) { + if (devfreq->dev.parent + && devfreq->dev.parent->of_node == node) { + mutex_unlock(&devfreq_list_lock); + return devfreq; + } + } + mutex_unlock(&devfreq_list_lock); + + return ERR_PTR(-EPROBE_DEFER); +} + /* * devfreq_get_devfreq_by_phandle - Get the devfreq device from devicetree * @dev - instance to the given device * @index - index into list of devfreq * @@ -929,25 +952,22 @@ struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index) node = of_parse_phandle(dev->of_node, "devfreq", index); if (!node) return ERR_PTR(-ENODEV); - mutex_lock(&devfreq_list_lock); - list_for_each_entry(devfreq, &devfreq_list, node) { - if (devfreq->dev.parent - && devfreq->dev.parent->of_node == node) { - mutex_unlock(&devfreq_list_lock); - of_node_put(node); - return devfreq; - } - } - mutex_unlock(&devfreq_list_lock); + devfreq = devfreq_get_devfreq_by_node(node); of_node_put(node); - return ERR_PTR(-EPROBE_DEFER); + return devfreq; } + #else +struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node) +{ + return ERR_PTR(-ENODEV); +} + struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index) { return ERR_PTR(-ENODEV); } #endif /* CONFIG_OF */ diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index d2c5bb7add0a..4b5cc80abbe3 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -242,10 +242,11 @@ extern int devm_devfreq_register_notifier(struct device *dev, unsigned int list); extern void devm_devfreq_unregister_notifier(struct device *dev, struct devfreq *devfreq, struct notifier_block *nb, unsigned int list); +extern struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node); extern struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index); #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND) /**