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>
22 #include <mach/hardware.h>
23 #include <mach/platform.h>
24 #include <asm/mach-types.h>
25 #include <asm/hardware/icst525.h>
27 static struct cpufreq_driver integrator_driver
;
29 #define CM_ID IO_ADDRESS(INTEGRATOR_HDR_ID)
30 #define CM_OSC IO_ADDRESS(INTEGRATOR_HDR_OSC)
31 #define CM_STAT IO_ADDRESS(INTEGRATOR_HDR_STAT)
32 #define CM_LOCK IO_ADDRESS(INTEGRATOR_HDR_LOCK)
34 static const struct icst_params lclk_params
= {
36 .vco_max
= ICST525_VCO_MAX_5V
,
37 .vco_min
= ICST525_VCO_MIN
,
42 .s2div
= icst525_s2div
,
43 .idx2s
= icst525_idx2s
,
46 static const struct icst_params cclk_params
= {
48 .vco_max
= ICST525_VCO_MAX_5V
,
49 .vco_min
= ICST525_VCO_MIN
,
54 .s2div
= icst525_s2div
,
55 .idx2s
= icst525_idx2s
,
59 * Validate the speed policy.
61 static int integrator_verify_policy(struct cpufreq_policy
*policy
)
65 cpufreq_verify_within_limits(policy
,
66 policy
->cpuinfo
.min_freq
,
67 policy
->cpuinfo
.max_freq
);
69 vco
= icst525_hz_to_vco(&cclk_params
, policy
->max
* 1000);
70 policy
->max
= icst525_hz(&cclk_params
, vco
) / 1000;
72 vco
= icst525_hz_to_vco(&cclk_params
, policy
->min
* 1000);
73 policy
->min
= icst525_hz(&cclk_params
, vco
) / 1000;
75 cpufreq_verify_within_limits(policy
,
76 policy
->cpuinfo
.min_freq
,
77 policy
->cpuinfo
.max_freq
);
83 static int integrator_set_target(struct cpufreq_policy
*policy
,
84 unsigned int target_freq
,
85 unsigned int relation
)
87 cpumask_t cpus_allowed
;
88 int cpu
= policy
->cpu
;
90 struct cpufreq_freqs freqs
;
94 * Save this threads cpus_allowed mask.
96 cpus_allowed
= current
->cpus_allowed
;
99 * Bind to the specified CPU. When this call returns,
100 * we should be running on the right CPU.
102 set_cpus_allowed(current
, cpumask_of_cpu(cpu
));
103 BUG_ON(cpu
!= smp_processor_id());
105 /* get current setting */
106 cm_osc
= __raw_readl(CM_OSC
);
108 if (machine_is_integrator()) {
109 vco
.s
= (cm_osc
>> 8) & 7;
110 } else if (machine_is_cintegrator()) {
113 vco
.v
= cm_osc
& 255;
115 freqs
.old
= icst525_hz(&cclk_params
, vco
) / 1000;
117 /* icst525_hz_to_vco rounds down -- so we need the next
118 * larger freq in case of CPUFREQ_RELATION_L.
120 if (relation
== CPUFREQ_RELATION_L
)
122 if (target_freq
> policy
->max
)
123 target_freq
= policy
->max
;
124 vco
= icst525_hz_to_vco(&cclk_params
, target_freq
* 1000);
125 freqs
.new = icst525_hz(&cclk_params
, vco
) / 1000;
127 freqs
.cpu
= policy
->cpu
;
129 if (freqs
.old
== freqs
.new) {
130 set_cpus_allowed(current
, cpus_allowed
);
134 cpufreq_notify_transition(&freqs
, CPUFREQ_PRECHANGE
);
136 cm_osc
= __raw_readl(CM_OSC
);
138 if (machine_is_integrator()) {
139 cm_osc
&= 0xfffff800;
140 cm_osc
|= vco
.s
<< 8;
141 } else if (machine_is_cintegrator()) {
142 cm_osc
&= 0xffffff00;
146 __raw_writel(0xa05f, CM_LOCK
);
147 __raw_writel(cm_osc
, CM_OSC
);
148 __raw_writel(0, CM_LOCK
);
151 * Restore the CPUs allowed mask.
153 set_cpus_allowed(current
, cpus_allowed
);
155 cpufreq_notify_transition(&freqs
, CPUFREQ_POSTCHANGE
);
160 static unsigned int integrator_get(unsigned int cpu
)
162 cpumask_t cpus_allowed
;
163 unsigned int current_freq
;
167 cpus_allowed
= current
->cpus_allowed
;
169 set_cpus_allowed(current
, cpumask_of_cpu(cpu
));
170 BUG_ON(cpu
!= smp_processor_id());
172 /* detect memory etc. */
173 cm_osc
= __raw_readl(CM_OSC
);
175 if (machine_is_integrator()) {
176 vco
.s
= (cm_osc
>> 8) & 7;
177 } else if (machine_is_cintegrator()) {
180 vco
.v
= cm_osc
& 255;
183 current_freq
= icst525_hz(&cclk_params
, vco
) / 1000; /* current freq */
185 set_cpus_allowed(current
, cpus_allowed
);
190 static int integrator_cpufreq_init(struct cpufreq_policy
*policy
)
193 /* set default policy and cpuinfo */
194 policy
->cpuinfo
.max_freq
= 160000;
195 policy
->cpuinfo
.min_freq
= 12000;
196 policy
->cpuinfo
.transition_latency
= 1000000; /* 1 ms, assumed */
197 policy
->cur
= policy
->min
= policy
->max
= integrator_get(policy
->cpu
);
202 static struct cpufreq_driver integrator_driver
= {
203 .verify
= integrator_verify_policy
,
204 .target
= integrator_set_target
,
205 .get
= integrator_get
,
206 .init
= integrator_cpufreq_init
,
207 .name
= "integrator",
210 static int __init
integrator_cpu_init(void)
212 return cpufreq_register_driver(&integrator_driver
);
215 static void __exit
integrator_cpu_exit(void)
217 cpufreq_unregister_driver(&integrator_driver
);
220 MODULE_AUTHOR ("Russell M. King");
221 MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs");
222 MODULE_LICENSE ("GPL");
224 module_init(integrator_cpu_init
);
225 module_exit(integrator_cpu_exit
);