2 * Copyright (C) 2001-2002 Deep Blue Solutions Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * CPU support functions
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/cpufreq.h>
14 #include <linux/sched.h>
15 #include <linux/smp.h>
16 #include <linux/init.h>
19 #include <mach/hardware.h>
20 #include <mach/platform.h>
21 #include <asm/mach-types.h>
22 #include <asm/hardware/icst.h>
24 static struct cpufreq_driver integrator_driver;
26 #define CM_ID __io_address(INTEGRATOR_HDR_ID)
27 #define CM_OSC __io_address(INTEGRATOR_HDR_OSC)
28 #define CM_STAT __io_address(INTEGRATOR_HDR_STAT)
29 #define CM_LOCK __io_address(INTEGRATOR_HDR_LOCK)
31 static const struct icst_params lclk_params = {
33 .vco_max = ICST525_VCO_MAX_5V,
34 .vco_min = ICST525_VCO_MIN,
39 .s2div = icst525_s2div,
40 .idx2s = icst525_idx2s,
43 static const struct icst_params cclk_params = {
45 .vco_max = ICST525_VCO_MAX_5V,
46 .vco_min = ICST525_VCO_MIN,
51 .s2div = icst525_s2div,
52 .idx2s = icst525_idx2s,
56 * Validate the speed policy.
58 static int integrator_verify_policy(struct cpufreq_policy *policy)
62 cpufreq_verify_within_cpu_limits(policy);
64 vco = icst_hz_to_vco(&cclk_params, policy->max * 1000);
65 policy->max = icst_hz(&cclk_params, vco) / 1000;
67 vco = icst_hz_to_vco(&cclk_params, policy->min * 1000);
68 policy->min = icst_hz(&cclk_params, vco) / 1000;
70 cpufreq_verify_within_cpu_limits(policy);
75 static int integrator_set_target(struct cpufreq_policy *policy,
76 unsigned int target_freq,
77 unsigned int relation)
79 cpumask_t cpus_allowed;
80 int cpu = policy->cpu;
82 struct cpufreq_freqs freqs;
86 * Save this threads cpus_allowed mask.
88 cpus_allowed = current->cpus_allowed;
91 * Bind to the specified CPU. When this call returns,
92 * we should be running on the right CPU.
94 set_cpus_allowed(current, cpumask_of_cpu(cpu));
95 BUG_ON(cpu != smp_processor_id());
97 /* get current setting */
98 cm_osc = __raw_readl(CM_OSC);
100 if (machine_is_integrator()) {
101 vco.s = (cm_osc >> 8) & 7;
102 } else if (machine_is_cintegrator()) {
105 vco.v = cm_osc & 255;
107 freqs.old = icst_hz(&cclk_params, vco) / 1000;
109 /* icst_hz_to_vco rounds down -- so we need the next
110 * larger freq in case of CPUFREQ_RELATION_L.
112 if (relation == CPUFREQ_RELATION_L)
114 if (target_freq > policy->max)
115 target_freq = policy->max;
116 vco = icst_hz_to_vco(&cclk_params, target_freq * 1000);
117 freqs.new = icst_hz(&cclk_params, vco) / 1000;
119 if (freqs.old == freqs.new) {
120 set_cpus_allowed(current, cpus_allowed);
124 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
126 cm_osc = __raw_readl(CM_OSC);
128 if (machine_is_integrator()) {
129 cm_osc &= 0xfffff800;
130 cm_osc |= vco.s << 8;
131 } else if (machine_is_cintegrator()) {
132 cm_osc &= 0xffffff00;
136 __raw_writel(0xa05f, CM_LOCK);
137 __raw_writel(cm_osc, CM_OSC);
138 __raw_writel(0, CM_LOCK);
141 * Restore the CPUs allowed mask.
143 set_cpus_allowed(current, cpus_allowed);
145 cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
150 static unsigned int integrator_get(unsigned int cpu)
152 cpumask_t cpus_allowed;
153 unsigned int current_freq;
157 cpus_allowed = current->cpus_allowed;
159 set_cpus_allowed(current, cpumask_of_cpu(cpu));
160 BUG_ON(cpu != smp_processor_id());
162 /* detect memory etc. */
163 cm_osc = __raw_readl(CM_OSC);
165 if (machine_is_integrator()) {
166 vco.s = (cm_osc >> 8) & 7;
170 vco.v = cm_osc & 255;
173 current_freq = icst_hz(&cclk_params, vco) / 1000; /* current freq */
175 set_cpus_allowed(current, cpus_allowed);
180 static int integrator_cpufreq_init(struct cpufreq_policy *policy)
183 /* set default policy and cpuinfo */
184 policy->max = policy->cpuinfo.max_freq = 160000;
185 policy->min = policy->cpuinfo.min_freq = 12000;
186 policy->cpuinfo.transition_latency = 1000000; /* 1 ms, assumed */
191 static struct cpufreq_driver integrator_driver = {
192 .verify = integrator_verify_policy,
193 .target = integrator_set_target,
194 .get = integrator_get,
195 .init = integrator_cpufreq_init,
196 .name = "integrator",
199 static int __init integrator_cpu_init(void)
201 return cpufreq_register_driver(&integrator_driver);
204 static void __exit integrator_cpu_exit(void)
206 cpufreq_unregister_driver(&integrator_driver);
209 MODULE_AUTHOR ("Russell M. King");
210 MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs");
211 MODULE_LICENSE ("GPL");
213 module_init(integrator_cpu_init);
214 module_exit(integrator_cpu_exit);