From: jamie@jamieiles.com (Jamie Iles)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V4 38/62] SPEAr CPU freq: Adding support for CPU Freq framework
Date: Wed, 19 Jan 2011 00:20:46 +0000 [thread overview]
Message-ID: <20110119002046.GC2209@gallagher> (raw)
In-Reply-To: <0f47958e70aa830f749fe1a5e8c03b853740d701.1295333959.git.viresh.kumar@st.com>
Hi,
On Tue, Jan 18, 2011 at 12:42:05PM +0530, Viresh Kumar wrote:
> From: Deepak Sikri <deepak.sikri@st.com>
>
> Signed-off-by: Deepak Sikri <deepak.sikri@st.com>
> Signed-off-by: Rajeev Kumar <rajeev-dlh.kumar@st.com>
> Signed-off-by: shiraz hashim <shiraz.hashim@st.com>
> Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
> ---
[...]
> diff --git a/arch/arm/plat-spear/cpufreq.c b/arch/arm/plat-spear/cpufreq.c
> new file mode 100644
> index 0000000..9384d65
> --- /dev/null
> +++ b/arch/arm/plat-spear/cpufreq.c
> @@ -0,0 +1,159 @@
> +/*
> + * arch/arm/plat-spear/cpufreq.c
> + *
> + * CPU Frequency Scaling for SPEAr platform
> + *
> + * Copyright (C) 2010 ST Microelectronics
> + * Deepak Sikri<deepak.sikri@st.com>
> + *
> + *
> + * This file is licensed under the terms of the GNU General Public
> + * License version 2. This program is licensed "as is" without any
> + * warranty of any kind, whether express or implied.
> + */
> +
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +#include <linux/sched.h>
> +#include <linux/cpufreq.h>
> +#include <linux/delay.h>
> +#include <linux/init.h>
> +#include <linux/err.h>
> +#include <linux/clk.h>
> +#include <linux/io.h>
> +#include <asm/system.h>
> +#include <mach/hardware.h>
> +
> +#define CPU_CLK "cpu_clk"
> +
> +#ifdef CONFIG_ARCH_SPEAR13XX
> +#define MIN_CPU_FREQ 200000
> +#define MAX_CPU_FREQ 500000
> +
> +static u32 spear_cpu_freq[] = {
> + 200000, /* 200 MHZ */
> + 250000, /* 250 MHZ */
> + 332000, /* 332 MHZ */
> + 400000, /* 400 MHZ */
> + 500000, /* 500 MHZ */
> +};
> +#elif defined(CONFIG_ARCH_SPEAR6XX) || defined(CONFIG_ARCH_SPEAR3XX)
> +#define MIN_CPU_FREQ 166000
> +#define MAX_CPU_FREQ 332000
> +
> +static u32 spear_cpu_freq[] = {
> + 166000, /* 166 MHZ */
> + 266000, /* 266 MHZ */
> + 332000, /* 333 MHZ */
> +};
> +#endif
> +
> +static struct
> + cpufreq_frequency_table spear_freq_tbl[ARRAY_SIZE(spear_cpu_freq) + 1];
> +static struct clk *cpu_clk;
> +
> +int spear_cpufreq_verify(struct cpufreq_policy *policy)
> +{
> + return cpufreq_frequency_table_verify(policy, spear_freq_tbl);
> +}
> +
> +unsigned int spear_cpufreq_get(unsigned int cpu)
> +{
> + unsigned long rate;
> +
> + if (cpu)
> + return 0;
> +
> + rate = clk_get_rate(cpu_clk) / 1000;
> + return rate;
> +}
Can this be simplified to:
unsigned int spear_cpufreq_get(unsigned int cpu)
{
return cpu ? 0 : clk_get_rate(cpu_clk) / 1000;
}
? It could also be made static.
> +
> +static int spear_cpufreq_target(struct cpufreq_policy *policy,
> + unsigned int target_freq, unsigned int relation)
> +{
> + struct cpufreq_freqs freqs;
> + int ret = 0;
> + int index;
> +
> + if (policy->cpu != 0)
> + return -EINVAL;
> +
> + if (cpufreq_frequency_table_target(policy, spear_freq_tbl,
> + target_freq, relation, &index))
> + return -EINVAL;
> +
> + freqs.old = spear_cpufreq_get(0);
> + freqs.new = spear_cpu_freq[index];
> + freqs.cpu = policy->cpu;
> +
> + if (freqs.old == target_freq)
> + return 0;
> +
> + cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
> + ret = clk_set_rate(cpu_clk, freqs.new * 1000);
> + cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
If clk_set_rate() failed then do you need to do freqs.new =
clk_get_rate(cpu_clk) before doing the CPUFREQ_POSTCHANGE to make sure you
don't notify the wrong frequency?
> +
> + return ret;
> +}
> +
> +static int spear_cpufreq_init(struct cpufreq_policy *policy)
> +{
> + int result;
> + int i = 0;
> +
> + if (policy->cpu != 0)
> + return -EINVAL;
> +
> + cpu_clk = clk_get(NULL, CPU_CLK);
> + if (IS_ERR(cpu_clk))
> + return PTR_ERR(cpu_clk);
> +
> + policy->cpuinfo.min_freq = MIN_CPU_FREQ;
> + policy->cpuinfo.max_freq = MAX_CPU_FREQ;
> + policy->cur = policy->min = policy->max = spear_cpufreq_get(0);
> +
> + for (i = 0; i < ARRAY_SIZE(spear_cpu_freq); i++) {
> + spear_freq_tbl[i].index = i;
> + spear_freq_tbl[i].frequency = spear_cpu_freq[i];
> + }
> +
> + spear_freq_tbl[i].index = i;
> + spear_freq_tbl[i].frequency = CPUFREQ_TABLE_END;
> + result = cpufreq_frequency_table_cpuinfo(policy, spear_freq_tbl);
> + if (!result)
> + cpufreq_frequency_table_get_attr(spear_freq_tbl,
> + policy->cpu);
result doesn't appear to be used to do anything other than check the return of
cpufreq_frequency_table_cpuinfo() so could tou just eliminate that local
variable?
> +
> + policy->cpuinfo.transition_latency = 300*1000; /*250 uS*/
The comment doesn't appear to match the value here.
> +
> + return 0;
> +}
> +
> +static int spear_cpufreq_exit(struct cpufreq_policy *policy)
> +{
> + clk_put(cpu_clk);
> + return 0;
> +}
> +
> +static struct freq_attr *spear_cpufreq_attr[] = {
> + &cpufreq_freq_attr_scaling_available_freqs,
> + NULL,
> +};
> +
> +static struct cpufreq_driver spear_driver = {
> + .flags = CPUFREQ_STICKY,
> + .verify = spear_cpufreq_verify,
> + .target = spear_cpufreq_target,
> + .get = spear_cpufreq_get,
> + .init = spear_cpufreq_init,
> + .exit = spear_cpufreq_exit,
> + .name = "spear_cpufreq",
> + .attr = spear_cpufreq_attr,
> +};
> +
> +static int __init spear_cpufreq_register(void)
> +{
> + return cpufreq_register_driver(&spear_driver);
> +}
> +
> +arch_initcall(spear_cpufreq_register);
Jamie
next prev parent reply other threads:[~2011-01-19 0:20 UTC|newest]
Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-18 7:11 [PATCH V4 00/62] Updating SPEAr Support Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 01/62] spear/vmalloc.h: Appending UL to VMALLOC_END Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 02/62] sp810 Fix: Switch to slow mode before sysctl_soft_reset Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 03/62] ST SPEAr: Padmux code Updated Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 04/62] ST SPEAr: Making clock functions more generic Viresh Kumar
2011-01-18 15:56 ` Russell King - ARM Linux
2011-01-19 4:03 ` viresh kumar
2011-01-18 7:11 ` [PATCH V4 05/62] ST SPEAr: Formalized timer support Viresh Kumar
2011-01-18 23:50 ` Jamie Iles
2011-01-19 3:53 ` viresh kumar
2011-01-18 7:11 ` [PATCH V4 06/62] ST SPEAr13XX: Adding machine specific header files Viresh Kumar
2011-01-18 16:00 ` Russell King - ARM Linux
2011-01-19 4:38 ` viresh kumar
2011-01-19 9:02 ` viresh kumar
2011-01-18 7:11 ` [PATCH V4 07/62] ST SPEAr13XX: Adding machine specific src files Viresh Kumar
2011-01-18 16:06 ` Russell King - ARM Linux
2011-01-19 6:03 ` Shiraz Hashim
2011-01-19 8:52 ` Russell King - ARM Linux
2011-01-19 9:20 ` Shiraz Hashim
2011-01-18 7:11 ` [PATCH V4 08/62] ST SPEAr: Adding support for SPEAr13xx SoC in spear generic plat/ Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 09/62] ST SPEAr13XX: Added compilation support in arch/arm/ Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 10/62] ST SPEAr13xx: Adding default config file Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 11/62] ST SPEAr: Adding support for CLCD on SPEAr3xx/6xx Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 12/62] ST SPEAr: Updating Clock Support Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 13/62] ST SPEAr: Adding Debugfs support on clock framework Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 14/62] ST SPEAr: Correcting SOC Config base address for spear320 Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 15/62] ST SPEAr: Adding PLGPIO driver for spear platform Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 17/62] ST SPEAr: Adding machine support for rtc-spear Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 18/62] ST SPEAr: adding support for synopsis i2c designware Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 19/62] ST SPEAr: Adding machine support for USB host Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 20/62] ST SPEAr: Adding machine support for keyboard Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 21/62] ST SPEAr: Added ARM PL061 GPIO Support on SPEAr13xx and modified resource size Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 22/62] ST SPEAr: Adding support for ST's PWM IP Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 23/62] ST SPEAr: Adding Watchdog support Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 24/62] ST SPEAr: Adding machine support for nand Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 25/62] ST SPEAr: Added PCIE host controller base driver support Viresh Kumar
2011-01-19 0:05 ` Russell King - ARM Linux
2011-01-19 4:17 ` viresh kumar
2011-01-18 7:11 ` [PATCH V4 26/62] ST SPEAr: Adding support for SSP PL022 Viresh Kumar
2011-01-18 16:18 ` Russell King - ARM Linux
2011-01-19 4:16 ` viresh kumar
2011-01-18 7:11 ` [PATCH V4 27/62] ST SPEAr: Adding support for SDHCI (SDIO) Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 28/62] ST SPEAr: Changing resource size of amba devices to SZ_4K Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 29/62] ST SPEAr: Replacing SIZE macro's with actual required size Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 30/62] SPEAr: defines base addresses as ulong Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 31/62] ST SPEAr: Adding miscellaneous devices Viresh Kumar
2011-01-18 7:11 ` [PATCH V4 32/62] ST SPEAr 13xx : Adding support for SPEAr1310 Viresh Kumar
2011-01-19 0:09 ` Jamie Iles
2011-01-19 4:39 ` viresh kumar
2011-01-19 6:40 ` viresh kumar
2011-01-19 8:29 ` Jamie Iles
2011-01-18 7:12 ` [PATCH V4 33/62] SPEAr320: Adding support for CAN Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 34/62] ST SPEAr: Adding support for DDR in clock framework Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 35/62] ST SPEAr : EMI (Extrenal Memory Interface) controller driver Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 36/62] SPEAr Clock Framework: Adding support for PLL frequency change Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 37/62] SPEAr Power Management: Added the support for Standby mode Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 38/62] SPEAr CPU freq: Adding support for CPU Freq framework Viresh Kumar
2011-01-19 0:20 ` Jamie Iles [this message]
2011-01-19 2:13 ` deepaksi
2011-01-19 8:35 ` Jamie Iles
2011-01-19 9:00 ` Shiraz Hashim
2011-01-19 9:39 ` Shiraz Hashim
2011-01-19 9:53 ` Russell King - ARM Linux
2011-01-19 11:14 ` viresh kumar
2011-01-18 7:12 ` [PATCH V4 39/62] ST SPEAr13xx: Adding CPU hotplug support added for SMP platforms Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 40/62] ST SPEAr: replace readl, writel with readl_relaxed, writel_relaxed in uncompress.h Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 41/62] ST SPEAr13xx: add L2 cache support Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 42/62] ST SPEAr13xx: Modified static mappings Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 43/62] SPEAr1310: Adding Static Mapping for RAS Area Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 44/62] SPEAr: Adding and Updating Clock definitions Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 45/62] SPEAr : Pad multiplexing handling modified Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 46/62] SPEAr13xx : Fixed part devices in SPEAr13xx addded to the generic implementation Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 47/62] SPEAr : Updating pad multiplexing support Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 48/62] ST SPEAr3xx: Passing pmx devices address from machine *.c files Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 49/62] ST SPEAr Clock Framework: Updating for single image solution Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 50/62] SPEAr3xx: Make local structures static Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 51/62] SPEAR3xx: Rename register/irq defines to remove naming conflicts Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 52/62] SPEAr3xx: Rework pmx_dev code to remove conflicts Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 53/62] SPEAr3xx: Rework KConfig to allow all boards to be compiled in Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 54/62] SPEAr3xx: Replace defconfigs with single unified defconfig Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 55/62] ST SPEAr: Appending spear3** with global structures Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 56/62] ST SPEAr3xx: Updating plgpio and emi source to make it compliant with single image strategy Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 57/62] SPEAr6xx: Rework Kconfig for single image solution Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 58/62] ST SPEAR6xx: renaming spear600_defconfig as spear6xx_defconfig Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 59/62] ST SPEAr13xx: Pass default padmux settings as parameter to spear13**_init routine Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 60/62] ST SPEAr: Adding devices & clocks Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 61/62] ST SPEAr: Adding information in Documentation/ and MAINTAINERS Viresh Kumar
2011-01-18 7:12 ` [PATCH V4 62/62] ST SPEAr: Updating defconfigs Viresh Kumar
2011-01-18 15:53 ` [PATCH V4 00/62] Updating SPEAr Support Russell King - ARM Linux
2011-01-19 3:49 ` viresh kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110119002046.GC2209@gallagher \
--to=jamie@jamieiles.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).