From patchwork Fri Oct 13 07:48:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 10003635 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 026B460325 for ; Fri, 13 Oct 2017 07:50:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8817283DA for ; Fri, 13 Oct 2017 07:50:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD68D28FF1; Fri, 13 Oct 2017 07:50:24 +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=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 99AE328FD2 for ; Fri, 13 Oct 2017 07:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757739AbdJMHuN (ORCPT ); Fri, 13 Oct 2017 03:50:13 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:17552 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756736AbdJMHsf (ORCPT ); Fri, 13 Oct 2017 03:48:35 -0400 Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20171013074833epoutp01da93d7a54b9ccf099ba6550487e7f673~tEbOXAVH60735607356epoutp01y; Fri, 13 Oct 2017 07:48:33 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.40.65]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20171013074832epcas1p16ac338752765f6752e278ba1032136c3~tEbODa_lr0112201122epcas1p1d; Fri, 13 Oct 2017 07:48:32 +0000 (GMT) Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id 9B.77.04435.0DF60E95; Fri, 13 Oct 2017 16:48:32 +0900 (KST) Received: from epsmgms2p2new.samsung.com (unknown [182.195.42.143]) by epcas2p2.samsung.com (KnoxPortal) with ESMTP id 20171013074831epcas2p2d9120a18f746f2831057a1da1977394a~tEbNJ6ThE1010610106epcas2p2O; Fri, 13 Oct 2017 07:48:31 +0000 (GMT) X-AuditID: b6c32a46-acbff70000001153-38-59e06fd0b2dd Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p2new.samsung.com (Symantec Messaging Gateway) with SMTP id D4.CA.06856.FCF60E95; Fri, 13 Oct 2017 16:48:31 +0900 (KST) Received: from localhost.localdomain ([10.113.62.212]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OXR00LHA4CULS20@mmp2.samsung.com>; Fri, 13 Oct 2017 16:48:31 +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-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v4 1/8] PM / devfreq: Set min/max_freq when adding the devfreq device Date: Fri, 13 Oct 2017 16:48:17 +0900 Message-id: <1507880904-31956-2-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1507880904-31956-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNKsWRmVeSWpSXmKPExsWy7bCmue6F/AeRBr/Om1tMvHGFxeL6l+es FpPuT2CxONv0ht3i8q45bBafe48wWtxuXMFm8XjFW3YHDo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ZZalF+nYJXBlTX/WzFpwVqHi4bDl7A+Nz3i5GTg4JAROJM/M2sXUxcnEICaxj lHh75jU7hPODUWLBgSPMIFVsAloS+1/cYAOxRQT8JLbPX88IUsQs0MQosbz/FlhCWCBcYvbb eWANLAKqEtNub2QHsXkFXCXeTr/DDrFOTuLDnkdgNqeAm8Stq9cZQWwhoJq7Mx8xTmDkWcDI sIpRMrWgODc9t9iowCgvtVyvODG3uDQvXS85P3cTIzCQth3W6t/B+HhJ/CFGAQ5GJR7eHeX3 I4VYE8uKK3MPMUpwMCuJ8Kq6PogU4k1JrKxKLcqPLyrNSS0+xCjNwaIkzsuffyxSSCA9sSQ1 OzW1ILUIJsvEwSnVwNhq9bxTvfrQ54sfl9cqOQh86ZrhLSA5S8a6/M+8y9vXpwiq82b3/CuY HbFPNtQtw5FzwcUnV9YvOv7i2f6tidmBq4KXf+39ff1f/TTBDdGM2bpvZgixZS0Qv3LY+PuD 8MYbE1WWbWH/9Dvh2h7lHb902Vdz8t+x/7bz6yLztU4T7q1keZCfrs+lxFKckWioxVxUnAgA BMZGgCACAAA= X-CMS-MailID: 20171013074831epcas2p2d9120a18f746f2831057a1da1977394a X-Msg-Generator: CA X-Sender-IP: 182.195.42.143 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: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20171013074831epcas2p2d9120a18f746f2831057a1da1977394a X-RootMTR: 20171013074831epcas2p2d9120a18f746f2831057a1da1977394a References: <1507880904-31956-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. Acked-by: MyungJoo Ham Signed-off-by: Chanwoo Choi --- drivers/devfreq/devfreq.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index a1c4ee818614..6a6f88bccdee 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,20 @@ struct devfreq *devfreq_add_device(struct device *dev, mutex_lock(&devfreq->lock); } + 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);