1
2
3
4
5
6
7
8#include <common.h>
9#include <asm/processor.h>
10
11#include <asm/immap.h>
12#include <asm/io.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16
17
18
19#define CLOCK_LPD_MIN (1 << 0)
20#define CLOCK_LPD_MAX (1 << 15)
21
22#define CLOCK_PLL_FVCO_MAX 540000000
23#define CLOCK_PLL_FVCO_MIN 300000000
24
25#define CLOCK_PLL_FSYS_MAX 266666666
26#define CLOCK_PLL_FSYS_MIN 100000000
27#define MHZ 1000000
28
29void clock_enter_limp(int lpdiv)
30{
31 ccm_t *ccm = (ccm_t *)MMAP_CCM;
32 int i, j;
33
34
35 if (lpdiv < CLOCK_LPD_MIN)
36 lpdiv = CLOCK_LPD_MIN;
37 if (lpdiv > CLOCK_LPD_MAX)
38 lpdiv = CLOCK_LPD_MAX;
39
40
41 for (i = 0, j = lpdiv; j != 1; j >>= 1, i++) ;
42
43
44 clrsetbits_be16(&ccm->cdr, 0x0f00, CCM_CDR_LPDIV(i));
45
46
47 setbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
48}
49
50
51
52
53
54void clock_exit_limp(void)
55{
56 ccm_t *ccm = (ccm_t *)MMAP_CCM;
57 pll_t *pll = (pll_t *)MMAP_PLL;
58
59
60 clrbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
61
62
63 while (!(in_be32(&pll->psr) & PLL_PSR_LOCK))
64 ;
65}
66
67
68
69
70int get_clocks(void)
71{
72
73 ccm_t *ccm = (ccm_t *)MMAP_CCM;
74 pll_t *pll = (pll_t *)MMAP_PLL;
75 int vco, temp, pcrvalue, pfdr;
76 u8 bootmode;
77
78 pcrvalue = in_be32(&pll->pcr) & 0xFF0F0FFF;
79 pfdr = pcrvalue >> 24;
80
81 if (pfdr == 0x1E)
82 bootmode = 0;
83
84#ifdef CONFIG_CF_SBF
85 bootmode = 3;
86#endif
87
88 if (bootmode == 0) {
89
90 vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
91 if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
92
93 pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF);
94 pcrvalue |= 0x1E << 24;
95 out_be32(&pll->pcr, pcrvalue);
96 vco =
97 ((in_be32(&pll->pcr) & 0xFF000000) >> 24) *
98 CONFIG_SYS_INPUT_CLKSRC;
99 }
100 gd->arch.vco_clk = vco;
101 } else if (bootmode == 3) {
102
103 vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
104 gd->arch.vco_clk = vco;
105 }
106
107 if ((in_be16(&ccm->ccr) & CCM_MISCCR_LIMP) == CCM_MISCCR_LIMP) {
108
109 } else {
110 gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC;
111
112 temp = (in_be32(&pll->pcr) & PLL_PCR_OUTDIV1_MASK) + 1;
113 gd->cpu_clk = vco / temp;
114
115 temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
116 gd->arch.flb_clk = vco / temp;
117 gd->bus_clk = gd->arch.flb_clk;
118 }
119
120#ifdef CONFIG_SYS_I2C_FSL
121 gd->arch.i2c1_clk = gd->bus_clk;
122#endif
123
124 return (0);
125}
126