From patchwork Thu Jan 9 15:59:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Abraham X-Patchwork-Id: 3462031 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 360D5C02DC for ; Thu, 9 Jan 2014 16:02:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ECC152016C for ; Thu, 9 Jan 2014 16:02:04 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 19CD02013D for ; Thu, 9 Jan 2014 16:02:00 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W1I2l-0003E7-3N; Thu, 09 Jan 2014 16:01:15 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W1I2a-0001at-Jt; Thu, 09 Jan 2014 16:01:04 +0000 Received: from mail-pb0-x230.google.com ([2607:f8b0:400e:c01::230]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W1I2O-0001YT-GW for linux-arm-kernel@lists.infradead.org; Thu, 09 Jan 2014 16:00:54 +0000 Received: by mail-pb0-f48.google.com with SMTP id md12so3188203pbc.35 for ; Thu, 09 Jan 2014 08:00:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VPWXe+NGZn7D3D0gtcRjhOFn3ErABHfvVsYOOY08USY=; b=OPBgFcYZOxTMb81eJolT805jVAYS41AnuWNv8e4HeTDscQavAAxyhHYp/hHxg5vIxJ Oyh653K6oMnxdSeVMws5pmAZhuQIt8rrSJfVV6kzVy+nE6ngee31yGd6V1J3x5dPn+BB mXFbKxrYYUSRdjGiWAE+qTi5d4eRpT/yrNyHKP2AoJnQFbtG5ZglHLhg4yPVS82Quicy PreJNwGrmWmcrqvG4GgaCa1xl8inNyFba05aVm8VSjSVv8ZHTYAfKStEvISUC0Zfp/bt pYG6r9q5r8b2X+dqzTy/uaCMWL5O05PQqhOKA3822PICmZMnKwpkWMSSkuBijxsPFOxU h2Zw== X-Received: by 10.66.163.74 with SMTP id yg10mr4503030pab.57.1389283230905; Thu, 09 Jan 2014 08:00:30 -0800 (PST) Received: from user-ubuntu.sisodomain.com ([115.113.119.130]) by mx.google.com with ESMTPSA id wp8sm10882717pbc.26.2014.01.09.08.00.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 Jan 2014 08:00:29 -0800 (PST) From: Thomas Abraham To: cpufreq@vger.kernel.org Subject: [PATCH 1/6] cpufreq: cpufreq-cpu0: allow optional safe voltage during frequency transitions Date: Thu, 9 Jan 2014 21:29:20 +0530 Message-Id: <1389283165-17708-2-git-send-email-thomas.ab@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1389283165-17708-1-git-send-email-thomas.ab@samsung.com> References: <1389283165-17708-1-git-send-email-thomas.ab@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140109_110052_788454_C11AB729 X-CRM114-Status: GOOD ( 20.34 ) X-Spam-Score: -2.0 (--) Cc: devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org, viresh.kumar@linaro.org, t.figa@samsung.com, kgene.kim@samsung.com, shawn.guo@linaro.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 On some platforms such as the Samsung Exynos, changing the frequency of the CPU clock requires changing the frequency of the PLL that is supplying the CPU clock. To change the frequency of the PLL, the CPU clock is temporarily reparented to another parent clock. The clock frequency of this temporary parent clock could be much higher than the clock frequency of the PLL at the time of reparenting. Due to the temporary increase in the CPU clock speed, the CPU (and any other components in the CPU clock domain such as dividers, mux, etc.) have to to be operated at a higher voltage level, called the safe voltage level. This patch adds optional support to temporarily switch to a safe voltage level during CPU frequency transitions. Cc: Shawn Guo Signed-off-by: Thomas Abraham Reviewed-by: Lukasz Majewski --- .../devicetree/bindings/cpufreq/cpufreq-cpu0.txt | 5 ++ drivers/cpufreq/cpufreq-cpu0.c | 49 +++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/cpufreq/cpufreq-cpu0.txt b/Documentation/devicetree/bindings/cpufreq/cpufreq-cpu0.txt index f055515..020d859 100644 --- a/Documentation/devicetree/bindings/cpufreq/cpufreq-cpu0.txt +++ b/Documentation/devicetree/bindings/cpufreq/cpufreq-cpu0.txt @@ -19,6 +19,10 @@ Optional properties: - cooling-min-level: - cooling-max-level: Please refer to Documentation/devicetree/bindings/thermal/thermal.txt. +- safe-opp-index: Certain platforms require that during a opp transition, + a system should not go below a particular opp level. For such systems, + this property specifies the minimum opp to be maintained during the + opp transitions. Examples: @@ -36,6 +40,7 @@ cpus { 396000 950000 198000 850000 >; + safe-opp-index = <1>; clock-latency = <61036>; /* two CLK32 periods */ #cooling-cells = <2>; cooling-min-level = <0>; diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c index 0c12ffc..dda4b7b 100644 --- a/drivers/cpufreq/cpufreq-cpu0.c +++ b/drivers/cpufreq/cpufreq-cpu0.c @@ -27,6 +27,8 @@ static unsigned int transition_latency; static unsigned int voltage_tolerance; /* in percentage */ +static unsigned long safe_frequency; +static unsigned long safe_voltage; static struct device *cpu_dev; static struct clk *cpu_clk; @@ -69,12 +71,26 @@ static int cpu0_set_target(struct cpufreq_policy *policy, unsigned int index) new_freq / 1000, volt ? volt / 1000 : -1); /* scaling up? scale voltage before frequency */ - if (!IS_ERR(cpu_reg) && new_freq > old_freq) { + if (!IS_ERR(cpu_reg) && new_freq > old_freq && + new_freq >= safe_frequency) { ret = regulator_set_voltage_tol(cpu_reg, volt, tol); if (ret) { pr_err("failed to scale voltage up: %d\n", ret); return ret; } + } else if (!IS_ERR(cpu_reg) && old_freq < safe_frequency) { + /* + * the scaled up voltage level for the new_freq is lower + * than the safe voltage level. so set safe_voltage + * as the intermediate voltage level and revert it + * back after the frequency has been changed. + */ + ret = regulator_set_voltage(cpu_reg, safe_voltage, + safe_voltage); + if (ret) { + pr_err("failed to set safe voltage: %d\n", ret); + return ret; + } } ret = clk_set_rate(cpu_clk, freq_exact); @@ -94,6 +110,19 @@ static int cpu0_set_target(struct cpufreq_policy *policy, unsigned int index) } } + /* + * if safe voltage was applied during voltage scale up, then set + * the correct target voltage now. + */ + if (!IS_ERR(cpu_reg) && new_freq > old_freq && + new_freq < safe_frequency) { + ret = regulator_set_voltage_tol(cpu_reg, volt, tol); + if (ret) { + pr_err("failed to scale voltage up: %d\n", ret); + return ret; + } + } + return ret; } @@ -116,7 +145,9 @@ static struct cpufreq_driver cpu0_cpufreq_driver = { static int cpu0_cpufreq_probe(struct platform_device *pdev) { + struct dev_pm_opp *opp; struct device_node *np; + unsigned int safe_opp_index; int ret; cpu_dev = get_cpu_device(0); @@ -165,13 +196,27 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev) goto out_put_node; } + if (!of_property_read_u32(np, "safe-opp-index", &safe_opp_index)) { + rcu_read_lock(); + opp = dev_pm_opp_find_freq_exact(cpu_dev, + freq_table[safe_opp_index].frequency * 1000, true); + if (IS_ERR(opp)) { + rcu_read_unlock(); + pr_err("safe opp index %d is invalid\n", + safe_opp_index); + goto out_free_table; + } + safe_voltage = dev_pm_opp_get_voltage(opp); + safe_frequency = freq_table[safe_opp_index].frequency; + rcu_read_unlock(); + } + of_property_read_u32(np, "voltage-tolerance", &voltage_tolerance); if (of_property_read_u32(np, "clock-latency", &transition_latency)) transition_latency = CPUFREQ_ETERNAL; if (!IS_ERR(cpu_reg)) { - struct dev_pm_opp *opp; unsigned long min_uV, max_uV; int i;