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
27 #define PRCM_FUNCTL 0x0
29 #define PRCM_EMIF_CLK_ACTIVITY BIT(2)
30 #define PRCM_L3_GCLK_ACTIVITY BIT(4)
32 #define PLL_BYPASS_MODE 0x4
33 #define ST_MN_BYPASS 0x00000100
34 #define ST_DPLL_CLK 0x00000001
35 #define CLK_SEL_MASK 0x7ffff
36 #define CLK_DIV_MASK 0x1f
37 #define CLK_DIV2_MASK 0x7f
38 #define CLK_SEL_SHIFT 0x8
39 #define CLK_MODE_SEL 0x7
40 #define CLK_MODE_MASK 0xfffffff8
41 #define CLK_DIV_SEL 0xFFFFFFE0
42 #define CPGMAC0_IDLE 0x30000
43 #define DPLL_CLKDCOLDO_GATE_CTRL 0x300
45 const struct cm_perpll *cmper = (struct cm_perpll *)CM_PER;
46 const struct cm_wkuppll *cmwkup = (struct cm_wkuppll *)CM_WKUP;
47 const struct cm_dpll *cmdpll = (struct cm_dpll *)CM_DPLL;
48 const struct cm_rtc *cmrtc = (struct cm_rtc *)CM_RTC;
50 static void enable_interface_clocks(void)
52 /* Enable all the Interconnect Modules */
53 writel(PRCM_MOD_EN, &cmper->l3clkctrl);
54 while (readl(&cmper->l3clkctrl) != PRCM_MOD_EN)
57 writel(PRCM_MOD_EN, &cmper->l4lsclkctrl);
58 while (readl(&cmper->l4lsclkctrl) != PRCM_MOD_EN)
61 writel(PRCM_MOD_EN, &cmper->l4fwclkctrl);
62 while (readl(&cmper->l4fwclkctrl) != PRCM_MOD_EN)
65 writel(PRCM_MOD_EN, &cmwkup->wkl4wkclkctrl);
66 while (readl(&cmwkup->wkl4wkclkctrl) != PRCM_MOD_EN)
69 writel(PRCM_MOD_EN, &cmper->l3instrclkctrl);
70 while (readl(&cmper->l3instrclkctrl) != PRCM_MOD_EN)
73 writel(PRCM_MOD_EN, &cmper->l4hsclkctrl);
74 while (readl(&cmper->l4hsclkctrl) != PRCM_MOD_EN)
77 writel(PRCM_MOD_EN, &cmwkup->wkgpio0clkctrl);
78 while (readl(&cmwkup->wkgpio0clkctrl) != PRCM_MOD_EN)
83 * Force power domain wake up transition
84 * Ensure that the corresponding interface clock is active before
85 * using the peripheral
87 static void power_domain_wkup_transition(void)
89 writel(PRCM_FORCE_WAKEUP, &cmper->l3clkstctrl);
90 writel(PRCM_FORCE_WAKEUP, &cmper->l4lsclkstctrl);
91 writel(PRCM_FORCE_WAKEUP, &cmwkup->wkclkstctrl);
92 writel(PRCM_FORCE_WAKEUP, &cmper->l4fwclkstctrl);
93 writel(PRCM_FORCE_WAKEUP, &cmper->l3sclkstctrl);
97 * Enable the peripheral clock for required peripherals
99 static void enable_per_clocks(void)
101 /* Enable the control module though RBL would have done it*/
102 writel(PRCM_MOD_EN, &cmwkup->wkctrlclkctrl);
103 while (readl(&cmwkup->wkctrlclkctrl) != PRCM_MOD_EN)
106 /* Enable the module clock */
107 writel(PRCM_MOD_EN, &cmper->timer2clkctrl);
108 while (readl(&cmper->timer2clkctrl) != PRCM_MOD_EN)
111 /* Select the Master osc 24 MHZ as Timer2 clock source */
112 writel(0x1, &cmdpll->clktimer2clk);
115 writel(PRCM_MOD_EN, &cmwkup->wkup_uart0ctrl);
116 while (readl(&cmwkup->wkup_uart0ctrl) != PRCM_MOD_EN)
120 #ifdef CONFIG_SERIAL2
121 writel(PRCM_MOD_EN, &cmper->uart1clkctrl);
122 while (readl(&cmper->uart1clkctrl) != PRCM_MOD_EN)
124 #endif /* CONFIG_SERIAL2 */
127 #ifdef CONFIG_SERIAL3
128 writel(PRCM_MOD_EN, &cmper->uart2clkctrl);
129 while (readl(&cmper->uart2clkctrl) != PRCM_MOD_EN)
131 #endif /* CONFIG_SERIAL3 */
134 #ifdef CONFIG_SERIAL4
135 writel(PRCM_MOD_EN, &cmper->uart3clkctrl);
136 while (readl(&cmper->uart3clkctrl) != PRCM_MOD_EN)
138 #endif /* CONFIG_SERIAL4 */
141 #ifdef CONFIG_SERIAL5
142 writel(PRCM_MOD_EN, &cmper->uart4clkctrl);
143 while (readl(&cmper->uart4clkctrl) != PRCM_MOD_EN)
145 #endif /* CONFIG_SERIAL5 */
148 #ifdef CONFIG_SERIAL6
149 writel(PRCM_MOD_EN, &cmper->uart5clkctrl);
150 while (readl(&cmper->uart5clkctrl) != PRCM_MOD_EN)
152 #endif /* CONFIG_SERIAL6 */
155 writel(PRCM_MOD_EN, &cmper->mmc0clkctrl);
156 while (readl(&cmper->mmc0clkctrl) != PRCM_MOD_EN)
160 writel(PRCM_MOD_EN, &cmwkup->wkup_i2c0ctrl);
161 while (readl(&cmwkup->wkup_i2c0ctrl) != PRCM_MOD_EN)
165 writel(PRCM_MOD_EN, &cmper->gpio1clkctrl);
166 while (readl(&cmper->gpio1clkctrl) != PRCM_MOD_EN)
170 writel(PRCM_MOD_EN, &cmper->gpio2clkctrl);
171 while (readl(&cmper->gpio2clkctrl) != PRCM_MOD_EN)
175 writel(PRCM_MOD_EN, &cmper->gpio3clkctrl);
176 while (readl(&cmper->gpio3clkctrl) != PRCM_MOD_EN)
180 writel(PRCM_MOD_EN, &cmper->i2c1clkctrl);
181 while (readl(&cmper->i2c1clkctrl) != PRCM_MOD_EN)
185 writel(PRCM_MOD_EN, &cmper->cpgmac0clkctrl);
186 while ((readl(&cmper->cpgmac0clkctrl) & CPGMAC0_IDLE) != PRCM_FUNCTL)
190 writel(PRCM_MOD_EN, &cmper->spi0clkctrl);
191 while (readl(&cmper->spi0clkctrl) != PRCM_MOD_EN)
195 writel(PRCM_MOD_EN, &cmrtc->rtcclkctrl);
196 while (readl(&cmrtc->rtcclkctrl) != PRCM_MOD_EN)
200 writel(PRCM_MOD_EN, &cmper->usb0clkctrl);
201 while (readl(&cmper->usb0clkctrl) != PRCM_MOD_EN)
205 static void mpu_pll_config(void)
207 u32 clkmode, clksel, div_m2;
209 clkmode = readl(&cmwkup->clkmoddpllmpu);
210 clksel = readl(&cmwkup->clkseldpllmpu);
211 div_m2 = readl(&cmwkup->divm2dpllmpu);
213 /* Set the PLL to bypass Mode */
214 writel(PLL_BYPASS_MODE, &cmwkup->clkmoddpllmpu);
215 while (readl(&cmwkup->idlestdpllmpu) != ST_MN_BYPASS)
218 clksel = clksel & (~CLK_SEL_MASK);
219 clksel = clksel | ((MPUPLL_M << CLK_SEL_SHIFT) | MPUPLL_N);
220 writel(clksel, &cmwkup->clkseldpllmpu);
222 div_m2 = div_m2 & ~CLK_DIV_MASK;
223 div_m2 = div_m2 | MPUPLL_M2;
224 writel(div_m2, &cmwkup->divm2dpllmpu);
226 clkmode = clkmode | CLK_MODE_SEL;
227 writel(clkmode, &cmwkup->clkmoddpllmpu);
229 while (readl(&cmwkup->idlestdpllmpu) != ST_DPLL_CLK)
233 static void core_pll_config(void)
235 u32 clkmode, clksel, div_m4, div_m5, div_m6;
237 clkmode = readl(&cmwkup->clkmoddpllcore);
238 clksel = readl(&cmwkup->clkseldpllcore);
239 div_m4 = readl(&cmwkup->divm4dpllcore);
240 div_m5 = readl(&cmwkup->divm5dpllcore);
241 div_m6 = readl(&cmwkup->divm6dpllcore);
243 /* Set the PLL to bypass Mode */
244 writel(PLL_BYPASS_MODE, &cmwkup->clkmoddpllcore);
246 while (readl(&cmwkup->idlestdpllcore) != ST_MN_BYPASS)
249 clksel = clksel & (~CLK_SEL_MASK);
250 clksel = clksel | ((COREPLL_M << CLK_SEL_SHIFT) | COREPLL_N);
251 writel(clksel, &cmwkup->clkseldpllcore);
253 div_m4 = div_m4 & ~CLK_DIV_MASK;
254 div_m4 = div_m4 | COREPLL_M4;
255 writel(div_m4, &cmwkup->divm4dpllcore);
257 div_m5 = div_m5 & ~CLK_DIV_MASK;
258 div_m5 = div_m5 | COREPLL_M5;
259 writel(div_m5, &cmwkup->divm5dpllcore);
261 div_m6 = div_m6 & ~CLK_DIV_MASK;
262 div_m6 = div_m6 | COREPLL_M6;
263 writel(div_m6, &cmwkup->divm6dpllcore);
265 clkmode = clkmode | CLK_MODE_SEL;
266 writel(clkmode, &cmwkup->clkmoddpllcore);
268 while (readl(&cmwkup->idlestdpllcore) != ST_DPLL_CLK)
272 static void per_pll_config(void)
274 u32 clkmode, clksel, div_m2;
276 clkmode = readl(&cmwkup->clkmoddpllper);
277 clksel = readl(&cmwkup->clkseldpllper);
278 div_m2 = readl(&cmwkup->divm2dpllper);
280 /* Set the PLL to bypass Mode */
281 writel(PLL_BYPASS_MODE, &cmwkup->clkmoddpllper);
283 while (readl(&cmwkup->idlestdpllper) != ST_MN_BYPASS)
286 clksel = clksel & (~CLK_SEL_MASK);
287 clksel = clksel | ((PERPLL_M << CLK_SEL_SHIFT) | PERPLL_N);
288 writel(clksel, &cmwkup->clkseldpllper);
290 div_m2 = div_m2 & ~CLK_DIV2_MASK;
291 div_m2 = div_m2 | PERPLL_M2;
292 writel(div_m2, &cmwkup->divm2dpllper);
294 clkmode = clkmode | CLK_MODE_SEL;
295 writel(clkmode, &cmwkup->clkmoddpllper);
297 while (readl(&cmwkup->idlestdpllper) != ST_DPLL_CLK)
300 writel(DPLL_CLKDCOLDO_GATE_CTRL, &cmwkup->clkdcoldodpllper);
303 void ddr_pll_config(unsigned int ddrpll_m)
305 u32 clkmode, clksel, div_m2;
307 clkmode = readl(&cmwkup->clkmoddpllddr);
308 clksel = readl(&cmwkup->clkseldpllddr);
309 div_m2 = readl(&cmwkup->divm2dpllddr);
311 /* Set the PLL to bypass Mode */
312 clkmode = (clkmode & CLK_MODE_MASK) | PLL_BYPASS_MODE;
313 writel(clkmode, &cmwkup->clkmoddpllddr);
315 /* Wait till bypass mode is enabled */
316 while ((readl(&cmwkup->idlestdpllddr) & ST_MN_BYPASS)
320 clksel = clksel & (~CLK_SEL_MASK);
321 clksel = clksel | ((ddrpll_m << CLK_SEL_SHIFT) | DDRPLL_N);
322 writel(clksel, &cmwkup->clkseldpllddr);
324 div_m2 = div_m2 & CLK_DIV_SEL;
325 div_m2 = div_m2 | DDRPLL_M2;
326 writel(div_m2, &cmwkup->divm2dpllddr);
328 clkmode = (clkmode & CLK_MODE_MASK) | CLK_MODE_SEL;
329 writel(clkmode, &cmwkup->clkmoddpllddr);
331 /* Wait till dpll is locked */
332 while ((readl(&cmwkup->idlestdpllddr) & ST_DPLL_CLK) != ST_DPLL_CLK)
336 void enable_emif_clocks(void)
338 /* Enable the EMIF_FW Functional clock */
339 writel(PRCM_MOD_EN, &cmper->emiffwclkctrl);
340 /* Enable EMIF0 Clock */
341 writel(PRCM_MOD_EN, &cmper->emifclkctrl);
342 /* Poll if module is functional */
343 while ((readl(&cmper->emifclkctrl)) != PRCM_MOD_EN)
348 * Configure the PLL/PRCM for necessary peripherals
356 /* Enable the required interconnect clocks */
357 enable_interface_clocks();
359 /* Power domain wake up transition */
360 power_domain_wkup_transition();
362 /* Enable the required peripherals */