Blame view

drivers/cpufreq/integrator-cpufreq.c 5.67 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
   *  Copyright (C) 2001-2002 Deep Blue Solutions Ltd.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
12
13
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   * CPU support functions
   */
  #include <linux/module.h>
  #include <linux/types.h>
  #include <linux/kernel.h>
  #include <linux/cpufreq.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
16
  #include <linux/sched.h>
  #include <linux/smp.h>
  #include <linux/init.h>
fced80c73   Russell King   [ARM] Convert asm...
17
  #include <linux/io.h>
bdac7eacc   Linus Walleij   cpufreq: probe th...
18
19
20
  #include <linux/platform_device.h>
  #include <linux/of.h>
  #include <linux/of_address.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  #include <asm/mach-types.h>
c5a0adb51   Russell King   ARM: ICST: kill d...
23
  #include <asm/hardware/icst.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24

bdac7eacc   Linus Walleij   cpufreq: probe th...
25
26
27
28
  static void __iomem *cm_base;
  /* The cpufreq driver only use the OSC register */
  #define INTEGRATOR_HDR_OSC_OFFSET       0x08
  #define INTEGRATOR_HDR_LOCK_OFFSET      0x14
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29

bdac7eacc   Linus Walleij   cpufreq: probe th...
30
  static struct cpufreq_driver integrator_driver;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31

39c0cb02d   Russell King   ARM: ICST: merge ...
32
  static const struct icst_params lclk_params = {
64fceb1dc   Russell King   ARM: ICST: use Hz...
33
  	.ref		= 24000000,
4de2edbd1   Russell King   ARM: ICST: provid...
34
  	.vco_max	= ICST525_VCO_MAX_5V,
e73a46a3d   Russell King   ARM: ICST: move m...
35
  	.vco_min	= ICST525_VCO_MIN,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
  	.vd_min		= 8,
  	.vd_max		= 132,
  	.rd_min		= 24,
  	.rd_max		= 24,
232eaf7f2   Russell King   ARM: ICST: indire...
40
41
  	.s2div		= icst525_s2div,
  	.idx2s		= icst525_idx2s,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  };
39c0cb02d   Russell King   ARM: ICST: merge ...
43
  static const struct icst_params cclk_params = {
64fceb1dc   Russell King   ARM: ICST: use Hz...
44
  	.ref		= 24000000,
4de2edbd1   Russell King   ARM: ICST: provid...
45
  	.vco_max	= ICST525_VCO_MAX_5V,
e73a46a3d   Russell King   ARM: ICST: move m...
46
  	.vco_min	= ICST525_VCO_MIN,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
49
50
  	.vd_min		= 12,
  	.vd_max		= 160,
  	.rd_min		= 24,
  	.rd_max		= 24,
232eaf7f2   Russell King   ARM: ICST: indire...
51
52
  	.s2div		= icst525_s2div,
  	.idx2s		= icst525_idx2s,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
55
56
57
58
59
  };
  
  /*
   * Validate the speed policy.
   */
  static int integrator_verify_policy(struct cpufreq_policy *policy)
  {
39c0cb02d   Russell King   ARM: ICST: merge ...
60
  	struct icst_vco vco;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61

be49e3465   Viresh Kumar   cpufreq: add new ...
62
  	cpufreq_verify_within_cpu_limits(policy);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63

c5a0adb51   Russell King   ARM: ICST: kill d...
64
65
  	vco = icst_hz_to_vco(&cclk_params, policy->max * 1000);
  	policy->max = icst_hz(&cclk_params, vco) / 1000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66

c5a0adb51   Russell King   ARM: ICST: kill d...
67
68
  	vco = icst_hz_to_vco(&cclk_params, policy->min * 1000);
  	policy->min = icst_hz(&cclk_params, vco) / 1000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69

be49e3465   Viresh Kumar   cpufreq: add new ...
70
  	cpufreq_verify_within_cpu_limits(policy);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
73
74
75
76
77
78
79
80
  	return 0;
  }
  
  
  static int integrator_set_target(struct cpufreq_policy *policy,
  				 unsigned int target_freq,
  				 unsigned int relation)
  {
  	cpumask_t cpus_allowed;
  	int cpu = policy->cpu;
39c0cb02d   Russell King   ARM: ICST: merge ...
81
  	struct icst_vco vco;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
86
87
88
89
90
91
92
93
  	struct cpufreq_freqs freqs;
  	u_int cm_osc;
  
  	/*
  	 * Save this threads cpus_allowed mask.
  	 */
  	cpus_allowed = current->cpus_allowed;
  
  	/*
  	 * Bind to the specified CPU.  When this call returns,
  	 * we should be running on the right CPU.
  	 */
18360d6ed   Himangi Saraogi   cpufreq: integrat...
94
  	set_cpus_allowed_ptr(current, cpumask_of(cpu));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
96
97
  	BUG_ON(cpu != smp_processor_id());
  
  	/* get current setting */
bdac7eacc   Linus Walleij   cpufreq: probe th...
98
  	cm_osc = __raw_readl(cm_base + INTEGRATOR_HDR_OSC_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99

3a5f5b2e3   Cristian Ardelean   cpufreq: integrat...
100
  	if (machine_is_integrator())
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
101
  		vco.s = (cm_osc >> 8) & 7;
3a5f5b2e3   Cristian Ardelean   cpufreq: integrat...
102
  	else if (machine_is_cintegrator())
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
  		vco.s = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
  	vco.v = cm_osc & 255;
  	vco.r = 22;
c5a0adb51   Russell King   ARM: ICST: kill d...
106
  	freqs.old = icst_hz(&cclk_params, vco) / 1000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107

c5a0adb51   Russell King   ARM: ICST: kill d...
108
  	/* icst_hz_to_vco rounds down -- so we need the next
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
111
112
113
114
  	 * larger freq in case of CPUFREQ_RELATION_L.
  	 */
  	if (relation == CPUFREQ_RELATION_L)
  		target_freq += 999;
  	if (target_freq > policy->max)
  		target_freq = policy->max;
c5a0adb51   Russell King   ARM: ICST: kill d...
115
116
  	vco = icst_hz_to_vco(&cclk_params, target_freq * 1000);
  	freqs.new = icst_hz(&cclk_params, vco) / 1000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
  	if (freqs.old == freqs.new) {
18360d6ed   Himangi Saraogi   cpufreq: integrat...
119
  		set_cpus_allowed_ptr(current, &cpus_allowed);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
121
  		return 0;
  	}
8fec051ee   Viresh Kumar   cpufreq: Convert ...
122
  	cpufreq_freq_transition_begin(policy, &freqs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123

bdac7eacc   Linus Walleij   cpufreq: probe th...
124
  	cm_osc = __raw_readl(cm_base + INTEGRATOR_HDR_OSC_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
126
127
128
129
130
131
132
  
  	if (machine_is_integrator()) {
  		cm_osc &= 0xfffff800;
  		cm_osc |= vco.s << 8;
  	} else if (machine_is_cintegrator()) {
  		cm_osc &= 0xffffff00;
  	}
  	cm_osc |= vco.v;
bdac7eacc   Linus Walleij   cpufreq: probe th...
133
134
135
  	__raw_writel(0xa05f, cm_base + INTEGRATOR_HDR_LOCK_OFFSET);
  	__raw_writel(cm_osc, cm_base + INTEGRATOR_HDR_OSC_OFFSET);
  	__raw_writel(0, cm_base + INTEGRATOR_HDR_LOCK_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
137
138
139
  
  	/*
  	 * Restore the CPUs allowed mask.
  	 */
18360d6ed   Himangi Saraogi   cpufreq: integrat...
140
  	set_cpus_allowed_ptr(current, &cpus_allowed);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141

8fec051ee   Viresh Kumar   cpufreq: Convert ...
142
  	cpufreq_freq_transition_end(policy, &freqs, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143
144
145
146
147
148
149
150
151
  
  	return 0;
  }
  
  static unsigned int integrator_get(unsigned int cpu)
  {
  	cpumask_t cpus_allowed;
  	unsigned int current_freq;
  	u_int cm_osc;
39c0cb02d   Russell King   ARM: ICST: merge ...
152
  	struct icst_vco vco;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
154
  
  	cpus_allowed = current->cpus_allowed;
18360d6ed   Himangi Saraogi   cpufreq: integrat...
155
  	set_cpus_allowed_ptr(current, cpumask_of(cpu));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
158
  	BUG_ON(cpu != smp_processor_id());
  
  	/* detect memory etc. */
bdac7eacc   Linus Walleij   cpufreq: probe th...
159
  	cm_osc = __raw_readl(cm_base + INTEGRATOR_HDR_OSC_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160

3a5f5b2e3   Cristian Ardelean   cpufreq: integrat...
161
  	if (machine_is_integrator())
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
  		vco.s = (cm_osc >> 8) & 7;
3a5f5b2e3   Cristian Ardelean   cpufreq: integrat...
163
  	else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
164
  		vco.s = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
166
  	vco.v = cm_osc & 255;
  	vco.r = 22;
c5a0adb51   Russell King   ARM: ICST: kill d...
167
  	current_freq = icst_hz(&cclk_params, vco) / 1000; /* current freq */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168

18360d6ed   Himangi Saraogi   cpufreq: integrat...
169
  	set_cpus_allowed_ptr(current, &cpus_allowed);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
171
172
173
174
175
176
177
  
  	return current_freq;
  }
  
  static int integrator_cpufreq_init(struct cpufreq_policy *policy)
  {
  
  	/* set default policy and cpuinfo */
ab537016e   Viresh Kumar   cpufreq: integrat...
178
179
  	policy->max = policy->cpuinfo.max_freq = 160000;
  	policy->min = policy->cpuinfo.min_freq = 12000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
  	policy->cpuinfo.transition_latency = 1000000; /* 1 ms, assumed */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
181
182
183
184
185
  
  	return 0;
  }
  
  static struct cpufreq_driver integrator_driver = {
ae6b42713   Viresh Kumar   cpufreq: Mark ARM...
186
  	.flags		= CPUFREQ_NEED_INITIAL_FREQ_CHECK,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
188
189
190
191
192
  	.verify		= integrator_verify_policy,
  	.target		= integrator_set_target,
  	.get		= integrator_get,
  	.init		= integrator_cpufreq_init,
  	.name		= "integrator",
  };
bdac7eacc   Linus Walleij   cpufreq: probe th...
193
  static int __init integrator_cpufreq_probe(struct platform_device *pdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
194
  {
bdac7eacc   Linus Walleij   cpufreq: probe th...
195
196
197
  	struct resource *res;
  
  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3a5f5b2e3   Cristian Ardelean   cpufreq: integrat...
198
  	if (!res)
bdac7eacc   Linus Walleij   cpufreq: probe th...
199
200
201
202
203
  		return -ENODEV;
  
  	cm_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
  	if (!cm_base)
  		return -ENODEV;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
204
205
  	return cpufreq_register_driver(&integrator_driver);
  }
d62dbf77f   Arnd Bergmann   cpufreq: integrat...
206
  static int __exit integrator_cpufreq_remove(struct platform_device *pdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
  {
d62dbf77f   Arnd Bergmann   cpufreq: integrat...
208
  	return cpufreq_unregister_driver(&integrator_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
  }
bdac7eacc   Linus Walleij   cpufreq: probe th...
210
211
212
213
214
215
216
217
  static const struct of_device_id integrator_cpufreq_match[] = {
  	{ .compatible = "arm,core-module-integrator"},
  	{ },
  };
  
  static struct platform_driver integrator_cpufreq_driver = {
  	.driver = {
  		.name = "integrator-cpufreq",
bdac7eacc   Linus Walleij   cpufreq: probe th...
218
219
220
221
222
223
224
  		.of_match_table = integrator_cpufreq_match,
  	},
  	.remove = __exit_p(integrator_cpufreq_remove),
  };
  
  module_platform_driver_probe(integrator_cpufreq_driver,
  			     integrator_cpufreq_probe);
3a5f5b2e3   Cristian Ardelean   cpufreq: integrat...
225
226
227
  MODULE_AUTHOR("Russell M. King");
  MODULE_DESCRIPTION("cpufreq driver for ARM Integrator CPUs");
  MODULE_LICENSE("GPL");