From patchwork Thu May 26 02:52:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Muckle X-Patchwork-Id: 9136503 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 AC846607D3 for ; Thu, 26 May 2016 02:54:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A24A727EE9 for ; Thu, 26 May 2016 02:54:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97494282BB; Thu, 26 May 2016 02:54:07 +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 24BF927EE9 for ; Thu, 26 May 2016 02:54:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752863AbcEZCxH (ORCPT ); Wed, 25 May 2016 22:53:07 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:35031 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752860AbcEZCxG (ORCPT ); Wed, 25 May 2016 22:53:06 -0400 Received: by mail-pf0-f182.google.com with SMTP id g64so26023529pfb.2 for ; Wed, 25 May 2016 19:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FoT8qq7HU/amkctJzP119WFFuBm2G7HnYyzcAvtrUto=; b=Nx89NTCSA9Pl/9p/mIPxcfQSf/Syaai13jtPLg0yseZgkqT7W6e4kpQ7CPxJfMNRj1 mN6GDl+vR5r4Je8FOwE2rxD2ASScAV86cYBlpK5OJsgLsQSu+/NZjYvHJNaoyk3FQGPt FhAcI0FoS3sGhcsnyFoyCPOpyPsuhFSHqZHrQ= 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:in-reply-to :references; bh=FoT8qq7HU/amkctJzP119WFFuBm2G7HnYyzcAvtrUto=; b=ZQtx7nwV+kz1Yui8IbxjnKES211Ej/X7x5PLXGvNdEiqooogED3h6erRcYXkmLCypI qnLrXuDyiDuXs1IeaU7pFMWx3QSJw3grVwHVvwVmzNcfLfXHWJaWh02S1G15kTFAcnE2 HQB4Ml7WlYKArv7B2uHkrELxiXM9sMLeTJR5G0YHmShGHsxX6NZ3RPvFi0z4zlI4Ui2Y Zp8hKwdgweHJrkIb7mSyw6qybJpZ7uHeuUYJHsZcKXBa8RQL4RPVahtYUmbLeQS2RKj/ 1/QrfR6YK5uUSOpGZQ7Cvy+RLyAuo7LG2zIEdz0eyCEGA1Yraux0MAxUeLjuRm+wKwqz j0gw== X-Gm-Message-State: ALyK8tL9oZ5g+skwBKcs2wtXxeW4gLbTYiafHk4m0JHHQSqVn2yFXeMwencRf0fDHYWB8Gl9 X-Received: by 10.98.108.6 with SMTP id h6mr10660545pfc.104.1464231185126; Wed, 25 May 2016 19:53:05 -0700 (PDT) Received: from graphite.smuckle.net (cpe-76-167-105-107.san.res.rr.com. [76.167.105.107]) by smtp.gmail.com with ESMTPSA id g82sm1540634pfj.22.2016.05.25.19.53.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 May 2016 19:53:04 -0700 (PDT) From: Steve Muckle X-Google-Original-From: Steve Muckle To: Peter Zijlstra , Ingo Molnar , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Juri Lelli , Patrick Bellasi , Michael Turquette Subject: [PATCH v2 1/3] cpufreq: add resolve_freq driver callback Date: Wed, 25 May 2016 19:52:59 -0700 Message-Id: <1464231181-30741-2-git-send-email-smuckle@linaro.org> X-Mailer: git-send-email 2.4.10 In-Reply-To: <1464231181-30741-1-git-send-email-smuckle@linaro.org> References: <1464231181-30741-1-git-send-email-smuckle@linaro.org> 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 Cpufreq governors may need to know what a particular target frequency maps to in the driver without necessarily wanting to set the frequency. Support this operation via a new cpufreq API, cpufreq_driver_resolve_freq(). The above API will call a new cpufreq driver callback, resolve_freq(), if it has been registered by the driver. If that callback has not been registered and a frequency table is available then the frequency table is walked using cpufreq_frequency_table_target(). UINT_MAX is returned if no driver callback or frequency table is available. Suggested-by: Rafael J. Wysocki Signed-off-by: Steve Muckle --- drivers/cpufreq/cpufreq.c | 25 +++++++++++++++++++++++++ include/linux/cpufreq.h | 11 +++++++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 77d77a4e3b74..3b44f4bdc071 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1849,6 +1849,31 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, } EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch); +unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, + unsigned int target_freq) +{ + struct cpufreq_frequency_table *freq_table; + int index, retval; + + clamp_val(target_freq, policy->min, policy->max); + + if (cpufreq_driver->resolve_freq) + return cpufreq_driver->resolve_freq(policy, target_freq); + + freq_table = cpufreq_frequency_get_table(policy->cpu); + if (!freq_table) + return UINT_MAX; + + retval = cpufreq_frequency_table_target(policy, freq_table, + target_freq, CPUFREQ_RELATION_L, + &index); + if (retval) + return UINT_MAX; + + return freq_table[index].frequency; +} +EXPORT_SYMBOL_GPL(cpufreq_driver_resolve_freq); + /* Must set freqs->new to intermediate frequency */ static int __target_intermediate(struct cpufreq_policy *policy, struct cpufreq_freqs *freqs, int index) diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 4e81e08db752..675f17f98e75 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -271,6 +271,13 @@ struct cpufreq_driver { int (*target_intermediate)(struct cpufreq_policy *policy, unsigned int index); + /* + * Return the driver-supported frequency that a particular target + * frequency maps to (does not set the new frequency). + */ + unsigned int (*resolve_freq)(struct cpufreq_policy *policy, + unsigned int target_freq); + /* should be defined, if possible */ unsigned int (*get)(unsigned int cpu); @@ -487,6 +494,10 @@ int cpufreq_driver_target(struct cpufreq_policy *policy, int __cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation); + +unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, + unsigned int target_freq); + int cpufreq_register_governor(struct cpufreq_governor *governor); void cpufreq_unregister_governor(struct cpufreq_governor *governor);