From patchwork Tue Nov 8 09:11:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huang lin X-Patchwork-Id: 9416951 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 7BF5C60721 for ; Tue, 8 Nov 2016 09:13:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68BF728869 for ; Tue, 8 Nov 2016 09:13:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CE842875E; Tue, 8 Nov 2016 09:13:42 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM 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 CAAA928829 for ; Tue, 8 Nov 2016 09:13:41 +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 1c42Ry-0007ow-CA; Tue, 08 Nov 2016 09:12:14 +0000 Received: from mail-pf0-f195.google.com ([209.85.192.195]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c42Rr-0007Yc-CJ; Tue, 08 Nov 2016 09:12:08 +0000 Received: by mail-pf0-f195.google.com with SMTP id i88so18673805pfk.2; Tue, 08 Nov 2016 01:11:46 -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=hzs7VsKS7rM4SBdxXsFdbynzSnP4l8Ekjy94iJCP9pc=; b=ZTYOzpLw46ZvUPBIlrvHTuc8z4MEbDlBVQhe963/7lpRCAW0zRmkQfQwWDUSBXw2c8 zIGqD7s9G0LJpLYGE9mmqbA/c9Src9GlCU1FnqhTTiJ0SdwuQJP/rMr2uFVVuuKlppwO 4DEUm0wmyyCp3YtxPy12sLySRegSYYWpQ+DdI3X5V/iBDYIfWjZ3fFelmGvwFNJkq/9i VtY8ddxDLRSEPVqTw5Fo2xJgckuHnJQgLpqxk0myoldPuv6gXiSgQkfbcxSOqhYF2r/X c7h7k3SqhXXUvnKWwlrBHtWkJpgFF2KCl8Ajo93Z3VvGUSOfy7S5laEI4ixjSGhp+rtW uD0w== X-Gm-Message-State: ABUngvc30JjaLb7nW+x2h3u7j2BKbhw1XakUyRj2O9z7QCNPlVMH/GZ20V812yJFQd0IUQ== X-Received: by 10.99.9.129 with SMTP id 123mr5306767pgj.84.1478596306236; Tue, 08 Nov 2016 01:11:46 -0800 (PST) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id f23sm46388845pff.59.2016.11.08.01.11.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Nov 2016 01:11:45 -0800 (PST) From: Lin Huang To: myungjoo.ham@samsung.com Subject: [PATCH v4] PM/devfreq: add suspend frequency support Date: Tue, 8 Nov 2016 17:11:29 +0800 Message-Id: <1478596289-7442-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-20161108_011207_521312_95F31278 X-CRM114-Status: GOOD ( 16.44 ) 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() drivers/devfreq/devfreq.c | 15 +++++++++++++-- drivers/devfreq/governor_simpleondemand.c | 9 +++++++++ include/linux/devfreq.h | 9 +++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index bf3ea76..d9d56e1 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -363,7 +363,10 @@ void devfreq_monitor_suspend(struct devfreq *devfreq) mutex_unlock(&devfreq->lock); return; } - + if (devfreq->suspend_freq) { + update_devfreq(devfreq); + devfreq->suspend_flag = true; + } devfreq_update_status(devfreq, devfreq->previous_freq); devfreq->stop_polling = true; mutex_unlock(&devfreq->lock); @@ -394,7 +397,8 @@ void devfreq_monitor_resume(struct devfreq *devfreq) devfreq->last_stat_updated = jiffies; devfreq->stop_polling = false; - + if (devfreq->suspend_freq) + devfreq->suspend_flag = false; if (devfreq->profile->get_cur_freq && !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq)) devfreq->previous_freq = freq; @@ -528,6 +532,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__); @@ -563,6 +568,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); diff --git a/drivers/devfreq/governor_simpleondemand.c b/drivers/devfreq/governor_simpleondemand.c index ae72ba5..84b3ce1 100644 --- a/drivers/devfreq/governor_simpleondemand.c +++ b/drivers/devfreq/governor_simpleondemand.c @@ -29,6 +29,15 @@ static int devfreq_simple_ondemand_func(struct devfreq *df, struct devfreq_simple_ondemand_data *data = df->data; unsigned long max = (df->max_freq) ? df->max_freq : UINT_MAX; + /* + * if devfreq in suspend status and have suspend_freq, + * the frequency need to set to suspend_freq + */ + if (df->suspend_flag) { + *freq = df->suspend_freq; + return 0; + } + err = devfreq_update_stats(df); if (err) return err; diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 2de4e2e..c463ae1 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 */ @@ -179,6 +180,7 @@ struct devfreq { unsigned long min_freq; unsigned long max_freq; bool stop_polling; + bool suspend_flag; /* information for device frequency transition */ unsigned int total_trans; @@ -214,6 +216,8 @@ extern int devfreq_resume_device(struct devfreq *devfreq); /* Helper functions for devfreq user device driver with OPP. */ extern struct dev_pm_opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, u32 flags); +extern void devfreq_opp_get_suspend_opp(struct device *dev, + struct devfreq *devfreq); extern int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq); extern int devfreq_unregister_opp_notifier(struct device *dev, @@ -348,6 +352,11 @@ static inline struct dev_pm_opp *devfreq_recommended_opp(struct device *dev, return ERR_PTR(-EINVAL); } +static inline void devfreq_opp_get_suspend_opp(struct device *dev, + struct devfreq *devfreq) +{ +} + static inline int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq) {