1 /* SPDX-License-Identifier: GPL-2.0-only */
3 /* Clock setup for SMDK5250 board based on EXYNOS5 */
5 #include <device/mmio.h>
10 void system_clock_init(struct mem_timings
*mem
,
11 struct arm_clk_ratios
*arm_clk_ratio
)
15 /* Turn on the MCT as early as possible. */
16 exynos_mct
->g_tcon
|= (1 << 8);
18 clrbits32(&exynos_clock
->src_cpu
, MUX_APLL_SEL_MASK
);
20 val
= read32(&exynos_clock
->mux_stat_cpu
);
21 } while ((val
| MUX_APLL_SEL_MASK
) != val
);
23 clrbits32(&exynos_clock
->src_core1
, MUX_MPLL_SEL_MASK
);
25 val
= read32(&exynos_clock
->mux_stat_core1
);
26 } while ((val
| MUX_MPLL_SEL_MASK
) != val
);
28 clrbits32(&exynos_clock
->src_top2
, MUX_CPLL_SEL_MASK
);
29 clrbits32(&exynos_clock
->src_top2
, MUX_EPLL_SEL_MASK
);
30 clrbits32(&exynos_clock
->src_top2
, MUX_VPLL_SEL_MASK
);
31 clrbits32(&exynos_clock
->src_top2
, MUX_GPLL_SEL_MASK
);
32 tmp
= MUX_CPLL_SEL_MASK
| MUX_EPLL_SEL_MASK
| MUX_VPLL_SEL_MASK
35 val
= read32(&exynos_clock
->mux_stat_top2
);
36 } while ((val
| tmp
) != val
);
38 clrbits32(&exynos_clock
->src_cdrex
, MUX_BPLL_SEL_MASK
);
40 val
= read32(&exynos_clock
->mux_stat_cdrex
);
41 } while ((val
| MUX_BPLL_SEL_MASK
) != val
);
44 write32(&exynos_clock
->apll_lock
, APLL_LOCK_VAL
);
46 write32(&exynos_clock
->mpll_lock
, MPLL_LOCK_VAL
);
48 write32(&exynos_clock
->bpll_lock
, BPLL_LOCK_VAL
);
50 write32(&exynos_clock
->cpll_lock
, CPLL_LOCK_VAL
);
52 write32(&exynos_clock
->gpll_lock
, GPLL_LOCK_VAL
);
54 write32(&exynos_clock
->epll_lock
, EPLL_LOCK_VAL
);
56 write32(&exynos_clock
->vpll_lock
, VPLL_LOCK_VAL
);
58 write32(&exynos_clock
->pll_div2_sel
, CLK_REG_DISABLE
);
60 write32(&exynos_clock
->src_cpu
, MUX_HPM_SEL_MASK
);
62 val
= read32(&exynos_clock
->mux_stat_cpu
);
63 } while ((val
| HPM_SEL_SCLK_MPLL
) != val
);
65 val
= arm_clk_ratio
->arm2_ratio
<< 28
66 | arm_clk_ratio
->apll_ratio
<< 24
67 | arm_clk_ratio
->pclk_dbg_ratio
<< 20
68 | arm_clk_ratio
->atb_ratio
<< 16
69 | arm_clk_ratio
->periph_ratio
<< 12
70 | arm_clk_ratio
->acp_ratio
<< 8
71 | arm_clk_ratio
->cpud_ratio
<< 4
72 | arm_clk_ratio
->arm_ratio
;
73 write32(&exynos_clock
->div_cpu0
, val
);
75 val
= read32(&exynos_clock
->div_stat_cpu0
);
78 write32(&exynos_clock
->div_cpu1
, CLK_DIV_CPU1_VAL
);
80 val
= read32(&exynos_clock
->div_stat_cpu1
);
83 /* switch A15 clock source to OSC clock before changing APLL */
84 clrbits32(&exynos_clock
->src_cpu
, APLL_FOUT
);
87 write32(&exynos_clock
->apll_con1
, APLL_CON1_VAL
);
88 val
= set_pll(arm_clk_ratio
->apll_mdiv
, arm_clk_ratio
->apll_pdiv
,
89 arm_clk_ratio
->apll_sdiv
);
90 write32(&exynos_clock
->apll_con0
, val
);
91 while ((read32(&exynos_clock
->apll_con0
) & APLL_CON0_LOCKED
) == 0)
94 /* now it is safe to switch to APLL */
95 setbits32(&exynos_clock
->src_cpu
, APLL_FOUT
);
98 write32(&exynos_clock
->mpll_con1
, MPLL_CON1_VAL
);
99 val
= set_pll(mem
->mpll_mdiv
, mem
->mpll_pdiv
, mem
->mpll_sdiv
);
100 write32(&exynos_clock
->mpll_con0
, val
);
101 while ((read32(&exynos_clock
->mpll_con0
) & MPLL_CON0_LOCKED
) == 0)
105 * Configure MUX_MPLL_FOUT to choose the direct clock source
106 * path and avoid the fixed DIV/2 block to save power
108 setbits32(&exynos_clock
->pll_div2_sel
, MUX_MPLL_FOUT_SEL
);
112 write32(&exynos_clock
->bpll_con1
, BPLL_CON1_VAL
);
113 val
= set_pll(mem
->bpll_mdiv
, mem
->bpll_pdiv
, mem
->bpll_sdiv
);
114 write32(&exynos_clock
->bpll_con0
, val
);
115 while ((read32(&exynos_clock
->bpll_con0
) & BPLL_CON0_LOCKED
) == 0)
118 setbits32(&exynos_clock
->pll_div2_sel
, MUX_BPLL_FOUT_SEL
);
122 write32(&exynos_clock
->cpll_con1
, CPLL_CON1_VAL
);
123 val
= set_pll(mem
->cpll_mdiv
, mem
->cpll_pdiv
, mem
->cpll_sdiv
);
124 write32(&exynos_clock
->cpll_con0
, val
);
125 while ((read32(&exynos_clock
->cpll_con0
) & CPLL_CON0_LOCKED
) == 0)
129 write32(&exynos_clock
->gpll_con1
, GPLL_CON1_VAL
);
130 val
= set_pll(mem
->gpll_mdiv
, mem
->gpll_pdiv
, mem
->gpll_sdiv
);
131 write32(&exynos_clock
->gpll_con0
, val
);
132 while ((read32(&exynos_clock
->gpll_con0
) & GPLL_CON0_LOCKED
) == 0)
136 write32(&exynos_clock
->epll_con2
, EPLL_CON2_VAL
);
137 write32(&exynos_clock
->epll_con1
, EPLL_CON1_VAL
);
138 val
= set_pll(mem
->epll_mdiv
, mem
->epll_pdiv
, mem
->epll_sdiv
);
139 write32(&exynos_clock
->epll_con0
, val
);
140 while ((read32(&exynos_clock
->epll_con0
) & EPLL_CON0_LOCKED
) == 0)
144 write32(&exynos_clock
->vpll_con2
, VPLL_CON2_VAL
);
145 write32(&exynos_clock
->vpll_con1
, VPLL_CON1_VAL
);
146 val
= set_pll(mem
->vpll_mdiv
, mem
->vpll_pdiv
, mem
->vpll_sdiv
);
147 write32(&exynos_clock
->vpll_con0
, val
);
148 while ((read32(&exynos_clock
->vpll_con0
) & VPLL_CON0_LOCKED
) == 0)
151 write32(&exynos_clock
->src_core0
, CLK_SRC_CORE0_VAL
);
152 write32(&exynos_clock
->div_core0
, CLK_DIV_CORE0_VAL
);
153 while (read32(&exynos_clock
->div_stat_core0
) != 0)
156 write32(&exynos_clock
->div_core1
, CLK_DIV_CORE1_VAL
);
157 while (read32(&exynos_clock
->div_stat_core1
) != 0)
160 write32(&exynos_clock
->div_sysrgt
, CLK_DIV_SYSRGT_VAL
);
161 while (read32(&exynos_clock
->div_stat_sysrgt
) != 0)
164 write32(&exynos_clock
->div_acp
, CLK_DIV_ACP_VAL
);
165 while (read32(&exynos_clock
->div_stat_acp
) != 0)
168 write32(&exynos_clock
->div_syslft
, CLK_DIV_SYSLFT_VAL
);
169 while (read32(&exynos_clock
->div_stat_syslft
) != 0)
172 write32(&exynos_clock
->src_top0
, CLK_SRC_TOP0_VAL
);
173 write32(&exynos_clock
->src_top1
, CLK_SRC_TOP1_VAL
);
174 write32(&exynos_clock
->src_top2
, TOP2_VAL
);
175 write32(&exynos_clock
->src_top3
, CLK_SRC_TOP3_VAL
);
177 write32(&exynos_clock
->div_top0
, CLK_DIV_TOP0_VAL
);
178 while (read32(&exynos_clock
->div_stat_top0
))
181 write32(&exynos_clock
->div_top1
, CLK_DIV_TOP1_VAL
);
182 while (read32(&exynos_clock
->div_stat_top1
))
185 write32(&exynos_clock
->src_lex
, CLK_SRC_LEX_VAL
);
187 val
= read32(&exynos_clock
->mux_stat_lex
);
188 if (val
== (val
| 1))
192 write32(&exynos_clock
->div_lex
, CLK_DIV_LEX_VAL
);
193 while (read32(&exynos_clock
->div_stat_lex
))
196 write32(&exynos_clock
->div_r0x
, CLK_DIV_R0X_VAL
);
197 while (read32(&exynos_clock
->div_stat_r0x
))
200 write32(&exynos_clock
->div_r0x
, CLK_DIV_R0X_VAL
);
201 while (read32(&exynos_clock
->div_stat_r0x
))
204 write32(&exynos_clock
->div_r1x
, CLK_DIV_R1X_VAL
);
205 while (read32(&exynos_clock
->div_stat_r1x
))
209 write32(&exynos_clock
->src_cdrex
, MUX_BPLL_SEL_MASK
|
210 MUX_MCLK_CDREX_SEL
| MUX_MCLK_DPHY_SEL
);
212 write32(&exynos_clock
->src_cdrex
, CLK_REG_DISABLE
);
215 write32(&exynos_clock
->div_cdrex
, CLK_DIV_CDREX_VAL
);
216 while (read32(&exynos_clock
->div_stat_cdrex
))
219 val
= read32(&exynos_clock
->src_cpu
);
220 val
|= CLK_SRC_CPU_VAL
;
221 write32(&exynos_clock
->src_cpu
, val
);
223 val
= read32(&exynos_clock
->src_top2
);
224 val
|= CLK_SRC_TOP2_VAL
;
225 write32(&exynos_clock
->src_top2
, val
);
227 val
= read32(&exynos_clock
->src_core1
);
228 val
|= CLK_SRC_CORE1_VAL
;
229 write32(&exynos_clock
->src_core1
, val
);
231 write32(&exynos_clock
->src_fsys
, CLK_SRC_FSYS0_VAL
);
232 write32(&exynos_clock
->div_fsys0
, CLK_DIV_FSYS0_VAL
);
233 while (read32(&exynos_clock
->div_stat_fsys0
))
236 write32(&exynos_clock
->clkout_cmu_cpu
, CLK_REG_DISABLE
);
237 write32(&exynos_clock
->clkout_cmu_core
, CLK_REG_DISABLE
);
238 write32(&exynos_clock
->clkout_cmu_acp
, CLK_REG_DISABLE
);
239 write32(&exynos_clock
->clkout_cmu_top
, CLK_REG_DISABLE
);
240 write32(&exynos_clock
->clkout_cmu_lex
, CLK_REG_DISABLE
);
241 write32(&exynos_clock
->clkout_cmu_r0x
, CLK_REG_DISABLE
);
242 write32(&exynos_clock
->clkout_cmu_r1x
, CLK_REG_DISABLE
);
243 write32(&exynos_clock
->clkout_cmu_cdrex
, CLK_REG_DISABLE
);
245 write32(&exynos_clock
->src_peric0
, CLK_SRC_PERIC0_VAL
);
246 write32(&exynos_clock
->div_peric0
, CLK_DIV_PERIC0_VAL
);
248 write32(&exynos_clock
->src_peric1
, CLK_SRC_PERIC1_VAL
);
249 write32(&exynos_clock
->div_peric1
, CLK_DIV_PERIC1_VAL
);
250 write32(&exynos_clock
->div_peric2
, CLK_DIV_PERIC2_VAL
);
251 write32(&exynos_clock
->sclk_src_isp
, SCLK_SRC_ISP_VAL
);
252 write32(&exynos_clock
->sclk_div_isp
, SCLK_DIV_ISP_VAL
);
253 write32(&exynos_clock
->div_isp0
, CLK_DIV_ISP0_VAL
);
254 write32(&exynos_clock
->div_isp1
, CLK_DIV_ISP1_VAL
);
255 write32(&exynos_clock
->div_isp2
, CLK_DIV_ISP2_VAL
);
257 /* FIMD1 SRC CLK SELECTION */
258 write32(&exynos_clock
->src_disp1_0
, CLK_SRC_DISP1_0_VAL
);
260 val
= MMC2_PRE_RATIO_VAL
<< MMC2_PRE_RATIO_OFFSET
261 | MMC2_RATIO_VAL
<< MMC2_RATIO_OFFSET
262 | MMC3_PRE_RATIO_VAL
<< MMC3_PRE_RATIO_OFFSET
263 | MMC3_RATIO_VAL
<< MMC3_RATIO_OFFSET
;
264 write32(&exynos_clock
->div_fsys2
, val
);
267 void clock_gate(void)
269 /* CLK_GATE_IP_SYSRGT */
270 clrbits32(&exynos_clock
->gate_ip_sysrgt
, CLK_C2C_MASK
);
272 /* CLK_GATE_IP_ACP */
273 clrbits32(&exynos_clock
->gate_ip_acp
, CLK_SMMUG2D_MASK
|
276 CLK_ID_REMAPPER_MASK
|
282 /* CLK_GATE_BUS_SYSLFT */
283 clrbits32(&exynos_clock
->gate_bus_syslft
, CLK_EFCLK_MASK
);
285 /* CLK_GATE_IP_ISP0 */
286 clrbits32(&exynos_clock
->gate_ip_isp0
, CLK_UART_ISP_MASK
|
289 CLK_MTCADC_ISP_MASK
|
293 CLK_MCUCTL_ISP_MASK
|
294 CLK_INT_COMB_ISP_MASK
|
295 CLK_SMMU_MCUISP_MASK
|
296 CLK_SMMU_SCALERP_MASK
|
297 CLK_SMMU_SCALERC_MASK
|
310 /* CLK_GATE_IP_ISP1 */
311 clrbits32(&exynos_clock
->gate_ip_isp1
, CLK_SPI1_ISP_MASK
|
321 /* CLK_GATE_SCLK_ISP */
322 clrbits32(&exynos_clock
->gate_sclk_isp
, SCLK_MPWM_ISP_MASK
);
324 /* CLK_GATE_IP_GSCL */
325 clrbits32(&exynos_clock
->gate_ip_gscl
, CLK_SMMUFIMC_LITE2_MASK
|
326 CLK_SMMUFIMC_LITE1_MASK
|
327 CLK_SMMUFIMC_LITE0_MASK
|
332 CLK_GSCL_WRAP_B_MASK
|
333 CLK_GSCL_WRAP_A_MASK
|
340 /* CLK_GATE_IP_DISP1 */
341 clrbits32(&exynos_clock
->gate_ip_disp1
, CLK_SMMUTVX_MASK
|
347 /* CLK_GATE_IP_MFC */
348 clrbits32(&exynos_clock
->gate_ip_mfc
, CLK_SMMUMFCR_MASK
|
352 /* CLK_GATE_IP_GEN */
353 clrbits32(&exynos_clock
->gate_ip_gen
, CLK_SMMUMDMA1_MASK
|
355 CLK_SMMUROTATOR_MASK
|
360 /* CLK_GATE_IP_FSYS */
361 clrbits32(&exynos_clock
->gate_ip_fsys
, CLK_WDT_IOP_MASK
|
362 CLK_SMMUMCU_IOP_MASK
|
363 CLK_SATA_PHY_I2C_MASK
|
364 CLK_SATA_PHY_CTRL_MASK
|
376 /* CLK_GATE_IP_PERIC */
377 clrbits32(&exynos_clock
->gate_ip_peric
, CLK_HS_I2C3_MASK
|
391 * Note: Keep CHIPID_APBIF ungated to ensure reading the product ID
392 * register (PRO_ID) works correctly when the OS kernel determines
393 * which chip it is running on.
395 clrbits32(&exynos_clock
->gate_ip_peris
, CLK_RTC_MASK
|
408 clrbits32(&exynos_clock
->gate_block
, CLK_ACP_MASK
);
410 /* CLK_GATE_IP_CDREX */
411 clrbits32(&exynos_clock
->gate_ip_cdrex
, CLK_DPHY0_MASK
|
413 CLK_TZASC_DRBXR_MASK
);
416 void clock_init_dp_clock(void)
418 /* DP clock enable */
419 setbits32(&exynos_clock
->gate_ip_disp1
, CLK_GATE_DP1_ALLOW
);
421 /* We run DP at 267 Mhz */
422 setbits32(&exynos_clock
->div_disp1_0
, CLK_DIV_DISP1_0_FIMD1
);