1
2
3
4
5
6
7
8
9#include <common.h>
10#include <asm/processor.h>
11
12#include <asm/immap.h>
13#include <asm/io.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17
18
19
20#define CLOCK_LPD_MIN (1 << 0)
21#define CLOCK_LPD_MAX (1 << 15)
22
23#define CLOCK_PLL_FVCO_MAX 540000000
24#define CLOCK_PLL_FVCO_MIN 300000000
25
26#define CLOCK_PLL_FSYS_MAX 266666666
27#define CLOCK_PLL_FSYS_MIN 100000000
28#define MHZ 1000000
29
30void clock_enter_limp(int lpdiv)
31{
32 ccm_t *ccm = (ccm_t *)MMAP_CCM;
33 int i, j;
34
35
36 if (lpdiv < CLOCK_LPD_MIN)
37 lpdiv = CLOCK_LPD_MIN;
38 if (lpdiv > CLOCK_LPD_MAX)
39 lpdiv = CLOCK_LPD_MAX;
40
41
42 for (i = 0, j = lpdiv; j != 1; j >>= 1, i++) ;
43
44#ifdef CONFIG_MCF5445x
45
46 clrsetbits_be16(&ccm->cdr, 0x0f00, CCM_CDR_LPDIV(i));
47#endif
48
49
50 setbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
51}
52
53
54
55
56
57void clock_exit_limp(void)
58{
59 ccm_t *ccm = (ccm_t *)MMAP_CCM;
60 pll_t *pll = (pll_t *)MMAP_PLL;
61
62
63 clrbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
64
65
66 while (!(in_be32(&pll->psr) & PLL_PSR_LOCK))
67 ;
68}
69
70#ifdef CONFIG_MCF5441x
71void setup_5441x_clocks(void)
72{
73 ccm_t *ccm = (ccm_t *)MMAP_CCM;
74 pll_t *pll = (pll_t *)MMAP_PLL;
75 int temp, vco = 0, bootmod_ccr, pdr;
76
77 bootmod_ccr = (in_be16(&ccm->ccr) & CCM_CCR_BOOTMOD) >> 14;
78
79 switch (bootmod_ccr) {
80 case 0:
81 out_be32(&pll->pcr, 0x00000013);
82 out_be32(&pll->pdr, 0x00e70c61);
83 clock_exit_limp();
84 break;
85 case 2:
86 break;
87 case 3:
88 break;
89 }
90
91
92#ifdef CONFIG_LOW_MCFCLK
93 temp = in_be32(&pll->pcr);
94 temp &= ~0x3f;
95 temp |= 5;
96 out_be32(&pll->pcr, temp);
97
98 temp = in_be32(&pll->pdr);
99 temp &= ~0x001f0000;
100 temp |= 0x00040000;
101 out_be32(&pll->pdr, temp);
102 __asm__("tpf");
103#endif
104
105 setbits_be16(&ccm->misccr2, 0x02);
106
107 vco = ((in_be32(&pll->pcr) & PLL_CR_FBKDIV_BITS) + 1) *
108 CONFIG_SYS_INPUT_CLKSRC;
109 gd->arch.vco_clk = vco;
110
111 gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC;
112
113 pdr = in_be32(&pll->pdr);
114 temp = (pdr & PLL_DR_OUTDIV1_BITS) + 1;
115 gd->cpu_clk = vco / temp;
116 gd->arch.flb_clk = vco / temp;
117 gd->arch.flb_clk >>= 1;
118 if (in_be16(&ccm->misccr2) & 2)
119 gd->arch.flb_clk >>= 1;
120
121 temp = ((pdr & PLL_DR_OUTDIV2_BITS) >> 5) + 1;
122 gd->bus_clk = vco / temp;
123
124}
125#endif
126
127#ifdef CONFIG_MCF5445x
128void setup_5445x_clocks(void)
129{
130 ccm_t *ccm = (ccm_t *)MMAP_CCM;
131 pll_t *pll = (pll_t *)MMAP_PLL;
132 int pllmult_nopci[] = { 20, 10, 24, 18, 12, 6, 16, 8 };
133 int pllmult_pci[] = { 12, 6, 16, 8 };
134 int vco = 0, temp, fbtemp, pcrvalue;
135 int *pPllmult = NULL;
136 u16 fbpll_mask;
137#ifdef CONFIG_PCI
138 int bPci;
139#endif
140
141#ifdef CONFIG_M54455EVB
142 u8 *cpld = (u8 *)(CONFIG_SYS_CS2_BASE + 3);
143#endif
144 u8 bootmode;
145
146
147 if (((in_be16(&ccm->ccr) & CCM_CCR_360_FBCONFIG_MASK) == 0x00e0) ||
148 ((in_be16(&ccm->ccr) & CCM_CCR_360_FBCONFIG_MASK) == 0x0060)) {
149 pPllmult = &pllmult_pci[0];
150 fbpll_mask = 3;
151#ifdef CONFIG_PCI
152 bPci = 1;
153#endif
154 } else {
155 pPllmult = &pllmult_nopci[0];
156 fbpll_mask = 7;
157#ifdef CONFIG_PCI
158 gd->pci_clk = 0;
159 bPci = 0;
160#endif
161 }
162
163#ifdef CONFIG_M54455EVB
164 bootmode = (in_8(cpld) & 0x03);
165
166 if (bootmode != 3) {
167
168
169 fbtemp = pPllmult[ccm->ccr & fbpll_mask];
170
171
172 pcrvalue = in_be32(&pll->pcr) & 0xFFFFF0FF;
173 temp = fbtemp - 1;
174 pcrvalue |= PLL_PCR_OUTDIV3(temp);
175
176 out_be32(&pll->pcr, pcrvalue);
177 }
178#endif
179#ifdef CONFIG_M54451EVB
180
181#ifdef CONFIG_CF_SBF
182 bootmode = 3;
183#else
184 bootmode = 2;
185
186
187 pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF) | 0x14000000;
188 out_be32(&pll->pcr, pcrvalue);
189 while ((in_be32(&pll->psr) & PLL_PSR_LOCK) != PLL_PSR_LOCK)
190 ;
191#endif
192#endif
193
194 if (bootmode == 0) {
195
196 vco = pPllmult[ccm->rcon & fbpll_mask] * CONFIG_SYS_INPUT_CLKSRC;
197
198 if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
199
200 int temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
201 int i, j, bus;
202
203 j = (in_be32(&pll->pcr) & 0xFF000000) >> 24;
204 for (i = j; i < 0xFF; i++) {
205 vco = i * CONFIG_SYS_INPUT_CLKSRC;
206 if (vco >= CLOCK_PLL_FVCO_MIN) {
207 bus = vco / temp;
208 if (bus <= CLOCK_PLL_FSYS_MIN - MHZ)
209 continue;
210 else
211 break;
212 }
213 }
214 pcrvalue = in_be32(&pll->pcr) & 0x00FF00FF;
215 fbtemp = ((i - 1) << 8) | ((i - 1) << 12);
216 pcrvalue |= ((i << 24) | fbtemp);
217
218 out_be32(&pll->pcr, pcrvalue);
219 }
220 gd->arch.vco_clk = vco;
221 } else if (bootmode == 2) {
222
223 vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
224 if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
225
226 pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF);
227 pcrvalue |= pPllmult[in_be16(&ccm->ccr) & fbpll_mask] << 24;
228 out_be32(&pll->pcr, pcrvalue);
229 vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
230 }
231 gd->arch.vco_clk = vco;
232 } else if (bootmode == 3) {
233
234 vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
235 gd->arch.vco_clk = vco;
236 }
237
238 if ((in_be16(&ccm->ccr) & CCM_MISCCR_LIMP) == CCM_MISCCR_LIMP) {
239
240 } else {
241 gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC;
242
243 temp = (in_be32(&pll->pcr) & PLL_PCR_OUTDIV1_MASK) + 1;
244 gd->cpu_clk = vco / temp;
245
246 temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
247 gd->bus_clk = vco / temp;
248
249 temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV3_MASK) >> 8) + 1;
250 gd->arch.flb_clk = vco / temp;
251
252#ifdef CONFIG_PCI
253 if (bPci) {
254 temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV4_MASK) >> 12) + 1;
255 gd->pci_clk = vco / temp;
256 }
257#endif
258 }
259
260#ifdef CONFIG_SYS_I2C_FSL
261 gd->arch.i2c1_clk = gd->bus_clk;
262#endif
263}
264#endif
265
266
267int get_clocks(void)
268{
269#ifdef CONFIG_MCF5441x
270 setup_5441x_clocks();
271#endif
272#ifdef CONFIG_MCF5445x
273 setup_5445x_clocks();
274#endif
275
276#ifdef CONFIG_SYS_FSL_I2C
277 gd->arch.i2c1_clk = gd->bus_clk;
278#endif
279
280 return (0);
281}
282