jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Rockchip Inc. |
| 5 | * |
| 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. |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 18 | */ |
| 19 | |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 20 | #include <arch/io.h> |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 21 | #include <assert.h> |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 22 | #include <console/console.h> |
| 23 | #include <delay.h> |
Julius Werner | 7a8a4ab | 2015-05-22 16:26:40 -0700 | [diff] [blame] | 24 | #include <lib.h> |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 25 | #include <soc/addressmap.h> |
| 26 | #include <soc/clock.h> |
| 27 | #include <soc/grf.h> |
| 28 | #include <soc/soc.h> |
| 29 | #include <stdint.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 32 | |
| 33 | struct pll_div { |
| 34 | u32 nr; |
| 35 | u32 nf; |
| 36 | u32 no; |
| 37 | }; |
| 38 | |
| 39 | struct rk3288_cru_reg { |
| 40 | u32 cru_apll_con[4]; |
| 41 | u32 cru_dpll_con[4]; |
| 42 | u32 cru_cpll_con[4]; |
| 43 | u32 cru_gpll_con[4]; |
| 44 | u32 cru_npll_con[4]; |
| 45 | u32 cru_mode_con; |
| 46 | u32 reserved0[3]; |
| 47 | u32 cru_clksel_con[43]; |
| 48 | u32 reserved1[21]; |
| 49 | u32 cru_clkgate_con[19]; |
| 50 | u32 reserved2; |
| 51 | u32 cru_glb_srst_fst_value; |
| 52 | u32 cru_glb_srst_snd_value; |
| 53 | u32 cru_softrst_con[12]; |
| 54 | u32 cru_misc_con; |
| 55 | u32 cru_glb_cnt_th; |
| 56 | u32 cru_glb_rst_con; |
| 57 | u32 reserved3; |
| 58 | u32 cru_glb_rst_st; |
| 59 | u32 reserved4; |
| 60 | u32 cru_sdmmc_con[2]; |
| 61 | u32 cru_sdio0_con[2]; |
| 62 | u32 cru_sdio1_con[2]; |
| 63 | u32 cru_emmc_con[2]; |
| 64 | }; |
| 65 | check_member(rk3288_cru_reg, cru_emmc_con[1], 0x021c); |
| 66 | |
| 67 | static struct rk3288_cru_reg * const cru_ptr = (void *)CRU_BASE; |
| 68 | |
huang lin | 630c86d | 2014-08-26 17:28:46 +0800 | [diff] [blame] | 69 | #define PLL_DIVISORS(hz, _nr, _no) {\ |
Julius Werner | f8dcdea | 2014-10-06 15:02:12 -0700 | [diff] [blame] | 70 | .nr = _nr, .nf = (u32)((u64)hz * _nr * _no / OSC_HZ), .no = _no};\ |
| 71 | _Static_assert(((u64)hz * _nr * _no / OSC_HZ) * OSC_HZ /\ |
| 72 | (_nr * _no) == hz, #hz "Hz cannot be hit with PLL "\ |
| 73 | "divisors on line " STRINGIFY(__LINE__)); |
huang lin | 630c86d | 2014-08-26 17:28:46 +0800 | [diff] [blame] | 74 | |
Julius Werner | f8dcdea | 2014-10-06 15:02:12 -0700 | [diff] [blame] | 75 | /* Keep divisors as low as possible to reduce jitter and power usage. */ |
Julius Werner | f8dcdea | 2014-10-06 15:02:12 -0700 | [diff] [blame] | 76 | static const struct pll_div gpll_init_cfg = PLL_DIVISORS(GPLL_HZ, 2, 2); |
| 77 | static const struct pll_div cpll_init_cfg = PLL_DIVISORS(CPLL_HZ, 1, 2); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 78 | |
David Hendricks | 4bd65e1 | 2015-09-02 18:10:14 -0700 | [diff] [blame] | 79 | /* See linux/drivers/clk/rockchip/clk-rk3288.c for more APLL combinations */ |
| 80 | static const struct pll_div apll_1800_cfg = PLL_DIVISORS(1800*MHz, 1, 1); |
| 81 | static const struct pll_div apll_1392_cfg = PLL_DIVISORS(1392*MHz, 1, 1); |
| 82 | static const struct pll_div *apll_cfgs[] = { |
| 83 | [APLL_1800_MHZ] = &apll_1800_cfg, |
| 84 | [APLL_1392_MHZ] = &apll_1392_cfg, |
| 85 | }; |
| 86 | |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 87 | /*******************PLL CON0 BITS***************************/ |
| 88 | #define PLL_OD_MSK (0x0F) |
| 89 | |
| 90 | #define PLL_NR_MSK (0x3F << 8) |
| 91 | #define PLL_NR_SHIFT (8) |
| 92 | |
| 93 | /*******************PLL CON1 BITS***************************/ |
| 94 | #define PLL_NF_MSK (0x1FFF) |
| 95 | |
| 96 | /*******************PLL CON2 BITS***************************/ |
| 97 | #define PLL_BWADJ_MSK (0x0FFF) |
| 98 | |
| 99 | /*******************PLL CON3 BITS***************************/ |
| 100 | #define PLL_RESET_MSK (1 << 5) |
| 101 | #define PLL_RESET (1 << 5) |
| 102 | #define PLL_RESET_RESUME (0 << 5) |
| 103 | |
| 104 | /*******************CLKSEL0 BITS***************************/ |
| 105 | /* core clk pll sel: amr or general */ |
| 106 | #define CORE_SEL_PLL_MSK (1 << 15) |
| 107 | #define CORE_SEL_APLL (0 << 15) |
| 108 | #define CORE_SEL_GPLL (1 << 15) |
| 109 | |
| 110 | /* a12 core clock div: clk_core = clk_src / (div_con + 1) */ |
| 111 | #define A12_DIV_SHIFT (8) |
| 112 | #define A12_DIV_MSK (0x1F << 8) |
| 113 | |
| 114 | /* mp core axi clock div: clk = clk_src / (div_con + 1) */ |
| 115 | #define MP_DIV_SHIFT (4) |
| 116 | #define MP_DIV_MSK (0xF << 4) |
| 117 | |
| 118 | /* m0 core axi clock div: clk = clk_src / (div_con + 1) */ |
| 119 | #define M0_DIV_MSK (0xF) |
| 120 | |
huang lin | bfdd732 | 2014-09-25 16:33:38 +0800 | [diff] [blame] | 121 | /*******************CLKSEL1 BITS***************************/ |
| 122 | /* pd bus clk pll sel: codec or general */ |
| 123 | #define PD_BUS_SEL_PLL_MSK (1 << 15) |
| 124 | #define PD_BUS_SEL_CPLL (0 << 15) |
| 125 | #define PD_BUS_SEL_GPLL (1 << 15) |
| 126 | |
| 127 | /* pd bus pclk div: |
| 128 | * pclk = pd_bus_aclk /(div + 1) |
| 129 | */ |
| 130 | #define PD_BUS_PCLK_DIV_SHIFT (12) |
| 131 | #define PD_BUS_PCLK_DIV_MSK (0x7 << 12) |
| 132 | |
| 133 | /* pd bus hclk div: |
| 134 | * aclk_bus: hclk_bus = 1:1 or 2:1 or 4:1 |
| 135 | */ |
| 136 | #define PD_BUS_HCLK_DIV_SHIFT (8) |
| 137 | #define PD_BUS_HCLK_DIV_MSK (0x3 << 8) |
| 138 | |
| 139 | /* pd bus aclk div: |
| 140 | * pd_bus_aclk = pd_bus_src_clk /(div0 * div1) |
| 141 | */ |
| 142 | #define PD_BUS_ACLK_DIV0_SHIFT (3) |
| 143 | #define PD_BUS_ACLK_DIV0_MASK (0x1f << 3) |
| 144 | #define PD_BUS_ACLK_DIV1_SHIFT (0) |
| 145 | #define PD_BUS_ACLK_DIV1_MASK (0x7 << 0) |
| 146 | |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 147 | /*******************CLKSEL10 BITS***************************/ |
| 148 | /* peripheral bus clk pll sel: codec or general */ |
| 149 | #define PERI_SEL_PLL_MSK (1 << 15) |
| 150 | #define PERI_SEL_CPLL (0 << 15) |
| 151 | #define PERI_SEL_GPLL (1 << 15) |
| 152 | |
| 153 | /* peripheral bus pclk div: |
| 154 | * aclk_bus: pclk_bus = 1:1 or 2:1 or 4:1 or 8:1 |
| 155 | */ |
| 156 | #define PERI_PCLK_DIV_SHIFT (12) |
| 157 | #define PERI_PCLK_DIV_MSK (0x7 << 12) |
| 158 | |
| 159 | /* peripheral bus hclk div: |
| 160 | * aclk_bus: hclk_bus = 1:1 or 2:1 or 4:1 |
| 161 | */ |
| 162 | #define PERI_HCLK_DIV_SHIFT (8) |
| 163 | #define PERI_HCLK_DIV_MSK (0x3 << 8) |
| 164 | |
| 165 | /* peripheral bus aclk div: |
| 166 | * aclk_periph = |
| 167 | * periph_clk_src / (peri_aclk_div_con + 1) |
| 168 | */ |
huang lin | bbcffd9 | 2014-09-27 12:02:27 +0800 | [diff] [blame] | 169 | #define PERI_ACLK_DIV_SHIFT (0x0) |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 170 | #define PERI_ACLK_DIV_MSK (0x1F) |
| 171 | |
| 172 | /*******************CLKSEL37 BITS***************************/ |
| 173 | #define L2_DIV_MSK (0x7) |
| 174 | |
| 175 | #define ATCLK_DIV_MSK (0x1F << 4) |
| 176 | #define ATCLK_DIV_SHIFT (4) |
| 177 | |
| 178 | #define PCLK_DBG_DIV_MSK (0x1F << 9) |
| 179 | #define PCLK_DBG_DIV_SHIFT (9) |
| 180 | |
| 181 | #define APLL_MODE_MSK (0x3) |
| 182 | #define APLL_MODE_SLOW (0) |
| 183 | #define APLL_MODE_NORM (1) |
| 184 | |
| 185 | #define DPLL_MODE_MSK (0x3 << 4) |
| 186 | #define DPLL_MODE_SLOW (0 << 4) |
| 187 | #define DPLL_MODE_NORM (1 << 4) |
| 188 | |
| 189 | #define CPLL_MODE_MSK (0x3 << 8) |
| 190 | #define CPLL_MODE_SLOW (0 << 8) |
| 191 | #define CPLL_MODE_NORM (1 << 8) |
| 192 | |
| 193 | #define GPLL_MODE_MSK (0x3 << 12) |
| 194 | #define GPLL_MODE_SLOW (0 << 12) |
| 195 | #define GPLL_MODE_NORM (1 << 12) |
| 196 | |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 197 | #define NPLL_MODE_MSK (0x3 << 14) |
| 198 | #define NPLL_MODE_SLOW (0 << 14) |
| 199 | #define NPLL_MODE_NORM (1 << 14) |
| 200 | |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 201 | #define SOCSTS_DPLL_LOCK (1 << 5) |
| 202 | #define SOCSTS_APLL_LOCK (1 << 6) |
| 203 | #define SOCSTS_CPLL_LOCK (1 << 7) |
| 204 | #define SOCSTS_GPLL_LOCK (1 << 8) |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 205 | #define SOCSTS_NPLL_LOCK (1 << 9) |
| 206 | |
| 207 | #define VCO_MAX_KHZ (2200 * (MHz/KHz)) |
| 208 | #define VCO_MIN_KHZ (440 * (MHz/KHz)) |
| 209 | #define OUTPUT_MAX_KHZ (2200 * (MHz/KHz)) |
| 210 | #define OUTPUT_MIN_KHZ 27500 |
| 211 | #define FREF_MAX_KHZ (2200 * (MHz/KHz)) |
| 212 | #define FREF_MIN_KHZ 269 |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 213 | |
Julius Werner | f8dcdea | 2014-10-06 15:02:12 -0700 | [diff] [blame] | 214 | static int rkclk_set_pll(u32 *pll_con, const struct pll_div *div) |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 215 | { |
Julius Werner | f8dcdea | 2014-10-06 15:02:12 -0700 | [diff] [blame] | 216 | /* All PLLs have same VCO and output frequency range restrictions. */ |
| 217 | u32 vco_khz = OSC_HZ/KHz * div->nf / div->nr; |
| 218 | u32 output_khz = vco_khz / div->no; |
| 219 | |
| 220 | printk(BIOS_DEBUG, "Configuring PLL at %p with NF = %d, NR = %d and " |
| 221 | "NO = %d (VCO = %uKHz, output = %uKHz)\n", |
| 222 | pll_con, div->nf, div->nr, div->no, vco_khz, output_khz); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 223 | assert(vco_khz >= VCO_MIN_KHZ && vco_khz <= VCO_MAX_KHZ && |
| 224 | output_khz >= OUTPUT_MIN_KHZ && output_khz <= OUTPUT_MAX_KHZ && |
Julius Werner | f8dcdea | 2014-10-06 15:02:12 -0700 | [diff] [blame] | 225 | (div->no == 1 || !(div->no % 2))); |
| 226 | |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 227 | /* enter rest */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 228 | write32(&pll_con[3], RK_SETBITS(PLL_RESET_MSK)); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 229 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 230 | write32(&pll_con[0], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 231 | RK_CLRSETBITS(PLL_NR_MSK, (div->nr - 1) << PLL_NR_SHIFT) | |
| 232 | RK_CLRSETBITS(PLL_OD_MSK, (div->no - 1))); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 233 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 234 | write32(&pll_con[1], RK_CLRSETBITS(PLL_NF_MSK, (div->nf - 1))); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 235 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 236 | write32(&pll_con[2], |
| 237 | RK_CLRSETBITS(PLL_BWADJ_MSK, ((div->nf >> 1) - 1))); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 238 | |
| 239 | udelay(10); |
| 240 | |
| 241 | /* return form rest */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 242 | write32(&pll_con[3], RK_CLRBITS(PLL_RESET_MSK)); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | void rkclk_init(void) |
| 248 | { |
huang lin | bfdd732 | 2014-09-25 16:33:38 +0800 | [diff] [blame] | 249 | u32 aclk_div; |
| 250 | u32 hclk_div; |
| 251 | u32 pclk_div; |
| 252 | |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 253 | /* pll enter slow-mode */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 254 | write32(&cru_ptr->cru_mode_con, |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 255 | RK_CLRSETBITS(GPLL_MODE_MSK, GPLL_MODE_SLOW) | |
| 256 | RK_CLRSETBITS(CPLL_MODE_MSK, CPLL_MODE_SLOW)); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 257 | |
| 258 | /* init pll */ |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 259 | rkclk_set_pll(&cru_ptr->cru_gpll_con[0], &gpll_init_cfg); |
| 260 | rkclk_set_pll(&cru_ptr->cru_cpll_con[0], &cpll_init_cfg); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 261 | |
| 262 | /* waiting for pll lock */ |
| 263 | while (1) { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 264 | if ((read32(&rk3288_grf->soc_status[1]) |
huang lin | 08884e3 | 2014-10-10 20:28:47 -0700 | [diff] [blame] | 265 | & (SOCSTS_CPLL_LOCK | SOCSTS_GPLL_LOCK)) |
| 266 | == (SOCSTS_CPLL_LOCK | SOCSTS_GPLL_LOCK)) |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 267 | break; |
| 268 | udelay(1); |
| 269 | } |
| 270 | |
| 271 | /* |
huang lin | bfdd732 | 2014-09-25 16:33:38 +0800 | [diff] [blame] | 272 | * pd_bus clock pll source selection and |
| 273 | * set up dependent divisors for PCLK/HCLK and ACLK clocks. |
| 274 | */ |
| 275 | aclk_div = GPLL_HZ / PD_BUS_ACLK_HZ - 1; |
| 276 | assert((aclk_div + 1) * PD_BUS_ACLK_HZ == GPLL_HZ && aclk_div < 0x1f); |
| 277 | hclk_div = PD_BUS_ACLK_HZ / PD_BUS_HCLK_HZ - 1; |
| 278 | assert((hclk_div + 1) * PD_BUS_HCLK_HZ == |
| 279 | PD_BUS_ACLK_HZ && (hclk_div < 0x4) && (hclk_div != 0x2)); |
| 280 | |
| 281 | pclk_div = PD_BUS_ACLK_HZ / PD_BUS_PCLK_HZ - 1; |
| 282 | assert((pclk_div + 1) * PD_BUS_PCLK_HZ == |
| 283 | PD_BUS_ACLK_HZ && pclk_div < 0x7); |
| 284 | |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 285 | write32(&cru_ptr->cru_clksel_con[1], RK_SETBITS(PD_BUS_SEL_GPLL) | |
| 286 | RK_CLRSETBITS(PD_BUS_PCLK_DIV_MSK, |
| 287 | pclk_div << PD_BUS_PCLK_DIV_SHIFT) | |
| 288 | RK_CLRSETBITS(PD_BUS_HCLK_DIV_MSK, |
| 289 | hclk_div << PD_BUS_HCLK_DIV_SHIFT) | |
| 290 | RK_CLRSETBITS(PD_BUS_ACLK_DIV0_MASK, |
| 291 | aclk_div << PD_BUS_ACLK_DIV0_SHIFT) | |
| 292 | RK_CLRSETBITS(PD_BUS_ACLK_DIV1_MASK, 0 << 0)); |
huang lin | bfdd732 | 2014-09-25 16:33:38 +0800 | [diff] [blame] | 293 | |
| 294 | /* |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 295 | * peri clock pll source selection and |
| 296 | * set up dependent divisors for PCLK/HCLK and ACLK clocks. |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 297 | */ |
huang lin | bfdd732 | 2014-09-25 16:33:38 +0800 | [diff] [blame] | 298 | aclk_div = GPLL_HZ / PERI_ACLK_HZ - 1; |
| 299 | assert((aclk_div + 1) * PERI_ACLK_HZ == GPLL_HZ && aclk_div < 0x1f); |
| 300 | |
| 301 | hclk_div = log2(PERI_ACLK_HZ / PERI_HCLK_HZ); |
| 302 | assert((1 << hclk_div) * PERI_HCLK_HZ == |
| 303 | PERI_ACLK_HZ && (hclk_div < 0x4)); |
| 304 | |
| 305 | pclk_div = log2(PERI_ACLK_HZ / PERI_PCLK_HZ); |
| 306 | assert((1 << pclk_div) * PERI_PCLK_HZ == |
| 307 | PERI_ACLK_HZ && (pclk_div < 0x4)); |
| 308 | |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 309 | write32(&cru_ptr->cru_clksel_con[10], RK_SETBITS(PERI_SEL_GPLL) | |
| 310 | RK_CLRSETBITS(PERI_PCLK_DIV_MSK, |
| 311 | pclk_div << PERI_PCLK_DIV_SHIFT) | |
| 312 | RK_CLRSETBITS(PERI_HCLK_DIV_MSK, |
| 313 | hclk_div << PERI_HCLK_DIV_SHIFT) | |
| 314 | RK_CLRSETBITS(PERI_ACLK_DIV_MSK, |
| 315 | aclk_div << PERI_ACLK_DIV_SHIFT)); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 316 | |
| 317 | /* PLL enter normal-mode */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 318 | write32(&cru_ptr->cru_mode_con, |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 319 | RK_CLRSETBITS(GPLL_MODE_MSK, GPLL_MODE_NORM) | |
| 320 | RK_CLRSETBITS(CPLL_MODE_MSK, CPLL_MODE_NORM)); |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 321 | |
| 322 | } |
| 323 | |
David Hendricks | 4bd65e1 | 2015-09-02 18:10:14 -0700 | [diff] [blame] | 324 | void rkclk_configure_cpu(enum apll_frequencies apll_freq) |
huang lin | 08884e3 | 2014-10-10 20:28:47 -0700 | [diff] [blame] | 325 | { |
| 326 | /* pll enter slow-mode */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 327 | write32(&cru_ptr->cru_mode_con, |
| 328 | RK_CLRSETBITS(APLL_MODE_MSK, APLL_MODE_SLOW)); |
huang lin | 08884e3 | 2014-10-10 20:28:47 -0700 | [diff] [blame] | 329 | |
David Hendricks | 4bd65e1 | 2015-09-02 18:10:14 -0700 | [diff] [blame] | 330 | rkclk_set_pll(&cru_ptr->cru_apll_con[0], apll_cfgs[apll_freq]); |
huang lin | 08884e3 | 2014-10-10 20:28:47 -0700 | [diff] [blame] | 331 | |
| 332 | /* waiting for pll lock */ |
| 333 | while (1) { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 334 | if (read32(&rk3288_grf->soc_status[1]) & SOCSTS_APLL_LOCK) |
huang lin | 08884e3 | 2014-10-10 20:28:47 -0700 | [diff] [blame] | 335 | break; |
| 336 | udelay(1); |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | * core clock pll source selection and |
| 341 | * set up dependent divisors for MPAXI/M0AXI and ARM clocks. |
| 342 | * core clock select apll, apll clk = 1800MHz |
| 343 | * arm clk = 1800MHz, mpclk = 450MHz, m0clk = 900MHz |
| 344 | */ |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 345 | write32(&cru_ptr->cru_clksel_con[0], RK_CLRBITS(CORE_SEL_PLL_MSK) | |
| 346 | RK_CLRSETBITS(A12_DIV_MSK, 0 << A12_DIV_SHIFT) | |
| 347 | RK_CLRSETBITS(MP_DIV_MSK, 3 << MP_DIV_SHIFT) | |
| 348 | RK_CLRSETBITS(M0_DIV_MSK, 1 << 0)); |
huang lin | 08884e3 | 2014-10-10 20:28:47 -0700 | [diff] [blame] | 349 | |
| 350 | /* |
| 351 | * set up dependent divisors for L2RAM/ATCLK and PCLK clocks. |
| 352 | * l2ramclk = 900MHz, atclk = 450MHz, pclk_dbg = 450MHz |
| 353 | */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 354 | write32(&cru_ptr->cru_clksel_con[37], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 355 | RK_CLRSETBITS(L2_DIV_MSK, 1 << 0) | |
| 356 | RK_CLRSETBITS(ATCLK_DIV_MSK, (3 << ATCLK_DIV_SHIFT)) | |
| 357 | RK_CLRSETBITS(PCLK_DBG_DIV_MSK, (3 << PCLK_DBG_DIV_SHIFT))); |
huang lin | 08884e3 | 2014-10-10 20:28:47 -0700 | [diff] [blame] | 358 | |
| 359 | /* PLL enter normal-mode */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 360 | write32(&cru_ptr->cru_mode_con, |
| 361 | RK_CLRSETBITS(APLL_MODE_MSK, APLL_MODE_NORM)); |
huang lin | 08884e3 | 2014-10-10 20:28:47 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Jinkun Hong | c33ce35 | 2014-08-28 09:37:22 -0700 | [diff] [blame] | 364 | void rkclk_configure_ddr(unsigned int hz) |
| 365 | { |
| 366 | struct pll_div dpll_cfg; |
| 367 | |
Julius Werner | f8dcdea | 2014-10-06 15:02:12 -0700 | [diff] [blame] | 368 | switch (hz) { |
| 369 | case 300*MHz: |
huang lin | c2b48e5 | 2015-06-30 10:01:14 +0800 | [diff] [blame] | 370 | dpll_cfg = (struct pll_div){.nf = 50, .nr = 2, .no = 2}; |
Julius Werner | f8dcdea | 2014-10-06 15:02:12 -0700 | [diff] [blame] | 371 | break; |
| 372 | case 533*MHz: /* actually 533.3P MHz */ |
| 373 | dpll_cfg = (struct pll_div){.nf = 400, .nr = 9, .no = 2}; |
| 374 | break; |
| 375 | case 666*MHz: /* actually 666.6P MHz */ |
| 376 | dpll_cfg = (struct pll_div){.nf = 500, .nr = 9, .no = 2}; |
| 377 | break; |
| 378 | case 800*MHz: |
| 379 | dpll_cfg = (struct pll_div){.nf = 100, .nr = 3, .no = 1}; |
| 380 | break; |
| 381 | default: |
| 382 | die("Unsupported SDRAM frequency, add to clock.c!"); |
Jinkun Hong | c33ce35 | 2014-08-28 09:37:22 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Jinkun Hong | c33ce35 | 2014-08-28 09:37:22 -0700 | [diff] [blame] | 385 | /* pll enter slow-mode */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 386 | write32(&cru_ptr->cru_mode_con, |
| 387 | RK_CLRSETBITS(DPLL_MODE_MSK, DPLL_MODE_SLOW)); |
Jinkun Hong | c33ce35 | 2014-08-28 09:37:22 -0700 | [diff] [blame] | 388 | |
| 389 | rkclk_set_pll(&cru_ptr->cru_dpll_con[0], &dpll_cfg); |
| 390 | |
| 391 | /* waiting for pll lock */ |
| 392 | while (1) { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 393 | if (read32(&rk3288_grf->soc_status[1]) & SOCSTS_DPLL_LOCK) |
Jinkun Hong | c33ce35 | 2014-08-28 09:37:22 -0700 | [diff] [blame] | 394 | break; |
| 395 | udelay(1); |
| 396 | } |
| 397 | |
| 398 | /* PLL enter normal-mode */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 399 | write32(&cru_ptr->cru_mode_con, |
| 400 | RK_CLRSETBITS(DPLL_MODE_MSK, DPLL_MODE_NORM)); |
Jinkun Hong | c33ce35 | 2014-08-28 09:37:22 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void rkclk_ddr_reset(u32 ch, u32 ctl, u32 phy) |
| 404 | { |
| 405 | u32 phy_ctl_srstn_shift = 4 + 5 * ch; |
| 406 | u32 ctl_psrstn_shift = 3 + 5 * ch; |
| 407 | u32 ctl_srstn_shift = 2 + 5 * ch; |
| 408 | u32 phy_psrstn_shift = 1 + 5 * ch; |
| 409 | u32 phy_srstn_shift = 5 * ch; |
| 410 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 411 | write32(&cru_ptr->cru_softrst_con[10], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 412 | RK_CLRSETBITS(1 << phy_ctl_srstn_shift, |
| 413 | phy << phy_ctl_srstn_shift) | |
| 414 | RK_CLRSETBITS(1 << ctl_psrstn_shift, ctl << ctl_psrstn_shift) | |
| 415 | RK_CLRSETBITS(1 << ctl_srstn_shift, ctl << ctl_srstn_shift) | |
| 416 | RK_CLRSETBITS(1 << phy_psrstn_shift, phy << phy_psrstn_shift) | |
| 417 | RK_CLRSETBITS(1 << phy_srstn_shift, phy << phy_srstn_shift)); |
Jinkun Hong | c33ce35 | 2014-08-28 09:37:22 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void rkclk_ddr_phy_ctl_reset(u32 ch, u32 n) |
| 421 | { |
| 422 | u32 phy_ctl_srstn_shift = 4 + 5 * ch; |
| 423 | |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 424 | write32(&cru_ptr->cru_softrst_con[10], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 425 | RK_CLRSETBITS(1 << phy_ctl_srstn_shift, |
| 426 | n << phy_ctl_srstn_shift)); |
Jinkun Hong | c33ce35 | 2014-08-28 09:37:22 -0700 | [diff] [blame] | 427 | } |
| 428 | |
huang lin | 630c86d | 2014-08-26 17:28:46 +0800 | [diff] [blame] | 429 | void rkclk_configure_spi(unsigned int bus, unsigned int hz) |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 430 | { |
huang lin | 630c86d | 2014-08-26 17:28:46 +0800 | [diff] [blame] | 431 | int src_clk_div = GPLL_HZ / hz; |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 432 | |
huang lin | 630c86d | 2014-08-26 17:28:46 +0800 | [diff] [blame] | 433 | assert((src_clk_div - 1 < 127) && (src_clk_div * hz == GPLL_HZ)); |
| 434 | |
| 435 | switch (bus) { /*select gpll as spi src clk, and set div*/ |
| 436 | case 0: |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 437 | write32(&cru_ptr->cru_clksel_con[25], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 438 | RK_CLRSETBITS(1 << 7 | 0x1f << 0, |
| 439 | 1 << 7 | (src_clk_div - 1) << 0)); |
huang lin | 630c86d | 2014-08-26 17:28:46 +0800 | [diff] [blame] | 440 | break; |
| 441 | case 1: |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 442 | write32(&cru_ptr->cru_clksel_con[25], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 443 | RK_CLRSETBITS(1 << 15 | 0x1f << 8, |
| 444 | 1 << 15 | (src_clk_div - 1) << 8)); |
huang lin | 630c86d | 2014-08-26 17:28:46 +0800 | [diff] [blame] | 445 | break; |
| 446 | case 2: |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 447 | write32(&cru_ptr->cru_clksel_con[39], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 448 | RK_CLRSETBITS(1 << 7 | 0x1f << 0, |
| 449 | 1 << 7 | (src_clk_div - 1) << 0)); |
huang lin | 630c86d | 2014-08-26 17:28:46 +0800 | [diff] [blame] | 450 | break; |
| 451 | default: |
| 452 | printk(BIOS_ERR, "do not support this spi bus\n"); |
| 453 | } |
jinkun.hong | 503d121 | 2014-07-31 14:50:49 +0800 | [diff] [blame] | 454 | } |
huang lin | 739df1b | 2014-08-27 17:07:42 +0800 | [diff] [blame] | 455 | |
| 456 | static u32 clk_gcd(u32 a, u32 b) |
| 457 | { |
| 458 | while (b != 0) { |
| 459 | int r = b; |
| 460 | b = a % b; |
| 461 | a = r; |
| 462 | } |
| 463 | return a; |
| 464 | } |
| 465 | |
| 466 | void rkclk_configure_i2s(unsigned int hz) |
| 467 | { |
| 468 | int n, d; |
| 469 | int v; |
| 470 | |
| 471 | /* i2s source clock: gpll |
| 472 | i2s0_outclk_sel: clk_i2s |
| 473 | i2s0_clk_sel: divider ouput from fraction |
| 474 | i2s0_pll_div_con: 0*/ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 475 | write32(&cru_ptr->cru_clksel_con[4], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 476 | RK_CLRSETBITS(1 << 15 | 1 << 12 | 3 << 8 | 0x7f << 0, |
| 477 | 1 << 15 | 0 << 12 | 1 << 8 | 0 << 0)); |
huang lin | 739df1b | 2014-08-27 17:07:42 +0800 | [diff] [blame] | 478 | |
| 479 | /* set frac divider */ |
| 480 | v = clk_gcd(GPLL_HZ, hz); |
| 481 | n = (GPLL_HZ / v) & (0xffff); |
| 482 | d = (hz / v) & (0xffff); |
| 483 | assert(hz == GPLL_HZ / n * d); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 484 | write32(&cru_ptr->cru_clksel_con[8], d << 16 | n); |
huang lin | 739df1b | 2014-08-27 17:07:42 +0800 | [diff] [blame] | 485 | } |
huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 486 | |
Julius Werner | 33df495 | 2014-12-16 22:48:26 -0800 | [diff] [blame] | 487 | void rkclk_configure_crypto(unsigned int hz) |
| 488 | { |
| 489 | u32 div = PD_BUS_ACLK_HZ / hz; |
| 490 | |
| 491 | assert((div - 1 < 4) && (div * hz == PD_BUS_ACLK_HZ)); |
| 492 | assert(hz <= 150*MHz); /* Suggested max in TRM. */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 493 | write32(&cru_ptr->cru_clksel_con[26], |
| 494 | RK_CLRSETBITS(0x3 << 6, (div - 1) << 6)); |
Julius Werner | 33df495 | 2014-12-16 22:48:26 -0800 | [diff] [blame] | 495 | } |
| 496 | |
huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 497 | void rkclk_configure_tsadc(unsigned int hz) |
| 498 | { |
| 499 | u32 div; |
| 500 | u32 src_clk = 32 * KHz; /* tsadc source clock is 32KHz*/ |
| 501 | |
| 502 | div = src_clk / hz; |
| 503 | assert((div - 1 < 64) && (div * hz == 32 * KHz)); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 504 | write32(&cru_ptr->cru_clksel_con[2], |
| 505 | RK_CLRSETBITS(0x3f << 0, (div - 1) << 0)); |
huang lin | a97bd5a | 2014-10-14 10:04:16 -0700 | [diff] [blame] | 506 | } |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 507 | |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 508 | static int pll_para_config(u32 freq_hz, struct pll_div *div, u32 *ext_div) |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 509 | { |
| 510 | u32 ref_khz = OSC_HZ / KHz, nr, nf = 0; |
| 511 | u32 fref_khz; |
| 512 | u32 diff_khz, best_diff_khz; |
| 513 | const u32 max_nr = 1 << 6, max_nf = 1 << 12, max_no = 1 << 4; |
| 514 | u32 vco_khz; |
| 515 | u32 no = 1; |
| 516 | u32 freq_khz = freq_hz / KHz; |
| 517 | |
| 518 | if (!freq_hz) { |
| 519 | printk(BIOS_ERR, "%s: the frequency can not be 0 Hz\n", __func__); |
| 520 | return -1; |
| 521 | } |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 522 | |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 523 | no = div_round_up(VCO_MIN_KHZ, freq_khz); |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 524 | if (ext_div) { |
| 525 | *ext_div = div_round_up(no, max_no); |
| 526 | no = div_round_up(no, *ext_div); |
| 527 | } |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 528 | |
| 529 | /* only even divisors (and 1) are supported */ |
| 530 | if (no > 1) |
| 531 | no = div_round_up(no, 2) * 2; |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 532 | |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 533 | vco_khz = freq_khz * no; |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 534 | if (ext_div) |
| 535 | vco_khz *= *ext_div; |
| 536 | |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 537 | if (vco_khz < VCO_MIN_KHZ || vco_khz > VCO_MAX_KHZ || no > max_no) { |
| 538 | printk(BIOS_ERR, "%s: Cannot find out a supported VCO" |
| 539 | " for Frequency (%uHz).\n", __func__, freq_hz); |
| 540 | return -1; |
| 541 | } |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 542 | |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 543 | div->no = no; |
| 544 | |
| 545 | best_diff_khz = vco_khz; |
| 546 | for (nr = 1; nr < max_nr && best_diff_khz; nr++) { |
| 547 | fref_khz = ref_khz / nr; |
| 548 | if (fref_khz < FREF_MIN_KHZ) |
| 549 | break; |
| 550 | if (fref_khz > FREF_MAX_KHZ) |
| 551 | continue; |
| 552 | |
| 553 | nf = vco_khz / fref_khz; |
| 554 | if (nf >= max_nf) |
| 555 | continue; |
| 556 | diff_khz = vco_khz - nf * fref_khz; |
| 557 | if (nf + 1 < max_nf && diff_khz > fref_khz / 2) { |
| 558 | nf++; |
| 559 | diff_khz = fref_khz - diff_khz; |
| 560 | } |
| 561 | |
| 562 | if (diff_khz >= best_diff_khz) |
| 563 | continue; |
| 564 | |
| 565 | best_diff_khz = diff_khz; |
| 566 | div->nr = nr; |
| 567 | div->nf = nf; |
| 568 | } |
| 569 | |
| 570 | if (best_diff_khz > 4 * (MHz/KHz)) { |
| 571 | printk(BIOS_ERR, "%s: Failed to match output frequency %u, " |
| 572 | "difference is %u Hz,exceed 4MHZ\n", __func__, freq_hz, |
| 573 | best_diff_khz * KHz); |
| 574 | return -1; |
| 575 | } |
| 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | void rkclk_configure_edp(void) |
| 581 | { |
huang lin | 2e2288d | 2014-11-25 09:27:13 +0800 | [diff] [blame] | 582 | /* clk_edp_24M source: 24M */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 583 | write32(&cru_ptr->cru_clksel_con[28], RK_SETBITS(1 << 15)); |
huang lin | 2e2288d | 2014-11-25 09:27:13 +0800 | [diff] [blame] | 584 | |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 585 | /* rst edp */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 586 | write32(&cru_ptr->cru_softrst_con[6], RK_SETBITS(1 << 15)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 587 | udelay(1); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 588 | write32(&cru_ptr->cru_softrst_con[6], RK_CLRBITS(1 << 15)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 589 | } |
| 590 | |
Yakir Yang | 68f42be | 2015-04-29 10:08:12 -0500 | [diff] [blame] | 591 | void rkclk_configure_hdmi(void) |
| 592 | { |
| 593 | /* enable pclk hdmi ctrl */ |
| 594 | write32(&cru_ptr->cru_clkgate_con[16], RK_CLRBITS(1 << 9)); |
| 595 | |
| 596 | /* software reset hdmi */ |
| 597 | write32(&cru_ptr->cru_softrst_con[7], RK_SETBITS(1 << 9)); |
| 598 | udelay(1); |
| 599 | write32(&cru_ptr->cru_softrst_con[7], RK_CLRBITS(1 << 9)); |
| 600 | } |
| 601 | |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 602 | void rkclk_configure_vop_aclk(u32 vop_id, u32 aclk_hz) |
| 603 | { |
| 604 | u32 div; |
| 605 | |
| 606 | /* vop aclk source clk: cpll */ |
| 607 | div = CPLL_HZ / aclk_hz; |
| 608 | assert((div - 1 < 64) && (div * aclk_hz == CPLL_HZ)); |
| 609 | |
| 610 | switch (vop_id) { |
| 611 | case 0: |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 612 | write32(&cru_ptr->cru_clksel_con[31], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 613 | RK_CLRSETBITS(3 << 6 | 0x1f << 0, |
| 614 | 0 << 6 | (div - 1) << 0)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 615 | break; |
| 616 | |
| 617 | case 1: |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 618 | write32(&cru_ptr->cru_clksel_con[31], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 619 | RK_CLRSETBITS(3 << 14 | 0x1f << 8, |
| 620 | 0 << 14 | (div - 1) << 8)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 621 | break; |
| 622 | } |
| 623 | } |
| 624 | |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 625 | int rkclk_configure_vop_dclk(u32 vop_id, u32 dclk_hz) |
| 626 | { |
| 627 | struct pll_div npll_config = {0}; |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 628 | u32 lcdc_div; |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 629 | |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 630 | if (pll_para_config(dclk_hz, &npll_config, &lcdc_div)) |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 631 | return -1; |
| 632 | |
| 633 | /* npll enter slow-mode */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 634 | write32(&cru_ptr->cru_mode_con, |
| 635 | RK_CLRSETBITS(NPLL_MODE_MSK, NPLL_MODE_SLOW)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 636 | |
| 637 | rkclk_set_pll(&cru_ptr->cru_npll_con[0], &npll_config); |
| 638 | |
| 639 | /* waiting for pll lock */ |
| 640 | while (1) { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 641 | if (read32(&rk3288_grf->soc_status[1]) & SOCSTS_NPLL_LOCK) |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 642 | break; |
| 643 | udelay(1); |
| 644 | } |
| 645 | |
| 646 | /* npll enter normal-mode */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 647 | write32(&cru_ptr->cru_mode_con, |
| 648 | RK_CLRSETBITS(NPLL_MODE_MSK, NPLL_MODE_NORM)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 649 | |
| 650 | /* vop dclk source clk: npll,dclk_div: 1 */ |
| 651 | switch (vop_id) { |
| 652 | case 0: |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 653 | write32(&cru_ptr->cru_clksel_con[27], |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 654 | RK_CLRSETBITS(0xff << 8 | 3 << 0, |
| 655 | (lcdc_div - 1) << 8 | 2 << 0)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 656 | break; |
| 657 | |
| 658 | case 1: |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 659 | write32(&cru_ptr->cru_clksel_con[29], |
Yakir Yang | 8c3ab6a | 2015-07-27 08:50:36 -0500 | [diff] [blame] | 660 | RK_CLRSETBITS(0xff << 8 | 3 << 6, |
| 661 | (lcdc_div - 1) << 8 | 2 << 6)); |
huang lin | 40f558e | 2014-09-19 14:51:52 +0800 | [diff] [blame] | 662 | break; |
| 663 | } |
| 664 | return 0; |
| 665 | } |
Julius Werner | 2460a55 | 2014-11-24 13:50:46 -0800 | [diff] [blame] | 666 | |
| 667 | int rkclk_was_watchdog_reset(void) |
| 668 | { |
| 669 | /* Bits 5 and 4 are "second" and "first" global watchdog reset. */ |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 670 | return read32(&cru_ptr->cru_glb_rst_st) & 0x30; |
Julius Werner | 2460a55 | 2014-11-24 13:50:46 -0800 | [diff] [blame] | 671 | } |