Angel Pons | bbc99cf | 2020-04-04 18:51:23 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
huang lin | c14b54d | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 2 | |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 3 | #include <assert.h> |
| 4 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 5 | #include <device/mmio.h> |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 6 | #include <delay.h> |
| 7 | #include <soc/addressmap.h> |
huang lin | c14b54d | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 8 | #include <soc/clock.h> |
Lin Huang | f5702e7 | 2016-03-19 22:45:19 +0800 | [diff] [blame] | 9 | #include <soc/grf.h> |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 10 | #include <soc/i2c.h> |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 11 | #include <soc/soc.h> |
| 12 | #include <stdint.h> |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 13 | #include <string.h> |
| 14 | |
| 15 | struct pll_div { |
| 16 | u32 refdiv; |
| 17 | u32 fbdiv; |
| 18 | u32 postdiv1; |
| 19 | u32 postdiv2; |
| 20 | u32 frac; |
Lin Huang | e3d78b8 | 2016-06-28 11:10:54 +0800 | [diff] [blame] | 21 | u32 freq; |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | #define PLL_DIVISORS(hz, _refdiv, _postdiv1, _postdiv2) {\ |
| 25 | .refdiv = _refdiv,\ |
| 26 | .fbdiv = (u32)((u64)hz * _refdiv * _postdiv1 * _postdiv2 / OSC_HZ),\ |
Lin Huang | e3d78b8 | 2016-06-28 11:10:54 +0800 | [diff] [blame] | 27 | .postdiv1 = _postdiv1, .postdiv2 = _postdiv2, .freq = hz};\ |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 28 | _Static_assert(((u64)hz * _refdiv * _postdiv1 * _postdiv2 / OSC_HZ) *\ |
| 29 | OSC_HZ / (_refdiv * _postdiv1 * _postdiv2) == hz,\ |
Julius Werner | 8e42bd1c | 2016-11-01 15:24:54 -0700 | [diff] [blame] | 30 | STRINGIFY(hz) " Hz cannot be hit with PLL "\ |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 31 | "divisors on line " STRINGIFY(__LINE__)) |
| 32 | |
Julius Werner | 8e42bd1c | 2016-11-01 15:24:54 -0700 | [diff] [blame] | 33 | static const struct pll_div gpll_init_cfg = PLL_DIVISORS(GPLL_HZ, 1, 4, 1); |
| 34 | static const struct pll_div cpll_init_cfg = PLL_DIVISORS(CPLL_HZ, 1, 3, 1); |
| 35 | static const struct pll_div ppll_init_cfg = PLL_DIVISORS(PPLL_HZ, 3, 2, 1); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 36 | |
Eric Gao | 61e6c44 | 2016-07-29 12:34:32 +0800 | [diff] [blame] | 37 | static const struct pll_div apll_1512_cfg = PLL_DIVISORS(1512*MHz, 1, 1, 1); |
| 38 | static const struct pll_div apll_600_cfg = PLL_DIVISORS(600*MHz, 1, 3, 1); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 39 | |
Lin Huang | 3d703bc | 2016-06-28 14:19:18 +0800 | [diff] [blame] | 40 | static const struct pll_div *apll_cfgs[] = { |
Eric Gao | 61e6c44 | 2016-07-29 12:34:32 +0800 | [diff] [blame] | 41 | [APLL_1512_MHZ] = &apll_1512_cfg, |
Lin Huang | 3d703bc | 2016-06-28 14:19:18 +0800 | [diff] [blame] | 42 | [APLL_600_MHZ] = &apll_600_cfg, |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | enum { |
| 46 | /* PLL_CON0 */ |
| 47 | PLL_FBDIV_MASK = 0xfff, |
| 48 | PLL_FBDIV_SHIFT = 0, |
| 49 | |
| 50 | /* PLL_CON1 */ |
| 51 | PLL_POSTDIV2_MASK = 0x7, |
| 52 | PLL_POSTDIV2_SHIFT = 12, |
| 53 | PLL_POSTDIV1_MASK = 0x7, |
| 54 | PLL_POSTDIV1_SHIFT = 8, |
| 55 | PLL_REFDIV_MASK = 0x3f, |
| 56 | PLL_REFDIV_SHIFT = 0, |
| 57 | |
| 58 | /* PLL_CON2 */ |
| 59 | PLL_LOCK_STATUS_MASK = 1, |
| 60 | PLL_LOCK_STATUS_SHIFT = 31, |
| 61 | PLL_FRACDIV_MASK = 0xffffff, |
| 62 | PLL_FRACDIV_SHIFT = 0, |
| 63 | |
| 64 | /* PLL_CON3 */ |
| 65 | PLL_MODE_MASK = 3, |
| 66 | PLL_MODE_SHIFT = 8, |
| 67 | PLL_MODE_SLOW = 0, |
| 68 | PLL_MODE_NORM, |
| 69 | PLL_MODE_DEEP, |
| 70 | PLL_DSMPD_MASK = 1, |
| 71 | PLL_DSMPD_SHIFT = 3, |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 72 | PLL_FRAC_MODE = 0, |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 73 | PLL_INTEGER_MODE = 1, |
| 74 | |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 75 | /* PLL_CON4 */ |
| 76 | PLL_SSMOD_BP_MASK = 1, |
| 77 | PLL_SSMOD_BP_SHIFT = 0, |
| 78 | PLL_SSMOD_DIS_SSCG_MASK = 1, |
| 79 | PLL_SSMOD_DIS_SSCG_SHIFT = 1, |
| 80 | PLL_SSMOD_RESET_MASK = 1, |
| 81 | PLL_SSMOD_RESET_SHIFT = 2, |
| 82 | PLL_SSMOD_DOWNSPEAD_MASK = 1, |
| 83 | PLL_SSMOD_DOWNSPEAD_SHIFT = 3, |
Subrata Banik | 8e6d5f2 | 2020-08-30 13:51:44 +0530 | [diff] [blame] | 84 | PLL_SSMOD_DIVVAL_MASK = 0xf, |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 85 | PLL_SSMOD_DIVVAL_SHIFT = 4, |
| 86 | PLL_SSMOD_SPREADAMP_MASK = 0x1f, |
| 87 | PLL_SSMOD_SPREADAMP_SHIFT = 8, |
| 88 | |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 89 | /* PMUCRU_CLKSEL_CON0 */ |
| 90 | PMU_PCLK_DIV_CON_MASK = 0x1f, |
| 91 | PMU_PCLK_DIV_CON_SHIFT = 0, |
| 92 | |
Shunqian Zheng | 347c83c | 2016-04-13 22:34:39 +0800 | [diff] [blame] | 93 | /* PMUCRU_CLKSEL_CON1 */ |
| 94 | SPI3_PLL_SEL_MASK = 1, |
| 95 | SPI3_PLL_SEL_SHIFT = 7, |
| 96 | SPI3_PLL_SEL_24M = 0, |
| 97 | SPI3_PLL_SEL_PPLL = 1, |
| 98 | SPI3_DIV_CON_MASK = 0x7f, |
| 99 | SPI3_DIV_CON_SHIFT = 0x0, |
| 100 | |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 101 | /* PMUCRU_CLKSEL_CON2 */ |
| 102 | I2C_DIV_CON_MASK = 0x7f, |
| 103 | I2C8_DIV_CON_SHIFT = 8, |
| 104 | I2C0_DIV_CON_SHIFT = 0, |
| 105 | |
| 106 | /* PMUCRU_CLKSEL_CON3 */ |
| 107 | I2C4_DIV_CON_SHIFT = 0, |
| 108 | |
Lin Huang | bdd06de | 2016-06-28 15:21:20 +0800 | [diff] [blame] | 109 | /* CLKSEL_CON0 / CLKSEL_CON2 */ |
| 110 | ACLKM_CORE_DIV_CON_MASK = 0x1f, |
| 111 | ACLKM_CORE_DIV_CON_SHIFT = 8, |
| 112 | CLK_CORE_PLL_SEL_MASK = 3, |
| 113 | CLK_CORE_PLL_SEL_SHIFT = 6, |
| 114 | CLK_CORE_PLL_SEL_ALPLL = 0x0, |
| 115 | CLK_CORE_PLL_SEL_ABPLL = 0x1, |
| 116 | CLK_CORE_PLL_SEL_DPLL = 0x10, |
| 117 | CLK_CORE_PLL_SEL_GPLL = 0x11, |
| 118 | CLK_CORE_DIV_MASK = 0x1f, |
| 119 | CLK_CORE_DIV_SHIFT = 0, |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 120 | |
Lin Huang | bdd06de | 2016-06-28 15:21:20 +0800 | [diff] [blame] | 121 | /* CLKSEL_CON1 / CLKSEL_CON3 */ |
| 122 | PCLK_DBG_DIV_MASK = 0x1f, |
| 123 | PCLK_DBG_DIV_SHIFT = 0x8, |
| 124 | ATCLK_CORE_DIV_MASK = 0x1f, |
| 125 | ATCLK_CORE_DIV_SHIFT = 0, |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 126 | |
| 127 | /* CLKSEL_CON14 */ |
| 128 | PCLK_PERIHP_DIV_CON_MASK = 0x7, |
| 129 | PCLK_PERIHP_DIV_CON_SHIFT = 12, |
| 130 | HCLK_PERIHP_DIV_CON_MASK = 3, |
| 131 | HCLK_PERIHP_DIV_CON_SHIFT = 8, |
| 132 | ACLK_PERIHP_PLL_SEL_MASK = 1, |
| 133 | ACLK_PERIHP_PLL_SEL_SHIFT = 7, |
| 134 | ACLK_PERIHP_PLL_SEL_CPLL = 0, |
| 135 | ACLK_PERIHP_PLL_SEL_GPLL = 1, |
| 136 | ACLK_PERIHP_DIV_CON_MASK = 0x1f, |
| 137 | ACLK_PERIHP_DIV_CON_SHIFT = 0, |
| 138 | |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 139 | /* CLKSEL_CON21 */ |
| 140 | ACLK_EMMC_PLL_SEL_MASK = 0x1, |
| 141 | ACLK_EMMC_PLL_SEL_SHIFT = 7, |
| 142 | ACLK_EMMC_PLL_SEL_GPLL = 0x1, |
| 143 | ACLK_EMMC_DIV_CON_MASK = 0x1f, |
| 144 | ACLK_EMMC_DIV_CON_SHIFT = 0, |
| 145 | |
| 146 | /* CLKSEL_CON22 */ |
| 147 | CLK_EMMC_PLL_MASK = 0x7, |
| 148 | CLK_EMMC_PLL_SHIFT = 8, |
| 149 | CLK_EMMC_PLL_SEL_GPLL = 0x1, |
| 150 | CLK_EMMC_DIV_CON_MASK = 0x7f, |
| 151 | CLK_EMMC_DIV_CON_SHIFT = 0, |
| 152 | |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 153 | /* CLKSEL_CON23 */ |
| 154 | PCLK_PERILP0_DIV_CON_MASK = 0x7, |
| 155 | PCLK_PERILP0_DIV_CON_SHIFT = 12, |
| 156 | HCLK_PERILP0_DIV_CON_MASK = 3, |
| 157 | HCLK_PERILP0_DIV_CON_SHIFT = 8, |
| 158 | ACLK_PERILP0_PLL_SEL_MASK = 1, |
| 159 | ACLK_PERILP0_PLL_SEL_SHIFT = 7, |
| 160 | ACLK_PERILP0_PLL_SEL_CPLL = 0, |
| 161 | ACLK_PERILP0_PLL_SEL_GPLL = 1, |
| 162 | ACLK_PERILP0_DIV_CON_MASK = 0x1f, |
| 163 | ACLK_PERILP0_DIV_CON_SHIFT = 0, |
| 164 | |
| 165 | /* CLKSEL_CON25 */ |
| 166 | PCLK_PERILP1_DIV_CON_MASK = 0x7, |
| 167 | PCLK_PERILP1_DIV_CON_SHIFT = 8, |
| 168 | HCLK_PERILP1_PLL_SEL_MASK = 1, |
| 169 | HCLK_PERILP1_PLL_SEL_SHIFT = 7, |
| 170 | HCLK_PERILP1_PLL_SEL_CPLL = 0, |
| 171 | HCLK_PERILP1_PLL_SEL_GPLL = 1, |
| 172 | HCLK_PERILP1_DIV_CON_MASK = 0x1f, |
| 173 | HCLK_PERILP1_DIV_CON_SHIFT = 0, |
Shunqian Zheng | ce60d5a | 2016-04-21 23:53:08 +0800 | [diff] [blame] | 174 | |
Lin Huang | bf48fbb | 2016-03-23 19:24:53 +0800 | [diff] [blame] | 175 | /* CLKSEL_CON26 */ |
| 176 | CLK_SARADC_DIV_CON_MASK = 0xff, |
| 177 | CLK_SARADC_DIV_CON_SHIFT = 8, |
| 178 | |
Shunqian Zheng | f4181ce | 2016-05-06 16:50:48 +0800 | [diff] [blame] | 179 | /* CLKSEL_CON27 */ |
| 180 | CLK_TSADC_SEL_X24M = 0x0, |
| 181 | CLK_TSADC_SEL_MASK = 1, |
| 182 | CLK_TSADC_SEL_SHIFT = 15, |
| 183 | CLK_TSADC_DIV_CON_MASK = 0x3ff, |
| 184 | CLK_TSADC_DIV_CON_SHIFT = 0, |
| 185 | |
Lin Huang | 4ecccff | 2017-01-18 09:44:34 +0800 | [diff] [blame] | 186 | /* CLKSEL_CON44 */ |
| 187 | CLK_PCLK_EDP_PLL_SEL_MASK = 1, |
| 188 | CLK_PCLK_EDP_PLL_SEL_SHIFT = 15, |
| 189 | CLK_PCLK_EDP_PLL_SEL_CPLL = 0, |
| 190 | CLK_PCLK_EDP_DIV_CON_MASK = 0x3f, |
| 191 | CLK_PCLK_EDP_DIV_CON_SHIFT = 8, |
| 192 | |
Shunqian Zheng | c7f32a5 | 2016-05-04 15:54:37 +0800 | [diff] [blame] | 193 | /* CLKSEL_CON47 & CLKSEL_CON48 */ |
| 194 | ACLK_VOP_PLL_SEL_MASK = 0x3, |
| 195 | ACLK_VOP_PLL_SEL_SHIFT = 6, |
| 196 | ACLK_VOP_PLL_SEL_CPLL = 0x1, |
| 197 | ACLK_VOP_DIV_CON_MASK = 0x1f, |
| 198 | ACLK_VOP_DIV_CON_SHIFT = 0, |
| 199 | |
| 200 | /* CLKSEL_CON49 & CLKSEL_CON50 */ |
| 201 | DCLK_VOP_DCLK_SEL_MASK = 1, |
| 202 | DCLK_VOP_DCLK_SEL_SHIFT = 11, |
| 203 | DCLK_VOP_DCLK_SEL_DIVOUT = 0, |
| 204 | DCLK_VOP_PLL_SEL_MASK = 3, |
| 205 | DCLK_VOP_PLL_SEL_SHIFT = 8, |
| 206 | DCLK_VOP_PLL_SEL_VPLL = 0, |
| 207 | DCLK_VOP_DIV_CON_MASK = 0xff, |
| 208 | DCLK_VOP_DIV_CON_SHIFT = 0, |
| 209 | |
Shunqian Zheng | 347c83c | 2016-04-13 22:34:39 +0800 | [diff] [blame] | 210 | /* CLKSEL_CON58 */ |
| 211 | CLK_SPI_PLL_SEL_MASK = 1, |
| 212 | CLK_SPI_PLL_SEL_CPLL = 0, |
| 213 | CLK_SPI_PLL_SEL_GPLL = 1, |
| 214 | CLK_SPI_PLL_DIV_CON_MASK = 0x7f, |
| 215 | CLK_SPI5_PLL_DIV_CON_SHIFT = 8, |
| 216 | CLK_SPI5_PLL_SEL_SHIFT = 15, |
| 217 | |
| 218 | /* CLKSEL_CON59 */ |
| 219 | CLK_SPI1_PLL_SEL_SHIFT = 15, |
| 220 | CLK_SPI1_PLL_DIV_CON_SHIFT = 8, |
| 221 | CLK_SPI0_PLL_SEL_SHIFT = 7, |
| 222 | CLK_SPI0_PLL_DIV_CON_SHIFT = 0, |
| 223 | |
| 224 | /* CLKSEL_CON60 */ |
| 225 | CLK_SPI4_PLL_SEL_SHIFT = 15, |
| 226 | CLK_SPI4_PLL_DIV_CON_SHIFT = 8, |
| 227 | CLK_SPI2_PLL_SEL_SHIFT = 7, |
| 228 | CLK_SPI2_PLL_DIV_CON_SHIFT = 0, |
| 229 | |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 230 | /* CLKSEL_CON61 */ |
| 231 | CLK_I2C_PLL_SEL_MASK = 1, |
| 232 | CLK_I2C_PLL_SEL_CPLL = 0, |
| 233 | CLK_I2C_PLL_SEL_GPLL = 1, |
| 234 | CLK_I2C5_PLL_SEL_SHIFT = 15, |
| 235 | CLK_I2C5_DIV_CON_SHIFT = 8, |
| 236 | CLK_I2C1_PLL_SEL_SHIFT = 7, |
| 237 | CLK_I2C1_DIV_CON_SHIFT = 0, |
| 238 | |
| 239 | /* CLKSEL_CON62 */ |
| 240 | CLK_I2C6_PLL_SEL_SHIFT = 15, |
| 241 | CLK_I2C6_DIV_CON_SHIFT = 8, |
| 242 | CLK_I2C2_PLL_SEL_SHIFT = 7, |
| 243 | CLK_I2C2_DIV_CON_SHIFT = 0, |
| 244 | |
| 245 | /* CLKSEL_CON63 */ |
| 246 | CLK_I2C7_PLL_SEL_SHIFT = 15, |
| 247 | CLK_I2C7_DIV_CON_SHIFT = 8, |
| 248 | CLK_I2C3_PLL_SEL_SHIFT = 7, |
| 249 | CLK_I2C3_DIV_CON_SHIFT = 0, |
| 250 | |
Shunqian Zheng | ce60d5a | 2016-04-21 23:53:08 +0800 | [diff] [blame] | 251 | /* CRU_SOFTRST_CON4 */ |
| 252 | RESETN_DDR0_REQ_MASK = 1, |
| 253 | RESETN_DDR0_REQ_SHIFT = 8, |
| 254 | RESETN_DDRPHY0_REQ_MASK = 1, |
| 255 | RESETN_DDRPHY0_REQ_SHIFT = 9, |
| 256 | RESETN_DDR1_REQ_MASK = 1, |
| 257 | RESETN_DDR1_REQ_SHIFT = 12, |
| 258 | RESETN_DDRPHY1_REQ_MASK = 1, |
| 259 | RESETN_DDRPHY1_REQ_SHIFT = 13, |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | #define VCO_MAX_KHZ (3200 * (MHz / KHz)) |
| 263 | #define VCO_MIN_KHZ (800 * (MHz / KHz)) |
| 264 | #define OUTPUT_MAX_KHZ (3200 * (MHz / KHz)) |
| 265 | #define OUTPUT_MIN_KHZ (16 * (MHz / KHz)) |
| 266 | |
| 267 | /* the div restrictions of pll in integer mode, |
| 268 | * these are defined in * CRU_*PLL_CON0 or PMUCRU_*PLL_CON0 |
| 269 | */ |
| 270 | #define PLL_DIV_MIN 16 |
| 271 | #define PLL_DIV_MAX 3200 |
| 272 | |
| 273 | /* How to calculate the PLL(from TRM V0.3 Part 1 Page 63): |
| 274 | * Formulas also embedded within the Fractional PLL Verilog model: |
| 275 | * If DSMPD = 1 (DSM is disabled, "integer mode") |
| 276 | * FOUTVCO = FREF / REFDIV * FBDIV |
| 277 | * FOUTPOSTDIV = FOUTVCO / POSTDIV1 / POSTDIV2 |
| 278 | * Where: |
| 279 | * FOUTVCO = Fractional PLL non-divided output frequency |
| 280 | * FOUTPOSTDIV = Fractional PLL divided output frequency |
| 281 | * (output of second post divider) |
| 282 | * FREF = Fractional PLL input reference frequency, (the OSC_HZ 24MHz input) |
| 283 | * REFDIV = Fractional PLL input reference clock divider |
| 284 | * FBDIV = Integer value programmed into feedback divide |
| 285 | * |
| 286 | */ |
| 287 | static void rkclk_set_pll(u32 *pll_con, const struct pll_div *div) |
| 288 | { |
| 289 | /* All 8 PLLs have same VCO and output frequency range restrictions. */ |
| 290 | u32 vco_khz = OSC_HZ / 1000 * div->fbdiv / div->refdiv; |
| 291 | u32 output_khz = vco_khz / div->postdiv1 / div->postdiv2; |
| 292 | |
| 293 | printk(BIOS_DEBUG, "PLL at %p: fbdiv=%d, refdiv=%d, postdiv1=%d, " |
Elyes HAOUAS | 8d1b0f1 | 2020-02-20 18:20:57 +0100 | [diff] [blame] | 294 | "postdiv2=%d, vco=%u kHz, output=%u kHz\n", |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 295 | pll_con, div->fbdiv, div->refdiv, div->postdiv1, |
| 296 | div->postdiv2, vco_khz, output_khz); |
| 297 | assert(vco_khz >= VCO_MIN_KHZ && vco_khz <= VCO_MAX_KHZ && |
| 298 | output_khz >= OUTPUT_MIN_KHZ && output_khz <= OUTPUT_MAX_KHZ && |
| 299 | div->fbdiv >= PLL_DIV_MIN && div->fbdiv <= PLL_DIV_MAX); |
| 300 | |
| 301 | /* When power on or changing PLL setting, |
| 302 | * we must force PLL into slow mode to ensure output stable clock. |
| 303 | */ |
| 304 | write32(&pll_con[3], RK_CLRSETBITS(PLL_MODE_MASK << PLL_MODE_SHIFT, |
| 305 | PLL_MODE_SLOW << PLL_MODE_SHIFT)); |
| 306 | |
| 307 | /* use integer mode */ |
| 308 | write32(&pll_con[3], |
| 309 | RK_CLRSETBITS(PLL_DSMPD_MASK << PLL_DSMPD_SHIFT, |
| 310 | PLL_INTEGER_MODE << PLL_DSMPD_SHIFT)); |
| 311 | |
| 312 | write32(&pll_con[0], RK_CLRSETBITS(PLL_FBDIV_MASK << PLL_FBDIV_SHIFT, |
| 313 | div->fbdiv << PLL_FBDIV_SHIFT)); |
| 314 | write32(&pll_con[1], |
| 315 | RK_CLRSETBITS(PLL_POSTDIV2_MASK << PLL_POSTDIV2_SHIFT | |
| 316 | PLL_POSTDIV1_MASK << PLL_POSTDIV1_SHIFT | |
| 317 | PLL_REFDIV_MASK | PLL_REFDIV_SHIFT, |
| 318 | (div->postdiv2 << PLL_POSTDIV2_SHIFT) | |
| 319 | (div->postdiv1 << PLL_POSTDIV1_SHIFT) | |
| 320 | (div->refdiv << PLL_REFDIV_SHIFT))); |
| 321 | |
| 322 | /* waiting for pll lock */ |
| 323 | while (!(read32(&pll_con[2]) & (1 << PLL_LOCK_STATUS_SHIFT))) |
| 324 | udelay(1); |
| 325 | |
| 326 | /* pll enter normal mode */ |
| 327 | write32(&pll_con[3], RK_CLRSETBITS(PLL_MODE_MASK << PLL_MODE_SHIFT, |
| 328 | PLL_MODE_NORM << PLL_MODE_SHIFT)); |
| 329 | } |
| 330 | |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 331 | /* |
| 332 | * Configure the DPLL spread spectrum feature on memory clock. |
| 333 | * Configure sequence: |
Martin Roth | 9641a92 | 2018-05-20 17:46:51 -0600 | [diff] [blame] | 334 | * 1. PLL been configured as frac mode, and DACPD should be set to 1'b0. |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 335 | * 2. Configure DOWNSPERAD, SPREAD, DIVVAL(option: configure xPLL_CON5 with |
| 336 | * extern wave table). |
Martin Roth | 9641a92 | 2018-05-20 17:46:51 -0600 | [diff] [blame] | 337 | * 3. set ssmod_disable_sscg = 1'b0, and set ssmod_bp = 1'b0. |
| 338 | * 4. Assert RESET = 1'b1 to SSMOD. |
| 339 | * 5. RESET = 1'b0 on SSMOD. |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 340 | * 6. Adjust SPREAD/DIVVAL/DOWNSPREAD. |
| 341 | */ |
| 342 | static void rkclk_set_dpllssc(struct pll_div *dpll_cfg) |
| 343 | { |
| 344 | u32 divval; |
| 345 | |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 346 | assert(dpll_cfg->refdiv && dpll_cfg->refdiv <= 6); |
| 347 | |
| 348 | /* |
| 349 | * Need to acquire ~30kHZ which is the target modulation frequency. |
| 350 | * The modulation frequency ~ 30kHz= OSC_HZ/revdiv/128/divval |
| 351 | * (the 128 is the number points in the query table). |
| 352 | */ |
| 353 | divval = OSC_HZ / 128 / (30 * KHz) / dpll_cfg->refdiv; |
| 354 | |
| 355 | /* |
| 356 | * Use frac mode. |
| 357 | * Make sure the output frequency isn't offset, set 0 for Fractional |
| 358 | * part of feedback divide. |
| 359 | */ |
| 360 | write32(&cru_ptr->dpll_con[3], |
| 361 | RK_CLRSETBITS(PLL_DSMPD_MASK << PLL_DSMPD_SHIFT, |
| 362 | PLL_FRAC_MODE << PLL_DSMPD_SHIFT)); |
Julius Werner | 55009af | 2019-12-02 22:03:27 -0800 | [diff] [blame] | 363 | clrsetbits32(&cru_ptr->dpll_con[2], |
| 364 | PLL_FRACDIV_MASK << PLL_FRACDIV_SHIFT, |
| 365 | 0 << PLL_FRACDIV_SHIFT); |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 366 | |
| 367 | /* |
| 368 | * Configure SSC divval. |
| 369 | * Spread amplitude range = 0.1 * SPREAD[4:0] (%). |
| 370 | * The below 8 means SPREAD[4:0] that appears to mitigate EMI on boards |
| 371 | * tested. Center and down spread modulation amplitudes based on the |
| 372 | * value of SPREAD. |
| 373 | * SPREAD[4:0] Center Spread Down Spread |
| 374 | * 0 0 0 |
Martin Roth | 9641a92 | 2018-05-20 17:46:51 -0600 | [diff] [blame] | 375 | * 1 +/-0.1% -0.10% |
| 376 | * 2 +/-0.2% -0.20% |
| 377 | * 3 +/-0.3% -0.30% |
| 378 | * 4 +/-0.4% -0.40% |
| 379 | * 5 +/-0.5% -0.50% |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 380 | * ... |
Martin Roth | 9641a92 | 2018-05-20 17:46:51 -0600 | [diff] [blame] | 381 | * 31 +/-3.1% -3.10% |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 382 | */ |
| 383 | write32(&cru_ptr->dpll_con[4], |
| 384 | RK_CLRSETBITS(PLL_SSMOD_DIVVAL_MASK << PLL_SSMOD_DIVVAL_SHIFT, |
| 385 | divval << PLL_SSMOD_DIVVAL_SHIFT)); |
| 386 | write32(&cru_ptr->dpll_con[4], |
| 387 | RK_CLRSETBITS(PLL_SSMOD_SPREADAMP_MASK << |
| 388 | PLL_SSMOD_SPREADAMP_SHIFT, |
| 389 | 8 << PLL_SSMOD_SPREADAMP_SHIFT)); |
| 390 | |
| 391 | /* Enable SSC for DPLL */ |
| 392 | write32(&cru_ptr->dpll_con[4], |
| 393 | RK_CLRBITS(PLL_SSMOD_BP_MASK << PLL_SSMOD_BP_SHIFT | |
| 394 | PLL_SSMOD_DIS_SSCG_MASK << PLL_SSMOD_DIS_SSCG_SHIFT)); |
| 395 | |
| 396 | /* Deassert reset SSMOD */ |
| 397 | write32(&cru_ptr->dpll_con[4], |
| 398 | RK_CLRBITS(PLL_SSMOD_RESET_MASK << PLL_SSMOD_RESET_SHIFT)); |
| 399 | |
| 400 | udelay(20); |
| 401 | } |
| 402 | |
Shunqian Zheng | c7f32a5 | 2016-05-04 15:54:37 +0800 | [diff] [blame] | 403 | static int pll_para_config(u32 freq_hz, struct pll_div *div) |
| 404 | { |
| 405 | u32 ref_khz = OSC_HZ / KHz, refdiv, fbdiv = 0; |
| 406 | u32 postdiv1, postdiv2 = 1; |
| 407 | u32 fref_khz; |
| 408 | u32 diff_khz, best_diff_khz; |
| 409 | const u32 max_refdiv = 63, max_fbdiv = 3200, min_fbdiv = 16; |
| 410 | const u32 max_postdiv1 = 7, max_postdiv2 = 7; |
| 411 | u32 vco_khz; |
| 412 | u32 freq_khz = freq_hz / KHz; |
| 413 | |
| 414 | if (!freq_hz) { |
| 415 | printk(BIOS_ERR, "%s: the frequency can't be 0 Hz\n", __func__); |
| 416 | return -1; |
| 417 | } |
| 418 | |
Elyes HAOUAS | 6df3b64 | 2018-11-26 22:53:49 +0100 | [diff] [blame] | 419 | postdiv1 = DIV_ROUND_UP(VCO_MIN_KHZ, freq_khz); |
Shunqian Zheng | c7f32a5 | 2016-05-04 15:54:37 +0800 | [diff] [blame] | 420 | if (postdiv1 > max_postdiv1) { |
Elyes HAOUAS | 6df3b64 | 2018-11-26 22:53:49 +0100 | [diff] [blame] | 421 | postdiv2 = DIV_ROUND_UP(postdiv1, max_postdiv1); |
| 422 | postdiv1 = DIV_ROUND_UP(postdiv1, postdiv2); |
Shunqian Zheng | c7f32a5 | 2016-05-04 15:54:37 +0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | vco_khz = freq_khz * postdiv1 * postdiv2; |
| 426 | |
| 427 | if (vco_khz < VCO_MIN_KHZ || vco_khz > VCO_MAX_KHZ || |
| 428 | postdiv2 > max_postdiv2) { |
| 429 | printk(BIOS_ERR, "%s: Cannot find out a supported VCO" |
| 430 | " for Frequency (%uHz).\n", __func__, freq_hz); |
| 431 | return -1; |
| 432 | } |
| 433 | |
| 434 | div->postdiv1 = postdiv1; |
| 435 | div->postdiv2 = postdiv2; |
| 436 | |
| 437 | best_diff_khz = vco_khz; |
| 438 | for (refdiv = 1; refdiv < max_refdiv && best_diff_khz; refdiv++) { |
| 439 | fref_khz = ref_khz / refdiv; |
| 440 | |
| 441 | fbdiv = vco_khz / fref_khz; |
| 442 | if ((fbdiv >= max_fbdiv) || (fbdiv <= min_fbdiv)) |
| 443 | continue; |
| 444 | diff_khz = vco_khz - fbdiv * fref_khz; |
| 445 | if (fbdiv + 1 < max_fbdiv && diff_khz > fref_khz / 2) { |
| 446 | fbdiv++; |
| 447 | diff_khz = fref_khz - diff_khz; |
| 448 | } |
| 449 | |
| 450 | if (diff_khz >= best_diff_khz) |
| 451 | continue; |
| 452 | |
| 453 | best_diff_khz = diff_khz; |
| 454 | div->refdiv = refdiv; |
| 455 | div->fbdiv = fbdiv; |
| 456 | } |
| 457 | |
| 458 | if (best_diff_khz > 4 * (MHz/KHz)) { |
| 459 | printk(BIOS_ERR, "%s: Failed to match output frequency %u, " |
| 460 | "difference is %u Hz,exceed 4MHZ\n", __func__, freq_hz, |
| 461 | best_diff_khz * KHz); |
| 462 | return -1; |
| 463 | } |
| 464 | return 0; |
| 465 | } |
| 466 | |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 467 | void rkclk_init(void) |
| 468 | { |
| 469 | u32 aclk_div; |
| 470 | u32 hclk_div; |
| 471 | u32 pclk_div; |
| 472 | |
| 473 | /* some cru registers changed by bootrom, we'd better reset them to |
| 474 | * reset/default values described in TRM to avoid confusion in kernel. |
Elyes HAOUAS | 8d1b0f1 | 2020-02-20 18:20:57 +0100 | [diff] [blame] | 475 | * Please consider these three lines as a fix of bootrom bug. |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 476 | */ |
| 477 | write32(&cru_ptr->clksel_con[12], 0xffff4101); |
| 478 | write32(&cru_ptr->clksel_con[19], 0xffff033f); |
| 479 | write32(&cru_ptr->clksel_con[56], 0x00030003); |
| 480 | |
| 481 | /* configure pmu pll(ppll) */ |
| 482 | rkclk_set_pll(&pmucru_ptr->ppll_con[0], &ppll_init_cfg); |
| 483 | |
| 484 | /* configure pmu pclk */ |
| 485 | pclk_div = PPLL_HZ / PMU_PCLK_HZ - 1; |
Julius Werner | 8e42bd1c | 2016-11-01 15:24:54 -0700 | [diff] [blame] | 486 | assert((unsigned int)(PPLL_HZ - (pclk_div + 1) * PMU_PCLK_HZ) <= pclk_div |
| 487 | && pclk_div <= 0x1f); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 488 | write32(&pmucru_ptr->pmucru_clksel[0], |
| 489 | RK_CLRSETBITS(PMU_PCLK_DIV_CON_MASK << PMU_PCLK_DIV_CON_SHIFT, |
| 490 | pclk_div << PMU_PCLK_DIV_CON_SHIFT)); |
| 491 | |
| 492 | /* configure gpll cpll */ |
| 493 | rkclk_set_pll(&cru_ptr->gpll_con[0], &gpll_init_cfg); |
| 494 | rkclk_set_pll(&cru_ptr->cpll_con[0], &cpll_init_cfg); |
| 495 | |
| 496 | /* configure perihp aclk, hclk, pclk */ |
| 497 | aclk_div = GPLL_HZ / PERIHP_ACLK_HZ - 1; |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 498 | assert((aclk_div + 1) * PERIHP_ACLK_HZ == GPLL_HZ && aclk_div <= 0x1f); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 499 | |
| 500 | hclk_div = PERIHP_ACLK_HZ / PERIHP_HCLK_HZ - 1; |
| 501 | assert((hclk_div + 1) * PERIHP_HCLK_HZ == |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 502 | PERIHP_ACLK_HZ && (hclk_div <= 0x3)); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 503 | |
| 504 | pclk_div = PERIHP_ACLK_HZ / PERIHP_PCLK_HZ - 1; |
| 505 | assert((pclk_div + 1) * PERIHP_PCLK_HZ == |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 506 | PERIHP_ACLK_HZ && (pclk_div <= 0x7)); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 507 | |
| 508 | write32(&cru_ptr->clksel_con[14], |
| 509 | RK_CLRSETBITS(PCLK_PERIHP_DIV_CON_MASK << |
| 510 | PCLK_PERIHP_DIV_CON_SHIFT | |
| 511 | HCLK_PERIHP_DIV_CON_MASK << |
| 512 | HCLK_PERIHP_DIV_CON_SHIFT | |
| 513 | ACLK_PERIHP_PLL_SEL_MASK << |
| 514 | ACLK_PERIHP_PLL_SEL_SHIFT | |
| 515 | ACLK_PERIHP_DIV_CON_MASK << |
| 516 | ACLK_PERIHP_DIV_CON_SHIFT, |
| 517 | pclk_div << PCLK_PERIHP_DIV_CON_SHIFT | |
| 518 | hclk_div << HCLK_PERIHP_DIV_CON_SHIFT | |
| 519 | ACLK_PERIHP_PLL_SEL_GPLL << |
| 520 | ACLK_PERIHP_PLL_SEL_SHIFT | |
| 521 | aclk_div << ACLK_PERIHP_DIV_CON_SHIFT)); |
| 522 | |
| 523 | /* configure perilp0 aclk, hclk, pclk */ |
| 524 | aclk_div = GPLL_HZ / PERILP0_ACLK_HZ - 1; |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 525 | assert((aclk_div + 1) * PERILP0_ACLK_HZ == GPLL_HZ && aclk_div <= 0x1f); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 526 | |
| 527 | hclk_div = PERILP0_ACLK_HZ / PERILP0_HCLK_HZ - 1; |
| 528 | assert((hclk_div + 1) * PERILP0_HCLK_HZ == |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 529 | PERILP0_ACLK_HZ && (hclk_div <= 0x3)); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 530 | |
| 531 | pclk_div = PERILP0_ACLK_HZ / PERILP0_PCLK_HZ - 1; |
| 532 | assert((pclk_div + 1) * PERILP0_PCLK_HZ == |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 533 | PERILP0_ACLK_HZ && (pclk_div <= 0x7)); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 534 | |
| 535 | write32(&cru_ptr->clksel_con[23], |
| 536 | RK_CLRSETBITS(PCLK_PERILP0_DIV_CON_MASK << |
| 537 | PCLK_PERILP0_DIV_CON_SHIFT | |
| 538 | HCLK_PERILP0_DIV_CON_MASK << |
| 539 | HCLK_PERILP0_DIV_CON_SHIFT | |
| 540 | ACLK_PERILP0_PLL_SEL_MASK << |
| 541 | ACLK_PERILP0_PLL_SEL_SHIFT | |
| 542 | ACLK_PERILP0_DIV_CON_MASK << |
| 543 | ACLK_PERILP0_DIV_CON_SHIFT, |
| 544 | pclk_div << PCLK_PERILP0_DIV_CON_SHIFT | |
| 545 | hclk_div << HCLK_PERILP0_DIV_CON_SHIFT | |
| 546 | ACLK_PERILP0_PLL_SEL_GPLL << |
| 547 | ACLK_PERILP0_PLL_SEL_SHIFT | |
| 548 | aclk_div << ACLK_PERILP0_DIV_CON_SHIFT)); |
| 549 | |
| 550 | /* perilp1 hclk select gpll as source */ |
| 551 | hclk_div = GPLL_HZ / PERILP1_HCLK_HZ - 1; |
| 552 | assert((hclk_div + 1) * PERILP1_HCLK_HZ == |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 553 | GPLL_HZ && (hclk_div <= 0x1f)); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 554 | |
Julius Werner | f7d519c | 2016-09-02 23:48:10 -0700 | [diff] [blame] | 555 | pclk_div = PERILP1_HCLK_HZ / PERILP1_PCLK_HZ - 1; |
| 556 | assert((pclk_div + 1) * PERILP1_PCLK_HZ == |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 557 | PERILP1_HCLK_HZ && (pclk_div <= 0x7)); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 558 | |
| 559 | write32(&cru_ptr->clksel_con[25], |
| 560 | RK_CLRSETBITS(PCLK_PERILP1_DIV_CON_MASK << |
| 561 | PCLK_PERILP1_DIV_CON_SHIFT | |
| 562 | HCLK_PERILP1_DIV_CON_MASK << |
| 563 | HCLK_PERILP1_DIV_CON_SHIFT | |
| 564 | HCLK_PERILP1_PLL_SEL_MASK << |
| 565 | HCLK_PERILP1_PLL_SEL_SHIFT, |
| 566 | pclk_div << PCLK_PERILP1_DIV_CON_SHIFT | |
| 567 | hclk_div << HCLK_PERILP1_DIV_CON_SHIFT | |
| 568 | HCLK_PERILP1_PLL_SEL_GPLL << |
| 569 | HCLK_PERILP1_PLL_SEL_SHIFT)); |
| 570 | } |
| 571 | |
Julius Werner | 7f96589 | 2016-08-29 15:07:58 -0700 | [diff] [blame] | 572 | void rkclk_configure_cpu(enum apll_frequencies freq, enum cpu_cluster cluster) |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 573 | { |
Julius Werner | 7f96589 | 2016-08-29 15:07:58 -0700 | [diff] [blame] | 574 | u32 aclkm_div, atclk_div, pclk_dbg_div, apll_hz; |
| 575 | int con_base, parent; |
| 576 | u32 *pll_con; |
Lin Huang | e3d78b8 | 2016-06-28 11:10:54 +0800 | [diff] [blame] | 577 | |
Julius Werner | 7f96589 | 2016-08-29 15:07:58 -0700 | [diff] [blame] | 578 | switch (cluster) { |
| 579 | case CPU_CLUSTER_LITTLE: |
| 580 | con_base = 0; |
| 581 | parent = CLK_CORE_PLL_SEL_ALPLL; |
| 582 | pll_con = &cru_ptr->apll_l_con[0]; |
| 583 | break; |
| 584 | case CPU_CLUSTER_BIG: |
| 585 | default: |
| 586 | con_base = 2; |
| 587 | parent = CLK_CORE_PLL_SEL_ABPLL; |
| 588 | pll_con = &cru_ptr->apll_b_con[0]; |
| 589 | break; |
| 590 | } |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 591 | |
Julius Werner | 7f96589 | 2016-08-29 15:07:58 -0700 | [diff] [blame] | 592 | apll_hz = apll_cfgs[freq]->freq; |
| 593 | rkclk_set_pll(pll_con, apll_cfgs[freq]); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 594 | |
Elyes HAOUAS | 6df3b64 | 2018-11-26 22:53:49 +0100 | [diff] [blame] | 595 | aclkm_div = DIV_ROUND_UP(apll_hz, ACLKM_CORE_HZ) - 1; |
| 596 | pclk_dbg_div = DIV_ROUND_UP(apll_hz, PCLK_DBG_HZ) - 1; |
| 597 | atclk_div = DIV_ROUND_UP(apll_hz, ATCLK_CORE_HZ) - 1; |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 598 | |
Lin Huang | bdd06de | 2016-06-28 15:21:20 +0800 | [diff] [blame] | 599 | write32(&cru_ptr->clksel_con[con_base], |
| 600 | RK_CLRSETBITS(ACLKM_CORE_DIV_CON_MASK << |
| 601 | ACLKM_CORE_DIV_CON_SHIFT | |
| 602 | CLK_CORE_PLL_SEL_MASK << CLK_CORE_PLL_SEL_SHIFT | |
| 603 | CLK_CORE_DIV_MASK << CLK_CORE_DIV_SHIFT, |
| 604 | aclkm_div << ACLKM_CORE_DIV_CON_SHIFT | |
| 605 | parent << CLK_CORE_PLL_SEL_SHIFT | |
| 606 | 0 << CLK_CORE_DIV_SHIFT)); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 607 | |
Lin Huang | bdd06de | 2016-06-28 15:21:20 +0800 | [diff] [blame] | 608 | write32(&cru_ptr->clksel_con[con_base + 1], |
| 609 | RK_CLRSETBITS(PCLK_DBG_DIV_MASK << PCLK_DBG_DIV_SHIFT | |
| 610 | ATCLK_CORE_DIV_MASK << ATCLK_CORE_DIV_SHIFT, |
| 611 | pclk_dbg_div << PCLK_DBG_DIV_SHIFT | |
| 612 | atclk_div << ATCLK_CORE_DIV_SHIFT)); |
Lin Huang | a1f82a3 | 2016-03-09 18:08:20 +0800 | [diff] [blame] | 613 | } |
Lin Huang | f5702e7 | 2016-03-19 22:45:19 +0800 | [diff] [blame] | 614 | |
Shunqian Zheng | ce60d5a | 2016-04-21 23:53:08 +0800 | [diff] [blame] | 615 | void rkclk_configure_ddr(unsigned int hz) |
| 616 | { |
| 617 | struct pll_div dpll_cfg; |
| 618 | |
| 619 | /* IC ECO bug, need to set this register */ |
| 620 | write32(&rk3399_pmusgrf->ddr_rgn_con[16], 0xc000c000); |
| 621 | |
| 622 | /* clk_ddrc == DPLL = 24MHz / refdiv * fbdiv / postdiv1 / postdiv2 */ |
| 623 | switch (hz) { |
| 624 | case 200*MHz: |
| 625 | dpll_cfg = (struct pll_div) |
Caesar Wang | a0199d8 | 2017-06-22 16:14:58 +0800 | [diff] [blame] | 626 | {.refdiv = 1, .fbdiv = 50, .postdiv1 = 3, .postdiv2 = 2}; |
Shunqian Zheng | ce60d5a | 2016-04-21 23:53:08 +0800 | [diff] [blame] | 627 | break; |
| 628 | case 300*MHz: |
| 629 | dpll_cfg = (struct pll_div) |
| 630 | {.refdiv = 2, .fbdiv = 100, .postdiv1 = 4, .postdiv2 = 1}; |
| 631 | break; |
| 632 | case 666*MHz: |
| 633 | dpll_cfg = (struct pll_div) |
| 634 | {.refdiv = 2, .fbdiv = 111, .postdiv1 = 2, .postdiv2 = 1}; |
| 635 | break; |
| 636 | case 800*MHz: |
| 637 | dpll_cfg = (struct pll_div) |
| 638 | {.refdiv = 1, .fbdiv = 100, .postdiv1 = 3, .postdiv2 = 1}; |
| 639 | break; |
Lin Huang | ba2b63a | 2016-07-25 10:06:09 +0800 | [diff] [blame] | 640 | case 933*MHz: |
Shunqian Zheng | 0d9839b | 2016-05-11 15:18:17 +0800 | [diff] [blame] | 641 | dpll_cfg = (struct pll_div) |
Derek Basehore | 8e1a995 | 2016-10-27 13:51:49 -0700 | [diff] [blame] | 642 | {.refdiv = 1, .fbdiv = 116, .postdiv1 = 3, .postdiv2 = 1}; |
Shunqian Zheng | 0d9839b | 2016-05-11 15:18:17 +0800 | [diff] [blame] | 643 | break; |
Shunqian Zheng | ce60d5a | 2016-04-21 23:53:08 +0800 | [diff] [blame] | 644 | default: |
| 645 | die("Unsupported SDRAM frequency, add to clock.c!"); |
| 646 | } |
| 647 | rkclk_set_pll(&cru_ptr->dpll_con[0], &dpll_cfg); |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 648 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 649 | if (CONFIG(RK3399_SPREAD_SPECTRUM_DDR)) |
Caesar Wang | e085a8a | 2017-05-04 09:24:23 +0800 | [diff] [blame] | 650 | rkclk_set_dpllssc(&dpll_cfg); |
Shunqian Zheng | ce60d5a | 2016-04-21 23:53:08 +0800 | [diff] [blame] | 651 | } |
| 652 | |
Moritz Fischer | f6e3254 | 2021-02-18 14:34:41 -0800 | [diff] [blame] | 653 | #define CRU_SFTRST_DDR_CTRL(ch, n) ((1 << 16 | (n)) << (8 + (ch) * 4)) |
| 654 | #define CRU_SFTRST_DDR_PHY(ch, n) ((1 << 16 | (n)) << (9 + (ch) * 4)) |
| 655 | |
| 656 | void rkclk_ddr_reset(u32 channel, u32 ctl, u32 phy) |
| 657 | { |
| 658 | write32(&cru_ptr->softrst_con[4], |
| 659 | CRU_SFTRST_DDR_CTRL(channel, ctl) | |
| 660 | CRU_SFTRST_DDR_PHY(channel, phy)); |
| 661 | } |
| 662 | |
Shunqian Zheng | 347c83c | 2016-04-13 22:34:39 +0800 | [diff] [blame] | 663 | #define SPI_CLK_REG_VALUE(bus, clk_div) \ |
| 664 | RK_CLRSETBITS(CLK_SPI_PLL_SEL_MASK << \ |
| 665 | CLK_SPI ##bus## _PLL_SEL_SHIFT | \ |
| 666 | CLK_SPI_PLL_DIV_CON_MASK << \ |
| 667 | CLK_SPI ##bus## _PLL_DIV_CON_SHIFT, \ |
| 668 | CLK_SPI_PLL_SEL_GPLL << \ |
| 669 | CLK_SPI ##bus## _PLL_SEL_SHIFT | \ |
| 670 | (clk_div - 1) << \ |
| 671 | CLK_SPI ##bus## _PLL_DIV_CON_SHIFT) |
| 672 | |
huang lin | c14b54d | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 673 | void rkclk_configure_spi(unsigned int bus, unsigned int hz) |
| 674 | { |
Shunqian Zheng | 347c83c | 2016-04-13 22:34:39 +0800 | [diff] [blame] | 675 | int src_clk_div; |
| 676 | int pll; |
| 677 | |
| 678 | /* spi3 src clock from ppll, while spi0,1,2,4,5 src clock from gpll */ |
| 679 | pll = (bus == 3) ? PPLL_HZ : GPLL_HZ; |
| 680 | src_clk_div = pll / hz; |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 681 | assert((src_clk_div - 1 <= 127) && (src_clk_div * hz == pll)); |
Shunqian Zheng | 347c83c | 2016-04-13 22:34:39 +0800 | [diff] [blame] | 682 | |
| 683 | switch (bus) { |
| 684 | case 0: |
| 685 | write32(&cru_ptr->clksel_con[59], |
| 686 | SPI_CLK_REG_VALUE(0, src_clk_div)); |
| 687 | break; |
| 688 | case 1: |
| 689 | write32(&cru_ptr->clksel_con[59], |
| 690 | SPI_CLK_REG_VALUE(1, src_clk_div)); |
| 691 | break; |
| 692 | case 2: |
| 693 | write32(&cru_ptr->clksel_con[60], |
| 694 | SPI_CLK_REG_VALUE(2, src_clk_div)); |
| 695 | break; |
| 696 | case 3: |
| 697 | write32(&pmucru_ptr->pmucru_clksel[1], |
| 698 | RK_CLRSETBITS(SPI3_PLL_SEL_MASK << SPI3_PLL_SEL_SHIFT | |
| 699 | SPI3_DIV_CON_MASK << SPI3_DIV_CON_SHIFT, |
| 700 | SPI3_PLL_SEL_PPLL << SPI3_PLL_SEL_SHIFT | |
| 701 | (src_clk_div - 1) << SPI3_DIV_CON_SHIFT)); |
| 702 | break; |
| 703 | case 4: |
| 704 | write32(&cru_ptr->clksel_con[60], |
| 705 | SPI_CLK_REG_VALUE(4, src_clk_div)); |
| 706 | break; |
| 707 | case 5: |
| 708 | write32(&cru_ptr->clksel_con[58], |
| 709 | SPI_CLK_REG_VALUE(5, src_clk_div)); |
| 710 | break; |
| 711 | default: |
| 712 | printk(BIOS_ERR, "do not support this spi bus\n"); |
| 713 | } |
huang lin | c14b54d | 2016-03-02 18:38:40 +0800 | [diff] [blame] | 714 | } |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 715 | |
| 716 | #define I2C_CLK_REG_VALUE(bus, clk_div) \ |
| 717 | RK_CLRSETBITS(I2C_DIV_CON_MASK << \ |
| 718 | CLK_I2C ##bus## _DIV_CON_SHIFT | \ |
| 719 | CLK_I2C_PLL_SEL_MASK << \ |
| 720 | CLK_I2C ##bus## _PLL_SEL_SHIFT, \ |
| 721 | (clk_div - 1) << \ |
| 722 | CLK_I2C ##bus## _DIV_CON_SHIFT | \ |
| 723 | CLK_I2C_PLL_SEL_GPLL << \ |
| 724 | CLK_I2C ##bus## _PLL_SEL_SHIFT) |
| 725 | #define PMU_I2C_CLK_REG_VALUE(bus, clk_div) \ |
| 726 | RK_CLRSETBITS(I2C_DIV_CON_MASK << I2C ##bus## _DIV_CON_SHIFT, \ |
| 727 | (clk_div - 1) << I2C ##bus## _DIV_CON_SHIFT) |
| 728 | |
Julius Werner | 8e42bd1c | 2016-11-01 15:24:54 -0700 | [diff] [blame] | 729 | uint32_t rkclk_i2c_clock_for_bus(unsigned int bus) |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 730 | { |
Julius Werner | 8e42bd1c | 2016-11-01 15:24:54 -0700 | [diff] [blame] | 731 | int src_clk_div, pll, freq; |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 732 | |
Julius Werner | 8e42bd1c | 2016-11-01 15:24:54 -0700 | [diff] [blame] | 733 | /* i2c0,4,8 src clock from ppll, i2c1,2,3,5,6,7 src clock from gpll */ |
| 734 | if (bus == 0 || bus == 4 || bus == 8) { |
| 735 | pll = PPLL_HZ; |
| 736 | freq = 338*MHz; |
| 737 | } else { |
| 738 | pll = GPLL_HZ; |
| 739 | freq = 198*MHz; |
| 740 | } |
| 741 | src_clk_div = pll / freq; |
| 742 | assert((src_clk_div - 1 <= 127) && (src_clk_div * freq == pll)); |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 743 | |
| 744 | switch (bus) { |
| 745 | case 0: |
| 746 | write32(&pmucru_ptr->pmucru_clksel[2], |
| 747 | PMU_I2C_CLK_REG_VALUE(0, src_clk_div)); |
| 748 | break; |
| 749 | case 1: |
| 750 | write32(&cru_ptr->clksel_con[61], |
| 751 | I2C_CLK_REG_VALUE(1, src_clk_div)); |
| 752 | break; |
| 753 | case 2: |
| 754 | write32(&cru_ptr->clksel_con[62], |
| 755 | I2C_CLK_REG_VALUE(2, src_clk_div)); |
| 756 | break; |
| 757 | case 3: |
| 758 | write32(&cru_ptr->clksel_con[63], |
| 759 | I2C_CLK_REG_VALUE(3, src_clk_div)); |
| 760 | break; |
| 761 | case 4: |
| 762 | write32(&pmucru_ptr->pmucru_clksel[3], |
| 763 | PMU_I2C_CLK_REG_VALUE(4, src_clk_div)); |
| 764 | break; |
| 765 | case 5: |
| 766 | write32(&cru_ptr->clksel_con[61], |
| 767 | I2C_CLK_REG_VALUE(5, src_clk_div)); |
| 768 | break; |
| 769 | case 6: |
| 770 | write32(&cru_ptr->clksel_con[62], |
| 771 | I2C_CLK_REG_VALUE(6, src_clk_div)); |
| 772 | break; |
| 773 | case 7: |
| 774 | write32(&cru_ptr->clksel_con[63], |
| 775 | I2C_CLK_REG_VALUE(7, src_clk_div)); |
| 776 | break; |
| 777 | case 8: |
| 778 | write32(&pmucru_ptr->pmucru_clksel[2], |
| 779 | PMU_I2C_CLK_REG_VALUE(8, src_clk_div)); |
| 780 | break; |
| 781 | default: |
Julius Werner | 8e42bd1c | 2016-11-01 15:24:54 -0700 | [diff] [blame] | 782 | die("unknown i2c bus\n"); |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 783 | } |
huang lin | 4f17374 | 2016-03-02 18:46:24 +0800 | [diff] [blame] | 784 | |
| 785 | return freq; |
| 786 | } |
Lin Huang | bf48fbb | 2016-03-23 19:24:53 +0800 | [diff] [blame] | 787 | |
Xing Zheng | 96fbc31 | 2016-05-19 11:39:20 +0800 | [diff] [blame] | 788 | static u32 clk_gcd(u32 a, u32 b) |
| 789 | { |
| 790 | while (b != 0) { |
| 791 | int r = b; |
| 792 | b = a % b; |
| 793 | a = r; |
| 794 | } |
| 795 | return a; |
| 796 | } |
| 797 | |
| 798 | void rkclk_configure_i2s(unsigned int hz) |
| 799 | { |
| 800 | int n, d; |
| 801 | int v; |
| 802 | |
| 803 | /** |
Elyes HAOUAS | 809aeee | 2018-08-07 12:14:33 +0200 | [diff] [blame] | 804 | * clk_i2s0_sel: divider output from fraction |
Xing Zheng | 96fbc31 | 2016-05-19 11:39:20 +0800 | [diff] [blame] | 805 | * clk_i2s0_pll_sel source clock: cpll |
| 806 | * clk_i2s0_div_con: 1 (div+1) |
| 807 | */ |
| 808 | write32(&cru_ptr->clksel_con[28], |
| 809 | RK_CLRSETBITS(3 << 8 | 1 << 7 | 0x7f << 0, |
| 810 | 1 << 8 | 0 << 7 | 0 << 0)); |
| 811 | |
| 812 | /* make sure and enable i2s0 path gates */ |
| 813 | write32(&cru_ptr->clkgate_con[8], |
| 814 | RK_CLRBITS(1 << 12 | 1 << 5 | 1 << 4 | 1 << 3)); |
| 815 | |
| 816 | /* set frac divider */ |
| 817 | v = clk_gcd(CPLL_HZ, hz); |
| 818 | n = (CPLL_HZ / v) & (0xffff); |
| 819 | d = (hz / v) & (0xffff); |
Julius Werner | 8e42bd1c | 2016-11-01 15:24:54 -0700 | [diff] [blame] | 820 | assert(hz == (u64)CPLL_HZ * d / n); |
Xing Zheng | 96fbc31 | 2016-05-19 11:39:20 +0800 | [diff] [blame] | 821 | write32(&cru_ptr->clksel_con[96], d << 16 | n); |
| 822 | |
| 823 | /** |
| 824 | * clk_i2sout_sel clk_i2s |
| 825 | * clk_i2s_ch_sel: clk_i2s0 |
| 826 | */ |
| 827 | write32(&cru_ptr->clksel_con[31], |
| 828 | RK_CLRSETBITS(1 << 2 | 3 << 0, |
| 829 | 0 << 2 | 0 << 0)); |
| 830 | } |
| 831 | |
Lin Huang | bf48fbb | 2016-03-23 19:24:53 +0800 | [diff] [blame] | 832 | void rkclk_configure_saradc(unsigned int hz) |
| 833 | { |
| 834 | int src_clk_div; |
| 835 | |
| 836 | /* saradc src clk from 24MHz */ |
| 837 | src_clk_div = 24 * MHz / hz; |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 838 | assert((src_clk_div - 1 <= 255) && (src_clk_div * hz == 24 * MHz)); |
Lin Huang | bf48fbb | 2016-03-23 19:24:53 +0800 | [diff] [blame] | 839 | |
| 840 | write32(&cru_ptr->clksel_con[26], |
| 841 | RK_CLRSETBITS(CLK_SARADC_DIV_CON_MASK << |
| 842 | CLK_SARADC_DIV_CON_SHIFT, |
| 843 | (src_clk_div - 1) << CLK_SARADC_DIV_CON_SHIFT)); |
| 844 | } |
Shunqian Zheng | c7f32a5 | 2016-05-04 15:54:37 +0800 | [diff] [blame] | 845 | |
| 846 | void rkclk_configure_vop_aclk(u32 vop_id, u32 aclk_hz) |
| 847 | { |
| 848 | u32 div; |
| 849 | void *reg_addr = vop_id ? &cru_ptr->clksel_con[48] : |
| 850 | &cru_ptr->clksel_con[47]; |
| 851 | |
| 852 | /* vop aclk source clk: cpll */ |
| 853 | div = CPLL_HZ / aclk_hz; |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 854 | assert((div - 1 <= 31) && (div * aclk_hz == CPLL_HZ)); |
Shunqian Zheng | c7f32a5 | 2016-05-04 15:54:37 +0800 | [diff] [blame] | 855 | |
| 856 | write32(reg_addr, RK_CLRSETBITS( |
| 857 | ACLK_VOP_PLL_SEL_MASK << ACLK_VOP_PLL_SEL_SHIFT | |
| 858 | ACLK_VOP_DIV_CON_MASK << ACLK_VOP_DIV_CON_SHIFT, |
| 859 | ACLK_VOP_PLL_SEL_CPLL << ACLK_VOP_PLL_SEL_SHIFT | |
| 860 | (div - 1) << ACLK_VOP_DIV_CON_SHIFT)); |
| 861 | } |
| 862 | |
| 863 | int rkclk_configure_vop_dclk(u32 vop_id, u32 dclk_hz) |
| 864 | { |
| 865 | struct pll_div vpll_config = {0}; |
| 866 | void *reg_addr = vop_id ? &cru_ptr->clksel_con[50] : |
| 867 | &cru_ptr->clksel_con[49]; |
| 868 | |
| 869 | /* vop dclk source from vpll, and equals to vpll(means div == 1) */ |
| 870 | if (pll_para_config(dclk_hz, &vpll_config)) |
| 871 | return -1; |
| 872 | |
| 873 | rkclk_set_pll(&cru_ptr->vpll_con[0], &vpll_config); |
| 874 | |
| 875 | write32(reg_addr, RK_CLRSETBITS( |
| 876 | DCLK_VOP_DCLK_SEL_MASK << DCLK_VOP_DCLK_SEL_SHIFT | |
| 877 | DCLK_VOP_PLL_SEL_MASK << DCLK_VOP_PLL_SEL_SHIFT | |
| 878 | DCLK_VOP_DIV_CON_MASK << DCLK_VOP_DIV_CON_SHIFT, |
| 879 | DCLK_VOP_DCLK_SEL_DIVOUT << DCLK_VOP_DCLK_SEL_SHIFT | |
| 880 | DCLK_VOP_PLL_SEL_VPLL << DCLK_VOP_PLL_SEL_SHIFT | |
| 881 | (1 - 1) << DCLK_VOP_DIV_CON_SHIFT)); |
| 882 | |
| 883 | return 0; |
| 884 | } |
Shunqian Zheng | f4181ce | 2016-05-06 16:50:48 +0800 | [diff] [blame] | 885 | |
| 886 | void rkclk_configure_tsadc(unsigned int hz) |
| 887 | { |
| 888 | int src_clk_div; |
| 889 | |
| 890 | /* use 24M as src clock */ |
| 891 | src_clk_div = OSC_HZ / hz; |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 892 | assert((src_clk_div - 1 <= 1023) && (src_clk_div * hz == OSC_HZ)); |
Shunqian Zheng | f4181ce | 2016-05-06 16:50:48 +0800 | [diff] [blame] | 893 | |
| 894 | write32(&cru_ptr->clksel_con[27], RK_CLRSETBITS( |
| 895 | CLK_TSADC_DIV_CON_MASK << CLK_TSADC_DIV_CON_SHIFT | |
| 896 | CLK_TSADC_SEL_MASK << CLK_TSADC_SEL_SHIFT, |
| 897 | src_clk_div << CLK_TSADC_DIV_CON_SHIFT | |
| 898 | CLK_TSADC_SEL_X24M << CLK_TSADC_SEL_SHIFT)); |
| 899 | } |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 900 | |
| 901 | void rkclk_configure_emmc(void) |
| 902 | { |
| 903 | int src_clk_div; |
Ziyuan Xu | c53cf64 | 2016-09-18 10:49:52 +0800 | [diff] [blame] | 904 | int aclk_emmc = 148500*KHz; |
| 905 | int clk_emmc = 148500*KHz; |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 906 | |
| 907 | /* Select aclk_emmc source from GPLL */ |
| 908 | src_clk_div = GPLL_HZ / aclk_emmc; |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 909 | assert((src_clk_div - 1 <= 31) && (src_clk_div * aclk_emmc == GPLL_HZ)); |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 910 | |
| 911 | write32(&cru_ptr->clksel_con[21], |
| 912 | RK_CLRSETBITS(ACLK_EMMC_PLL_SEL_MASK << |
| 913 | ACLK_EMMC_PLL_SEL_SHIFT | |
| 914 | ACLK_EMMC_DIV_CON_MASK << ACLK_EMMC_DIV_CON_SHIFT, |
| 915 | ACLK_EMMC_PLL_SEL_GPLL << |
| 916 | ACLK_EMMC_PLL_SEL_SHIFT | |
| 917 | (src_clk_div - 1) << ACLK_EMMC_DIV_CON_SHIFT)); |
| 918 | |
| 919 | /* Select clk_emmc source from GPLL too */ |
| 920 | src_clk_div = GPLL_HZ / clk_emmc; |
Julius Werner | b37c8c0 | 2016-09-06 14:09:16 -0700 | [diff] [blame] | 921 | assert((src_clk_div - 1 <= 127) && (src_clk_div * clk_emmc == GPLL_HZ)); |
Lin Huang | 2f7ed8d | 2016-04-08 18:56:20 +0800 | [diff] [blame] | 922 | |
| 923 | write32(&cru_ptr->clksel_con[22], |
| 924 | RK_CLRSETBITS(CLK_EMMC_PLL_MASK << CLK_EMMC_PLL_SHIFT | |
| 925 | CLK_EMMC_DIV_CON_MASK << CLK_EMMC_DIV_CON_SHIFT, |
| 926 | CLK_EMMC_PLL_SEL_GPLL << CLK_EMMC_PLL_SHIFT | |
| 927 | (src_clk_div - 1) << CLK_EMMC_DIV_CON_SHIFT)); |
| 928 | } |
Julius Werner | b6bf1dd | 2016-08-24 19:38:05 -0700 | [diff] [blame] | 929 | |
| 930 | int rkclk_was_watchdog_reset(void) |
| 931 | { |
| 932 | /* Bits 5 and 4 are "second" and "first" global watchdog reset. */ |
| 933 | return read32(&cru_ptr->glb_rst_st) & 0x30; |
| 934 | } |
Lin Huang | 4ecccff | 2017-01-18 09:44:34 +0800 | [diff] [blame] | 935 | |
| 936 | void rkclk_configure_edp(unsigned int hz) |
| 937 | { |
| 938 | int src_clk_div; |
| 939 | |
| 940 | src_clk_div = CPLL_HZ / hz; |
| 941 | assert((src_clk_div - 1 <= 63) && (src_clk_div * hz == CPLL_HZ)); |
| 942 | |
| 943 | write32(&cru_ptr->clksel_con[44], |
| 944 | RK_CLRSETBITS(CLK_PCLK_EDP_PLL_SEL_MASK << |
| 945 | CLK_PCLK_EDP_PLL_SEL_SHIFT | |
| 946 | CLK_PCLK_EDP_DIV_CON_MASK << |
| 947 | CLK_PCLK_EDP_DIV_CON_SHIFT, |
| 948 | CLK_PCLK_EDP_PLL_SEL_CPLL << |
| 949 | CLK_PCLK_EDP_PLL_SEL_SHIFT | |
| 950 | (src_clk_div - 1) << |
| 951 | CLK_PCLK_EDP_DIV_CON_SHIFT)); |
| 952 | } |
Nickey Yang | fe122d4 | 2017-04-27 09:38:06 +0800 | [diff] [blame] | 953 | |
| 954 | void rkclk_configure_mipi(void) |
| 955 | { |
| 956 | /* Enable clk_mipidphy_ref and clk_mipidphy_cfg */ |
| 957 | write32(&cru_ptr->clkgate_con[11], |
| 958 | RK_CLRBITS(1 << 14 | 1 << 15)); |
| 959 | /* Enable pclk_mipi_dsi0 */ |
| 960 | write32(&cru_ptr->clkgate_con[29], |
| 961 | RK_CLRBITS(1 << 1)); |
| 962 | } |