blob: 42b664b57625f0d30728be90dae7ed6c2c45ebd3 [file] [log] [blame]
Vitaly Andrianovef509b92014-04-04 13:16:53 -04001/*
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 Andrianovef509b92014-04-04 13:16:53 -040011#include <asm/arch/clock.h>
12#include <asm/arch/clock_defs.h>
13
14static 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 Andrianovef509b92014-04-04 13:16:53 -040024void 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, Ivan8dfc15f2014-07-09 23:44:47 +030039 setbits_le32(keystone_pll_regs[data->pll].reg1,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040040 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, Ivan8dfc15f2014-07-09 23:44:47 +030059 clrsetbits_le32(keystone_pll_regs[data->pll].reg0,
60 PLLM_MULT_HI_SMASK, (pllm << 6));
Vitaly Andrianovef509b92014-04-04 13:16:53 -040061
62 /* Set the BWADJ (12 bit field) */
63 tmp_ctl = pllm >> 1; /* Divide the pllm by 2 */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +030064 clrsetbits_le32(keystone_pll_regs[data->pll].reg0,
65 PLL_BWADJ_LO_SMASK,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040066 (tmp_ctl << PLL_BWADJ_LO_SHIFT));
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +030067 clrsetbits_le32(keystone_pll_regs[data->pll].reg1,
68 PLL_BWADJ_HI_MASK,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040069 (tmp_ctl >> 8));
70
71 /*
72 * Set the pll divider (6 bit field) *
73 * PLLD[5:0] is located in MAINPLLCTL0
74 */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +030075 clrsetbits_le32(keystone_pll_regs[data->pll].reg0,
76 PLL_DIV_MASK, plld);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040077
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, Ivan8dfc15f2014-07-09 23:44:47 +0300112 setbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400113 /*
114 * Set CHIPMISCCTL1[13] = 0 (enable glitchfree bypass)
115 * only applicable for Kepler
116 */
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +0300117 clrbits_le32(KS2_MISC_CTRL, KS2_ARM_PLL_EN);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400118 /* 2 In PLLCTL1, write PLLRST = 1 (PLL is reset) */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300119 setbits_le32(keystone_pll_regs[data->pll].reg1 ,
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400120 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, Ivan8dfc15f2014-07-09 23:44:47 +0300132 __raw_writel(tmp, keystone_pll_regs[data->pll].reg0);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400133
134 /* Set BWADJ[11:8] bits */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300135 tmp = __raw_readl(keystone_pll_regs[data->pll].reg1);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400136 tmp &= ~(PLL_BWADJ_HI_MASK);
137 tmp |= ((bwadj>>8) & PLL_BWADJ_HI_MASK);
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300138 __raw_writel(tmp, keystone_pll_regs[data->pll].reg1);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400139 /*
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, Ivan8dfc15f2014-07-09 23:44:47 +0300146 clrbits_le32(keystone_pll_regs[data->pll].reg1, PLL_PLLRST);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400147 /*
148 * 7 Wait for at least 500 * REFCLK cycles * (PLLD + 1)
149 * (PLL lock time)
150 */
151 sdelay(105000);
152 /* 8 disable bypass */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300153 clrbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400154 /*
155 * 9 Set CHIPMISCCTL1[13] = 1 (disable glitchfree bypass)
156 * only applicable for Kepler
157 */
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +0300158 setbits_le32(KS2_MISC_CTRL, KS2_ARM_PLL_EN);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400159 } else {
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300160 setbits_le32(keystone_pll_regs[data->pll].reg1, PLLCTL_ENSAT);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400161 /*
162 * process keeps state of Bypass bit while programming
163 * all other DDR PLL settings
164 */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300165 tmp = __raw_readl(keystone_pll_regs[data->pll].reg0);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400166 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, Ivan8dfc15f2014-07-09 23:44:47 +0300177 __raw_writel(tmp, keystone_pll_regs[data->pll].reg0);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400178
179 /* Set BWADJ[11:8] bits */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300180 tmp = __raw_readl(keystone_pll_regs[data->pll].reg1);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400181 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, Ivan8dfc15f2014-07-09 23:44:47 +0300188 __raw_writel(tmp, keystone_pll_regs[data->pll].reg1);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400189
190 /* Reset bit: bit 14 for both DDR3 & PASS PLL */
191 tmp = PLL_PLLRST;
192 /* Set RESET bit = 1 */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300193 setbits_le32(keystone_pll_regs[data->pll].reg1, tmp);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400194 /* Wait for a minimum of 7 us*/
195 sdelay(21000);
196 /* Clear RESET bit */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300197 clrbits_le32(keystone_pll_regs[data->pll].reg1, tmp);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400198 sdelay(105000);
199
200 /* clear BYPASS (Enable PLL Mode) */
Khoronzhuk, Ivan8dfc15f2014-07-09 23:44:47 +0300201 clrbits_le32(keystone_pll_regs[data->pll].reg0, PLLCTL_BYPASS);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400202 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
212void 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}