From patchwork Thu Sep 21 00:33:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 9963061 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 1F3626056D for ; Thu, 21 Sep 2017 00:34:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11C3C2927E for ; Thu, 21 Sep 2017 00:34:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0493F2928B; Thu, 21 Sep 2017 00:34:48 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 EECD42927E for ; Thu, 21 Sep 2017 00:34:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751858AbdIUAeC (ORCPT ); Wed, 20 Sep 2017 20:34:02 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:49969 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751894AbdIUAd6 (ORCPT ); Wed, 20 Sep 2017 20:33:58 -0400 Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20170921003356epoutp03e70db1fdf848161918b36b6d30162160~mOTea7PwV2151421514epoutp030; Thu, 21 Sep 2017 00:33:56 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.40.66]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20170921003356epcas1p3f53fbdea669a74ad980441ae8ddf9bbf~mOTeJAPwz1037110371epcas1p3p; Thu, 21 Sep 2017 00:33:56 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 17.90.22848.3F803C95; Thu, 21 Sep 2017 09:33:56 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20170921003355epcas1p42e0547938d45c32c3064895140bf5848~mOTd0ByUB0339003390epcas1p4n; Thu, 21 Sep 2017 00:33:55 +0000 (GMT) X-AuditID: b6c32a35-f798c6d000005940-c6-59c308f381ac Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 17.02.11757.3F803C95; Thu, 21 Sep 2017 09:33:55 +0900 (KST) Received: from localhost.localdomain ([10.113.62.212]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OWL00BYOTKJX990@mmp1.samsung.com>; Thu, 21 Sep 2017 09:33:55 +0900 (KST) From: Chanwoo Choi To: myungjoo.ham@samsung.com, kyungmin.park@samsung.com, cw00.choi@samsung.com Cc: rafael.j.wysocki@intel.com, chanwoo@kernel.org, inki.dae@samsung.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/8] PM / devfreq: Set min/max_freq when adding the devfreq device Date: Thu, 21 Sep 2017 09:33:45 +0900 Message-id: <1505954032-3327-2-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1505954032-3327-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEKsWRmVeSWpSXmKPExsWy7bCmge4XjsORBkc+MllMvHGFxeL6l+es FpPuT2CxONv0ht3i8q45bBafe48wWtxuXMFm8XjFW3YHDo/Fe14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ZZalF+nYJXBkHl2YVXBGo+PV1PUsD4wveLkZODgkBE4mFO7aydzFycQgJ7GSU +HBhFhOE84NR4tbds+wgVWwCWhL7X9xgA7FFBPwkts9fzwhSxCzQxCix8dkBJpCEsEC4RP+z 02ANLAKqEg8XbgFr4BVwkWia2ssKsU5O4sOeR2A1nAKuEt/OdoHVCAHVnH3xmm0CI88CRoZV jJKpBcW56bnFRgWGeanlesWJucWleel6yfm5mxiBYbTtsFbfDsb7S+IPMQpwMCrx8AZYHYwU Yk0sK67MPcQowcGsJMIb8/BQpBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHezL4ZkUIC6Yklqdmp qQWpRTBZJg5OqQZGr119ngqCIUJr/no0n/gRURhyTSNxY8xKXekza/+eW8rxONf7q+dB2b+t eafudeznCpu1wStxjrX+Znb9nM8lujef/DwrI+u/IVN4a6CdvFr41hleFuEaKXM5sqbXhlvL GSzjzbA7eytx0e2N8wyWe+2XnOFh+jxI/0eXyWLViV7Bh4/OTNunxFKckWioxVxUnAgA7otM ZB8CAAA= X-CMS-MailID: 20170921003355epcas1p42e0547938d45c32c3064895140bf5848 X-Msg-Generator: CA X-Sender-IP: 182.195.42.142 X-Local-Sender: =?UTF-8?B?7LWc7LCs7JqwG1RpemVuIFBsYXRmb3JtIExhYihTL1fshLw=?= =?UTF-8?B?7YSwKRvsgrzshLHsoITsnpAbU2VuaW9yIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?Q2hhbndvbyBDaG9pG1RpemVuIFBsYXRmb3JtIExhYi4bU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtTZW5pb3IgRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG1RFTEUbQzEwVjgxMTE=?= CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20170921003355epcas1p42e0547938d45c32c3064895140bf5848 X-RootMTR: 20170921003355epcas1p42e0547938d45c32c3064895140bf5848 References: <1505954032-3327-1-git-send-email-cw00.choi@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Prior to that, the min/max_freq of the devfreq device are always zero before the user changes the min/max_freq through sysfs entries. It might make the confusion for the min/max_freq. This patch initializes the available min/max_freq by using the OPP during adding the devfreq device. Signed-off-by: Chanwoo Choi --- drivers/devfreq/devfreq.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index a1c4ee818614..ae8717a6eee1 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -69,6 +69,34 @@ static struct devfreq *find_device_devfreq(struct device *dev) return ERR_PTR(-ENODEV); } +static unsigned long find_available_min_freq(struct devfreq *devfreq) +{ + struct dev_pm_opp *opp; + unsigned long min_freq = 0; + + opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &min_freq); + if (IS_ERR(opp)) + min_freq = 0; + else + dev_pm_opp_put(opp); + + return min_freq; +} + +static unsigned long find_available_max_freq(struct devfreq *devfreq) +{ + struct dev_pm_opp *opp; + unsigned long max_freq = ULONG_MAX; + + opp = dev_pm_opp_find_freq_floor(devfreq->dev.parent, &max_freq); + if (IS_ERR(opp)) + max_freq = 0; + else + dev_pm_opp_put(opp); + + return max_freq; +} + /** * devfreq_get_freq_level() - Lookup freq_table for the frequency * @devfreq: the devfreq instance @@ -559,6 +587,21 @@ struct devfreq *devfreq_add_device(struct device *dev, mutex_lock(&devfreq->lock); } + /* Set the scaling available min_freq and max_freq */ + devfreq->min_freq = find_available_min_freq(devfreq); + if (!devfreq->min_freq) { + mutex_unlock(&devfreq->lock); + err = -EINVAL; + goto err_dev; + } + + devfreq->max_freq = find_available_max_freq(devfreq); + if (!devfreq->max_freq) { + mutex_unlock(&devfreq->lock); + err = -EINVAL; + goto err_dev; + } + dev_set_name(&devfreq->dev, "devfreq%d", atomic_inc_return(&devfreq_no)); err = device_register(&devfreq->dev);