From patchwork Mon Jul 8 01:44:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Turquette X-Patchwork-Id: 2824670 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 712CB9F7D6 for ; Mon, 8 Jul 2013 01:45:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 808B92012F for ; Mon, 8 Jul 2013 01:45:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E99D20113 for ; Mon, 8 Jul 2013 01:45:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753440Ab3GHBoy (ORCPT ); Sun, 7 Jul 2013 21:44:54 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:58596 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753429Ab3GHBow (ORCPT ); Sun, 7 Jul 2013 21:44:52 -0400 Received: by mail-pd0-f177.google.com with SMTP id p10so3526575pdj.36 for ; Sun, 07 Jul 2013 18:44:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=PY+N+pikxK6Dt4e0m4QzEZwQbFR1XI7BEfj2aCPcFHY=; b=WnRyrctFa0hvq8RJFMRkJ35PZLQgBdZe9fDtIreSKnCgHL4sp2mHFsjDdBZof28GHQ 5/VDpO4GzwsnAJT/CbzUY8hbe8OWrrlQkvxgMf2mcroYdQzbxbMi4vW7B4fJyBWEn+qX iIqAD067MvfYnGaoZ9vKbnMGE0c7+NSB6FbUPGYfvkNaULLbDxcExodgnVwdEzlXcMKj RwnP8vZzzH9wLQ6kk3f8pnrPsqrfI7hWeaukJ1/mz/ET7XDVWbc3ApFgpmOJvJ/ZXctt nGPSbRSNYHP36Tji4CCsYEHu2ucQLTNLI/nn2CYkvHNQ09gYdCkyFsMNM3e6DsxGu/pW QPBg== X-Received: by 10.66.50.104 with SMTP id b8mr20938500pao.39.1373247891944; Sun, 07 Jul 2013 18:44:51 -0700 (PDT) Received: from localhost.localdomain (c-50-152-203-145.hsd1.ca.comcast.net. [50.152.203.145]) by mx.google.com with ESMTPSA id ib9sm19378164pbc.43.2013.07.07.18.44.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 07 Jul 2013 18:44:51 -0700 (PDT) From: Mike Turquette To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, Mike Turquette Subject: [PATCH RFC 2/3] clk: cpufreq helper for voltage scaling Date: Sun, 7 Jul 2013 18:44:27 -0700 Message-Id: <1373247868-21444-3-git-send-email-mturquette@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1373247868-21444-1-git-send-email-mturquette@linaro.org> References: <1373247868-21444-1-git-send-email-mturquette@linaro.org> X-Gm-Message-State: ALoCoQno4OCNVjHXz/rcOVzfTcj97A9bzYhLZyx8g6RjIbnkgyIltGXHx2lhNmJ0JMvYG+HkDAqU Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.2 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 This patch builds on "clk: notifier handler for dynamic voltage scaling" by adding a CPUfreq-specific helper function for registering a clock rate-change notifier to scale regulator voltage as a function of clock rate. In particular this patch creates an instance of struct cpufreq_frequency_table and also calculate the voltage scaling latency, both of which are returned to the caller for use in the CPUfreq driver. Signed-off-by: Mike Turquette --- drivers/clk/clk-voltage-notifier.c | 71 ++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 6 ++++ 2 files changed, 77 insertions(+) diff --git a/drivers/clk/clk-voltage-notifier.c b/drivers/clk/clk-voltage-notifier.c index cb6b85f..8e1707f 100644 --- a/drivers/clk/clk-voltage-notifier.c +++ b/drivers/clk/clk-voltage-notifier.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -133,3 +134,73 @@ void of_clk_volt_notifier_unregister(struct notifier_block *nb) kfree(vsd); } EXPORT_SYMBOL_GPL(of_clk_volt_notifier_unregister); + +void of_clk_cpufreq_notifier_unregister(struct notifier_block *nb, + struct cpufreq_frequency_table *freq_table) +{ + struct volt_scale_data *data = to_volt_scale_data(nb); + struct device *dev = data->dev; + + opp_free_cpufreq_table(dev, &freq_table); + of_clk_volt_notifier_unregister(nb); +} +EXPORT_SYMBOL_GPL(of_clk_cpufreq_notifier_unregister); + +/** + * of_clk_cpufreq_notifer_register - register clock notifier to scale voltage + * @dev: device that owns this scaling operation + * @np: pointer to device's DT node + * @clk: clock whose rate-change notifier triggers voltage scaling + * @supply: regulator id string + * @freq_table: pointer to uninitialized CPUfreq frequency scaling table + * @voltage_latency: worst case voltage scaling latency + */ +struct notifier_block *of_clk_cpufreq_notifier_register(struct device *dev, + struct device_node *np, struct clk *clk, const char *supply, + struct cpufreq_frequency_table **table, + unsigned int *voltage_latency) +{ + struct notifier_block *nb; + struct volt_scale_data *vsd; + struct opp *opp; + unsigned long min, max; + int ret, i; + + nb = of_clk_volt_notifier_register(dev, np, clk, supply, + voltage_latency); + if (IS_ERR(nb)) + return nb; + + vsd = to_volt_scale_data(nb); + + ret = opp_init_cpufreq_table(dev, table); + if (ret) { + pr_err("failed to init cpufreq table: %d\n", ret); + goto err_unregister; + } + + /* find the min and max voltages and compute worst-case latency */ + for (i = 0; table[0][i].frequency != CPUFREQ_TABLE_END; i++) + ; + + rcu_read_lock(); + opp = opp_find_freq_exact(dev, + table[0][0].frequency * 1000, true); + min = opp_get_voltage(opp); + opp = opp_find_freq_exact(dev, + table[0][i-1].frequency * 1000, true); + max = opp_get_voltage(opp); + rcu_read_unlock(); + + *voltage_latency = regulator_set_voltage_time(vsd->reg, min, max); + if (*voltage_latency < 0) + pr_warn("%s: failed to calculate voltage latency, %d\n", + __func__, ret); + + return nb; + +err_unregister: + of_clk_volt_notifier_unregister(nb); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(of_clk_cpufreq_notifier_register); diff --git a/include/linux/clk.h b/include/linux/clk.h index 85ea520..3104883 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -86,6 +86,12 @@ struct notifier_block *of_clk_volt_notifier_register(struct device *dev, struct device_node *np, struct clk *clk, const char *supply, int *voltage_latency); void of_clk_volt_notifier_unregister(struct notifier_block *nb); +struct notifier_block *of_clk_cpufreq_notifier_register(struct device *dev, + struct device_node *np, struct clk *clk, const char *supply, + struct cpufreq_frequency_table **table, + unsigned int *voltage_latency); +void of_clk_cpufreq_notifier_unregister(struct notifier_block *nb, + struct cpufreq_frequency_table *freq_table); #endif