From patchwork Fri Sep 13 12:59:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 20101 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 729C1202E6 for ; Fri, 13 Sep 2013 13:08:37 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id ht10sf1194628vcb.1 for ; Fri, 13 Sep 2013 06:08:37 -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=+ZeCwtUS1c6tIhzziFrmSRoQOND2XWedR38acXbueSs=; b=Z8DnBO2HU3fEyi7vbbOU1hQ7soxsPaH6oexGCA0kaMbv0+h2ehSgcRd1g5r5xldWEy ZSTd1bgsm7oU4FXYk8BMBhM3BR3Jy5E2jxs/NNRq/u5g06DozcZhPmsO1DdFyvZD4eqU LqXJpsgmE1sen2UEwfpY3jjLtHMs3nmWnQa8FX1cLx1BKAGGe5Zzcakn3C8ar+r1RtOq UHyHn3zEp+M9OIEcJZ2lwhJqmItT+DlijnK8S4g39z2FZMTHq0Ejr7AzNb/851+oM5/T tlEuMgQUDy9hEfqqSqh9cd8NpBKxbChB+LLnHXB+C+wUOgF1b0riI4zw+sdZi/MbqHWn 6JKg== X-Gm-Message-State: ALoCoQnxuRx5Om0w92t3sE/jKj0gfiiTeZQTIsj8YLt160+0GW5a4KjODXop3T8W+Nbe/7iZGiYK X-Received: by 10.236.115.198 with SMTP id e46mr5404238yhh.33.1379077717219; Fri, 13 Sep 2013 06:08:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.39.104 with SMTP id o8ls1098132qek.38.gmail; Fri, 13 Sep 2013 06:08:37 -0700 (PDT) X-Received: by 10.220.11.7 with SMTP id r7mr11999770vcr.12.1379077717007; Fri, 13 Sep 2013 06:08:37 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id tq4si3102813vdc.38.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Sep 2013 06:08:37 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.178 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.178; Received: by mail-vc0-f178.google.com with SMTP id ha12so886647vcb.37 for ; Fri, 13 Sep 2013 06:08:36 -0700 (PDT) X-Received: by 10.52.103.35 with SMTP id ft3mr10200878vdb.5.1379077716901; Fri, 13 Sep 2013 06:08:36 -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 u4csp79731vcz; Fri, 13 Sep 2013 06:08:36 -0700 (PDT) X-Received: by 10.68.59.38 with SMTP id w6mr12357554pbq.135.1379077716013; Fri, 13 Sep 2013 06:08:36 -0700 (PDT) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by mx.google.com with ESMTPS id hi6si11202435pac.84.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Sep 2013 06:08:36 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.169 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.192.169; Received: by mail-pd0-f169.google.com with SMTP id r10so1244972pdi.0 for ; Fri, 13 Sep 2013 06:08:35 -0700 (PDT) X-Received: by 10.68.200.34 with SMTP id jp2mr13244733pbc.53.1379077715607; Fri, 13 Sep 2013 06:08:35 -0700 (PDT) Received: from localhost ([122.167.78.148]) by mx.google.com with ESMTPSA id u7sm11681120pbf.12.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 13 Sep 2013 06:08:35 -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, linux-arm-kernel@lists.infradead.org, Hans-Christian Egtvedt , Viresh Kumar Subject: [PATCH 047/228] cpufreq: at32ap: add frequency table Date: Fri, 13 Sep 2013 18:29:53 +0530 Message-Id: <3a35746ef433eb30448302efe2c610c14b7feeca.1379063063.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.220.178 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: , From: Hans-Christian Egtvedt This patch adds a dynamically calculated frequency table to the at32ap driver. In short the architecture can scale in power of two between a maximum and minimum frequency. Min, max, and the steps in between are added to the table. Signed-off-by: Hans-Christian Egtvedt Signed-off-by: Viresh Kumar --- drivers/cpufreq/at32ap-cpufreq.c | 49 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/at32ap-cpufreq.c b/drivers/cpufreq/at32ap-cpufreq.c index e0c38d9..1d19fa5 100644 --- a/drivers/cpufreq/at32ap-cpufreq.c +++ b/drivers/cpufreq/at32ap-cpufreq.c @@ -19,8 +19,10 @@ #include #include #include +#include static struct clk *cpuclk; +static struct cpufreq_frequency_table *freq_table; static int at32_verify_speed(struct cpufreq_policy *policy) { @@ -85,13 +87,17 @@ static int at32_set_target(struct cpufreq_policy *policy, static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy) { + unsigned int frequency, rate; + int retval, steps, i; + if (policy->cpu != 0) return -EINVAL; cpuclk = clk_get(NULL, "cpu"); if (IS_ERR(cpuclk)) { pr_debug("cpufreq: could not get CPU clk\n"); - return PTR_ERR(cpuclk); + retval = PTR_ERR(cpuclk); + goto out_err; } policy->cpuinfo.min_freq = (clk_round_rate(cpuclk, 1) + 500) / 1000; @@ -101,9 +107,46 @@ static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy) policy->min = policy->cpuinfo.min_freq; policy->max = policy->cpuinfo.max_freq; - printk("cpufreq: AT32AP CPU frequency driver\n"); + /* + * AVR32 CPU frequency rate scales in power of two between maximum and + * minimum, also add space for the table end marker. + * + * Further validate that the frequency is usable, and append it to the + * frequency table. + */ + steps = fls(policy->cpuinfo.max_freq / policy->cpuinfo.min_freq) + 1; + freq_table = kzalloc(steps * sizeof(struct cpufreq_frequency_table), + GFP_KERNEL); + if (!freq_table) { + retval = -ENOMEM; + goto out_err_put_clk; + } - return 0; + frequency = policy->cpuinfo.max_freq; + for (i = 0; i < (steps - 1); i++) { + rate = clk_round_rate(cpuclk, frequency * 1000) / 1000; + + if (rate != frequency) + freq_table[i].frequency = CPUFREQ_ENTRY_INVALID; + else + freq_table[i].frequency = frequency; + + frequency /= 2; + } + + freq_table[steps - 1].frequency = CPUFREQ_TABLE_END; + + retval = cpufreq_table_validate_and_show(policy, freq_table); + if (!retval) { + printk("cpufreq: AT32AP CPU frequency driver\n"); + return 0; + } + + kfree(freq_table); +out_err_put_clk: + clk_put(cpuclk); +out_err: + return retval; } static struct cpufreq_driver at32_driver = {