xref: /openbmc/linux/drivers/cpufreq/s5pv210-cpufreq.c (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f7d77079SKukjin Kim /*
3f7d77079SKukjin Kim  * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4f7d77079SKukjin Kim  *		http://www.samsung.com
5f7d77079SKukjin Kim  *
6f7d77079SKukjin Kim  * CPU frequency scaling for S5PC110/S5PV210
7f7d77079SKukjin Kim */
8f7d77079SKukjin Kim 
91c5864e2SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
101c5864e2SJoe Perches 
11f7d77079SKukjin Kim #include <linux/types.h>
12f7d77079SKukjin Kim #include <linux/kernel.h>
13f7d77079SKukjin Kim #include <linux/init.h>
14f7d77079SKukjin Kim #include <linux/err.h>
15f7d77079SKukjin Kim #include <linux/clk.h>
16f7d77079SKukjin Kim #include <linux/io.h>
17f7d77079SKukjin Kim #include <linux/cpufreq.h>
186d4ed0f4STomasz Figa #include <linux/of.h>
196d4ed0f4STomasz Figa #include <linux/of_address.h>
206d4ed0f4STomasz Figa #include <linux/platform_device.h>
21fe7f1bcbSHuisung Kang #include <linux/reboot.h>
22e8b4c198SJonghwan Choi #include <linux/regulator/consumer.h>
23f7d77079SKukjin Kim 
246d4ed0f4STomasz Figa static void __iomem *clk_base;
256d4ed0f4STomasz Figa static void __iomem *dmc_base[2];
266d4ed0f4STomasz Figa 
276d4ed0f4STomasz Figa #define S5P_CLKREG(x)		(clk_base + (x))
286d4ed0f4STomasz Figa 
296d4ed0f4STomasz Figa #define S5P_APLL_LOCK		S5P_CLKREG(0x00)
306d4ed0f4STomasz Figa #define S5P_APLL_CON		S5P_CLKREG(0x100)
316d4ed0f4STomasz Figa #define S5P_CLK_SRC0		S5P_CLKREG(0x200)
326d4ed0f4STomasz Figa #define S5P_CLK_SRC2		S5P_CLKREG(0x208)
336d4ed0f4STomasz Figa #define S5P_CLK_DIV0		S5P_CLKREG(0x300)
346d4ed0f4STomasz Figa #define S5P_CLK_DIV2		S5P_CLKREG(0x308)
356d4ed0f4STomasz Figa #define S5P_CLK_DIV6		S5P_CLKREG(0x318)
366d4ed0f4STomasz Figa #define S5P_CLKDIV_STAT0	S5P_CLKREG(0x1000)
376d4ed0f4STomasz Figa #define S5P_CLKDIV_STAT1	S5P_CLKREG(0x1004)
386d4ed0f4STomasz Figa #define S5P_CLKMUX_STAT0	S5P_CLKREG(0x1100)
396d4ed0f4STomasz Figa #define S5P_CLKMUX_STAT1	S5P_CLKREG(0x1104)
406d4ed0f4STomasz Figa 
416d4ed0f4STomasz Figa #define S5P_ARM_MCS_CON		S5P_CLKREG(0x6100)
426d4ed0f4STomasz Figa 
436d4ed0f4STomasz Figa /* CLKSRC0 */
446d4ed0f4STomasz Figa #define S5P_CLKSRC0_MUX200_SHIFT	(16)
456d4ed0f4STomasz Figa #define S5P_CLKSRC0_MUX200_MASK		(0x1 << S5P_CLKSRC0_MUX200_SHIFT)
466d4ed0f4STomasz Figa #define S5P_CLKSRC0_MUX166_MASK		(0x1<<20)
476d4ed0f4STomasz Figa #define S5P_CLKSRC0_MUX133_MASK		(0x1<<24)
486d4ed0f4STomasz Figa 
496d4ed0f4STomasz Figa /* CLKSRC2 */
506d4ed0f4STomasz Figa #define S5P_CLKSRC2_G3D_SHIFT           (0)
516d4ed0f4STomasz Figa #define S5P_CLKSRC2_G3D_MASK            (0x3 << S5P_CLKSRC2_G3D_SHIFT)
526d4ed0f4STomasz Figa #define S5P_CLKSRC2_MFC_SHIFT           (4)
536d4ed0f4STomasz Figa #define S5P_CLKSRC2_MFC_MASK            (0x3 << S5P_CLKSRC2_MFC_SHIFT)
546d4ed0f4STomasz Figa 
556d4ed0f4STomasz Figa /* CLKDIV0 */
566d4ed0f4STomasz Figa #define S5P_CLKDIV0_APLL_SHIFT		(0)
576d4ed0f4STomasz Figa #define S5P_CLKDIV0_APLL_MASK		(0x7 << S5P_CLKDIV0_APLL_SHIFT)
586d4ed0f4STomasz Figa #define S5P_CLKDIV0_A2M_SHIFT		(4)
596d4ed0f4STomasz Figa #define S5P_CLKDIV0_A2M_MASK		(0x7 << S5P_CLKDIV0_A2M_SHIFT)
606d4ed0f4STomasz Figa #define S5P_CLKDIV0_HCLK200_SHIFT	(8)
616d4ed0f4STomasz Figa #define S5P_CLKDIV0_HCLK200_MASK	(0x7 << S5P_CLKDIV0_HCLK200_SHIFT)
626d4ed0f4STomasz Figa #define S5P_CLKDIV0_PCLK100_SHIFT	(12)
636d4ed0f4STomasz Figa #define S5P_CLKDIV0_PCLK100_MASK	(0x7 << S5P_CLKDIV0_PCLK100_SHIFT)
646d4ed0f4STomasz Figa #define S5P_CLKDIV0_HCLK166_SHIFT	(16)
656d4ed0f4STomasz Figa #define S5P_CLKDIV0_HCLK166_MASK	(0xF << S5P_CLKDIV0_HCLK166_SHIFT)
666d4ed0f4STomasz Figa #define S5P_CLKDIV0_PCLK83_SHIFT	(20)
676d4ed0f4STomasz Figa #define S5P_CLKDIV0_PCLK83_MASK		(0x7 << S5P_CLKDIV0_PCLK83_SHIFT)
686d4ed0f4STomasz Figa #define S5P_CLKDIV0_HCLK133_SHIFT	(24)
696d4ed0f4STomasz Figa #define S5P_CLKDIV0_HCLK133_MASK	(0xF << S5P_CLKDIV0_HCLK133_SHIFT)
706d4ed0f4STomasz Figa #define S5P_CLKDIV0_PCLK66_SHIFT	(28)
716d4ed0f4STomasz Figa #define S5P_CLKDIV0_PCLK66_MASK		(0x7 << S5P_CLKDIV0_PCLK66_SHIFT)
726d4ed0f4STomasz Figa 
736d4ed0f4STomasz Figa /* CLKDIV2 */
746d4ed0f4STomasz Figa #define S5P_CLKDIV2_G3D_SHIFT           (0)
756d4ed0f4STomasz Figa #define S5P_CLKDIV2_G3D_MASK            (0xF << S5P_CLKDIV2_G3D_SHIFT)
766d4ed0f4STomasz Figa #define S5P_CLKDIV2_MFC_SHIFT           (4)
776d4ed0f4STomasz Figa #define S5P_CLKDIV2_MFC_MASK            (0xF << S5P_CLKDIV2_MFC_SHIFT)
786d4ed0f4STomasz Figa 
796d4ed0f4STomasz Figa /* CLKDIV6 */
806d4ed0f4STomasz Figa #define S5P_CLKDIV6_ONEDRAM_SHIFT       (28)
816d4ed0f4STomasz Figa #define S5P_CLKDIV6_ONEDRAM_MASK        (0xF << S5P_CLKDIV6_ONEDRAM_SHIFT)
82f7d77079SKukjin Kim 
83f7d77079SKukjin Kim static struct clk *dmc0_clk;
84f7d77079SKukjin Kim static struct clk *dmc1_clk;
855b02b779SArve Hjønnevåg static DEFINE_MUTEX(set_freq_lock);
86f7d77079SKukjin Kim 
87f7d77079SKukjin Kim /* APLL M,P,S values for 1G/800Mhz */
88f7d77079SKukjin Kim #define APLL_VAL_1000	((1 << 31) | (125 << 16) | (3 << 8) | 1)
89f7d77079SKukjin Kim #define APLL_VAL_800	((1 << 31) | (100 << 16) | (3 << 8) | 1)
90f7d77079SKukjin Kim 
91405e6d6dSHuisung Kang /* Use 800MHz when entering sleep mode */
92405e6d6dSHuisung Kang #define SLEEP_FREQ	(800 * 1000)
93405e6d6dSHuisung Kang 
9415aa70a3SBhaskar Chowdhury /* Tracks if CPU frequency can be updated anymore */
9590d5d0a1SHuisung Kang static bool no_cpufreq_access;
9690d5d0a1SHuisung Kang 
9790d5d0a1SHuisung Kang /*
98f7d77079SKukjin Kim  * DRAM configurations to calculate refresh counter for changing
99f7d77079SKukjin Kim  * frequency of memory.
100f7d77079SKukjin Kim  */
101f7d77079SKukjin Kim struct dram_conf {
102f7d77079SKukjin Kim 	unsigned long freq;	/* HZ */
103f7d77079SKukjin Kim 	unsigned long refresh;	/* DRAM refresh counter * 1000 */
104f7d77079SKukjin Kim };
105f7d77079SKukjin Kim 
106f7d77079SKukjin Kim /* DRAM configuration (DMC0 and DMC1) */
107f7d77079SKukjin Kim static struct dram_conf s5pv210_dram_conf[2];
108f7d77079SKukjin Kim 
109f7d77079SKukjin Kim enum perf_level {
110f7d77079SKukjin Kim 	L0, L1, L2, L3, L4,
111f7d77079SKukjin Kim };
112f7d77079SKukjin Kim 
113f7d77079SKukjin Kim enum s5pv210_mem_type {
114f7d77079SKukjin Kim 	LPDDR	= 0x1,
115f7d77079SKukjin Kim 	LPDDR2	= 0x2,
116f7d77079SKukjin Kim 	DDR2	= 0x4,
117f7d77079SKukjin Kim };
118f7d77079SKukjin Kim 
119f7d77079SKukjin Kim enum s5pv210_dmc_port {
120f7d77079SKukjin Kim 	DMC0 = 0,
121f7d77079SKukjin Kim 	DMC1,
122f7d77079SKukjin Kim };
123f7d77079SKukjin Kim 
124f7d77079SKukjin Kim static struct cpufreq_frequency_table s5pv210_freq_table[] = {
1257f4b0461SViresh Kumar 	{0, L0, 1000*1000},
1267f4b0461SViresh Kumar 	{0, L1, 800*1000},
1277f4b0461SViresh Kumar 	{0, L2, 400*1000},
1287f4b0461SViresh Kumar 	{0, L3, 200*1000},
1297f4b0461SViresh Kumar 	{0, L4, 100*1000},
1307f4b0461SViresh Kumar 	{0, 0, CPUFREQ_TABLE_END},
131f7d77079SKukjin Kim };
132f7d77079SKukjin Kim 
133e8b4c198SJonghwan Choi static struct regulator *arm_regulator;
134e8b4c198SJonghwan Choi static struct regulator *int_regulator;
135e8b4c198SJonghwan Choi 
136e8b4c198SJonghwan Choi struct s5pv210_dvs_conf {
137e8b4c198SJonghwan Choi 	int arm_volt;	/* uV */
138e8b4c198SJonghwan Choi 	int int_volt;	/* uV */
139e8b4c198SJonghwan Choi };
140e8b4c198SJonghwan Choi 
141e8b4c198SJonghwan Choi static const int arm_volt_max = 1350000;
142e8b4c198SJonghwan Choi static const int int_volt_max = 1250000;
143e8b4c198SJonghwan Choi 
144e8b4c198SJonghwan Choi static struct s5pv210_dvs_conf dvs_conf[] = {
145e8b4c198SJonghwan Choi 	[L0] = {
146e8b4c198SJonghwan Choi 		.arm_volt	= 1250000,
147e8b4c198SJonghwan Choi 		.int_volt	= 1100000,
148e8b4c198SJonghwan Choi 	},
149e8b4c198SJonghwan Choi 	[L1] = {
150e8b4c198SJonghwan Choi 		.arm_volt	= 1200000,
151e8b4c198SJonghwan Choi 		.int_volt	= 1100000,
152e8b4c198SJonghwan Choi 	},
153e8b4c198SJonghwan Choi 	[L2] = {
154e8b4c198SJonghwan Choi 		.arm_volt	= 1050000,
155e8b4c198SJonghwan Choi 		.int_volt	= 1100000,
156e8b4c198SJonghwan Choi 	},
157e8b4c198SJonghwan Choi 	[L3] = {
158e8b4c198SJonghwan Choi 		.arm_volt	= 950000,
159e8b4c198SJonghwan Choi 		.int_volt	= 1100000,
160e8b4c198SJonghwan Choi 	},
161e8b4c198SJonghwan Choi 	[L4] = {
162e8b4c198SJonghwan Choi 		.arm_volt	= 950000,
163e8b4c198SJonghwan Choi 		.int_volt	= 1000000,
164e8b4c198SJonghwan Choi 	},
165e8b4c198SJonghwan Choi };
166e8b4c198SJonghwan Choi 
167f7d77079SKukjin Kim static u32 clkdiv_val[5][11] = {
168f7d77079SKukjin Kim 	/*
169f7d77079SKukjin Kim 	 * Clock divider value for following
170f7d77079SKukjin Kim 	 * { APLL, A2M, HCLK_MSYS, PCLK_MSYS,
171f7d77079SKukjin Kim 	 *   HCLK_DSYS, PCLK_DSYS, HCLK_PSYS, PCLK_PSYS,
172f7d77079SKukjin Kim 	 *   ONEDRAM, MFC, G3D }
173f7d77079SKukjin Kim 	 */
174f7d77079SKukjin Kim 
175f7d77079SKukjin Kim 	/* L0 : [1000/200/100][166/83][133/66][200/200] */
176f7d77079SKukjin Kim 	{0, 4, 4, 1, 3, 1, 4, 1, 3, 0, 0},
177f7d77079SKukjin Kim 
178f7d77079SKukjin Kim 	/* L1 : [800/200/100][166/83][133/66][200/200] */
179f7d77079SKukjin Kim 	{0, 3, 3, 1, 3, 1, 4, 1, 3, 0, 0},
180f7d77079SKukjin Kim 
181f7d77079SKukjin Kim 	/* L2 : [400/200/100][166/83][133/66][200/200] */
182f7d77079SKukjin Kim 	{1, 3, 1, 1, 3, 1, 4, 1, 3, 0, 0},
183f7d77079SKukjin Kim 
184f7d77079SKukjin Kim 	/* L3 : [200/200/100][166/83][133/66][200/200] */
185f7d77079SKukjin Kim 	{3, 3, 1, 1, 3, 1, 4, 1, 3, 0, 0},
186f7d77079SKukjin Kim 
187f7d77079SKukjin Kim 	/* L4 : [100/100/100][83/83][66/66][100/100] */
188f7d77079SKukjin Kim 	{7, 7, 0, 0, 7, 0, 9, 0, 7, 0, 0},
189f7d77079SKukjin Kim };
190f7d77079SKukjin Kim 
191f7d77079SKukjin Kim /*
192f7d77079SKukjin Kim  * This function set DRAM refresh counter
19315aa70a3SBhaskar Chowdhury  * according to operating frequency of DRAM
194f7d77079SKukjin Kim  * ch: DMC port number 0 or 1
195f7d77079SKukjin Kim  * freq: Operating frequency of DRAM(KHz)
196f7d77079SKukjin Kim  */
s5pv210_set_refresh(enum s5pv210_dmc_port ch,unsigned long freq)197f7d77079SKukjin Kim static void s5pv210_set_refresh(enum s5pv210_dmc_port ch, unsigned long freq)
198f7d77079SKukjin Kim {
199f7d77079SKukjin Kim 	unsigned long tmp, tmp1;
200f7d77079SKukjin Kim 	void __iomem *reg = NULL;
201f7d77079SKukjin Kim 
202f7d77079SKukjin Kim 	if (ch == DMC0) {
2036d4ed0f4STomasz Figa 		reg = (dmc_base[0] + 0x30);
204f7d77079SKukjin Kim 	} else if (ch == DMC1) {
2056d4ed0f4STomasz Figa 		reg = (dmc_base[1] + 0x30);
206f7d77079SKukjin Kim 	} else {
207b49c22a6SJoe Perches 		pr_err("Cannot find DMC port\n");
208f7d77079SKukjin Kim 		return;
209f7d77079SKukjin Kim 	}
210f7d77079SKukjin Kim 
211f7d77079SKukjin Kim 	/* Find current DRAM frequency */
212f7d77079SKukjin Kim 	tmp = s5pv210_dram_conf[ch].freq;
213f7d77079SKukjin Kim 
214d7e53e35SNicolas Pitre 	tmp /= freq;
215f7d77079SKukjin Kim 
216f7d77079SKukjin Kim 	tmp1 = s5pv210_dram_conf[ch].refresh;
217f7d77079SKukjin Kim 
218d7e53e35SNicolas Pitre 	tmp1 /= tmp;
219f7d77079SKukjin Kim 
220187364b6SBen Dooks 	writel_relaxed(tmp1, reg);
221f7d77079SKukjin Kim }
222f7d77079SKukjin Kim 
s5pv210_target(struct cpufreq_policy * policy,unsigned int index)2239c0ebcf7SViresh Kumar static int s5pv210_target(struct cpufreq_policy *policy, unsigned int index)
224f7d77079SKukjin Kim {
225f7d77079SKukjin Kim 	unsigned long reg;
2269c0ebcf7SViresh Kumar 	unsigned int priv_index;
227f7d77079SKukjin Kim 	unsigned int pll_changing = 0;
228f7d77079SKukjin Kim 	unsigned int bus_speed_changing = 0;
229d4019f0aSViresh Kumar 	unsigned int old_freq, new_freq;
230e8b4c198SJonghwan Choi 	int arm_volt, int_volt;
231e8b4c198SJonghwan Choi 	int ret = 0;
232f7d77079SKukjin Kim 
2335b02b779SArve Hjønnevåg 	mutex_lock(&set_freq_lock);
2345b02b779SArve Hjønnevåg 
23590d5d0a1SHuisung Kang 	if (no_cpufreq_access) {
2361ef546f2SPaul Bolle 		pr_err("Denied access to %s as it is disabled temporarily\n",
2371ef546f2SPaul Bolle 		       __func__);
2385b02b779SArve Hjønnevåg 		ret = -EINVAL;
2395b02b779SArve Hjønnevåg 		goto exit;
24090d5d0a1SHuisung Kang 	}
24190d5d0a1SHuisung Kang 
242652ed95dSViresh Kumar 	old_freq = policy->cur;
243d4019f0aSViresh Kumar 	new_freq = s5pv210_freq_table[index].frequency;
244f7d77079SKukjin Kim 
245f7d77079SKukjin Kim 	/* Finding current running level index */
246*1f39fa0dSVincent Donnefort 	priv_index = cpufreq_table_find_index_h(policy, old_freq, false);
247f7d77079SKukjin Kim 
248e8b4c198SJonghwan Choi 	arm_volt = dvs_conf[index].arm_volt;
249e8b4c198SJonghwan Choi 	int_volt = dvs_conf[index].int_volt;
250f7d77079SKukjin Kim 
251d4019f0aSViresh Kumar 	if (new_freq > old_freq) {
252e8b4c198SJonghwan Choi 		ret = regulator_set_voltage(arm_regulator,
253e8b4c198SJonghwan Choi 				arm_volt, arm_volt_max);
254e8b4c198SJonghwan Choi 		if (ret)
2555b02b779SArve Hjønnevåg 			goto exit;
256e8b4c198SJonghwan Choi 
257e8b4c198SJonghwan Choi 		ret = regulator_set_voltage(int_regulator,
258e8b4c198SJonghwan Choi 				int_volt, int_volt_max);
259e8b4c198SJonghwan Choi 		if (ret)
2605b02b779SArve Hjønnevåg 			goto exit;
261f7d77079SKukjin Kim 	}
262f7d77079SKukjin Kim 
263f7d77079SKukjin Kim 	/* Check if there need to change PLL */
264f7d77079SKukjin Kim 	if ((index == L0) || (priv_index == L0))
265f7d77079SKukjin Kim 		pll_changing = 1;
266f7d77079SKukjin Kim 
267f7d77079SKukjin Kim 	/* Check if there need to change System bus clock */
268f7d77079SKukjin Kim 	if ((index == L4) || (priv_index == L4))
269f7d77079SKukjin Kim 		bus_speed_changing = 1;
270f7d77079SKukjin Kim 
271f7d77079SKukjin Kim 	if (bus_speed_changing) {
272f7d77079SKukjin Kim 		/*
273f7d77079SKukjin Kim 		 * Reconfigure DRAM refresh counter value for minimum
274f7d77079SKukjin Kim 		 * temporary clock while changing divider.
275f7d77079SKukjin Kim 		 * expected clock is 83Mhz : 7.8usec/(1/83Mhz) = 0x287
276f7d77079SKukjin Kim 		 */
277f7d77079SKukjin Kim 		if (pll_changing)
278f7d77079SKukjin Kim 			s5pv210_set_refresh(DMC1, 83000);
279f7d77079SKukjin Kim 		else
280f7d77079SKukjin Kim 			s5pv210_set_refresh(DMC1, 100000);
281f7d77079SKukjin Kim 
282f7d77079SKukjin Kim 		s5pv210_set_refresh(DMC0, 83000);
283f7d77079SKukjin Kim 	}
284f7d77079SKukjin Kim 
285f7d77079SKukjin Kim 	/*
286f7d77079SKukjin Kim 	 * APLL should be changed in this level
287f7d77079SKukjin Kim 	 * APLL -> MPLL(for stable transition) -> APLL
288f7d77079SKukjin Kim 	 * Some clock source's clock API are not prepared.
289f7d77079SKukjin Kim 	 * Do not use clock API in below code.
290f7d77079SKukjin Kim 	 */
291f7d77079SKukjin Kim 	if (pll_changing) {
292f7d77079SKukjin Kim 		/*
293f7d77079SKukjin Kim 		 * 1. Temporary Change divider for MFC and G3D
294f7d77079SKukjin Kim 		 * SCLKA2M(200/1=200)->(200/4=50)Mhz
295f7d77079SKukjin Kim 		 */
296187364b6SBen Dooks 		reg = readl_relaxed(S5P_CLK_DIV2);
297f7d77079SKukjin Kim 		reg &= ~(S5P_CLKDIV2_G3D_MASK | S5P_CLKDIV2_MFC_MASK);
298f7d77079SKukjin Kim 		reg |= (3 << S5P_CLKDIV2_G3D_SHIFT) |
299f7d77079SKukjin Kim 			(3 << S5P_CLKDIV2_MFC_SHIFT);
300187364b6SBen Dooks 		writel_relaxed(reg, S5P_CLK_DIV2);
301f7d77079SKukjin Kim 
302f7d77079SKukjin Kim 		/* For MFC, G3D dividing */
303f7d77079SKukjin Kim 		do {
304187364b6SBen Dooks 			reg = readl_relaxed(S5P_CLKDIV_STAT0);
305f7d77079SKukjin Kim 		} while (reg & ((1 << 16) | (1 << 17)));
306f7d77079SKukjin Kim 
307f7d77079SKukjin Kim 		/*
308f7d77079SKukjin Kim 		 * 2. Change SCLKA2M(200Mhz)to SCLKMPLL in MFC_MUX, G3D MUX
309f7d77079SKukjin Kim 		 * (200/4=50)->(667/4=166)Mhz
310f7d77079SKukjin Kim 		 */
311187364b6SBen Dooks 		reg = readl_relaxed(S5P_CLK_SRC2);
312f7d77079SKukjin Kim 		reg &= ~(S5P_CLKSRC2_G3D_MASK | S5P_CLKSRC2_MFC_MASK);
313f7d77079SKukjin Kim 		reg |= (1 << S5P_CLKSRC2_G3D_SHIFT) |
314f7d77079SKukjin Kim 			(1 << S5P_CLKSRC2_MFC_SHIFT);
315187364b6SBen Dooks 		writel_relaxed(reg, S5P_CLK_SRC2);
316f7d77079SKukjin Kim 
317f7d77079SKukjin Kim 		do {
318187364b6SBen Dooks 			reg = readl_relaxed(S5P_CLKMUX_STAT1);
319f7d77079SKukjin Kim 		} while (reg & ((1 << 7) | (1 << 3)));
320f7d77079SKukjin Kim 
321f7d77079SKukjin Kim 		/*
322f7d77079SKukjin Kim 		 * 3. DMC1 refresh count for 133Mhz if (index == L4) is
32315aa70a3SBhaskar Chowdhury 		 * true refresh counter is already programmed in upper
324f7d77079SKukjin Kim 		 * code. 0x287@83Mhz
325f7d77079SKukjin Kim 		 */
326f7d77079SKukjin Kim 		if (!bus_speed_changing)
327f7d77079SKukjin Kim 			s5pv210_set_refresh(DMC1, 133000);
328f7d77079SKukjin Kim 
329f7d77079SKukjin Kim 		/* 4. SCLKAPLL -> SCLKMPLL */
330187364b6SBen Dooks 		reg = readl_relaxed(S5P_CLK_SRC0);
331f7d77079SKukjin Kim 		reg &= ~(S5P_CLKSRC0_MUX200_MASK);
332f7d77079SKukjin Kim 		reg |= (0x1 << S5P_CLKSRC0_MUX200_SHIFT);
333187364b6SBen Dooks 		writel_relaxed(reg, S5P_CLK_SRC0);
334f7d77079SKukjin Kim 
335f7d77079SKukjin Kim 		do {
336187364b6SBen Dooks 			reg = readl_relaxed(S5P_CLKMUX_STAT0);
337f7d77079SKukjin Kim 		} while (reg & (0x1 << 18));
338f7d77079SKukjin Kim 
339f7d77079SKukjin Kim 	}
340f7d77079SKukjin Kim 
341f7d77079SKukjin Kim 	/* Change divider */
342187364b6SBen Dooks 	reg = readl_relaxed(S5P_CLK_DIV0);
343f7d77079SKukjin Kim 
344f7d77079SKukjin Kim 	reg &= ~(S5P_CLKDIV0_APLL_MASK | S5P_CLKDIV0_A2M_MASK |
345f7d77079SKukjin Kim 		S5P_CLKDIV0_HCLK200_MASK | S5P_CLKDIV0_PCLK100_MASK |
346f7d77079SKukjin Kim 		S5P_CLKDIV0_HCLK166_MASK | S5P_CLKDIV0_PCLK83_MASK |
347f7d77079SKukjin Kim 		S5P_CLKDIV0_HCLK133_MASK | S5P_CLKDIV0_PCLK66_MASK);
348f7d77079SKukjin Kim 
349f7d77079SKukjin Kim 	reg |= ((clkdiv_val[index][0] << S5P_CLKDIV0_APLL_SHIFT) |
350f7d77079SKukjin Kim 		(clkdiv_val[index][1] << S5P_CLKDIV0_A2M_SHIFT) |
351f7d77079SKukjin Kim 		(clkdiv_val[index][2] << S5P_CLKDIV0_HCLK200_SHIFT) |
352f7d77079SKukjin Kim 		(clkdiv_val[index][3] << S5P_CLKDIV0_PCLK100_SHIFT) |
353f7d77079SKukjin Kim 		(clkdiv_val[index][4] << S5P_CLKDIV0_HCLK166_SHIFT) |
354f7d77079SKukjin Kim 		(clkdiv_val[index][5] << S5P_CLKDIV0_PCLK83_SHIFT) |
355f7d77079SKukjin Kim 		(clkdiv_val[index][6] << S5P_CLKDIV0_HCLK133_SHIFT) |
356f7d77079SKukjin Kim 		(clkdiv_val[index][7] << S5P_CLKDIV0_PCLK66_SHIFT));
357f7d77079SKukjin Kim 
358187364b6SBen Dooks 	writel_relaxed(reg, S5P_CLK_DIV0);
359f7d77079SKukjin Kim 
360f7d77079SKukjin Kim 	do {
361187364b6SBen Dooks 		reg = readl_relaxed(S5P_CLKDIV_STAT0);
362f7d77079SKukjin Kim 	} while (reg & 0xff);
363f7d77079SKukjin Kim 
364f7d77079SKukjin Kim 	/* ARM MCS value changed */
365187364b6SBen Dooks 	reg = readl_relaxed(S5P_ARM_MCS_CON);
366f7d77079SKukjin Kim 	reg &= ~0x3;
367f7d77079SKukjin Kim 	if (index >= L3)
368f7d77079SKukjin Kim 		reg |= 0x3;
369f7d77079SKukjin Kim 	else
370f7d77079SKukjin Kim 		reg |= 0x1;
371f7d77079SKukjin Kim 
372187364b6SBen Dooks 	writel_relaxed(reg, S5P_ARM_MCS_CON);
373f7d77079SKukjin Kim 
374f7d77079SKukjin Kim 	if (pll_changing) {
375f7d77079SKukjin Kim 		/* 5. Set Lock time = 30us*24Mhz = 0x2cf */
376187364b6SBen Dooks 		writel_relaxed(0x2cf, S5P_APLL_LOCK);
377f7d77079SKukjin Kim 
378f7d77079SKukjin Kim 		/*
379f7d77079SKukjin Kim 		 * 6. Turn on APLL
380f7d77079SKukjin Kim 		 * 6-1. Set PMS values
38115aa70a3SBhaskar Chowdhury 		 * 6-2. Wait until the PLL is locked
382f7d77079SKukjin Kim 		 */
383f7d77079SKukjin Kim 		if (index == L0)
384187364b6SBen Dooks 			writel_relaxed(APLL_VAL_1000, S5P_APLL_CON);
385f7d77079SKukjin Kim 		else
386187364b6SBen Dooks 			writel_relaxed(APLL_VAL_800, S5P_APLL_CON);
387f7d77079SKukjin Kim 
388f7d77079SKukjin Kim 		do {
389187364b6SBen Dooks 			reg = readl_relaxed(S5P_APLL_CON);
390f7d77079SKukjin Kim 		} while (!(reg & (0x1 << 29)));
391f7d77079SKukjin Kim 
392f7d77079SKukjin Kim 		/*
39315aa70a3SBhaskar Chowdhury 		 * 7. Change source clock from SCLKMPLL(667Mhz)
394f7d77079SKukjin Kim 		 * to SCLKA2M(200Mhz) in MFC_MUX and G3D MUX
395f7d77079SKukjin Kim 		 * (667/4=166)->(200/4=50)Mhz
396f7d77079SKukjin Kim 		 */
397187364b6SBen Dooks 		reg = readl_relaxed(S5P_CLK_SRC2);
398f7d77079SKukjin Kim 		reg &= ~(S5P_CLKSRC2_G3D_MASK | S5P_CLKSRC2_MFC_MASK);
399f7d77079SKukjin Kim 		reg |= (0 << S5P_CLKSRC2_G3D_SHIFT) |
400f7d77079SKukjin Kim 			(0 << S5P_CLKSRC2_MFC_SHIFT);
401187364b6SBen Dooks 		writel_relaxed(reg, S5P_CLK_SRC2);
402f7d77079SKukjin Kim 
403f7d77079SKukjin Kim 		do {
404187364b6SBen Dooks 			reg = readl_relaxed(S5P_CLKMUX_STAT1);
405f7d77079SKukjin Kim 		} while (reg & ((1 << 7) | (1 << 3)));
406f7d77079SKukjin Kim 
407f7d77079SKukjin Kim 		/*
408f7d77079SKukjin Kim 		 * 8. Change divider for MFC and G3D
409f7d77079SKukjin Kim 		 * (200/4=50)->(200/1=200)Mhz
410f7d77079SKukjin Kim 		 */
411187364b6SBen Dooks 		reg = readl_relaxed(S5P_CLK_DIV2);
412f7d77079SKukjin Kim 		reg &= ~(S5P_CLKDIV2_G3D_MASK | S5P_CLKDIV2_MFC_MASK);
413f7d77079SKukjin Kim 		reg |= (clkdiv_val[index][10] << S5P_CLKDIV2_G3D_SHIFT) |
414f7d77079SKukjin Kim 			(clkdiv_val[index][9] << S5P_CLKDIV2_MFC_SHIFT);
415187364b6SBen Dooks 		writel_relaxed(reg, S5P_CLK_DIV2);
416f7d77079SKukjin Kim 
417f7d77079SKukjin Kim 		/* For MFC, G3D dividing */
418f7d77079SKukjin Kim 		do {
419187364b6SBen Dooks 			reg = readl_relaxed(S5P_CLKDIV_STAT0);
420f7d77079SKukjin Kim 		} while (reg & ((1 << 16) | (1 << 17)));
421f7d77079SKukjin Kim 
422f7d77079SKukjin Kim 		/* 9. Change MPLL to APLL in MSYS_MUX */
423187364b6SBen Dooks 		reg = readl_relaxed(S5P_CLK_SRC0);
424f7d77079SKukjin Kim 		reg &= ~(S5P_CLKSRC0_MUX200_MASK);
425f7d77079SKukjin Kim 		reg |= (0x0 << S5P_CLKSRC0_MUX200_SHIFT);
426187364b6SBen Dooks 		writel_relaxed(reg, S5P_CLK_SRC0);
427f7d77079SKukjin Kim 
428f7d77079SKukjin Kim 		do {
429187364b6SBen Dooks 			reg = readl_relaxed(S5P_CLKMUX_STAT0);
430f7d77079SKukjin Kim 		} while (reg & (0x1 << 18));
431f7d77079SKukjin Kim 
432f7d77079SKukjin Kim 		/*
433f7d77079SKukjin Kim 		 * 10. DMC1 refresh counter
434f7d77079SKukjin Kim 		 * L4 : DMC1 = 100Mhz 7.8us/(1/100) = 0x30c
435f7d77079SKukjin Kim 		 * Others : DMC1 = 200Mhz 7.8us/(1/200) = 0x618
436f7d77079SKukjin Kim 		 */
437f7d77079SKukjin Kim 		if (!bus_speed_changing)
438f7d77079SKukjin Kim 			s5pv210_set_refresh(DMC1, 200000);
439f7d77079SKukjin Kim 	}
440f7d77079SKukjin Kim 
441f7d77079SKukjin Kim 	/*
44215aa70a3SBhaskar Chowdhury 	 * L4 level needs to change memory bus speed, hence ONEDRAM clock
44315aa70a3SBhaskar Chowdhury 	 * divider and memory refresh parameter should be changed
444f7d77079SKukjin Kim 	 */
445f7d77079SKukjin Kim 	if (bus_speed_changing) {
446187364b6SBen Dooks 		reg = readl_relaxed(S5P_CLK_DIV6);
447f7d77079SKukjin Kim 		reg &= ~S5P_CLKDIV6_ONEDRAM_MASK;
448f7d77079SKukjin Kim 		reg |= (clkdiv_val[index][8] << S5P_CLKDIV6_ONEDRAM_SHIFT);
449187364b6SBen Dooks 		writel_relaxed(reg, S5P_CLK_DIV6);
450f7d77079SKukjin Kim 
451f7d77079SKukjin Kim 		do {
452187364b6SBen Dooks 			reg = readl_relaxed(S5P_CLKDIV_STAT1);
453f7d77079SKukjin Kim 		} while (reg & (1 << 15));
454f7d77079SKukjin Kim 
455f7d77079SKukjin Kim 		/* Reconfigure DRAM refresh counter value */
456f7d77079SKukjin Kim 		if (index != L4) {
457f7d77079SKukjin Kim 			/*
458f7d77079SKukjin Kim 			 * DMC0 : 166Mhz
459f7d77079SKukjin Kim 			 * DMC1 : 200Mhz
460f7d77079SKukjin Kim 			 */
461f7d77079SKukjin Kim 			s5pv210_set_refresh(DMC0, 166000);
462f7d77079SKukjin Kim 			s5pv210_set_refresh(DMC1, 200000);
463f7d77079SKukjin Kim 		} else {
464f7d77079SKukjin Kim 			/*
465f7d77079SKukjin Kim 			 * DMC0 : 83Mhz
466f7d77079SKukjin Kim 			 * DMC1 : 100Mhz
467f7d77079SKukjin Kim 			 */
468f7d77079SKukjin Kim 			s5pv210_set_refresh(DMC0, 83000);
469f7d77079SKukjin Kim 			s5pv210_set_refresh(DMC1, 100000);
470f7d77079SKukjin Kim 		}
471f7d77079SKukjin Kim 	}
472f7d77079SKukjin Kim 
473d4019f0aSViresh Kumar 	if (new_freq < old_freq) {
474e8b4c198SJonghwan Choi 		regulator_set_voltage(int_regulator,
475e8b4c198SJonghwan Choi 				int_volt, int_volt_max);
476e8b4c198SJonghwan Choi 
477e8b4c198SJonghwan Choi 		regulator_set_voltage(arm_regulator,
478e8b4c198SJonghwan Choi 				arm_volt, arm_volt_max);
479f7d77079SKukjin Kim 	}
480f7d77079SKukjin Kim 
481f9020441SPaweł Chmiel 	pr_debug("Perf changed[L%d]\n", index);
482f7d77079SKukjin Kim 
4835b02b779SArve Hjønnevåg exit:
4845b02b779SArve Hjønnevåg 	mutex_unlock(&set_freq_lock);
4855b02b779SArve Hjønnevåg 	return ret;
486f7d77079SKukjin Kim }
487f7d77079SKukjin Kim 
check_mem_type(void __iomem * dmc_reg)488f7d77079SKukjin Kim static int check_mem_type(void __iomem *dmc_reg)
489f7d77079SKukjin Kim {
490f7d77079SKukjin Kim 	unsigned long val;
491f7d77079SKukjin Kim 
492187364b6SBen Dooks 	val = readl_relaxed(dmc_reg + 0x4);
493f7d77079SKukjin Kim 	val = (val & (0xf << 8));
494f7d77079SKukjin Kim 
495f7d77079SKukjin Kim 	return val >> 8;
496f7d77079SKukjin Kim }
497f7d77079SKukjin Kim 
s5pv210_cpu_init(struct cpufreq_policy * policy)498dc268742SMark Brown static int s5pv210_cpu_init(struct cpufreq_policy *policy)
499f7d77079SKukjin Kim {
500f7d77079SKukjin Kim 	unsigned long mem_type;
5014911ca10SJulia Lawall 	int ret;
502f7d77079SKukjin Kim 
503652ed95dSViresh Kumar 	policy->clk = clk_get(NULL, "armclk");
504652ed95dSViresh Kumar 	if (IS_ERR(policy->clk))
505652ed95dSViresh Kumar 		return PTR_ERR(policy->clk);
506f7d77079SKukjin Kim 
507f7d77079SKukjin Kim 	dmc0_clk = clk_get(NULL, "sclk_dmc0");
508f7d77079SKukjin Kim 	if (IS_ERR(dmc0_clk)) {
5094911ca10SJulia Lawall 		ret = PTR_ERR(dmc0_clk);
5104911ca10SJulia Lawall 		goto out_dmc0;
511f7d77079SKukjin Kim 	}
512f7d77079SKukjin Kim 
513f7d77079SKukjin Kim 	dmc1_clk = clk_get(NULL, "hclk_msys");
514f7d77079SKukjin Kim 	if (IS_ERR(dmc1_clk)) {
5154911ca10SJulia Lawall 		ret = PTR_ERR(dmc1_clk);
5164911ca10SJulia Lawall 		goto out_dmc1;
517f7d77079SKukjin Kim 	}
518f7d77079SKukjin Kim 
5194911ca10SJulia Lawall 	if (policy->cpu != 0) {
5204911ca10SJulia Lawall 		ret = -EINVAL;
5214911ca10SJulia Lawall 		goto out_dmc1;
5224911ca10SJulia Lawall 	}
523f7d77079SKukjin Kim 
524f7d77079SKukjin Kim 	/*
525f7d77079SKukjin Kim 	 * check_mem_type : This driver only support LPDDR & LPDDR2.
526f7d77079SKukjin Kim 	 * other memory type is not supported.
527f7d77079SKukjin Kim 	 */
5286d4ed0f4STomasz Figa 	mem_type = check_mem_type(dmc_base[0]);
529f7d77079SKukjin Kim 
530f7d77079SKukjin Kim 	if ((mem_type != LPDDR) && (mem_type != LPDDR2)) {
531b49c22a6SJoe Perches 		pr_err("CPUFreq doesn't support this memory type\n");
5324911ca10SJulia Lawall 		ret = -EINVAL;
5334911ca10SJulia Lawall 		goto out_dmc1;
534f7d77079SKukjin Kim 	}
535f7d77079SKukjin Kim 
536f7d77079SKukjin Kim 	/* Find current refresh counter and frequency each DMC */
537187364b6SBen Dooks 	s5pv210_dram_conf[0].refresh = (readl_relaxed(dmc_base[0] + 0x30) * 1000);
538f7d77079SKukjin Kim 	s5pv210_dram_conf[0].freq = clk_get_rate(dmc0_clk);
539f7d77079SKukjin Kim 
540187364b6SBen Dooks 	s5pv210_dram_conf[1].refresh = (readl_relaxed(dmc_base[1] + 0x30) * 1000);
541f7d77079SKukjin Kim 	s5pv210_dram_conf[1].freq = clk_get_rate(dmc1_clk);
542f7d77079SKukjin Kim 
54359625ba3SViresh Kumar 	policy->suspend_freq = SLEEP_FREQ;
544c4dcc8a1SViresh Kumar 	cpufreq_generic_init(policy, s5pv210_freq_table, 40000);
545c4dcc8a1SViresh Kumar 	return 0;
5464911ca10SJulia Lawall 
5474911ca10SJulia Lawall out_dmc1:
5484911ca10SJulia Lawall 	clk_put(dmc0_clk);
5494911ca10SJulia Lawall out_dmc0:
550652ed95dSViresh Kumar 	clk_put(policy->clk);
5514911ca10SJulia Lawall 	return ret;
552f7d77079SKukjin Kim }
553f7d77079SKukjin Kim 
s5pv210_cpufreq_reboot_notifier_event(struct notifier_block * this,unsigned long event,void * ptr)554fe7f1bcbSHuisung Kang static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
555fe7f1bcbSHuisung Kang 						 unsigned long event, void *ptr)
556fe7f1bcbSHuisung Kang {
557fe7f1bcbSHuisung Kang 	int ret;
5588ead819fSchenqiwu 	struct cpufreq_policy *policy;
559fe7f1bcbSHuisung Kang 
5608ead819fSchenqiwu 	policy = cpufreq_cpu_get(0);
5618ead819fSchenqiwu 	if (!policy) {
5628ead819fSchenqiwu 		pr_debug("cpufreq: get no policy for cpu0\n");
5638ead819fSchenqiwu 		return NOTIFY_BAD;
5648ead819fSchenqiwu 	}
5658ead819fSchenqiwu 
5668ead819fSchenqiwu 	ret = cpufreq_driver_target(policy, SLEEP_FREQ, 0);
5678ead819fSchenqiwu 	cpufreq_cpu_put(policy);
5688ead819fSchenqiwu 
569fe7f1bcbSHuisung Kang 	if (ret < 0)
570fe7f1bcbSHuisung Kang 		return NOTIFY_BAD;
571fe7f1bcbSHuisung Kang 
5729c0ebcf7SViresh Kumar 	no_cpufreq_access = true;
573fe7f1bcbSHuisung Kang 	return NOTIFY_DONE;
574fe7f1bcbSHuisung Kang }
575fe7f1bcbSHuisung Kang 
576f7d77079SKukjin Kim static struct cpufreq_driver s5pv210_driver = {
5775ae4a4b4SViresh Kumar 	.flags		= CPUFREQ_NEED_INITIAL_FREQ_CHECK,
5789c3c6e33SViresh Kumar 	.verify		= cpufreq_generic_frequency_table_verify,
5799c0ebcf7SViresh Kumar 	.target_index	= s5pv210_target,
580652ed95dSViresh Kumar 	.get		= cpufreq_generic_get,
581f7d77079SKukjin Kim 	.init		= s5pv210_cpu_init,
582f7d77079SKukjin Kim 	.name		= "s5pv210",
58359625ba3SViresh Kumar 	.suspend	= cpufreq_generic_suspend,
58459625ba3SViresh Kumar 	.resume		= cpufreq_generic_suspend, /* We need to set SLEEP FREQ again */
585f7d77079SKukjin Kim };
586f7d77079SKukjin Kim 
587fe7f1bcbSHuisung Kang static struct notifier_block s5pv210_cpufreq_reboot_notifier = {
588fe7f1bcbSHuisung Kang 	.notifier_call = s5pv210_cpufreq_reboot_notifier_event,
589fe7f1bcbSHuisung Kang };
590fe7f1bcbSHuisung Kang 
s5pv210_cpufreq_probe(struct platform_device * pdev)5916d4ed0f4STomasz Figa static int s5pv210_cpufreq_probe(struct platform_device *pdev)
592f7d77079SKukjin Kim {
59362923806SKrzysztof Kozlowski 	struct device *dev = &pdev->dev;
5946d4ed0f4STomasz Figa 	struct device_node *np;
595e0e5b2b4SPaweł Chmiel 	int id, result = 0;
5966d4ed0f4STomasz Figa 
5976d4ed0f4STomasz Figa 	/*
5986d4ed0f4STomasz Figa 	 * HACK: This is a temporary workaround to get access to clock
5996d4ed0f4STomasz Figa 	 * and DMC controller registers directly and remove static mappings
6006d4ed0f4STomasz Figa 	 * and dependencies on platform headers. It is necessary to enable
6016d4ed0f4STomasz Figa 	 * S5PV210 multi-platform support and will be removed together with
6026d4ed0f4STomasz Figa 	 * this whole driver as soon as S5PV210 gets migrated to use
603bbcf0719SViresh Kumar 	 * cpufreq-dt driver.
6046d4ed0f4STomasz Figa 	 */
605e0e5b2b4SPaweł Chmiel 	arm_regulator = regulator_get(NULL, "vddarm");
60662923806SKrzysztof Kozlowski 	if (IS_ERR(arm_regulator))
60762923806SKrzysztof Kozlowski 		return dev_err_probe(dev, PTR_ERR(arm_regulator),
60862923806SKrzysztof Kozlowski 				     "failed to get regulator vddarm\n");
609e0e5b2b4SPaweł Chmiel 
610e0e5b2b4SPaweł Chmiel 	int_regulator = regulator_get(NULL, "vddint");
611e0e5b2b4SPaweł Chmiel 	if (IS_ERR(int_regulator)) {
61262923806SKrzysztof Kozlowski 		result = dev_err_probe(dev, PTR_ERR(int_regulator),
61362923806SKrzysztof Kozlowski 				       "failed to get regulator vddint\n");
614e0e5b2b4SPaweł Chmiel 		goto err_int_regulator;
615e0e5b2b4SPaweł Chmiel 	}
616e0e5b2b4SPaweł Chmiel 
6176d4ed0f4STomasz Figa 	np = of_find_compatible_node(NULL, NULL, "samsung,s5pv210-clock");
6186d4ed0f4STomasz Figa 	if (!np) {
61977c6d5cdSKrzysztof Kozlowski 		dev_err(dev, "failed to find clock controller DT node\n");
620e0e5b2b4SPaweł Chmiel 		result = -ENODEV;
621e0e5b2b4SPaweł Chmiel 		goto err_clock;
6226d4ed0f4STomasz Figa 	}
6236d4ed0f4STomasz Figa 
6246d4ed0f4STomasz Figa 	clk_base = of_iomap(np, 0);
62538c1c6a9SJulia Lawall 	of_node_put(np);
6266d4ed0f4STomasz Figa 	if (!clk_base) {
62777c6d5cdSKrzysztof Kozlowski 		dev_err(dev, "failed to map clock registers\n");
628e0e5b2b4SPaweł Chmiel 		result = -EFAULT;
629e0e5b2b4SPaweł Chmiel 		goto err_clock;
6306d4ed0f4STomasz Figa 	}
6316d4ed0f4STomasz Figa 
6326d4ed0f4STomasz Figa 	for_each_compatible_node(np, NULL, "samsung,s5pv210-dmc") {
6336d4ed0f4STomasz Figa 		id = of_alias_get_id(np, "dmc");
6346d4ed0f4STomasz Figa 		if (id < 0 || id >= ARRAY_SIZE(dmc_base)) {
63577c6d5cdSKrzysztof Kozlowski 			dev_err(dev, "failed to get alias of dmc node '%pOFn'\n", np);
63638c1c6a9SJulia Lawall 			of_node_put(np);
637e0e5b2b4SPaweł Chmiel 			result = id;
638e0e5b2b4SPaweł Chmiel 			goto err_clk_base;
6396d4ed0f4STomasz Figa 		}
6406d4ed0f4STomasz Figa 
6416d4ed0f4STomasz Figa 		dmc_base[id] = of_iomap(np, 0);
6426d4ed0f4STomasz Figa 		if (!dmc_base[id]) {
64377c6d5cdSKrzysztof Kozlowski 			dev_err(dev, "failed to map dmc%d registers\n", id);
64438c1c6a9SJulia Lawall 			of_node_put(np);
645e0e5b2b4SPaweł Chmiel 			result = -EFAULT;
646e0e5b2b4SPaweł Chmiel 			goto err_dmc;
6476d4ed0f4STomasz Figa 		}
6486d4ed0f4STomasz Figa 	}
6496d4ed0f4STomasz Figa 
6506d4ed0f4STomasz Figa 	for (id = 0; id < ARRAY_SIZE(dmc_base); ++id) {
6516d4ed0f4STomasz Figa 		if (!dmc_base[id]) {
65277c6d5cdSKrzysztof Kozlowski 			dev_err(dev, "failed to find dmc%d node\n", id);
653e0e5b2b4SPaweł Chmiel 			result = -ENODEV;
654e0e5b2b4SPaweł Chmiel 			goto err_dmc;
6556d4ed0f4STomasz Figa 		}
6566d4ed0f4STomasz Figa 	}
6576d4ed0f4STomasz Figa 
658fe7f1bcbSHuisung Kang 	register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
659405e6d6dSHuisung Kang 
660f7d77079SKukjin Kim 	return cpufreq_register_driver(&s5pv210_driver);
661e0e5b2b4SPaweł Chmiel 
662e0e5b2b4SPaweł Chmiel err_dmc:
663e0e5b2b4SPaweł Chmiel 	for (id = 0; id < ARRAY_SIZE(dmc_base); ++id)
664e0e5b2b4SPaweł Chmiel 		if (dmc_base[id]) {
665e0e5b2b4SPaweł Chmiel 			iounmap(dmc_base[id]);
666e0e5b2b4SPaweł Chmiel 			dmc_base[id] = NULL;
667e0e5b2b4SPaweł Chmiel 		}
668e0e5b2b4SPaweł Chmiel 
669e0e5b2b4SPaweł Chmiel err_clk_base:
670e0e5b2b4SPaweł Chmiel 	iounmap(clk_base);
671e0e5b2b4SPaweł Chmiel 
672e0e5b2b4SPaweł Chmiel err_clock:
673e0e5b2b4SPaweł Chmiel 	regulator_put(int_regulator);
674e0e5b2b4SPaweł Chmiel 
675e0e5b2b4SPaweł Chmiel err_int_regulator:
676e0e5b2b4SPaweł Chmiel 	regulator_put(arm_regulator);
677e0e5b2b4SPaweł Chmiel 
678e0e5b2b4SPaweł Chmiel 	return result;
679f7d77079SKukjin Kim }
680f7d77079SKukjin Kim 
6816d4ed0f4STomasz Figa static struct platform_driver s5pv210_cpufreq_platdrv = {
6826d4ed0f4STomasz Figa 	.driver = {
6836d4ed0f4STomasz Figa 		.name	= "s5pv210-cpufreq",
6846d4ed0f4STomasz Figa 	},
6856d4ed0f4STomasz Figa 	.probe = s5pv210_cpufreq_probe,
6866d4ed0f4STomasz Figa };
6875b64127eSPaul Gortmaker builtin_platform_driver(s5pv210_cpufreq_platdrv);
688