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