From patchwork Fri Aug 23 15:50:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 19477 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7A1BE248E6 for ; Fri, 23 Aug 2013 15:52:02 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id ox1sf607342veb.8 for ; Fri, 23 Aug 2013 08:52:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=8ZI5tWGswEB3s10jGGF/ZAJeaCvdjJMAv1FuGRkTISA=; b=ohamVs/uI/O1jzX3mtZ0L6wMyt4LEailpMsz8ysy5BkKBxFlAQBqlkBrISbnN0dnX7 E/98hQXWKmXWDgZvBmnZAMHYMGpGwphrQfncqpD4BkRFiLp/PqtWChdJdmhNlW04K4lO 8ER7adnK3ZrEBo2IELQ/QV4R7r/qdo2gbDtN7JnqyZBpJFbjs9iZlOAoZw+3gvXmPw39 PBpiT50jLqCEXLhwDMRhA3gHdRyzArjU7q9iIr/Nv15J943Iho9cctMsCA4DePucsMMi wYgDLbbZdeY6s5YYn2Q5MUYHe+5Pghz4AsyTeVSU4v5LxrjLtICaZfC+sT7PVl9epIbM RkPQ== X-Received: by 10.236.222.228 with SMTP id t94mr122394yhp.18.1377273121815; Fri, 23 Aug 2013 08:52:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.14.106 with SMTP id o10ls1546149qec.36.gmail; Fri, 23 Aug 2013 08:52:01 -0700 (PDT) X-Received: by 10.220.48.194 with SMTP id s2mr131830vcf.43.1377273121716; Fri, 23 Aug 2013 08:52:01 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id gb9si116858vdc.119.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Aug 2013 08:52:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id ha11so541090vcb.35 for ; Fri, 23 Aug 2013 08:52:01 -0700 (PDT) X-Gm-Message-State: ALoCoQmavz0Opi6QdUkNwvpy0tckz3iOm2dk5pgzhWiGZCAez2rwGOThlXEiJQ8kHR2oEOlQDLK8 X-Received: by 10.52.245.2 with SMTP id xk2mr108875vdc.57.1377273121600; Fri, 23 Aug 2013 08:52:01 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp100609vcz; Fri, 23 Aug 2013 08:52:01 -0700 (PDT) X-Received: by 10.66.162.167 with SMTP id yb7mr21951470pab.16.1377273120631; Fri, 23 Aug 2013 08:52:00 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id rt3si194086pbc.353.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 Aug 2013 08:52:00 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.160.50; Received: by mail-pb0-f50.google.com with SMTP id uo5so835943pbc.9 for ; Fri, 23 Aug 2013 08:52:00 -0700 (PDT) X-Received: by 10.68.196.37 with SMTP id ij5mr283642pbc.175.1377273120133; Fri, 23 Aug 2013 08:52:00 -0700 (PDT) Received: from localhost ([122.172.193.46]) by mx.google.com with ESMTPSA id zq10sm1869992pab.6.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 23 Aug 2013 08:51:59 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Viresh Kumar Subject: [PATCH 01/16] cpufreq: create cpufreq_generic_get() routine Date: Fri, 23 Aug 2013 21:20:36 +0530 Message-Id: X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , CPUFreq drivers that use clock frameworks interface,i.e. clk_get_rate(), to get CPUs clk rate, has similar sort of code used for most of them. This patch adds a generic ->get() which will do the same thing for them. All those drivers are required to now is to set .get to cpufreq_generic_get() and set their clk pointer in policy->clk during ->init(). Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 26 ++++++++++++++++++++------ include/linux/cpufreq.h | 3 +++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 5fc9c6b..b068f00 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -219,6 +219,20 @@ int cpufreq_generic_init(struct cpufreq_policy *policy, } EXPORT_SYMBOL_GPL(cpufreq_generic_init); +unsigned int cpufreq_generic_get(unsigned int cpu) +{ + struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); + + if (!policy || IS_ERR(policy->clk)) { + pr_err("%s: No %s associated to cpu: %d\n", __func__, + policy ? "clk" : "policy", cpu); + return 0; + } + + return clk_get_rate(policy->clk) / 1000; +} +EXPORT_SYMBOL_GPL(cpufreq_generic_get); + struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) { struct cpufreq_policy *policy = NULL; @@ -1058,6 +1072,11 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, goto err_set_policy_cpu; } + write_lock_irqsave(&cpufreq_driver_lock, flags); + for_each_cpu(j, policy->cpus) + per_cpu(cpufreq_cpu_data, j) = policy; + write_unlock_irqrestore(&cpufreq_driver_lock, flags); + if (cpufreq_driver->get) { policy->cur = cpufreq_driver->get(policy->cpu); if (!policy->cur) { @@ -1090,11 +1109,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, } #endif - write_lock_irqsave(&cpufreq_driver_lock, flags); - for_each_cpu(j, policy->cpus) - per_cpu(cpufreq_cpu_data, j) = policy; - write_unlock_irqrestore(&cpufreq_driver_lock, flags); - if (!frozen) { ret = cpufreq_add_dev_interface(policy, dev); if (ret) @@ -1115,12 +1129,12 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, return 0; err_out_unregister: +err_get_freq: write_lock_irqsave(&cpufreq_driver_lock, flags); for_each_cpu(j, policy->cpus) per_cpu(cpufreq_cpu_data, j) = NULL; write_unlock_irqrestore(&cpufreq_driver_lock, flags); -err_get_freq: if (cpufreq_driver->exit) cpufreq_driver->exit(policy); err_set_policy_cpu: diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 6adea26..7746d11 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -11,6 +11,7 @@ #ifndef _LINUX_CPUFREQ_H #define _LINUX_CPUFREQ_H +#include #include #include #include @@ -66,6 +67,7 @@ struct cpufreq_policy { unsigned int cpu; /* cpu nr of CPU managing this policy */ unsigned int last_cpu; /* cpu nr of previous CPU that managed * this policy */ + struct clk *clk; struct cpufreq_cpuinfo cpuinfo;/* see above */ unsigned int min; /* in kHz */ @@ -424,6 +426,7 @@ void cpufreq_frequency_table_put_attr(unsigned int cpu); int cpufreq_table_validate_and_show(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table); +unsigned int cpufreq_generic_get(unsigned int cpu); int cpufreq_generic_init(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table, unsigned int transition_latency);