From patchwork Mon Oct 23 01:32:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 10021927 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 3E8C560381 for ; Mon, 23 Oct 2017 01:35:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EB5C286D1 for ; Mon, 23 Oct 2017 01:35:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21F8F286DC; Mon, 23 Oct 2017 01:35:41 +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=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 74B5B286D1 for ; Mon, 23 Oct 2017 01:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932312AbdJWBfN (ORCPT ); Sun, 22 Oct 2017 21:35:13 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:24473 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932178AbdJWBfB (ORCPT ); Sun, 22 Oct 2017 21:35:01 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20171023013500epoutp03fab6cc3e5c6443a7df63fdc386deb59e~wDx7Tl5D-1558115581epoutp03N; Mon, 23 Oct 2017 01:35:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20171023013500epoutp03fab6cc3e5c6443a7df63fdc386deb59e~wDx7Tl5D-1558115581epoutp03N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1508722500; bh=P/C+Kejr/S51ueofE8RPd5+b15FUSKutMOAJuC3BCVU=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=aCGnEtpym19MA4L/5qPaQSBsIYWWNPgHjX0pQywVLroKdbDr8Aa/xBTIFDtpR0PIr o+71MuFowl51a37cu8Nk7+mEaPdQLg8zuI6SVflTpiX9PsXeIIMA5TGkd15FFuP+Ea sR0UapocdbWKJCSZT23D7kIL9D3A+JMTEh98arIY= Received: from epsmges1p2.samsung.com (unknown [182.195.40.65]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20171023013459epcas1p1aec04a5107910d9f164d3658ecf2e475~wDx60vg741232112321epcas1p1E; Mon, 23 Oct 2017 01:34:59 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 0D.88.04153.F964DE95; Mon, 23 Oct 2017 10:32:15 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20171023013214epcas1p353a430282734319c904ea2edaa737dce~wDvhO9Tya2808628086epcas1p3h; Mon, 23 Oct 2017 01:32:14 +0000 (GMT) X-AuditID: b6c32a36-325ff70000001039-04-59ed469f1e5f Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 87.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:14 +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 3/7] PM / devfreq: Use the available min/max frequency Date: Mon, 23 Oct 2017 10:32:08 +0900 Message-id: <1508722332-10628-4-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+NgFlrNKsWRmVeSWpSXmKPExsWy7bCmru58t7eRBtvm8lpMvHGFxeL6l+es FpPuT2CxONv0ht3i8q45bBafe48wWtxuXMFm8XjFW3YHDo/Fe14yeWxa1cnm0bdlFaPH501y ASxRqTYZqYkpqUUKqXnJ+SmZeem2St7B8c7xpmYGhrqGlhbmSgp5ibmptkouPgG6bpk5QGco KZQl5pQChQISi4uV9O1sivJLS1IVMvKLS2yVog0NjfQMDcz1jIyM9EyMY62MTIFKElIztux+ w16wWKOiZc0zxgbGfsUuRk4OCQETiZNT17J3MXJxCAnsYJTounOOCcL5zihx/d4/ZpiqtU0b WSASGxglti36CNXyg1Fi0/NDbCBVbAJaEvtf3ACzRQQCJDrXrgIbxSzQxCix/94NdpCEsICn xNoTs8CKWARUJSYfWgYW5xVwlehY3wm1Tk7iw55HYHFOATeJu2u/MoIMkhDoYZOY83saG0SR i8Sv+X1QtrDEq+NbgBo4gGxpiUtHbSHq2xklNs+5xwLhdDBK3F/ZyArRYCxxqquRCcRmFuCT ePe1hxWimVeio00IosRD4uLdXqiDHCU2H29ng3h5JqPEz8vL2SYwSi1gZFjFKJZaUJybnlps WGCkV5yYW1yal66XnJ+7iRGcULTMdjAuOudziFGAg1GJh5fB8G2kEGtiWXFl7iFGCQ5mJRHe ORZAId6UxMqq1KL8+KLSnNTiQ4ymwMCZyCwlmpwPTHZ5JfGGJpYGJmZGwORgaWioJM4ruv5a hJBAemJJanZqakFqEUwfEwenVANjZOibO0YH2+006/KnvfxczSZaeo59/m4msX0dEYW2KZ0h Lm+b36xti7xp9OJSHtv2rS/mcR+7lZN1Rrv+X/rHIzJ67nc40u9Ev9K/qJfNoZRywGthu9bK hW9S3xx+afD6UwjfloM9+4/G3Nl3X7t6jpL5xy+3Hnh53V3ItmF+nY//sUlLzuxdp8RSnJFo qMVcVJwIAE/NJos+AwAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplluLIzCtJLcpLzFFi42I5/e+xoO48t7eRBrv36VhMvHGFxeL6l+es FpPuT2CxONv0ht3i8q45bBafe48wWtxuXMFm8XjFW3YHDo/Fe14yeWxa1cnm0bdlFaPH501y ASxRXDYpqTmZZalF+nYJXBlbdr9hL1isUdGy5hljA2O/YhcjJ4eEgInE2qaNLF2MXBxCAusY Jb7+O8QM4fxglOg70s4GUsUmoCWx/8UNMFtEwE9i+/z1jCBFzAJNjBLL+2+BJYQFPCXWnpgF ZrMIqEpMPrSMHcTmFXCV6FjfyQyxTk7iw55HYHFOATeJu2u/MoLYQkA1fz/9Z5rAyLOAkWEV o2RqQXFuem6xUYFhXmq5XnFibnFpXrpecn7uJkZgIG07rNW3g/H+kvhDjAIcjEo8vAyGbyOF WBPLiitzDzFKcDArifDOsQAK8aYkVlalFuXHF5XmpBYfYpTmYFES572ddyxSSCA9sSQ1OzW1 ILUIJsvEwSnVwFhg7Wa89IUJxyne4hWLioV6fNeskXnz+LrYAkm5eWEnJHzmrvmkcDba6E2I ysdYl4DOYwzODmf0/9TZTuLZ1HZ5TmjiXd5zG4xPf35w7Q3Xm2eq3o0rTNkVX5a6Tkjk3X35 4WHdQiWuV3G+9Z6cTHH2HV8npd47zv+pM8m3ecWN6nt+8utV9yqxFGckGmoxFxUnAgAZaNzb IAIAAA== X-CMS-MailID: 20171023013214epcas1p353a430282734319c904ea2edaa737dce X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20171023013214epcas1p353a430282734319c904ea2edaa737dce X-RootMTR: 20171023013214epcas1p353a430282734319c904ea2edaa737dce 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 The commit a76caf55e5b35 ("thermal: Add devfreq cooling") is able to disable OPP as a cooling device. In result, both update_devfreq() and {min|max}_freq_show() have to consider the 'opp->available' status of each OPP. So, this patch adds the 'scaling_{min|max}_freq' to struct devfreq in order to indicate the available mininum and maximum frequency by adjusting OPP interface such as dev_pm_opp_{disable|enable}(). The 'scaling_{min|max}_freq' are used for on both update_devfreq() and {min|max}_freq_show(). Signed-off-by: Chanwoo Choi Acked-by: MyungJoo Ham --- drivers/devfreq/devfreq.c | 40 ++++++++++++++++++++++++++++++++-------- include/linux/devfreq.h | 4 ++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index b6ba24e5db0d..ee3e7cee30b6 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -28,6 +28,9 @@ #include #include "governor.h" +#define MAX(a,b) ((a > b) ? a : b) +#define MIN(a,b) ((a < b) ? a : b) + static struct class *devfreq_class; /* @@ -255,7 +258,7 @@ static int devfreq_notify_transition(struct devfreq *devfreq, int update_devfreq(struct devfreq *devfreq) { struct devfreq_freqs freqs; - unsigned long freq, cur_freq; + unsigned long freq, cur_freq, min_freq, max_freq; int err = 0; u32 flags = 0; @@ -273,19 +276,21 @@ int update_devfreq(struct devfreq *devfreq) return err; /* - * Adjust the frequency with user freq and QoS. + * Adjust the frequency with user freq, QoS and available freq. * * List from the highest priority * max_freq * min_freq */ + max_freq = MIN(devfreq->scaling_max_freq, devfreq->max_freq); + min_freq = MAX(devfreq->scaling_min_freq, devfreq->min_freq); - if (devfreq->min_freq && freq < devfreq->min_freq) { - freq = devfreq->min_freq; + if (min_freq && freq < min_freq) { + freq = min_freq; flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */ } - if (devfreq->max_freq && freq > devfreq->max_freq) { - freq = devfreq->max_freq; + if (max_freq && freq > max_freq) { + freq = max_freq; flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */ } @@ -494,6 +499,19 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type, int ret; mutex_lock(&devfreq->lock); + + devfreq->scaling_min_freq = find_available_min_freq(devfreq); + if (!devfreq->scaling_min_freq) { + mutex_unlock(&devfreq->lock); + return -EINVAL; + } + + devfreq->scaling_max_freq = find_available_max_freq(devfreq); + if (!devfreq->scaling_max_freq) { + mutex_unlock(&devfreq->lock); + return -EINVAL; + } + ret = update_devfreq(devfreq); mutex_unlock(&devfreq->lock); @@ -593,6 +611,7 @@ struct devfreq *devfreq_add_device(struct device *dev, err = -EINVAL; goto err_dev; } + devfreq->scaling_min_freq = devfreq->min_freq; devfreq->max_freq = find_available_max_freq(devfreq); if (!devfreq->max_freq) { @@ -600,6 +619,7 @@ struct devfreq *devfreq_add_device(struct device *dev, err = -EINVAL; goto err_dev; } + devfreq->scaling_max_freq = devfreq->max_freq; dev_set_name(&devfreq->dev, "devfreq%d", atomic_inc_return(&devfreq_no)); @@ -1127,7 +1147,9 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, static ssize_t min_freq_show(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%lu\n", to_devfreq(dev)->min_freq); + struct devfreq *df = to_devfreq(dev); + + return sprintf(buf, "%lu\n", MAX(df->scaling_min_freq, df->min_freq)); } static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, @@ -1161,7 +1183,9 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, static ssize_t max_freq_show(struct device *dev, struct device_attribute *attr, char *buf) { - return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq); + struct devfreq *df = to_devfreq(dev); + + return sprintf(buf, "%lu\n", MIN(df->scaling_max_freq, df->max_freq)); } static DEVICE_ATTR_RW(max_freq); diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 597294e0cc40..997a9eb34191 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -120,6 +120,8 @@ struct devfreq_dev_profile { * touch this. * @min_freq: Limit minimum frequency requested by user (0: none) * @max_freq: Limit maximum frequency requested by user (0: none) + * @scaling_min_freq: Limit minimum frequency requested by OPP interface + * @scaling_max_freq: Limit maximum frequency requested by OPP interface * @stop_polling: devfreq polling status of a device. * @total_trans: Number of devfreq transitions * @trans_table: Statistics of devfreq transitions @@ -153,6 +155,8 @@ struct devfreq { unsigned long min_freq; unsigned long max_freq; + unsigned long scaling_min_freq; + unsigned long scaling_max_freq; bool stop_polling; /* information for device frequency transition */