Merge branch 'for-linus' of git://git.infradead.org/users/vkoul/slave-dma
[deliverable/linux.git] / drivers / cpufreq / exynos4210-cpufreq.c
CommitLineData
f7d77079 1/*
7d30e8b3 2 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
f40f91fe
SK
3 * http://www.samsung.com
4 *
a125a17f 5 * EXYNOS4210 - CPU frequency scaling support
f40f91fe
SK
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
6c523c61 12#include <linux/module.h>
f40f91fe
SK
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>
f40f91fe 18#include <linux/cpufreq.h>
4c8d8193
TF
19#include <linux/of.h>
20#include <linux/of_address.h>
f40f91fe 21
c4aaa295 22#include "exynos-cpufreq.h"
f40f91fe 23
f40f91fe
SK
24static struct clk *cpu_clk;
25static struct clk *moutcore;
26static struct clk *mout_mpll;
27static struct clk *mout_apll;
4c8d8193 28static struct exynos_dvfs_info *cpufreq;
f40f91fe 29
9d0554ff 30static unsigned int exynos4210_volt_table[] = {
a125a17f 31 1250000, 1150000, 1050000, 975000, 950000,
f40f91fe
SK
32};
33
a125a17f 34static struct cpufreq_frequency_table exynos4210_freq_table[] = {
7f4b0461
VK
35 {0, L0, 1200 * 1000},
36 {0, L1, 1000 * 1000},
37 {0, L2, 800 * 1000},
38 {0, L3, 500 * 1000},
39 {0, L4, 200 * 1000},
40 {0, 0, CPUFREQ_TABLE_END},
f40f91fe
SK
41};
42
9d0554ff 43static struct apll_freq apll_freq_4210[] = {
f40f91fe 44 /*
9d0554ff
JC
45 * values:
46 * freq
47 * clock divider for CORE, COREM0, COREM1, PERIPH, ATB, PCLK_DBG, APLL, RESERVED
48 * clock divider for COPY, HPM, RESERVED
49 * PLL M, P, S
f40f91fe 50 */
9d0554ff
JC
51 APLL_FREQ(1200, 0, 3, 7, 3, 4, 1, 7, 0, 5, 0, 0, 150, 3, 1),
52 APLL_FREQ(1000, 0, 3, 7, 3, 4, 1, 7, 0, 4, 0, 0, 250, 6, 1),
53 APLL_FREQ(800, 0, 3, 7, 3, 3, 1, 7, 0, 3, 0, 0, 200, 6, 1),
54 APLL_FREQ(500, 0, 3, 7, 3, 3, 1, 7, 0, 3, 0, 0, 250, 6, 2),
55 APLL_FREQ(200, 0, 1, 3, 1, 3, 1, 0, 0, 3, 0, 0, 200, 6, 3),
bf5ce054
SJ
56};
57
a125a17f 58static void exynos4210_set_clkdiv(unsigned int div_index)
f40f91fe
SK
59{
60 unsigned int tmp;
61
62 /* Change Divider - CPU0 */
63
9d0554ff 64 tmp = apll_freq_4210[div_index].clk_div_cpu0;
f40f91fe 65
4c8d8193 66 __raw_writel(tmp, cpufreq->cmu_regs + EXYNOS4_CLKDIV_CPU);
f40f91fe
SK
67
68 do {
4c8d8193 69 tmp = __raw_readl(cpufreq->cmu_regs + EXYNOS4_CLKDIV_STATCPU);
f40f91fe
SK
70 } while (tmp & 0x1111111);
71
bf5ce054
SJ
72 /* Change Divider - CPU1 */
73
9d0554ff 74 tmp = apll_freq_4210[div_index].clk_div_cpu1;
bf5ce054 75
4c8d8193 76 __raw_writel(tmp, cpufreq->cmu_regs + EXYNOS4_CLKDIV_CPU1);
bf5ce054
SJ
77
78 do {
4c8d8193 79 tmp = __raw_readl(cpufreq->cmu_regs + EXYNOS4_CLKDIV_STATCPU1);
bf5ce054 80 } while (tmp & 0x11);
f40f91fe
SK
81}
82
a125a17f 83static void exynos4210_set_apll(unsigned int index)
bf5ce054 84{
7ad65d59 85 unsigned int tmp, freq = apll_freq_4210[index].freq;
bf5ce054 86
7ad65d59 87 /* MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
bf5ce054
SJ
88 clk_set_parent(moutcore, mout_mpll);
89
90 do {
4c8d8193 91 tmp = (__raw_readl(cpufreq->cmu_regs + EXYNOS4_CLKMUX_STATCPU)
09cee1ab 92 >> EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT);
bf5ce054
SJ
93 tmp &= 0x7;
94 } while (tmp != 0x2);
95
7ad65d59 96 clk_set_rate(mout_apll, freq * 1000);
bf5ce054 97
7ad65d59 98 /* MUX_CORE_SEL = APLL */
bf5ce054
SJ
99 clk_set_parent(moutcore, mout_apll);
100
101 do {
4c8d8193 102 tmp = __raw_readl(cpufreq->cmu_regs + EXYNOS4_CLKMUX_STATCPU);
09cee1ab
KK
103 tmp &= EXYNOS4_CLKMUX_STATCPU_MUXCORE_MASK;
104 } while (tmp != (0x1 << EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT));
bf5ce054
SJ
105}
106
a125a17f
JL
107static void exynos4210_set_frequency(unsigned int old_index,
108 unsigned int new_index)
bf5ce054 109{
bf5ce054 110 if (old_index > new_index) {
7ad65d59
LM
111 exynos4210_set_clkdiv(new_index);
112 exynos4210_set_apll(new_index);
27f805dc 113 } else if (old_index < new_index) {
7ad65d59
LM
114 exynos4210_set_apll(new_index);
115 exynos4210_set_clkdiv(new_index);
bf5ce054
SJ
116 }
117}
118
a125a17f 119int exynos4210_cpufreq_init(struct exynos_dvfs_info *info)
f40f91fe 120{
4c8d8193 121 struct device_node *np;
a125a17f 122 unsigned long rate;
27f805dc 123
4c8d8193
TF
124 /*
125 * HACK: This is a temporary workaround to get access to clock
126 * controller registers directly and remove static mappings and
127 * dependencies on platform headers. It is necessary to enable
128 * Exynos multi-platform support and will be removed together with
129 * this whole driver as soon as Exynos gets migrated to use
bbcf0719 130 * cpufreq-dt driver.
4c8d8193
TF
131 */
132 np = of_find_compatible_node(NULL, NULL, "samsung,exynos4210-clock");
133 if (!np) {
134 pr_err("%s: failed to find clock controller DT node\n",
135 __func__);
136 return -ENODEV;
137 }
138
139 info->cmu_regs = of_iomap(np, 0);
140 if (!info->cmu_regs) {
141 pr_err("%s: failed to map CMU registers\n", __func__);
142 return -EFAULT;
143 }
144
f40f91fe
SK
145 cpu_clk = clk_get(NULL, "armclk");
146 if (IS_ERR(cpu_clk))
147 return PTR_ERR(cpu_clk);
148
149 moutcore = clk_get(NULL, "moutcore");
150 if (IS_ERR(moutcore))
a125a17f 151 goto err_moutcore;
f40f91fe
SK
152
153 mout_mpll = clk_get(NULL, "mout_mpll");
154 if (IS_ERR(mout_mpll))
a125a17f
JL
155 goto err_mout_mpll;
156
157 rate = clk_get_rate(mout_mpll) / 1000;
f40f91fe
SK
158
159 mout_apll = clk_get(NULL, "mout_apll");
160 if (IS_ERR(mout_apll))
a125a17f 161 goto err_mout_apll;
0073f538 162
a125a17f 163 info->mpll_freq_khz = rate;
9d0554ff 164 /* 800Mhz */
a125a17f 165 info->pll_safe_idx = L2;
a125a17f
JL
166 info->cpu_clk = cpu_clk;
167 info->volt_table = exynos4210_volt_table;
168 info->freq_table = exynos4210_freq_table;
169 info->set_freq = exynos4210_set_frequency;
f40f91fe 170
4c8d8193
TF
171 cpufreq = info;
172
a125a17f 173 return 0;
f40f91fe 174
a125a17f 175err_mout_apll:
184cddd1 176 clk_put(mout_mpll);
a125a17f 177err_mout_mpll:
184cddd1 178 clk_put(moutcore);
a125a17f 179err_moutcore:
184cddd1 180 clk_put(cpu_clk);
f40f91fe 181
a125a17f 182 pr_debug("%s: failed initialization\n", __func__);
f40f91fe
SK
183 return -EINVAL;
184}
This page took 0.213116 seconds and 5 git commands to generate.