Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Keystone2: pll initialization |
| 3 | * |
| 4 | * (C) Copyright 2012-2014 |
| 5 | * Texas Instruments Incorporated, <www.ti.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/clock_defs.h> |
| 13 | |
| 14 | static void wait_for_completion(const struct pll_init_data *data) |
| 15 | { |
| 16 | int i; |
| 17 | for (i = 0; i < 100; i++) { |
| 18 | sdelay(450); |
| 19 | if ((pllctl_reg_read(data->pll, stat) & PLLSTAT_GO) == 0) |
| 20 | break; |
| 21 | } |
| 22 | } |
| 23 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 24 | void init_pll(const struct pll_init_data *data) |
| 25 | { |
| 26 | u32 tmp, tmp_ctl, pllm, plld, pllod, bwadj; |
| 27 | |
| 28 | pllm = data->pll_m - 1; |
| 29 | plld = (data->pll_d - 1) & PLL_DIV_MASK; |
| 30 | pllod = (data->pll_od - 1) & PLL_CLKOD_MASK; |
| 31 | |
| 32 | if (data->pll == MAIN_PLL) { |
| 33 | /* The requered delay before main PLL configuration */ |
| 34 | sdelay(210000); |
| 35 | |
| 36 | tmp = pllctl_reg_read(data->pll, secctl); |
| 37 | |
| 38 | if (tmp & (PLLCTL_BYPASS)) { |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 39 | setbits_le32(keystone_pll_regs[data->pll].reg1, |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 40 | BIT(MAIN_ENSAT_OFFSET)); |
| 41 | |
| 42 | pllctl_reg_clrbits(data->pll, ctl, PLLCTL_PLLEN | |
| 43 | PLLCTL_PLLENSRC); |
| 44 | sdelay(340); |
| 45 | |
| 46 | pllctl_reg_setbits(data->pll, secctl, PLLCTL_BYPASS); |
| 47 | pllctl_reg_setbits(data->pll, ctl, PLLCTL_PLLPWRDN); |
| 48 | sdelay(21000); |
| 49 | |
| 50 | pllctl_reg_clrbits(data->pll, ctl, PLLCTL_PLLPWRDN); |
| 51 | } else { |
| 52 | pllctl_reg_clrbits(data->pll, ctl, PLLCTL_PLLEN | |
| 53 | PLLCTL_PLLENSRC); |
| 54 | sdelay(340); |
| 55 | } |
| 56 | |
| 57 | pllctl_reg_write(data->pll, mult, pllm & PLLM_MULT_LO_MASK); |
| 58 | |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 59 | clrsetbits_le32(keystone_pll_regs[data->pll].reg0, |
| 60 | PLLM_MULT_HI_SMASK, (pllm << 6)); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 61 | |
| 62 | /* Set the BWADJ (12 bit field) */ |
| 63 | tmp_ctl = pllm >> 1; /* Divide the pllm by 2 */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 64 | clrsetbits_le32(keystone_pll_regs[data->pll].reg0, |
| 65 | PLL_BWADJ_LO_SMASK, |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 66 | (tmp_ctl << PLL_BWADJ_LO_SHIFT)); |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 67 | clrsetbits_le32(keystone_pll_regs[data->pll].reg1, |
| 68 | PLL_BWADJ_HI_MASK, |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 69 | (tmp_ctl >> 8)); |
| 70 | |
| 71 | /* |
| 72 | * Set the pll divider (6 bit field) * |
| 73 | * PLLD[5:0] is located in MAINPLLCTL0 |
| 74 | */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 75 | clrsetbits_le32(keystone_pll_regs[data->pll].reg0, |
| 76 | PLL_DIV_MASK, plld); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 77 | |
| 78 | /* Set the OUTPUT DIVIDE (4 bit field) in SECCTL */ |
| 79 | pllctl_reg_rmw(data->pll, secctl, PLL_CLKOD_SMASK, |
| 80 | (pllod << PLL_CLKOD_SHIFT)); |
| 81 | wait_for_completion(data); |
| 82 | |
| 83 | pllctl_reg_write(data->pll, div1, PLLM_RATIO_DIV1); |
| 84 | pllctl_reg_write(data->pll, div2, PLLM_RATIO_DIV2); |
| 85 | pllctl_reg_write(data->pll, div3, PLLM_RATIO_DIV3); |
| 86 | pllctl_reg_write(data->pll, div4, PLLM_RATIO_DIV4); |
| 87 | pllctl_reg_write(data->pll, div5, PLLM_RATIO_DIV5); |
| 88 | |
| 89 | pllctl_reg_setbits(data->pll, alnctl, 0x1f); |
| 90 | |
| 91 | /* |
| 92 | * Set GOSET bit in PLLCMD to initiate the GO operation |
| 93 | * to change the divide |
| 94 | */ |
| 95 | pllctl_reg_setbits(data->pll, cmd, PLLSTAT_GO); |
| 96 | sdelay(1500); /* wait for the phase adj */ |
| 97 | wait_for_completion(data); |
| 98 | |
| 99 | /* Reset PLL */ |
| 100 | pllctl_reg_setbits(data->pll, ctl, PLLCTL_PLLRST); |
| 101 | sdelay(21000); /* Wait for a minimum of 7 us*/ |
| 102 | pllctl_reg_clrbits(data->pll, ctl, PLLCTL_PLLRST); |
| 103 | sdelay(105000); /* Wait for PLL Lock time (min 50 us) */ |
| 104 | |
| 105 | pllctl_reg_clrbits(data->pll, secctl, PLLCTL_BYPASS); |
| 106 | |
| 107 | tmp = pllctl_reg_setbits(data->pll, ctl, PLLCTL_PLLEN); |
| 108 | |
| 109 | } else if (data->pll == TETRIS_PLL) { |
| 110 | bwadj = pllm >> 1; |
| 111 | /* 1.5 Set PLLCTL0[BYPASS] =1 (enable bypass), */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 112 | setbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 113 | /* |
| 114 | * Set CHIPMISCCTL1[13] = 0 (enable glitchfree bypass) |
| 115 | * only applicable for Kepler |
| 116 | */ |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 117 | clrbits_le32(KS2_MISC_CTRL, KS2_ARM_PLL_EN); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 118 | /* 2 In PLLCTL1, write PLLRST = 1 (PLL is reset) */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 119 | setbits_le32(keystone_pll_regs[data->pll].reg1 , |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 120 | PLL_PLLRST | PLLCTL_ENSAT); |
| 121 | |
| 122 | /* |
| 123 | * 3 Program PLLM and PLLD in PLLCTL0 register |
| 124 | * 4 Program BWADJ[7:0] in PLLCTL0 and BWADJ[11:8] in |
| 125 | * PLLCTL1 register. BWADJ value must be set |
| 126 | * to ((PLLM + 1) >> 1) – 1) |
| 127 | */ |
| 128 | tmp = ((bwadj & PLL_BWADJ_LO_MASK) << PLL_BWADJ_LO_SHIFT) | |
| 129 | (pllm << 6) | |
| 130 | (plld & PLL_DIV_MASK) | |
| 131 | (pllod << PLL_CLKOD_SHIFT) | PLLCTL_BYPASS; |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 132 | __raw_writel(tmp, keystone_pll_regs[data->pll].reg0); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 133 | |
| 134 | /* Set BWADJ[11:8] bits */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 135 | tmp = __raw_readl(keystone_pll_regs[data->pll].reg1); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 136 | tmp &= ~(PLL_BWADJ_HI_MASK); |
| 137 | tmp |= ((bwadj>>8) & PLL_BWADJ_HI_MASK); |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 138 | __raw_writel(tmp, keystone_pll_regs[data->pll].reg1); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 139 | /* |
| 140 | * 5 Wait for at least 5 us based on the reference |
| 141 | * clock (PLL reset time) |
| 142 | */ |
| 143 | sdelay(21000); /* Wait for a minimum of 7 us*/ |
| 144 | |
| 145 | /* 6 In PLLCTL1, write PLLRST = 0 (PLL reset is released) */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 146 | clrbits_le32(keystone_pll_regs[data->pll].reg1, PLL_PLLRST); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 147 | /* |
| 148 | * 7 Wait for at least 500 * REFCLK cycles * (PLLD + 1) |
| 149 | * (PLL lock time) |
| 150 | */ |
| 151 | sdelay(105000); |
| 152 | /* 8 disable bypass */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 153 | clrbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 154 | /* |
| 155 | * 9 Set CHIPMISCCTL1[13] = 1 (disable glitchfree bypass) |
| 156 | * only applicable for Kepler |
| 157 | */ |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 158 | setbits_le32(KS2_MISC_CTRL, KS2_ARM_PLL_EN); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 159 | } else { |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 160 | setbits_le32(keystone_pll_regs[data->pll].reg1, PLLCTL_ENSAT); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 161 | /* |
| 162 | * process keeps state of Bypass bit while programming |
| 163 | * all other DDR PLL settings |
| 164 | */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 165 | tmp = __raw_readl(keystone_pll_regs[data->pll].reg0); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 166 | tmp &= PLLCTL_BYPASS; /* clear everything except Bypass */ |
| 167 | |
| 168 | /* |
| 169 | * Set the BWADJ[7:0], PLLD[5:0] and PLLM to PLLCTL0, |
| 170 | * bypass disabled |
| 171 | */ |
| 172 | bwadj = pllm >> 1; |
| 173 | tmp |= ((bwadj & PLL_BWADJ_LO_SHIFT) << PLL_BWADJ_LO_SHIFT) | |
| 174 | (pllm << PLL_MULT_SHIFT) | |
| 175 | (plld & PLL_DIV_MASK) | |
| 176 | (pllod << PLL_CLKOD_SHIFT); |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 177 | __raw_writel(tmp, keystone_pll_regs[data->pll].reg0); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 178 | |
| 179 | /* Set BWADJ[11:8] bits */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 180 | tmp = __raw_readl(keystone_pll_regs[data->pll].reg1); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 181 | tmp &= ~(PLL_BWADJ_HI_MASK); |
| 182 | tmp |= ((bwadj >> 8) & PLL_BWADJ_HI_MASK); |
| 183 | |
| 184 | /* set PLL Select (bit 13) for PASS PLL */ |
| 185 | if (data->pll == PASS_PLL) |
| 186 | tmp |= PLLCTL_PAPLL; |
| 187 | |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 188 | __raw_writel(tmp, keystone_pll_regs[data->pll].reg1); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 189 | |
| 190 | /* Reset bit: bit 14 for both DDR3 & PASS PLL */ |
| 191 | tmp = PLL_PLLRST; |
| 192 | /* Set RESET bit = 1 */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 193 | setbits_le32(keystone_pll_regs[data->pll].reg1, tmp); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 194 | /* Wait for a minimum of 7 us*/ |
| 195 | sdelay(21000); |
| 196 | /* Clear RESET bit */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 197 | clrbits_le32(keystone_pll_regs[data->pll].reg1, tmp); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 198 | sdelay(105000); |
| 199 | |
| 200 | /* clear BYPASS (Enable PLL Mode) */ |
Khoronzhuk, Ivan | 8dfc15f | 2014-07-09 23:44:47 +0300 | [diff] [blame^] | 201 | clrbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 202 | sdelay(21000); /* Wait for a minimum of 7 us*/ |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * This is required to provide a delay between multiple |
| 207 | * consequent PPL configurations |
| 208 | */ |
| 209 | sdelay(210000); |
| 210 | } |
| 211 | |
| 212 | void init_plls(int num_pll, struct pll_init_data *config) |
| 213 | { |
| 214 | int i; |
| 215 | |
| 216 | for (i = 0; i < num_pll; i++) |
| 217 | init_pll(&config[i]); |
| 218 | } |