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> |
Lokesh Vutla | fef54c3 | 2013-02-04 04:21:59 +0000 | [diff] [blame] | 39 | #include <asm/emif.h> |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 40 | |
| 41 | #ifndef CONFIG_SPL_BUILD |
| 42 | /* |
| 43 | * printing to console doesn't work unless |
| 44 | * this code is executed from SPL |
| 45 | */ |
| 46 | #define printf(fmt, args...) |
| 47 | #define puts(s) |
| 48 | #endif |
| 49 | |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 50 | const u32 sys_clk_array[8] = { |
| 51 | 12000000, /* 12 MHz */ |
| 52 | 13000000, /* 13 MHz */ |
| 53 | 16800000, /* 16.8 MHz */ |
| 54 | 19200000, /* 19.2 MHz */ |
| 55 | 26000000, /* 26 MHz */ |
| 56 | 27000000, /* 27 MHz */ |
| 57 | 38400000, /* 38.4 MHz */ |
| 58 | }; |
| 59 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 60 | static inline u32 __get_sys_clk_index(void) |
| 61 | { |
| 62 | u32 ind; |
| 63 | /* |
| 64 | * For ES1 the ROM code calibration of sys clock is not reliable |
| 65 | * due to hw issue. So, use hard-coded value. If this value is not |
| 66 | * correct for any board over-ride this function in board file |
| 67 | * From ES2.0 onwards you will get this information from |
| 68 | * CM_SYS_CLKSEL |
| 69 | */ |
| 70 | if (omap_revision() == OMAP4430_ES1_0) |
| 71 | ind = OMAP_SYS_CLK_IND_38_4_MHZ; |
| 72 | else { |
| 73 | /* SYS_CLKSEL - 1 to match the dpll param array indices */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 74 | ind = (readl((*prcm)->cm_sys_clksel) & |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 75 | CM_SYS_CLKSEL_SYS_CLKSEL_MASK) - 1; |
| 76 | } |
| 77 | return ind; |
| 78 | } |
| 79 | |
| 80 | u32 get_sys_clk_index(void) |
| 81 | __attribute__ ((weak, alias("__get_sys_clk_index"))); |
| 82 | |
| 83 | u32 get_sys_clk_freq(void) |
| 84 | { |
| 85 | u8 index = get_sys_clk_index(); |
| 86 | return sys_clk_array[index]; |
| 87 | } |
| 88 | |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 89 | void setup_post_dividers(u32 const base, const struct dpll_params *params) |
| 90 | { |
| 91 | struct dpll_regs *const dpll_regs = (struct dpll_regs *)base; |
| 92 | |
| 93 | /* Setup post-dividers */ |
| 94 | if (params->m2 >= 0) |
| 95 | writel(params->m2, &dpll_regs->cm_div_m2_dpll); |
| 96 | if (params->m3 >= 0) |
| 97 | writel(params->m3, &dpll_regs->cm_div_m3_dpll); |
| 98 | if (params->m4_h11 >= 0) |
| 99 | writel(params->m4_h11, &dpll_regs->cm_div_m4_h11_dpll); |
| 100 | if (params->m5_h12 >= 0) |
| 101 | writel(params->m5_h12, &dpll_regs->cm_div_m5_h12_dpll); |
| 102 | if (params->m6_h13 >= 0) |
| 103 | writel(params->m6_h13, &dpll_regs->cm_div_m6_h13_dpll); |
| 104 | if (params->m7_h14 >= 0) |
| 105 | writel(params->m7_h14, &dpll_regs->cm_div_m7_h14_dpll); |
| 106 | if (params->h22 >= 0) |
| 107 | writel(params->h22, &dpll_regs->cm_div_h22_dpll); |
| 108 | if (params->h23 >= 0) |
| 109 | writel(params->h23, &dpll_regs->cm_div_h23_dpll); |
| 110 | } |
| 111 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 112 | static inline void do_bypass_dpll(u32 const base) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 113 | { |
| 114 | struct dpll_regs *dpll_regs = (struct dpll_regs *)base; |
| 115 | |
| 116 | clrsetbits_le32(&dpll_regs->cm_clkmode_dpll, |
| 117 | CM_CLKMODE_DPLL_DPLL_EN_MASK, |
| 118 | DPLL_EN_FAST_RELOCK_BYPASS << |
| 119 | CM_CLKMODE_DPLL_EN_SHIFT); |
| 120 | } |
| 121 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 122 | static inline void wait_for_bypass(u32 const base) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 123 | { |
| 124 | struct dpll_regs *const dpll_regs = (struct dpll_regs *)base; |
| 125 | |
| 126 | if (!wait_on_value(ST_DPLL_CLK_MASK, 0, &dpll_regs->cm_idlest_dpll, |
| 127 | LDELAY)) { |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 128 | printf("Bypassing DPLL failed %x\n", base); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 132 | static inline void do_lock_dpll(u32 const base) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 133 | { |
| 134 | struct dpll_regs *const dpll_regs = (struct dpll_regs *)base; |
| 135 | |
| 136 | clrsetbits_le32(&dpll_regs->cm_clkmode_dpll, |
| 137 | CM_CLKMODE_DPLL_DPLL_EN_MASK, |
| 138 | DPLL_EN_LOCK << CM_CLKMODE_DPLL_EN_SHIFT); |
| 139 | } |
| 140 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 141 | static inline void wait_for_lock(u32 const base) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 142 | { |
| 143 | struct dpll_regs *const dpll_regs = (struct dpll_regs *)base; |
| 144 | |
| 145 | if (!wait_on_value(ST_DPLL_CLK_MASK, ST_DPLL_CLK_MASK, |
| 146 | &dpll_regs->cm_idlest_dpll, LDELAY)) { |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 147 | printf("DPLL locking failed for %x\n", base); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 148 | hang(); |
| 149 | } |
| 150 | } |
| 151 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 152 | inline u32 check_for_lock(u32 const base) |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 153 | { |
| 154 | struct dpll_regs *const dpll_regs = (struct dpll_regs *)base; |
| 155 | u32 lock = readl(&dpll_regs->cm_idlest_dpll) & ST_DPLL_CLK_MASK; |
| 156 | |
| 157 | return lock; |
| 158 | } |
| 159 | |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 160 | const struct dpll_params *get_mpu_dpll_params(struct dplls const *dpll_data) |
| 161 | { |
| 162 | u32 sysclk_ind = get_sys_clk_index(); |
| 163 | return &dpll_data->mpu[sysclk_ind]; |
| 164 | } |
| 165 | |
| 166 | const struct dpll_params *get_core_dpll_params(struct dplls const *dpll_data) |
| 167 | { |
| 168 | u32 sysclk_ind = get_sys_clk_index(); |
| 169 | return &dpll_data->core[sysclk_ind]; |
| 170 | } |
| 171 | |
| 172 | const struct dpll_params *get_per_dpll_params(struct dplls const *dpll_data) |
| 173 | { |
| 174 | u32 sysclk_ind = get_sys_clk_index(); |
| 175 | return &dpll_data->per[sysclk_ind]; |
| 176 | } |
| 177 | |
| 178 | const struct dpll_params *get_iva_dpll_params(struct dplls const *dpll_data) |
| 179 | { |
| 180 | u32 sysclk_ind = get_sys_clk_index(); |
| 181 | return &dpll_data->iva[sysclk_ind]; |
| 182 | } |
| 183 | |
| 184 | const struct dpll_params *get_usb_dpll_params(struct dplls const *dpll_data) |
| 185 | { |
| 186 | u32 sysclk_ind = get_sys_clk_index(); |
| 187 | return &dpll_data->usb[sysclk_ind]; |
| 188 | } |
| 189 | |
| 190 | const struct dpll_params *get_abe_dpll_params(struct dplls const *dpll_data) |
| 191 | { |
| 192 | #ifdef CONFIG_SYS_OMAP_ABE_SYSCK |
| 193 | u32 sysclk_ind = get_sys_clk_index(); |
| 194 | return &dpll_data->abe[sysclk_ind]; |
| 195 | #else |
| 196 | return dpll_data->abe; |
| 197 | #endif |
| 198 | } |
| 199 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 200 | static void do_setup_dpll(u32 const base, const struct dpll_params *params, |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 201 | u8 lock, char *dpll) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 202 | { |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 203 | u32 temp, M, N; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 204 | struct dpll_regs *const dpll_regs = (struct dpll_regs *)base; |
| 205 | |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 206 | temp = readl(&dpll_regs->cm_clksel_dpll); |
| 207 | |
| 208 | if (check_for_lock(base)) { |
| 209 | /* |
| 210 | * The Dpll has already been locked by rom code using CH. |
| 211 | * Check if M,N are matching with Ideal nominal opp values. |
| 212 | * If matches, skip the rest otherwise relock. |
| 213 | */ |
| 214 | M = (temp & CM_CLKSEL_DPLL_M_MASK) >> CM_CLKSEL_DPLL_M_SHIFT; |
| 215 | N = (temp & CM_CLKSEL_DPLL_N_MASK) >> CM_CLKSEL_DPLL_N_SHIFT; |
| 216 | if ((M != (params->m)) || (N != (params->n))) { |
| 217 | debug("\n %s Dpll locked, but not for ideal M = %d," |
| 218 | "N = %d values, current values are M = %d," |
| 219 | "N= %d" , dpll, params->m, params->n, |
| 220 | M, N); |
| 221 | } else { |
| 222 | /* Dpll locked with ideal values for nominal opps. */ |
| 223 | debug("\n %s Dpll already locked with ideal" |
| 224 | "nominal opp values", dpll); |
| 225 | goto setup_post_dividers; |
| 226 | } |
| 227 | } |
| 228 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 229 | bypass_dpll(base); |
| 230 | |
| 231 | /* Set M & N */ |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 232 | temp &= ~CM_CLKSEL_DPLL_M_MASK; |
| 233 | temp |= (params->m << CM_CLKSEL_DPLL_M_SHIFT) & CM_CLKSEL_DPLL_M_MASK; |
| 234 | |
| 235 | temp &= ~CM_CLKSEL_DPLL_N_MASK; |
| 236 | temp |= (params->n << CM_CLKSEL_DPLL_N_SHIFT) & CM_CLKSEL_DPLL_N_MASK; |
| 237 | |
| 238 | writel(temp, &dpll_regs->cm_clksel_dpll); |
| 239 | |
| 240 | /* Lock */ |
| 241 | if (lock) |
| 242 | do_lock_dpll(base); |
| 243 | |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 244 | setup_post_dividers: |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 245 | setup_post_dividers(base, params); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 246 | |
| 247 | /* Wait till the DPLL locks */ |
| 248 | if (lock) |
| 249 | wait_for_lock(base); |
| 250 | } |
| 251 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 252 | u32 omap_ddr_clk(void) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 253 | { |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 254 | u32 ddr_clk, sys_clk_khz, omap_rev, divider; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 255 | const struct dpll_params *core_dpll_params; |
| 256 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 257 | omap_rev = omap_revision(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 258 | sys_clk_khz = get_sys_clk_freq() / 1000; |
| 259 | |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 260 | core_dpll_params = get_core_dpll_params(*dplls_data); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 261 | |
| 262 | debug("sys_clk %d\n ", sys_clk_khz * 1000); |
| 263 | |
| 264 | /* Find Core DPLL locked frequency first */ |
| 265 | ddr_clk = sys_clk_khz * 2 * core_dpll_params->m / |
| 266 | (core_dpll_params->n + 1); |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 267 | |
| 268 | if (omap_rev < OMAP5430_ES1_0) { |
| 269 | /* |
| 270 | * DDR frequency is PHY_ROOT_CLK/2 |
| 271 | * PHY_ROOT_CLK = Fdpll/2/M2 |
| 272 | */ |
| 273 | divider = 4; |
| 274 | } else { |
| 275 | /* |
| 276 | * DDR frequency is PHY_ROOT_CLK |
| 277 | * PHY_ROOT_CLK = Fdpll/2/M2 |
| 278 | */ |
| 279 | divider = 2; |
| 280 | } |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 281 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 282 | ddr_clk = ddr_clk / divider / core_dpll_params->m2; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 283 | ddr_clk *= 1000; /* convert to Hz */ |
| 284 | debug("ddr_clk %d\n ", ddr_clk); |
| 285 | |
| 286 | return ddr_clk; |
| 287 | } |
| 288 | |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 289 | /* |
| 290 | * Lock MPU dpll |
| 291 | * |
| 292 | * Resulting MPU frequencies: |
| 293 | * 4430 ES1.0 : 600 MHz |
| 294 | * 4430 ES2.x : 792 MHz (OPP Turbo) |
| 295 | * 4460 : 920 MHz (OPP Turbo) - DCC disabled |
| 296 | */ |
| 297 | void configure_mpu_dpll(void) |
| 298 | { |
| 299 | const struct dpll_params *params; |
| 300 | struct dpll_regs *mpu_dpll_regs; |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 301 | u32 omap_rev; |
| 302 | omap_rev = omap_revision(); |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 303 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 304 | /* |
| 305 | * DCC and clock divider settings for 4460. |
| 306 | * DCC is required, if more than a certain frequency is required. |
| 307 | * For, 4460 > 1GHZ. |
| 308 | * 5430 > 1.4GHZ. |
| 309 | */ |
| 310 | if ((omap_rev >= OMAP4460_ES1_0) && (omap_rev < OMAP5430_ES1_0)) { |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 311 | mpu_dpll_regs = |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 312 | (struct dpll_regs *)((*prcm)->cm_clkmode_dpll_mpu); |
| 313 | bypass_dpll((*prcm)->cm_clkmode_dpll_mpu); |
| 314 | clrbits_le32((*prcm)->cm_mpu_mpu_clkctrl, |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 315 | MPU_CLKCTRL_CLKSEL_EMIF_DIV_MODE_MASK); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 316 | setbits_le32((*prcm)->cm_mpu_mpu_clkctrl, |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 317 | MPU_CLKCTRL_CLKSEL_ABE_DIV_MODE_MASK); |
| 318 | clrbits_le32(&mpu_dpll_regs->cm_clksel_dpll, |
| 319 | CM_CLKSEL_DCC_EN_MASK); |
| 320 | } |
| 321 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 322 | setbits_le32((*prcm)->cm_mpu_mpu_clkctrl, |
SRICHARAN R | b1ee0bc | 2012-03-12 02:25:34 +0000 | [diff] [blame] | 323 | MPU_CLKCTRL_CLKSEL_EMIF_DIV_MODE_MASK); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 324 | setbits_le32((*prcm)->cm_mpu_mpu_clkctrl, |
SRICHARAN R | b1ee0bc | 2012-03-12 02:25:34 +0000 | [diff] [blame] | 325 | MPU_CLKCTRL_CLKSEL_ABE_DIV_MODE_MASK); |
| 326 | |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 327 | params = get_mpu_dpll_params(*dplls_data); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 328 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 329 | do_setup_dpll((*prcm)->cm_clkmode_dpll_mpu, params, DPLL_LOCK, "mpu"); |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 330 | debug("MPU DPLL locked\n"); |
| 331 | } |
| 332 | |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 333 | #ifdef CONFIG_USB_EHCI_OMAP |
| 334 | static void setup_usb_dpll(void) |
| 335 | { |
| 336 | const struct dpll_params *params; |
| 337 | u32 sys_clk_khz, sd_div, num, den; |
| 338 | |
| 339 | sys_clk_khz = get_sys_clk_freq() / 1000; |
| 340 | /* |
| 341 | * USB: |
| 342 | * USB dpll is J-type. Need to set DPLL_SD_DIV for jitter correction |
| 343 | * DPLL_SD_DIV = CEILING ([DPLL_MULT/(DPLL_DIV+1)]* CLKINP / 250) |
| 344 | * - where CLKINP is sys_clk in MHz |
| 345 | * Use CLKINP in KHz and adjust the denominator accordingly so |
| 346 | * that we have enough accuracy and at the same time no overflow |
| 347 | */ |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 348 | params = get_usb_dpll_params(*dplls_data); |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 349 | num = params->m * sys_clk_khz; |
| 350 | den = (params->n + 1) * 250 * 1000; |
| 351 | num += den - 1; |
| 352 | sd_div = num / den; |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 353 | clrsetbits_le32((*prcm)->cm_clksel_dpll_usb, |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 354 | CM_CLKSEL_DPLL_DPLL_SD_DIV_MASK, |
| 355 | sd_div << CM_CLKSEL_DPLL_DPLL_SD_DIV_SHIFT); |
| 356 | |
| 357 | /* Now setup the dpll with the regular function */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 358 | do_setup_dpll((*prcm)->cm_clkmode_dpll_usb, params, DPLL_LOCK, "usb"); |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 359 | } |
| 360 | #endif |
| 361 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 362 | static void setup_dplls(void) |
| 363 | { |
Anatolij Gustschin | 20f2351 | 2011-12-03 06:46:14 +0000 | [diff] [blame] | 364 | u32 temp; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 365 | const struct dpll_params *params; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 366 | |
Anatolij Gustschin | 20f2351 | 2011-12-03 06:46:14 +0000 | [diff] [blame] | 367 | debug("setup_dplls\n"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 368 | |
| 369 | /* CORE dpll */ |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 370 | params = get_core_dpll_params(*dplls_data); /* default - safest */ |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 371 | /* |
| 372 | * Do not lock the core DPLL now. Just set it up. |
| 373 | * Core DPLL will be locked after setting up EMIF |
| 374 | * using the FREQ_UPDATE method(freq_update_core()) |
| 375 | */ |
Lokesh Vutla | fef54c3 | 2013-02-04 04:21:59 +0000 | [diff] [blame] | 376 | if (emif_sdram_type() == EMIF_SDRAM_TYPE_LPDDR2) |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 377 | do_setup_dpll((*prcm)->cm_clkmode_dpll_core, params, |
Lokesh Vutla | cdfc4ea | 2012-05-22 00:03:26 +0000 | [diff] [blame] | 378 | DPLL_NO_LOCK, "core"); |
| 379 | else |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 380 | do_setup_dpll((*prcm)->cm_clkmode_dpll_core, params, |
Lokesh Vutla | cdfc4ea | 2012-05-22 00:03:26 +0000 | [diff] [blame] | 381 | DPLL_LOCK, "core"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 382 | /* Set the ratios for CORE_CLK, L3_CLK, L4_CLK */ |
| 383 | temp = (CLKSEL_CORE_X2_DIV_1 << CLKSEL_CORE_SHIFT) | |
| 384 | (CLKSEL_L3_CORE_DIV_2 << CLKSEL_L3_SHIFT) | |
| 385 | (CLKSEL_L4_L3_DIV_2 << CLKSEL_L4_SHIFT); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 386 | writel(temp, (*prcm)->cm_clksel_core); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 387 | debug("Core DPLL configured\n"); |
| 388 | |
| 389 | /* lock PER dpll */ |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 390 | params = get_per_dpll_params(*dplls_data); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 391 | do_setup_dpll((*prcm)->cm_clkmode_dpll_per, |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 392 | params, DPLL_LOCK, "per"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 393 | debug("PER DPLL locked\n"); |
| 394 | |
| 395 | /* MPU dpll */ |
Aneesh V | a47a79f | 2011-07-21 09:29:36 -0400 | [diff] [blame] | 396 | configure_mpu_dpll(); |
Govindraj.R | ad4426b | 2012-02-06 03:55:36 +0000 | [diff] [blame] | 397 | |
| 398 | #ifdef CONFIG_USB_EHCI_OMAP |
| 399 | setup_usb_dpll(); |
| 400 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 403 | #ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 404 | static void setup_non_essential_dplls(void) |
| 405 | { |
Anatolij Gustschin | d75ffd4 | 2012-03-27 23:13:43 +0000 | [diff] [blame] | 406 | u32 abe_ref_clk; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 407 | const struct dpll_params *params; |
| 408 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 409 | /* IVA */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 410 | clrsetbits_le32((*prcm)->cm_bypclk_dpll_iva, |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 411 | CM_BYPCLK_DPLL_IVA_CLKSEL_MASK, DPLL_IVA_CLKSEL_CORE_X2_DIV_2); |
| 412 | |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 413 | params = get_iva_dpll_params(*dplls_data); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 414 | do_setup_dpll((*prcm)->cm_clkmode_dpll_iva, params, DPLL_LOCK, "iva"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 415 | |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 416 | /* Configure ABE dpll */ |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 417 | params = get_abe_dpll_params(*dplls_data); |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 418 | #ifdef CONFIG_SYS_OMAP_ABE_SYSCK |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 419 | abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_SYSCLK; |
| 420 | #else |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 421 | abe_ref_clk = CM_ABE_PLL_REF_CLKSEL_CLKSEL_32KCLK; |
| 422 | /* |
| 423 | * We need to enable some additional options to achieve |
| 424 | * 196.608MHz from 32768 Hz |
| 425 | */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 426 | setbits_le32((*prcm)->cm_clkmode_dpll_abe, |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 427 | CM_CLKMODE_DPLL_DRIFTGUARD_EN_MASK| |
| 428 | CM_CLKMODE_DPLL_RELOCK_RAMP_EN_MASK| |
| 429 | CM_CLKMODE_DPLL_LPMODE_EN_MASK| |
| 430 | CM_CLKMODE_DPLL_REGM4XEN_MASK); |
| 431 | /* Spend 4 REFCLK cycles at each stage */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 432 | clrsetbits_le32((*prcm)->cm_clkmode_dpll_abe, |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 433 | CM_CLKMODE_DPLL_RAMP_RATE_MASK, |
| 434 | 1 << CM_CLKMODE_DPLL_RAMP_RATE_SHIFT); |
| 435 | #endif |
| 436 | |
| 437 | /* Select the right reference clk */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 438 | clrsetbits_le32((*prcm)->cm_abe_pll_ref_clksel, |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 439 | CM_ABE_PLL_REF_CLKSEL_CLKSEL_MASK, |
| 440 | abe_ref_clk << CM_ABE_PLL_REF_CLKSEL_CLKSEL_SHIFT); |
| 441 | /* Lock the dpll */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 442 | do_setup_dpll((*prcm)->cm_clkmode_dpll_abe, params, DPLL_LOCK, "abe"); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 443 | } |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 444 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 445 | |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 446 | u32 get_offset_code(u32 volt_offset, struct pmic_data *pmic) |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 447 | { |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 448 | u32 offset_code; |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 449 | |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 450 | volt_offset -= pmic->base_offset; |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 451 | |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 452 | offset_code = (volt_offset + pmic->step - 1) / pmic->step; |
Nishanth Menon | a0f45c1 | 2012-03-01 14:17:38 +0000 | [diff] [blame] | 453 | |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 454 | /* |
| 455 | * Offset codes 1-6 all give the base voltage in Palmas |
| 456 | * Offset code 0 switches OFF the SMPS |
| 457 | */ |
| 458 | return offset_code + pmic->start_code; |
Aneesh V | 0fa1d1b | 2011-07-21 09:29:32 -0400 | [diff] [blame] | 459 | } |
| 460 | |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 461 | void do_scale_vcore(u32 vcore_reg, u32 volt_mv, struct pmic_data *pmic) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 462 | { |
Nishanth Menon | 41d7ab1 | 2012-03-01 14:17:37 +0000 | [diff] [blame] | 463 | u32 offset_code; |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 464 | u32 offset = volt_mv; |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 465 | int ret = 0; |
| 466 | |
| 467 | /* See if we can first get the GPIO if needed */ |
| 468 | if (pmic->gpio_en) |
| 469 | ret = gpio_request(pmic->gpio, "PMIC_GPIO"); |
| 470 | |
| 471 | if (ret < 0) { |
| 472 | printf("%s: gpio %d request failed %d\n", __func__, |
| 473 | pmic->gpio, ret); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | /* Pull the GPIO low to select SET0 register, while we program SET1 */ |
| 478 | if (pmic->gpio_en) |
| 479 | gpio_direction_output(pmic->gpio, 0); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 480 | |
| 481 | /* convert to uV for better accuracy in the calculations */ |
| 482 | offset *= 1000; |
| 483 | |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 484 | offset_code = get_offset_code(offset, pmic); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 485 | |
| 486 | debug("do_scale_vcore: volt - %d offset_code - 0x%x\n", volt_mv, |
| 487 | offset_code); |
SRICHARAN R | 698a1f2 | 2012-03-12 02:25:38 +0000 | [diff] [blame] | 488 | |
Nishanth Menon | 41d7ab1 | 2012-03-01 14:17:37 +0000 | [diff] [blame] | 489 | if (omap_vc_bypass_send_value(SMPS_I2C_SLAVE_ADDR, |
| 490 | vcore_reg, offset_code)) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 491 | printf("Scaling voltage failed for 0x%x\n", vcore_reg); |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 492 | |
| 493 | if (pmic->gpio_en) |
| 494 | gpio_direction_output(pmic->gpio, 1); |
| 495 | } |
| 496 | |
| 497 | /* |
| 498 | * Setup the voltages for vdd_mpu, vdd_core, and vdd_iva |
| 499 | * We set the maximum voltages allowed here because Smart-Reflex is not |
| 500 | * enabled in bootloader. Voltage initialization in the kernel will set |
| 501 | * these to the nominal values after enabling Smart-Reflex |
| 502 | */ |
| 503 | void scale_vcores(struct vcores_data const *vcores) |
| 504 | { |
| 505 | omap_vc_init(PRM_VC_I2C_CHANNEL_FREQ_KHZ); |
| 506 | |
| 507 | do_scale_vcore(vcores->core.addr, vcores->core.value, |
| 508 | vcores->core.pmic); |
| 509 | |
| 510 | do_scale_vcore(vcores->mpu.addr, vcores->mpu.value, |
| 511 | vcores->mpu.pmic); |
| 512 | |
| 513 | do_scale_vcore(vcores->mm.addr, vcores->mm.value, |
| 514 | vcores->mm.pmic); |
| 515 | |
| 516 | if (emif_sdram_type() == EMIF_SDRAM_TYPE_DDR3) { |
| 517 | /* Configure LDO SRAM "magic" bits */ |
| 518 | writel(2, (*prcm)->prm_sldo_core_setup); |
| 519 | writel(2, (*prcm)->prm_sldo_mpu_setup); |
| 520 | writel(2, (*prcm)->prm_sldo_mm_setup); |
| 521 | } |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 522 | } |
| 523 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 524 | static inline void enable_clock_domain(u32 const clkctrl_reg, u32 enable_mode) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 525 | { |
| 526 | clrsetbits_le32(clkctrl_reg, CD_CLKCTRL_CLKTRCTRL_MASK, |
| 527 | enable_mode << CD_CLKCTRL_CLKTRCTRL_SHIFT); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 528 | debug("Enable clock domain - %x\n", clkctrl_reg); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 529 | } |
| 530 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 531 | static inline void wait_for_clk_enable(u32 clkctrl_addr) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 532 | { |
| 533 | u32 clkctrl, idlest = MODULE_CLKCTRL_IDLEST_DISABLED; |
| 534 | u32 bound = LDELAY; |
| 535 | |
| 536 | while ((idlest == MODULE_CLKCTRL_IDLEST_DISABLED) || |
| 537 | (idlest == MODULE_CLKCTRL_IDLEST_TRANSITIONING)) { |
| 538 | |
| 539 | clkctrl = readl(clkctrl_addr); |
| 540 | idlest = (clkctrl & MODULE_CLKCTRL_IDLEST_MASK) >> |
| 541 | MODULE_CLKCTRL_IDLEST_SHIFT; |
| 542 | if (--bound == 0) { |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 543 | printf("Clock enable failed for 0x%x idlest 0x%x\n", |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 544 | clkctrl_addr, clkctrl); |
| 545 | return; |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 550 | static inline void enable_clock_module(u32 const clkctrl_addr, u32 enable_mode, |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 551 | u32 wait_for_enable) |
| 552 | { |
| 553 | clrsetbits_le32(clkctrl_addr, MODULE_CLKCTRL_MODULEMODE_MASK, |
| 554 | enable_mode << MODULE_CLKCTRL_MODULEMODE_SHIFT); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 555 | debug("Enable clock module - %x\n", clkctrl_addr); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 556 | if (wait_for_enable) |
| 557 | wait_for_clk_enable(clkctrl_addr); |
| 558 | } |
| 559 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 560 | void freq_update_core(void) |
| 561 | { |
| 562 | u32 freq_config1 = 0; |
| 563 | const struct dpll_params *core_dpll_params; |
SRICHARAN R | 3d53496 | 2012-03-12 02:25:37 +0000 | [diff] [blame] | 564 | u32 omap_rev = omap_revision(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 565 | |
SRICHARAN R | 1a79cab | 2013-02-04 04:22:01 +0000 | [diff] [blame] | 566 | core_dpll_params = get_core_dpll_params(*dplls_data); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 567 | /* Put EMIF clock domain in sw wakeup mode */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 568 | enable_clock_domain((*prcm)->cm_memif_clkstctrl, |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 569 | CD_CLKCTRL_CLKTRCTRL_SW_WKUP); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 570 | wait_for_clk_enable((*prcm)->cm_memif_emif_1_clkctrl); |
| 571 | wait_for_clk_enable((*prcm)->cm_memif_emif_2_clkctrl); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 572 | |
| 573 | freq_config1 = SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK | |
| 574 | SHADOW_FREQ_CONFIG1_DLL_RESET_MASK; |
| 575 | |
| 576 | freq_config1 |= (DPLL_EN_LOCK << SHADOW_FREQ_CONFIG1_DPLL_EN_SHIFT) & |
| 577 | SHADOW_FREQ_CONFIG1_DPLL_EN_MASK; |
| 578 | |
| 579 | freq_config1 |= (core_dpll_params->m2 << |
| 580 | SHADOW_FREQ_CONFIG1_M2_DIV_SHIFT) & |
| 581 | SHADOW_FREQ_CONFIG1_M2_DIV_MASK; |
| 582 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 583 | writel(freq_config1, (*prcm)->cm_shadow_freq_config1); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 584 | if (!wait_on_value(SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK, 0, |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 585 | (u32 *) (*prcm)->cm_shadow_freq_config1, LDELAY)) { |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 586 | puts("FREQ UPDATE procedure failed!!"); |
| 587 | hang(); |
| 588 | } |
| 589 | |
SRICHARAN R | 3d53496 | 2012-03-12 02:25:37 +0000 | [diff] [blame] | 590 | /* |
| 591 | * Putting EMIF in HW_AUTO is seen to be causing issues with |
| 592 | * EMIF clocks and the master DLL. Put EMIF in SW_WKUP |
| 593 | * in OMAP5430 ES1.0 silicon |
| 594 | */ |
| 595 | if (omap_rev != OMAP5430_ES1_0) { |
| 596 | /* Put EMIF clock domain back in hw auto mode */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 597 | enable_clock_domain((*prcm)->cm_memif_clkstctrl, |
SRICHARAN R | 3d53496 | 2012-03-12 02:25:37 +0000 | [diff] [blame] | 598 | CD_CLKCTRL_CLKTRCTRL_HW_AUTO); |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 599 | wait_for_clk_enable((*prcm)->cm_memif_emif_1_clkctrl); |
| 600 | wait_for_clk_enable((*prcm)->cm_memif_emif_2_clkctrl); |
SRICHARAN R | 3d53496 | 2012-03-12 02:25:37 +0000 | [diff] [blame] | 601 | } |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 602 | } |
| 603 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 604 | void bypass_dpll(u32 const base) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 605 | { |
| 606 | do_bypass_dpll(base); |
| 607 | wait_for_bypass(base); |
| 608 | } |
| 609 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 610 | void lock_dpll(u32 const base) |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 611 | { |
| 612 | do_lock_dpll(base); |
| 613 | wait_for_lock(base); |
| 614 | } |
| 615 | |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 616 | void setup_clocks_for_console(void) |
| 617 | { |
| 618 | /* Do not add any spl_debug prints in this function */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 619 | clrsetbits_le32((*prcm)->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK, |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 620 | CD_CLKCTRL_CLKTRCTRL_SW_WKUP << |
| 621 | CD_CLKCTRL_CLKTRCTRL_SHIFT); |
| 622 | |
| 623 | /* Enable all UARTs - console will be on one of them */ |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 624 | clrsetbits_le32((*prcm)->cm_l4per_uart1_clkctrl, |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 625 | MODULE_CLKCTRL_MODULEMODE_MASK, |
| 626 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN << |
| 627 | MODULE_CLKCTRL_MODULEMODE_SHIFT); |
| 628 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 629 | clrsetbits_le32((*prcm)->cm_l4per_uart2_clkctrl, |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 630 | MODULE_CLKCTRL_MODULEMODE_MASK, |
| 631 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN << |
| 632 | MODULE_CLKCTRL_MODULEMODE_SHIFT); |
| 633 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 634 | clrsetbits_le32((*prcm)->cm_l4per_uart3_clkctrl, |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 635 | MODULE_CLKCTRL_MODULEMODE_MASK, |
| 636 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN << |
| 637 | MODULE_CLKCTRL_MODULEMODE_SHIFT); |
| 638 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 639 | clrsetbits_le32((*prcm)->cm_l4per_uart3_clkctrl, |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 640 | MODULE_CLKCTRL_MODULEMODE_MASK, |
| 641 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN << |
| 642 | MODULE_CLKCTRL_MODULEMODE_SHIFT); |
| 643 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 644 | clrsetbits_le32((*prcm)->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK, |
Aneesh V | b8e60b9 | 2011-07-21 09:10:21 -0400 | [diff] [blame] | 645 | CD_CLKCTRL_CLKTRCTRL_HW_AUTO << |
| 646 | CD_CLKCTRL_CLKTRCTRL_SHIFT); |
| 647 | } |
| 648 | |
SRICHARAN R | fb6aa1f | 2013-02-04 04:22:00 +0000 | [diff] [blame] | 649 | void do_enable_clocks(u32 const *clk_domains, |
| 650 | u32 const *clk_modules_hw_auto, |
| 651 | u32 const *clk_modules_explicit_en, |
Sricharan | 9784f1f | 2011-11-15 09:49:58 -0500 | [diff] [blame] | 652 | u8 wait_for_enable) |
| 653 | { |
| 654 | u32 i, max = 100; |
| 655 | |
| 656 | /* Put the clock domains in SW_WKUP mode */ |
| 657 | for (i = 0; (i < max) && clk_domains[i]; i++) { |
| 658 | enable_clock_domain(clk_domains[i], |
| 659 | CD_CLKCTRL_CLKTRCTRL_SW_WKUP); |
| 660 | } |
| 661 | |
| 662 | /* Clock modules that need to be put in HW_AUTO */ |
| 663 | for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) { |
| 664 | enable_clock_module(clk_modules_hw_auto[i], |
| 665 | MODULE_CLKCTRL_MODULEMODE_HW_AUTO, |
| 666 | wait_for_enable); |
| 667 | }; |
| 668 | |
| 669 | /* Clock modules that need to be put in SW_EXPLICIT_EN mode */ |
| 670 | for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) { |
| 671 | enable_clock_module(clk_modules_explicit_en[i], |
| 672 | MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN, |
| 673 | wait_for_enable); |
| 674 | }; |
| 675 | |
| 676 | /* Put the clock domains in HW_AUTO mode now */ |
| 677 | for (i = 0; (i < max) && clk_domains[i]; i++) { |
| 678 | enable_clock_domain(clk_domains[i], |
| 679 | CD_CLKCTRL_CLKTRCTRL_HW_AUTO); |
| 680 | } |
| 681 | } |
| 682 | |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 683 | void prcm_init(void) |
| 684 | { |
Sricharan | 9310ff7 | 2011-11-15 09:49:55 -0500 | [diff] [blame] | 685 | switch (omap_hw_init_context()) { |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 686 | case OMAP_INIT_CONTEXT_SPL: |
| 687 | case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR: |
| 688 | case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH: |
Aneesh V | 9a39088 | 2011-07-21 09:29:29 -0400 | [diff] [blame] | 689 | enable_basic_clocks(); |
SRICHARAN R | 00d328c | 2013-02-04 04:22:02 +0000 | [diff] [blame^] | 690 | scale_vcores(*omap_vcores); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 691 | setup_dplls(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 692 | #ifdef CONFIG_SYS_CLOCKS_ENABLE_ALL |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 693 | setup_non_essential_dplls(); |
| 694 | enable_non_essential_clocks(); |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 695 | #endif |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 696 | break; |
| 697 | default: |
| 698 | break; |
| 699 | } |
Sricharan | 308fe92 | 2011-11-15 09:50:03 -0500 | [diff] [blame] | 700 | |
| 701 | if (OMAP_INIT_CONTEXT_SPL != omap_hw_init_context()) |
| 702 | enable_basic_uboot_clocks(); |
Aneesh V | 0d2628b | 2011-07-21 09:10:07 -0400 | [diff] [blame] | 703 | } |