From patchwork Wed Oct 30 22:51:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 21277 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6B8C0244A4 for ; Wed, 30 Oct 2013 22:52:21 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id w10sf2647963pde.11 for ; Wed, 30 Oct 2013 15:52:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version: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=lc0JY71ZATzgG3RhDVxyp1lJePdugcfcxC/WWh3P6CU=; b=HSGdPcQVN5xQGU+QYPpXUVpnqlaB4GEt6uQF481ffXX9ktrJ3agaPutdUSuIzfx5Mh 2MWOKD47PqwIflH2kL4z76v7CTZH+YXCHJi7Inru1oUq5xQsDAK6flfOLOZfn3ZdJJIX wQRudotYRGYs26n4UEi445LTAz5vWbbIu/L/+mWIznFDDIP3ouymCMYk3o7p9WttXL91 vCaRh/kQ/a7np2NIesfphbT6woxdjTZsFMusBLRRZIHmlcssvQJTn/Oe7BmiOanAV2RU ZcJNKCOcvXIvFp0joaScU6yctm74E4PT1P90JldEtzPnDCaxzijdHO+jvVkCxNIURdxn x7Tg== X-Gm-Message-State: ALoCoQm0sJ9VMsCNJDXK/9QRjQzGoBENoLzXSql7RLhgPg3K5xxkQHqQ19w8dBhHmrSwSARQDtn5 X-Received: by 10.66.189.163 with SMTP id gj3mr376429pac.32.1383173540725; Wed, 30 Oct 2013 15:52:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.98.99 with SMTP id eh3ls788276qeb.68.gmail; Wed, 30 Oct 2013 15:52:20 -0700 (PDT) X-Received: by 10.220.144.18 with SMTP id x18mr23759vcu.15.1383173540576; Wed, 30 Oct 2013 15:52:20 -0700 (PDT) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id st7si78400vdc.81.2013.10.30.15.52.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Oct 2013 15:52:20 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id oy12so1533046veb.11 for ; Wed, 30 Oct 2013 15:52:20 -0700 (PDT) X-Received: by 10.58.181.230 with SMTP id dz6mr21231vec.35.1383173540454; Wed, 30 Oct 2013 15:52:20 -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 u4csp316039vcz; Wed, 30 Oct 2013 15:52:20 -0700 (PDT) X-Received: by 10.182.143.103 with SMTP id sd7mr93665obb.70.1383173538913; Wed, 30 Oct 2013 15:52:18 -0700 (PDT) Received: from mail-oa0-f52.google.com (mail-oa0-f52.google.com [209.85.219.52]) by mx.google.com with ESMTPS id qc5si104645oeb.149.2013.10.30.15.52.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Oct 2013 15:52:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.219.52 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.219.52; Received: by mail-oa0-f52.google.com with SMTP id j1so2209976oag.39 for ; Wed, 30 Oct 2013 15:52:18 -0700 (PDT) X-Received: by 10.182.44.167 with SMTP id f7mr68419obm.3.1383173538640; Wed, 30 Oct 2013 15:52:18 -0700 (PDT) Received: from localhost (sccc-66-78-236-243.smartcity.com. [66.78.236.243]) by mx.google.com with ESMTPSA id ee7sm735778oeb.5.2013.10.30.15.52.17 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 30 Oct 2013 15:52:18 -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@linaro.org Subject: [PATCH V2 Resend 01/16] cpufreq: create cpufreq_generic_get() routine Date: Thu, 31 Oct 2013 04:21:59 +0530 Message-Id: <1a672a5e0b0f6fa4e03646b5f124f68e13f079f2.1383173230.git.viresh.kumar@linaro.org> 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.128.180 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 02d534d..eb42edb 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -176,6 +176,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; @@ -1030,6 +1044,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) { @@ -1062,11 +1081,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) @@ -1087,12 +1101,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 5bd6ab9..122d4cd 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 */ @@ -447,6 +449,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);