blob: ba579e0a5c3fd25b00abbb34ecead6f08578be12 [file] [log] [blame]
Kukjin Kimf7d77072011-06-01 14:18:22 -07001/*
Kukjin Kim7d30e8b2011-02-14 16:33:10 +09002 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
Sunyoung Kangf40f91f2010-09-16 17:59:21 +09003 * http://www.samsung.com
4 *
Kukjin Kim7d30e8b2011-02-14 16:33:10 +09005 * EXYNOS4 - CPU frequency scaling support
Sunyoung Kangf40f91f2010-09-16 17:59:21 +09006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/types.h>
13#include <linux/kernel.h>
14#include <linux/err.h>
15#include <linux/clk.h>
16#include <linux/io.h>
17#include <linux/slab.h>
18#include <linux/regulator/consumer.h>
19#include <linux/cpufreq.h>
MyungJoo Ham0073f532011-08-18 19:45:16 +090020#include <linux/notifier.h>
21#include <linux/suspend.h>
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090022
23#include <mach/map.h>
24#include <mach/regs-clock.h>
25#include <mach/regs-mem.h>
26
27#include <plat/clock.h>
Sangwook Jubf5ce052010-12-22 16:49:32 +090028#include <plat/pm.h>
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090029
30static struct clk *cpu_clk;
31static struct clk *moutcore;
32static struct clk *mout_mpll;
33static struct clk *mout_apll;
34
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090035static struct regulator *arm_regulator;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090036
37static struct cpufreq_freqs freqs;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090038
MyungJoo Ham0073f532011-08-18 19:45:16 +090039static unsigned int locking_frequency;
40static bool frequency_locked;
41static DEFINE_MUTEX(cpufreq_lock);
42
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090043enum cpufreq_level_index {
Jaecheol Leeba9d7802011-12-07 11:43:56 +090044 L0, L1, L2, L3, L4, CPUFREQ_LEVEL_END,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090045};
46
Kukjin Kim7d30e8b2011-02-14 16:33:10 +090047static struct cpufreq_frequency_table exynos4_freq_table[] = {
Jaecheol Leeba9d7802011-12-07 11:43:56 +090048 {L0, 1200*1000},
49 {L1, 1000*1000},
50 {L2, 800*1000},
51 {L3, 500*1000},
52 {L4, 200*1000},
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090053 {0, CPUFREQ_TABLE_END},
54};
55
Sangwook Jubf5ce052010-12-22 16:49:32 +090056static unsigned int clkdiv_cpu0[CPUFREQ_LEVEL_END][7] = {
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090057 /*
58 * Clock divider value for following
59 * { DIVCORE, DIVCOREM0, DIVCOREM1, DIVPERIPH,
60 * DIVATB, DIVPCLK_DBG, DIVAPLL }
61 */
62
Jaecheol Leeba9d7802011-12-07 11:43:56 +090063 /* ARM L0: 1200MHz */
64 { 0, 3, 7, 3, 4, 1, 7 },
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090065
Jaecheol Leeba9d7802011-12-07 11:43:56 +090066 /* ARM L1: 1000MHz */
67 { 0, 3, 7, 3, 4, 1, 7 },
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090068
Jaecheol Leeba9d7802011-12-07 11:43:56 +090069 /* ARM L2: 800MHz */
70 { 0, 3, 7, 3, 3, 1, 7 },
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090071
Jaecheol Leeba9d7802011-12-07 11:43:56 +090072 /* ARM L3: 500MHz */
73 { 0, 3, 7, 3, 3, 1, 7 },
74
75 /* ARM L4: 200MHz */
76 { 0, 1, 3, 1, 3, 1, 0 },
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090077};
78
Sangwook Jubf5ce052010-12-22 16:49:32 +090079static unsigned int clkdiv_cpu1[CPUFREQ_LEVEL_END][2] = {
80 /*
81 * Clock divider value for following
82 * { DIVCOPY, DIVHPM }
83 */
84
Jaecheol Leeba9d7802011-12-07 11:43:56 +090085 /* ARM L0: 1200MHz */
86 { 5, 0 },
87
88 /* ARM L1: 1000MHz */
89 { 4, 0 },
90
91 /* ARM L2: 800MHz */
Sangwook Jubf5ce052010-12-22 16:49:32 +090092 { 3, 0 },
93
Jaecheol Leeba9d7802011-12-07 11:43:56 +090094 /* ARM L3: 500MHz */
Sangwook Jubf5ce052010-12-22 16:49:32 +090095 { 3, 0 },
96
Jaecheol Leeba9d7802011-12-07 11:43:56 +090097 /* ARM L4: 200MHz */
Sangwook Jubf5ce052010-12-22 16:49:32 +090098 { 3, 0 },
99};
100
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900101struct cpufreq_voltage_table {
102 unsigned int index; /* any */
103 unsigned int arm_volt; /* uV */
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900104};
105
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900106static struct cpufreq_voltage_table exynos4_volt_table[CPUFREQ_LEVEL_END] = {
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900107 {
108 .index = L0,
Jaecheol Leeba9d7802011-12-07 11:43:56 +0900109 .arm_volt = 1350000,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900110 }, {
111 .index = L1,
Jaecheol Leeba9d7802011-12-07 11:43:56 +0900112 .arm_volt = 1300000,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900113 }, {
114 .index = L2,
Jaecheol Leeba9d7802011-12-07 11:43:56 +0900115 .arm_volt = 1200000,
Sangwook Jubf5ce052010-12-22 16:49:32 +0900116 }, {
117 .index = L3,
Jaecheol Leeba9d7802011-12-07 11:43:56 +0900118 .arm_volt = 1100000,
119 }, {
120 .index = L4,
121 .arm_volt = 1050000,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900122 },
123};
124
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900125static unsigned int exynos4_apll_pms_table[CPUFREQ_LEVEL_END] = {
Jaecheol Leeba9d7802011-12-07 11:43:56 +0900126 /* APLL FOUT L0: 1200MHz */
127 ((150 << 16) | (3 << 8) | 1),
128
129 /* APLL FOUT L1: 1000MHz */
Sangwook Jubf5ce052010-12-22 16:49:32 +0900130 ((250 << 16) | (6 << 8) | 1),
131
Jaecheol Leeba9d7802011-12-07 11:43:56 +0900132 /* APLL FOUT L2: 800MHz */
Sangwook Jubf5ce052010-12-22 16:49:32 +0900133 ((200 << 16) | (6 << 8) | 1),
134
Jaecheol Leeba9d7802011-12-07 11:43:56 +0900135 /* APLL FOUT L3: 500MHz */
136 ((250 << 16) | (6 << 8) | 2),
Sangwook Jubf5ce052010-12-22 16:49:32 +0900137
Jaecheol Leeba9d7802011-12-07 11:43:56 +0900138 /* APLL FOUT L4: 200MHz */
139 ((200 << 16) | (6 << 8) | 3),
Sangwook Jubf5ce052010-12-22 16:49:32 +0900140};
141
Axel Lin2f0d6f22011-07-08 14:20:44 +0800142static int exynos4_verify_speed(struct cpufreq_policy *policy)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900143{
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900144 return cpufreq_frequency_table_verify(policy, exynos4_freq_table);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900145}
146
Axel Lin2f0d6f22011-07-08 14:20:44 +0800147static unsigned int exynos4_getspeed(unsigned int cpu)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900148{
149 return clk_get_rate(cpu_clk) / 1000;
150}
151
Axel Lin2f0d6f22011-07-08 14:20:44 +0800152static void exynos4_set_clkdiv(unsigned int div_index)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900153{
154 unsigned int tmp;
155
156 /* Change Divider - CPU0 */
157
158 tmp = __raw_readl(S5P_CLKDIV_CPU);
159
160 tmp &= ~(S5P_CLKDIV_CPU0_CORE_MASK | S5P_CLKDIV_CPU0_COREM0_MASK |
161 S5P_CLKDIV_CPU0_COREM1_MASK | S5P_CLKDIV_CPU0_PERIPH_MASK |
162 S5P_CLKDIV_CPU0_ATB_MASK | S5P_CLKDIV_CPU0_PCLKDBG_MASK |
163 S5P_CLKDIV_CPU0_APLL_MASK);
164
165 tmp |= ((clkdiv_cpu0[div_index][0] << S5P_CLKDIV_CPU0_CORE_SHIFT) |
166 (clkdiv_cpu0[div_index][1] << S5P_CLKDIV_CPU0_COREM0_SHIFT) |
167 (clkdiv_cpu0[div_index][2] << S5P_CLKDIV_CPU0_COREM1_SHIFT) |
168 (clkdiv_cpu0[div_index][3] << S5P_CLKDIV_CPU0_PERIPH_SHIFT) |
169 (clkdiv_cpu0[div_index][4] << S5P_CLKDIV_CPU0_ATB_SHIFT) |
170 (clkdiv_cpu0[div_index][5] << S5P_CLKDIV_CPU0_PCLKDBG_SHIFT) |
171 (clkdiv_cpu0[div_index][6] << S5P_CLKDIV_CPU0_APLL_SHIFT));
172
173 __raw_writel(tmp, S5P_CLKDIV_CPU);
174
175 do {
176 tmp = __raw_readl(S5P_CLKDIV_STATCPU);
177 } while (tmp & 0x1111111);
178
Sangwook Jubf5ce052010-12-22 16:49:32 +0900179 /* Change Divider - CPU1 */
180
181 tmp = __raw_readl(S5P_CLKDIV_CPU1);
182
183 tmp &= ~((0x7 << 4) | 0x7);
184
185 tmp |= ((clkdiv_cpu1[div_index][0] << 4) |
186 (clkdiv_cpu1[div_index][1] << 0));
187
188 __raw_writel(tmp, S5P_CLKDIV_CPU1);
189
190 do {
191 tmp = __raw_readl(S5P_CLKDIV_STATCPU1);
192 } while (tmp & 0x11);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900193}
194
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900195static void exynos4_set_apll(unsigned int index)
Sangwook Jubf5ce052010-12-22 16:49:32 +0900196{
197 unsigned int tmp;
198
199 /* 1. MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
200 clk_set_parent(moutcore, mout_mpll);
201
202 do {
203 tmp = (__raw_readl(S5P_CLKMUX_STATCPU)
204 >> S5P_CLKSRC_CPU_MUXCORE_SHIFT);
205 tmp &= 0x7;
206 } while (tmp != 0x2);
207
208 /* 2. Set APLL Lock time */
209 __raw_writel(S5P_APLL_LOCKTIME, S5P_APLL_LOCK);
210
211 /* 3. Change PLL PMS values */
212 tmp = __raw_readl(S5P_APLL_CON0);
213 tmp &= ~((0x3ff << 16) | (0x3f << 8) | (0x7 << 0));
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900214 tmp |= exynos4_apll_pms_table[index];
Sangwook Jubf5ce052010-12-22 16:49:32 +0900215 __raw_writel(tmp, S5P_APLL_CON0);
216
217 /* 4. wait_lock_time */
218 do {
219 tmp = __raw_readl(S5P_APLL_CON0);
220 } while (!(tmp & (0x1 << S5P_APLLCON0_LOCKED_SHIFT)));
221
222 /* 5. MUX_CORE_SEL = APLL */
223 clk_set_parent(moutcore, mout_apll);
224
225 do {
226 tmp = __raw_readl(S5P_CLKMUX_STATCPU);
227 tmp &= S5P_CLKMUX_STATCPU_MUXCORE_MASK;
228 } while (tmp != (0x1 << S5P_CLKSRC_CPU_MUXCORE_SHIFT));
229}
230
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900231static void exynos4_set_frequency(unsigned int old_index, unsigned int new_index)
Sangwook Jubf5ce052010-12-22 16:49:32 +0900232{
233 unsigned int tmp;
234
235 if (old_index > new_index) {
236 /* The frequency changing to L0 needs to change apll */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900237 if (freqs.new == exynos4_freq_table[L0].frequency) {
Sangwook Jubf5ce052010-12-22 16:49:32 +0900238 /* 1. Change the system clock divider values */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900239 exynos4_set_clkdiv(new_index);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900240
241 /* 2. Change the apll m,p,s value */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900242 exynos4_set_apll(new_index);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900243 } else {
244 /* 1. Change the system clock divider values */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900245 exynos4_set_clkdiv(new_index);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900246
247 /* 2. Change just s value in apll m,p,s value */
248 tmp = __raw_readl(S5P_APLL_CON0);
249 tmp &= ~(0x7 << 0);
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900250 tmp |= (exynos4_apll_pms_table[new_index] & 0x7);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900251 __raw_writel(tmp, S5P_APLL_CON0);
252 }
253 }
254
255 else if (old_index < new_index) {
256 /* The frequency changing from L0 needs to change apll */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900257 if (freqs.old == exynos4_freq_table[L0].frequency) {
Sangwook Jubf5ce052010-12-22 16:49:32 +0900258 /* 1. Change the apll m,p,s value */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900259 exynos4_set_apll(new_index);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900260
261 /* 2. Change the system clock divider values */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900262 exynos4_set_clkdiv(new_index);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900263 } else {
264 /* 1. Change just s value in apll m,p,s value */
265 tmp = __raw_readl(S5P_APLL_CON0);
266 tmp &= ~(0x7 << 0);
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900267 tmp |= (exynos4_apll_pms_table[new_index] & 0x7);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900268 __raw_writel(tmp, S5P_APLL_CON0);
269
270 /* 2. Change the system clock divider values */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900271 exynos4_set_clkdiv(new_index);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900272 }
273 }
274}
275
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900276static int exynos4_target(struct cpufreq_policy *policy,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900277 unsigned int target_freq,
278 unsigned int relation)
279{
Sangwook Jubf5ce052010-12-22 16:49:32 +0900280 unsigned int index, old_index;
Jaecheol Leec8c430e2011-12-07 11:43:42 +0900281 unsigned int arm_volt;
MyungJoo Ham0073f532011-08-18 19:45:16 +0900282 int err = -EINVAL;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900283
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900284 freqs.old = exynos4_getspeed(policy->cpu);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900285
MyungJoo Ham0073f532011-08-18 19:45:16 +0900286 mutex_lock(&cpufreq_lock);
287
288 if (frequency_locked && target_freq != locking_frequency) {
289 err = -EAGAIN;
290 goto out;
291 }
292
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900293 if (cpufreq_frequency_table_target(policy, exynos4_freq_table,
Sangwook Jubf5ce052010-12-22 16:49:32 +0900294 freqs.old, relation, &old_index))
MyungJoo Ham0073f532011-08-18 19:45:16 +0900295 goto out;
Sangwook Jubf5ce052010-12-22 16:49:32 +0900296
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900297 if (cpufreq_frequency_table_target(policy, exynos4_freq_table,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900298 target_freq, relation, &index))
MyungJoo Ham0073f532011-08-18 19:45:16 +0900299 goto out;
300
301 err = 0;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900302
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900303 freqs.new = exynos4_freq_table[index].frequency;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900304 freqs.cpu = policy->cpu;
305
306 if (freqs.new == freqs.old)
MyungJoo Ham0073f532011-08-18 19:45:16 +0900307 goto out;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900308
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900309 /* get the voltage value */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900310 arm_volt = exynos4_volt_table[index].arm_volt;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900311
312 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
313
314 /* control regulator */
315 if (freqs.new > freqs.old) {
316 /* Voltage up */
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900317 regulator_set_voltage(arm_regulator, arm_volt, arm_volt);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900318 }
319
320 /* Clock Configuration Procedure */
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900321 exynos4_set_frequency(old_index, index);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900322
323 /* control regulator */
324 if (freqs.new < freqs.old) {
325 /* Voltage down */
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900326 regulator_set_voltage(arm_regulator, arm_volt, arm_volt);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900327 }
328
329 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
330
MyungJoo Ham0073f532011-08-18 19:45:16 +0900331out:
332 mutex_unlock(&cpufreq_lock);
333 return err;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900334}
335
336#ifdef CONFIG_PM
MyungJoo Ham0073f532011-08-18 19:45:16 +0900337/*
338 * These suspend/resume are used as syscore_ops, it is already too
339 * late to set regulator voltages at this stage.
340 */
Linus Torvalds411f5c72011-03-17 19:08:06 -0700341static int exynos4_cpufreq_suspend(struct cpufreq_policy *policy)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900342{
343 return 0;
344}
345
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900346static int exynos4_cpufreq_resume(struct cpufreq_policy *policy)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900347{
348 return 0;
349}
350#endif
351
MyungJoo Ham0073f532011-08-18 19:45:16 +0900352/**
353 * exynos4_cpufreq_pm_notifier - block CPUFREQ's activities in suspend-resume
354 * context
355 * @notifier
356 * @pm_event
357 * @v
358 *
359 * While frequency_locked == true, target() ignores every frequency but
360 * locking_frequency. The locking_frequency value is the initial frequency,
361 * which is set by the bootloader. In order to eliminate possible
362 * inconsistency in clock values, we save and restore frequencies during
363 * suspend and resume and block CPUFREQ activities. Note that the standard
364 * suspend/resume cannot be used as they are too deep (syscore_ops) for
365 * regulator actions.
366 */
367static int exynos4_cpufreq_pm_notifier(struct notifier_block *notifier,
368 unsigned long pm_event, void *v)
369{
370 struct cpufreq_policy *policy = cpufreq_cpu_get(0); /* boot CPU */
371 static unsigned int saved_frequency;
372 unsigned int temp;
373
374 mutex_lock(&cpufreq_lock);
375 switch (pm_event) {
376 case PM_SUSPEND_PREPARE:
377 if (frequency_locked)
378 goto out;
379 frequency_locked = true;
380
381 if (locking_frequency) {
382 saved_frequency = exynos4_getspeed(0);
383
384 mutex_unlock(&cpufreq_lock);
385 exynos4_target(policy, locking_frequency,
386 CPUFREQ_RELATION_H);
387 mutex_lock(&cpufreq_lock);
388 }
389
390 break;
391 case PM_POST_SUSPEND:
392
393 if (saved_frequency) {
394 /*
395 * While frequency_locked, only locking_frequency
396 * is valid for target(). In order to use
397 * saved_frequency while keeping frequency_locked,
398 * we temporarly overwrite locking_frequency.
399 */
400 temp = locking_frequency;
401 locking_frequency = saved_frequency;
402
403 mutex_unlock(&cpufreq_lock);
404 exynos4_target(policy, locking_frequency,
405 CPUFREQ_RELATION_H);
406 mutex_lock(&cpufreq_lock);
407
408 locking_frequency = temp;
409 }
410
411 frequency_locked = false;
412 break;
413 }
414out:
415 mutex_unlock(&cpufreq_lock);
416
417 return NOTIFY_OK;
418}
419
420static struct notifier_block exynos4_cpufreq_nb = {
421 .notifier_call = exynos4_cpufreq_pm_notifier,
422};
423
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900424static int exynos4_cpufreq_cpu_init(struct cpufreq_policy *policy)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900425{
Donggeun Kim5beae3b2011-07-19 14:41:57 +0900426 int ret;
427
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900428 policy->cur = policy->min = policy->max = exynos4_getspeed(policy->cpu);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900429
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900430 cpufreq_frequency_table_get_attr(exynos4_freq_table, policy->cpu);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900431
432 /* set the transition latency value */
433 policy->cpuinfo.transition_latency = 100000;
434
435 /*
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900436 * EXYNOS4 multi-core processors has 2 cores
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900437 * that the frequency cannot be set independently.
438 * Each cpu is bound to the same speed.
439 * So the affected cpu is all of the cpus.
440 */
441 cpumask_setall(policy->cpus);
442
Donggeun Kim5beae3b2011-07-19 14:41:57 +0900443 ret = cpufreq_frequency_table_cpuinfo(policy, exynos4_freq_table);
444 if (ret)
445 return ret;
446
447 cpufreq_frequency_table_get_attr(exynos4_freq_table, policy->cpu);
448
449 return 0;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900450}
451
Donggeun Kim5beae3b2011-07-19 14:41:57 +0900452static int exynos4_cpufreq_cpu_exit(struct cpufreq_policy *policy)
453{
454 cpufreq_frequency_table_put_attr(policy->cpu);
455 return 0;
456}
457
458static struct freq_attr *exynos4_cpufreq_attr[] = {
459 &cpufreq_freq_attr_scaling_available_freqs,
460 NULL,
461};
462
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900463static struct cpufreq_driver exynos4_driver = {
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900464 .flags = CPUFREQ_STICKY,
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900465 .verify = exynos4_verify_speed,
466 .target = exynos4_target,
467 .get = exynos4_getspeed,
468 .init = exynos4_cpufreq_cpu_init,
Donggeun Kim5beae3b2011-07-19 14:41:57 +0900469 .exit = exynos4_cpufreq_cpu_exit,
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900470 .name = "exynos4_cpufreq",
Donggeun Kim5beae3b2011-07-19 14:41:57 +0900471 .attr = exynos4_cpufreq_attr,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900472#ifdef CONFIG_PM
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900473 .suspend = exynos4_cpufreq_suspend,
474 .resume = exynos4_cpufreq_resume,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900475#endif
476};
477
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900478static int __init exynos4_cpufreq_init(void)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900479{
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900480 cpu_clk = clk_get(NULL, "armclk");
481 if (IS_ERR(cpu_clk))
482 return PTR_ERR(cpu_clk);
483
MyungJoo Ham0073f532011-08-18 19:45:16 +0900484 locking_frequency = exynos4_getspeed(0);
485
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900486 moutcore = clk_get(NULL, "moutcore");
487 if (IS_ERR(moutcore))
488 goto out;
489
490 mout_mpll = clk_get(NULL, "mout_mpll");
491 if (IS_ERR(mout_mpll))
492 goto out;
493
494 mout_apll = clk_get(NULL, "mout_apll");
495 if (IS_ERR(mout_apll))
496 goto out;
497
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900498 arm_regulator = regulator_get(NULL, "vdd_arm");
499 if (IS_ERR(arm_regulator)) {
500 printk(KERN_ERR "failed to get resource %s\n", "vdd_arm");
501 goto out;
502 }
503
MyungJoo Ham0073f532011-08-18 19:45:16 +0900504 register_pm_notifier(&exynos4_cpufreq_nb);
505
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900506 return cpufreq_register_driver(&exynos4_driver);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900507
508out:
509 if (!IS_ERR(cpu_clk))
510 clk_put(cpu_clk);
511
512 if (!IS_ERR(moutcore))
513 clk_put(moutcore);
514
515 if (!IS_ERR(mout_mpll))
516 clk_put(mout_mpll);
517
518 if (!IS_ERR(mout_apll))
519 clk_put(mout_apll);
520
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900521 if (!IS_ERR(arm_regulator))
522 regulator_put(arm_regulator);
523
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900524 printk(KERN_ERR "%s: failed initialization\n", __func__);
525
526 return -EINVAL;
527}
Kukjin Kim7d30e8b2011-02-14 16:33:10 +0900528late_initcall(exynos4_cpufreq_init);