From patchwork Tue Feb 2 06:10:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 60993 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp529387lbb; Mon, 1 Feb 2016 22:10:32 -0800 (PST) X-Received: by 10.98.76.80 with SMTP id z77mr44742557pfa.121.1454393432153; Mon, 01 Feb 2016 22:10:32 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id by6si29147642pad.69.2016.02.01.22.10.23; Mon, 01 Feb 2016 22:10:32 -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 S1752733AbcBBGKT (ORCPT + 30 others); Tue, 2 Feb 2016 01:10:19 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:34953 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751002AbcBBGKR (ORCPT ); Tue, 2 Feb 2016 01:10:17 -0500 Received: by mail-pf0-f174.google.com with SMTP id 65so97342443pfd.2 for ; Mon, 01 Feb 2016 22:10:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=CI2wRFDK32uznAfhPsT5WRd8EN3G1oSlzfTm5Jbf42Q=; b=bfpOl6X27u6wiojOt9FUV3KPSWzjLPaV7PbhxOFV2AzoWRXCffMsr5Y0JvTK+VAQA8 mOzwfKMYBq6Eo8K+4e7RDNKZUbcY68BbaujOxqVVYuJ2fysNy9BEGW14ToUciUqx5gJK 2hwfJSlQi7KXNibp4/cI4Y6HCVYKlEUtwUMqw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=CI2wRFDK32uznAfhPsT5WRd8EN3G1oSlzfTm5Jbf42Q=; b=a3JxIq/nMvIs1qIn5oiaxTyb5twKV9p1fQwn5vaqa61tJXL4lUUZHtXauIglbQtabn Xxt218CnRxyUF4gm5pNyHki1sqAgvKI+2HQAWN+NVgtIbIlqn1I3UTIuYvXlOZVOLvAQ 7XjKEmPFcBVP37FsIhOgVfvqPmuJn1QJK3jgxtGuttbrKJ/LRgMu1ydBwretdl1biKon KGw1ZzZEw9P0zLIuDA2LrS2IRClPfX2wLRR6l38vicrdSIN2Lz+pKGDnZT5VtWaWDW1K Tl2s2YrOa1ylA75RMSJg3oOSdLt8ruxInLnIe3miyF15vtyw7SwONY+Or1Vw5M9u5Mh4 5DgQ== X-Gm-Message-State: AG10YOTKk8OtLQnS89QuC1lSQZ8057uXNAhMpEn6v+/ZC80QziWzCIFh7+/Cy4I73MEYPjMU X-Received: by 10.98.64.215 with SMTP id f84mr44665941pfd.113.1454393416529; Mon, 01 Feb 2016 22:10:16 -0800 (PST) Received: from localhost ([122.172.22.246]) by smtp.gmail.com with ESMTPSA id 72sm47425821pfk.28.2016.02.01.22.10.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Feb 2016 22:10:15 -0800 (PST) Date: Tue, 2 Feb 2016 11:40:13 +0530 From: Viresh Kumar To: Stephen Boyd Cc: Rafael Wysocki , linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, nm@ti.com, open list Subject: Re: [PATCH V2 11/16] cpufreq: dt: Pass regulator name to the OPP core Message-ID: <20160202061013.GC31828@vireshk> References: <20160202023418.GK4848@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160202023418.GK4848@codeaurora.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01-02-16, 18:34, Stephen Boyd wrote: > On 01/28, Viresh Kumar wrote: > > + cpu_reg = regulator_get_optional(dev, reg); > > + ret = PTR_ERR_OR_ZERO(cpu_reg); > > + if (!ret) { > > + regulator_put(cpu_reg); > > What's the point of creating a regulator just to find the name? > It seems like we should just look in the DT node of the CPU for > cpu-supply vs cpu0-supply. Then we don't need to involve the > regulator framework at all. Yeah, this can be simplified a bit.. > > static int allocate_resources(int cpu, struct device **cdev, > > struct regulator **creg, struct clk **cclk) > > { > > @@ -383,6 +450,9 @@ static int cpufreq_exit(struct cpufreq_policy *policy) > > cpufreq_cooling_unregister(priv->cdev); > > dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table); > > dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); > > + if (priv->reg_name) > > + dev_pm_opp_put_regulator(priv->cpu_dev); > > Let's hope this goes away because it's always right next to > dev_pm_opp_of_cpumask_remove_table() anyway. Same for reg_name. We are calling it from cpufreq-dt in this particular case, but it can be called from platform code as well. -------------------------8<------------------------- From: Viresh Kumar Date: Tue, 8 Sep 2015 17:16:46 +0530 Subject: [PATCH 04/20] cpufreq: dt: Pass regulator name to the OPP core OPP core can handle the regulators by itself, and but it needs to know the name of the regulator to fetch. Add support for that. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq-dt.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 4c9f8a828f6f..d4651d684f11 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -34,6 +34,7 @@ struct private_data { struct regulator *cpu_reg; struct thermal_cooling_device *cdev; unsigned int voltage_tolerance; /* in percentage */ + const char *reg_name; }; static struct freq_attr *cpufreq_dt_attr[] = { @@ -119,6 +120,30 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index) return ret; } +/* + * An earlier version of opp-v1 bindings used to name the regulator + * "cpu0-supply", we still need to handle that for backwards compatibility. + */ +static const char *find_supply_name(struct device *dev, struct device_node *np) +{ + struct property *pp; + int cpu = dev->id; + + /* Try "cpu0" for older DTs */ + if (!cpu) { + pp = of_find_property(np, "cpu0-supply", NULL); + if (pp) + return "cpu0"; + } + + pp = of_find_property(np, "cpu-supply", NULL); + if (pp) + return "cpu"; + + dev_dbg(dev, "no regulator for cpu%d\n", cpu); + return NULL; +} + static int allocate_resources(int cpu, struct device **cdev, struct regulator **creg, struct clk **cclk) { @@ -200,6 +225,7 @@ static int cpufreq_init(struct cpufreq_policy *policy) unsigned long min_uV = ~0, max_uV = 0; unsigned int transition_latency; bool opp_v1 = false; + const char *name = NULL; int ret; ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk); @@ -229,6 +255,25 @@ static int cpufreq_init(struct cpufreq_policy *policy) } /* + * OPP layer will be taking care of regulators now, but it needs to know + * the name of the regulator first. + */ + name = find_supply_name(cpu_dev, np); + if (IS_ERR(name)) { + ret = PTR_ERR(name); + goto out_node_put; + } + + if (name) { + ret = dev_pm_opp_set_regulator(cpu_dev, name); + if (ret) { + dev_err(cpu_dev, "Failed to set regulator for cpu%d: %d\n", + policy->cpu, ret); + goto out_node_put; + } + } + + /* * Initialize OPP tables for all policy->cpus. They will be shared by * all CPUs which have marked their CPUs shared with OPP bindings. * @@ -273,6 +318,7 @@ static int cpufreq_init(struct cpufreq_policy *policy) goto out_free_opp; } + priv->reg_name = name; of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance); transition_latency = dev_pm_opp_get_max_clock_latency(cpu_dev); @@ -366,6 +412,8 @@ static int cpufreq_init(struct cpufreq_policy *policy) kfree(priv); out_free_opp: dev_pm_opp_of_cpumask_remove_table(policy->cpus); + if (name) + dev_pm_opp_put_regulator(cpu_dev); out_node_put: of_node_put(np); out_put_reg_clk: @@ -383,6 +431,9 @@ static int cpufreq_exit(struct cpufreq_policy *policy) cpufreq_cooling_unregister(priv->cdev); dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table); dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); + if (priv->reg_name) + dev_pm_opp_put_regulator(priv->cpu_dev); + clk_put(policy->clk); if (!IS_ERR(priv->cpu_reg)) regulator_put(priv->cpu_reg);