From patchwork Mon Jul 13 17:33:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Javi Merino X-Patchwork-Id: 6780711 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9798B9F2F0 for ; Mon, 13 Jul 2015 17:34:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A09E120525 for ; Mon, 13 Jul 2015 17:34:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F18F2051C for ; Mon, 13 Jul 2015 17:34:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751625AbbGMReV (ORCPT ); Mon, 13 Jul 2015 13:34:21 -0400 Received: from foss.arm.com ([217.140.101.70]:58789 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbbGMReV (ORCPT ); Mon, 13 Jul 2015 13:34:21 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 82011491; Mon, 13 Jul 2015 10:34:42 -0700 (PDT) Received: from e104805.cambridge.arm.com (e104805.cambridge.arm.com [10.2.131.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1B88E3F317; Mon, 13 Jul 2015 10:34:19 -0700 (PDT) From: Javi Merino To: linux-pm@vger.kernel.org Cc: =?UTF-8?q?=C3=98rjan=20Eide?= , MyungJoo Ham , Kyungmin Park Subject: [PATCH v2 1/4] PM / devfreq: Add function to set max/min frequency Date: Mon, 13 Jul 2015 18:33:55 +0100 Message-Id: <1436808838-23391-2-git-send-email-javi.merino@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436808838-23391-1-git-send-email-javi.merino@arm.com> References: <1436808838-23391-1-git-send-email-javi.merino@arm.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ørjan Eide Factor out the logic to set minimum and maximum frequency for the device so that it can be used by other parts of the kernel. Cc: MyungJoo Ham Cc: Kyungmin Park Signed-off-by: Ørjan Eide --- Changes since v1: - Rename devfreq_qos_set_[max|min] to devfreq_set_[max|min] as suggested by MyungJoo Ham drivers/devfreq/devfreq.c | 72 +++++++++++++++++++++++++++++++---------------- include/linux/devfreq.h | 13 +++++++++ 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index ca1b362d77e2..5b3f2f32f1e5 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -768,6 +768,48 @@ err_out: } EXPORT_SYMBOL(devfreq_remove_governor); +int devfreq_set_max(struct devfreq *df, unsigned long value) +{ + unsigned long min; + int ret = 0; + + mutex_lock(&df->lock); + min = df->min_freq; + if (value && min && value < min) { + ret = -EINVAL; + goto unlock; + } + + df->max_freq = value; + update_devfreq(df); +unlock: + mutex_unlock(&df->lock); + + return ret; +} +EXPORT_SYMBOL(devfreq_set_max); + +int devfreq_set_min(struct devfreq *df, unsigned long value) +{ + unsigned long max; + int ret = 0; + + mutex_lock(&df->lock); + max = df->max_freq; + if (value && max && value > max) { + ret = -EINVAL; + goto unlock; + } + + df->min_freq = value; + update_devfreq(df); +unlock: + mutex_unlock(&df->lock); + + return ret; +} +EXPORT_SYMBOL(devfreq_set_min); + static ssize_t governor_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -899,24 +941,15 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, struct devfreq *df = to_devfreq(dev); unsigned long value; int ret; - unsigned long max; ret = sscanf(buf, "%lu", &value); if (ret != 1) return -EINVAL; - mutex_lock(&df->lock); - max = df->max_freq; - if (value && max && value > max) { - ret = -EINVAL; - goto unlock; - } + ret = devfreq_set_min(df, value); + if (!ret) + ret = count; - df->min_freq = value; - update_devfreq(df); - ret = count; -unlock: - mutex_unlock(&df->lock); return ret; } @@ -932,24 +965,15 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, struct devfreq *df = to_devfreq(dev); unsigned long value; int ret; - unsigned long min; ret = sscanf(buf, "%lu", &value); if (ret != 1) return -EINVAL; - mutex_lock(&df->lock); - min = df->min_freq; - if (value && min && value < min) { - ret = -EINVAL; - goto unlock; - } + ret = devfreq_set_max(df, value); + if (!ret) + ret = count; - df->max_freq = value; - update_devfreq(df); - ret = count; -unlock: - mutex_unlock(&df->lock); return ret; } static DEVICE_ATTR_RW(min_freq); diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index ce447f0f1bad..dce82c695955 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -204,6 +204,9 @@ extern int devm_devfreq_register_opp_notifier(struct device *dev, extern void devm_devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq); +int devfreq_set_min(struct devfreq *df, unsigned long value); +int devfreq_set_max(struct devfreq *df, unsigned long value); + #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND) /** * struct devfreq_simple_ondemand_data - void *data fed to struct devfreq @@ -289,6 +292,16 @@ static inline void devm_devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq) { } + +static inline int devfreq_set_min(struct devfreq *df, unsigned long value) +{ + return -EINVAL; +} + +static inline int devfreq_set_max(struct devfreq *df, unsigned long value) +{ + return -EINVAL; +} #endif /* CONFIG_PM_DEVFREQ */ #endif /* __LINUX_DEVFREQ_H__ */