blob: b288e66f0ebef945c91fe1d5db8b426b77f5394c [file] [log] [blame]
Chander Kashyap0aee53b2012-02-05 23:01:47 +00001/*
2 * Clock setup for SMDK5250 board based on EXYNOS5
3 *
4 * Copyright (C) 2012 Samsung Electronics
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +000025#include <common.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000026#include <config.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000027#include <asm/io.h>
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +000028#include <asm/arch/clk.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000029#include <asm/arch/clock.h>
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +000030#include <asm/arch/spl.h>
Amarc748be02013-04-27 11:42:59 +053031#include <asm/arch/dwmmc.h>
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +000032
33#include "clock_init.h"
Chander Kashyap0aee53b2012-02-05 23:01:47 +000034#include "setup.h"
35
Amarc748be02013-04-27 11:42:59 +053036#define FSYS1_MMC0_DIV_MASK 0xff0f
37#define FSYS1_MMC0_DIV_VAL 0x0701
38
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +000039DECLARE_GLOBAL_DATA_PTR;
40
41struct arm_clk_ratios arm_clk_ratios[] = {
42 {
43 .arm_freq_mhz = 600,
44
45 .apll_mdiv = 0xc8,
46 .apll_pdiv = 0x4,
47 .apll_sdiv = 0x1,
48
49 .arm2_ratio = 0x0,
50 .apll_ratio = 0x1,
51 .pclk_dbg_ratio = 0x1,
52 .atb_ratio = 0x2,
53 .periph_ratio = 0x7,
54 .acp_ratio = 0x7,
55 .cpud_ratio = 0x1,
56 .arm_ratio = 0x0,
57 }, {
58 .arm_freq_mhz = 800,
59
60 .apll_mdiv = 0x64,
61 .apll_pdiv = 0x3,
62 .apll_sdiv = 0x0,
63
64 .arm2_ratio = 0x0,
65 .apll_ratio = 0x1,
66 .pclk_dbg_ratio = 0x1,
67 .atb_ratio = 0x3,
68 .periph_ratio = 0x7,
69 .acp_ratio = 0x7,
70 .cpud_ratio = 0x2,
71 .arm_ratio = 0x0,
72 }, {
73 .arm_freq_mhz = 1000,
74
75 .apll_mdiv = 0x7d,
76 .apll_pdiv = 0x3,
77 .apll_sdiv = 0x0,
78
79 .arm2_ratio = 0x0,
80 .apll_ratio = 0x1,
81 .pclk_dbg_ratio = 0x1,
82 .atb_ratio = 0x4,
83 .periph_ratio = 0x7,
84 .acp_ratio = 0x7,
85 .cpud_ratio = 0x2,
86 .arm_ratio = 0x0,
87 }, {
88 .arm_freq_mhz = 1200,
89
90 .apll_mdiv = 0x96,
91 .apll_pdiv = 0x3,
92 .apll_sdiv = 0x0,
93
94 .arm2_ratio = 0x0,
95 .apll_ratio = 0x3,
96 .pclk_dbg_ratio = 0x1,
97 .atb_ratio = 0x5,
98 .periph_ratio = 0x7,
99 .acp_ratio = 0x7,
100 .cpud_ratio = 0x3,
101 .arm_ratio = 0x0,
102 }, {
103 .arm_freq_mhz = 1400,
104
105 .apll_mdiv = 0xaf,
106 .apll_pdiv = 0x3,
107 .apll_sdiv = 0x0,
108
109 .arm2_ratio = 0x0,
110 .apll_ratio = 0x3,
111 .pclk_dbg_ratio = 0x1,
112 .atb_ratio = 0x6,
113 .periph_ratio = 0x7,
114 .acp_ratio = 0x7,
115 .cpud_ratio = 0x3,
116 .arm_ratio = 0x0,
117 }, {
118 .arm_freq_mhz = 1700,
119
120 .apll_mdiv = 0x1a9,
121 .apll_pdiv = 0x6,
122 .apll_sdiv = 0x0,
123
124 .arm2_ratio = 0x0,
125 .apll_ratio = 0x3,
126 .pclk_dbg_ratio = 0x1,
127 .atb_ratio = 0x6,
128 .periph_ratio = 0x7,
129 .acp_ratio = 0x7,
130 .cpud_ratio = 0x3,
131 .arm_ratio = 0x0,
132 }
133};
134struct mem_timings mem_timings[] = {
135 {
136 .mem_manuf = MEM_MANUF_ELPIDA,
137 .mem_type = DDR_MODE_DDR3,
138 .frequency_mhz = 800,
139 .mpll_mdiv = 0xc8,
140 .mpll_pdiv = 0x3,
141 .mpll_sdiv = 0x0,
142 .cpll_mdiv = 0xde,
143 .cpll_pdiv = 0x4,
144 .cpll_sdiv = 0x2,
145 .gpll_mdiv = 0x215,
146 .gpll_pdiv = 0xc,
147 .gpll_sdiv = 0x1,
148 .epll_mdiv = 0x60,
149 .epll_pdiv = 0x3,
150 .epll_sdiv = 0x3,
151 .vpll_mdiv = 0x96,
152 .vpll_pdiv = 0x3,
153 .vpll_sdiv = 0x2,
154
155 .bpll_mdiv = 0x64,
156 .bpll_pdiv = 0x3,
157 .bpll_sdiv = 0x0,
158 .pclk_cdrex_ratio = 0x5,
159 .direct_cmd_msr = {
160 0x00020018, 0x00030000, 0x00010042, 0x00000d70
161 },
162 .timing_ref = 0x000000bb,
163 .timing_row = 0x8c36650e,
164 .timing_data = 0x3630580b,
165 .timing_power = 0x41000a44,
166 .phy0_dqs = 0x08080808,
167 .phy1_dqs = 0x08080808,
168 .phy0_dq = 0x08080808,
169 .phy1_dq = 0x08080808,
170 .phy0_tFS = 0x4,
171 .phy1_tFS = 0x4,
172 .phy0_pulld_dqs = 0xf,
173 .phy1_pulld_dqs = 0xf,
174
175 .lpddr3_ctrl_phy_reset = 0x1,
176 .ctrl_start_point = 0x10,
177 .ctrl_inc = 0x10,
178 .ctrl_start = 0x1,
179 .ctrl_dll_on = 0x1,
180 .ctrl_ref = 0x8,
181
182 .ctrl_force = 0x1a,
183 .ctrl_rdlat = 0x0b,
184 .ctrl_bstlen = 0x08,
185
186 .fp_resync = 0x8,
187 .iv_size = 0x7,
188 .dfi_init_start = 1,
189 .aref_en = 1,
190
191 .rd_fetch = 0x3,
192
193 .zq_mode_dds = 0x7,
194 .zq_mode_term = 0x1,
195 .zq_mode_noterm = 0,
196
197 /*
198 * Dynamic Clock: Always Running
199 * Memory Burst length: 8
200 * Number of chips: 1
201 * Memory Bus width: 32 bit
202 * Memory Type: DDR3
203 * Additional Latancy for PLL: 0 Cycle
204 */
205 .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
206 DMC_MEMCONTROL_DPWRDN_DISABLE |
207 DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
208 DMC_MEMCONTROL_TP_DISABLE |
209 DMC_MEMCONTROL_DSREF_ENABLE |
210 DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
211 DMC_MEMCONTROL_MEM_TYPE_DDR3 |
212 DMC_MEMCONTROL_MEM_WIDTH_32BIT |
213 DMC_MEMCONTROL_NUM_CHIP_1 |
214 DMC_MEMCONTROL_BL_8 |
215 DMC_MEMCONTROL_PZQ_DISABLE |
216 DMC_MEMCONTROL_MRR_BYTE_7_0,
217 .memconfig = DMC_MEMCONFIGx_CHIP_MAP_INTERLEAVED |
218 DMC_MEMCONFIGx_CHIP_COL_10 |
219 DMC_MEMCONFIGx_CHIP_ROW_15 |
220 DMC_MEMCONFIGx_CHIP_BANK_8,
221 .membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
222 .membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
223 .prechconfig_tp_cnt = 0xff,
224 .dpwrdn_cyc = 0xff,
225 .dsref_cyc = 0xffff,
226 .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
227 DMC_CONCONTROL_TIMEOUT_LEVEL0 |
228 DMC_CONCONTROL_RD_FETCH_DISABLE |
229 DMC_CONCONTROL_EMPTY_DISABLE |
230 DMC_CONCONTROL_AREF_EN_DISABLE |
231 DMC_CONCONTROL_IO_PD_CON_DISABLE,
232 .dmc_channels = 2,
233 .chips_per_channel = 2,
234 .chips_to_configure = 1,
235 .send_zq_init = 1,
236 .impedance = IMP_OUTPUT_DRV_30_OHM,
237 .gate_leveling_enable = 0,
238 }, {
239 .mem_manuf = MEM_MANUF_SAMSUNG,
240 .mem_type = DDR_MODE_DDR3,
241 .frequency_mhz = 800,
242 .mpll_mdiv = 0xc8,
243 .mpll_pdiv = 0x3,
244 .mpll_sdiv = 0x0,
245 .cpll_mdiv = 0xde,
246 .cpll_pdiv = 0x4,
247 .cpll_sdiv = 0x2,
248 .gpll_mdiv = 0x215,
249 .gpll_pdiv = 0xc,
250 .gpll_sdiv = 0x1,
251 .epll_mdiv = 0x60,
252 .epll_pdiv = 0x3,
253 .epll_sdiv = 0x3,
254 .vpll_mdiv = 0x96,
255 .vpll_pdiv = 0x3,
256 .vpll_sdiv = 0x2,
257
258 .bpll_mdiv = 0x64,
259 .bpll_pdiv = 0x3,
260 .bpll_sdiv = 0x0,
261 .pclk_cdrex_ratio = 0x5,
262 .direct_cmd_msr = {
263 0x00020018, 0x00030000, 0x00010000, 0x00000d70
264 },
265 .timing_ref = 0x000000bb,
266 .timing_row = 0x8c36650e,
267 .timing_data = 0x3630580b,
268 .timing_power = 0x41000a44,
269 .phy0_dqs = 0x08080808,
270 .phy1_dqs = 0x08080808,
271 .phy0_dq = 0x08080808,
272 .phy1_dq = 0x08080808,
273 .phy0_tFS = 0x8,
274 .phy1_tFS = 0x8,
275 .phy0_pulld_dqs = 0xf,
276 .phy1_pulld_dqs = 0xf,
277
278 .lpddr3_ctrl_phy_reset = 0x1,
279 .ctrl_start_point = 0x10,
280 .ctrl_inc = 0x10,
281 .ctrl_start = 0x1,
282 .ctrl_dll_on = 0x1,
283 .ctrl_ref = 0x8,
284
285 .ctrl_force = 0x1a,
286 .ctrl_rdlat = 0x0b,
287 .ctrl_bstlen = 0x08,
288
289 .fp_resync = 0x8,
290 .iv_size = 0x7,
291 .dfi_init_start = 1,
292 .aref_en = 1,
293
294 .rd_fetch = 0x3,
295
296 .zq_mode_dds = 0x5,
297 .zq_mode_term = 0x1,
298 .zq_mode_noterm = 1,
299
300 /*
301 * Dynamic Clock: Always Running
302 * Memory Burst length: 8
303 * Number of chips: 1
304 * Memory Bus width: 32 bit
305 * Memory Type: DDR3
306 * Additional Latancy for PLL: 0 Cycle
307 */
308 .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
309 DMC_MEMCONTROL_DPWRDN_DISABLE |
310 DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
311 DMC_MEMCONTROL_TP_DISABLE |
312 DMC_MEMCONTROL_DSREF_ENABLE |
313 DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
314 DMC_MEMCONTROL_MEM_TYPE_DDR3 |
315 DMC_MEMCONTROL_MEM_WIDTH_32BIT |
316 DMC_MEMCONTROL_NUM_CHIP_1 |
317 DMC_MEMCONTROL_BL_8 |
318 DMC_MEMCONTROL_PZQ_DISABLE |
319 DMC_MEMCONTROL_MRR_BYTE_7_0,
320 .memconfig = DMC_MEMCONFIGx_CHIP_MAP_INTERLEAVED |
321 DMC_MEMCONFIGx_CHIP_COL_10 |
322 DMC_MEMCONFIGx_CHIP_ROW_15 |
323 DMC_MEMCONFIGx_CHIP_BANK_8,
324 .membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
325 .membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
326 .prechconfig_tp_cnt = 0xff,
327 .dpwrdn_cyc = 0xff,
328 .dsref_cyc = 0xffff,
329 .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
330 DMC_CONCONTROL_TIMEOUT_LEVEL0 |
331 DMC_CONCONTROL_RD_FETCH_DISABLE |
332 DMC_CONCONTROL_EMPTY_DISABLE |
333 DMC_CONCONTROL_AREF_EN_DISABLE |
334 DMC_CONCONTROL_IO_PD_CON_DISABLE,
335 .dmc_channels = 2,
336 .chips_per_channel = 2,
337 .chips_to_configure = 1,
338 .send_zq_init = 1,
339 .impedance = IMP_OUTPUT_DRV_40_OHM,
340 .gate_leveling_enable = 1,
341 }
342};
343
344/**
345 * Get the required memory type and speed (SPL version).
346 *
347 * In SPL we have no device tree, so we use the machine parameters
348 *
349 * @param mem_type Returns memory type
350 * @param frequency_mhz Returns memory speed in MHz
351 * @param arm_freq Returns ARM clock speed in MHz
352 * @param mem_manuf Return Memory Manufacturer name
353 * @return 0 if all ok
354 */
355static int clock_get_mem_selection(enum ddr_mode *mem_type,
356 unsigned *frequency_mhz, unsigned *arm_freq,
357 enum mem_manuf *mem_manuf)
358{
359 struct spl_machine_param *params;
360
361 params = spl_get_machine_params();
362 *mem_type = params->mem_type;
363 *frequency_mhz = params->frequency_mhz;
364 *arm_freq = params->arm_freq_mhz;
365 *mem_manuf = params->mem_manuf;
366
367 return 0;
368}
369
370/* Get the ratios for setting ARM clock */
371struct arm_clk_ratios *get_arm_ratios(void)
372{
373 struct arm_clk_ratios *arm_ratio;
374 enum ddr_mode mem_type;
375 enum mem_manuf mem_manuf;
376 unsigned frequency_mhz, arm_freq;
377 int i;
378
379 if (clock_get_mem_selection(&mem_type, &frequency_mhz,
380 &arm_freq, &mem_manuf))
381 ;
382 for (i = 0, arm_ratio = arm_clk_ratios; i < ARRAY_SIZE(arm_clk_ratios);
383 i++, arm_ratio++) {
384 if (arm_ratio->arm_freq_mhz == arm_freq)
385 return arm_ratio;
386 }
387
388 /* will hang if failed to find clock ratio */
389 while (1)
390 ;
391
392 return NULL;
393}
394
395struct mem_timings *clock_get_mem_timings(void)
396{
397 struct mem_timings *mem;
398 enum ddr_mode mem_type;
399 enum mem_manuf mem_manuf;
400 unsigned frequency_mhz, arm_freq;
401 int i;
402
403 if (!clock_get_mem_selection(&mem_type, &frequency_mhz,
404 &arm_freq, &mem_manuf)) {
405 for (i = 0, mem = mem_timings; i < ARRAY_SIZE(mem_timings);
406 i++, mem++) {
407 if (mem->mem_type == mem_type &&
408 mem->frequency_mhz == frequency_mhz &&
409 mem->mem_manuf == mem_manuf)
410 return mem;
411 }
412 }
413
414 /* will hang if failed to find memory timings */
415 while (1)
416 ;
417
418 return NULL;
419}
420
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000421void system_clock_init()
422{
423 struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE;
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000424 struct mem_timings *mem;
425 struct arm_clk_ratios *arm_clk_ratio;
426 u32 val, tmp;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000427
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000428 mem = clock_get_mem_timings();
429 arm_clk_ratio = get_arm_ratios();
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000430
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000431 clrbits_le32(&clk->src_cpu, MUX_APLL_SEL_MASK);
432 do {
433 val = readl(&clk->mux_stat_cpu);
434 } while ((val | MUX_APLL_SEL_MASK) != val);
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000435
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000436 clrbits_le32(&clk->src_core1, MUX_MPLL_SEL_MASK);
437 do {
438 val = readl(&clk->mux_stat_core1);
439 } while ((val | MUX_MPLL_SEL_MASK) != val);
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000440
Akshay Saraswata4d40b82013-03-21 02:13:13 +0000441 clrbits_le32(&clk->src_top2, MUX_CPLL_SEL_MASK);
442 clrbits_le32(&clk->src_top2, MUX_EPLL_SEL_MASK);
443 clrbits_le32(&clk->src_top2, MUX_VPLL_SEL_MASK);
444 clrbits_le32(&clk->src_top2, MUX_GPLL_SEL_MASK);
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000445 tmp = MUX_CPLL_SEL_MASK | MUX_EPLL_SEL_MASK | MUX_VPLL_SEL_MASK
446 | MUX_GPLL_SEL_MASK;
447 do {
448 val = readl(&clk->mux_stat_top2);
449 } while ((val | tmp) != val);
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000450
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000451 clrbits_le32(&clk->src_cdrex, MUX_BPLL_SEL_MASK);
452 do {
453 val = readl(&clk->mux_stat_cdrex);
454 } while ((val | MUX_BPLL_SEL_MASK) != val);
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000455
456 /* PLL locktime */
457 writel(APLL_LOCK_VAL, &clk->apll_lock);
458
459 writel(MPLL_LOCK_VAL, &clk->mpll_lock);
460
461 writel(BPLL_LOCK_VAL, &clk->bpll_lock);
462
463 writel(CPLL_LOCK_VAL, &clk->cpll_lock);
464
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000465 writel(GPLL_LOCK_VAL, &clk->gpll_lock);
466
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000467 writel(EPLL_LOCK_VAL, &clk->epll_lock);
468
469 writel(VPLL_LOCK_VAL, &clk->vpll_lock);
470
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000471 writel(CLK_REG_DISABLE, &clk->pll_div2_sel);
472
473 writel(MUX_HPM_SEL_MASK, &clk->src_cpu);
474 do {
475 val = readl(&clk->mux_stat_cpu);
476 } while ((val | HPM_SEL_SCLK_MPLL) != val);
477
478 val = arm_clk_ratio->arm2_ratio << 28
479 | arm_clk_ratio->apll_ratio << 24
480 | arm_clk_ratio->pclk_dbg_ratio << 20
481 | arm_clk_ratio->atb_ratio << 16
482 | arm_clk_ratio->periph_ratio << 12
483 | arm_clk_ratio->acp_ratio << 8
484 | arm_clk_ratio->cpud_ratio << 4
485 | arm_clk_ratio->arm_ratio;
486 writel(val, &clk->div_cpu0);
487 do {
488 val = readl(&clk->div_stat_cpu0);
489 } while (0 != val);
490
491 writel(CLK_DIV_CPU1_VAL, &clk->div_cpu1);
492 do {
493 val = readl(&clk->div_stat_cpu1);
494 } while (0 != val);
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000495
496 /* Set APLL */
497 writel(APLL_CON1_VAL, &clk->apll_con1);
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000498 val = set_pll(arm_clk_ratio->apll_mdiv, arm_clk_ratio->apll_pdiv,
499 arm_clk_ratio->apll_sdiv);
500 writel(val, &clk->apll_con0);
Akshay Saraswatdb9e5e62013-03-15 02:29:09 +0000501 while ((readl(&clk->apll_con0) & APLL_CON0_LOCKED) == 0)
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000502 ;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000503
504 /* Set MPLL */
505 writel(MPLL_CON1_VAL, &clk->mpll_con1);
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000506 val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv);
507 writel(val, &clk->mpll_con0);
Akshay Saraswatdb9e5e62013-03-15 02:29:09 +0000508 while ((readl(&clk->mpll_con0) & MPLL_CON0_LOCKED) == 0)
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000509 ;
510
511 /* Set BPLL */
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000512 writel(BPLL_CON1_VAL, &clk->bpll_con1);
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000513 val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv);
514 writel(val, &clk->bpll_con0);
Akshay Saraswatdb9e5e62013-03-15 02:29:09 +0000515 while ((readl(&clk->bpll_con0) & BPLL_CON0_LOCKED) == 0)
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000516 ;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000517
518 /* Set CPLL */
519 writel(CPLL_CON1_VAL, &clk->cpll_con1);
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000520 val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv);
521 writel(val, &clk->cpll_con0);
Akshay Saraswatdb9e5e62013-03-15 02:29:09 +0000522 while ((readl(&clk->cpll_con0) & CPLL_CON0_LOCKED) == 0)
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000523 ;
524
525 /* Set GPLL */
526 writel(GPLL_CON1_VAL, &clk->gpll_con1);
527 val = set_pll(mem->gpll_mdiv, mem->gpll_pdiv, mem->gpll_sdiv);
528 writel(val, &clk->gpll_con0);
Akshay Saraswatdb9e5e62013-03-15 02:29:09 +0000529 while ((readl(&clk->gpll_con0) & GPLL_CON0_LOCKED) == 0)
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000530 ;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000531
532 /* Set EPLL */
533 writel(EPLL_CON2_VAL, &clk->epll_con2);
534 writel(EPLL_CON1_VAL, &clk->epll_con1);
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000535 val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv);
536 writel(val, &clk->epll_con0);
Akshay Saraswatdb9e5e62013-03-15 02:29:09 +0000537 while ((readl(&clk->epll_con0) & EPLL_CON0_LOCKED) == 0)
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000538 ;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000539
540 /* Set VPLL */
541 writel(VPLL_CON2_VAL, &clk->vpll_con2);
542 writel(VPLL_CON1_VAL, &clk->vpll_con1);
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000543 val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv);
544 writel(val, &clk->vpll_con0);
Akshay Saraswatdb9e5e62013-03-15 02:29:09 +0000545 while ((readl(&clk->vpll_con0) & VPLL_CON0_LOCKED) == 0)
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000546 ;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000547
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000548 writel(CLK_SRC_CORE0_VAL, &clk->src_core0);
549 writel(CLK_DIV_CORE0_VAL, &clk->div_core0);
550 while (readl(&clk->div_stat_core0) != 0)
551 ;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000552
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000553 writel(CLK_DIV_CORE1_VAL, &clk->div_core1);
554 while (readl(&clk->div_stat_core1) != 0)
555 ;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000556
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000557 writel(CLK_DIV_SYSRGT_VAL, &clk->div_sysrgt);
558 while (readl(&clk->div_stat_sysrgt) != 0)
559 ;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000560
Rajeshwari Shinde998e5d32012-07-03 20:02:55 +0000561 writel(CLK_DIV_ACP_VAL, &clk->div_acp);
562 while (readl(&clk->div_stat_acp) != 0)
563 ;
564
565 writel(CLK_DIV_SYSLFT_VAL, &clk->div_syslft);
566 while (readl(&clk->div_stat_syslft) != 0)
567 ;
568
569 writel(CLK_SRC_TOP0_VAL, &clk->src_top0);
570 writel(CLK_SRC_TOP1_VAL, &clk->src_top1);
571 writel(TOP2_VAL, &clk->src_top2);
572 writel(CLK_SRC_TOP3_VAL, &clk->src_top3);
573
574 writel(CLK_DIV_TOP0_VAL, &clk->div_top0);
575 while (readl(&clk->div_stat_top0))
576 ;
577
578 writel(CLK_DIV_TOP1_VAL, &clk->div_top1);
579 while (readl(&clk->div_stat_top1))
580 ;
581
582 writel(CLK_SRC_LEX_VAL, &clk->src_lex);
583 while (1) {
584 val = readl(&clk->mux_stat_lex);
585 if (val == (val | 1))
586 break;
587 }
588
589 writel(CLK_DIV_LEX_VAL, &clk->div_lex);
590 while (readl(&clk->div_stat_lex))
591 ;
592
593 writel(CLK_DIV_R0X_VAL, &clk->div_r0x);
594 while (readl(&clk->div_stat_r0x))
595 ;
596
597 writel(CLK_DIV_R0X_VAL, &clk->div_r0x);
598 while (readl(&clk->div_stat_r0x))
599 ;
600
601 writel(CLK_DIV_R1X_VAL, &clk->div_r1x);
602 while (readl(&clk->div_stat_r1x))
603 ;
604
605 writel(CLK_REG_DISABLE, &clk->src_cdrex);
606
607 writel(CLK_DIV_CDREX_VAL, &clk->div_cdrex);
608 while (readl(&clk->div_stat_cdrex))
609 ;
610
611 val = readl(&clk->src_cpu);
612 val |= CLK_SRC_CPU_VAL;
613 writel(val, &clk->src_cpu);
614
615 val = readl(&clk->src_top2);
616 val |= CLK_SRC_TOP2_VAL;
617 writel(val, &clk->src_top2);
618
619 val = readl(&clk->src_core1);
620 val |= CLK_SRC_CORE1_VAL;
621 writel(val, &clk->src_core1);
622
623 writel(CLK_SRC_FSYS0_VAL, &clk->src_fsys);
624 writel(CLK_DIV_FSYS0_VAL, &clk->div_fsys0);
625 while (readl(&clk->div_stat_fsys0))
626 ;
627
628 writel(CLK_REG_DISABLE, &clk->clkout_cmu_cpu);
629 writel(CLK_REG_DISABLE, &clk->clkout_cmu_core);
630 writel(CLK_REG_DISABLE, &clk->clkout_cmu_acp);
631 writel(CLK_REG_DISABLE, &clk->clkout_cmu_top);
632 writel(CLK_REG_DISABLE, &clk->clkout_cmu_lex);
633 writel(CLK_REG_DISABLE, &clk->clkout_cmu_r0x);
634 writel(CLK_REG_DISABLE, &clk->clkout_cmu_r1x);
635 writel(CLK_REG_DISABLE, &clk->clkout_cmu_cdrex);
636
637 writel(CLK_SRC_PERIC0_VAL, &clk->src_peric0);
638 writel(CLK_DIV_PERIC0_VAL, &clk->div_peric0);
639
640 writel(CLK_SRC_PERIC1_VAL, &clk->src_peric1);
641 writel(CLK_DIV_PERIC1_VAL, &clk->div_peric1);
642 writel(CLK_DIV_PERIC2_VAL, &clk->div_peric2);
643 writel(CLK_DIV_PERIC3_VAL, &clk->div_peric3);
644
645 writel(SCLK_SRC_ISP_VAL, &clk->sclk_src_isp);
646 writel(SCLK_DIV_ISP_VAL, &clk->sclk_div_isp);
647 writel(CLK_DIV_ISP0_VAL, &clk->div_isp0);
648 writel(CLK_DIV_ISP1_VAL, &clk->div_isp1);
649 writel(CLK_DIV_ISP2_VAL, &clk->div_isp2);
650
651 /* FIMD1 SRC CLK SELECTION */
652 writel(CLK_SRC_DISP1_0_VAL, &clk->src_disp1_0);
653
654 val = MMC2_PRE_RATIO_VAL << MMC2_PRE_RATIO_OFFSET
655 | MMC2_RATIO_VAL << MMC2_RATIO_OFFSET
656 | MMC3_PRE_RATIO_VAL << MMC3_PRE_RATIO_OFFSET
657 | MMC3_RATIO_VAL << MMC3_RATIO_OFFSET;
658 writel(val, &clk->div_fsys2);
659}
660
661void clock_init_dp_clock(void)
662{
663 struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE;
664
665 /* DP clock enable */
666 setbits_le32(&clk->gate_ip_disp1, CLK_GATE_DP1_ALLOW);
667
668 /* We run DP at 267 Mhz */
669 setbits_le32(&clk->div_disp1_0, CLK_DIV_DISP1_0_FIMD1);
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000670}
Amarc748be02013-04-27 11:42:59 +0530671
672/*
673 * Set clock divisor value for booting from EMMC.
674 * Set DWMMC channel-0 clk div to operate mmc0 device at 50MHz.
675 */
676void emmc_boot_clk_div_set(void)
677{
678 struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE;
679 unsigned int div_mmc;
680
681 div_mmc = readl((unsigned int) &clk->div_fsys1) & ~FSYS1_MMC0_DIV_MASK;
682 div_mmc |= FSYS1_MMC0_DIV_VAL;
683 writel(div_mmc, (unsigned int) &clk->div_fsys1);
684}