blob: b1fd277d6d58cc17726b73cbcadc41a3b1d9a73e [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
SRICHARAN Rb1ee0bc2012-03-12 02:25:34 +0000248 setbits_le32(&prcm->cm_mpu_mpu_clkctrl,
249 MPU_CLKCTRL_CLKSEL_EMIF_DIV_MODE_MASK);
250 setbits_le32(&prcm->cm_mpu_mpu_clkctrl,
251 MPU_CLKCTRL_CLKSEL_ABE_DIV_MODE_MASK);
252
Sricharan9784f1f2011-11-15 09:49:58 -0500253 params = get_mpu_dpll_params();
Sricharan308fe922011-11-15 09:50:03 -0500254
255 do_setup_dpll(&prcm->cm_clkmode_dpll_mpu, params, DPLL_LOCK, "mpu");
Aneesh Va47a79f2011-07-21 09:29:36 -0400256 debug("MPU DPLL locked\n");
257}
258
Govindraj.Rad4426b2012-02-06 03:55:36 +0000259#ifdef CONFIG_USB_EHCI_OMAP
260static void setup_usb_dpll(void)
261{
262 const struct dpll_params *params;
263 u32 sys_clk_khz, sd_div, num, den;
264
265 sys_clk_khz = get_sys_clk_freq() / 1000;
266 /*
267 * USB:
268 * USB dpll is J-type. Need to set DPLL_SD_DIV for jitter correction
269 * DPLL_SD_DIV = CEILING ([DPLL_MULT/(DPLL_DIV+1)]* CLKINP / 250)
270 * - where CLKINP is sys_clk in MHz
271 * Use CLKINP in KHz and adjust the denominator accordingly so
272 * that we have enough accuracy and at the same time no overflow
273 */
274 params = get_usb_dpll_params();
275 num = params->m * sys_clk_khz;
276 den = (params->n + 1) * 250 * 1000;
277 num += den - 1;
278 sd_div = num / den;
279 clrsetbits_le32(&prcm->cm_clksel_dpll_usb,
280 CM_CLKSEL_DPLL_DPLL_SD_DIV_MASK,
281 sd_div << CM_CLKSEL_DPLL_DPLL_SD_DIV_SHIFT);
282
283 /* Now setup the dpll with the regular function */
284 do_setup_dpll(&prcm->cm_clkmode_dpll_usb, params, DPLL_LOCK, "usb");
285}
286#endif
287
Aneesh V0d2628b2011-07-21 09:10:07 -0400288static void setup_dplls(void)
289{
Anatolij Gustschin20f23512011-12-03 06:46:14 +0000290 u32 temp;
Aneesh V0d2628b2011-07-21 09:10:07 -0400291 const struct dpll_params *params;
Aneesh V0d2628b2011-07-21 09:10:07 -0400292
Anatolij Gustschin20f23512011-12-03 06:46:14 +0000293 debug("setup_dplls\n");
Aneesh V0d2628b2011-07-21 09:10:07 -0400294
295 /* CORE dpll */
296 params = get_core_dpll_params(); /* default - safest */
297 /*
298 * Do not lock the core DPLL now. Just set it up.
299 * Core DPLL will be locked after setting up EMIF
300 * using the FREQ_UPDATE method(freq_update_core())
301 */
Lokesh Vutlacdfc4ea2012-05-22 00:03:26 +0000302 if (omap_revision() != OMAP5432_ES1_0)
303 do_setup_dpll(&prcm->cm_clkmode_dpll_core, params,
304 DPLL_NO_LOCK, "core");
305 else
306 do_setup_dpll(&prcm->cm_clkmode_dpll_core, params,
307 DPLL_LOCK, "core");
Aneesh V0d2628b2011-07-21 09:10:07 -0400308 /* Set the ratios for CORE_CLK, L3_CLK, L4_CLK */
309 temp = (CLKSEL_CORE_X2_DIV_1 << CLKSEL_CORE_SHIFT) |
310 (CLKSEL_L3_CORE_DIV_2 << CLKSEL_L3_SHIFT) |
311 (CLKSEL_L4_L3_DIV_2 << CLKSEL_L4_SHIFT);
312 writel(temp, &prcm->cm_clksel_core);
313 debug("Core DPLL configured\n");
314
315 /* lock PER dpll */
Sricharan9784f1f2011-11-15 09:49:58 -0500316 params = get_per_dpll_params();
Aneesh V0d2628b2011-07-21 09:10:07 -0400317 do_setup_dpll(&prcm->cm_clkmode_dpll_per,
Sricharan308fe922011-11-15 09:50:03 -0500318 params, DPLL_LOCK, "per");
Aneesh V0d2628b2011-07-21 09:10:07 -0400319 debug("PER DPLL locked\n");
320
321 /* MPU dpll */
Aneesh Va47a79f2011-07-21 09:29:36 -0400322 configure_mpu_dpll();
Govindraj.Rad4426b2012-02-06 03:55:36 +0000323
324#ifdef CONFIG_USB_EHCI_OMAP
325 setup_usb_dpll();
326#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400327}
328
Sricharan308fe922011-11-15 09:50:03 -0500329#ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL
Aneesh V0d2628b2011-07-21 09:10:07 -0400330static void setup_non_essential_dplls(void)
331{
Anatolij Gustschind75ffd42012-03-27 23:13:43 +0000332 u32 abe_ref_clk;
Aneesh V0d2628b2011-07-21 09:10:07 -0400333 const struct dpll_params *params;
334
Aneesh V0d2628b2011-07-21 09:10:07 -0400335 /* IVA */
336 clrsetbits_le32(&prcm->cm_bypclk_dpll_iva,
337 CM_BYPCLK_DPLL_IVA_CLKSEL_MASK, DPLL_IVA_CLKSEL_CORE_X2_DIV_2);
338
Sricharan9784f1f2011-11-15 09:49:58 -0500339 params = get_iva_dpll_params();
Sricharan308fe922011-11-15 09:50:03 -0500340 do_setup_dpll(&prcm->cm_clkmode_dpll_iva, params, DPLL_LOCK, "iva");
Aneesh V0d2628b2011-07-21 09:10:07 -0400341
Sricharan9784f1f2011-11-15 09:49:58 -0500342 /* Configure ABE dpll */
343 params = get_abe_dpll_params();
344#ifdef CONFIG_SYS_OMAP_ABE_SYSCK
Aneesh V0d2628b2011-07-21 09:10:07 -0400345 abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_SYSCLK;
346#else
Aneesh V0d2628b2011-07-21 09:10:07 -0400347 abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_32KCLK;
348 /*
349 * We need to enable some additional options to achieve
350 * 196.608MHz from 32768 Hz
351 */
352 setbits_le32(&prcm->cm_clkmode_dpll_abe,
353 CM_CLKMODE_DPLL_DRIFTGUARD_EN_MASK|
354 CM_CLKMODE_DPLL_RELOCK_RAMP_EN_MASK|
355 CM_CLKMODE_DPLL_LPMODE_EN_MASK|
356 CM_CLKMODE_DPLL_REGM4XEN_MASK);
357 /* Spend 4 REFCLK cycles at each stage */
358 clrsetbits_le32(&prcm->cm_clkmode_dpll_abe,
359 CM_CLKMODE_DPLL_RAMP_RATE_MASK,
360 1 << CM_CLKMODE_DPLL_RAMP_RATE_SHIFT);
361#endif
362
363 /* Select the right reference clk */
364 clrsetbits_le32(&prcm->cm_abe_pll_ref_clksel,
365 CM_ABE_PLL_REF_CLKSEL_CLKSEL_MASK,
366 abe_ref_clk << CM_ABE_PLL_REF_CLKSEL_CLKSEL_SHIFT);
367 /* Lock the dpll */
Sricharan308fe922011-11-15 09:50:03 -0500368 do_setup_dpll(&prcm->cm_clkmode_dpll_abe, params, DPLL_LOCK, "abe");
Aneesh V0d2628b2011-07-21 09:10:07 -0400369}
Sricharan308fe922011-11-15 09:50:03 -0500370#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400371
Nishanth Menona0f45c12012-03-01 14:17:38 +0000372void do_scale_tps62361(int gpio, u32 reg, u32 volt_mv)
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400373{
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000374 u32 step;
Nishanth Menona0f45c12012-03-01 14:17:38 +0000375 int ret = 0;
376
377 /* See if we can first get the GPIO if needed */
378 if (gpio >= 0)
379 ret = gpio_request(gpio, "TPS62361_VSEL0_GPIO");
380 if (ret < 0) {
381 printf("%s: gpio %d request failed %d\n", __func__, gpio, ret);
382 gpio = -1;
383 }
384
385 /* Pull the GPIO low to select SET0 register, while we program SET1 */
386 if (gpio >= 0)
387 gpio_direction_output(gpio, 0);
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400388
389 step = volt_mv - TPS62361_BASE_VOLT_MV;
390 step /= 10;
391
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400392 debug("do_scale_tps62361: volt - %d step - 0x%x\n", volt_mv, step);
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000393 if (omap_vc_bypass_send_value(TPS62361_I2C_SLAVE_ADDR, reg, step))
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400394 puts("Scaling voltage failed for vdd_mpu from TPS\n");
Nishanth Menona0f45c12012-03-01 14:17:38 +0000395
396 /* Pull the GPIO high to select SET1 register */
397 if (gpio >= 0)
398 gpio_direction_output(gpio, 1);
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400399}
400
Sricharan9784f1f2011-11-15 09:49:58 -0500401void do_scale_vcore(u32 vcore_reg, u32 volt_mv)
Aneesh V0d2628b2011-07-21 09:10:07 -0400402{
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000403 u32 offset_code;
Aneesh V0d2628b2011-07-21 09:10:07 -0400404 u32 offset = volt_mv;
405
406 /* convert to uV for better accuracy in the calculations */
407 offset *= 1000;
408
SRICHARAN R698a1f22012-03-12 02:25:38 +0000409 offset_code = get_offset_code(offset);
Aneesh V0d2628b2011-07-21 09:10:07 -0400410
411 debug("do_scale_vcore: volt - %d offset_code - 0x%x\n", volt_mv,
412 offset_code);
SRICHARAN R698a1f22012-03-12 02:25:38 +0000413
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000414 if (omap_vc_bypass_send_value(SMPS_I2C_SLAVE_ADDR,
415 vcore_reg, offset_code))
Aneesh V0d2628b2011-07-21 09:10:07 -0400416 printf("Scaling voltage failed for 0x%x\n", vcore_reg);
Aneesh V0d2628b2011-07-21 09:10:07 -0400417}
418
Aneesh V0d2628b2011-07-21 09:10:07 -0400419static inline void enable_clock_domain(u32 *const clkctrl_reg, u32 enable_mode)
420{
421 clrsetbits_le32(clkctrl_reg, CD_CLKCTRL_CLKTRCTRL_MASK,
422 enable_mode << CD_CLKCTRL_CLKTRCTRL_SHIFT);
Marek Vasutcff84342011-10-24 23:41:40 +0000423 debug("Enable clock domain - %p\n", clkctrl_reg);
Aneesh V0d2628b2011-07-21 09:10:07 -0400424}
425
426static inline void wait_for_clk_enable(u32 *clkctrl_addr)
427{
428 u32 clkctrl, idlest = MODULE_CLKCTRL_IDLEST_DISABLED;
429 u32 bound = LDELAY;
430
431 while ((idlest == MODULE_CLKCTRL_IDLEST_DISABLED) ||
432 (idlest == MODULE_CLKCTRL_IDLEST_TRANSITIONING)) {
433
434 clkctrl = readl(clkctrl_addr);
435 idlest = (clkctrl & MODULE_CLKCTRL_IDLEST_MASK) >>
436 MODULE_CLKCTRL_IDLEST_SHIFT;
437 if (--bound == 0) {
438 printf("Clock enable failed for 0x%p idlest 0x%x\n",
439 clkctrl_addr, clkctrl);
440 return;
441 }
442 }
443}
444
445static inline void enable_clock_module(u32 *const clkctrl_addr, u32 enable_mode,
446 u32 wait_for_enable)
447{
448 clrsetbits_le32(clkctrl_addr, MODULE_CLKCTRL_MODULEMODE_MASK,
449 enable_mode << MODULE_CLKCTRL_MODULEMODE_SHIFT);
Marek Vasutcff84342011-10-24 23:41:40 +0000450 debug("Enable clock module - %p\n", clkctrl_addr);
Aneesh V0d2628b2011-07-21 09:10:07 -0400451 if (wait_for_enable)
452 wait_for_clk_enable(clkctrl_addr);
453}
454
Aneesh V0d2628b2011-07-21 09:10:07 -0400455void freq_update_core(void)
456{
457 u32 freq_config1 = 0;
458 const struct dpll_params *core_dpll_params;
SRICHARAN R3d534962012-03-12 02:25:37 +0000459 u32 omap_rev = omap_revision();
Aneesh V0d2628b2011-07-21 09:10:07 -0400460
461 core_dpll_params = get_core_dpll_params();
462 /* Put EMIF clock domain in sw wakeup mode */
463 enable_clock_domain(&prcm->cm_memif_clkstctrl,
464 CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
465 wait_for_clk_enable(&prcm->cm_memif_emif_1_clkctrl);
466 wait_for_clk_enable(&prcm->cm_memif_emif_2_clkctrl);
467
468 freq_config1 = SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK |
469 SHADOW_FREQ_CONFIG1_DLL_RESET_MASK;
470
471 freq_config1 |= (DPLL_EN_LOCK << SHADOW_FREQ_CONFIG1_DPLL_EN_SHIFT) &
472 SHADOW_FREQ_CONFIG1_DPLL_EN_MASK;
473
474 freq_config1 |= (core_dpll_params->m2 <<
475 SHADOW_FREQ_CONFIG1_M2_DIV_SHIFT) &
476 SHADOW_FREQ_CONFIG1_M2_DIV_MASK;
477
478 writel(freq_config1, &prcm->cm_shadow_freq_config1);
479 if (!wait_on_value(SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK, 0,
480 &prcm->cm_shadow_freq_config1, LDELAY)) {
481 puts("FREQ UPDATE procedure failed!!");
482 hang();
483 }
484
SRICHARAN R3d534962012-03-12 02:25:37 +0000485 /*
486 * Putting EMIF in HW_AUTO is seen to be causing issues with
487 * EMIF clocks and the master DLL. Put EMIF in SW_WKUP
488 * in OMAP5430 ES1.0 silicon
489 */
490 if (omap_rev != OMAP5430_ES1_0) {
491 /* Put EMIF clock domain back in hw auto mode */
492 enable_clock_domain(&prcm->cm_memif_clkstctrl,
493 CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
494 wait_for_clk_enable(&prcm->cm_memif_emif_1_clkctrl);
495 wait_for_clk_enable(&prcm->cm_memif_emif_2_clkctrl);
496 }
Aneesh V0d2628b2011-07-21 09:10:07 -0400497}
498
499void bypass_dpll(u32 *const base)
500{
501 do_bypass_dpll(base);
502 wait_for_bypass(base);
503}
504
505void lock_dpll(u32 *const base)
506{
507 do_lock_dpll(base);
508 wait_for_lock(base);
509}
510
Aneesh Vb8e60b92011-07-21 09:10:21 -0400511void setup_clocks_for_console(void)
512{
513 /* Do not add any spl_debug prints in this function */
514 clrsetbits_le32(&prcm->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK,
515 CD_CLKCTRL_CLKTRCTRL_SW_WKUP <<
516 CD_CLKCTRL_CLKTRCTRL_SHIFT);
517
518 /* Enable all UARTs - console will be on one of them */
519 clrsetbits_le32(&prcm->cm_l4per_uart1_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_uart2_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_uart3_clkctrl,
530 MODULE_CLKCTRL_MODULEMODE_MASK,
531 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
532 MODULE_CLKCTRL_MODULEMODE_SHIFT);
533
534 clrsetbits_le32(&prcm->cm_l4per_uart3_clkctrl,
535 MODULE_CLKCTRL_MODULEMODE_MASK,
536 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
537 MODULE_CLKCTRL_MODULEMODE_SHIFT);
538
539 clrsetbits_le32(&prcm->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK,
540 CD_CLKCTRL_CLKTRCTRL_HW_AUTO <<
541 CD_CLKCTRL_CLKTRCTRL_SHIFT);
542}
543
Sricharan9784f1f2011-11-15 09:49:58 -0500544void do_enable_clocks(u32 *const *clk_domains,
545 u32 *const *clk_modules_hw_auto,
546 u32 *const *clk_modules_explicit_en,
547 u8 wait_for_enable)
548{
549 u32 i, max = 100;
550
551 /* Put the clock domains in SW_WKUP mode */
552 for (i = 0; (i < max) && clk_domains[i]; i++) {
553 enable_clock_domain(clk_domains[i],
554 CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
555 }
556
557 /* Clock modules that need to be put in HW_AUTO */
558 for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) {
559 enable_clock_module(clk_modules_hw_auto[i],
560 MODULE_CLKCTRL_MODULEMODE_HW_AUTO,
561 wait_for_enable);
562 };
563
564 /* Clock modules that need to be put in SW_EXPLICIT_EN mode */
565 for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
566 enable_clock_module(clk_modules_explicit_en[i],
567 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
568 wait_for_enable);
569 };
570
571 /* Put the clock domains in HW_AUTO mode now */
572 for (i = 0; (i < max) && clk_domains[i]; i++) {
573 enable_clock_domain(clk_domains[i],
574 CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
575 }
576}
577
Aneesh V0d2628b2011-07-21 09:10:07 -0400578void prcm_init(void)
579{
Sricharan9310ff72011-11-15 09:49:55 -0500580 switch (omap_hw_init_context()) {
Aneesh V0d2628b2011-07-21 09:10:07 -0400581 case OMAP_INIT_CONTEXT_SPL:
582 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
583 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
Aneesh V9a390882011-07-21 09:29:29 -0400584 enable_basic_clocks();
Aneesh V0d2628b2011-07-21 09:10:07 -0400585 scale_vcores();
586 setup_dplls();
Sricharan308fe922011-11-15 09:50:03 -0500587#ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL
Aneesh V0d2628b2011-07-21 09:10:07 -0400588 setup_non_essential_dplls();
589 enable_non_essential_clocks();
Sricharan308fe922011-11-15 09:50:03 -0500590#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400591 break;
592 default:
593 break;
594 }
Sricharan308fe922011-11-15 09:50:03 -0500595
596 if (OMAP_INIT_CONTEXT_SPL != omap_hw_init_context())
597 enable_basic_uboot_clocks();
Aneesh V0d2628b2011-07-21 09:10:07 -0400598}