avoid endless loops in lib/swiotlb.c
[wrt350n-kernel.git] / arch / arm / mach-integrator / cpu.c
blob71c58bff304c4e2a8484264de7e9bedd1636ed14
1 /*
2 * linux/arch/arm/mach-integrator/cpu.c
4 * Copyright (C) 2001-2002 Deep Blue Solutions Ltd.
6 * $Id: cpu.c,v 1.6 2002/07/18 13:58:51 rmk Exp $
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * CPU support functions
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/cpufreq.h>
18 #include <linux/slab.h>
19 #include <linux/sched.h>
20 #include <linux/smp.h>
21 #include <linux/init.h>
23 #include <asm/hardware.h>
24 #include <asm/io.h>
25 #include <asm/mach-types.h>
26 #include <asm/hardware/icst525.h>
28 static struct cpufreq_driver integrator_driver;
30 #define CM_ID (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_ID_OFFSET)
31 #define CM_OSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_OSC_OFFSET)
32 #define CM_STAT (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_STAT_OFFSET)
33 #define CM_LOCK (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
35 static const struct icst525_params lclk_params = {
36 .ref = 24000,
37 .vco_max = 320000,
38 .vd_min = 8,
39 .vd_max = 132,
40 .rd_min = 24,
41 .rd_max = 24,
44 static const struct icst525_params cclk_params = {
45 .ref = 24000,
46 .vco_max = 320000,
47 .vd_min = 12,
48 .vd_max = 160,
49 .rd_min = 24,
50 .rd_max = 24,
54 * Validate the speed policy.
56 static int integrator_verify_policy(struct cpufreq_policy *policy)
58 struct icst525_vco vco;
60 cpufreq_verify_within_limits(policy,
61 policy->cpuinfo.min_freq,
62 policy->cpuinfo.max_freq);
64 vco = icst525_khz_to_vco(&cclk_params, policy->max);
65 policy->max = icst525_khz(&cclk_params, vco);
67 vco = icst525_khz_to_vco(&cclk_params, policy->min);
68 policy->min = icst525_khz(&cclk_params, vco);
70 cpufreq_verify_within_limits(policy,
71 policy->cpuinfo.min_freq,
72 policy->cpuinfo.max_freq);
74 return 0;
78 static int integrator_set_target(struct cpufreq_policy *policy,
79 unsigned int target_freq,
80 unsigned int relation)
82 cpumask_t cpus_allowed;
83 int cpu = policy->cpu;
84 struct icst525_vco vco;
85 struct cpufreq_freqs freqs;
86 u_int cm_osc;
89 * Save this threads cpus_allowed mask.
91 cpus_allowed = current->cpus_allowed;
94 * Bind to the specified CPU. When this call returns,
95 * we should be running on the right CPU.
97 set_cpus_allowed(current, cpumask_of_cpu(cpu));
98 BUG_ON(cpu != smp_processor_id());
100 /* get current setting */
101 cm_osc = __raw_readl(CM_OSC);
103 if (machine_is_integrator()) {
104 vco.s = (cm_osc >> 8) & 7;
105 } else if (machine_is_cintegrator()) {
106 vco.s = 1;
108 vco.v = cm_osc & 255;
109 vco.r = 22;
110 freqs.old = icst525_khz(&cclk_params, vco);
112 /* icst525_khz_to_vco rounds down -- so we need the next
113 * larger freq in case of CPUFREQ_RELATION_L.
115 if (relation == CPUFREQ_RELATION_L)
116 target_freq += 999;
117 if (target_freq > policy->max)
118 target_freq = policy->max;
119 vco = icst525_khz_to_vco(&cclk_params, target_freq);
120 freqs.new = icst525_khz(&cclk_params, vco);
122 freqs.cpu = policy->cpu;
124 if (freqs.old == freqs.new) {
125 set_cpus_allowed(current, cpus_allowed);
126 return 0;
129 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
131 cm_osc = __raw_readl(CM_OSC);
133 if (machine_is_integrator()) {
134 cm_osc &= 0xfffff800;
135 cm_osc |= vco.s << 8;
136 } else if (machine_is_cintegrator()) {
137 cm_osc &= 0xffffff00;
139 cm_osc |= vco.v;
141 __raw_writel(0xa05f, CM_LOCK);
142 __raw_writel(cm_osc, CM_OSC);
143 __raw_writel(0, CM_LOCK);
146 * Restore the CPUs allowed mask.
148 set_cpus_allowed(current, cpus_allowed);
150 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
152 return 0;
155 static unsigned int integrator_get(unsigned int cpu)
157 cpumask_t cpus_allowed;
158 unsigned int current_freq;
159 u_int cm_osc;
160 struct icst525_vco vco;
162 cpus_allowed = current->cpus_allowed;
164 set_cpus_allowed(current, cpumask_of_cpu(cpu));
165 BUG_ON(cpu != smp_processor_id());
167 /* detect memory etc. */
168 cm_osc = __raw_readl(CM_OSC);
170 if (machine_is_integrator()) {
171 vco.s = (cm_osc >> 8) & 7;
172 } else if (machine_is_cintegrator()) {
173 vco.s = 1;
175 vco.v = cm_osc & 255;
176 vco.r = 22;
178 current_freq = icst525_khz(&cclk_params, vco); /* current freq */
180 set_cpus_allowed(current, cpus_allowed);
182 return current_freq;
185 static int integrator_cpufreq_init(struct cpufreq_policy *policy)
188 /* set default policy and cpuinfo */
189 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
190 policy->cpuinfo.max_freq = 160000;
191 policy->cpuinfo.min_freq = 12000;
192 policy->cpuinfo.transition_latency = 1000000; /* 1 ms, assumed */
193 policy->cur = policy->min = policy->max = integrator_get(policy->cpu);
195 return 0;
198 static struct cpufreq_driver integrator_driver = {
199 .verify = integrator_verify_policy,
200 .target = integrator_set_target,
201 .get = integrator_get,
202 .init = integrator_cpufreq_init,
203 .name = "integrator",
206 static int __init integrator_cpu_init(void)
208 return cpufreq_register_driver(&integrator_driver);
211 static void __exit integrator_cpu_exit(void)
213 cpufreq_unregister_driver(&integrator_driver);
216 MODULE_AUTHOR ("Russell M. King");
217 MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs");
218 MODULE_LICENSE ("GPL");
220 module_init(integrator_cpu_init);
221 module_exit(integrator_cpu_exit);