From patchwork Mon Oct 23 01:32:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 10021923 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 ABCE760381 for ; Mon, 23 Oct 2017 01:35:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DBFB286A8 for ; Mon, 23 Oct 2017 01:35:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92AA6286DC; Mon, 23 Oct 2017 01:35:17 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 3B246286A8 for ; Mon, 23 Oct 2017 01:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932178AbdJWBfO (ORCPT ); Sun, 22 Oct 2017 21:35:14 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:62163 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932177AbdJWBfB (ORCPT ); Sun, 22 Oct 2017 21:35:01 -0400 Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20171023013500epoutp02725f5280f7815641fc6bf50d2bfb87cc~wDx7UudHJ1357213572epoutp025; Mon, 23 Oct 2017 01:35:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20171023013500epoutp02725f5280f7815641fc6bf50d2bfb87cc~wDx7UudHJ1357213572epoutp025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1508722500; bh=NAcdrZhwHtqzqAtDEEfSljWTzaAzJuFAoEmWkJnVA/k=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=Bn6b8CdfWj98IfAE764tMBV3v7QXT/DAgj31WyvbZ65bBLHs02wEW3z6c0DfPH+si 41pLLY/aOlqKf4DodkN7PdtrMK9FxPCRymFkub8ieESMn8tcwhf0IrQkJ3ul3azwrt aZLVB43RUmRLH+/DE+Z1NqXQIa7uIrUdCR7+dpKU= Received: from epsmges1p2.samsung.com (unknown [182.195.40.66]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20171023013459epcas1p3e677adb0a1ba8e1704574f8dcb7d9936~wDx6y7je_3230532305epcas1p3P; Mon, 23 Oct 2017 01:34:59 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 4C.88.04153.E964DE95; Mon, 23 Oct 2017 10:32:14 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20171023013214epcas1p4f0652eceade1e3812ed7781d60b18367~wDvgnOGcG2896328963epcas1p43; Mon, 23 Oct 2017 01:32:14 +0000 (GMT) X-AuditID: b6c32a36-33dff70000001039-01-59ed469efbcd Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 36.07.04095.E964DE95; Mon, 23 Oct 2017 10:32:14 +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 <0OY90045G5LPR020@mmp2.samsung.com>; Mon, 23 Oct 2017 10:32:13 +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 v5 1/7] PM / devfreq: Set min/max_freq when adding the devfreq device Date: Mon, 23 Oct 2017 10:32:06 +0900 Message-id: <1508722332-10628-2-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1508722332-10628-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJKsWRmVeSWpSXmKPExsWy7bCmnu48t7eRBie7tC0m3rjCYnH9y3NW i0n3J7BYnG16w25xedccNovPvUcYLW43rmCzeLziLbsDh8fiPS+ZPDat6mTz6NuyitHj8ya5 AJaoVJuM1MSU1CKF1Lzk/JTMvHRbJe/geOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wcoDOU FMoSc0qBQgGJxcVK+nY2RfmlJakKGfnFJbZK0YaGRnqGBuZ6RkZGeibGsVZGpkAlCakZnx7O ZC84K1Bx6e1FxgbG57xdjJwcEgImEvP2r2PpYuTiEBLYwShx5HgDO4TznVHizKVTTDBVi1u7 2CASGxglVq9sYYVwfjBKHDq2kR2kik1AS2L/ixtsILaIQIBE59pVTCBFzAJNjBL7790AKxIW CJc4NfkUYxcjBweLgKrE+jYpkDCvgKvE9I8PoLbJSXzY8wisnFPATeLu2q+MIHMkBCawSfTs WM4K0ish4CIxvU8Lol5Y4tXxLewQYWmJS0dtIcrbGSU2z7nHAuF0MErcX9nICtFgLHGqqxFs GbMAn8S7rz1QM3klOtqEIEo8JCa0v2SBsB0lFr4+zwTx8Eygh/vesk9glFrAyLCKUSy1oDg3 PbXYsMBIrzgxt7g0L10vOT93EyM4mWiZ7WBcdM7nEKMAB6MSDy+D4dtIIdbEsuLK3EOMEhzM SiK8cyyAQrwpiZVVqUX58UWlOanFhxhNgUEzkVlKNDkfmOjySuINTSwNTMyMgInB0tBQSZxX dP21CCGB9MSS1OzU1ILUIpg+Jg5OqQbGhGSr+dc2qp73L/FkvtXxqLjaK8Ra5P52hYbU3b+i zDQz1Gz4/hc0+5++Fdoxd/q6qe/e77kU95thn9WkTV3ZLySdPh/2uK2TVHz+/KPHT0Tab4kZ NRY3qB8X6Bc+ZNASYaAQzsN7PoP9Q96MZ0d1i7aqJVuZeLP1St1e7/7Ee+fszf3+sXVKLMUZ iYZazEXFiQBChD/SPAMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphluLIzCtJLcpLzFFi42I5/e+xoO48t7eRBrdnsVtMvHGFxeL6l+es FpPuT2CxONv0ht3i8q45bBafe48wWtxuXMFm8XjFW3YHDo/Fe14yeWxa1cnm0bdlFaPH501y ASxRXDYpqTmZZalF+nYJXBmfHs5kLzgrUHHp7UXGBsbnvF2MnBwSAiYSi1u72LoYuTiEBNYx SsyceY0ZwvnBKPH3xBomkCo2AS2J/S9usIHYIgJ+Etvnr2cEKWIWaGKUWN5/CywhLBAucWzr XiCbg4NFQFVifZsUSJhXwFVi+scHTBDb5CQ+7HnEDmJzCrhJ3F37lRHEFgKq+fvpP9MERp4F jAyrGCVTC4pz03OLjQoM81LL9YoTc4tL89L1kvNzNzECw2jbYa2+HYz3l8QfYhTgYFTi4WUw fBspxJpYVlyZe4hRgoNZSYR3jgVQiDclsbIqtSg/vqg0J7X4EKM0B4uSOO/tvGORQgLpiSWp 2ampBalFMFkmDk6pBkaWj72nH9cZTXxxTqFciPfTD9kDL6wm5J9LurH62bn4jpyJAT5Xf27+ u4d/zY7vOuLcbW8b41x2OvlXhwuvLHTq/8nLcWH5c86/K3tENJclznmd+/Ca4S2BQ/4T3q0V WpE367nlosa1ivuaN5/vat68WHDdxNgN4isi8+KOLpnTv5GZtVMlfuZ1JZbijERDLeai4kQA 40ElAx8CAAA= X-CMS-MailID: 20171023013214epcas1p4f0652eceade1e3812ed7781d60b18367 X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20171023013214epcas1p4f0652eceade1e3812ed7781d60b18367 X-RootMTR: 20171023013214epcas1p4f0652eceade1e3812ed7781d60b18367 References: <1508722332-10628-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 Acked-by: MyungJoo Ham --- 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);