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