blob: c02d73cd8ac139f930ed43d4e69571b8dba496f8 [file] [log] [blame]
Aneesh V0d2628b2011-07-21 09:10:07 -04001/*
2 *
3 * Clock initialization for OMAP4
4 *
5 * (C) Copyright 2010
6 * Texas Instruments, <www.ti.com>
7 *
8 * Aneesh V <aneesh@ti.com>
9 *
10 * Based on previous work by:
11 * Santosh Shilimkar <santosh.shilimkar@ti.com>
12 * Rajendra Nayak <rnayak@ti.com>
13 *
14 * See file CREDITS for list of people who contributed to this
15 * project.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * MA 02111-1307 USA
31 */
32#include <common.h>
33#include <asm/omap_common.h>
Sanjeev Premi0c2c8ac2011-09-08 10:48:39 -040034#include <asm/gpio.h>
Aneesh V0d2628b2011-07-21 09:10:07 -040035#include <asm/arch/clocks.h>
36#include <asm/arch/sys_proto.h>
37#include <asm/utils.h>
Aneesh V0fa1d1b2011-07-21 09:29:32 -040038#include <asm/omap_gpio.h>
Aneesh V0d2628b2011-07-21 09:10:07 -040039
40#ifndef CONFIG_SPL_BUILD
41/*
42 * printing to console doesn't work unless
43 * this code is executed from SPL
44 */
45#define printf(fmt, args...)
46#define puts(s)
47#endif
48
Aneesh V0d2628b2011-07-21 09:10:07 -040049static inline u32 __get_sys_clk_index(void)
50{
51 u32 ind;
52 /*
53 * For ES1 the ROM code calibration of sys clock is not reliable
54 * due to hw issue. So, use hard-coded value. If this value is not
55 * correct for any board over-ride this function in board file
56 * From ES2.0 onwards you will get this information from
57 * CM_SYS_CLKSEL
58 */
59 if (omap_revision() == OMAP4430_ES1_0)
60 ind = OMAP_SYS_CLK_IND_38_4_MHZ;
61 else {
62 /* SYS_CLKSEL - 1 to match the dpll param array indices */
63 ind = (readl(&prcm->cm_sys_clksel) &
64 CM_SYS_CLKSEL_SYS_CLKSEL_MASK) - 1;
65 }
66 return ind;
67}
68
69u32 get_sys_clk_index(void)
70 __attribute__ ((weak, alias("__get_sys_clk_index")));
71
72u32 get_sys_clk_freq(void)
73{
74 u8 index = get_sys_clk_index();
75 return sys_clk_array[index];
76}
77
78static inline void do_bypass_dpll(u32 *const base)
79{
80 struct dpll_regs *dpll_regs = (struct dpll_regs *)base;
81
82 clrsetbits_le32(&dpll_regs->cm_clkmode_dpll,
83 CM_CLKMODE_DPLL_DPLL_EN_MASK,
84 DPLL_EN_FAST_RELOCK_BYPASS <<
85 CM_CLKMODE_DPLL_EN_SHIFT);
86}
87
88static inline void wait_for_bypass(u32 *const base)
89{
90 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
91
92 if (!wait_on_value(ST_DPLL_CLK_MASK, 0, &dpll_regs->cm_idlest_dpll,
93 LDELAY)) {
94 printf("Bypassing DPLL failed %p\n", base);
95 }
96}
97
98static inline void do_lock_dpll(u32 *const base)
99{
100 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
101
102 clrsetbits_le32(&dpll_regs->cm_clkmode_dpll,
103 CM_CLKMODE_DPLL_DPLL_EN_MASK,
104 DPLL_EN_LOCK << CM_CLKMODE_DPLL_EN_SHIFT);
105}
106
107static inline void wait_for_lock(u32 *const base)
108{
109 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
110
111 if (!wait_on_value(ST_DPLL_CLK_MASK, ST_DPLL_CLK_MASK,
112 &dpll_regs->cm_idlest_dpll, LDELAY)) {
113 printf("DPLL locking failed for %p\n", base);
114 hang();
115 }
116}
117
Sricharan308fe922011-11-15 09:50:03 -0500118inline u32 check_for_lock(u32 *const base)
119{
120 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
121 u32 lock = readl(&dpll_regs->cm_idlest_dpll) & ST_DPLL_CLK_MASK;
122
123 return lock;
124}
125
Aneesh V0d2628b2011-07-21 09:10:07 -0400126static void do_setup_dpll(u32 *const base, const struct dpll_params *params,
Sricharan308fe922011-11-15 09:50:03 -0500127 u8 lock, char *dpll)
Aneesh V0d2628b2011-07-21 09:10:07 -0400128{
Sricharan308fe922011-11-15 09:50:03 -0500129 u32 temp, M, N;
Aneesh V0d2628b2011-07-21 09:10:07 -0400130 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
131
Sricharan308fe922011-11-15 09:50:03 -0500132 temp = readl(&dpll_regs->cm_clksel_dpll);
133
134 if (check_for_lock(base)) {
135 /*
136 * The Dpll has already been locked by rom code using CH.
137 * Check if M,N are matching with Ideal nominal opp values.
138 * If matches, skip the rest otherwise relock.
139 */
140 M = (temp & CM_CLKSEL_DPLL_M_MASK) >> CM_CLKSEL_DPLL_M_SHIFT;
141 N = (temp & CM_CLKSEL_DPLL_N_MASK) >> CM_CLKSEL_DPLL_N_SHIFT;
142 if ((M != (params->m)) || (N != (params->n))) {
143 debug("\n %s Dpll locked, but not for ideal M = %d,"
144 "N = %d values, current values are M = %d,"
145 "N= %d" , dpll, params->m, params->n,
146 M, N);
147 } else {
148 /* Dpll locked with ideal values for nominal opps. */
149 debug("\n %s Dpll already locked with ideal"
150 "nominal opp values", dpll);
151 goto setup_post_dividers;
152 }
153 }
154
Aneesh V0d2628b2011-07-21 09:10:07 -0400155 bypass_dpll(base);
156
157 /* Set M & N */
Aneesh V0d2628b2011-07-21 09:10:07 -0400158 temp &= ~CM_CLKSEL_DPLL_M_MASK;
159 temp |= (params->m << CM_CLKSEL_DPLL_M_SHIFT) & CM_CLKSEL_DPLL_M_MASK;
160
161 temp &= ~CM_CLKSEL_DPLL_N_MASK;
162 temp |= (params->n << CM_CLKSEL_DPLL_N_SHIFT) & CM_CLKSEL_DPLL_N_MASK;
163
164 writel(temp, &dpll_regs->cm_clksel_dpll);
165
166 /* Lock */
167 if (lock)
168 do_lock_dpll(base);
169
Sricharan308fe922011-11-15 09:50:03 -0500170setup_post_dividers:
Sricharan9784f1f2011-11-15 09:49:58 -0500171 setup_post_dividers(base, params);
Aneesh V0d2628b2011-07-21 09:10:07 -0400172
173 /* Wait till the DPLL locks */
174 if (lock)
175 wait_for_lock(base);
176}
177
Sricharan9784f1f2011-11-15 09:49:58 -0500178u32 omap_ddr_clk(void)
Aneesh V0d2628b2011-07-21 09:10:07 -0400179{
Sricharan9784f1f2011-11-15 09:49:58 -0500180 u32 ddr_clk, sys_clk_khz, omap_rev, divider;
Aneesh V0d2628b2011-07-21 09:10:07 -0400181 const struct dpll_params *core_dpll_params;
182
Sricharan9784f1f2011-11-15 09:49:58 -0500183 omap_rev = omap_revision();
Aneesh V0d2628b2011-07-21 09:10:07 -0400184 sys_clk_khz = get_sys_clk_freq() / 1000;
185
186 core_dpll_params = get_core_dpll_params();
187
188 debug("sys_clk %d\n ", sys_clk_khz * 1000);
189
190 /* Find Core DPLL locked frequency first */
191 ddr_clk = sys_clk_khz * 2 * core_dpll_params->m /
192 (core_dpll_params->n + 1);
Sricharan9784f1f2011-11-15 09:49:58 -0500193
194 if (omap_rev < OMAP5430_ES1_0) {
195 /*
196 * DDR frequency is PHY_ROOT_CLK/2
197 * PHY_ROOT_CLK = Fdpll/2/M2
198 */
199 divider = 4;
200 } else {
201 /*
202 * DDR frequency is PHY_ROOT_CLK
203 * PHY_ROOT_CLK = Fdpll/2/M2
204 */
205 divider = 2;
206 }
Aneesh V0d2628b2011-07-21 09:10:07 -0400207
Sricharan9784f1f2011-11-15 09:49:58 -0500208 ddr_clk = ddr_clk / divider / core_dpll_params->m2;
Aneesh V0d2628b2011-07-21 09:10:07 -0400209 ddr_clk *= 1000; /* convert to Hz */
210 debug("ddr_clk %d\n ", ddr_clk);
211
212 return ddr_clk;
213}
214
Aneesh Va47a79f2011-07-21 09:29:36 -0400215/*
216 * Lock MPU dpll
217 *
218 * Resulting MPU frequencies:
219 * 4430 ES1.0 : 600 MHz
220 * 4430 ES2.x : 792 MHz (OPP Turbo)
221 * 4460 : 920 MHz (OPP Turbo) - DCC disabled
222 */
223void configure_mpu_dpll(void)
224{
225 const struct dpll_params *params;
226 struct dpll_regs *mpu_dpll_regs;
Sricharan9784f1f2011-11-15 09:49:58 -0500227 u32 omap_rev;
228 omap_rev = omap_revision();
Aneesh Va47a79f2011-07-21 09:29:36 -0400229
Sricharan9784f1f2011-11-15 09:49:58 -0500230 /*
231 * DCC and clock divider settings for 4460.
232 * DCC is required, if more than a certain frequency is required.
233 * For, 4460 > 1GHZ.
234 * 5430 > 1.4GHZ.
235 */
236 if ((omap_rev >= OMAP4460_ES1_0) && (omap_rev < OMAP5430_ES1_0)) {
Aneesh Va47a79f2011-07-21 09:29:36 -0400237 mpu_dpll_regs =
238 (struct dpll_regs *)&prcm->cm_clkmode_dpll_mpu;
239 bypass_dpll(&prcm->cm_clkmode_dpll_mpu);
240 clrbits_le32(&prcm->cm_mpu_mpu_clkctrl,
241 MPU_CLKCTRL_CLKSEL_EMIF_DIV_MODE_MASK);
242 setbits_le32(&prcm->cm_mpu_mpu_clkctrl,
243 MPU_CLKCTRL_CLKSEL_ABE_DIV_MODE_MASK);
244 clrbits_le32(&mpu_dpll_regs->cm_clksel_dpll,
245 CM_CLKSEL_DCC_EN_MASK);
246 }
247
Sricharan9784f1f2011-11-15 09:49:58 -0500248 params = get_mpu_dpll_params();
Sricharan308fe922011-11-15 09:50:03 -0500249
250 do_setup_dpll(&prcm->cm_clkmode_dpll_mpu, params, DPLL_LOCK, "mpu");
Aneesh Va47a79f2011-07-21 09:29:36 -0400251 debug("MPU DPLL locked\n");
252}
253
Govindraj.Rad4426b2012-02-06 03:55:36 +0000254#ifdef CONFIG_USB_EHCI_OMAP
255static void setup_usb_dpll(void)
256{
257 const struct dpll_params *params;
258 u32 sys_clk_khz, sd_div, num, den;
259
260 sys_clk_khz = get_sys_clk_freq() / 1000;
261 /*
262 * USB:
263 * USB dpll is J-type. Need to set DPLL_SD_DIV for jitter correction
264 * DPLL_SD_DIV = CEILING ([DPLL_MULT/(DPLL_DIV+1)]* CLKINP / 250)
265 * - where CLKINP is sys_clk in MHz
266 * Use CLKINP in KHz and adjust the denominator accordingly so
267 * that we have enough accuracy and at the same time no overflow
268 */
269 params = get_usb_dpll_params();
270 num = params->m * sys_clk_khz;
271 den = (params->n + 1) * 250 * 1000;
272 num += den - 1;
273 sd_div = num / den;
274 clrsetbits_le32(&prcm->cm_clksel_dpll_usb,
275 CM_CLKSEL_DPLL_DPLL_SD_DIV_MASK,
276 sd_div << CM_CLKSEL_DPLL_DPLL_SD_DIV_SHIFT);
277
278 /* Now setup the dpll with the regular function */
279 do_setup_dpll(&prcm->cm_clkmode_dpll_usb, params, DPLL_LOCK, "usb");
280}
281#endif
282
Aneesh V0d2628b2011-07-21 09:10:07 -0400283static void setup_dplls(void)
284{
Anatolij Gustschin20f23512011-12-03 06:46:14 +0000285 u32 temp;
Aneesh V0d2628b2011-07-21 09:10:07 -0400286 const struct dpll_params *params;
Aneesh V0d2628b2011-07-21 09:10:07 -0400287
Anatolij Gustschin20f23512011-12-03 06:46:14 +0000288 debug("setup_dplls\n");
Aneesh V0d2628b2011-07-21 09:10:07 -0400289
290 /* CORE dpll */
291 params = get_core_dpll_params(); /* default - safest */
292 /*
293 * Do not lock the core DPLL now. Just set it up.
294 * Core DPLL will be locked after setting up EMIF
295 * using the FREQ_UPDATE method(freq_update_core())
296 */
Sricharan308fe922011-11-15 09:50:03 -0500297 do_setup_dpll(&prcm->cm_clkmode_dpll_core, params, DPLL_NO_LOCK,
298 "core");
Aneesh V0d2628b2011-07-21 09:10:07 -0400299 /* Set the ratios for CORE_CLK, L3_CLK, L4_CLK */
300 temp = (CLKSEL_CORE_X2_DIV_1 << CLKSEL_CORE_SHIFT) |
301 (CLKSEL_L3_CORE_DIV_2 << CLKSEL_L3_SHIFT) |
302 (CLKSEL_L4_L3_DIV_2 << CLKSEL_L4_SHIFT);
303 writel(temp, &prcm->cm_clksel_core);
304 debug("Core DPLL configured\n");
305
306 /* lock PER dpll */
Sricharan9784f1f2011-11-15 09:49:58 -0500307 params = get_per_dpll_params();
Aneesh V0d2628b2011-07-21 09:10:07 -0400308 do_setup_dpll(&prcm->cm_clkmode_dpll_per,
Sricharan308fe922011-11-15 09:50:03 -0500309 params, DPLL_LOCK, "per");
Aneesh V0d2628b2011-07-21 09:10:07 -0400310 debug("PER DPLL locked\n");
311
312 /* MPU dpll */
Aneesh Va47a79f2011-07-21 09:29:36 -0400313 configure_mpu_dpll();
Govindraj.Rad4426b2012-02-06 03:55:36 +0000314
315#ifdef CONFIG_USB_EHCI_OMAP
316 setup_usb_dpll();
317#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400318}
319
Sricharan308fe922011-11-15 09:50:03 -0500320#ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL
Aneesh V0d2628b2011-07-21 09:10:07 -0400321static void setup_non_essential_dplls(void)
322{
Anatolij Gustschind75ffd42012-03-27 23:13:43 +0000323 u32 abe_ref_clk;
Aneesh V0d2628b2011-07-21 09:10:07 -0400324 const struct dpll_params *params;
325
Aneesh V0d2628b2011-07-21 09:10:07 -0400326 /* IVA */
327 clrsetbits_le32(&prcm->cm_bypclk_dpll_iva,
328 CM_BYPCLK_DPLL_IVA_CLKSEL_MASK, DPLL_IVA_CLKSEL_CORE_X2_DIV_2);
329
Sricharan9784f1f2011-11-15 09:49:58 -0500330 params = get_iva_dpll_params();
Sricharan308fe922011-11-15 09:50:03 -0500331 do_setup_dpll(&prcm->cm_clkmode_dpll_iva, params, DPLL_LOCK, "iva");
Aneesh V0d2628b2011-07-21 09:10:07 -0400332
Sricharan9784f1f2011-11-15 09:49:58 -0500333 /* Configure ABE dpll */
334 params = get_abe_dpll_params();
335#ifdef CONFIG_SYS_OMAP_ABE_SYSCK
Aneesh V0d2628b2011-07-21 09:10:07 -0400336 abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_SYSCLK;
337#else
Aneesh V0d2628b2011-07-21 09:10:07 -0400338 abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_32KCLK;
339 /*
340 * We need to enable some additional options to achieve
341 * 196.608MHz from 32768 Hz
342 */
343 setbits_le32(&prcm->cm_clkmode_dpll_abe,
344 CM_CLKMODE_DPLL_DRIFTGUARD_EN_MASK|
345 CM_CLKMODE_DPLL_RELOCK_RAMP_EN_MASK|
346 CM_CLKMODE_DPLL_LPMODE_EN_MASK|
347 CM_CLKMODE_DPLL_REGM4XEN_MASK);
348 /* Spend 4 REFCLK cycles at each stage */
349 clrsetbits_le32(&prcm->cm_clkmode_dpll_abe,
350 CM_CLKMODE_DPLL_RAMP_RATE_MASK,
351 1 << CM_CLKMODE_DPLL_RAMP_RATE_SHIFT);
352#endif
353
354 /* Select the right reference clk */
355 clrsetbits_le32(&prcm->cm_abe_pll_ref_clksel,
356 CM_ABE_PLL_REF_CLKSEL_CLKSEL_MASK,
357 abe_ref_clk << CM_ABE_PLL_REF_CLKSEL_CLKSEL_SHIFT);
358 /* Lock the dpll */
Sricharan308fe922011-11-15 09:50:03 -0500359 do_setup_dpll(&prcm->cm_clkmode_dpll_abe, params, DPLL_LOCK, "abe");
Aneesh V0d2628b2011-07-21 09:10:07 -0400360}
Sricharan308fe922011-11-15 09:50:03 -0500361#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400362
Nishanth Menona0f45c12012-03-01 14:17:38 +0000363void do_scale_tps62361(int gpio, u32 reg, u32 volt_mv)
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400364{
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000365 u32 step;
Nishanth Menona0f45c12012-03-01 14:17:38 +0000366 int ret = 0;
367
368 /* See if we can first get the GPIO if needed */
369 if (gpio >= 0)
370 ret = gpio_request(gpio, "TPS62361_VSEL0_GPIO");
371 if (ret < 0) {
372 printf("%s: gpio %d request failed %d\n", __func__, gpio, ret);
373 gpio = -1;
374 }
375
376 /* Pull the GPIO low to select SET0 register, while we program SET1 */
377 if (gpio >= 0)
378 gpio_direction_output(gpio, 0);
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400379
380 step = volt_mv - TPS62361_BASE_VOLT_MV;
381 step /= 10;
382
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400383 debug("do_scale_tps62361: volt - %d step - 0x%x\n", volt_mv, step);
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000384 if (omap_vc_bypass_send_value(TPS62361_I2C_SLAVE_ADDR, reg, step))
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400385 puts("Scaling voltage failed for vdd_mpu from TPS\n");
Nishanth Menona0f45c12012-03-01 14:17:38 +0000386
387 /* Pull the GPIO high to select SET1 register */
388 if (gpio >= 0)
389 gpio_direction_output(gpio, 1);
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400390}
391
Sricharan9784f1f2011-11-15 09:49:58 -0500392void do_scale_vcore(u32 vcore_reg, u32 volt_mv)
Aneesh V0d2628b2011-07-21 09:10:07 -0400393{
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000394 u32 offset_code;
Aneesh V0d2628b2011-07-21 09:10:07 -0400395 u32 step = 12660; /* 12.66 mV represented in uV */
396 u32 offset = volt_mv;
397
398 /* convert to uV for better accuracy in the calculations */
399 offset *= 1000;
400
401 if (omap_revision() == OMAP4430_ES1_0)
402 offset -= PHOENIX_SMPS_BASE_VOLT_STD_MODE_UV;
403 else
404 offset -= PHOENIX_SMPS_BASE_VOLT_STD_MODE_WITH_OFFSET_UV;
405
406 offset_code = (offset + step - 1) / step;
407 /* The code starts at 1 not 0 */
408 offset_code++;
409
410 debug("do_scale_vcore: volt - %d offset_code - 0x%x\n", volt_mv,
411 offset_code);
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000412 if (omap_vc_bypass_send_value(SMPS_I2C_SLAVE_ADDR,
413 vcore_reg, offset_code))
Aneesh V0d2628b2011-07-21 09:10:07 -0400414 printf("Scaling voltage failed for 0x%x\n", vcore_reg);
Aneesh V0d2628b2011-07-21 09:10:07 -0400415}
416
Aneesh V0d2628b2011-07-21 09:10:07 -0400417static inline void enable_clock_domain(u32 *const clkctrl_reg, u32 enable_mode)
418{
419 clrsetbits_le32(clkctrl_reg, CD_CLKCTRL_CLKTRCTRL_MASK,
420 enable_mode << CD_CLKCTRL_CLKTRCTRL_SHIFT);
Marek Vasutcff84342011-10-24 23:41:40 +0000421 debug("Enable clock domain - %p\n", clkctrl_reg);
Aneesh V0d2628b2011-07-21 09:10:07 -0400422}
423
424static inline void wait_for_clk_enable(u32 *clkctrl_addr)
425{
426 u32 clkctrl, idlest = MODULE_CLKCTRL_IDLEST_DISABLED;
427 u32 bound = LDELAY;
428
429 while ((idlest == MODULE_CLKCTRL_IDLEST_DISABLED) ||
430 (idlest == MODULE_CLKCTRL_IDLEST_TRANSITIONING)) {
431
432 clkctrl = readl(clkctrl_addr);
433 idlest = (clkctrl & MODULE_CLKCTRL_IDLEST_MASK) >>
434 MODULE_CLKCTRL_IDLEST_SHIFT;
435 if (--bound == 0) {
436 printf("Clock enable failed for 0x%p idlest 0x%x\n",
437 clkctrl_addr, clkctrl);
438 return;
439 }
440 }
441}
442
443static inline void enable_clock_module(u32 *const clkctrl_addr, u32 enable_mode,
444 u32 wait_for_enable)
445{
446 clrsetbits_le32(clkctrl_addr, MODULE_CLKCTRL_MODULEMODE_MASK,
447 enable_mode << MODULE_CLKCTRL_MODULEMODE_SHIFT);
Marek Vasutcff84342011-10-24 23:41:40 +0000448 debug("Enable clock module - %p\n", clkctrl_addr);
Aneesh V0d2628b2011-07-21 09:10:07 -0400449 if (wait_for_enable)
450 wait_for_clk_enable(clkctrl_addr);
451}
452
Aneesh V0d2628b2011-07-21 09:10:07 -0400453void freq_update_core(void)
454{
455 u32 freq_config1 = 0;
456 const struct dpll_params *core_dpll_params;
457
458 core_dpll_params = get_core_dpll_params();
459 /* Put EMIF clock domain in sw wakeup mode */
460 enable_clock_domain(&prcm->cm_memif_clkstctrl,
461 CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
462 wait_for_clk_enable(&prcm->cm_memif_emif_1_clkctrl);
463 wait_for_clk_enable(&prcm->cm_memif_emif_2_clkctrl);
464
465 freq_config1 = SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK |
466 SHADOW_FREQ_CONFIG1_DLL_RESET_MASK;
467
468 freq_config1 |= (DPLL_EN_LOCK << SHADOW_FREQ_CONFIG1_DPLL_EN_SHIFT) &
469 SHADOW_FREQ_CONFIG1_DPLL_EN_MASK;
470
471 freq_config1 |= (core_dpll_params->m2 <<
472 SHADOW_FREQ_CONFIG1_M2_DIV_SHIFT) &
473 SHADOW_FREQ_CONFIG1_M2_DIV_MASK;
474
475 writel(freq_config1, &prcm->cm_shadow_freq_config1);
476 if (!wait_on_value(SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK, 0,
477 &prcm->cm_shadow_freq_config1, LDELAY)) {
478 puts("FREQ UPDATE procedure failed!!");
479 hang();
480 }
481
482 /* Put EMIF clock domain back in hw auto mode */
483 enable_clock_domain(&prcm->cm_memif_clkstctrl,
484 CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
485 wait_for_clk_enable(&prcm->cm_memif_emif_1_clkctrl);
486 wait_for_clk_enable(&prcm->cm_memif_emif_2_clkctrl);
487}
488
489void bypass_dpll(u32 *const base)
490{
491 do_bypass_dpll(base);
492 wait_for_bypass(base);
493}
494
495void lock_dpll(u32 *const base)
496{
497 do_lock_dpll(base);
498 wait_for_lock(base);
499}
500
Aneesh Vb8e60b92011-07-21 09:10:21 -0400501void setup_clocks_for_console(void)
502{
503 /* Do not add any spl_debug prints in this function */
504 clrsetbits_le32(&prcm->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK,
505 CD_CLKCTRL_CLKTRCTRL_SW_WKUP <<
506 CD_CLKCTRL_CLKTRCTRL_SHIFT);
507
508 /* Enable all UARTs - console will be on one of them */
509 clrsetbits_le32(&prcm->cm_l4per_uart1_clkctrl,
510 MODULE_CLKCTRL_MODULEMODE_MASK,
511 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
512 MODULE_CLKCTRL_MODULEMODE_SHIFT);
513
514 clrsetbits_le32(&prcm->cm_l4per_uart2_clkctrl,
515 MODULE_CLKCTRL_MODULEMODE_MASK,
516 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
517 MODULE_CLKCTRL_MODULEMODE_SHIFT);
518
519 clrsetbits_le32(&prcm->cm_l4per_uart3_clkctrl,
520 MODULE_CLKCTRL_MODULEMODE_MASK,
521 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
522 MODULE_CLKCTRL_MODULEMODE_SHIFT);
523
524 clrsetbits_le32(&prcm->cm_l4per_uart3_clkctrl,
525 MODULE_CLKCTRL_MODULEMODE_MASK,
526 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
527 MODULE_CLKCTRL_MODULEMODE_SHIFT);
528
529 clrsetbits_le32(&prcm->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK,
530 CD_CLKCTRL_CLKTRCTRL_HW_AUTO <<
531 CD_CLKCTRL_CLKTRCTRL_SHIFT);
532}
533
Sricharan9784f1f2011-11-15 09:49:58 -0500534void do_enable_clocks(u32 *const *clk_domains,
535 u32 *const *clk_modules_hw_auto,
536 u32 *const *clk_modules_explicit_en,
537 u8 wait_for_enable)
538{
539 u32 i, max = 100;
540
541 /* Put the clock domains in SW_WKUP mode */
542 for (i = 0; (i < max) && clk_domains[i]; i++) {
543 enable_clock_domain(clk_domains[i],
544 CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
545 }
546
547 /* Clock modules that need to be put in HW_AUTO */
548 for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) {
549 enable_clock_module(clk_modules_hw_auto[i],
550 MODULE_CLKCTRL_MODULEMODE_HW_AUTO,
551 wait_for_enable);
552 };
553
554 /* Clock modules that need to be put in SW_EXPLICIT_EN mode */
555 for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
556 enable_clock_module(clk_modules_explicit_en[i],
557 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
558 wait_for_enable);
559 };
560
561 /* Put the clock domains in HW_AUTO mode now */
562 for (i = 0; (i < max) && clk_domains[i]; i++) {
563 enable_clock_domain(clk_domains[i],
564 CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
565 }
566}
567
Aneesh V0d2628b2011-07-21 09:10:07 -0400568void prcm_init(void)
569{
Sricharan9310ff72011-11-15 09:49:55 -0500570 switch (omap_hw_init_context()) {
Aneesh V0d2628b2011-07-21 09:10:07 -0400571 case OMAP_INIT_CONTEXT_SPL:
572 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
573 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
Aneesh V9a390882011-07-21 09:29:29 -0400574 enable_basic_clocks();
Aneesh V0d2628b2011-07-21 09:10:07 -0400575 scale_vcores();
576 setup_dplls();
Sricharan308fe922011-11-15 09:50:03 -0500577#ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL
Aneesh V0d2628b2011-07-21 09:10:07 -0400578 setup_non_essential_dplls();
579 enable_non_essential_clocks();
Sricharan308fe922011-11-15 09:50:03 -0500580#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400581 break;
582 default:
583 break;
584 }
Sricharan308fe922011-11-15 09:50:03 -0500585
586 if (OMAP_INIT_CONTEXT_SPL != omap_hw_init_context())
587 enable_basic_uboot_clocks();
Aneesh V0d2628b2011-07-21 09:10:07 -0400588}