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 R | b1ee0bc | 2012-03-12 02:25:34 +0000 | [diff] [blame] | 248 | 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 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 253 | params = get_mpu_dpll_params(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 254 | |
| 255 | do_setup_dpll(&prcm->cm_clkmode_dpll_mpu, params, DPLL_LOCK, "mpu"); |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 256 | debug("MPU DPLL locked\n"); |
| 257 | } |
| 258 | |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 259 | #ifdef CONFIG_USB_EHCI_OMAP |
| 260 | static 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 288 | static void setup_dplls(void) |
| 289 | { |
Anatolij Gustschin | 20f2351 | 2011-12-03 06:46:14 +0000 | [diff] [blame] | 290 | u32 temp; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 291 | const struct dpll_params *params; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 292 | |
Anatolij Gustschin | 20f2351 | 2011-12-03 06:46:14 +0000 | [diff] [blame] | 293 | debug("setup_dplls\n"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 294 | |
| 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 Vutla | cdfc4ea | 2012-05-22 00:03:26 +0000 | [diff] [blame^] | 302 | 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 308 | /* 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 */ |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 316 | params = get_per_dpll_params(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 317 | do_setup_dpll(&prcm->cm_clkmode_dpll_per, |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 318 | params, DPLL_LOCK, "per"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 319 | debug("PER DPLL locked\n"); |
| 320 | |
| 321 | /* MPU dpll */ |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 322 | configure_mpu_dpll(); |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 323 | |
| 324 | #ifdef CONFIG_USB_EHCI_OMAP |
| 325 | setup_usb_dpll(); |
| 326 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 327 | } |
| 328 | |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 329 | #ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 330 | static void setup_non_essential_dplls(void) |
| 331 | { |
Anatolij Gustschin | d75ffd4 | 2012-03-27 23:13:43 +0000 | [diff] [blame] | 332 | u32 abe_ref_clk; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 333 | const struct dpll_params *params; |
| 334 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 335 | /* IVA */ |
| 336 | clrsetbits_le32(&prcm->cm_bypclk_dpll_iva, |
| 337 | CM_BYPCLK_DPLL_IVA_CLKSEL_MASK, DPLL_IVA_CLKSEL_CORE_X2_DIV_2); |
| 338 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 339 | params = get_iva_dpll_params(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 340 | do_setup_dpll(&prcm->cm_clkmode_dpll_iva, params, DPLL_LOCK, "iva"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 341 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 342 | /* Configure ABE dpll */ |
| 343 | params = get_abe_dpll_params(); |
| 344 | #ifdef CONFIG_SYS_OMAP_ABE_SYSCK |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 345 | abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_SYSCLK; |
| 346 | #else |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 347 | 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 */ |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 368 | do_setup_dpll(&prcm->cm_clkmode_dpll_abe, params, DPLL_LOCK, "abe"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 369 | } |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 370 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 371 | |
Nishanth Menon | a0f45c1 | 2012-03-01 14:17:38 +0000 | [diff] [blame] | 372 | void do_scale_tps62361(int gpio, u32 reg, u32 volt_mv) |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 373 | { |
Nishanth Menon | 41d7ab1 | 2012-03-01 14:17:37 +0000 | [diff] [blame] | 374 | u32 step; |
Nishanth Menon | a0f45c1 | 2012-03-01 14:17:38 +0000 | [diff] [blame] | 375 | 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 V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 388 | |
| 389 | step = volt_mv - TPS62361_BASE_VOLT_MV; |
| 390 | step /= 10; |
| 391 | |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 392 | debug("do_scale_tps62361: volt - %d step - 0x%x\n", volt_mv, step); |
Nishanth Menon | 41d7ab1 | 2012-03-01 14:17:37 +0000 | [diff] [blame] | 393 | if (omap_vc_bypass_send_value(TPS62361_I2C_SLAVE_ADDR, reg, step)) |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 394 | puts("Scaling voltage failed for vdd_mpu from TPS\n"); |
Nishanth Menon | a0f45c1 | 2012-03-01 14:17:38 +0000 | [diff] [blame] | 395 | |
| 396 | /* Pull the GPIO high to select SET1 register */ |
| 397 | if (gpio >= 0) |
| 398 | gpio_direction_output(gpio, 1); |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 399 | } |
| 400 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 401 | void do_scale_vcore(u32 vcore_reg, u32 volt_mv) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 402 | { |
Nishanth Menon | 41d7ab1 | 2012-03-01 14:17:37 +0000 | [diff] [blame] | 403 | u32 offset_code; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 404 | u32 offset = volt_mv; |
| 405 | |
| 406 | /* convert to uV for better accuracy in the calculations */ |
| 407 | offset *= 1000; |
| 408 | |
SRICHARAN R | 698a1f2 | 2012-03-12 02:25:38 +0000 | [diff] [blame] | 409 | offset_code = get_offset_code(offset); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 410 | |
| 411 | debug("do_scale_vcore: volt - %d offset_code - 0x%x\n", volt_mv, |
| 412 | offset_code); |
SRICHARAN R | 698a1f2 | 2012-03-12 02:25:38 +0000 | [diff] [blame] | 413 | |
Nishanth Menon | 41d7ab1 | 2012-03-01 14:17:37 +0000 | [diff] [blame] | 414 | if (omap_vc_bypass_send_value(SMPS_I2C_SLAVE_ADDR, |
| 415 | vcore_reg, offset_code)) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 416 | printf("Scaling voltage failed for 0x%x\n", vcore_reg); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 417 | } |
| 418 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 419 | static 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 Vasut | cff8434 | 2011-10-24 23:41:40 +0000 | [diff] [blame] | 423 | debug("Enable clock domain - %p\n", clkctrl_reg); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | static 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 | |
| 445 | static 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 Vasut | cff8434 | 2011-10-24 23:41:40 +0000 | [diff] [blame] | 450 | debug("Enable clock module - %p\n", clkctrl_addr); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 451 | if (wait_for_enable) |
| 452 | wait_for_clk_enable(clkctrl_addr); |
| 453 | } |
| 454 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 455 | void freq_update_core(void) |
| 456 | { |
| 457 | u32 freq_config1 = 0; |
| 458 | const struct dpll_params *core_dpll_params; |
SRICHARAN R | 3d53496 | 2012-03-12 02:25:37 +0000 | [diff] [blame] | 459 | u32 omap_rev = omap_revision(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 460 | |
| 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 R | 3d53496 | 2012-03-12 02:25:37 +0000 | [diff] [blame] | 485 | /* |
| 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void bypass_dpll(u32 *const base) |
| 500 | { |
| 501 | do_bypass_dpll(base); |
| 502 | wait_for_bypass(base); |
| 503 | } |
| 504 | |
| 505 | void lock_dpll(u32 *const base) |
| 506 | { |
| 507 | do_lock_dpll(base); |
| 508 | wait_for_lock(base); |
| 509 | } |
| 510 | |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 511 | void 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 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 544 | void 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 V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 578 | void prcm_init(void) |
| 579 | { |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 580 | switch (omap_hw_init_context()) { |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 581 | case OMAP_INIT_CONTEXT_SPL: |
| 582 | case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR: |
| 583 | case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH: |
Aneesh V | 9a39088 | 2011-07-21 09:29:29 -0400 | [diff] [blame] | 584 | enable_basic_clocks(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 585 | scale_vcores(); |
| 586 | setup_dplls(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 587 | #ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 588 | setup_non_essential_dplls(); |
| 589 | enable_non_essential_clocks(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 590 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 591 | break; |
| 592 | default: |
| 593 | break; |
| 594 | } |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 595 | |
| 596 | if (OMAP_INIT_CONTEXT_SPL != omap_hw_init_context()) |
| 597 | enable_basic_uboot_clocks(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 598 | } |