Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electronics |
| 5 | * |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 16 | /* Clock setup for SMDK5250 board based on EXYNOS5 */ |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 17 | |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 18 | #include <delay.h> |
Julius Werner | 1ed0c8c | 2014-10-20 13:16:29 -0700 | [diff] [blame] | 19 | #include <soc/clk.h> |
| 20 | #include <soc/dp.h> |
| 21 | #include <soc/setup.h> |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 22 | |
David Hendricks | 0d4f97e | 2013-02-03 18:09:58 -0800 | [diff] [blame] | 23 | void system_clock_init(struct mem_timings *mem, |
| 24 | struct arm_clk_ratios *arm_clk_ratio) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 25 | { |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 26 | u32 val, tmp; |
| 27 | |
| 28 | /* Turn on the MCT as early as possible. */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 29 | exynos_mct->g_tcon |= (1 << 8); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 30 | |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 31 | clrbits_le32(&exynos_clock->src_cpu, MUX_APLL_SEL_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 32 | do { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 33 | val = read32(&exynos_clock->mux_stat_cpu); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 34 | } while ((val | MUX_APLL_SEL_MASK) != val); |
| 35 | |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 36 | clrbits_le32(&exynos_clock->src_core1, MUX_MPLL_SEL_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 37 | do { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 38 | val = read32(&exynos_clock->mux_stat_core1); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 39 | } while ((val | MUX_MPLL_SEL_MASK) != val); |
| 40 | |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 41 | clrbits_le32(&exynos_clock->src_top2, MUX_CPLL_SEL_MASK); |
| 42 | clrbits_le32(&exynos_clock->src_top2, MUX_EPLL_SEL_MASK); |
| 43 | clrbits_le32(&exynos_clock->src_top2, MUX_VPLL_SEL_MASK); |
| 44 | clrbits_le32(&exynos_clock->src_top2, MUX_GPLL_SEL_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 45 | tmp = MUX_CPLL_SEL_MASK | MUX_EPLL_SEL_MASK | MUX_VPLL_SEL_MASK |
| 46 | | MUX_GPLL_SEL_MASK; |
| 47 | do { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 48 | val = read32(&exynos_clock->mux_stat_top2); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 49 | } while ((val | tmp) != val); |
| 50 | |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 51 | clrbits_le32(&exynos_clock->src_cdrex, MUX_BPLL_SEL_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 52 | do { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 53 | val = read32(&exynos_clock->mux_stat_cdrex); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 54 | } while ((val | MUX_BPLL_SEL_MASK) != val); |
| 55 | |
| 56 | /* PLL locktime */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 57 | write32(&exynos_clock->apll_lock, APLL_LOCK_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 58 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 59 | write32(&exynos_clock->mpll_lock, MPLL_LOCK_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 60 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 61 | write32(&exynos_clock->bpll_lock, BPLL_LOCK_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 62 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 63 | write32(&exynos_clock->cpll_lock, CPLL_LOCK_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 64 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 65 | write32(&exynos_clock->gpll_lock, GPLL_LOCK_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 66 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 67 | write32(&exynos_clock->epll_lock, EPLL_LOCK_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 68 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 69 | write32(&exynos_clock->vpll_lock, VPLL_LOCK_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 70 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 71 | write32(&exynos_clock->pll_div2_sel, CLK_REG_DISABLE); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 72 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 73 | write32(&exynos_clock->src_cpu, MUX_HPM_SEL_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 74 | do { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 75 | val = read32(&exynos_clock->mux_stat_cpu); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 76 | } while ((val | HPM_SEL_SCLK_MPLL) != val); |
| 77 | |
| 78 | val = arm_clk_ratio->arm2_ratio << 28 |
| 79 | | arm_clk_ratio->apll_ratio << 24 |
| 80 | | arm_clk_ratio->pclk_dbg_ratio << 20 |
| 81 | | arm_clk_ratio->atb_ratio << 16 |
| 82 | | arm_clk_ratio->periph_ratio << 12 |
| 83 | | arm_clk_ratio->acp_ratio << 8 |
| 84 | | arm_clk_ratio->cpud_ratio << 4 |
| 85 | | arm_clk_ratio->arm_ratio; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 86 | write32(&exynos_clock->div_cpu0, val); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 87 | do { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 88 | val = read32(&exynos_clock->div_stat_cpu0); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 89 | } while (0 != val); |
| 90 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 91 | write32(&exynos_clock->div_cpu1, CLK_DIV_CPU1_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 92 | do { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 93 | val = read32(&exynos_clock->div_stat_cpu1); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 94 | } while (0 != val); |
| 95 | |
David Hendricks | f05e871 | 2013-08-06 15:17:37 -0700 | [diff] [blame] | 96 | /* switch A15 clock source to OSC clock before changing APLL */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 97 | clrbits_le32(&exynos_clock->src_cpu, APLL_FOUT); |
David Hendricks | f05e871 | 2013-08-06 15:17:37 -0700 | [diff] [blame] | 98 | |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 99 | /* Set APLL */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 100 | write32(&exynos_clock->apll_con1, APLL_CON1_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 101 | val = set_pll(arm_clk_ratio->apll_mdiv, arm_clk_ratio->apll_pdiv, |
| 102 | arm_clk_ratio->apll_sdiv); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 103 | write32(&exynos_clock->apll_con0, val); |
| 104 | while ((read32(&exynos_clock->apll_con0) & APLL_CON0_LOCKED) == 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 105 | ; |
| 106 | |
David Hendricks | f05e871 | 2013-08-06 15:17:37 -0700 | [diff] [blame] | 107 | /* now it is safe to switch to APLL */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 108 | setbits_le32(&exynos_clock->src_cpu, APLL_FOUT); |
David Hendricks | f05e871 | 2013-08-06 15:17:37 -0700 | [diff] [blame] | 109 | |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 110 | /* Set MPLL */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 111 | write32(&exynos_clock->mpll_con1, MPLL_CON1_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 112 | val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 113 | write32(&exynos_clock->mpll_con0, val); |
| 114 | while ((read32(&exynos_clock->mpll_con0) & MPLL_CON0_LOCKED) == 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 115 | ; |
| 116 | |
| 117 | /* |
| 118 | * Configure MUX_MPLL_FOUT to choose the direct clock source |
| 119 | * path and avoid the fixed DIV/2 block to save power |
| 120 | */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 121 | setbits_le32(&exynos_clock->pll_div2_sel, MUX_MPLL_FOUT_SEL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 122 | |
| 123 | /* Set BPLL */ |
| 124 | if (mem->use_bpll) { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 125 | write32(&exynos_clock->bpll_con1, BPLL_CON1_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 126 | val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 127 | write32(&exynos_clock->bpll_con0, val); |
| 128 | while ((read32(&exynos_clock->bpll_con0) & BPLL_CON0_LOCKED) == 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 129 | ; |
| 130 | |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 131 | setbits_le32(&exynos_clock->pll_div2_sel, MUX_BPLL_FOUT_SEL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* Set CPLL */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 135 | write32(&exynos_clock->cpll_con1, CPLL_CON1_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 136 | val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 137 | write32(&exynos_clock->cpll_con0, val); |
| 138 | while ((read32(&exynos_clock->cpll_con0) & CPLL_CON0_LOCKED) == 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 139 | ; |
| 140 | |
| 141 | /* Set GPLL */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 142 | write32(&exynos_clock->gpll_con1, GPLL_CON1_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 143 | val = set_pll(mem->gpll_mdiv, mem->gpll_pdiv, mem->gpll_sdiv); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 144 | write32(&exynos_clock->gpll_con0, val); |
| 145 | while ((read32(&exynos_clock->gpll_con0) & GPLL_CON0_LOCKED) == 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 146 | ; |
| 147 | |
| 148 | /* Set EPLL */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 149 | write32(&exynos_clock->epll_con2, EPLL_CON2_VAL); |
| 150 | write32(&exynos_clock->epll_con1, EPLL_CON1_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 151 | val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 152 | write32(&exynos_clock->epll_con0, val); |
| 153 | while ((read32(&exynos_clock->epll_con0) & EPLL_CON0_LOCKED) == 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 154 | ; |
| 155 | |
| 156 | /* Set VPLL */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 157 | write32(&exynos_clock->vpll_con2, VPLL_CON2_VAL); |
| 158 | write32(&exynos_clock->vpll_con1, VPLL_CON1_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 159 | val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 160 | write32(&exynos_clock->vpll_con0, val); |
| 161 | while ((read32(&exynos_clock->vpll_con0) & VPLL_CON0_LOCKED) == 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 162 | ; |
| 163 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 164 | write32(&exynos_clock->src_core0, CLK_SRC_CORE0_VAL); |
| 165 | write32(&exynos_clock->div_core0, CLK_DIV_CORE0_VAL); |
| 166 | while (read32(&exynos_clock->div_stat_core0) != 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 167 | ; |
| 168 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 169 | write32(&exynos_clock->div_core1, CLK_DIV_CORE1_VAL); |
| 170 | while (read32(&exynos_clock->div_stat_core1) != 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 171 | ; |
| 172 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 173 | write32(&exynos_clock->div_sysrgt, CLK_DIV_SYSRGT_VAL); |
| 174 | while (read32(&exynos_clock->div_stat_sysrgt) != 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 175 | ; |
| 176 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 177 | write32(&exynos_clock->div_acp, CLK_DIV_ACP_VAL); |
| 178 | while (read32(&exynos_clock->div_stat_acp) != 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 179 | ; |
| 180 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 181 | write32(&exynos_clock->div_syslft, CLK_DIV_SYSLFT_VAL); |
| 182 | while (read32(&exynos_clock->div_stat_syslft) != 0) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 183 | ; |
| 184 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 185 | write32(&exynos_clock->src_top0, CLK_SRC_TOP0_VAL); |
| 186 | write32(&exynos_clock->src_top1, CLK_SRC_TOP1_VAL); |
| 187 | write32(&exynos_clock->src_top2, TOP2_VAL); |
| 188 | write32(&exynos_clock->src_top3, CLK_SRC_TOP3_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 189 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 190 | write32(&exynos_clock->div_top0, CLK_DIV_TOP0_VAL); |
| 191 | while (read32(&exynos_clock->div_stat_top0)) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 192 | ; |
| 193 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 194 | write32(&exynos_clock->div_top1, CLK_DIV_TOP1_VAL); |
| 195 | while (read32(&exynos_clock->div_stat_top1)) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 196 | ; |
| 197 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 198 | write32(&exynos_clock->src_lex, CLK_SRC_LEX_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 199 | while (1) { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 200 | val = read32(&exynos_clock->mux_stat_lex); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 201 | if (val == (val | 1)) |
| 202 | break; |
| 203 | } |
| 204 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 205 | write32(&exynos_clock->div_lex, CLK_DIV_LEX_VAL); |
| 206 | while (read32(&exynos_clock->div_stat_lex)) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 207 | ; |
| 208 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 209 | write32(&exynos_clock->div_r0x, CLK_DIV_R0X_VAL); |
| 210 | while (read32(&exynos_clock->div_stat_r0x)) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 211 | ; |
| 212 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 213 | write32(&exynos_clock->div_r0x, CLK_DIV_R0X_VAL); |
| 214 | while (read32(&exynos_clock->div_stat_r0x)) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 215 | ; |
| 216 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 217 | write32(&exynos_clock->div_r1x, CLK_DIV_R1X_VAL); |
| 218 | while (read32(&exynos_clock->div_stat_r1x)) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 219 | ; |
| 220 | |
| 221 | if (mem->use_bpll) { |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 222 | write32(&exynos_clock->src_cdrex, MUX_BPLL_SEL_MASK | |
| 223 | MUX_MCLK_CDREX_SEL | MUX_MCLK_DPHY_SEL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 224 | } else { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 225 | write32(&exynos_clock->src_cdrex, CLK_REG_DISABLE); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 228 | write32(&exynos_clock->div_cdrex, CLK_DIV_CDREX_VAL); |
| 229 | while (read32(&exynos_clock->div_stat_cdrex)) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 230 | ; |
| 231 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 232 | val = read32(&exynos_clock->src_cpu); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 233 | val |= CLK_SRC_CPU_VAL; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 234 | write32(&exynos_clock->src_cpu, val); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 235 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 236 | val = read32(&exynos_clock->src_top2); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 237 | val |= CLK_SRC_TOP2_VAL; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 238 | write32(&exynos_clock->src_top2, val); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 239 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 240 | val = read32(&exynos_clock->src_core1); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 241 | val |= CLK_SRC_CORE1_VAL; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 242 | write32(&exynos_clock->src_core1, val); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 243 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 244 | write32(&exynos_clock->src_fsys, CLK_SRC_FSYS0_VAL); |
| 245 | write32(&exynos_clock->div_fsys0, CLK_DIV_FSYS0_VAL); |
| 246 | while (read32(&exynos_clock->div_stat_fsys0)) |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 247 | ; |
| 248 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 249 | write32(&exynos_clock->clkout_cmu_cpu, CLK_REG_DISABLE); |
| 250 | write32(&exynos_clock->clkout_cmu_core, CLK_REG_DISABLE); |
| 251 | write32(&exynos_clock->clkout_cmu_acp, CLK_REG_DISABLE); |
| 252 | write32(&exynos_clock->clkout_cmu_top, CLK_REG_DISABLE); |
| 253 | write32(&exynos_clock->clkout_cmu_lex, CLK_REG_DISABLE); |
| 254 | write32(&exynos_clock->clkout_cmu_r0x, CLK_REG_DISABLE); |
| 255 | write32(&exynos_clock->clkout_cmu_r1x, CLK_REG_DISABLE); |
| 256 | write32(&exynos_clock->clkout_cmu_cdrex, CLK_REG_DISABLE); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 257 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 258 | write32(&exynos_clock->src_peric0, CLK_SRC_PERIC0_VAL); |
| 259 | write32(&exynos_clock->div_peric0, CLK_DIV_PERIC0_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 260 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 261 | write32(&exynos_clock->src_peric1, CLK_SRC_PERIC1_VAL); |
| 262 | write32(&exynos_clock->div_peric1, CLK_DIV_PERIC1_VAL); |
| 263 | write32(&exynos_clock->div_peric2, CLK_DIV_PERIC2_VAL); |
| 264 | write32(&exynos_clock->sclk_src_isp, SCLK_SRC_ISP_VAL); |
| 265 | write32(&exynos_clock->sclk_div_isp, SCLK_DIV_ISP_VAL); |
| 266 | write32(&exynos_clock->div_isp0, CLK_DIV_ISP0_VAL); |
| 267 | write32(&exynos_clock->div_isp1, CLK_DIV_ISP1_VAL); |
| 268 | write32(&exynos_clock->div_isp2, CLK_DIV_ISP2_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 269 | |
| 270 | /* FIMD1 SRC CLK SELECTION */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 271 | write32(&exynos_clock->src_disp1_0, CLK_SRC_DISP1_0_VAL); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 272 | |
| 273 | val = MMC2_PRE_RATIO_VAL << MMC2_PRE_RATIO_OFFSET |
| 274 | | MMC2_RATIO_VAL << MMC2_RATIO_OFFSET |
| 275 | | MMC3_PRE_RATIO_VAL << MMC3_PRE_RATIO_OFFSET |
| 276 | | MMC3_RATIO_VAL << MMC3_RATIO_OFFSET; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 277 | write32(&exynos_clock->div_fsys2, val); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void clock_gate(void) |
| 281 | { |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 282 | /* CLK_GATE_IP_SYSRGT */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 283 | clrbits_le32(&exynos_clock->gate_ip_sysrgt, CLK_C2C_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 284 | |
| 285 | /* CLK_GATE_IP_ACP */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 286 | clrbits_le32(&exynos_clock->gate_ip_acp, CLK_SMMUG2D_MASK | |
| 287 | CLK_SMMUSSS_MASK | |
| 288 | CLK_SMMUMDMA_MASK | |
| 289 | CLK_ID_REMAPPER_MASK | |
| 290 | CLK_G2D_MASK | |
| 291 | CLK_SSS_MASK | |
| 292 | CLK_MDMA_MASK | |
| 293 | CLK_SECJTAG_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 294 | |
| 295 | /* CLK_GATE_BUS_SYSLFT */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 296 | clrbits_le32(&exynos_clock->gate_bus_syslft, CLK_EFCLK_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 297 | |
| 298 | /* CLK_GATE_IP_ISP0 */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 299 | clrbits_le32(&exynos_clock->gate_ip_isp0, CLK_UART_ISP_MASK | |
| 300 | CLK_WDT_ISP_MASK | |
| 301 | CLK_PWM_ISP_MASK | |
| 302 | CLK_MTCADC_ISP_MASK | |
| 303 | CLK_I2C1_ISP_MASK | |
| 304 | CLK_I2C0_ISP_MASK | |
| 305 | CLK_MPWM_ISP_MASK | |
| 306 | CLK_MCUCTL_ISP_MASK | |
| 307 | CLK_INT_COMB_ISP_MASK | |
| 308 | CLK_SMMU_MCUISP_MASK | |
| 309 | CLK_SMMU_SCALERP_MASK | |
| 310 | CLK_SMMU_SCALERC_MASK | |
| 311 | CLK_SMMU_FD_MASK | |
| 312 | CLK_SMMU_DRC_MASK | |
| 313 | CLK_SMMU_ISP_MASK | |
| 314 | CLK_GICISP_MASK | |
| 315 | CLK_ARM9S_MASK | |
| 316 | CLK_MCUISP_MASK | |
| 317 | CLK_SCALERP_MASK | |
| 318 | CLK_SCALERC_MASK | |
| 319 | CLK_FD_MASK | |
| 320 | CLK_DRC_MASK | |
| 321 | CLK_ISP_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 322 | |
| 323 | /* CLK_GATE_IP_ISP1 */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 324 | clrbits_le32(&exynos_clock->gate_ip_isp1, CLK_SPI1_ISP_MASK | |
| 325 | CLK_SPI0_ISP_MASK | |
| 326 | CLK_SMMU3DNR_MASK | |
| 327 | CLK_SMMUDIS1_MASK | |
| 328 | CLK_SMMUDIS0_MASK | |
| 329 | CLK_SMMUODC_MASK | |
| 330 | CLK_3DNR_MASK | |
| 331 | CLK_DIS_MASK | |
| 332 | CLK_ODC_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 333 | |
| 334 | /* CLK_GATE_SCLK_ISP */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 335 | clrbits_le32(&exynos_clock->gate_sclk_isp, SCLK_MPWM_ISP_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 336 | |
| 337 | /* CLK_GATE_IP_GSCL */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 338 | clrbits_le32(&exynos_clock->gate_ip_gscl, CLK_SMMUFIMC_LITE2_MASK | |
| 339 | CLK_SMMUFIMC_LITE1_MASK | |
| 340 | CLK_SMMUFIMC_LITE0_MASK | |
| 341 | CLK_SMMUGSCL3_MASK | |
| 342 | CLK_SMMUGSCL2_MASK | |
| 343 | CLK_SMMUGSCL1_MASK | |
| 344 | CLK_SMMUGSCL0_MASK | |
| 345 | CLK_GSCL_WRAP_B_MASK | |
| 346 | CLK_GSCL_WRAP_A_MASK | |
| 347 | CLK_CAMIF_TOP_MASK | |
| 348 | CLK_GSCL3_MASK | |
| 349 | CLK_GSCL2_MASK | |
| 350 | CLK_GSCL1_MASK | |
| 351 | CLK_GSCL0_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 352 | |
| 353 | /* CLK_GATE_IP_DISP1 */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 354 | clrbits_le32(&exynos_clock->gate_ip_disp1, CLK_SMMUTVX_MASK | |
| 355 | CLK_ASYNCTVX_MASK | |
| 356 | CLK_HDMI_MASK | |
| 357 | CLK_MIXER_MASK | |
| 358 | CLK_DSIM1_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 359 | |
| 360 | /* CLK_GATE_IP_MFC */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 361 | clrbits_le32(&exynos_clock->gate_ip_mfc, CLK_SMMUMFCR_MASK | |
| 362 | CLK_SMMUMFCL_MASK | |
| 363 | CLK_MFC_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 364 | |
| 365 | /* CLK_GATE_IP_GEN */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 366 | clrbits_le32(&exynos_clock->gate_ip_gen, CLK_SMMUMDMA1_MASK | |
| 367 | CLK_SMMUJPEG_MASK | |
| 368 | CLK_SMMUROTATOR_MASK | |
| 369 | CLK_MDMA1_MASK | |
| 370 | CLK_JPEG_MASK | |
| 371 | CLK_ROTATOR_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 372 | |
| 373 | /* CLK_GATE_IP_FSYS */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 374 | clrbits_le32(&exynos_clock->gate_ip_fsys, CLK_WDT_IOP_MASK | |
| 375 | CLK_SMMUMCU_IOP_MASK | |
| 376 | CLK_SATA_PHY_I2C_MASK | |
| 377 | CLK_SATA_PHY_CTRL_MASK | |
| 378 | CLK_MCUCTL_MASK | |
| 379 | CLK_NFCON_MASK | |
| 380 | CLK_SMMURTIC_MASK | |
| 381 | CLK_RTIC_MASK | |
| 382 | CLK_MIPI_HSI_MASK | |
| 383 | CLK_USBOTG_MASK | |
| 384 | CLK_SATA_MASK | |
| 385 | CLK_PDMA1_MASK | |
| 386 | CLK_PDMA0_MASK | |
| 387 | CLK_MCU_IOP_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 388 | |
| 389 | /* CLK_GATE_IP_PERIC */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 390 | clrbits_le32(&exynos_clock->gate_ip_peric, CLK_HS_I2C3_MASK | |
| 391 | CLK_HS_I2C2_MASK | |
| 392 | CLK_HS_I2C1_MASK | |
| 393 | CLK_HS_I2C0_MASK | |
| 394 | CLK_AC97_MASK | |
| 395 | CLK_SPDIF_MASK | |
| 396 | CLK_PCM2_MASK | |
| 397 | CLK_PCM1_MASK | |
| 398 | CLK_I2S2_MASK | |
| 399 | CLK_SPI2_MASK | |
| 400 | CLK_SPI0_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 401 | |
David Hendricks | aee444f | 2013-04-22 16:03:11 -0700 | [diff] [blame] | 402 | /* |
| 403 | * CLK_GATE_IP_PERIS |
| 404 | * Note: Keep CHIPID_APBIF ungated to ensure reading the product ID |
| 405 | * register (PRO_ID) works correctly when the OS kernel determines |
| 406 | * which chip it is running on. |
| 407 | */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 408 | clrbits_le32(&exynos_clock->gate_ip_peris, CLK_RTC_MASK | |
| 409 | CLK_TZPC9_MASK | |
| 410 | CLK_TZPC8_MASK | |
| 411 | CLK_TZPC7_MASK | |
| 412 | CLK_TZPC6_MASK | |
| 413 | CLK_TZPC5_MASK | |
| 414 | CLK_TZPC4_MASK | |
| 415 | CLK_TZPC3_MASK | |
| 416 | CLK_TZPC2_MASK | |
| 417 | CLK_TZPC1_MASK | |
| 418 | CLK_TZPC0_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 419 | |
| 420 | /* CLK_GATE_BLOCK */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 421 | clrbits_le32(&exynos_clock->gate_block, CLK_ACP_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 422 | |
| 423 | /* CLK_GATE_IP_CDREX */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 424 | clrbits_le32(&exynos_clock->gate_ip_cdrex, CLK_DPHY0_MASK | |
| 425 | CLK_DPHY1_MASK | |
| 426 | CLK_TZASC_DRBXR_MASK); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 427 | |
| 428 | } |
| 429 | |
| 430 | void clock_init_dp_clock(void) |
| 431 | { |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 432 | /* DP clock enable */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 433 | setbits_le32(&exynos_clock->gate_ip_disp1, CLK_GATE_DP1_ALLOW); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 434 | |
| 435 | /* We run DP at 267 Mhz */ |
Julius Werner | fa938c7 | 2013-08-29 14:17:36 -0700 | [diff] [blame] | 436 | setbits_le32(&exynos_clock->div_disp1_0, CLK_DIV_DISP1_0_FIMD1); |
Stefan Reinauer | 9fe20cb | 2012-12-07 17:18:43 -0800 | [diff] [blame] | 437 | } |