blob: 6384e5b9a347dab5fefdcb5aa2ad40c0924f5230 [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 *
Jaecheol Leea125a172012-01-07 20:18:35 +09005 * EXYNOS4210 - 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
Jaecheol Lee6c523c62012-01-07 20:18:39 +090012#include <linux/module.h>
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090013#include <linux/kernel.h>
14#include <linux/err.h>
15#include <linux/clk.h>
16#include <linux/io.h>
17#include <linux/slab.h>
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090018#include <linux/cpufreq.h>
19
Kukjin Kimc4aaa292012-12-28 16:29:10 -080020#include "exynos-cpufreq.h"
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090021
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090022static 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 exynos4210_volt_table[] = {
Jaecheol Leea125a172012-01-07 20:18:35 +090028 1250000, 1150000, 1050000, 975000, 950000,
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090029};
30
Jaecheol Leea125a172012-01-07 20:18:35 +090031static struct cpufreq_frequency_table exynos4210_freq_table[] = {
Viresh Kumar7f4b0462014-03-28 19:11:47 +053032 {0, L0, 1200 * 1000},
33 {0, L1, 1000 * 1000},
34 {0, L2, 800 * 1000},
35 {0, L3, 500 * 1000},
36 {0, L4, 200 * 1000},
37 {0, 0, CPUFREQ_TABLE_END},
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090038};
39
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080040static struct apll_freq apll_freq_4210[] = {
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090041 /*
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080042 * values:
43 * freq
44 * clock divider for CORE, COREM0, COREM1, PERIPH, ATB, PCLK_DBG, APLL, RESERVED
45 * clock divider for COPY, HPM, RESERVED
46 * PLL M, P, S
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090047 */
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080048 APLL_FREQ(1200, 0, 3, 7, 3, 4, 1, 7, 0, 5, 0, 0, 150, 3, 1),
49 APLL_FREQ(1000, 0, 3, 7, 3, 4, 1, 7, 0, 4, 0, 0, 250, 6, 1),
50 APLL_FREQ(800, 0, 3, 7, 3, 3, 1, 7, 0, 3, 0, 0, 200, 6, 1),
51 APLL_FREQ(500, 0, 3, 7, 3, 3, 1, 7, 0, 3, 0, 0, 250, 6, 2),
52 APLL_FREQ(200, 0, 1, 3, 1, 3, 1, 0, 0, 3, 0, 0, 200, 6, 3),
Sangwook Jubf5ce052010-12-22 16:49:32 +090053};
54
Jaecheol Leea125a172012-01-07 20:18:35 +090055static void exynos4210_set_clkdiv(unsigned int div_index)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090056{
57 unsigned int tmp;
58
59 /* Change Divider - CPU0 */
60
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080061 tmp = apll_freq_4210[div_index].clk_div_cpu0;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090062
Kukjin Kim09cee1a2012-01-31 13:49:24 +090063 __raw_writel(tmp, EXYNOS4_CLKDIV_CPU);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090064
65 do {
Kukjin Kim09cee1a2012-01-31 13:49:24 +090066 tmp = __raw_readl(EXYNOS4_CLKDIV_STATCPU);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090067 } while (tmp & 0x1111111);
68
Sangwook Jubf5ce052010-12-22 16:49:32 +090069 /* Change Divider - CPU1 */
70
Jonghwan Choi9d0554f2012-12-23 15:57:42 -080071 tmp = apll_freq_4210[div_index].clk_div_cpu1;
Sangwook Jubf5ce052010-12-22 16:49:32 +090072
Kukjin Kim09cee1a2012-01-31 13:49:24 +090073 __raw_writel(tmp, EXYNOS4_CLKDIV_CPU1);
Sangwook Jubf5ce052010-12-22 16:49:32 +090074
75 do {
Kukjin Kim09cee1a2012-01-31 13:49:24 +090076 tmp = __raw_readl(EXYNOS4_CLKDIV_STATCPU1);
Sangwook Jubf5ce052010-12-22 16:49:32 +090077 } while (tmp & 0x11);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +090078}
79
Jaecheol Leea125a172012-01-07 20:18:35 +090080static void exynos4210_set_apll(unsigned int index)
Sangwook Jubf5ce052010-12-22 16:49:32 +090081{
Lukasz Majewski7ad65d52013-10-09 14:08:43 +020082 unsigned int tmp, freq = apll_freq_4210[index].freq;
Sangwook Jubf5ce052010-12-22 16:49:32 +090083
Lukasz Majewski7ad65d52013-10-09 14:08:43 +020084 /* MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
Sangwook Jubf5ce052010-12-22 16:49:32 +090085 clk_set_parent(moutcore, mout_mpll);
86
87 do {
Kukjin Kim09cee1a2012-01-31 13:49:24 +090088 tmp = (__raw_readl(EXYNOS4_CLKMUX_STATCPU)
89 >> EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT);
Sangwook Jubf5ce052010-12-22 16:49:32 +090090 tmp &= 0x7;
91 } while (tmp != 0x2);
92
Lukasz Majewski7ad65d52013-10-09 14:08:43 +020093 clk_set_rate(mout_apll, freq * 1000);
Sangwook Jubf5ce052010-12-22 16:49:32 +090094
Lukasz Majewski7ad65d52013-10-09 14:08:43 +020095 /* MUX_CORE_SEL = APLL */
Sangwook Jubf5ce052010-12-22 16:49:32 +090096 clk_set_parent(moutcore, mout_apll);
97
98 do {
Kukjin Kim09cee1a2012-01-31 13:49:24 +090099 tmp = __raw_readl(EXYNOS4_CLKMUX_STATCPU);
100 tmp &= EXYNOS4_CLKMUX_STATCPU_MUXCORE_MASK;
101 } while (tmp != (0x1 << EXYNOS4_CLKSRC_CPU_MUXCORE_SHIFT));
Sangwook Jubf5ce052010-12-22 16:49:32 +0900102}
103
Jaecheol Leea125a172012-01-07 20:18:35 +0900104static void exynos4210_set_frequency(unsigned int old_index,
105 unsigned int new_index)
Sangwook Jubf5ce052010-12-22 16:49:32 +0900106{
Sangwook Jubf5ce052010-12-22 16:49:32 +0900107 if (old_index > new_index) {
Lukasz Majewski7ad65d52013-10-09 14:08:43 +0200108 exynos4210_set_clkdiv(new_index);
109 exynos4210_set_apll(new_index);
Jaecheol Lee27f805d2011-12-07 11:44:09 +0900110 } else if (old_index < new_index) {
Lukasz Majewski7ad65d52013-10-09 14:08:43 +0200111 exynos4210_set_apll(new_index);
112 exynos4210_set_clkdiv(new_index);
Sangwook Jubf5ce052010-12-22 16:49:32 +0900113 }
114}
115
Jaecheol Leea125a172012-01-07 20:18:35 +0900116int exynos4210_cpufreq_init(struct exynos_dvfs_info *info)
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900117{
Jaecheol Leea125a172012-01-07 20:18:35 +0900118 unsigned long rate;
Jaecheol Lee27f805d2011-12-07 11:44:09 +0900119
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900120 cpu_clk = clk_get(NULL, "armclk");
121 if (IS_ERR(cpu_clk))
122 return PTR_ERR(cpu_clk);
123
124 moutcore = clk_get(NULL, "moutcore");
125 if (IS_ERR(moutcore))
Jaecheol Leea125a172012-01-07 20:18:35 +0900126 goto err_moutcore;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900127
128 mout_mpll = clk_get(NULL, "mout_mpll");
129 if (IS_ERR(mout_mpll))
Jaecheol Leea125a172012-01-07 20:18:35 +0900130 goto err_mout_mpll;
131
132 rate = clk_get_rate(mout_mpll) / 1000;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900133
134 mout_apll = clk_get(NULL, "mout_apll");
135 if (IS_ERR(mout_apll))
Jaecheol Leea125a172012-01-07 20:18:35 +0900136 goto err_mout_apll;
MyungJoo Ham0073f532011-08-18 19:45:16 +0900137
Jaecheol Leea125a172012-01-07 20:18:35 +0900138 info->mpll_freq_khz = rate;
Jonghwan Choi9d0554f2012-12-23 15:57:42 -0800139 /* 800Mhz */
Jaecheol Leea125a172012-01-07 20:18:35 +0900140 info->pll_safe_idx = L2;
Jaecheol Leea125a172012-01-07 20:18:35 +0900141 info->cpu_clk = cpu_clk;
142 info->volt_table = exynos4210_volt_table;
143 info->freq_table = exynos4210_freq_table;
144 info->set_freq = exynos4210_set_frequency;
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900145
Jaecheol Leea125a172012-01-07 20:18:35 +0900146 return 0;
147
148err_mout_apll:
Jonghwan Choi184cddd2012-12-23 15:51:40 -0800149 clk_put(mout_mpll);
Jaecheol Leea125a172012-01-07 20:18:35 +0900150err_mout_mpll:
Jonghwan Choi184cddd2012-12-23 15:51:40 -0800151 clk_put(moutcore);
Jaecheol Leea125a172012-01-07 20:18:35 +0900152err_moutcore:
Jonghwan Choi184cddd2012-12-23 15:51:40 -0800153 clk_put(cpu_clk);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900154
Jaecheol Leea125a172012-01-07 20:18:35 +0900155 pr_debug("%s: failed initialization\n", __func__);
Sunyoung Kangf40f91f2010-09-16 17:59:21 +0900156 return -EINVAL;
157}