2 * linux/arch/arm/mach-integrator/cpu.c
4 * Copyright (C) 2001-2002 Deep Blue Solutions Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * CPU support functions
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/cpufreq.h>
16 #include <linux/sched.h>
17 #include <linux/smp.h>
18 #include <linux/init.h>
21 #include <mach/hardware.h>
22 #include <mach/platform.h>
23 #include <asm/mach-types.h>
24 #include <asm/hardware/icst.h>
26 static struct cpufreq_driver integrator_driver;
28 #define CM_ID IO_ADDRESS(INTEGRATOR_HDR_ID)
29 #define CM_OSC IO_ADDRESS(INTEGRATOR_HDR_OSC)
30 #define CM_STAT IO_ADDRESS(INTEGRATOR_HDR_STAT)
31 #define CM_LOCK IO_ADDRESS(INTEGRATOR_HDR_LOCK)
33 static const struct icst_params lclk_params = {
35 .vco_max = ICST525_VCO_MAX_5V,
36 .vco_min = ICST525_VCO_MIN,
41 .s2div = icst525_s2div,
42 .idx2s = icst525_idx2s,
45 static const struct icst_params cclk_params = {
47 .vco_max = ICST525_VCO_MAX_5V,
48 .vco_min = ICST525_VCO_MIN,
53 .s2div = icst525_s2div,
54 .idx2s = icst525_idx2s,
58 * Validate the speed policy.
60 static int integrator_verify_policy(struct cpufreq_policy *policy)
64 cpufreq_verify_within_limits(policy,
65 policy->cpuinfo.min_freq,
66 policy->cpuinfo.max_freq);
68 vco = icst_hz_to_vco(&cclk_params, policy->max * 1000);
69 policy->max = icst_hz(&cclk_params, vco) / 1000;
71 vco = icst_hz_to_vco(&cclk_params, policy->min * 1000);
72 policy->min = icst_hz(&cclk_params, vco) / 1000;
74 cpufreq_verify_within_limits(policy,
75 policy->cpuinfo.min_freq,
76 policy->cpuinfo.max_freq);
82 static int integrator_set_target(struct cpufreq_policy *policy,
83 unsigned int target_freq,
84 unsigned int relation)
86 cpumask_t cpus_allowed;
87 int cpu = policy->cpu;
89 struct cpufreq_freqs freqs;
93 * Save this threads cpus_allowed mask.
95 cpus_allowed = current->cpus_allowed;
98 * Bind to the specified CPU. When this call returns,
99 * we should be running on the right CPU.
101 set_cpus_allowed(current, cpumask_of_cpu(cpu));
102 BUG_ON(cpu != smp_processor_id());
104 /* get current setting */
105 cm_osc = __raw_readl(CM_OSC);
107 if (machine_is_integrator()) {
108 vco.s = (cm_osc >> 8) & 7;
109 } else if (machine_is_cintegrator()) {
112 vco.v = cm_osc & 255;
114 freqs.old = icst_hz(&cclk_params, vco) / 1000;
116 /* icst_hz_to_vco rounds down -- so we need the next
117 * larger freq in case of CPUFREQ_RELATION_L.
119 if (relation == CPUFREQ_RELATION_L)
121 if (target_freq > policy->max)
122 target_freq = policy->max;
123 vco = icst_hz_to_vco(&cclk_params, target_freq * 1000);
124 freqs.new = icst_hz(&cclk_params, vco) / 1000;
126 freqs.cpu = policy->cpu;
128 if (freqs.old == freqs.new) {
129 set_cpus_allowed(current, cpus_allowed);
133 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
135 cm_osc = __raw_readl(CM_OSC);
137 if (machine_is_integrator()) {
138 cm_osc &= 0xfffff800;
139 cm_osc |= vco.s << 8;
140 } else if (machine_is_cintegrator()) {
141 cm_osc &= 0xffffff00;
145 __raw_writel(0xa05f, CM_LOCK);
146 __raw_writel(cm_osc, CM_OSC);
147 __raw_writel(0, CM_LOCK);
150 * Restore the CPUs allowed mask.
152 set_cpus_allowed(current, cpus_allowed);
154 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
159 static unsigned int integrator_get(unsigned int cpu)
161 cpumask_t cpus_allowed;
162 unsigned int current_freq;
166 cpus_allowed = current->cpus_allowed;
168 set_cpus_allowed(current, cpumask_of_cpu(cpu));
169 BUG_ON(cpu != smp_processor_id());
171 /* detect memory etc. */
172 cm_osc = __raw_readl(CM_OSC);
174 if (machine_is_integrator()) {
175 vco.s = (cm_osc >> 8) & 7;
179 vco.v = cm_osc & 255;
182 current_freq = icst_hz(&cclk_params, vco) / 1000; /* current freq */
184 set_cpus_allowed(current, cpus_allowed);
189 static int integrator_cpufreq_init(struct cpufreq_policy *policy)
192 /* set default policy and cpuinfo */
193 policy->cpuinfo.max_freq = 160000;
194 policy->cpuinfo.min_freq = 12000;
195 policy->cpuinfo.transition_latency = 1000000; /* 1 ms, assumed */
196 policy->cur = policy->min = policy->max = integrator_get(policy->cpu);
201 static struct cpufreq_driver integrator_driver = {
202 .verify = integrator_verify_policy,
203 .target = integrator_set_target,
204 .get = integrator_get,
205 .init = integrator_cpufreq_init,
206 .name = "integrator",
209 static int __init integrator_cpu_init(void)
211 return cpufreq_register_driver(&integrator_driver);
214 static void __exit integrator_cpu_exit(void)
216 cpufreq_unregister_driver(&integrator_driver);
219 MODULE_AUTHOR ("Russell M. King");
220 MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs");
221 MODULE_LICENSE ("GPL");
223 module_init(integrator_cpu_init);
224 module_exit(integrator_cpu_exit);