From patchwork Wed Nov 9 03:37:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huang lin X-Patchwork-Id: 9418441 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 B817D6048E for ; Wed, 9 Nov 2016 03:39:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC67D28620 for ; Wed, 9 Nov 2016 03:39:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 911A428705; Wed, 9 Nov 2016 03:39:55 +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 3AE8F28620 for ; Wed, 9 Nov 2016 03:39:55 +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 1c4JiU-0005hg-Mt; Wed, 09 Nov 2016 03:38:26 +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 1c4JiM-0005d5-CE; Wed, 09 Nov 2016 03:38:20 +0000 Received: by mail-pf0-f195.google.com with SMTP id y68so21884292pfb.1; Tue, 08 Nov 2016 19:37:57 -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=KBl6FJU/x8AJRspNftFOIsyDkr6Wvp05q+jI2Owyr78=; b=ivpg4DaSUk+O18eFPCUMFghYEExkz2zxTeV6ruYI7t8zFc/f1cpgNSKeS4Ml4RiMfY jg2eyYVaXsm8xM0BMivYPJYGy3HByQpHeniG9lA/GdWyKz4ikNnttnAYzenfWdoTZ77q iZVYe8XEfuDUnO0jnj7/0lFZuE/SmdAQVvlMcx7nOLu1fXXzH9BMJhGQPZ3ceg2uFD7S Ey9CvbQe/o4PtJxVhYCcHMI637hp1flonaKaCFcq34TmdF6dnhQ9WmTolvjyco5zh1SC aa5AvikEgjeLIOF/7ZRCjbcSGLyPAQycA/5wfzA/8dOhP5GF2fmYxjFoNRbLUL6lkKpV DDzQ== X-Gm-Message-State: ABUngveJTHfcuYcLvmZpNzCzeNpx5mMU+ichehmYxH5lDVAYzPSfoKmZ9YSt6F3Eu2Wyyg== X-Received: by 10.99.60.11 with SMTP id j11mr11739266pga.26.1478662677280; Tue, 08 Nov 2016 19:37:57 -0800 (PST) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id g10sm10153338pac.14.2016.11.08.19.37.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Nov 2016 19:37:56 -0800 (PST) From: Lin Huang To: myungjoo.ham@samsung.com Subject: [PATCH v6] PM/devfreq: add suspend frequency support Date: Wed, 9 Nov 2016 11:37:45 +0800 Message-Id: <1478662665-6357-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_193818_489361_DDA68F78 X-CRM114-Status: GOOD ( 15.66 ) 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 drivers/devfreq/devfreq.c | 14 +++++++++++--- drivers/devfreq/governor_simpleondemand.c | 9 +++++++++ include/linux/devfreq.h | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index da72d97..cfa64a0 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -359,9 +359,11 @@ void devfreq_monitor_suspend(struct devfreq *devfreq) mutex_unlock(&devfreq->lock); return; } - - devfreq_update_status(devfreq, devfreq->previous_freq); devfreq->stop_polling = true; + if (devfreq->suspend_freq) + update_devfreq(devfreq); + else + devfreq_update_status(devfreq, devfreq->previous_freq); mutex_unlock(&devfreq->lock); cancel_delayed_work_sync(&devfreq->work); } @@ -390,7 +392,6 @@ void devfreq_monitor_resume(struct devfreq *devfreq) devfreq->last_stat_updated = jiffies; devfreq->stop_polling = false; - if (devfreq->profile->get_cur_freq && !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq)) devfreq->previous_freq = freq; @@ -524,6 +525,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 +560,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..b82f089 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->stop_polling) { + *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 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 */