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/slab.h>
17 #include <linux/sched.h>
18 #include <linux/smp.h>
19 #include <linux/init.h>
21 #include <mach/hardware.h>
23 #include <asm/mach-types.h>
24 #include <asm/hardware/icst525.h>
26 static struct cpufreq_driver integrator_driver;
28 #define CM_ID (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_ID_OFFSET)
29 #define CM_OSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_OSC_OFFSET)
30 #define CM_STAT (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_STAT_OFFSET)
31 #define CM_LOCK (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
33 static const struct icst525_params lclk_params = {
42 static const struct icst525_params cclk_params = {
52 * Validate the speed policy.
54 static int integrator_verify_policy(struct cpufreq_policy *policy)
56 struct icst525_vco vco;
58 cpufreq_verify_within_limits(policy,
59 policy->cpuinfo.min_freq,
60 policy->cpuinfo.max_freq);
62 vco = icst525_khz_to_vco(&cclk_params, policy->max);
63 policy->max = icst525_khz(&cclk_params, vco);
65 vco = icst525_khz_to_vco(&cclk_params, policy->min);
66 policy->min = icst525_khz(&cclk_params, vco);
68 cpufreq_verify_within_limits(policy,
69 policy->cpuinfo.min_freq,
70 policy->cpuinfo.max_freq);
76 static int integrator_set_target(struct cpufreq_policy *policy,
77 unsigned int target_freq,
78 unsigned int relation)
80 cpumask_t cpus_allowed;
81 int cpu = policy->cpu;
82 struct icst525_vco vco;
83 struct cpufreq_freqs freqs;
87 * Save this threads cpus_allowed mask.
89 cpus_allowed = current->cpus_allowed;
92 * Bind to the specified CPU. When this call returns,
93 * we should be running on the right CPU.
95 set_cpus_allowed(current, cpumask_of_cpu(cpu));
96 BUG_ON(cpu != smp_processor_id());
98 /* get current setting */
99 cm_osc = __raw_readl(CM_OSC);
101 if (machine_is_integrator()) {
102 vco.s = (cm_osc >> 8) & 7;
103 } else if (machine_is_cintegrator()) {
106 vco.v = cm_osc & 255;
108 freqs.old = icst525_khz(&cclk_params, vco);
110 /* icst525_khz_to_vco rounds down -- so we need the next
111 * larger freq in case of CPUFREQ_RELATION_L.
113 if (relation == CPUFREQ_RELATION_L)
115 if (target_freq > policy->max)
116 target_freq = policy->max;
117 vco = icst525_khz_to_vco(&cclk_params, target_freq);
118 freqs.new = icst525_khz(&cclk_params, vco);
120 freqs.cpu = policy->cpu;
122 if (freqs.old == freqs.new) {
123 set_cpus_allowed(current, cpus_allowed);
127 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
129 cm_osc = __raw_readl(CM_OSC);
131 if (machine_is_integrator()) {
132 cm_osc &= 0xfffff800;
133 cm_osc |= vco.s << 8;
134 } else if (machine_is_cintegrator()) {
135 cm_osc &= 0xffffff00;
139 __raw_writel(0xa05f, CM_LOCK);
140 __raw_writel(cm_osc, CM_OSC);
141 __raw_writel(0, CM_LOCK);
144 * Restore the CPUs allowed mask.
146 set_cpus_allowed(current, cpus_allowed);
148 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
153 static unsigned int integrator_get(unsigned int cpu)
155 cpumask_t cpus_allowed;
156 unsigned int current_freq;
158 struct icst525_vco vco;
160 cpus_allowed = current->cpus_allowed;
162 set_cpus_allowed(current, cpumask_of_cpu(cpu));
163 BUG_ON(cpu != smp_processor_id());
165 /* detect memory etc. */
166 cm_osc = __raw_readl(CM_OSC);
168 if (machine_is_integrator()) {
169 vco.s = (cm_osc >> 8) & 7;
170 } else if (machine_is_cintegrator()) {
173 vco.v = cm_osc & 255;
176 current_freq = icst525_khz(&cclk_params, vco); /* current freq */
178 set_cpus_allowed(current, cpus_allowed);
183 static int integrator_cpufreq_init(struct cpufreq_policy *policy)
186 /* set default policy and cpuinfo */
187 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
188 policy->cpuinfo.max_freq = 160000;
189 policy->cpuinfo.min_freq = 12000;
190 policy->cpuinfo.transition_latency = 1000000; /* 1 ms, assumed */
191 policy->cur = policy->min = policy->max = integrator_get(policy->cpu);
196 static struct cpufreq_driver integrator_driver = {
197 .verify = integrator_verify_policy,
198 .target = integrator_set_target,
199 .get = integrator_get,
200 .init = integrator_cpufreq_init,
201 .name = "integrator",
204 static int __init integrator_cpu_init(void)
206 return cpufreq_register_driver(&integrator_driver);
209 static void __exit integrator_cpu_exit(void)
211 cpufreq_unregister_driver(&integrator_driver);
214 MODULE_AUTHOR ("Russell M. King");
215 MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs");
216 MODULE_LICENSE ("GPL");
218 module_init(integrator_cpu_init);
219 module_exit(integrator_cpu_exit);