From patchwork Thu Nov 24 09:11:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huang lin X-Patchwork-Id: 9445011 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 A60B96075F for ; Thu, 24 Nov 2016 09:14:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DF3927C7A for ; Thu, 24 Nov 2016 09:14:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8256D27CF3; Thu, 24 Nov 2016 09:14:06 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C20827C7A for ; Thu, 24 Nov 2016 09:14:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c9q5A-0003UF-KT; Thu, 24 Nov 2016 09:12:40 +0000 Received: from mail-pg0-f65.google.com ([74.125.83.65]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c9q4k-0003Ls-SC; Thu, 24 Nov 2016 09:12:16 +0000 Received: by mail-pg0-f65.google.com with SMTP id e9so2968244pgc.1; Thu, 24 Nov 2016 01:11:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/SBBJH7DybbHF+XVBfhqgxfR2TsjcA+65AB6sfZaw48=; b=nC2yGqRXJoAUZiu9+1zKsCvy4H757dHzh+WfWX++yns0Ge+bM7WENzL7yC8KIdxLN6 682WVQEESRX7FS9FvxG8+cSLB2nntnpToD31/7bB2ZVI6WPfHzQyZIEXuCRcOz9FG8HE Vvkz1O7NPVuwSpgQZz1Tg52oBRmzrlDouLqU9PIuzfv2qX0ccfEfhW0UHP/wXHaPMaWG 29XtfXIYZbQ7lA86HG34SCTMvQywBhbF58cZT2/tuAtXmEKcLxEXrEA2nowcnOv9/mk3 OEqhX/SVz+Hs1qIEJiDrj/mTpBg/UhOJmfgMo80qyFuPZpQactRMe+mQclvZbrRyBEwW Z1ZQ== X-Gm-Message-State: AKaTC01mh+wEZWWnpb3DQLB7Rh2PWLl8KH4Xv4Kt9ZlQH5oZtAVl1+MntjLDDKaGS2t4og== X-Received: by 10.98.217.67 with SMTP id s64mr1339362pfg.66.1479978713329; Thu, 24 Nov 2016 01:11:53 -0800 (PST) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id 16sm58536508pfk.54.2016.11.24.01.11.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Nov 2016 01:11:52 -0800 (PST) From: Lin Huang To: myungjoo.ham@samsung.com Subject: [PATCH v7] PM/devfreq: add suspend frequency support Date: Thu, 24 Nov 2016 17:11:42 +0800 Message-Id: <1479978702-21449-1-git-send-email-hl@rock-chips.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161124_011215_030177_2A577D84 X-CRM114-Status: GOOD ( 15.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lin Huang , linux-pm@vger.kernel.org, dbasehore@chromium.org, dianders@chromium.org, linux-kernel@vger.kernel.org, cw00.choi@samsung.com, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add suspend frequency support and if needed set it to the frequency obtained from the suspend opp (can be defined using opp-v2 bindings and is optional). Signed-off-by: Lin Huang --- Changes in v2: - use update_devfreq() instead devfreq_update_status() Changes in v3: - fix build error Changes in v4: - move dev_pm_opp_get_suspend_opp() to devfreq_add_device() Changes in v5: - delete devfreq_opp_get_suspend_opp() in devfreq.h Changes in v6: - return to use stop_polling check suspend status Changes in v7: - move handle suspend frequency in devfreq_suspend_device() drivers/devfreq/devfreq.c | 47 ++++++++++++++++++++++++++++++++++------------- include/linux/devfreq.h | 1 + 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index da72d97..958abc8 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -212,16 +212,7 @@ static int devfreq_notify_transition(struct devfreq *devfreq, return 0; } -/* Load monitoring helper functions for governors use */ - -/** - * update_devfreq() - Reevaluate the device and configure frequency. - * @devfreq: the devfreq instance. - * - * Note: Lock devfreq->lock before calling update_devfreq - * This function is exported for governors. - */ -int update_devfreq(struct devfreq *devfreq) +static int _update_devfreq(struct devfreq *devfreq, bool is_suspending) { struct devfreq_freqs freqs; unsigned long freq, cur_freq; @@ -237,9 +228,13 @@ int update_devfreq(struct devfreq *devfreq) return -EINVAL; /* Reevaluate the proper frequency */ - err = devfreq->governor->get_target_freq(devfreq, &freq); - if (err) - return err; + if (is_suspending && devfreq->suspend_freq) { + freq = devfreq->suspend_freq; + } else { + err = devfreq->governor->get_target_freq(devfreq, &freq); + if (err) + return err; + } /* * Adjust the frequency with user freq and QoS. @@ -285,6 +280,21 @@ int update_devfreq(struct devfreq *devfreq) devfreq->previous_freq = freq; return err; } + +/* Load monitoring helper functions for governors use */ + +/** + * update_devfreq() - Reevaluate the device and configure frequency. + * @devfreq: the devfreq instance. + * + * Note: Lock devfreq->lock before calling update_devfreq + * This function is exported for governors. + */ + +int update_devfreq(struct devfreq *devfreq) +{ + return _update_devfreq(devfreq, false); +} EXPORT_SYMBOL(update_devfreq); /** @@ -524,6 +534,7 @@ struct devfreq *devfreq_add_device(struct device *dev, struct devfreq *devfreq; struct devfreq_governor *governor; int err = 0; + struct dev_pm_opp *suspend_opp; if (!dev || !profile || !governor_name) { dev_err(dev, "%s: Invalid parameters.\n", __func__); @@ -558,6 +569,12 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->data = data; devfreq->nb.notifier_call = devfreq_notifier_call; + rcu_read_lock(); + suspend_opp = dev_pm_opp_get_suspend_opp(dev); + if (suspend_opp) + devfreq->suspend_freq = dev_pm_opp_get_freq(suspend_opp); + rcu_read_unlock(); + if (!devfreq->profile->max_state && !devfreq->profile->freq_table) { mutex_unlock(&devfreq->lock); devfreq_set_freq_table(devfreq); @@ -754,6 +771,10 @@ int devfreq_suspend_device(struct devfreq *devfreq) if (!devfreq->governor) return 0; + mutex_lock(&devfreq->lock); + _update_devfreq(devfreq, true); + mutex_unlock(&devfreq->lock); + return devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_SUSPEND, NULL); } diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 98c6993..517e394 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -172,6 +172,7 @@ struct devfreq { struct delayed_work work; unsigned long previous_freq; + unsigned long suspend_freq; struct devfreq_dev_status last_status; void *data; /* private data for governors */