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