From patchwork Tue Dec 22 10:16:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 58857 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp3139884lbb; Tue, 22 Dec 2015 02:17:16 -0800 (PST) X-Received: by 10.98.89.27 with SMTP id n27mr4968844pfb.70.1450779436315; Tue, 22 Dec 2015 02:17:16 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sw10si3585212pab.55.2015.12.22.02.17.16; Tue, 22 Dec 2015 02:17:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932669AbbLVKRP (ORCPT + 11 others); Tue, 22 Dec 2015 05:17:15 -0500 Received: from mail-pf0-f172.google.com ([209.85.192.172]:36347 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932181AbbLVKRO (ORCPT ); Tue, 22 Dec 2015 05:17:14 -0500 Received: by mail-pf0-f172.google.com with SMTP id o64so104289538pfb.3 for ; Tue, 22 Dec 2015 02:17:14 -0800 (PST) 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 :in-reply-to:references; bh=Jnuaxvu4slpD7UhvDC1MtY26tDo9mqYoGW9U0HeivZA=; b=Zg7O5ICSQK97pf0jDCkTGKZgCgqoNT7bj8OUsUCowIh26aFlfD14rdwkrK07SCBb89 9YCS5rKCAdEitrWxn5uChP13MlZm+JnOGIy8ZjILQZpimvW39BArxtR6LIt+5Ko5GMNo JYBCM5Bzm51qb+1qK5xi4NBjxSbxK5p0w1tME= 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:in-reply-to:references; bh=Jnuaxvu4slpD7UhvDC1MtY26tDo9mqYoGW9U0HeivZA=; b=Cnd6+97hC4BsQloawHht5Q+KeqkpjLZtyCu5HuCiq6PYK9ozoFYRpOA2SrA787a/ef Nnxt2iyk331Xaxa1VXsKlc9FKtKTHewNxKWOolH1XeSWTgPyFI7KUoJdR/s5QydEtqJg QkwH31/ElHPkuu5wowEAOkeCwiXDd/+Qhy8kQA+t/aTbQ+4q33YjHGy+ILj+lhrTJbqu N1wCis3eNK1gA5TGR88oXQ5JeRWnPMbK4zb+DdhWkmyn8r8IBCQ9E2DvCLuZZ9nmIwJn BSUiGJPW7aqr9etTWPNN2Mo290Zuq/hI7ux/aWVp6x6j5e7S/KO45UevjgfLj0i25XXV 0OeA== X-Gm-Message-State: ALoCoQkDTlNxdzYGqXWi4NCuj2JTlpyBz9D9TTzJpCYCkPRguSTFdX7RcKoZuApU+yN2g1ikVDv0QRHxM2yvBoiks17uGichFA== X-Received: by 10.98.87.133 with SMTP id i5mr14365337pfj.130.1450779434417; Tue, 22 Dec 2015 02:17:14 -0800 (PST) Received: from localhost ([122.171.29.67]) by smtp.gmail.com with ESMTPSA id n3sm40235856pfa.79.2015.12.22.02.17.13 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 22 Dec 2015 02:17:13 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Stephen Boyd , nm@ti.com, Viresh Kumar Subject: [PATCH 15/17] cpufreq: dt: Use dev_pm_opp_set_rate() to switch frequency Date: Tue, 22 Dec 2015 15:46:16 +0530 Message-Id: X-Mailer: git-send-email 2.7.0.rc1.186.g94414c4 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org OPP core supports frequency/voltage changes based on the target frequency now, use that instead of open coding the same in cpufreq-dt driver. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq-dt.c | 72 ++------------------------------------------ 1 file changed, 2 insertions(+), 70 deletions(-) -- 2.7.0.rc1.186.g94414c4 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 01a7354b1ada..89c89dfab237 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -45,78 +45,10 @@ static struct freq_attr *cpufreq_dt_attr[] = { static int set_target(struct cpufreq_policy *policy, unsigned int index) { - struct dev_pm_opp *opp; - struct cpufreq_frequency_table *freq_table = policy->freq_table; - struct clk *cpu_clk = policy->clk; struct private_data *priv = policy->driver_data; - struct device *cpu_dev = priv->cpu_dev; - struct regulator *cpu_reg = priv->cpu_reg; - unsigned long volt = 0, volt_old = 0, tol = 0; - unsigned int old_freq, new_freq; - long freq_Hz, freq_exact; - int ret; - - freq_Hz = clk_round_rate(cpu_clk, freq_table[index].frequency * 1000); - if (freq_Hz <= 0) - freq_Hz = freq_table[index].frequency * 1000; - - freq_exact = freq_Hz; - new_freq = freq_Hz / 1000; - old_freq = clk_get_rate(cpu_clk) / 1000; - if (!IS_ERR(cpu_reg)) { - unsigned long opp_freq; - - rcu_read_lock(); - opp = dev_pm_opp_find_freq_ceil(cpu_dev, &freq_Hz); - if (IS_ERR(opp)) { - rcu_read_unlock(); - dev_err(cpu_dev, "failed to find OPP for %ld\n", - freq_Hz); - return PTR_ERR(opp); - } - volt = dev_pm_opp_get_voltage(opp); - opp_freq = dev_pm_opp_get_freq(opp); - rcu_read_unlock(); - tol = volt * priv->voltage_tolerance / 100; - volt_old = regulator_get_voltage(cpu_reg); - dev_dbg(cpu_dev, "Found OPP: %ld kHz, %ld uV\n", - opp_freq / 1000, volt); - } - - dev_dbg(cpu_dev, "%u MHz, %ld mV --> %u MHz, %ld mV\n", - old_freq / 1000, (volt_old > 0) ? volt_old / 1000 : -1, - new_freq / 1000, volt ? volt / 1000 : -1); - - /* scaling up? scale voltage before frequency */ - if (!IS_ERR(cpu_reg) && new_freq > old_freq) { - ret = regulator_set_voltage_tol(cpu_reg, volt, tol); - if (ret) { - dev_err(cpu_dev, "failed to scale voltage up: %d\n", - ret); - return ret; - } - } - - ret = clk_set_rate(cpu_clk, freq_exact); - if (ret) { - dev_err(cpu_dev, "failed to set clock rate: %d\n", ret); - if (!IS_ERR(cpu_reg) && volt_old > 0) - regulator_set_voltage_tol(cpu_reg, volt_old, tol); - return ret; - } - - /* scaling down? scale voltage after frequency */ - if (!IS_ERR(cpu_reg) && new_freq < old_freq) { - ret = regulator_set_voltage_tol(cpu_reg, volt, tol); - if (ret) { - dev_err(cpu_dev, "failed to scale voltage down: %d\n", - ret); - clk_set_rate(cpu_clk, old_freq * 1000); - } - } - - return ret; + return dev_pm_opp_set_rate(priv->cpu_dev, + policy->freq_table[index].frequency * 1000); } /*