Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751858AbdHXBoq (ORCPT ); Wed, 23 Aug 2017 21:44:46 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:20009 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751142AbdHXBnC (ORCPT ); Wed, 23 Aug 2017 21:43:02 -0400 X-AuditID: b6c32a47-f79db6d000003732-bf-599e2f24d0fb 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 05/12] PM / devfreq: Set min/max_freq when adding the devfreq device Date: Thu, 24 Aug 2017 10:42:52 +0900 Message-id: <1503538979-22693-6-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1503538979-22693-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGKsWRmVeSWpSXmKPExsWy7bCmma6K/rxIg72XuC0m3rjCYnH9y3NW i0n3J7BYnG16w25xedccNovPvUcYLW43rmCzeLziLbsDh8fiPS+ZPDat6mTz6NuyitHj8ya5 AJaoVJuM1MSU1CKF1Lzk/JTMvHRbJe/geOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wcoDOU FMoSc0qBQgGJxcVK+nY2RfmlJakKGfnFJbZK0YaGRnqGBuZ6RkZGeibGsVZGpkAlCakZb4+9 ZSt4JFBxZtNy1gbGBr4uRg4OCQETiUnXA7oYOYFMMYkL99azdTFycQgJ7GCUOPX2DCuE851R YvHUJ+wQVSYSp6c9ZwaxhQQ2MEps3BYOUfSDUeLEhE2MIAk2AS2J/S9usIHYIgIBEp1rVzGB FDELNDFK7L93A2ySsECYxPsvL8EaWARUJe7fXwMW5xVwlVixdQsTxDY5iQ97HoHFOQXcJFqe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Jykf9RpUegyDcvtXxKn1VzqXLxS9IIVV6P2wSxZwwCjY4XpLBnHi3x+ qa6VrfP+dUfkl0xhTja7auyDKf83L3Q8fjLmjUJ9AOvs26e+t3oWdUTMTrLgrtAOUlR6G+Sj J3Tn1PrTUy+GZdbuc03b/cg9JONw7BGnuS9PlDH8Ohbh/2ll/zZncyWW4oxEQy3mouJEALtY jXkgAgAA X-CMS-MailID: 20170824014259epcas2p161d781837dffe0724c0fd73fc477281a 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: 20170824014259epcas2p161d781837dffe0724c0fd73fc477281a X-RootMTR: 20170824014259epcas2p161d781837dffe0724c0fd73fc477281a References: <1503538979-22693-1-git-send-email-cw00.choi@samsung.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2070 Lines: 74 Previously, the min/max_freq of devfreq device are always zero before the user changes the min/max_freq through sysfs entry. It might make the confusion of min/max_freq. This patch initializes the available min/max_freq by using the OPP API. 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 3c5ccb96e165..56f8a0473834 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; + + 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; + + dev_pm_opp_put(opp); + + return max_freq; +} + /** * devfreq_get_freq_level() - Lookup freq_table for the frequency * @devfreq: the devfreq instance @@ -556,6 +584,21 @@ struct devfreq *devfreq_add_device(struct device *dev, if (!devfreq->profile->max_state && !devfreq->profile->freq_table) devfreq_set_freq_table(devfreq); + /* 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); -- 1.9.1