Staging: comedi: hwdrv_apci2032.c: static sparse fix
[linux/fpc-iii.git] / arch / arm / mach-integrator / cpu.c
blobf77f20255045aed83f8648bf1be2d0afbed5b7a3
1 /*
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>
19 #include <linux/io.h>
21 #include <mach/hardware.h>
22 #include <asm/mach-types.h>
23 #include <asm/hardware/icst525.h>
25 static struct cpufreq_driver integrator_driver;
27 #define CM_ID (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_ID_OFFSET)
28 #define CM_OSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_OSC_OFFSET)
29 #define CM_STAT (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_STAT_OFFSET)
30 #define CM_LOCK (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
32 static const struct icst525_params lclk_params = {
33 .ref = 24000,
34 .vco_max = 320000,
35 .vd_min = 8,
36 .vd_max = 132,
37 .rd_min = 24,
38 .rd_max = 24,
41 static const struct icst525_params cclk_params = {
42 .ref = 24000,
43 .vco_max = 320000,
44 .vd_min = 12,
45 .vd_max = 160,
46 .rd_min = 24,
47 .rd_max = 24,
51 * Validate the speed policy.
53 static int integrator_verify_policy(struct cpufreq_policy *policy)
55 struct icst525_vco vco;
57 cpufreq_verify_within_limits(policy,
58 policy->cpuinfo.min_freq,
59 policy->cpuinfo.max_freq);
61 vco = icst525_khz_to_vco(&cclk_params, policy->max);
62 policy->max = icst525_khz(&cclk_params, vco);
64 vco = icst525_khz_to_vco(&cclk_params, policy->min);
65 policy->min = icst525_khz(&cclk_params, vco);
67 cpufreq_verify_within_limits(policy,
68 policy->cpuinfo.min_freq,
69 policy->cpuinfo.max_freq);
71 return 0;
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;
81 struct icst525_vco vco;
82 struct cpufreq_freqs freqs;
83 u_int cm_osc;
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()) {
103 vco.s = 1;
105 vco.v = cm_osc & 255;
106 vco.r = 22;
107 freqs.old = icst525_khz(&cclk_params, vco);
109 /* icst525_khz_to_vco rounds down -- so we need the next
110 * larger freq in case of CPUFREQ_RELATION_L.
112 if (relation == CPUFREQ_RELATION_L)
113 target_freq += 999;
114 if (target_freq > policy->max)
115 target_freq = policy->max;
116 vco = icst525_khz_to_vco(&cclk_params, target_freq);
117 freqs.new = icst525_khz(&cclk_params, vco);
119 freqs.cpu = policy->cpu;
121 if (freqs.old == freqs.new) {
122 set_cpus_allowed(current, cpus_allowed);
123 return 0;
126 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
128 cm_osc = __raw_readl(CM_OSC);
130 if (machine_is_integrator()) {
131 cm_osc &= 0xfffff800;
132 cm_osc |= vco.s << 8;
133 } else if (machine_is_cintegrator()) {
134 cm_osc &= 0xffffff00;
136 cm_osc |= vco.v;
138 __raw_writel(0xa05f, CM_LOCK);
139 __raw_writel(cm_osc, CM_OSC);
140 __raw_writel(0, CM_LOCK);
143 * Restore the CPUs allowed mask.
145 set_cpus_allowed(current, cpus_allowed);
147 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
149 return 0;
152 static unsigned int integrator_get(unsigned int cpu)
154 cpumask_t cpus_allowed;
155 unsigned int current_freq;
156 u_int cm_osc;
157 struct icst525_vco vco;
159 cpus_allowed = current->cpus_allowed;
161 set_cpus_allowed(current, cpumask_of_cpu(cpu));
162 BUG_ON(cpu != smp_processor_id());
164 /* detect memory etc. */
165 cm_osc = __raw_readl(CM_OSC);
167 if (machine_is_integrator()) {
168 vco.s = (cm_osc >> 8) & 7;
169 } else if (machine_is_cintegrator()) {
170 vco.s = 1;
172 vco.v = cm_osc & 255;
173 vco.r = 22;
175 current_freq = icst525_khz(&cclk_params, vco); /* current freq */
177 set_cpus_allowed(current, cpus_allowed);
179 return current_freq;
182 static int integrator_cpufreq_init(struct cpufreq_policy *policy)
185 /* set default policy and cpuinfo */
186 policy->cpuinfo.max_freq = 160000;
187 policy->cpuinfo.min_freq = 12000;
188 policy->cpuinfo.transition_latency = 1000000; /* 1 ms, assumed */
189 policy->cur = policy->min = policy->max = integrator_get(policy->cpu);
191 return 0;
194 static struct cpufreq_driver integrator_driver = {
195 .verify = integrator_verify_policy,
196 .target = integrator_set_target,
197 .get = integrator_get,
198 .init = integrator_cpufreq_init,
199 .name = "integrator",
202 static int __init integrator_cpu_init(void)
204 return cpufreq_register_driver(&integrator_driver);
207 static void __exit integrator_cpu_exit(void)
209 cpufreq_unregister_driver(&integrator_driver);
212 MODULE_AUTHOR ("Russell M. King");
213 MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs");
214 MODULE_LICENSE ("GPL");
216 module_init(integrator_cpu_init);
217 module_exit(integrator_cpu_exit);