From patchwork Thu Feb 28 04:49: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: 15129 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 023A223E24 for ; Thu, 28 Feb 2013 04:50:29 +0000 (UTC) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by fiordland.canonical.com (Postfix) with ESMTP id A0F4BA18B22 for ; Thu, 28 Feb 2013 04:50:28 +0000 (UTC) Received: by mail-vc0-f178.google.com with SMTP id m8so916021vcd.37 for ; Wed, 27 Feb 2013 20:50:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=2J+UER5f7BryRPs8QdyNqynH4tXEstFzjkEPS12sETc=; b=Q/6FC66e3hrsWdsKkpIkLo/jou28CQWqEQKI4+krQZxGsbv/vT6/i3i83R5UelXBlv cnOhdv0RmIaoIXRHrv/8Y5YHkYAEEGQyD6MtslLxaFqWiuvGoPzHCbJQ9oJxWvrm/+dq nxjdnJcwUvSZKoPNvhfltKXW2WKyHlifgemrsshHhGDCSfAhi1NiJWGZkHmHBApnbWni A87Iu8vUIOEUIgy6RqmENTrDBx0NnWPU8YF2YxT/43Njgf/W3kjMMrALMBG6EJtvEKRG RXyLZwffPnNLF6x7kp6hJOHa8nJyGoLyhPUpRYNDfFOcur1Ek2tB9if+S9kwypYfsPWk uHtw== X-Received: by 10.52.29.18 with SMTP id f18mr1706892vdh.57.1362027027878; Wed, 27 Feb 2013 20:50:27 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp206251veb; Wed, 27 Feb 2013 20:50:27 -0800 (PST) X-Received: by 10.68.129.135 with SMTP id nw7mr7145322pbb.58.1362027026887; Wed, 27 Feb 2013 20:50:26 -0800 (PST) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) by mx.google.com with ESMTPS id t8si679942pav.141.2013.02.27.20.50.26 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Feb 2013 20:50:26 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.53 is neither permitted nor denied by best guess record for domain of mturquette@linaro.org) client-ip=209.85.160.53; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.53 is neither permitted nor denied by best guess record for domain of mturquette@linaro.org) smtp.mail=mturquette@linaro.org Received: by mail-pb0-f53.google.com with SMTP id un1so823188pbc.40 for ; Wed, 27 Feb 2013 20:50:26 -0800 (PST) X-Received: by 10.68.154.202 with SMTP id vq10mr7105685pbb.45.1362027026353; Wed, 27 Feb 2013 20:50:26 -0800 (PST) Received: from quantum.gateway.2wire.net (adsl-69-228-86-207.dsl.pltn13.pacbell.net. [69.228.86.207]) by mx.google.com with ESMTPS id y9sm7799811paw.1.2013.02.27.20.50.22 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Feb 2013 20:50:25 -0800 (PST) From: Mike Turquette To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, patches@linaro.org, linaro-dev@lists.linaro.org, Mike Turquette Subject: [PATCH 3/5] cpufreq: omap: scale regulator from clk notifier Date: Wed, 27 Feb 2013 20:49:27 -0800 Message-Id: <1362026969-11457-4-git-send-email-mturquette@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1362026969-11457-1-git-send-email-mturquette@linaro.org> References: <1362026969-11457-1-git-send-email-mturquette@linaro.org> X-Gm-Message-State: ALoCoQn85kmu6/dw2YdsTKZcxUru8lXFPDWA8kEmqJ5Whkl4TH/QhdoXKjXqzcosB/F3Zl6Ju0J/ This patch moves direct control of the MPU voltage regulator out of the cpufreq driver .target callback and instead uses the common dvfs clk rate-change notifier infrastructure. Ideally it would be nice to reduce the .target callback for omap's cpufreq driver to a simple call to clk_set_rate. For now there is still some other stuff needed there (jiffies per loop, rounding the rate, etc etc). Signed-off-by: Mike Turquette --- drivers/cpufreq/omap-cpufreq.c | 82 ++++++++++------------------------------ 1 file changed, 20 insertions(+), 62 deletions(-) diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c index 1f3417a..6bec1c4 100644 --- a/drivers/cpufreq/omap-cpufreq.c +++ b/drivers/cpufreq/omap-cpufreq.c @@ -37,7 +37,7 @@ static struct cpufreq_frequency_table *freq_table; static atomic_t freq_table_users = ATOMIC_INIT(0); static struct clk *mpu_clk; static struct device *mpu_dev; -static struct regulator *mpu_reg; +static struct dvfs_info *di; static int omap_verify_speed(struct cpufreq_policy *policy) { @@ -62,10 +62,9 @@ static int omap_target(struct cpufreq_policy *policy, unsigned int relation) { unsigned int i; - int r, ret = 0; + int ret = 0; struct cpufreq_freqs freqs; - struct opp *opp; - unsigned long freq, volt = 0, volt_old = 0, tol = 0; + unsigned long freq; if (!freq_table) { dev_err(mpu_dev, "%s: cpu%d: no freq table!\n", __func__, @@ -109,50 +108,13 @@ static int omap_target(struct cpufreq_policy *policy, } freq = ret; - if (mpu_reg) { - opp = opp_find_freq_ceil(mpu_dev, &freq); - if (IS_ERR(opp)) { - dev_err(mpu_dev, "%s: unable to find MPU OPP for %d\n", - __func__, freqs.new); - return -EINVAL; - } - volt = opp_get_voltage(opp); - tol = volt * OPP_TOLERANCE / 100; - volt_old = regulator_get_voltage(mpu_reg); - } - - dev_dbg(mpu_dev, "cpufreq-omap: %u MHz, %ld mV --> %u MHz, %ld mV\n", - freqs.old / 1000, volt_old ? volt_old / 1000 : -1, - freqs.new / 1000, volt ? volt / 1000 : -1); - - /* scaling up? scale voltage before frequency */ - if (mpu_reg && (freqs.new > freqs.old)) { - r = regulator_set_voltage(mpu_reg, volt - tol, volt + tol); - if (r < 0) { - dev_warn(mpu_dev, "%s: unable to scale voltage up.\n", - __func__); - freqs.new = freqs.old; - goto done; - } - } + dev_dbg(mpu_dev, "cpufreq-omap: %u MHz --> %u MHz\n", + freqs.old / 1000, freqs.new / 1000); ret = clk_set_rate(mpu_clk, freqs.new * 1000); - /* scaling down? scale voltage after frequency */ - if (mpu_reg && (freqs.new < freqs.old)) { - r = regulator_set_voltage(mpu_reg, volt - tol, volt + tol); - if (r < 0) { - dev_warn(mpu_dev, "%s: unable to scale voltage down.\n", - __func__); - ret = clk_set_rate(mpu_clk, freqs.old * 1000); - freqs.new = freqs.old; - goto done; - } - } - freqs.new = omap_getspeed(policy->cpu); -done: /* notifiers */ for_each_cpu(i, policy->cpus) { freqs.cpu = i; @@ -172,10 +134,6 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy) { int result = 0; - mpu_clk = clk_get(NULL, "cpufreq_ck"); - if (IS_ERR(mpu_clk)) - return PTR_ERR(mpu_clk); - if (policy->cpu >= NR_CPUS) { result = -EINVAL; goto fail_ck; @@ -253,34 +211,34 @@ static struct cpufreq_driver omap_driver = { static int __init omap_cpufreq_init(void) { + struct dvfs_info_init dii; + + mpu_clk = clk_get(NULL, "cpufreq_ck"); + if (IS_ERR(mpu_clk)) + return PTR_ERR(mpu_clk); + mpu_dev = get_cpu_device(0); if (!mpu_dev) { pr_warning("%s: unable to get the mpu device\n", __func__); return -EINVAL; } - mpu_reg = regulator_get(mpu_dev, "vcc"); - if (IS_ERR(mpu_reg)) { - pr_warning("%s: unable to get MPU regulator\n", __func__); - mpu_reg = NULL; - } else { - /* - * Ensure physical regulator is present. - * (e.g. could be dummy regulator.) - */ - if (regulator_get_voltage(mpu_reg) < 0) { - pr_warn("%s: physical regulator not present for MPU\n", + dii.dev = mpu_dev; + dii.con_id = "cpufreq_ck"; + dii.reg_id = "vcc"; + dii.tol = OPP_TOLERANCE; + + di = dvfs_clk_notifier_register(&dii); + if (IS_ERR(di)) + pr_warning("%s: failed to register dvfs clk notifier\n", __func__); - regulator_put(mpu_reg); - mpu_reg = NULL; - } - } return cpufreq_register_driver(&omap_driver); } static void __exit omap_cpufreq_exit(void) { + dvfs_clk_notifier_unregister(di); cpufreq_unregister_driver(&omap_driver); }