Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 1 | /* |
| 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 Premi | 0c2c8ac | 2011-09-08 10:48:39 -0400 | [diff] [blame] | 34 | #include <asm/gpio.h> |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 35 | #include <asm/arch/clocks.h> |
| 36 | #include <asm/arch/sys_proto.h> |
| 37 | #include <asm/utils.h> |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 38 | #include <asm/omap_gpio.h> |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 39 | |
| 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 49 | static 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 | |
| 69 | u32 get_sys_clk_index(void) |
| 70 | __attribute__ ((weak, alias("__get_sys_clk_index"))); |
| 71 | |
| 72 | u32 get_sys_clk_freq(void) |
| 73 | { |
| 74 | u8 index = get_sys_clk_index(); |
| 75 | return sys_clk_array[index]; |
| 76 | } |
| 77 | |
| 78 | static 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 | |
| 88 | static 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 | |
| 98 | static 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 | |
| 107 | static 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 | |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 118 | inline 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 126 | static void do_setup_dpll(u32 *const base, const struct dpll_params *params, |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 127 | u8 lock, char *dpll) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 128 | { |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 129 | u32 temp, M, N; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 130 | struct dpll_regs *const dpll_regs = (struct dpll_regs *)base; |
| 131 | |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 132 | 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 155 | bypass_dpll(base); |
| 156 | |
| 157 | /* Set M & N */ |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 158 | 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 | |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 170 | setup_post_dividers: |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 171 | setup_post_dividers(base, params); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 172 | |
| 173 | /* Wait till the DPLL locks */ |
| 174 | if (lock) |
| 175 | wait_for_lock(base); |
| 176 | } |
| 177 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 178 | u32 omap_ddr_clk(void) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 179 | { |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 180 | u32 ddr_clk, sys_clk_khz, omap_rev, divider; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 181 | const struct dpll_params *core_dpll_params; |
| 182 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 183 | omap_rev = omap_revision(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 184 | 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); |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 193 | |
| 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 207 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 208 | ddr_clk = ddr_clk / divider / core_dpll_params->m2; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 209 | ddr_clk *= 1000; /* convert to Hz */ |
| 210 | debug("ddr_clk %d\n ", ddr_clk); |
| 211 | |
| 212 | return ddr_clk; |
| 213 | } |
| 214 | |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 215 | /* |
| 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 | */ |
| 223 | void configure_mpu_dpll(void) |
| 224 | { |
| 225 | const struct dpll_params *params; |
| 226 | struct dpll_regs *mpu_dpll_regs; |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 227 | u32 omap_rev; |
| 228 | omap_rev = omap_revision(); |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 229 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 230 | /* |
| 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 V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 237 | 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 | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 248 | params = get_mpu_dpll_params(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 249 | |
| 250 | do_setup_dpll(&prcm->cm_clkmode_dpll_mpu, params, DPLL_LOCK, "mpu"); |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 251 | debug("MPU DPLL locked\n"); |
| 252 | } |
| 253 | |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 254 | #ifdef CONFIG_USB_EHCI_OMAP |
| 255 | static 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 283 | static void setup_dplls(void) |
| 284 | { |
Anatolij Gustschin | 20f2351 | 2011-12-03 06:46:14 +0000 | [diff] [blame] | 285 | u32 temp; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 286 | const struct dpll_params *params; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 287 | |
Anatolij Gustschin | 20f2351 | 2011-12-03 06:46:14 +0000 | [diff] [blame] | 288 | debug("setup_dplls\n"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 289 | |
| 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 | */ |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 297 | do_setup_dpll(&prcm->cm_clkmode_dpll_core, params, DPLL_NO_LOCK, |
| 298 | "core"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 299 | /* 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 */ |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 307 | params = get_per_dpll_params(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 308 | do_setup_dpll(&prcm->cm_clkmode_dpll_per, |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 309 | params, DPLL_LOCK, "per"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 310 | debug("PER DPLL locked\n"); |
| 311 | |
| 312 | /* MPU dpll */ |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 313 | configure_mpu_dpll(); |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 314 | |
| 315 | #ifdef CONFIG_USB_EHCI_OMAP |
| 316 | setup_usb_dpll(); |
| 317 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 320 | #ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 321 | static void setup_non_essential_dplls(void) |
| 322 | { |
Anatolij Gustschin | d75ffd4 | 2012-03-27 23:13:43 +0000 | [diff] [blame] | 323 | u32 abe_ref_clk; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 324 | const struct dpll_params *params; |
| 325 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 326 | /* IVA */ |
| 327 | clrsetbits_le32(&prcm->cm_bypclk_dpll_iva, |
| 328 | CM_BYPCLK_DPLL_IVA_CLKSEL_MASK, DPLL_IVA_CLKSEL_CORE_X2_DIV_2); |
| 329 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 330 | params = get_iva_dpll_params(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 331 | do_setup_dpll(&prcm->cm_clkmode_dpll_iva, params, DPLL_LOCK, "iva"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 332 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 333 | /* Configure ABE dpll */ |
| 334 | params = get_abe_dpll_params(); |
| 335 | #ifdef CONFIG_SYS_OMAP_ABE_SYSCK |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 336 | abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_SYSCLK; |
| 337 | #else |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 338 | 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 */ |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 359 | do_setup_dpll(&prcm->cm_clkmode_dpll_abe, params, DPLL_LOCK, "abe"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 360 | } |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 361 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 362 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 363 | void do_scale_tps62361(u32 reg, u32 volt_mv) |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 364 | { |
| 365 | u32 temp, step; |
| 366 | |
| 367 | step = volt_mv - TPS62361_BASE_VOLT_MV; |
| 368 | step /= 10; |
| 369 | |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 370 | temp = TPS62361_I2C_SLAVE_ADDR | |
| 371 | (reg << PRM_VC_VAL_BYPASS_REGADDR_SHIFT) | |
| 372 | (step << PRM_VC_VAL_BYPASS_DATA_SHIFT) | |
| 373 | PRM_VC_VAL_BYPASS_VALID_BIT; |
| 374 | debug("do_scale_tps62361: volt - %d step - 0x%x\n", volt_mv, step); |
| 375 | |
| 376 | writel(temp, &prcm->prm_vc_val_bypass); |
| 377 | if (!wait_on_value(PRM_VC_VAL_BYPASS_VALID_BIT, 0, |
| 378 | &prcm->prm_vc_val_bypass, LDELAY)) { |
| 379 | puts("Scaling voltage failed for vdd_mpu from TPS\n"); |
| 380 | } |
| 381 | } |
| 382 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 383 | void do_scale_vcore(u32 vcore_reg, u32 volt_mv) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 384 | { |
| 385 | u32 temp, offset_code; |
| 386 | u32 step = 12660; /* 12.66 mV represented in uV */ |
| 387 | u32 offset = volt_mv; |
| 388 | |
| 389 | /* convert to uV for better accuracy in the calculations */ |
| 390 | offset *= 1000; |
| 391 | |
| 392 | if (omap_revision() == OMAP4430_ES1_0) |
| 393 | offset -= PHOENIX_SMPS_BASE_VOLT_STD_MODE_UV; |
| 394 | else |
| 395 | offset -= PHOENIX_SMPS_BASE_VOLT_STD_MODE_WITH_OFFSET_UV; |
| 396 | |
| 397 | offset_code = (offset + step - 1) / step; |
| 398 | /* The code starts at 1 not 0 */ |
| 399 | offset_code++; |
| 400 | |
| 401 | debug("do_scale_vcore: volt - %d offset_code - 0x%x\n", volt_mv, |
| 402 | offset_code); |
| 403 | |
| 404 | temp = SMPS_I2C_SLAVE_ADDR | |
| 405 | (vcore_reg << PRM_VC_VAL_BYPASS_REGADDR_SHIFT) | |
| 406 | (offset_code << PRM_VC_VAL_BYPASS_DATA_SHIFT) | |
| 407 | PRM_VC_VAL_BYPASS_VALID_BIT; |
| 408 | writel(temp, &prcm->prm_vc_val_bypass); |
| 409 | if (!wait_on_value(PRM_VC_VAL_BYPASS_VALID_BIT, 0, |
| 410 | &prcm->prm_vc_val_bypass, LDELAY)) { |
| 411 | printf("Scaling voltage failed for 0x%x\n", vcore_reg); |
| 412 | } |
| 413 | } |
| 414 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 415 | static inline void enable_clock_domain(u32 *const clkctrl_reg, u32 enable_mode) |
| 416 | { |
| 417 | clrsetbits_le32(clkctrl_reg, CD_CLKCTRL_CLKTRCTRL_MASK, |
| 418 | enable_mode << CD_CLKCTRL_CLKTRCTRL_SHIFT); |
Marek Vasut | cff8434 | 2011-10-24 23:41:40 +0000 | [diff] [blame] | 419 | debug("Enable clock domain - %p\n", clkctrl_reg); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static inline void wait_for_clk_enable(u32 *clkctrl_addr) |
| 423 | { |
| 424 | u32 clkctrl, idlest = MODULE_CLKCTRL_IDLEST_DISABLED; |
| 425 | u32 bound = LDELAY; |
| 426 | |
| 427 | while ((idlest == MODULE_CLKCTRL_IDLEST_DISABLED) || |
| 428 | (idlest == MODULE_CLKCTRL_IDLEST_TRANSITIONING)) { |
| 429 | |
| 430 | clkctrl = readl(clkctrl_addr); |
| 431 | idlest = (clkctrl & MODULE_CLKCTRL_IDLEST_MASK) >> |
| 432 | MODULE_CLKCTRL_IDLEST_SHIFT; |
| 433 | if (--bound == 0) { |
| 434 | printf("Clock enable failed for 0x%p idlest 0x%x\n", |
| 435 | clkctrl_addr, clkctrl); |
| 436 | return; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | static inline void enable_clock_module(u32 *const clkctrl_addr, u32 enable_mode, |
| 442 | u32 wait_for_enable) |
| 443 | { |
| 444 | clrsetbits_le32(clkctrl_addr, MODULE_CLKCTRL_MODULEMODE_MASK, |
| 445 | enable_mode << MODULE_CLKCTRL_MODULEMODE_SHIFT); |
Marek Vasut | cff8434 | 2011-10-24 23:41:40 +0000 | [diff] [blame] | 446 | debug("Enable clock module - %p\n", clkctrl_addr); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 447 | if (wait_for_enable) |
| 448 | wait_for_clk_enable(clkctrl_addr); |
| 449 | } |
| 450 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 451 | void freq_update_core(void) |
| 452 | { |
| 453 | u32 freq_config1 = 0; |
| 454 | const struct dpll_params *core_dpll_params; |
| 455 | |
| 456 | core_dpll_params = get_core_dpll_params(); |
| 457 | /* Put EMIF clock domain in sw wakeup mode */ |
| 458 | enable_clock_domain(&prcm->cm_memif_clkstctrl, |
| 459 | CD_CLKCTRL_CLKTRCTRL_SW_WKUP); |
| 460 | wait_for_clk_enable(&prcm->cm_memif_emif_1_clkctrl); |
| 461 | wait_for_clk_enable(&prcm->cm_memif_emif_2_clkctrl); |
| 462 | |
| 463 | freq_config1 = SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK | |
| 464 | SHADOW_FREQ_CONFIG1_DLL_RESET_MASK; |
| 465 | |
| 466 | freq_config1 |= (DPLL_EN_LOCK << SHADOW_FREQ_CONFIG1_DPLL_EN_SHIFT) & |
| 467 | SHADOW_FREQ_CONFIG1_DPLL_EN_MASK; |
| 468 | |
| 469 | freq_config1 |= (core_dpll_params->m2 << |
| 470 | SHADOW_FREQ_CONFIG1_M2_DIV_SHIFT) & |
| 471 | SHADOW_FREQ_CONFIG1_M2_DIV_MASK; |
| 472 | |
| 473 | writel(freq_config1, &prcm->cm_shadow_freq_config1); |
| 474 | if (!wait_on_value(SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK, 0, |
| 475 | &prcm->cm_shadow_freq_config1, LDELAY)) { |
| 476 | puts("FREQ UPDATE procedure failed!!"); |
| 477 | hang(); |
| 478 | } |
| 479 | |
| 480 | /* Put EMIF clock domain back in hw auto mode */ |
| 481 | enable_clock_domain(&prcm->cm_memif_clkstctrl, |
| 482 | CD_CLKCTRL_CLKTRCTRL_HW_AUTO); |
| 483 | wait_for_clk_enable(&prcm->cm_memif_emif_1_clkctrl); |
| 484 | wait_for_clk_enable(&prcm->cm_memif_emif_2_clkctrl); |
| 485 | } |
| 486 | |
| 487 | void bypass_dpll(u32 *const base) |
| 488 | { |
| 489 | do_bypass_dpll(base); |
| 490 | wait_for_bypass(base); |
| 491 | } |
| 492 | |
| 493 | void lock_dpll(u32 *const base) |
| 494 | { |
| 495 | do_lock_dpll(base); |
| 496 | wait_for_lock(base); |
| 497 | } |
| 498 | |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 499 | void setup_clocks_for_console(void) |
| 500 | { |
| 501 | /* Do not add any spl_debug prints in this function */ |
| 502 | clrsetbits_le32(&prcm->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK, |
| 503 | CD_CLKCTRL_CLKTRCTRL_SW_WKUP << |
| 504 | CD_CLKCTRL_CLKTRCTRL_SHIFT); |
| 505 | |
| 506 | /* Enable all UARTs - console will be on one of them */ |
| 507 | clrsetbits_le32(&prcm->cm_l4per_uart1_clkctrl, |
| 508 | MODULE_CLKCTRL_MODULEMODE_MASK, |
| 509 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN << |
| 510 | MODULE_CLKCTRL_MODULEMODE_SHIFT); |
| 511 | |
| 512 | clrsetbits_le32(&prcm->cm_l4per_uart2_clkctrl, |
| 513 | MODULE_CLKCTRL_MODULEMODE_MASK, |
| 514 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN << |
| 515 | MODULE_CLKCTRL_MODULEMODE_SHIFT); |
| 516 | |
| 517 | clrsetbits_le32(&prcm->cm_l4per_uart3_clkctrl, |
| 518 | MODULE_CLKCTRL_MODULEMODE_MASK, |
| 519 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN << |
| 520 | MODULE_CLKCTRL_MODULEMODE_SHIFT); |
| 521 | |
| 522 | clrsetbits_le32(&prcm->cm_l4per_uart3_clkctrl, |
| 523 | MODULE_CLKCTRL_MODULEMODE_MASK, |
| 524 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN << |
| 525 | MODULE_CLKCTRL_MODULEMODE_SHIFT); |
| 526 | |
| 527 | clrsetbits_le32(&prcm->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK, |
| 528 | CD_CLKCTRL_CLKTRCTRL_HW_AUTO << |
| 529 | CD_CLKCTRL_CLKTRCTRL_SHIFT); |
| 530 | } |
| 531 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 532 | void setup_sri2c(void) |
| 533 | { |
| 534 | u32 sys_clk_khz, cycles_hi, cycles_low, temp; |
| 535 | |
| 536 | sys_clk_khz = get_sys_clk_freq() / 1000; |
| 537 | |
| 538 | /* |
| 539 | * Setup the dedicated I2C controller for Voltage Control |
| 540 | * I2C clk - high period 40% low period 60% |
| 541 | */ |
| 542 | cycles_hi = sys_clk_khz * 4 / PRM_VC_I2C_CHANNEL_FREQ_KHZ / 10; |
| 543 | cycles_low = sys_clk_khz * 6 / PRM_VC_I2C_CHANNEL_FREQ_KHZ / 10; |
| 544 | /* values to be set in register - less by 5 & 7 respectively */ |
| 545 | cycles_hi -= 5; |
| 546 | cycles_low -= 7; |
| 547 | temp = (cycles_hi << PRM_VC_CFG_I2C_CLK_SCLH_SHIFT) | |
| 548 | (cycles_low << PRM_VC_CFG_I2C_CLK_SCLL_SHIFT); |
| 549 | writel(temp, &prcm->prm_vc_cfg_i2c_clk); |
| 550 | |
| 551 | /* Disable high speed mode and all advanced features */ |
| 552 | writel(0x0, &prcm->prm_vc_cfg_i2c_mode); |
| 553 | } |
| 554 | |
| 555 | void do_enable_clocks(u32 *const *clk_domains, |
| 556 | u32 *const *clk_modules_hw_auto, |
| 557 | u32 *const *clk_modules_explicit_en, |
| 558 | u8 wait_for_enable) |
| 559 | { |
| 560 | u32 i, max = 100; |
| 561 | |
| 562 | /* Put the clock domains in SW_WKUP mode */ |
| 563 | for (i = 0; (i < max) && clk_domains[i]; i++) { |
| 564 | enable_clock_domain(clk_domains[i], |
| 565 | CD_CLKCTRL_CLKTRCTRL_SW_WKUP); |
| 566 | } |
| 567 | |
| 568 | /* Clock modules that need to be put in HW_AUTO */ |
| 569 | for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) { |
| 570 | enable_clock_module(clk_modules_hw_auto[i], |
| 571 | MODULE_CLKCTRL_MODULEMODE_HW_AUTO, |
| 572 | wait_for_enable); |
| 573 | }; |
| 574 | |
| 575 | /* Clock modules that need to be put in SW_EXPLICIT_EN mode */ |
| 576 | for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) { |
| 577 | enable_clock_module(clk_modules_explicit_en[i], |
| 578 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN, |
| 579 | wait_for_enable); |
| 580 | }; |
| 581 | |
| 582 | /* Put the clock domains in HW_AUTO mode now */ |
| 583 | for (i = 0; (i < max) && clk_domains[i]; i++) { |
| 584 | enable_clock_domain(clk_domains[i], |
| 585 | CD_CLKCTRL_CLKTRCTRL_HW_AUTO); |
| 586 | } |
| 587 | } |
| 588 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 589 | void prcm_init(void) |
| 590 | { |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 591 | switch (omap_hw_init_context()) { |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 592 | case OMAP_INIT_CONTEXT_SPL: |
| 593 | case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR: |
| 594 | case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH: |
Aneesh V | 9a39088 | 2011-07-21 09:29:29 -0400 | [diff] [blame] | 595 | enable_basic_clocks(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 596 | scale_vcores(); |
| 597 | setup_dplls(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 598 | #ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 599 | setup_non_essential_dplls(); |
| 600 | enable_non_essential_clocks(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 601 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 602 | break; |
| 603 | default: |
| 604 | break; |
| 605 | } |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 606 | |
| 607 | if (OMAP_INIT_CONTEXT_SPL != omap_hw_init_context()) |
| 608 | enable_basic_uboot_clocks(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 609 | } |