blob: 63a3907ce5782d45860fff01fb35cb14f837ffba [file] [log] [blame]
Jaecheol Leea35c50512012-03-10 02:59:22 -08001/*
2 * Copyright (c) 2010-2012 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
4 *
5 * EXYNOS4X12 - CPU frequency scaling support
6 *
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/module.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/cpufreq.h>
19
Kukjin Kimc4aaa292012-12-28 16:29:10 -080020#include "exynos-cpufreq.h"
Jaecheol Leea35c50512012-03-10 02:59:22 -080021
Jaecheol Leea35c50512012-03-10 02:59:22 -080022static struct clk *cpu_clk;
23static struct clk *moutcore;
24static struct clk *mout_mpll;
25static struct clk *mout_apll;
26
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080027static unsigned int exynos4x12_volt_table[] = {
28 1350000, 1287500, 1250000, 1187500, 1137500, 1087500, 1037500,
29 1000000, 987500, 975000, 950000, 925000, 900000, 900000
Jaecheol Leea35c50512012-03-10 02:59:22 -080030};
31
Jaecheol Leea35c50512012-03-10 02:59:22 -080032static struct cpufreq_frequency_table exynos4x12_freq_table[] = {
Viresh Kumar7f4b0462014-03-28 19:11:47 +053033 {CPUFREQ_BOOST_FREQ, L0, 1500 * 1000},
34 {0, L1, 1400 * 1000},
35 {0, L2, 1300 * 1000},
36 {0, L3, 1200 * 1000},
37 {0, L4, 1100 * 1000},
38 {0, L5, 1000 * 1000},
39 {0, L6, 900 * 1000},
40 {0, L7, 800 * 1000},
41 {0, L8, 700 * 1000},
42 {0, L9, 600 * 1000},
43 {0, L10, 500 * 1000},
44 {0, L11, 400 * 1000},
45 {0, L12, 300 * 1000},
46 {0, L13, 200 * 1000},
47 {0, 0, CPUFREQ_TABLE_END},
Jaecheol Leea35c50512012-03-10 02:59:22 -080048};
49
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080050static struct apll_freq *apll_freq_4x12;
Jaecheol Leea35c50512012-03-10 02:59:22 -080051
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080052static struct apll_freq apll_freq_4212[] = {
Jaecheol Leea35c50512012-03-10 02:59:22 -080053 /*
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080054 * values:
55 * freq
56 * clock divider for CORE, COREM0, COREM1, PERIPH, ATB, PCLK_DBG, APLL, CORE2
57 * clock divider for COPY, HPM, RESERVED
58 * PLL M, P, S
Jaecheol Leea35c50512012-03-10 02:59:22 -080059 */
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080060 APLL_FREQ(1500, 0, 3, 7, 0, 6, 1, 2, 0, 6, 2, 0, 250, 4, 0),
61 APLL_FREQ(1400, 0, 3, 7, 0, 6, 1, 2, 0, 6, 2, 0, 175, 3, 0),
62 APLL_FREQ(1300, 0, 3, 7, 0, 5, 1, 2, 0, 5, 2, 0, 325, 6, 0),
63 APLL_FREQ(1200, 0, 3, 7, 0, 5, 1, 2, 0, 5, 2, 0, 200, 4, 0),
64 APLL_FREQ(1100, 0, 3, 6, 0, 4, 1, 2, 0, 4, 2, 0, 275, 6, 0),
65 APLL_FREQ(1000, 0, 2, 5, 0, 4, 1, 1, 0, 4, 2, 0, 125, 3, 0),
66 APLL_FREQ(900, 0, 2, 5, 0, 3, 1, 1, 0, 3, 2, 0, 150, 4, 0),
67 APLL_FREQ(800, 0, 2, 5, 0, 3, 1, 1, 0, 3, 2, 0, 100, 3, 0),
68 APLL_FREQ(700, 0, 2, 4, 0, 3, 1, 1, 0, 3, 2, 0, 175, 3, 1),
69 APLL_FREQ(600, 0, 2, 4, 0, 3, 1, 1, 0, 3, 2, 0, 200, 4, 1),
70 APLL_FREQ(500, 0, 2, 4, 0, 3, 1, 1, 0, 3, 2, 0, 125, 3, 1),
71 APLL_FREQ(400, 0, 2, 4, 0, 3, 1, 1, 0, 3, 2, 0, 100, 3, 1),
72 APLL_FREQ(300, 0, 2, 4, 0, 2, 1, 1, 0, 3, 2, 0, 200, 4, 2),
73 APLL_FREQ(200, 0, 1, 3, 0, 1, 1, 1, 0, 3, 2, 0, 100, 3, 2),
Jaecheol Leea35c50512012-03-10 02:59:22 -080074};
75
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080076static struct apll_freq apll_freq_4412[] = {
Jaecheol Leea35c50512012-03-10 02:59:22 -080077 /*
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080078 * values:
79 * freq
80 * clock divider for CORE, COREM0, COREM1, PERIPH, ATB, PCLK_DBG, APLL, CORE2
81 * clock divider for COPY, HPM, CORES
82 * PLL M, P, S
Jaecheol Leea35c50512012-03-10 02:59:22 -080083 */
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080084 APLL_FREQ(1500, 0, 3, 7, 0, 6, 1, 2, 0, 6, 0, 7, 250, 4, 0),
85 APLL_FREQ(1400, 0, 3, 7, 0, 6, 1, 2, 0, 6, 0, 6, 175, 3, 0),
86 APLL_FREQ(1300, 0, 3, 7, 0, 5, 1, 2, 0, 5, 0, 6, 325, 6, 0),
87 APLL_FREQ(1200, 0, 3, 7, 0, 5, 1, 2, 0, 5, 0, 5, 200, 4, 0),
88 APLL_FREQ(1100, 0, 3, 6, 0, 4, 1, 2, 0, 4, 0, 5, 275, 6, 0),
89 APLL_FREQ(1000, 0, 2, 5, 0, 4, 1, 1, 0, 4, 0, 4, 125, 3, 0),
90 APLL_FREQ(900, 0, 2, 5, 0, 3, 1, 1, 0, 3, 0, 4, 150, 4, 0),
91 APLL_FREQ(800, 0, 2, 5, 0, 3, 1, 1, 0, 3, 0, 3, 100, 3, 0),
92 APLL_FREQ(700, 0, 2, 4, 0, 3, 1, 1, 0, 3, 0, 3, 175, 3, 1),
93 APLL_FREQ(600, 0, 2, 4, 0, 3, 1, 1, 0, 3, 0, 2, 200, 4, 1),
94 APLL_FREQ(500, 0, 2, 4, 0, 3, 1, 1, 0, 3, 0, 2, 125, 3, 1),
95 APLL_FREQ(400, 0, 2, 4, 0, 3, 1, 1, 0, 3, 0, 1, 100, 3, 1),
96 APLL_FREQ(300, 0, 2, 4, 0, 2, 1, 1, 0, 3, 0, 1, 200, 4, 2),
97 APLL_FREQ(200, 0, 1, 3, 0, 1, 1, 1, 0, 3, 0, 0, 100, 3, 2),
Jaecheol Leea35c50512012-03-10 02:59:22 -080098};
99
100static void exynos4x12_set_clkdiv(unsigned int div_index)
101{
102 unsigned int tmp;
Jaecheol Leea35c50512012-03-10 02:59:22 -0800103
104 /* Change Divider - CPU0 */
105
Jonghwan Choi9d0554f2012-12-23 15:57:42 -0800106 tmp = apll_freq_4x12[div_index].clk_div_cpu0;
Jaecheol Leea35c50512012-03-10 02:59:22 -0800107
108 __raw_writel(tmp, EXYNOS4_CLKDIV_CPU);
109
110 while (__raw_readl(EXYNOS4_CLKDIV_STATCPU) & 0x11111111)
111 cpu_relax();
112
113 /* Change Divider - CPU1 */
Jonghwan Choi9d0554f2012-12-23 15:57:42 -0800114 tmp = apll_freq_4x12[div_index].clk_div_cpu1;
Jaecheol Leea35c50512012-03-10 02:59:22 -0800115
116 __raw_writel(tmp, EXYNOS4_CLKDIV_CPU1);
Jaecheol Leea35c50512012-03-10 02:59:22 -0800117
Jonghwan Choibe1f7c82014-05-17 08:19:30 +0900118 do {
Jaecheol Leea35c50512012-03-10 02:59:22 -0800119 cpu_relax();
Jonghwan Choibe1f7c82014-05-17 08:19:30 +0900120 tmp = __raw_readl(EXYNOS4_CLKDIV_STATCPU1);
121 } while (tmp != 0x0);
Jaecheol Leea35c50512012-03-10 02:59:22 -0800122}
123
124static void exynos4x12_set_apll(unsigned int index)
125{
Lukasz Majewskicf467152013-10-09 14:08:42 +0200126 unsigned int tmp, freq = apll_freq_4x12[index].freq;
Jaecheol Leea35c50512012-03-10 02:59:22 -0800127
Lukasz Majewskicf467152013-10-09 14:08:42 +0200128 /* MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
Jaecheol Leea35c50512012-03-10 02:59:22 -0800129 clk_set_parent(moutcore, mout_mpll);
130
131 do {
132 cpu_relax();
133 tmp = (__raw_readl(EXYNOS4_CLKMUX_STATCPU)
134 >> EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT);
135 tmp &= 0x7;
136 } while (tmp != 0x2);
137
Lukasz Majewskicf467152013-10-09 14:08:42 +0200138 clk_set_rate(mout_apll, freq * 1000);
Jaecheol Leea35c50512012-03-10 02:59:22 -0800139
Lukasz Majewskicf467152013-10-09 14:08:42 +0200140 /* MUX_CORE_SEL = APLL */
Jaecheol Leea35c50512012-03-10 02:59:22 -0800141 clk_set_parent(moutcore, mout_apll);
142
143 do {
144 cpu_relax();
145 tmp = __raw_readl(EXYNOS4_CLKMUX_STATCPU);
146 tmp &= EXYNOS4_CLKMUX_STATCPU_MUXCORE_MASK;
147 } while (tmp != (0x1 << EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT));
148}
149
Jaecheol Leea35c50512012-03-10 02:59:22 -0800150static void exynos4x12_set_frequency(unsigned int old_index,
151 unsigned int new_index)
152{
Jaecheol Leea35c50512012-03-10 02:59:22 -0800153 if (old_index > new_index) {
Lukasz Majewskicf467152013-10-09 14:08:42 +0200154 exynos4x12_set_clkdiv(new_index);
155 exynos4x12_set_apll(new_index);
Jaecheol Leea35c50512012-03-10 02:59:22 -0800156 } else if (old_index < new_index) {
Lukasz Majewskicf467152013-10-09 14:08:42 +0200157 exynos4x12_set_apll(new_index);
158 exynos4x12_set_clkdiv(new_index);
Jaecheol Leea35c50512012-03-10 02:59:22 -0800159 }
160}
161
Jaecheol Leea35c50512012-03-10 02:59:22 -0800162int exynos4x12_cpufreq_init(struct exynos_dvfs_info *info)
163{
Jaecheol Leea35c50512012-03-10 02:59:22 -0800164 unsigned long rate;
165
Jaecheol Leea35c50512012-03-10 02:59:22 -0800166 cpu_clk = clk_get(NULL, "armclk");
167 if (IS_ERR(cpu_clk))
168 return PTR_ERR(cpu_clk);
169
170 moutcore = clk_get(NULL, "moutcore");
171 if (IS_ERR(moutcore))
172 goto err_moutcore;
173
174 mout_mpll = clk_get(NULL, "mout_mpll");
175 if (IS_ERR(mout_mpll))
176 goto err_mout_mpll;
177
178 rate = clk_get_rate(mout_mpll) / 1000;
179
180 mout_apll = clk_get(NULL, "mout_apll");
181 if (IS_ERR(mout_apll))
182 goto err_mout_apll;
183
Jonghwan Choibe1f7c82014-05-17 08:19:30 +0900184 if (info->type == EXYNOS_SOC_4212)
Jonghwan Choi9d0554f2012-12-23 15:57:42 -0800185 apll_freq_4x12 = apll_freq_4212;
186 else
187 apll_freq_4x12 = apll_freq_4412;
Jaecheol Leea35c50512012-03-10 02:59:22 -0800188
189 info->mpll_freq_khz = rate;
Jonghwan Choi9d0554f2012-12-23 15:57:42 -0800190 /* 800Mhz */
Jaecheol Leea35c50512012-03-10 02:59:22 -0800191 info->pll_safe_idx = L7;
Jaecheol Leea35c50512012-03-10 02:59:22 -0800192 info->cpu_clk = cpu_clk;
193 info->volt_table = exynos4x12_volt_table;
194 info->freq_table = exynos4x12_freq_table;
195 info->set_freq = exynos4x12_set_frequency;
Jaecheol Leea35c50512012-03-10 02:59:22 -0800196
197 return 0;
198
199err_mout_apll:
200 clk_put(mout_mpll);
201err_mout_mpll:
202 clk_put(moutcore);
203err_moutcore:
204 clk_put(cpu_clk);
205
206 pr_debug("%s: failed initialization\n", __func__);
207 return -EINVAL;
208}