xref: /rk3399_rockchip-uboot/arch/arm/mach-exynos/clock_init_exynos5.c (revision 5f5620ab2679608f94b3a77e51c77d0a770103bd)
177b55e8cSThomas Abraham /*
277b55e8cSThomas Abraham  * Clock setup for SMDK5250 board based on EXYNOS5
377b55e8cSThomas Abraham  *
477b55e8cSThomas Abraham  * Copyright (C) 2012 Samsung Electronics
577b55e8cSThomas Abraham  *
677b55e8cSThomas Abraham  * SPDX-License-Identifier:	GPL-2.0+
777b55e8cSThomas Abraham  */
877b55e8cSThomas Abraham 
977b55e8cSThomas Abraham #include <common.h>
1077b55e8cSThomas Abraham #include <config.h>
1177b55e8cSThomas Abraham #include <asm/io.h>
1277b55e8cSThomas Abraham #include <asm/arch/clk.h>
1377b55e8cSThomas Abraham #include <asm/arch/clock.h>
1477b55e8cSThomas Abraham #include <asm/arch/spl.h>
1577b55e8cSThomas Abraham #include <asm/arch/dwmmc.h>
1677b55e8cSThomas Abraham 
1777b55e8cSThomas Abraham #include "clock_init.h"
1877b55e8cSThomas Abraham #include "common_setup.h"
1977b55e8cSThomas Abraham #include "exynos5_setup.h"
2077b55e8cSThomas Abraham 
2177b55e8cSThomas Abraham #define FSYS1_MMC0_DIV_MASK	0xff0f
2277b55e8cSThomas Abraham #define FSYS1_MMC0_DIV_VAL	0x0701
2377b55e8cSThomas Abraham 
2477b55e8cSThomas Abraham DECLARE_GLOBAL_DATA_PTR;
2577b55e8cSThomas Abraham 
2677b55e8cSThomas Abraham struct arm_clk_ratios arm_clk_ratios[] = {
2777b55e8cSThomas Abraham #ifdef CONFIG_EXYNOS5420
2877b55e8cSThomas Abraham 	{
2977b55e8cSThomas Abraham 		.arm_freq_mhz = 900,
3077b55e8cSThomas Abraham 
3177b55e8cSThomas Abraham 		.apll_mdiv = 0x96,
3277b55e8cSThomas Abraham 		.apll_pdiv = 0x2,
3377b55e8cSThomas Abraham 		.apll_sdiv = 0x1,
3477b55e8cSThomas Abraham 
3577b55e8cSThomas Abraham 		.arm2_ratio = 0x0,
3677b55e8cSThomas Abraham 		.apll_ratio = 0x3,
3777b55e8cSThomas Abraham 		.pclk_dbg_ratio = 0x6,
3877b55e8cSThomas Abraham 		.atb_ratio = 0x6,
3977b55e8cSThomas Abraham 		.periph_ratio = 0x7,
4077b55e8cSThomas Abraham 		.acp_ratio = 0x0,
4177b55e8cSThomas Abraham 		.cpud_ratio = 0x2,
4277b55e8cSThomas Abraham 		.arm_ratio = 0x0,
4377b55e8cSThomas Abraham 	}
4477b55e8cSThomas Abraham #else
4577b55e8cSThomas Abraham 	{
4677b55e8cSThomas Abraham 		.arm_freq_mhz = 600,
4777b55e8cSThomas Abraham 
4877b55e8cSThomas Abraham 		.apll_mdiv = 0xc8,
4977b55e8cSThomas Abraham 		.apll_pdiv = 0x4,
5077b55e8cSThomas Abraham 		.apll_sdiv = 0x1,
5177b55e8cSThomas Abraham 
5277b55e8cSThomas Abraham 		.arm2_ratio = 0x0,
5377b55e8cSThomas Abraham 		.apll_ratio = 0x1,
5477b55e8cSThomas Abraham 		.pclk_dbg_ratio = 0x1,
5577b55e8cSThomas Abraham 		.atb_ratio = 0x2,
5677b55e8cSThomas Abraham 		.periph_ratio = 0x7,
5777b55e8cSThomas Abraham 		.acp_ratio = 0x7,
5877b55e8cSThomas Abraham 		.cpud_ratio = 0x1,
5977b55e8cSThomas Abraham 		.arm_ratio = 0x0,
6077b55e8cSThomas Abraham 	}, {
6177b55e8cSThomas Abraham 		.arm_freq_mhz = 800,
6277b55e8cSThomas Abraham 
6377b55e8cSThomas Abraham 		.apll_mdiv = 0x64,
6477b55e8cSThomas Abraham 		.apll_pdiv = 0x3,
6577b55e8cSThomas Abraham 		.apll_sdiv = 0x0,
6677b55e8cSThomas Abraham 
6777b55e8cSThomas Abraham 		.arm2_ratio = 0x0,
6877b55e8cSThomas Abraham 		.apll_ratio = 0x1,
6977b55e8cSThomas Abraham 		.pclk_dbg_ratio = 0x1,
7077b55e8cSThomas Abraham 		.atb_ratio = 0x3,
7177b55e8cSThomas Abraham 		.periph_ratio = 0x7,
7277b55e8cSThomas Abraham 		.acp_ratio = 0x7,
7377b55e8cSThomas Abraham 		.cpud_ratio = 0x2,
7477b55e8cSThomas Abraham 		.arm_ratio = 0x0,
7577b55e8cSThomas Abraham 	}, {
7677b55e8cSThomas Abraham 		.arm_freq_mhz = 1000,
7777b55e8cSThomas Abraham 
7877b55e8cSThomas Abraham 		.apll_mdiv = 0x7d,
7977b55e8cSThomas Abraham 		.apll_pdiv = 0x3,
8077b55e8cSThomas Abraham 		.apll_sdiv = 0x0,
8177b55e8cSThomas Abraham 
8277b55e8cSThomas Abraham 		.arm2_ratio = 0x0,
8377b55e8cSThomas Abraham 		.apll_ratio = 0x1,
8477b55e8cSThomas Abraham 		.pclk_dbg_ratio = 0x1,
8577b55e8cSThomas Abraham 		.atb_ratio = 0x4,
8677b55e8cSThomas Abraham 		.periph_ratio = 0x7,
8777b55e8cSThomas Abraham 		.acp_ratio = 0x7,
8877b55e8cSThomas Abraham 		.cpud_ratio = 0x2,
8977b55e8cSThomas Abraham 		.arm_ratio = 0x0,
9077b55e8cSThomas Abraham 	}, {
9177b55e8cSThomas Abraham 		.arm_freq_mhz = 1200,
9277b55e8cSThomas Abraham 
9377b55e8cSThomas Abraham 		.apll_mdiv = 0x96,
9477b55e8cSThomas Abraham 		.apll_pdiv = 0x3,
9577b55e8cSThomas Abraham 		.apll_sdiv = 0x0,
9677b55e8cSThomas Abraham 
9777b55e8cSThomas Abraham 		.arm2_ratio = 0x0,
9877b55e8cSThomas Abraham 		.apll_ratio = 0x3,
9977b55e8cSThomas Abraham 		.pclk_dbg_ratio = 0x1,
10077b55e8cSThomas Abraham 		.atb_ratio = 0x5,
10177b55e8cSThomas Abraham 		.periph_ratio = 0x7,
10277b55e8cSThomas Abraham 		.acp_ratio = 0x7,
10377b55e8cSThomas Abraham 		.cpud_ratio = 0x3,
10477b55e8cSThomas Abraham 		.arm_ratio = 0x0,
10577b55e8cSThomas Abraham 	}, {
10677b55e8cSThomas Abraham 		.arm_freq_mhz = 1400,
10777b55e8cSThomas Abraham 
10877b55e8cSThomas Abraham 		.apll_mdiv = 0xaf,
10977b55e8cSThomas Abraham 		.apll_pdiv = 0x3,
11077b55e8cSThomas Abraham 		.apll_sdiv = 0x0,
11177b55e8cSThomas Abraham 
11277b55e8cSThomas Abraham 		.arm2_ratio = 0x0,
11377b55e8cSThomas Abraham 		.apll_ratio = 0x3,
11477b55e8cSThomas Abraham 		.pclk_dbg_ratio = 0x1,
11577b55e8cSThomas Abraham 		.atb_ratio = 0x6,
11677b55e8cSThomas Abraham 		.periph_ratio = 0x7,
11777b55e8cSThomas Abraham 		.acp_ratio = 0x7,
11877b55e8cSThomas Abraham 		.cpud_ratio = 0x3,
11977b55e8cSThomas Abraham 		.arm_ratio = 0x0,
12077b55e8cSThomas Abraham 	}, {
12177b55e8cSThomas Abraham 		.arm_freq_mhz = 1700,
12277b55e8cSThomas Abraham 
12377b55e8cSThomas Abraham 		.apll_mdiv = 0x1a9,
12477b55e8cSThomas Abraham 		.apll_pdiv = 0x6,
12577b55e8cSThomas Abraham 		.apll_sdiv = 0x0,
12677b55e8cSThomas Abraham 
12777b55e8cSThomas Abraham 		.arm2_ratio = 0x0,
12877b55e8cSThomas Abraham 		.apll_ratio = 0x3,
12977b55e8cSThomas Abraham 		.pclk_dbg_ratio = 0x1,
13077b55e8cSThomas Abraham 		.atb_ratio = 0x6,
13177b55e8cSThomas Abraham 		.periph_ratio = 0x7,
13277b55e8cSThomas Abraham 		.acp_ratio = 0x7,
13377b55e8cSThomas Abraham 		.cpud_ratio = 0x3,
13477b55e8cSThomas Abraham 		.arm_ratio = 0x0,
13577b55e8cSThomas Abraham 	}
13677b55e8cSThomas Abraham #endif
13777b55e8cSThomas Abraham };
13877b55e8cSThomas Abraham 
13977b55e8cSThomas Abraham struct mem_timings mem_timings[] = {
14077b55e8cSThomas Abraham #ifdef CONFIG_EXYNOS5420
14177b55e8cSThomas Abraham 	{
14277b55e8cSThomas Abraham 		.mem_manuf = MEM_MANUF_SAMSUNG,
14377b55e8cSThomas Abraham 		.mem_type = DDR_MODE_DDR3,
14477b55e8cSThomas Abraham 		.frequency_mhz = 800,
14577b55e8cSThomas Abraham 
14677b55e8cSThomas Abraham 		/* MPLL @800MHz*/
14777b55e8cSThomas Abraham 		.mpll_mdiv = 0xc8,
14877b55e8cSThomas Abraham 		.mpll_pdiv = 0x3,
14977b55e8cSThomas Abraham 		.mpll_sdiv = 0x1,
15077b55e8cSThomas Abraham 		/* CPLL @666MHz */
15177b55e8cSThomas Abraham 		.cpll_mdiv = 0xde,
15277b55e8cSThomas Abraham 		.cpll_pdiv = 0x4,
15377b55e8cSThomas Abraham 		.cpll_sdiv = 0x1,
15477b55e8cSThomas Abraham 		/* EPLL @600MHz */
15577b55e8cSThomas Abraham 		.epll_mdiv = 0x64,
15677b55e8cSThomas Abraham 		.epll_pdiv = 0x2,
15777b55e8cSThomas Abraham 		.epll_sdiv = 0x1,
15877b55e8cSThomas Abraham 		/* VPLL @430MHz */
15977b55e8cSThomas Abraham 		.vpll_mdiv = 0xd7,
16077b55e8cSThomas Abraham 		.vpll_pdiv = 0x3,
16177b55e8cSThomas Abraham 		.vpll_sdiv = 0x2,
16277b55e8cSThomas Abraham 		/* BPLL @800MHz */
16377b55e8cSThomas Abraham 		.bpll_mdiv = 0xc8,
16477b55e8cSThomas Abraham 		.bpll_pdiv = 0x3,
16577b55e8cSThomas Abraham 		.bpll_sdiv = 0x1,
16677b55e8cSThomas Abraham 		/* KPLL @600MHz */
16777b55e8cSThomas Abraham 		.kpll_mdiv = 0x190,
16877b55e8cSThomas Abraham 		.kpll_pdiv = 0x4,
16977b55e8cSThomas Abraham 		.kpll_sdiv = 0x2,
17077b55e8cSThomas Abraham 		/* DPLL @600MHz */
17177b55e8cSThomas Abraham 		.dpll_mdiv = 0x190,
17277b55e8cSThomas Abraham 		.dpll_pdiv = 0x4,
17377b55e8cSThomas Abraham 		.dpll_sdiv = 0x2,
17477b55e8cSThomas Abraham 		/* IPLL @370MHz */
17577b55e8cSThomas Abraham 		.ipll_mdiv = 0xb9,
17677b55e8cSThomas Abraham 		.ipll_pdiv = 0x3,
17777b55e8cSThomas Abraham 		.ipll_sdiv = 0x2,
17877b55e8cSThomas Abraham 		/* SPLL @400MHz */
17977b55e8cSThomas Abraham 		.spll_mdiv = 0xc8,
18077b55e8cSThomas Abraham 		.spll_pdiv = 0x3,
18177b55e8cSThomas Abraham 		.spll_sdiv = 0x2,
18277b55e8cSThomas Abraham 		/* RPLL @141Mhz */
18377b55e8cSThomas Abraham 		.rpll_mdiv = 0x5E,
18477b55e8cSThomas Abraham 		.rpll_pdiv = 0x2,
18577b55e8cSThomas Abraham 		.rpll_sdiv = 0x3,
18677b55e8cSThomas Abraham 
18777b55e8cSThomas Abraham 		.direct_cmd_msr = {
18877b55e8cSThomas Abraham 			0x00020018, 0x00030000, 0x00010046, 0x00000d70,
18977b55e8cSThomas Abraham 			0x00000c70
19077b55e8cSThomas Abraham 		},
19177b55e8cSThomas Abraham 		.timing_ref = 0x000000bb,
19277b55e8cSThomas Abraham 		.timing_row = 0x6836650f,
19377b55e8cSThomas Abraham 		.timing_data = 0x3630580b,
19477b55e8cSThomas Abraham 		.timing_power = 0x41000a26,
19577b55e8cSThomas Abraham 		.phy0_dqs = 0x08080808,
19677b55e8cSThomas Abraham 		.phy1_dqs = 0x08080808,
19777b55e8cSThomas Abraham 		.phy0_dq = 0x08080808,
19877b55e8cSThomas Abraham 		.phy1_dq = 0x08080808,
19977b55e8cSThomas Abraham 		.phy0_tFS = 0x8,
20077b55e8cSThomas Abraham 		.phy1_tFS = 0x8,
20177b55e8cSThomas Abraham 		.phy0_pulld_dqs = 0xf,
20277b55e8cSThomas Abraham 		.phy1_pulld_dqs = 0xf,
20377b55e8cSThomas Abraham 
20477b55e8cSThomas Abraham 		.lpddr3_ctrl_phy_reset = 0x1,
20577b55e8cSThomas Abraham 		.ctrl_start_point = 0x10,
20677b55e8cSThomas Abraham 		.ctrl_inc = 0x10,
20777b55e8cSThomas Abraham 		.ctrl_start = 0x1,
20877b55e8cSThomas Abraham 		.ctrl_dll_on = 0x1,
20977b55e8cSThomas Abraham 		.ctrl_ref = 0x8,
21077b55e8cSThomas Abraham 
21177b55e8cSThomas Abraham 		.ctrl_force = 0x1a,
21277b55e8cSThomas Abraham 		.ctrl_rdlat = 0x0b,
21377b55e8cSThomas Abraham 		.ctrl_bstlen = 0x08,
21477b55e8cSThomas Abraham 
21577b55e8cSThomas Abraham 		.fp_resync = 0x8,
21677b55e8cSThomas Abraham 		.iv_size = 0x7,
21777b55e8cSThomas Abraham 		.dfi_init_start = 1,
21877b55e8cSThomas Abraham 		.aref_en = 1,
21977b55e8cSThomas Abraham 
22077b55e8cSThomas Abraham 		.rd_fetch = 0x3,
22177b55e8cSThomas Abraham 
22277b55e8cSThomas Abraham 		.zq_mode_dds = 0x7,
22377b55e8cSThomas Abraham 		.zq_mode_term = 0x1,
22477b55e8cSThomas Abraham 		.zq_mode_noterm = 1,
22577b55e8cSThomas Abraham 
22677b55e8cSThomas Abraham 		/*
22777b55e8cSThomas Abraham 		* Dynamic Clock: Always Running
22877b55e8cSThomas Abraham 		* Memory Burst length: 8
22977b55e8cSThomas Abraham 		* Number of chips: 1
23077b55e8cSThomas Abraham 		* Memory Bus width: 32 bit
23177b55e8cSThomas Abraham 		* Memory Type: DDR3
23277b55e8cSThomas Abraham 		* Additional Latancy for PLL: 0 Cycle
23377b55e8cSThomas Abraham 		*/
23477b55e8cSThomas Abraham 		.memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
23577b55e8cSThomas Abraham 			DMC_MEMCONTROL_DPWRDN_DISABLE |
23677b55e8cSThomas Abraham 			DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
23777b55e8cSThomas Abraham 			DMC_MEMCONTROL_TP_DISABLE |
23877b55e8cSThomas Abraham 			DMC_MEMCONTROL_DSREF_DISABLE |
23977b55e8cSThomas Abraham 			DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
24077b55e8cSThomas Abraham 			DMC_MEMCONTROL_MEM_TYPE_DDR3 |
24177b55e8cSThomas Abraham 			DMC_MEMCONTROL_MEM_WIDTH_32BIT |
24277b55e8cSThomas Abraham 			DMC_MEMCONTROL_NUM_CHIP_1 |
24377b55e8cSThomas Abraham 			DMC_MEMCONTROL_BL_8 |
24477b55e8cSThomas Abraham 			DMC_MEMCONTROL_PZQ_DISABLE |
24577b55e8cSThomas Abraham 			DMC_MEMCONTROL_MRR_BYTE_7_0,
24677b55e8cSThomas Abraham 		.memconfig = DMC_MEMCONFIG_CHIP_MAP_SPLIT |
24777b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_COL_10 |
24877b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_ROW_15 |
24977b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_BANK_8,
25077b55e8cSThomas Abraham 		.prechconfig_tp_cnt = 0xff,
25177b55e8cSThomas Abraham 		.dpwrdn_cyc = 0xff,
25277b55e8cSThomas Abraham 		.dsref_cyc = 0xffff,
25377b55e8cSThomas Abraham 		.concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
25477b55e8cSThomas Abraham 			DMC_CONCONTROL_TIMEOUT_LEVEL0 |
25577b55e8cSThomas Abraham 			DMC_CONCONTROL_RD_FETCH_DISABLE |
25677b55e8cSThomas Abraham 			DMC_CONCONTROL_EMPTY_DISABLE |
25777b55e8cSThomas Abraham 			DMC_CONCONTROL_AREF_EN_DISABLE |
25877b55e8cSThomas Abraham 			DMC_CONCONTROL_IO_PD_CON_DISABLE,
25977b55e8cSThomas Abraham 		.dmc_channels = 1,
26077b55e8cSThomas Abraham 		.chips_per_channel = 1,
26177b55e8cSThomas Abraham 		.chips_to_configure = 1,
26277b55e8cSThomas Abraham 		.send_zq_init = 1,
26377b55e8cSThomas Abraham 		.gate_leveling_enable = 1,
26477b55e8cSThomas Abraham 		.read_leveling_enable = 0,
26577b55e8cSThomas Abraham 	}
26677b55e8cSThomas Abraham #else
26777b55e8cSThomas Abraham 	{
26877b55e8cSThomas Abraham 		.mem_manuf = MEM_MANUF_ELPIDA,
26977b55e8cSThomas Abraham 		.mem_type = DDR_MODE_DDR3,
27077b55e8cSThomas Abraham 		.frequency_mhz = 800,
27177b55e8cSThomas Abraham 		.mpll_mdiv = 0xc8,
27277b55e8cSThomas Abraham 		.mpll_pdiv = 0x3,
27377b55e8cSThomas Abraham 		.mpll_sdiv = 0x0,
27477b55e8cSThomas Abraham 		.cpll_mdiv = 0xde,
27577b55e8cSThomas Abraham 		.cpll_pdiv = 0x4,
27677b55e8cSThomas Abraham 		.cpll_sdiv = 0x2,
27777b55e8cSThomas Abraham 		.gpll_mdiv = 0x215,
27877b55e8cSThomas Abraham 		.gpll_pdiv = 0xc,
27977b55e8cSThomas Abraham 		.gpll_sdiv = 0x1,
28077b55e8cSThomas Abraham 		.epll_mdiv = 0x60,
28177b55e8cSThomas Abraham 		.epll_pdiv = 0x3,
28277b55e8cSThomas Abraham 		.epll_sdiv = 0x3,
28377b55e8cSThomas Abraham 		.vpll_mdiv = 0x96,
28477b55e8cSThomas Abraham 		.vpll_pdiv = 0x3,
28577b55e8cSThomas Abraham 		.vpll_sdiv = 0x2,
28677b55e8cSThomas Abraham 
28777b55e8cSThomas Abraham 		.bpll_mdiv = 0x64,
28877b55e8cSThomas Abraham 		.bpll_pdiv = 0x3,
28977b55e8cSThomas Abraham 		.bpll_sdiv = 0x0,
29077b55e8cSThomas Abraham 		.pclk_cdrex_ratio = 0x5,
29177b55e8cSThomas Abraham 		.direct_cmd_msr = {
29277b55e8cSThomas Abraham 			0x00020018, 0x00030000, 0x00010042, 0x00000d70
29377b55e8cSThomas Abraham 		},
29477b55e8cSThomas Abraham 		.timing_ref = 0x000000bb,
29577b55e8cSThomas Abraham 		.timing_row = 0x8c36650e,
29677b55e8cSThomas Abraham 		.timing_data = 0x3630580b,
29777b55e8cSThomas Abraham 		.timing_power = 0x41000a44,
29877b55e8cSThomas Abraham 		.phy0_dqs = 0x08080808,
29977b55e8cSThomas Abraham 		.phy1_dqs = 0x08080808,
30077b55e8cSThomas Abraham 		.phy0_dq = 0x08080808,
30177b55e8cSThomas Abraham 		.phy1_dq = 0x08080808,
30277b55e8cSThomas Abraham 		.phy0_tFS = 0x4,
30377b55e8cSThomas Abraham 		.phy1_tFS = 0x4,
30477b55e8cSThomas Abraham 		.phy0_pulld_dqs = 0xf,
30577b55e8cSThomas Abraham 		.phy1_pulld_dqs = 0xf,
30677b55e8cSThomas Abraham 
30777b55e8cSThomas Abraham 		.lpddr3_ctrl_phy_reset = 0x1,
30877b55e8cSThomas Abraham 		.ctrl_start_point = 0x10,
30977b55e8cSThomas Abraham 		.ctrl_inc = 0x10,
31077b55e8cSThomas Abraham 		.ctrl_start = 0x1,
31177b55e8cSThomas Abraham 		.ctrl_dll_on = 0x1,
31277b55e8cSThomas Abraham 		.ctrl_ref = 0x8,
31377b55e8cSThomas Abraham 
31477b55e8cSThomas Abraham 		.ctrl_force = 0x1a,
31577b55e8cSThomas Abraham 		.ctrl_rdlat = 0x0b,
31677b55e8cSThomas Abraham 		.ctrl_bstlen = 0x08,
31777b55e8cSThomas Abraham 
31877b55e8cSThomas Abraham 		.fp_resync = 0x8,
31977b55e8cSThomas Abraham 		.iv_size = 0x7,
32077b55e8cSThomas Abraham 		.dfi_init_start = 1,
32177b55e8cSThomas Abraham 		.aref_en = 1,
32277b55e8cSThomas Abraham 
32377b55e8cSThomas Abraham 		.rd_fetch = 0x3,
32477b55e8cSThomas Abraham 
32577b55e8cSThomas Abraham 		.zq_mode_dds = 0x7,
32677b55e8cSThomas Abraham 		.zq_mode_term = 0x1,
32777b55e8cSThomas Abraham 		.zq_mode_noterm = 0,
32877b55e8cSThomas Abraham 
32977b55e8cSThomas Abraham 		/*
33077b55e8cSThomas Abraham 		* Dynamic Clock: Always Running
33177b55e8cSThomas Abraham 		* Memory Burst length: 8
33277b55e8cSThomas Abraham 		* Number of chips: 1
33377b55e8cSThomas Abraham 		* Memory Bus width: 32 bit
33477b55e8cSThomas Abraham 		* Memory Type: DDR3
33577b55e8cSThomas Abraham 		* Additional Latancy for PLL: 0 Cycle
33677b55e8cSThomas Abraham 		*/
33777b55e8cSThomas Abraham 		.memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
33877b55e8cSThomas Abraham 			DMC_MEMCONTROL_DPWRDN_DISABLE |
33977b55e8cSThomas Abraham 			DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
34077b55e8cSThomas Abraham 			DMC_MEMCONTROL_TP_DISABLE |
34177b55e8cSThomas Abraham 			DMC_MEMCONTROL_DSREF_ENABLE |
34277b55e8cSThomas Abraham 			DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
34377b55e8cSThomas Abraham 			DMC_MEMCONTROL_MEM_TYPE_DDR3 |
34477b55e8cSThomas Abraham 			DMC_MEMCONTROL_MEM_WIDTH_32BIT |
34577b55e8cSThomas Abraham 			DMC_MEMCONTROL_NUM_CHIP_1 |
34677b55e8cSThomas Abraham 			DMC_MEMCONTROL_BL_8 |
34777b55e8cSThomas Abraham 			DMC_MEMCONTROL_PZQ_DISABLE |
34877b55e8cSThomas Abraham 			DMC_MEMCONTROL_MRR_BYTE_7_0,
34977b55e8cSThomas Abraham 		.memconfig = DMC_MEMCONFIGX_CHIP_MAP_INTERLEAVED |
35077b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_COL_10 |
35177b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_ROW_15 |
35277b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_BANK_8,
35377b55e8cSThomas Abraham 		.membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
35477b55e8cSThomas Abraham 		.membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
35577b55e8cSThomas Abraham 		.prechconfig_tp_cnt = 0xff,
35677b55e8cSThomas Abraham 		.dpwrdn_cyc = 0xff,
35777b55e8cSThomas Abraham 		.dsref_cyc = 0xffff,
35877b55e8cSThomas Abraham 		.concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
35977b55e8cSThomas Abraham 			DMC_CONCONTROL_TIMEOUT_LEVEL0 |
36077b55e8cSThomas Abraham 			DMC_CONCONTROL_RD_FETCH_DISABLE |
36177b55e8cSThomas Abraham 			DMC_CONCONTROL_EMPTY_DISABLE |
36277b55e8cSThomas Abraham 			DMC_CONCONTROL_AREF_EN_DISABLE |
36377b55e8cSThomas Abraham 			DMC_CONCONTROL_IO_PD_CON_DISABLE,
36477b55e8cSThomas Abraham 		.dmc_channels = 2,
36577b55e8cSThomas Abraham 		.chips_per_channel = 2,
36677b55e8cSThomas Abraham 		.chips_to_configure = 1,
36777b55e8cSThomas Abraham 		.send_zq_init = 1,
36877b55e8cSThomas Abraham 		.impedance = IMP_OUTPUT_DRV_30_OHM,
36977b55e8cSThomas Abraham 		.gate_leveling_enable = 0,
37077b55e8cSThomas Abraham 	}, {
37177b55e8cSThomas Abraham 		.mem_manuf = MEM_MANUF_SAMSUNG,
37277b55e8cSThomas Abraham 		.mem_type = DDR_MODE_DDR3,
37377b55e8cSThomas Abraham 		.frequency_mhz = 800,
37477b55e8cSThomas Abraham 		.mpll_mdiv = 0xc8,
37577b55e8cSThomas Abraham 		.mpll_pdiv = 0x3,
37677b55e8cSThomas Abraham 		.mpll_sdiv = 0x0,
37777b55e8cSThomas Abraham 		.cpll_mdiv = 0xde,
37877b55e8cSThomas Abraham 		.cpll_pdiv = 0x4,
37977b55e8cSThomas Abraham 		.cpll_sdiv = 0x2,
38077b55e8cSThomas Abraham 		.gpll_mdiv = 0x215,
38177b55e8cSThomas Abraham 		.gpll_pdiv = 0xc,
38277b55e8cSThomas Abraham 		.gpll_sdiv = 0x1,
38377b55e8cSThomas Abraham 		.epll_mdiv = 0x60,
38477b55e8cSThomas Abraham 		.epll_pdiv = 0x3,
38577b55e8cSThomas Abraham 		.epll_sdiv = 0x3,
38677b55e8cSThomas Abraham 		.vpll_mdiv = 0x96,
38777b55e8cSThomas Abraham 		.vpll_pdiv = 0x3,
38877b55e8cSThomas Abraham 		.vpll_sdiv = 0x2,
38977b55e8cSThomas Abraham 
39077b55e8cSThomas Abraham 		.bpll_mdiv = 0x64,
39177b55e8cSThomas Abraham 		.bpll_pdiv = 0x3,
39277b55e8cSThomas Abraham 		.bpll_sdiv = 0x0,
39377b55e8cSThomas Abraham 		.pclk_cdrex_ratio = 0x5,
39477b55e8cSThomas Abraham 		.direct_cmd_msr = {
39577b55e8cSThomas Abraham 			0x00020018, 0x00030000, 0x00010000, 0x00000d70
39677b55e8cSThomas Abraham 		},
39777b55e8cSThomas Abraham 		.timing_ref = 0x000000bb,
39877b55e8cSThomas Abraham 		.timing_row = 0x8c36650e,
39977b55e8cSThomas Abraham 		.timing_data = 0x3630580b,
40077b55e8cSThomas Abraham 		.timing_power = 0x41000a44,
40177b55e8cSThomas Abraham 		.phy0_dqs = 0x08080808,
40277b55e8cSThomas Abraham 		.phy1_dqs = 0x08080808,
40377b55e8cSThomas Abraham 		.phy0_dq = 0x08080808,
40477b55e8cSThomas Abraham 		.phy1_dq = 0x08080808,
40577b55e8cSThomas Abraham 		.phy0_tFS = 0x8,
40677b55e8cSThomas Abraham 		.phy1_tFS = 0x8,
40777b55e8cSThomas Abraham 		.phy0_pulld_dqs = 0xf,
40877b55e8cSThomas Abraham 		.phy1_pulld_dqs = 0xf,
40977b55e8cSThomas Abraham 
41077b55e8cSThomas Abraham 		.lpddr3_ctrl_phy_reset = 0x1,
41177b55e8cSThomas Abraham 		.ctrl_start_point = 0x10,
41277b55e8cSThomas Abraham 		.ctrl_inc = 0x10,
41377b55e8cSThomas Abraham 		.ctrl_start = 0x1,
41477b55e8cSThomas Abraham 		.ctrl_dll_on = 0x1,
41577b55e8cSThomas Abraham 		.ctrl_ref = 0x8,
41677b55e8cSThomas Abraham 
41777b55e8cSThomas Abraham 		.ctrl_force = 0x1a,
41877b55e8cSThomas Abraham 		.ctrl_rdlat = 0x0b,
41977b55e8cSThomas Abraham 		.ctrl_bstlen = 0x08,
42077b55e8cSThomas Abraham 
42177b55e8cSThomas Abraham 		.fp_resync = 0x8,
42277b55e8cSThomas Abraham 		.iv_size = 0x7,
42377b55e8cSThomas Abraham 		.dfi_init_start = 1,
42477b55e8cSThomas Abraham 		.aref_en = 1,
42577b55e8cSThomas Abraham 
42677b55e8cSThomas Abraham 		.rd_fetch = 0x3,
42777b55e8cSThomas Abraham 
42877b55e8cSThomas Abraham 		.zq_mode_dds = 0x5,
42977b55e8cSThomas Abraham 		.zq_mode_term = 0x1,
43077b55e8cSThomas Abraham 		.zq_mode_noterm = 1,
43177b55e8cSThomas Abraham 
43277b55e8cSThomas Abraham 		/*
43377b55e8cSThomas Abraham 		* Dynamic Clock: Always Running
43477b55e8cSThomas Abraham 		* Memory Burst length: 8
43577b55e8cSThomas Abraham 		* Number of chips: 1
43677b55e8cSThomas Abraham 		* Memory Bus width: 32 bit
43777b55e8cSThomas Abraham 		* Memory Type: DDR3
43877b55e8cSThomas Abraham 		* Additional Latancy for PLL: 0 Cycle
43977b55e8cSThomas Abraham 		*/
44077b55e8cSThomas Abraham 		.memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
44177b55e8cSThomas Abraham 			DMC_MEMCONTROL_DPWRDN_DISABLE |
44277b55e8cSThomas Abraham 			DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
44377b55e8cSThomas Abraham 			DMC_MEMCONTROL_TP_DISABLE |
44477b55e8cSThomas Abraham 			DMC_MEMCONTROL_DSREF_ENABLE |
44577b55e8cSThomas Abraham 			DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
44677b55e8cSThomas Abraham 			DMC_MEMCONTROL_MEM_TYPE_DDR3 |
44777b55e8cSThomas Abraham 			DMC_MEMCONTROL_MEM_WIDTH_32BIT |
44877b55e8cSThomas Abraham 			DMC_MEMCONTROL_NUM_CHIP_1 |
44977b55e8cSThomas Abraham 			DMC_MEMCONTROL_BL_8 |
45077b55e8cSThomas Abraham 			DMC_MEMCONTROL_PZQ_DISABLE |
45177b55e8cSThomas Abraham 			DMC_MEMCONTROL_MRR_BYTE_7_0,
45277b55e8cSThomas Abraham 		.memconfig = DMC_MEMCONFIGX_CHIP_MAP_INTERLEAVED |
45377b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_COL_10 |
45477b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_ROW_15 |
45577b55e8cSThomas Abraham 			DMC_MEMCONFIGX_CHIP_BANK_8,
45677b55e8cSThomas Abraham 		.membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
45777b55e8cSThomas Abraham 		.membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
45877b55e8cSThomas Abraham 		.prechconfig_tp_cnt = 0xff,
45977b55e8cSThomas Abraham 		.dpwrdn_cyc = 0xff,
46077b55e8cSThomas Abraham 		.dsref_cyc = 0xffff,
46177b55e8cSThomas Abraham 		.concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
46277b55e8cSThomas Abraham 			DMC_CONCONTROL_TIMEOUT_LEVEL0 |
46377b55e8cSThomas Abraham 			DMC_CONCONTROL_RD_FETCH_DISABLE |
46477b55e8cSThomas Abraham 			DMC_CONCONTROL_EMPTY_DISABLE |
46577b55e8cSThomas Abraham 			DMC_CONCONTROL_AREF_EN_DISABLE |
46677b55e8cSThomas Abraham 			DMC_CONCONTROL_IO_PD_CON_DISABLE,
46777b55e8cSThomas Abraham 		.dmc_channels = 2,
46877b55e8cSThomas Abraham 		.chips_per_channel = 2,
46977b55e8cSThomas Abraham 		.chips_to_configure = 1,
47077b55e8cSThomas Abraham 		.send_zq_init = 1,
47177b55e8cSThomas Abraham 		.impedance = IMP_OUTPUT_DRV_40_OHM,
47277b55e8cSThomas Abraham 		.gate_leveling_enable = 1,
47377b55e8cSThomas Abraham 	}
47477b55e8cSThomas Abraham #endif
47577b55e8cSThomas Abraham };
47677b55e8cSThomas Abraham 
47777b55e8cSThomas Abraham /**
47877b55e8cSThomas Abraham  * Get the required memory type and speed (SPL version).
47977b55e8cSThomas Abraham  *
48077b55e8cSThomas Abraham  * In SPL we have no device tree, so we use the machine parameters
48177b55e8cSThomas Abraham  *
48277b55e8cSThomas Abraham  * @param mem_type	Returns memory type
48377b55e8cSThomas Abraham  * @param frequency_mhz	Returns memory speed in MHz
48477b55e8cSThomas Abraham  * @param arm_freq	Returns ARM clock speed in MHz
48577b55e8cSThomas Abraham  * @param mem_manuf	Return Memory Manufacturer name
48677b55e8cSThomas Abraham  */
clock_get_mem_selection(enum ddr_mode * mem_type,unsigned * frequency_mhz,unsigned * arm_freq,enum mem_manuf * mem_manuf)48777b55e8cSThomas Abraham static void clock_get_mem_selection(enum ddr_mode *mem_type,
48877b55e8cSThomas Abraham 		unsigned *frequency_mhz, unsigned *arm_freq,
48977b55e8cSThomas Abraham 		enum mem_manuf *mem_manuf)
49077b55e8cSThomas Abraham {
49177b55e8cSThomas Abraham 	struct spl_machine_param *params;
49277b55e8cSThomas Abraham 
49377b55e8cSThomas Abraham 	params = spl_get_machine_params();
49477b55e8cSThomas Abraham 	*mem_type = params->mem_type;
49577b55e8cSThomas Abraham 	*frequency_mhz = params->frequency_mhz;
49677b55e8cSThomas Abraham 	*arm_freq = params->arm_freq_mhz;
49777b55e8cSThomas Abraham 	*mem_manuf = params->mem_manuf;
49877b55e8cSThomas Abraham }
49977b55e8cSThomas Abraham 
50077b55e8cSThomas Abraham /* Get the ratios for setting ARM clock */
get_arm_ratios(void)50177b55e8cSThomas Abraham struct arm_clk_ratios *get_arm_ratios(void)
50277b55e8cSThomas Abraham {
50377b55e8cSThomas Abraham 	struct arm_clk_ratios *arm_ratio;
50477b55e8cSThomas Abraham 	enum ddr_mode mem_type;
50577b55e8cSThomas Abraham 	enum mem_manuf mem_manuf;
50677b55e8cSThomas Abraham 	unsigned frequency_mhz, arm_freq;
50777b55e8cSThomas Abraham 	int i;
50877b55e8cSThomas Abraham 
50977b55e8cSThomas Abraham 	clock_get_mem_selection(&mem_type, &frequency_mhz,
51077b55e8cSThomas Abraham 				&arm_freq, &mem_manuf);
51177b55e8cSThomas Abraham 
51277b55e8cSThomas Abraham 	for (i = 0, arm_ratio = arm_clk_ratios; i < ARRAY_SIZE(arm_clk_ratios);
51377b55e8cSThomas Abraham 		i++, arm_ratio++) {
51477b55e8cSThomas Abraham 		if (arm_ratio->arm_freq_mhz == arm_freq)
51577b55e8cSThomas Abraham 			return arm_ratio;
51677b55e8cSThomas Abraham 	}
51777b55e8cSThomas Abraham 
51877b55e8cSThomas Abraham 	/* will hang if failed to find clock ratio */
51977b55e8cSThomas Abraham 	while (1)
52077b55e8cSThomas Abraham 		;
52177b55e8cSThomas Abraham 
52277b55e8cSThomas Abraham 	return NULL;
52377b55e8cSThomas Abraham }
52477b55e8cSThomas Abraham 
clock_get_mem_timings(void)52577b55e8cSThomas Abraham struct mem_timings *clock_get_mem_timings(void)
52677b55e8cSThomas Abraham {
52777b55e8cSThomas Abraham 	struct mem_timings *mem;
52877b55e8cSThomas Abraham 	enum ddr_mode mem_type;
52977b55e8cSThomas Abraham 	enum mem_manuf mem_manuf;
53077b55e8cSThomas Abraham 	unsigned frequency_mhz, arm_freq;
53177b55e8cSThomas Abraham 	int i;
53277b55e8cSThomas Abraham 
53377b55e8cSThomas Abraham 	clock_get_mem_selection(&mem_type, &frequency_mhz,
53477b55e8cSThomas Abraham 				&arm_freq, &mem_manuf);
53577b55e8cSThomas Abraham 	for (i = 0, mem = mem_timings; i < ARRAY_SIZE(mem_timings);
53677b55e8cSThomas Abraham 	     i++, mem++) {
53777b55e8cSThomas Abraham 		if (mem->mem_type == mem_type &&
53877b55e8cSThomas Abraham 		    mem->frequency_mhz == frequency_mhz &&
53977b55e8cSThomas Abraham 		    mem->mem_manuf == mem_manuf)
54077b55e8cSThomas Abraham 			return mem;
54177b55e8cSThomas Abraham 	}
54277b55e8cSThomas Abraham 
54377b55e8cSThomas Abraham 	/* will hang if failed to find memory timings */
54477b55e8cSThomas Abraham 	while (1)
54577b55e8cSThomas Abraham 		;
54677b55e8cSThomas Abraham 
54777b55e8cSThomas Abraham 	return NULL;
54877b55e8cSThomas Abraham }
54977b55e8cSThomas Abraham 
exynos5250_system_clock_init(void)55077b55e8cSThomas Abraham static void exynos5250_system_clock_init(void)
55177b55e8cSThomas Abraham {
55277b55e8cSThomas Abraham 	struct exynos5_clock *clk =
55377b55e8cSThomas Abraham 		(struct exynos5_clock *)samsung_get_base_clock();
55477b55e8cSThomas Abraham 	struct mem_timings *mem;
55577b55e8cSThomas Abraham 	struct arm_clk_ratios *arm_clk_ratio;
55677b55e8cSThomas Abraham 	u32 val, tmp;
55777b55e8cSThomas Abraham 
55877b55e8cSThomas Abraham 	mem = clock_get_mem_timings();
55977b55e8cSThomas Abraham 	arm_clk_ratio = get_arm_ratios();
56077b55e8cSThomas Abraham 
56177b55e8cSThomas Abraham 	clrbits_le32(&clk->src_cpu, MUX_APLL_SEL_MASK);
56277b55e8cSThomas Abraham 	do {
56377b55e8cSThomas Abraham 		val = readl(&clk->mux_stat_cpu);
56477b55e8cSThomas Abraham 	} while ((val | MUX_APLL_SEL_MASK) != val);
56577b55e8cSThomas Abraham 
56677b55e8cSThomas Abraham 	clrbits_le32(&clk->src_core1, MUX_MPLL_SEL_MASK);
56777b55e8cSThomas Abraham 	do {
56877b55e8cSThomas Abraham 		val = readl(&clk->mux_stat_core1);
56977b55e8cSThomas Abraham 	} while ((val | MUX_MPLL_SEL_MASK) != val);
57077b55e8cSThomas Abraham 
57177b55e8cSThomas Abraham 	clrbits_le32(&clk->src_top2, MUX_CPLL_SEL_MASK);
57277b55e8cSThomas Abraham 	clrbits_le32(&clk->src_top2, MUX_EPLL_SEL_MASK);
57377b55e8cSThomas Abraham 	clrbits_le32(&clk->src_top2, MUX_VPLL_SEL_MASK);
57477b55e8cSThomas Abraham 	clrbits_le32(&clk->src_top2, MUX_GPLL_SEL_MASK);
57577b55e8cSThomas Abraham 	tmp = MUX_CPLL_SEL_MASK | MUX_EPLL_SEL_MASK | MUX_VPLL_SEL_MASK
57677b55e8cSThomas Abraham 		| MUX_GPLL_SEL_MASK;
57777b55e8cSThomas Abraham 	do {
57877b55e8cSThomas Abraham 		val = readl(&clk->mux_stat_top2);
57977b55e8cSThomas Abraham 	} while ((val | tmp) != val);
58077b55e8cSThomas Abraham 
58177b55e8cSThomas Abraham 	clrbits_le32(&clk->src_cdrex, MUX_BPLL_SEL_MASK);
58277b55e8cSThomas Abraham 	do {
58377b55e8cSThomas Abraham 		val = readl(&clk->mux_stat_cdrex);
58477b55e8cSThomas Abraham 	} while ((val | MUX_BPLL_SEL_MASK) != val);
58577b55e8cSThomas Abraham 
58677b55e8cSThomas Abraham 	/* PLL locktime */
58777b55e8cSThomas Abraham 	writel(mem->apll_pdiv * PLL_LOCK_FACTOR, &clk->apll_lock);
58877b55e8cSThomas Abraham 	writel(mem->mpll_pdiv * PLL_LOCK_FACTOR, &clk->mpll_lock);
58977b55e8cSThomas Abraham 	writel(mem->bpll_pdiv * PLL_LOCK_FACTOR, &clk->bpll_lock);
59077b55e8cSThomas Abraham 	writel(mem->cpll_pdiv * PLL_LOCK_FACTOR, &clk->cpll_lock);
59177b55e8cSThomas Abraham 	writel(mem->gpll_pdiv * PLL_X_LOCK_FACTOR, &clk->gpll_lock);
59277b55e8cSThomas Abraham 	writel(mem->epll_pdiv * PLL_X_LOCK_FACTOR, &clk->epll_lock);
59377b55e8cSThomas Abraham 	writel(mem->vpll_pdiv * PLL_X_LOCK_FACTOR, &clk->vpll_lock);
59477b55e8cSThomas Abraham 
59577b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->pll_div2_sel);
59677b55e8cSThomas Abraham 
59777b55e8cSThomas Abraham 	writel(MUX_HPM_SEL_MASK, &clk->src_cpu);
59877b55e8cSThomas Abraham 	do {
59977b55e8cSThomas Abraham 		val = readl(&clk->mux_stat_cpu);
60077b55e8cSThomas Abraham 	} while ((val | HPM_SEL_SCLK_MPLL) != val);
60177b55e8cSThomas Abraham 
60277b55e8cSThomas Abraham 	val = arm_clk_ratio->arm2_ratio << 28
60377b55e8cSThomas Abraham 		| arm_clk_ratio->apll_ratio << 24
60477b55e8cSThomas Abraham 		| arm_clk_ratio->pclk_dbg_ratio << 20
60577b55e8cSThomas Abraham 		| arm_clk_ratio->atb_ratio << 16
60677b55e8cSThomas Abraham 		| arm_clk_ratio->periph_ratio << 12
60777b55e8cSThomas Abraham 		| arm_clk_ratio->acp_ratio << 8
60877b55e8cSThomas Abraham 		| arm_clk_ratio->cpud_ratio << 4
60977b55e8cSThomas Abraham 		| arm_clk_ratio->arm_ratio;
61077b55e8cSThomas Abraham 	writel(val, &clk->div_cpu0);
61177b55e8cSThomas Abraham 	do {
61277b55e8cSThomas Abraham 		val = readl(&clk->div_stat_cpu0);
61377b55e8cSThomas Abraham 	} while (0 != val);
61477b55e8cSThomas Abraham 
61577b55e8cSThomas Abraham 	writel(CLK_DIV_CPU1_VAL, &clk->div_cpu1);
61677b55e8cSThomas Abraham 	do {
61777b55e8cSThomas Abraham 		val = readl(&clk->div_stat_cpu1);
61877b55e8cSThomas Abraham 	} while (0 != val);
61977b55e8cSThomas Abraham 
62077b55e8cSThomas Abraham 	/* Set APLL */
62177b55e8cSThomas Abraham 	writel(APLL_CON1_VAL, &clk->apll_con1);
62277b55e8cSThomas Abraham 	val = set_pll(arm_clk_ratio->apll_mdiv, arm_clk_ratio->apll_pdiv,
62377b55e8cSThomas Abraham 			arm_clk_ratio->apll_sdiv);
62477b55e8cSThomas Abraham 	writel(val, &clk->apll_con0);
62577b55e8cSThomas Abraham 	while ((readl(&clk->apll_con0) & APLL_CON0_LOCKED) == 0)
62677b55e8cSThomas Abraham 		;
62777b55e8cSThomas Abraham 
62877b55e8cSThomas Abraham 	/* Set MPLL */
62977b55e8cSThomas Abraham 	writel(MPLL_CON1_VAL, &clk->mpll_con1);
63077b55e8cSThomas Abraham 	val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv);
63177b55e8cSThomas Abraham 	writel(val, &clk->mpll_con0);
63277b55e8cSThomas Abraham 	while ((readl(&clk->mpll_con0) & MPLL_CON0_LOCKED) == 0)
63377b55e8cSThomas Abraham 		;
63477b55e8cSThomas Abraham 
63577b55e8cSThomas Abraham 	/* Set BPLL */
63677b55e8cSThomas Abraham 	writel(BPLL_CON1_VAL, &clk->bpll_con1);
63777b55e8cSThomas Abraham 	val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv);
63877b55e8cSThomas Abraham 	writel(val, &clk->bpll_con0);
63977b55e8cSThomas Abraham 	while ((readl(&clk->bpll_con0) & BPLL_CON0_LOCKED) == 0)
64077b55e8cSThomas Abraham 		;
64177b55e8cSThomas Abraham 
64277b55e8cSThomas Abraham 	/* Set CPLL */
64377b55e8cSThomas Abraham 	writel(CPLL_CON1_VAL, &clk->cpll_con1);
64477b55e8cSThomas Abraham 	val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv);
64577b55e8cSThomas Abraham 	writel(val, &clk->cpll_con0);
64677b55e8cSThomas Abraham 	while ((readl(&clk->cpll_con0) & CPLL_CON0_LOCKED) == 0)
64777b55e8cSThomas Abraham 		;
64877b55e8cSThomas Abraham 
64977b55e8cSThomas Abraham 	/* Set GPLL */
65077b55e8cSThomas Abraham 	writel(GPLL_CON1_VAL, &clk->gpll_con1);
65177b55e8cSThomas Abraham 	val = set_pll(mem->gpll_mdiv, mem->gpll_pdiv, mem->gpll_sdiv);
65277b55e8cSThomas Abraham 	writel(val, &clk->gpll_con0);
65377b55e8cSThomas Abraham 	while ((readl(&clk->gpll_con0) & GPLL_CON0_LOCKED) == 0)
65477b55e8cSThomas Abraham 		;
65577b55e8cSThomas Abraham 
65677b55e8cSThomas Abraham 	/* Set EPLL */
65777b55e8cSThomas Abraham 	writel(EPLL_CON2_VAL, &clk->epll_con2);
65877b55e8cSThomas Abraham 	writel(EPLL_CON1_VAL, &clk->epll_con1);
65977b55e8cSThomas Abraham 	val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv);
66077b55e8cSThomas Abraham 	writel(val, &clk->epll_con0);
66177b55e8cSThomas Abraham 	while ((readl(&clk->epll_con0) & EPLL_CON0_LOCKED) == 0)
66277b55e8cSThomas Abraham 		;
66377b55e8cSThomas Abraham 
66477b55e8cSThomas Abraham 	/* Set VPLL */
66577b55e8cSThomas Abraham 	writel(VPLL_CON2_VAL, &clk->vpll_con2);
66677b55e8cSThomas Abraham 	writel(VPLL_CON1_VAL, &clk->vpll_con1);
66777b55e8cSThomas Abraham 	val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv);
66877b55e8cSThomas Abraham 	writel(val, &clk->vpll_con0);
66977b55e8cSThomas Abraham 	while ((readl(&clk->vpll_con0) & VPLL_CON0_LOCKED) == 0)
67077b55e8cSThomas Abraham 		;
67177b55e8cSThomas Abraham 
67277b55e8cSThomas Abraham 	writel(CLK_SRC_CORE0_VAL, &clk->src_core0);
67377b55e8cSThomas Abraham 	writel(CLK_DIV_CORE0_VAL, &clk->div_core0);
67477b55e8cSThomas Abraham 	while (readl(&clk->div_stat_core0) != 0)
67577b55e8cSThomas Abraham 		;
67677b55e8cSThomas Abraham 
67777b55e8cSThomas Abraham 	writel(CLK_DIV_CORE1_VAL, &clk->div_core1);
67877b55e8cSThomas Abraham 	while (readl(&clk->div_stat_core1) != 0)
67977b55e8cSThomas Abraham 		;
68077b55e8cSThomas Abraham 
68177b55e8cSThomas Abraham 	writel(CLK_DIV_SYSRGT_VAL, &clk->div_sysrgt);
68277b55e8cSThomas Abraham 	while (readl(&clk->div_stat_sysrgt) != 0)
68377b55e8cSThomas Abraham 		;
68477b55e8cSThomas Abraham 
68577b55e8cSThomas Abraham 	writel(CLK_DIV_ACP_VAL, &clk->div_acp);
68677b55e8cSThomas Abraham 	while (readl(&clk->div_stat_acp) != 0)
68777b55e8cSThomas Abraham 		;
68877b55e8cSThomas Abraham 
68977b55e8cSThomas Abraham 	writel(CLK_DIV_SYSLFT_VAL, &clk->div_syslft);
69077b55e8cSThomas Abraham 	while (readl(&clk->div_stat_syslft) != 0)
69177b55e8cSThomas Abraham 		;
69277b55e8cSThomas Abraham 
69377b55e8cSThomas Abraham 	writel(CLK_SRC_TOP0_VAL, &clk->src_top0);
69477b55e8cSThomas Abraham 	writel(CLK_SRC_TOP1_VAL, &clk->src_top1);
69577b55e8cSThomas Abraham 	writel(TOP2_VAL, &clk->src_top2);
69677b55e8cSThomas Abraham 	writel(CLK_SRC_TOP3_VAL, &clk->src_top3);
69777b55e8cSThomas Abraham 
69877b55e8cSThomas Abraham 	writel(CLK_DIV_TOP0_VAL, &clk->div_top0);
69977b55e8cSThomas Abraham 	while (readl(&clk->div_stat_top0))
70077b55e8cSThomas Abraham 		;
70177b55e8cSThomas Abraham 
70277b55e8cSThomas Abraham 	writel(CLK_DIV_TOP1_VAL, &clk->div_top1);
70377b55e8cSThomas Abraham 	while (readl(&clk->div_stat_top1))
70477b55e8cSThomas Abraham 		;
70577b55e8cSThomas Abraham 
70677b55e8cSThomas Abraham 	writel(CLK_SRC_LEX_VAL, &clk->src_lex);
70777b55e8cSThomas Abraham 	while (1) {
70877b55e8cSThomas Abraham 		val = readl(&clk->mux_stat_lex);
70977b55e8cSThomas Abraham 		if (val == (val | 1))
71077b55e8cSThomas Abraham 			break;
71177b55e8cSThomas Abraham 	}
71277b55e8cSThomas Abraham 
71377b55e8cSThomas Abraham 	writel(CLK_DIV_LEX_VAL, &clk->div_lex);
71477b55e8cSThomas Abraham 	while (readl(&clk->div_stat_lex))
71577b55e8cSThomas Abraham 		;
71677b55e8cSThomas Abraham 
71777b55e8cSThomas Abraham 	writel(CLK_DIV_R0X_VAL, &clk->div_r0x);
71877b55e8cSThomas Abraham 	while (readl(&clk->div_stat_r0x))
71977b55e8cSThomas Abraham 		;
72077b55e8cSThomas Abraham 
72177b55e8cSThomas Abraham 	writel(CLK_DIV_R0X_VAL, &clk->div_r0x);
72277b55e8cSThomas Abraham 	while (readl(&clk->div_stat_r0x))
72377b55e8cSThomas Abraham 		;
72477b55e8cSThomas Abraham 
72577b55e8cSThomas Abraham 	writel(CLK_DIV_R1X_VAL, &clk->div_r1x);
72677b55e8cSThomas Abraham 	while (readl(&clk->div_stat_r1x))
72777b55e8cSThomas Abraham 		;
72877b55e8cSThomas Abraham 
72977b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->src_cdrex);
73077b55e8cSThomas Abraham 
73177b55e8cSThomas Abraham 	writel(CLK_DIV_CDREX_VAL, &clk->div_cdrex);
73277b55e8cSThomas Abraham 	while (readl(&clk->div_stat_cdrex))
73377b55e8cSThomas Abraham 		;
73477b55e8cSThomas Abraham 
73577b55e8cSThomas Abraham 	val = readl(&clk->src_cpu);
73677b55e8cSThomas Abraham 	val |= CLK_SRC_CPU_VAL;
73777b55e8cSThomas Abraham 	writel(val, &clk->src_cpu);
73877b55e8cSThomas Abraham 
73977b55e8cSThomas Abraham 	val = readl(&clk->src_top2);
74077b55e8cSThomas Abraham 	val |= CLK_SRC_TOP2_VAL;
74177b55e8cSThomas Abraham 	writel(val, &clk->src_top2);
74277b55e8cSThomas Abraham 
74377b55e8cSThomas Abraham 	val = readl(&clk->src_core1);
74477b55e8cSThomas Abraham 	val |= CLK_SRC_CORE1_VAL;
74577b55e8cSThomas Abraham 	writel(val, &clk->src_core1);
74677b55e8cSThomas Abraham 
74777b55e8cSThomas Abraham 	writel(CLK_SRC_FSYS0_VAL, &clk->src_fsys);
74877b55e8cSThomas Abraham 	writel(CLK_DIV_FSYS0_VAL, &clk->div_fsys0);
74977b55e8cSThomas Abraham 	while (readl(&clk->div_stat_fsys0))
75077b55e8cSThomas Abraham 		;
75177b55e8cSThomas Abraham 
75277b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->clkout_cmu_cpu);
75377b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->clkout_cmu_core);
75477b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->clkout_cmu_acp);
75577b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->clkout_cmu_top);
75677b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->clkout_cmu_lex);
75777b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->clkout_cmu_r0x);
75877b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->clkout_cmu_r1x);
75977b55e8cSThomas Abraham 	writel(CLK_REG_DISABLE, &clk->clkout_cmu_cdrex);
76077b55e8cSThomas Abraham 
76177b55e8cSThomas Abraham 	writel(CLK_SRC_PERIC0_VAL, &clk->src_peric0);
76277b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC0_VAL, &clk->div_peric0);
76377b55e8cSThomas Abraham 
76477b55e8cSThomas Abraham 	writel(CLK_SRC_PERIC1_VAL, &clk->src_peric1);
76577b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC1_VAL, &clk->div_peric1);
76677b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC2_VAL, &clk->div_peric2);
76777b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC3_VAL, &clk->div_peric3);
76877b55e8cSThomas Abraham 
76977b55e8cSThomas Abraham 	writel(SCLK_SRC_ISP_VAL, &clk->sclk_src_isp);
77077b55e8cSThomas Abraham 	writel(SCLK_DIV_ISP_VAL, &clk->sclk_div_isp);
77177b55e8cSThomas Abraham 	writel(CLK_DIV_ISP0_VAL, &clk->div_isp0);
77277b55e8cSThomas Abraham 	writel(CLK_DIV_ISP1_VAL, &clk->div_isp1);
77377b55e8cSThomas Abraham 	writel(CLK_DIV_ISP2_VAL, &clk->div_isp2);
77477b55e8cSThomas Abraham 
77577b55e8cSThomas Abraham 	/* FIMD1 SRC CLK SELECTION */
77677b55e8cSThomas Abraham 	writel(CLK_SRC_DISP1_0_VAL, &clk->src_disp1_0);
77777b55e8cSThomas Abraham 
77877b55e8cSThomas Abraham 	val = MMC2_PRE_RATIO_VAL << MMC2_PRE_RATIO_OFFSET
77977b55e8cSThomas Abraham 		| MMC2_RATIO_VAL << MMC2_RATIO_OFFSET
78077b55e8cSThomas Abraham 		| MMC3_PRE_RATIO_VAL << MMC3_PRE_RATIO_OFFSET
78177b55e8cSThomas Abraham 		| MMC3_RATIO_VAL << MMC3_RATIO_OFFSET;
78277b55e8cSThomas Abraham 	writel(val, &clk->div_fsys2);
78377b55e8cSThomas Abraham }
78477b55e8cSThomas Abraham 
exynos5420_system_clock_init(void)78577b55e8cSThomas Abraham static void exynos5420_system_clock_init(void)
78677b55e8cSThomas Abraham {
78777b55e8cSThomas Abraham 	struct exynos5420_clock *clk =
78877b55e8cSThomas Abraham 		(struct exynos5420_clock *)samsung_get_base_clock();
78977b55e8cSThomas Abraham 	struct mem_timings *mem;
79077b55e8cSThomas Abraham 	struct arm_clk_ratios *arm_clk_ratio;
79177b55e8cSThomas Abraham 	u32 val;
79277b55e8cSThomas Abraham 
79377b55e8cSThomas Abraham 	mem = clock_get_mem_timings();
79477b55e8cSThomas Abraham 	arm_clk_ratio = get_arm_ratios();
79577b55e8cSThomas Abraham 
79677b55e8cSThomas Abraham 	/* PLL locktime */
79777b55e8cSThomas Abraham 	writel(arm_clk_ratio->apll_pdiv * PLL_LOCK_FACTOR, &clk->apll_lock);
79877b55e8cSThomas Abraham 	writel(mem->mpll_pdiv * PLL_LOCK_FACTOR, &clk->mpll_lock);
79977b55e8cSThomas Abraham 	writel(mem->bpll_pdiv * PLL_LOCK_FACTOR, &clk->bpll_lock);
80077b55e8cSThomas Abraham 	writel(mem->cpll_pdiv * PLL_LOCK_FACTOR, &clk->cpll_lock);
80177b55e8cSThomas Abraham 	writel(mem->dpll_pdiv * PLL_LOCK_FACTOR, &clk->dpll_lock);
80277b55e8cSThomas Abraham 	writel(mem->epll_pdiv * PLL_X_LOCK_FACTOR, &clk->epll_lock);
80377b55e8cSThomas Abraham 	writel(mem->vpll_pdiv * PLL_LOCK_FACTOR, &clk->vpll_lock);
80477b55e8cSThomas Abraham 	writel(mem->ipll_pdiv * PLL_LOCK_FACTOR, &clk->ipll_lock);
80577b55e8cSThomas Abraham 	writel(mem->spll_pdiv * PLL_LOCK_FACTOR, &clk->spll_lock);
80677b55e8cSThomas Abraham 	writel(mem->kpll_pdiv * PLL_LOCK_FACTOR, &clk->kpll_lock);
80777b55e8cSThomas Abraham 	writel(mem->rpll_pdiv * PLL_X_LOCK_FACTOR, &clk->rpll_lock);
80877b55e8cSThomas Abraham 
80977b55e8cSThomas Abraham 	setbits_le32(&clk->src_cpu, MUX_HPM_SEL_MASK);
81077b55e8cSThomas Abraham 
81177b55e8cSThomas Abraham 	writel(0, &clk->src_top6);
81277b55e8cSThomas Abraham 
81377b55e8cSThomas Abraham 	writel(0, &clk->src_cdrex);
81477b55e8cSThomas Abraham 	writel(SRC_KFC_HPM_SEL, &clk->src_kfc);
81577b55e8cSThomas Abraham 	writel(HPM_RATIO,  &clk->div_cpu1);
81677b55e8cSThomas Abraham 	writel(CLK_DIV_CPU0_VAL,  &clk->div_cpu0);
81777b55e8cSThomas Abraham 
81877b55e8cSThomas Abraham 	/* switch A15 clock source to OSC clock before changing APLL */
81977b55e8cSThomas Abraham 	clrbits_le32(&clk->src_cpu, APLL_FOUT);
82077b55e8cSThomas Abraham 
82177b55e8cSThomas Abraham 	/* Set APLL */
82277b55e8cSThomas Abraham 	writel(APLL_CON1_VAL, &clk->apll_con1);
82377b55e8cSThomas Abraham 	val = set_pll(arm_clk_ratio->apll_mdiv,
82477b55e8cSThomas Abraham 		      arm_clk_ratio->apll_pdiv,
82577b55e8cSThomas Abraham 		      arm_clk_ratio->apll_sdiv);
82677b55e8cSThomas Abraham 	writel(val, &clk->apll_con0);
82777b55e8cSThomas Abraham 	while ((readl(&clk->apll_con0) & PLL_LOCKED) == 0)
82877b55e8cSThomas Abraham 		;
82977b55e8cSThomas Abraham 
83077b55e8cSThomas Abraham 	/* now it is safe to switch to APLL */
83177b55e8cSThomas Abraham 	setbits_le32(&clk->src_cpu, APLL_FOUT);
83277b55e8cSThomas Abraham 
83377b55e8cSThomas Abraham 	writel(SRC_KFC_HPM_SEL, &clk->src_kfc);
83477b55e8cSThomas Abraham 	writel(CLK_DIV_KFC_VAL, &clk->div_kfc0);
83577b55e8cSThomas Abraham 
83677b55e8cSThomas Abraham 	/* switch A7 clock source to OSC clock before changing KPLL */
83777b55e8cSThomas Abraham 	clrbits_le32(&clk->src_kfc, KPLL_FOUT);
83877b55e8cSThomas Abraham 
83977b55e8cSThomas Abraham 	/* Set KPLL*/
84077b55e8cSThomas Abraham 	writel(KPLL_CON1_VAL, &clk->kpll_con1);
84177b55e8cSThomas Abraham 	val = set_pll(mem->kpll_mdiv, mem->kpll_pdiv, mem->kpll_sdiv);
84277b55e8cSThomas Abraham 	writel(val, &clk->kpll_con0);
84377b55e8cSThomas Abraham 	while ((readl(&clk->kpll_con0) & PLL_LOCKED) == 0)
84477b55e8cSThomas Abraham 		;
84577b55e8cSThomas Abraham 
84677b55e8cSThomas Abraham 	/* now it is safe to switch to KPLL */
84777b55e8cSThomas Abraham 	setbits_le32(&clk->src_kfc, KPLL_FOUT);
84877b55e8cSThomas Abraham 
84977b55e8cSThomas Abraham 	/* Set MPLL */
85077b55e8cSThomas Abraham 	writel(MPLL_CON1_VAL, &clk->mpll_con1);
85177b55e8cSThomas Abraham 	val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv);
85277b55e8cSThomas Abraham 	writel(val, &clk->mpll_con0);
85377b55e8cSThomas Abraham 	while ((readl(&clk->mpll_con0) & PLL_LOCKED) == 0)
85477b55e8cSThomas Abraham 		;
85577b55e8cSThomas Abraham 
85677b55e8cSThomas Abraham 	/* Set DPLL */
85777b55e8cSThomas Abraham 	writel(DPLL_CON1_VAL, &clk->dpll_con1);
85877b55e8cSThomas Abraham 	val = set_pll(mem->dpll_mdiv, mem->dpll_pdiv, mem->dpll_sdiv);
85977b55e8cSThomas Abraham 	writel(val, &clk->dpll_con0);
86077b55e8cSThomas Abraham 	while ((readl(&clk->dpll_con0) & PLL_LOCKED) == 0)
86177b55e8cSThomas Abraham 		;
86277b55e8cSThomas Abraham 
86377b55e8cSThomas Abraham 	/* Set EPLL */
86477b55e8cSThomas Abraham 	writel(EPLL_CON2_VAL, &clk->epll_con2);
86577b55e8cSThomas Abraham 	writel(EPLL_CON1_VAL, &clk->epll_con1);
86677b55e8cSThomas Abraham 	val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv);
86777b55e8cSThomas Abraham 	writel(val, &clk->epll_con0);
86877b55e8cSThomas Abraham 	while ((readl(&clk->epll_con0) & PLL_LOCKED) == 0)
86977b55e8cSThomas Abraham 		;
87077b55e8cSThomas Abraham 
87177b55e8cSThomas Abraham 	/* Set CPLL */
87277b55e8cSThomas Abraham 	writel(CPLL_CON1_VAL, &clk->cpll_con1);
87377b55e8cSThomas Abraham 	val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv);
87477b55e8cSThomas Abraham 	writel(val, &clk->cpll_con0);
87577b55e8cSThomas Abraham 	while ((readl(&clk->cpll_con0) & PLL_LOCKED) == 0)
87677b55e8cSThomas Abraham 		;
87777b55e8cSThomas Abraham 
87877b55e8cSThomas Abraham 	/* Set IPLL */
87977b55e8cSThomas Abraham 	writel(IPLL_CON1_VAL, &clk->ipll_con1);
88077b55e8cSThomas Abraham 	val = set_pll(mem->ipll_mdiv, mem->ipll_pdiv, mem->ipll_sdiv);
88177b55e8cSThomas Abraham 	writel(val, &clk->ipll_con0);
88277b55e8cSThomas Abraham 	while ((readl(&clk->ipll_con0) & PLL_LOCKED) == 0)
88377b55e8cSThomas Abraham 		;
88477b55e8cSThomas Abraham 
88577b55e8cSThomas Abraham 	/* Set VPLL */
88677b55e8cSThomas Abraham 	writel(VPLL_CON1_VAL, &clk->vpll_con1);
88777b55e8cSThomas Abraham 	val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv);
88877b55e8cSThomas Abraham 	writel(val, &clk->vpll_con0);
88977b55e8cSThomas Abraham 	while ((readl(&clk->vpll_con0) & PLL_LOCKED) == 0)
89077b55e8cSThomas Abraham 		;
89177b55e8cSThomas Abraham 
89277b55e8cSThomas Abraham 	/* Set BPLL */
89377b55e8cSThomas Abraham 	writel(BPLL_CON1_VAL, &clk->bpll_con1);
89477b55e8cSThomas Abraham 	val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv);
89577b55e8cSThomas Abraham 	writel(val, &clk->bpll_con0);
89677b55e8cSThomas Abraham 	while ((readl(&clk->bpll_con0) & PLL_LOCKED) == 0)
89777b55e8cSThomas Abraham 		;
89877b55e8cSThomas Abraham 
89977b55e8cSThomas Abraham 	/* Set SPLL */
90077b55e8cSThomas Abraham 	writel(SPLL_CON1_VAL, &clk->spll_con1);
90177b55e8cSThomas Abraham 	val = set_pll(mem->spll_mdiv, mem->spll_pdiv, mem->spll_sdiv);
90277b55e8cSThomas Abraham 	writel(val, &clk->spll_con0);
90377b55e8cSThomas Abraham 	while ((readl(&clk->spll_con0) & PLL_LOCKED) == 0)
90477b55e8cSThomas Abraham 		;
90577b55e8cSThomas Abraham 
90677b55e8cSThomas Abraham 	/* Set RPLL */
90777b55e8cSThomas Abraham 	writel(RPLL_CON2_VAL, &clk->rpll_con2);
90877b55e8cSThomas Abraham 	writel(RPLL_CON1_VAL, &clk->rpll_con1);
90977b55e8cSThomas Abraham 	val = set_pll(mem->rpll_mdiv, mem->rpll_pdiv, mem->rpll_sdiv);
91077b55e8cSThomas Abraham 	writel(val, &clk->rpll_con0);
91177b55e8cSThomas Abraham 	while ((readl(&clk->rpll_con0) & PLL_LOCKED) == 0)
91277b55e8cSThomas Abraham 		;
91377b55e8cSThomas Abraham 
91477b55e8cSThomas Abraham 	writel(CLK_DIV_CDREX0_VAL, &clk->div_cdrex0);
91577b55e8cSThomas Abraham 	writel(CLK_DIV_CDREX1_VAL, &clk->div_cdrex1);
91677b55e8cSThomas Abraham 
91777b55e8cSThomas Abraham 	writel(CLK_SRC_TOP0_VAL, &clk->src_top0);
91877b55e8cSThomas Abraham 	writel(CLK_SRC_TOP1_VAL, &clk->src_top1);
91977b55e8cSThomas Abraham 	writel(CLK_SRC_TOP2_VAL, &clk->src_top2);
92077b55e8cSThomas Abraham 	writel(CLK_SRC_TOP7_VAL, &clk->src_top7);
92177b55e8cSThomas Abraham 
92277b55e8cSThomas Abraham 	writel(CLK_DIV_TOP0_VAL, &clk->div_top0);
92377b55e8cSThomas Abraham 	writel(CLK_DIV_TOP1_VAL, &clk->div_top1);
92477b55e8cSThomas Abraham 	writel(CLK_DIV_TOP2_VAL, &clk->div_top2);
92577b55e8cSThomas Abraham 
92677b55e8cSThomas Abraham 	writel(0, &clk->src_top10);
92777b55e8cSThomas Abraham 	writel(0, &clk->src_top11);
92877b55e8cSThomas Abraham 	writel(0, &clk->src_top12);
92977b55e8cSThomas Abraham 
93077b55e8cSThomas Abraham 	writel(CLK_SRC_TOP3_VAL, &clk->src_top3);
93177b55e8cSThomas Abraham 	writel(CLK_SRC_TOP4_VAL, &clk->src_top4);
93277b55e8cSThomas Abraham 	writel(CLK_SRC_TOP5_VAL, &clk->src_top5);
93377b55e8cSThomas Abraham 
93477b55e8cSThomas Abraham 	/* DISP1 BLK CLK SELECTION */
93577b55e8cSThomas Abraham 	writel(CLK_SRC_DISP1_0_VAL, &clk->src_disp10);
93677b55e8cSThomas Abraham 	writel(CLK_DIV_DISP1_0_VAL, &clk->div_disp10);
93777b55e8cSThomas Abraham 
93877b55e8cSThomas Abraham 	/* AUDIO BLK */
93977b55e8cSThomas Abraham 	writel(AUDIO0_SEL_EPLL, &clk->src_mau);
94077b55e8cSThomas Abraham 	writel(DIV_MAU_VAL, &clk->div_mau);
94177b55e8cSThomas Abraham 
94277b55e8cSThomas Abraham 	/* FSYS */
94377b55e8cSThomas Abraham 	writel(CLK_SRC_FSYS0_VAL, &clk->src_fsys);
94477b55e8cSThomas Abraham 	writel(CLK_DIV_FSYS0_VAL, &clk->div_fsys0);
94577b55e8cSThomas Abraham 	writel(CLK_DIV_FSYS1_VAL, &clk->div_fsys1);
94677b55e8cSThomas Abraham 	writel(CLK_DIV_FSYS2_VAL, &clk->div_fsys2);
94777b55e8cSThomas Abraham 
94877b55e8cSThomas Abraham 	writel(CLK_SRC_ISP_VAL, &clk->src_isp);
94977b55e8cSThomas Abraham 	writel(CLK_DIV_ISP0_VAL, &clk->div_isp0);
95077b55e8cSThomas Abraham 	writel(CLK_DIV_ISP1_VAL, &clk->div_isp1);
95177b55e8cSThomas Abraham 
95277b55e8cSThomas Abraham 	writel(CLK_SRC_PERIC0_VAL, &clk->src_peric0);
95377b55e8cSThomas Abraham 	writel(CLK_SRC_PERIC1_VAL, &clk->src_peric1);
95477b55e8cSThomas Abraham 
95577b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC0_VAL, &clk->div_peric0);
95677b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC1_VAL, &clk->div_peric1);
95777b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC2_VAL, &clk->div_peric2);
95877b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC3_VAL, &clk->div_peric3);
95977b55e8cSThomas Abraham 	writel(CLK_DIV_PERIC4_VAL, &clk->div_peric4);
96077b55e8cSThomas Abraham 
96177b55e8cSThomas Abraham 	writel(CLK_DIV_CPERI1_VAL, &clk->div_cperi1);
96277b55e8cSThomas Abraham 
96377b55e8cSThomas Abraham 	writel(CLK_DIV2_RATIO, &clk->clkdiv2_ratio);
96477b55e8cSThomas Abraham 	writel(CLK_DIV4_RATIO, &clk->clkdiv4_ratio);
96577b55e8cSThomas Abraham 	writel(CLK_DIV_G2D, &clk->div_g2d);
96677b55e8cSThomas Abraham 
96777b55e8cSThomas Abraham 	writel(CLK_SRC_TOP6_VAL, &clk->src_top6);
96877b55e8cSThomas Abraham 	writel(CLK_SRC_CDREX_VAL, &clk->src_cdrex);
96977b55e8cSThomas Abraham 	writel(CLK_SRC_KFC_VAL, &clk->src_kfc);
97077b55e8cSThomas Abraham }
97177b55e8cSThomas Abraham 
system_clock_init(void)97277b55e8cSThomas Abraham void system_clock_init(void)
97377b55e8cSThomas Abraham {
974*d64c8adeSPrzemyslaw Marczak 	if (proid_is_exynos5420() || proid_is_exynos5422())
97577b55e8cSThomas Abraham 		exynos5420_system_clock_init();
97677b55e8cSThomas Abraham 	else
97777b55e8cSThomas Abraham 		exynos5250_system_clock_init();
97877b55e8cSThomas Abraham }
97977b55e8cSThomas Abraham 
clock_init_dp_clock(void)98077b55e8cSThomas Abraham void clock_init_dp_clock(void)
98177b55e8cSThomas Abraham {
98277b55e8cSThomas Abraham 	struct exynos5_clock *clk =
98377b55e8cSThomas Abraham 		(struct exynos5_clock *)samsung_get_base_clock();
98477b55e8cSThomas Abraham 
98577b55e8cSThomas Abraham 	/* DP clock enable */
98677b55e8cSThomas Abraham 	setbits_le32(&clk->gate_ip_disp1, CLK_GATE_DP1_ALLOW);
98777b55e8cSThomas Abraham 
98877b55e8cSThomas Abraham 	/* We run DP at 267 Mhz */
98977b55e8cSThomas Abraham 	setbits_le32(&clk->div_disp1_0, CLK_DIV_DISP1_0_FIMD1);
99077b55e8cSThomas Abraham }
99177b55e8cSThomas Abraham 
99277b55e8cSThomas Abraham /*
99377b55e8cSThomas Abraham  * Set clock divisor value for booting from EMMC.
99477b55e8cSThomas Abraham  * Set DWMMC channel-0 clk div to operate mmc0 device at 50MHz.
99577b55e8cSThomas Abraham  */
emmc_boot_clk_div_set(void)99677b55e8cSThomas Abraham void emmc_boot_clk_div_set(void)
99777b55e8cSThomas Abraham {
99877b55e8cSThomas Abraham 	struct exynos5_clock *clk =
99977b55e8cSThomas Abraham 		(struct exynos5_clock *)samsung_get_base_clock();
100077b55e8cSThomas Abraham 	unsigned int div_mmc;
100177b55e8cSThomas Abraham 
100277b55e8cSThomas Abraham 	div_mmc = readl((unsigned int) &clk->div_fsys1) & ~FSYS1_MMC0_DIV_MASK;
100377b55e8cSThomas Abraham 	div_mmc |= FSYS1_MMC0_DIV_VAL;
100477b55e8cSThomas Abraham 	writel(div_mmc, (unsigned int) &clk->div_fsys1);
100577b55e8cSThomas Abraham }
1006