From patchwork Tue Feb 9 05:00:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 61499 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1831548lbl; Mon, 8 Feb 2016 21:03:23 -0800 (PST) X-Received: by 10.66.220.71 with SMTP id pu7mr8261293pac.83.1454994203195; Mon, 08 Feb 2016 21:03:23 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yv4si51305508pab.119.2016.02.08.21.03.22; Mon, 08 Feb 2016 21:03:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932197AbcBIFDS (ORCPT + 30 others); Tue, 9 Feb 2016 00:03:18 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:33294 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755270AbcBIFCX (ORCPT ); Tue, 9 Feb 2016 00:02:23 -0500 Received: by mail-pa0-f47.google.com with SMTP id cy9so85374304pac.0 for ; Mon, 08 Feb 2016 21:02:23 -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=nQ1i4UEEhgkbxl/hMO7Easp1zUdImUcH11RLB0dVC6c=; b=IGit6SMd9JoshCIUvPbsNbSIcSwRzjD6a4rIA6sb9ZXvF1mOM/oepM5YxBzjkl6IF7 Bc54YngOHNyRpbClhSpuSal0tAZ1YNGRkm2fu9OWJOO8NZrKr6+GKbExEr50zL4XEmsj QBbvymuTUQbDzcpZXfwtbnKUAxcIpUIowKGYM= 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=nQ1i4UEEhgkbxl/hMO7Easp1zUdImUcH11RLB0dVC6c=; b=OTE9lx2p6lkcRXnLZOIzuaPQz8t7r6PgCmHOyE3OmO4U0MxViSJv72UumbNMwWLIsF ZNNosGjfOIVdhxt0fwXTtJCN9FTviaoyOIBaN0B98zMGeSlYiPlGM8t6+x2zIfuD/j1Z WZl8HEUKp+wKtv7loTCAgDTbE5aa+9qW8UGTYP+Gyo87uqevIVur59oxEy2xdspWO7ar Bm5j+4OBQj3YHyWVoaGOVhLBK4xy1AbOyqMn/I4WMY80vUHBZPsmRsM+sed1HrQ9Jdxh LajlT6z/8um9DI/wRfhwXQmzG5chK1nwH8l6TAWpHMZr49fOw2CgwyH6vo/743aup7el bDJQ== X-Gm-Message-State: AG10YOSMNrpaYuqdsbFdVBw93iU9ualSl/QpBVa9ZDUeVFi9U0nj6q7oEVUFi7Nl89b/nPmo X-Received: by 10.66.97.8 with SMTP id dw8mr34215153pab.39.1454994142813; Mon, 08 Feb 2016 21:02:22 -0800 (PST) Received: from localhost ([122.172.22.246]) by smtp.gmail.com with ESMTPSA id yx4sm33504736pac.5.2016.02.08.21.02.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 21:02:22 -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 , linux-kernel@vger.kernel.org (open list) Subject: [PATCH V3 14/16] cpufreq: dt: Use dev_pm_opp_set_rate() to switch frequency Date: Tue, 9 Feb 2016 10:30:46 +0530 Message-Id: <29ed9d51c47e5a95b53c617508d5bcbb1cbd44eb.1454992187.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.370.gb2aa7f8 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Reviewed-by: Stephen Boyd --- drivers/cpufreq/cpufreq-dt.c | 73 ++------------------------------------------ 1 file changed, 2 insertions(+), 71 deletions(-) -- 2.7.1.370.gb2aa7f8 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 6f80ce56b4ec..150a172c7d0a 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -45,79 +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, tol = 0; - int volt_old = 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, %d 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); } /*