]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/armv7/am33xx/clock.c
4 * clocks for AM33XX based boards
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <asm/arch/cpu.h>
21 #include <asm/arch/clock.h>
22 #include <asm/arch/hardware.h>
25 #define PRCM_MOD_EN 0x2
26 #define PRCM_FORCE_WAKEUP 0x2
28 #define PRCM_EMIF_CLK_ACTIVITY BIT(2)
29 #define PRCM_L3_GCLK_ACTIVITY BIT(4)
31 #define PLL_BYPASS_MODE 0x4
32 #define ST_MN_BYPASS 0x00000100
33 #define ST_DPLL_CLK 0x00000001
34 #define CLK_SEL_MASK 0x7ffff
35 #define CLK_DIV_MASK 0x1f
36 #define CLK_DIV2_MASK 0x7f
37 #define CLK_SEL_SHIFT 0x8
38 #define CLK_MODE_SEL 0x7
39 #define CLK_MODE_MASK 0xfffffff8
40 #define CLK_DIV_SEL 0xFFFFFFE0
43 const struct cm_perpll
*cmper
= (struct cm_perpll
*)CM_PER
;
44 const struct cm_wkuppll
*cmwkup
= (struct cm_wkuppll
*)CM_WKUP
;
45 const struct cm_dpll
*cmdpll
= (struct cm_dpll
*)CM_DPLL
;
47 static void enable_interface_clocks(void)
49 /* Enable all the Interconnect Modules */
50 writel(PRCM_MOD_EN
, &cmper
->l3clkctrl
);
51 while (readl(&cmper
->l3clkctrl
) != PRCM_MOD_EN
)
54 writel(PRCM_MOD_EN
, &cmper
->l4lsclkctrl
);
55 while (readl(&cmper
->l4lsclkctrl
) != PRCM_MOD_EN
)
58 writel(PRCM_MOD_EN
, &cmper
->l4fwclkctrl
);
59 while (readl(&cmper
->l4fwclkctrl
) != PRCM_MOD_EN
)
62 writel(PRCM_MOD_EN
, &cmwkup
->wkl4wkclkctrl
);
63 while (readl(&cmwkup
->wkl4wkclkctrl
) != PRCM_MOD_EN
)
66 writel(PRCM_MOD_EN
, &cmper
->l3instrclkctrl
);
67 while (readl(&cmper
->l3instrclkctrl
) != PRCM_MOD_EN
)
70 writel(PRCM_MOD_EN
, &cmper
->l4hsclkctrl
);
71 while (readl(&cmper
->l4hsclkctrl
) != PRCM_MOD_EN
)
76 * Force power domain wake up transition
77 * Ensure that the corresponding interface clock is active before
78 * using the peripheral
80 static void power_domain_wkup_transition(void)
82 writel(PRCM_FORCE_WAKEUP
, &cmper
->l3clkstctrl
);
83 writel(PRCM_FORCE_WAKEUP
, &cmper
->l4lsclkstctrl
);
84 writel(PRCM_FORCE_WAKEUP
, &cmwkup
->wkclkstctrl
);
85 writel(PRCM_FORCE_WAKEUP
, &cmper
->l4fwclkstctrl
);
86 writel(PRCM_FORCE_WAKEUP
, &cmper
->l3sclkstctrl
);
90 * Enable the peripheral clock for required peripherals
92 static void enable_per_clocks(void)
94 /* Enable the control module though RBL would have done it*/
95 writel(PRCM_MOD_EN
, &cmwkup
->wkctrlclkctrl
);
96 while (readl(&cmwkup
->wkctrlclkctrl
) != PRCM_MOD_EN
)
99 /* Enable the module clock */
100 writel(PRCM_MOD_EN
, &cmper
->timer2clkctrl
);
101 while (readl(&cmper
->timer2clkctrl
) != PRCM_MOD_EN
)
104 /* Select the Master osc 24 MHZ as Timer2 clock source */
105 writel(0x1, &cmdpll
->clktimer2clk
);
108 writel(PRCM_MOD_EN
, &cmwkup
->wkup_uart0ctrl
);
109 while (readl(&cmwkup
->wkup_uart0ctrl
) != PRCM_MOD_EN
)
113 writel(PRCM_MOD_EN
, &cmper
->mmc0clkctrl
);
114 while (readl(&cmper
->mmc0clkctrl
) != PRCM_MOD_EN
)
118 writel(PRCM_MOD_EN
, &cmwkup
->wkup_i2c0ctrl
);
119 while (readl(&cmwkup
->wkup_i2c0ctrl
) != PRCM_MOD_EN
)
123 static void mpu_pll_config(void)
125 u32 clkmode
, clksel
, div_m2
;
127 clkmode
= readl(&cmwkup
->clkmoddpllmpu
);
128 clksel
= readl(&cmwkup
->clkseldpllmpu
);
129 div_m2
= readl(&cmwkup
->divm2dpllmpu
);
131 /* Set the PLL to bypass Mode */
132 writel(PLL_BYPASS_MODE
, &cmwkup
->clkmoddpllmpu
);
133 while (readl(&cmwkup
->idlestdpllmpu
) != ST_MN_BYPASS
)
136 clksel
= clksel
& (~CLK_SEL_MASK
);
137 clksel
= clksel
| ((MPUPLL_M
<< CLK_SEL_SHIFT
) | MPUPLL_N
);
138 writel(clksel
, &cmwkup
->clkseldpllmpu
);
140 div_m2
= div_m2
& ~CLK_DIV_MASK
;
141 div_m2
= div_m2
| MPUPLL_M2
;
142 writel(div_m2
, &cmwkup
->divm2dpllmpu
);
144 clkmode
= clkmode
| CLK_MODE_SEL
;
145 writel(clkmode
, &cmwkup
->clkmoddpllmpu
);
147 while (readl(&cmwkup
->idlestdpllmpu
) != ST_DPLL_CLK
)
151 static void core_pll_config(void)
153 u32 clkmode
, clksel
, div_m4
, div_m5
, div_m6
;
155 clkmode
= readl(&cmwkup
->clkmoddpllcore
);
156 clksel
= readl(&cmwkup
->clkseldpllcore
);
157 div_m4
= readl(&cmwkup
->divm4dpllcore
);
158 div_m5
= readl(&cmwkup
->divm5dpllcore
);
159 div_m6
= readl(&cmwkup
->divm6dpllcore
);
161 /* Set the PLL to bypass Mode */
162 writel(PLL_BYPASS_MODE
, &cmwkup
->clkmoddpllcore
);
164 while (readl(&cmwkup
->idlestdpllcore
) != ST_MN_BYPASS
)
167 clksel
= clksel
& (~CLK_SEL_MASK
);
168 clksel
= clksel
| ((COREPLL_M
<< CLK_SEL_SHIFT
) | COREPLL_N
);
169 writel(clksel
, &cmwkup
->clkseldpllcore
);
171 div_m4
= div_m4
& ~CLK_DIV_MASK
;
172 div_m4
= div_m4
| COREPLL_M4
;
173 writel(div_m4
, &cmwkup
->divm4dpllcore
);
175 div_m5
= div_m5
& ~CLK_DIV_MASK
;
176 div_m5
= div_m5
| COREPLL_M5
;
177 writel(div_m5
, &cmwkup
->divm5dpllcore
);
179 div_m6
= div_m6
& ~CLK_DIV_MASK
;
180 div_m6
= div_m6
| COREPLL_M6
;
181 writel(div_m6
, &cmwkup
->divm6dpllcore
);
183 clkmode
= clkmode
| CLK_MODE_SEL
;
184 writel(clkmode
, &cmwkup
->clkmoddpllcore
);
186 while (readl(&cmwkup
->idlestdpllcore
) != ST_DPLL_CLK
)
190 static void per_pll_config(void)
192 u32 clkmode
, clksel
, div_m2
;
194 clkmode
= readl(&cmwkup
->clkmoddpllper
);
195 clksel
= readl(&cmwkup
->clkseldpllper
);
196 div_m2
= readl(&cmwkup
->divm2dpllper
);
198 /* Set the PLL to bypass Mode */
199 writel(PLL_BYPASS_MODE
, &cmwkup
->clkmoddpllper
);
201 while (readl(&cmwkup
->idlestdpllper
) != ST_MN_BYPASS
)
204 clksel
= clksel
& (~CLK_SEL_MASK
);
205 clksel
= clksel
| ((PERPLL_M
<< CLK_SEL_SHIFT
) | PERPLL_N
);
206 writel(clksel
, &cmwkup
->clkseldpllper
);
208 div_m2
= div_m2
& ~CLK_DIV2_MASK
;
209 div_m2
= div_m2
| PERPLL_M2
;
210 writel(div_m2
, &cmwkup
->divm2dpllper
);
212 clkmode
= clkmode
| CLK_MODE_SEL
;
213 writel(clkmode
, &cmwkup
->clkmoddpllper
);
215 while (readl(&cmwkup
->idlestdpllper
) != ST_DPLL_CLK
)
219 static void ddr_pll_config(void)
221 u32 clkmode
, clksel
, div_m2
;
223 clkmode
= readl(&cmwkup
->clkmoddpllddr
);
224 clksel
= readl(&cmwkup
->clkseldpllddr
);
225 div_m2
= readl(&cmwkup
->divm2dpllddr
);
227 /* Set the PLL to bypass Mode */
228 clkmode
= (clkmode
& CLK_MODE_MASK
) | PLL_BYPASS_MODE
;
229 writel(clkmode
, &cmwkup
->clkmoddpllddr
);
231 /* Wait till bypass mode is enabled */
232 while ((readl(&cmwkup
->idlestdpllddr
) & ST_MN_BYPASS
)
236 clksel
= clksel
& (~CLK_SEL_MASK
);
237 clksel
= clksel
| ((DDRPLL_M
<< CLK_SEL_SHIFT
) | DDRPLL_N
);
238 writel(clksel
, &cmwkup
->clkseldpllddr
);
240 div_m2
= div_m2
& CLK_DIV_SEL
;
241 div_m2
= div_m2
| DDRPLL_M2
;
242 writel(div_m2
, &cmwkup
->divm2dpllddr
);
244 clkmode
= (clkmode
& CLK_MODE_MASK
) | CLK_MODE_SEL
;
245 writel(clkmode
, &cmwkup
->clkmoddpllddr
);
247 /* Wait till dpll is locked */
248 while ((readl(&cmwkup
->idlestdpllddr
) & ST_DPLL_CLK
) != ST_DPLL_CLK
)
252 void enable_emif_clocks(void)
254 /* Enable the EMIF_FW Functional clock */
255 writel(PRCM_MOD_EN
, &cmper
->emiffwclkctrl
);
256 /* Enable EMIF0 Clock */
257 writel(PRCM_MOD_EN
, &cmper
->emifclkctrl
);
258 /* Poll for emif_gclk & L3_G clock are active */
259 while ((readl(&cmper
->l3clkstctrl
) & (PRCM_EMIF_CLK_ACTIVITY
|
260 PRCM_L3_GCLK_ACTIVITY
)) != (PRCM_EMIF_CLK_ACTIVITY
|
261 PRCM_L3_GCLK_ACTIVITY
))
263 /* Poll if module is functional */
264 while ((readl(&cmper
->emifclkctrl
)) != PRCM_MOD_EN
)
269 * Configure the PLL/PRCM for necessary peripherals
278 /* Enable the required interconnect clocks */
279 enable_interface_clocks();
281 /* Power domain wake up transition */
282 power_domain_wkup_transition();
284 /* Enable the required peripherals */