Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
Randy Dunlap | 01d1144 | 2010-12-01 11:16:35 -0800 | [diff] [blame] | 16 | #include <linux/delay.h> |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Brett Rudley | 3327989 | 2010-10-01 18:03:27 -0700 | [diff] [blame] | 18 | #include <linux/string.h> |
Brett Rudley | c6ac24e | 2010-10-26 11:55:23 -0700 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/pci.h> |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 21 | #include <bcmdefs.h> |
| 22 | #include <osl.h> |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 23 | #include <bcmutils.h> |
| 24 | #include <siutils.h> |
| 25 | #include <bcmdevs.h> |
| 26 | #include <hndsoc.h> |
| 27 | #include <sbchipc.h> |
| 28 | #include <hndpmu.h> |
| 29 | #include "siutils_priv.h" |
| 30 | |
| 31 | #define PMU_ERROR(args) |
| 32 | |
| 33 | #ifdef BCMDBG |
Arend van Spriel | 0bef774 | 2011-02-10 12:03:44 +0100 | [diff] [blame] | 34 | #define PMU_MSG(args) printk args |
Arend van Spriel | db3f94c | 2011-01-25 16:53:40 +0100 | [diff] [blame] | 35 | |
| 36 | /* debug-only definitions */ |
| 37 | /* #define BCMDBG_FORCEHT */ |
| 38 | /* #define CHIPC_UART_ALWAYS_ON */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 39 | #else |
| 40 | #define PMU_MSG(args) |
| 41 | #endif /* BCMDBG */ |
| 42 | |
| 43 | /* To check in verbose debugging messages not intended |
| 44 | * to be on except on private builds. |
| 45 | */ |
| 46 | #define PMU_NONE(args) |
| 47 | |
| 48 | /* PLL controls/clocks */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 49 | static void si_pmu1_pllinit0(si_t *sih, struct osl_info *osh, chipcregs_t *cc, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 50 | u32 xtal); |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 51 | static u32 si_pmu1_cpuclk0(si_t *sih, struct osl_info *osh, chipcregs_t *cc); |
| 52 | static u32 si_pmu1_alpclk0(si_t *sih, struct osl_info *osh, chipcregs_t *cc); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 53 | |
| 54 | /* PMU resources */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 55 | static bool si_pmu_res_depfltr_bb(si_t *sih); |
| 56 | static bool si_pmu_res_depfltr_ncb(si_t *sih); |
| 57 | static bool si_pmu_res_depfltr_paldo(si_t *sih); |
| 58 | static bool si_pmu_res_depfltr_npaldo(si_t *sih); |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 59 | static u32 si_pmu_res_deps(si_t *sih, struct osl_info *osh, chipcregs_t *cc, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 60 | u32 rsrcs, bool all); |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 61 | static uint si_pmu_res_uptime(si_t *sih, struct osl_info *osh, chipcregs_t *cc, |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 62 | u8 rsrc); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 63 | static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 64 | static void si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 65 | struct osl_info *osh, u8 spuravoid); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 66 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 67 | static void si_pmu_set_4330_plldivs(si_t *sih); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 68 | |
| 69 | /* FVCO frequency */ |
| 70 | #define FVCO_880 880000 /* 880MHz */ |
| 71 | #define FVCO_1760 1760000 /* 1760MHz */ |
| 72 | #define FVCO_1440 1440000 /* 1440MHz */ |
| 73 | #define FVCO_960 960000 /* 960MHz */ |
| 74 | |
| 75 | /* Read/write a chipcontrol reg */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 76 | u32 si_pmu_chipcontrol(si_t *sih, uint reg, u32 mask, u32 val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 77 | { |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 78 | si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol_addr), ~0, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 79 | reg); |
| 80 | return si_corereg(sih, SI_CC_IDX, |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 81 | offsetof(chipcregs_t, chipcontrol_data), mask, val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* Read/write a regcontrol reg */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 85 | u32 si_pmu_regcontrol(si_t *sih, uint reg, u32 mask, u32 val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 86 | { |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 87 | si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_addr), ~0, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 88 | reg); |
| 89 | return si_corereg(sih, SI_CC_IDX, |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 90 | offsetof(chipcregs_t, regcontrol_data), mask, val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* Read/write a pllcontrol reg */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 94 | u32 si_pmu_pllcontrol(si_t *sih, uint reg, u32 mask, u32 val) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 95 | { |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 96 | si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pllcontrol_addr), ~0, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 97 | reg); |
| 98 | return si_corereg(sih, SI_CC_IDX, |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 99 | offsetof(chipcregs_t, pllcontrol_data), mask, val); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* PMU PLL update */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 103 | void si_pmu_pllupd(si_t *sih) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 104 | { |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 105 | si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pmucontrol), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 106 | PCTL_PLL_PLLCTL_UPD, PCTL_PLL_PLLCTL_UPD); |
| 107 | } |
| 108 | |
| 109 | /* Setup switcher voltage */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 110 | void si_pmu_set_switcher_voltage(si_t *sih, struct osl_info *osh, u8 bb_voltage, |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 111 | u8 rf_voltage) |
| 112 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 113 | chipcregs_t *cc; |
| 114 | uint origidx; |
| 115 | |
| 116 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 117 | |
| 118 | /* Remember original core before switch to chipc */ |
| 119 | origidx = si_coreidx(sih); |
| 120 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 121 | ASSERT(cc != NULL); |
| 122 | |
| 123 | W_REG(osh, &cc->regcontrol_addr, 0x01); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 124 | W_REG(osh, &cc->regcontrol_data, (u32) (bb_voltage & 0x1f) << 22); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 125 | |
| 126 | W_REG(osh, &cc->regcontrol_addr, 0x00); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 127 | W_REG(osh, &cc->regcontrol_data, (u32) (rf_voltage & 0x1f) << 14); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 128 | |
| 129 | /* Return to original core */ |
| 130 | si_setcoreidx(sih, origidx); |
| 131 | } |
| 132 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 133 | void si_pmu_set_ldo_voltage(si_t *sih, struct osl_info *osh, u8 ldo, u8 voltage) |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 134 | { |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 135 | u8 sr_cntl_shift = 0, rc_shift = 0, shift = 0, mask = 0; |
| 136 | u8 addr = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 137 | |
| 138 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 139 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 140 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 141 | case BCM4336_CHIP_ID: |
| 142 | switch (ldo) { |
| 143 | case SET_LDO_VOLTAGE_CLDO_PWM: |
| 144 | addr = 4; |
| 145 | rc_shift = 1; |
| 146 | mask = 0xf; |
| 147 | break; |
| 148 | case SET_LDO_VOLTAGE_CLDO_BURST: |
| 149 | addr = 4; |
| 150 | rc_shift = 5; |
| 151 | mask = 0xf; |
| 152 | break; |
| 153 | case SET_LDO_VOLTAGE_LNLDO1: |
| 154 | addr = 4; |
| 155 | rc_shift = 17; |
| 156 | mask = 0xf; |
| 157 | break; |
| 158 | default: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 159 | ASSERT(false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | break; |
| 163 | case BCM4330_CHIP_ID: |
| 164 | switch (ldo) { |
| 165 | case SET_LDO_VOLTAGE_CBUCK_PWM: |
| 166 | addr = 3; |
| 167 | rc_shift = 0; |
| 168 | mask = 0x1f; |
| 169 | break; |
| 170 | default: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 171 | ASSERT(false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 172 | break; |
| 173 | } |
| 174 | break; |
| 175 | default: |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 176 | ASSERT(false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 177 | return; |
| 178 | } |
| 179 | |
| 180 | shift = sr_cntl_shift + rc_shift; |
| 181 | |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 182 | si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_addr), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 183 | ~0, addr); |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 184 | si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_data), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 185 | mask << shift, (voltage & mask) << shift); |
| 186 | } |
| 187 | |
| 188 | /* d11 slow to fast clock transition time in slow clock cycles */ |
| 189 | #define D11SCC_SLOW2FAST_TRANSITION 2 |
| 190 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 191 | u16 si_pmu_fast_pwrup_delay(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 192 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 193 | uint delay = PMU_MAX_TRANSITION_DLY; |
| 194 | chipcregs_t *cc; |
| 195 | uint origidx; |
| 196 | #ifdef BCMDBG |
| 197 | char chn[8]; |
| 198 | chn[0] = 0; /* to suppress compile error */ |
| 199 | #endif |
| 200 | |
| 201 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 202 | |
| 203 | /* Remember original core before switch to chipc */ |
| 204 | origidx = si_coreidx(sih); |
| 205 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 206 | ASSERT(cc != NULL); |
| 207 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 208 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 209 | case BCM43224_CHIP_ID: |
| 210 | case BCM43225_CHIP_ID: |
| 211 | case BCM43421_CHIP_ID: |
| 212 | case BCM43235_CHIP_ID: |
| 213 | case BCM43236_CHIP_ID: |
| 214 | case BCM43238_CHIP_ID: |
| 215 | case BCM4331_CHIP_ID: |
| 216 | case BCM6362_CHIP_ID: |
| 217 | case BCM4313_CHIP_ID: |
| 218 | delay = ISSIM_ENAB(sih) ? 70 : 3700; |
| 219 | break; |
| 220 | case BCM4329_CHIP_ID: |
| 221 | if (ISSIM_ENAB(sih)) |
| 222 | delay = 70; |
| 223 | else { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 224 | u32 ilp = si_ilp_clock(sih); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 225 | delay = |
| 226 | (si_pmu_res_uptime(sih, osh, cc, RES4329_HT_AVAIL) + |
| 227 | D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp - |
| 228 | 1) / ilp); |
| 229 | delay = (11 * delay) / 10; |
| 230 | } |
| 231 | break; |
| 232 | case BCM4319_CHIP_ID: |
| 233 | delay = ISSIM_ENAB(sih) ? 70 : 3700; |
| 234 | break; |
| 235 | case BCM4336_CHIP_ID: |
| 236 | if (ISSIM_ENAB(sih)) |
| 237 | delay = 70; |
| 238 | else { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 239 | u32 ilp = si_ilp_clock(sih); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 240 | delay = |
| 241 | (si_pmu_res_uptime(sih, osh, cc, RES4336_HT_AVAIL) + |
| 242 | D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp - |
| 243 | 1) / ilp); |
| 244 | delay = (11 * delay) / 10; |
| 245 | } |
| 246 | break; |
| 247 | case BCM4330_CHIP_ID: |
| 248 | if (ISSIM_ENAB(sih)) |
| 249 | delay = 70; |
| 250 | else { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 251 | u32 ilp = si_ilp_clock(sih); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 252 | delay = |
| 253 | (si_pmu_res_uptime(sih, osh, cc, RES4330_HT_AVAIL) + |
| 254 | D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp - |
| 255 | 1) / ilp); |
| 256 | delay = (11 * delay) / 10; |
| 257 | } |
| 258 | break; |
| 259 | default: |
| 260 | break; |
| 261 | } |
| 262 | /* Return to original core */ |
| 263 | si_setcoreidx(sih, origidx); |
| 264 | |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 265 | return (u16) delay; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 268 | u32 si_pmu_force_ilp(si_t *sih, struct osl_info *osh, bool force) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 269 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 270 | chipcregs_t *cc; |
| 271 | uint origidx; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 272 | u32 oldpmucontrol; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 273 | |
| 274 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 275 | |
| 276 | /* Remember original core before switch to chipc */ |
| 277 | origidx = si_coreidx(sih); |
| 278 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 279 | ASSERT(cc != NULL); |
| 280 | |
| 281 | oldpmucontrol = R_REG(osh, &cc->pmucontrol); |
| 282 | if (force) |
| 283 | W_REG(osh, &cc->pmucontrol, oldpmucontrol & |
| 284 | ~(PCTL_HT_REQ_EN | PCTL_ALP_REQ_EN)); |
| 285 | else |
| 286 | W_REG(osh, &cc->pmucontrol, oldpmucontrol | |
| 287 | (PCTL_HT_REQ_EN | PCTL_ALP_REQ_EN)); |
| 288 | |
| 289 | /* Return to original core */ |
| 290 | si_setcoreidx(sih, origidx); |
| 291 | |
| 292 | return oldpmucontrol; |
| 293 | } |
| 294 | |
| 295 | /* Setup resource up/down timers */ |
| 296 | typedef struct { |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 297 | u8 resnum; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 298 | u16 updown; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 299 | } pmu_res_updown_t; |
| 300 | |
| 301 | /* Change resource dependancies masks */ |
| 302 | typedef struct { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 303 | u32 res_mask; /* resources (chip specific) */ |
Greg Kroah-Hartman | 562c885 | 2010-10-05 11:04:17 -0700 | [diff] [blame] | 304 | s8 action; /* action */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 305 | u32 depend_mask; /* changes to the dependancies mask */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 306 | bool(*filter) (si_t *sih); /* action is taken when filter is NULL or return true */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 307 | } pmu_res_depend_t; |
| 308 | |
| 309 | /* Resource dependancies mask change action */ |
| 310 | #define RES_DEPEND_SET 0 /* Override the dependancies mask */ |
| 311 | #define RES_DEPEND_ADD 1 /* Add to the dependancies mask */ |
| 312 | #define RES_DEPEND_REMOVE -1 /* Remove from the dependancies mask */ |
| 313 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 314 | static const pmu_res_updown_t bcm4328a0_res_updown[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 315 | { |
| 316 | RES4328_EXT_SWITCHER_PWM, 0x0101}, { |
| 317 | RES4328_BB_SWITCHER_PWM, 0x1f01}, { |
| 318 | RES4328_BB_SWITCHER_BURST, 0x010f}, { |
| 319 | RES4328_BB_EXT_SWITCHER_BURST, 0x0101}, { |
| 320 | RES4328_ILP_REQUEST, 0x0202}, { |
| 321 | RES4328_RADIO_SWITCHER_PWM, 0x0f01}, { |
| 322 | RES4328_RADIO_SWITCHER_BURST, 0x0f01}, { |
| 323 | RES4328_ROM_SWITCH, 0x0101}, { |
| 324 | RES4328_PA_REF_LDO, 0x0f01}, { |
| 325 | RES4328_RADIO_LDO, 0x0f01}, { |
| 326 | RES4328_AFE_LDO, 0x0f01}, { |
| 327 | RES4328_PLL_LDO, 0x0f01}, { |
| 328 | RES4328_BG_FILTBYP, 0x0101}, { |
| 329 | RES4328_TX_FILTBYP, 0x0101}, { |
| 330 | RES4328_RX_FILTBYP, 0x0101}, { |
| 331 | RES4328_XTAL_PU, 0x0101}, { |
| 332 | RES4328_XTAL_EN, 0xa001}, { |
| 333 | RES4328_BB_PLL_FILTBYP, 0x0101}, { |
| 334 | RES4328_RF_PLL_FILTBYP, 0x0101}, { |
| 335 | RES4328_BB_PLL_PU, 0x0701} |
| 336 | }; |
| 337 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 338 | static const pmu_res_depend_t bcm4328a0_res_depend[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 339 | /* Adjust ILP request resource not to force ext/BB switchers into burst mode */ |
| 340 | { |
| 341 | PMURES_BIT(RES4328_ILP_REQUEST), |
| 342 | RES_DEPEND_SET, |
| 343 | PMURES_BIT(RES4328_EXT_SWITCHER_PWM) | |
| 344 | PMURES_BIT(RES4328_BB_SWITCHER_PWM), NULL} |
| 345 | }; |
| 346 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 347 | static const pmu_res_updown_t bcm4325a0_res_updown_qt[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 348 | { |
| 349 | RES4325_HT_AVAIL, 0x0300}, { |
| 350 | RES4325_BBPLL_PWRSW_PU, 0x0101}, { |
| 351 | RES4325_RFPLL_PWRSW_PU, 0x0101}, { |
| 352 | RES4325_ALP_AVAIL, 0x0100}, { |
| 353 | RES4325_XTAL_PU, 0x1000}, { |
| 354 | RES4325_LNLDO1_PU, 0x0800}, { |
| 355 | RES4325_CLDO_CBUCK_PWM, 0x0101}, { |
| 356 | RES4325_CBUCK_PWM, 0x0803} |
| 357 | }; |
| 358 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 359 | static const pmu_res_updown_t bcm4325a0_res_updown[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 360 | { |
| 361 | RES4325_XTAL_PU, 0x1501} |
| 362 | }; |
| 363 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 364 | static const pmu_res_depend_t bcm4325a0_res_depend[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 365 | /* Adjust OTP PU resource dependencies - remove BB BURST */ |
| 366 | { |
| 367 | PMURES_BIT(RES4325_OTP_PU), |
| 368 | RES_DEPEND_REMOVE, |
| 369 | PMURES_BIT(RES4325_BUCK_BOOST_BURST), NULL}, |
| 370 | /* Adjust ALP/HT Avail resource dependencies - bring up BB along if it is used. */ |
| 371 | { |
| 372 | PMURES_BIT(RES4325_ALP_AVAIL) | PMURES_BIT(RES4325_HT_AVAIL), |
| 373 | RES_DEPEND_ADD, |
| 374 | PMURES_BIT(RES4325_BUCK_BOOST_BURST) | |
| 375 | PMURES_BIT(RES4325_BUCK_BOOST_PWM), si_pmu_res_depfltr_bb}, |
| 376 | /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */ |
| 377 | { |
| 378 | PMURES_BIT(RES4325_HT_AVAIL), |
| 379 | RES_DEPEND_ADD, |
| 380 | PMURES_BIT(RES4325_RX_PWRSW_PU) | |
| 381 | PMURES_BIT(RES4325_TX_PWRSW_PU) | |
| 382 | PMURES_BIT(RES4325_LOGEN_PWRSW_PU) | |
| 383 | PMURES_BIT(RES4325_AFE_PWRSW_PU), NULL}, |
| 384 | /* Adjust ALL resource dependencies - remove CBUCK dependancies if it is not used. */ |
| 385 | { |
| 386 | PMURES_BIT(RES4325_ILP_REQUEST) | |
| 387 | PMURES_BIT(RES4325_ABUCK_BURST) | |
| 388 | PMURES_BIT(RES4325_ABUCK_PWM) | |
| 389 | PMURES_BIT(RES4325_LNLDO1_PU) | |
| 390 | PMURES_BIT(RES4325C1_LNLDO2_PU) | |
| 391 | PMURES_BIT(RES4325_XTAL_PU) | |
| 392 | PMURES_BIT(RES4325_ALP_AVAIL) | |
| 393 | PMURES_BIT(RES4325_RX_PWRSW_PU) | |
| 394 | PMURES_BIT(RES4325_TX_PWRSW_PU) | |
| 395 | PMURES_BIT(RES4325_RFPLL_PWRSW_PU) | |
| 396 | PMURES_BIT(RES4325_LOGEN_PWRSW_PU) | |
| 397 | PMURES_BIT(RES4325_AFE_PWRSW_PU) | |
| 398 | PMURES_BIT(RES4325_BBPLL_PWRSW_PU) | |
| 399 | PMURES_BIT(RES4325_HT_AVAIL), RES_DEPEND_REMOVE, |
| 400 | PMURES_BIT(RES4325B0_CBUCK_LPOM) | |
| 401 | PMURES_BIT(RES4325B0_CBUCK_BURST) | |
| 402 | PMURES_BIT(RES4325B0_CBUCK_PWM), si_pmu_res_depfltr_ncb} |
| 403 | }; |
| 404 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 405 | static const pmu_res_updown_t bcm4315a0_res_updown_qt[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 406 | { |
| 407 | RES4315_HT_AVAIL, 0x0101}, { |
| 408 | RES4315_XTAL_PU, 0x0100}, { |
| 409 | RES4315_LNLDO1_PU, 0x0100}, { |
| 410 | RES4315_PALDO_PU, 0x0100}, { |
| 411 | RES4315_CLDO_PU, 0x0100}, { |
| 412 | RES4315_CBUCK_PWM, 0x0100}, { |
| 413 | RES4315_CBUCK_BURST, 0x0100}, { |
| 414 | RES4315_CBUCK_LPOM, 0x0100} |
| 415 | }; |
| 416 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 417 | static const pmu_res_updown_t bcm4315a0_res_updown[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 418 | { |
| 419 | RES4315_XTAL_PU, 0x2501} |
| 420 | }; |
| 421 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 422 | static const pmu_res_depend_t bcm4315a0_res_depend[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 423 | /* Adjust OTP PU resource dependencies - not need PALDO unless write */ |
| 424 | { |
| 425 | PMURES_BIT(RES4315_OTP_PU), |
| 426 | RES_DEPEND_REMOVE, |
| 427 | PMURES_BIT(RES4315_PALDO_PU), si_pmu_res_depfltr_npaldo}, |
| 428 | /* Adjust ALP/HT Avail resource dependencies - bring up PALDO along if it is used. */ |
| 429 | { |
| 430 | PMURES_BIT(RES4315_ALP_AVAIL) | PMURES_BIT(RES4315_HT_AVAIL), |
| 431 | RES_DEPEND_ADD, |
| 432 | PMURES_BIT(RES4315_PALDO_PU), si_pmu_res_depfltr_paldo}, |
| 433 | /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */ |
| 434 | { |
| 435 | PMURES_BIT(RES4315_HT_AVAIL), |
| 436 | RES_DEPEND_ADD, |
| 437 | PMURES_BIT(RES4315_RX_PWRSW_PU) | |
| 438 | PMURES_BIT(RES4315_TX_PWRSW_PU) | |
| 439 | PMURES_BIT(RES4315_LOGEN_PWRSW_PU) | |
| 440 | PMURES_BIT(RES4315_AFE_PWRSW_PU), NULL}, |
| 441 | /* Adjust ALL resource dependencies - remove CBUCK dependancies if it is not used. */ |
| 442 | { |
| 443 | PMURES_BIT(RES4315_CLDO_PU) | PMURES_BIT(RES4315_ILP_REQUEST) | |
| 444 | PMURES_BIT(RES4315_LNLDO1_PU) | |
| 445 | PMURES_BIT(RES4315_OTP_PU) | |
| 446 | PMURES_BIT(RES4315_LNLDO2_PU) | |
| 447 | PMURES_BIT(RES4315_XTAL_PU) | |
| 448 | PMURES_BIT(RES4315_ALP_AVAIL) | |
| 449 | PMURES_BIT(RES4315_RX_PWRSW_PU) | |
| 450 | PMURES_BIT(RES4315_TX_PWRSW_PU) | |
| 451 | PMURES_BIT(RES4315_RFPLL_PWRSW_PU) | |
| 452 | PMURES_BIT(RES4315_LOGEN_PWRSW_PU) | |
| 453 | PMURES_BIT(RES4315_AFE_PWRSW_PU) | |
| 454 | PMURES_BIT(RES4315_BBPLL_PWRSW_PU) | |
| 455 | PMURES_BIT(RES4315_HT_AVAIL), RES_DEPEND_REMOVE, |
| 456 | PMURES_BIT(RES4315_CBUCK_LPOM) | |
| 457 | PMURES_BIT(RES4315_CBUCK_BURST) | |
| 458 | PMURES_BIT(RES4315_CBUCK_PWM), si_pmu_res_depfltr_ncb} |
| 459 | }; |
| 460 | |
| 461 | /* 4329 specific. needs to come back this issue later */ |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 462 | static const pmu_res_updown_t bcm4329_res_updown[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 463 | { |
| 464 | RES4329_XTAL_PU, 0x1501} |
| 465 | }; |
| 466 | |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 467 | static const pmu_res_depend_t bcm4329_res_depend[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 468 | /* Adjust HT Avail resource dependencies */ |
| 469 | { |
| 470 | PMURES_BIT(RES4329_HT_AVAIL), |
| 471 | RES_DEPEND_ADD, |
| 472 | PMURES_BIT(RES4329_CBUCK_LPOM) | |
| 473 | PMURES_BIT(RES4329_CBUCK_BURST) | |
| 474 | PMURES_BIT(RES4329_CBUCK_PWM) | |
| 475 | PMURES_BIT(RES4329_CLDO_PU) | |
| 476 | PMURES_BIT(RES4329_PALDO_PU) | |
| 477 | PMURES_BIT(RES4329_LNLDO1_PU) | |
| 478 | PMURES_BIT(RES4329_XTAL_PU) | |
| 479 | PMURES_BIT(RES4329_ALP_AVAIL) | |
| 480 | PMURES_BIT(RES4329_RX_PWRSW_PU) | |
| 481 | PMURES_BIT(RES4329_TX_PWRSW_PU) | |
| 482 | PMURES_BIT(RES4329_RFPLL_PWRSW_PU) | |
| 483 | PMURES_BIT(RES4329_LOGEN_PWRSW_PU) | |
| 484 | PMURES_BIT(RES4329_AFE_PWRSW_PU) | |
| 485 | PMURES_BIT(RES4329_BBPLL_PWRSW_PU), NULL} |
| 486 | }; |
| 487 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 488 | static const pmu_res_updown_t bcm4319a0_res_updown_qt[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 489 | { |
| 490 | RES4319_HT_AVAIL, 0x0101}, { |
| 491 | RES4319_XTAL_PU, 0x0100}, { |
| 492 | RES4319_LNLDO1_PU, 0x0100}, { |
| 493 | RES4319_PALDO_PU, 0x0100}, { |
| 494 | RES4319_CLDO_PU, 0x0100}, { |
| 495 | RES4319_CBUCK_PWM, 0x0100}, { |
| 496 | RES4319_CBUCK_BURST, 0x0100}, { |
| 497 | RES4319_CBUCK_LPOM, 0x0100} |
| 498 | }; |
| 499 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 500 | static const pmu_res_updown_t bcm4319a0_res_updown[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 501 | { |
| 502 | RES4319_XTAL_PU, 0x3f01} |
| 503 | }; |
| 504 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 505 | static const pmu_res_depend_t bcm4319a0_res_depend[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 506 | /* Adjust OTP PU resource dependencies - not need PALDO unless write */ |
| 507 | { |
| 508 | PMURES_BIT(RES4319_OTP_PU), |
| 509 | RES_DEPEND_REMOVE, |
| 510 | PMURES_BIT(RES4319_PALDO_PU), si_pmu_res_depfltr_npaldo}, |
| 511 | /* Adjust HT Avail resource dependencies - bring up PALDO along if it is used. */ |
| 512 | { |
| 513 | PMURES_BIT(RES4319_HT_AVAIL), |
| 514 | RES_DEPEND_ADD, |
| 515 | PMURES_BIT(RES4319_PALDO_PU), si_pmu_res_depfltr_paldo}, |
| 516 | /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */ |
| 517 | { |
| 518 | PMURES_BIT(RES4319_HT_AVAIL), |
| 519 | RES_DEPEND_ADD, |
| 520 | PMURES_BIT(RES4319_RX_PWRSW_PU) | |
| 521 | PMURES_BIT(RES4319_TX_PWRSW_PU) | |
| 522 | PMURES_BIT(RES4319_RFPLL_PWRSW_PU) | |
| 523 | PMURES_BIT(RES4319_LOGEN_PWRSW_PU) | |
| 524 | PMURES_BIT(RES4319_AFE_PWRSW_PU), NULL} |
| 525 | }; |
| 526 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 527 | static const pmu_res_updown_t bcm4336a0_res_updown_qt[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 528 | { |
| 529 | RES4336_HT_AVAIL, 0x0101}, { |
| 530 | RES4336_XTAL_PU, 0x0100}, { |
| 531 | RES4336_CLDO_PU, 0x0100}, { |
| 532 | RES4336_CBUCK_PWM, 0x0100}, { |
| 533 | RES4336_CBUCK_BURST, 0x0100}, { |
| 534 | RES4336_CBUCK_LPOM, 0x0100} |
| 535 | }; |
| 536 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 537 | static const pmu_res_updown_t bcm4336a0_res_updown[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 538 | { |
| 539 | RES4336_HT_AVAIL, 0x0D01} |
| 540 | }; |
| 541 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 542 | static const pmu_res_depend_t bcm4336a0_res_depend[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 543 | /* Just a dummy entry for now */ |
| 544 | { |
| 545 | PMURES_BIT(RES4336_RSVD), RES_DEPEND_ADD, 0, NULL} |
| 546 | }; |
| 547 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 548 | static const pmu_res_updown_t bcm4330a0_res_updown_qt[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 549 | { |
| 550 | RES4330_HT_AVAIL, 0x0101}, { |
| 551 | RES4330_XTAL_PU, 0x0100}, { |
| 552 | RES4330_CLDO_PU, 0x0100}, { |
| 553 | RES4330_CBUCK_PWM, 0x0100}, { |
| 554 | RES4330_CBUCK_BURST, 0x0100}, { |
| 555 | RES4330_CBUCK_LPOM, 0x0100} |
| 556 | }; |
| 557 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 558 | static const pmu_res_updown_t bcm4330a0_res_updown[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 559 | { |
| 560 | RES4330_HT_AVAIL, 0x0e02} |
| 561 | }; |
| 562 | |
Greg Kroah-Hartman | 17c4da1 | 2010-10-08 14:11:20 -0700 | [diff] [blame] | 563 | static const pmu_res_depend_t bcm4330a0_res_depend[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 564 | /* Just a dummy entry for now */ |
| 565 | { |
| 566 | PMURES_BIT(RES4330_HT_AVAIL), RES_DEPEND_ADD, 0, NULL} |
| 567 | }; |
| 568 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 569 | /* true if the power topology uses the buck boost to provide 3.3V to VDDIO_RF and WLAN PA */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 570 | static bool si_pmu_res_depfltr_bb(si_t *sih) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 571 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 572 | return (sih->boardflags & BFL_BUCKBOOST) != 0; |
| 573 | } |
| 574 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 575 | /* true if the power topology doesn't use the cbuck. Key on chiprev also if the chip is BCM4325. */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 576 | static bool si_pmu_res_depfltr_ncb(si_t *sih) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 577 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 578 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 579 | return (sih->boardflags & BFL_NOCBUCK) != 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 582 | /* true if the power topology uses the PALDO */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 583 | static bool si_pmu_res_depfltr_paldo(si_t *sih) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 584 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 585 | return (sih->boardflags & BFL_PALDO) != 0; |
| 586 | } |
| 587 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 588 | /* true if the power topology doesn't use the PALDO */ |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 589 | static bool si_pmu_res_depfltr_npaldo(si_t *sih) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 590 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 591 | return (sih->boardflags & BFL_PALDO) == 0; |
| 592 | } |
| 593 | |
| 594 | #define BCM94325_BBVDDIOSD_BOARDS(sih) (sih->boardtype == BCM94325DEVBU_BOARD || \ |
| 595 | sih->boardtype == BCM94325BGABU_BOARD) |
| 596 | |
| 597 | /* Determine min/max rsrc masks. Value 0 leaves hardware at default. */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 598 | static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 599 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 600 | u32 min_mask = 0, max_mask = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 601 | uint rsrcs; |
| 602 | char *val; |
| 603 | |
| 604 | /* # resources */ |
| 605 | rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT; |
| 606 | |
| 607 | /* determine min/max rsrc masks */ |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 608 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 609 | case BCM43224_CHIP_ID: |
| 610 | case BCM43225_CHIP_ID: |
| 611 | case BCM43421_CHIP_ID: |
| 612 | case BCM43235_CHIP_ID: |
| 613 | case BCM43236_CHIP_ID: |
| 614 | case BCM43238_CHIP_ID: |
| 615 | case BCM4331_CHIP_ID: |
| 616 | case BCM6362_CHIP_ID: |
| 617 | /* ??? */ |
| 618 | break; |
| 619 | |
| 620 | case BCM4329_CHIP_ID: |
| 621 | /* 4329 spedific issue. Needs to come back this issue later */ |
| 622 | /* Down to save the power. */ |
| 623 | min_mask = |
| 624 | PMURES_BIT(RES4329_CBUCK_LPOM) | |
| 625 | PMURES_BIT(RES4329_CLDO_PU); |
| 626 | /* Allow (but don't require) PLL to turn on */ |
| 627 | max_mask = 0x3ff63e; |
| 628 | break; |
| 629 | case BCM4319_CHIP_ID: |
| 630 | /* We only need a few resources to be kept on all the time */ |
| 631 | min_mask = PMURES_BIT(RES4319_CBUCK_LPOM) | |
| 632 | PMURES_BIT(RES4319_CLDO_PU); |
| 633 | |
| 634 | /* Allow everything else to be turned on upon requests */ |
| 635 | max_mask = ~(~0 << rsrcs); |
| 636 | break; |
| 637 | case BCM4336_CHIP_ID: |
| 638 | /* Down to save the power. */ |
| 639 | min_mask = |
| 640 | PMURES_BIT(RES4336_CBUCK_LPOM) | PMURES_BIT(RES4336_CLDO_PU) |
| 641 | | PMURES_BIT(RES4336_LDO3P3_PU) | PMURES_BIT(RES4336_OTP_PU) |
| 642 | | PMURES_BIT(RES4336_DIS_INT_RESET_PD); |
| 643 | /* Allow (but don't require) PLL to turn on */ |
| 644 | max_mask = 0x1ffffff; |
| 645 | break; |
| 646 | |
| 647 | case BCM4330_CHIP_ID: |
| 648 | /* Down to save the power. */ |
| 649 | min_mask = |
| 650 | PMURES_BIT(RES4330_CBUCK_LPOM) | PMURES_BIT(RES4330_CLDO_PU) |
| 651 | | PMURES_BIT(RES4330_DIS_INT_RESET_PD) | |
| 652 | PMURES_BIT(RES4330_LDO3P3_PU) | PMURES_BIT(RES4330_OTP_PU); |
| 653 | /* Allow (but don't require) PLL to turn on */ |
| 654 | max_mask = 0xfffffff; |
| 655 | break; |
| 656 | |
| 657 | case BCM4313_CHIP_ID: |
| 658 | min_mask = PMURES_BIT(RES4313_BB_PU_RSRC) | |
| 659 | PMURES_BIT(RES4313_XTAL_PU_RSRC) | |
| 660 | PMURES_BIT(RES4313_ALP_AVAIL_RSRC) | |
| 661 | PMURES_BIT(RES4313_BB_PLL_PWRSW_RSRC); |
| 662 | max_mask = 0xffff; |
| 663 | break; |
| 664 | default: |
| 665 | break; |
| 666 | } |
| 667 | |
| 668 | /* Apply nvram override to min mask */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 669 | val = getvar(NULL, "rmin"); |
| 670 | if (val != NULL) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 671 | PMU_MSG(("Applying rmin=%s to min_mask\n", val)); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 672 | min_mask = (u32) simple_strtoul(val, NULL, 0); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 673 | } |
| 674 | /* Apply nvram override to max mask */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 675 | val = getvar(NULL, "rmax"); |
| 676 | if (val != NULL) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 677 | PMU_MSG(("Applying rmax=%s to max_mask\n", val)); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 678 | max_mask = (u32) simple_strtoul(val, NULL, 0); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | *pmin = min_mask; |
| 682 | *pmax = max_mask; |
| 683 | } |
| 684 | |
| 685 | /* initialize PMU resources */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 686 | void si_pmu_res_init(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 687 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 688 | chipcregs_t *cc; |
| 689 | uint origidx; |
| 690 | const pmu_res_updown_t *pmu_res_updown_table = NULL; |
| 691 | uint pmu_res_updown_table_sz = 0; |
| 692 | const pmu_res_depend_t *pmu_res_depend_table = NULL; |
| 693 | uint pmu_res_depend_table_sz = 0; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 694 | u32 min_mask = 0, max_mask = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 695 | char name[8], *val; |
| 696 | uint i, rsrcs; |
| 697 | |
| 698 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 699 | |
| 700 | /* Remember original core before switch to chipc */ |
| 701 | origidx = si_coreidx(sih); |
| 702 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 703 | ASSERT(cc != NULL); |
| 704 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 705 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 706 | case BCM4329_CHIP_ID: |
| 707 | /* Optimize resources up/down timers */ |
| 708 | if (ISSIM_ENAB(sih)) { |
| 709 | pmu_res_updown_table = NULL; |
| 710 | pmu_res_updown_table_sz = 0; |
| 711 | } else { |
| 712 | pmu_res_updown_table = bcm4329_res_updown; |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 713 | pmu_res_updown_table_sz = ARRAY_SIZE(bcm4329_res_updown); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 714 | } |
| 715 | /* Optimize resources dependencies */ |
| 716 | pmu_res_depend_table = bcm4329_res_depend; |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 717 | pmu_res_depend_table_sz = ARRAY_SIZE(bcm4329_res_depend); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 718 | break; |
| 719 | |
| 720 | case BCM4319_CHIP_ID: |
| 721 | /* Optimize resources up/down timers */ |
| 722 | if (ISSIM_ENAB(sih)) { |
| 723 | pmu_res_updown_table = bcm4319a0_res_updown_qt; |
| 724 | pmu_res_updown_table_sz = |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 725 | ARRAY_SIZE(bcm4319a0_res_updown_qt); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 726 | } else { |
| 727 | pmu_res_updown_table = bcm4319a0_res_updown; |
| 728 | pmu_res_updown_table_sz = |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 729 | ARRAY_SIZE(bcm4319a0_res_updown); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 730 | } |
| 731 | /* Optimize resources dependancies masks */ |
| 732 | pmu_res_depend_table = bcm4319a0_res_depend; |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 733 | pmu_res_depend_table_sz = ARRAY_SIZE(bcm4319a0_res_depend); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case BCM4336_CHIP_ID: |
| 737 | /* Optimize resources up/down timers */ |
| 738 | if (ISSIM_ENAB(sih)) { |
| 739 | pmu_res_updown_table = bcm4336a0_res_updown_qt; |
| 740 | pmu_res_updown_table_sz = |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 741 | ARRAY_SIZE(bcm4336a0_res_updown_qt); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 742 | } else { |
| 743 | pmu_res_updown_table = bcm4336a0_res_updown; |
| 744 | pmu_res_updown_table_sz = |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 745 | ARRAY_SIZE(bcm4336a0_res_updown); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 746 | } |
| 747 | /* Optimize resources dependancies masks */ |
| 748 | pmu_res_depend_table = bcm4336a0_res_depend; |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 749 | pmu_res_depend_table_sz = ARRAY_SIZE(bcm4336a0_res_depend); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case BCM4330_CHIP_ID: |
| 753 | /* Optimize resources up/down timers */ |
| 754 | if (ISSIM_ENAB(sih)) { |
| 755 | pmu_res_updown_table = bcm4330a0_res_updown_qt; |
| 756 | pmu_res_updown_table_sz = |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 757 | ARRAY_SIZE(bcm4330a0_res_updown_qt); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 758 | } else { |
| 759 | pmu_res_updown_table = bcm4330a0_res_updown; |
| 760 | pmu_res_updown_table_sz = |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 761 | ARRAY_SIZE(bcm4330a0_res_updown); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 762 | } |
| 763 | /* Optimize resources dependancies masks */ |
| 764 | pmu_res_depend_table = bcm4330a0_res_depend; |
Greg Kroah-Hartman | 8d3d6a6 | 2010-10-08 11:47:11 -0700 | [diff] [blame] | 765 | pmu_res_depend_table_sz = ARRAY_SIZE(bcm4330a0_res_depend); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | default: |
| 769 | break; |
| 770 | } |
| 771 | |
| 772 | /* # resources */ |
| 773 | rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT; |
| 774 | |
| 775 | /* Program up/down timers */ |
| 776 | while (pmu_res_updown_table_sz--) { |
| 777 | ASSERT(pmu_res_updown_table != NULL); |
| 778 | PMU_MSG(("Changing rsrc %d res_updn_timer to 0x%x\n", |
| 779 | pmu_res_updown_table[pmu_res_updown_table_sz].resnum, |
| 780 | pmu_res_updown_table[pmu_res_updown_table_sz].updown)); |
| 781 | W_REG(osh, &cc->res_table_sel, |
| 782 | pmu_res_updown_table[pmu_res_updown_table_sz].resnum); |
| 783 | W_REG(osh, &cc->res_updn_timer, |
| 784 | pmu_res_updown_table[pmu_res_updown_table_sz].updown); |
| 785 | } |
| 786 | /* Apply nvram overrides to up/down timers */ |
| 787 | for (i = 0; i < rsrcs; i++) { |
| 788 | snprintf(name, sizeof(name), "r%dt", i); |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 789 | val = getvar(NULL, name); |
| 790 | if (val == NULL) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 791 | continue; |
| 792 | PMU_MSG(("Applying %s=%s to rsrc %d res_updn_timer\n", name, |
| 793 | val, i)); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 794 | W_REG(osh, &cc->res_table_sel, (u32) i); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 795 | W_REG(osh, &cc->res_updn_timer, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 796 | (u32) simple_strtoul(val, NULL, 0)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | /* Program resource dependencies table */ |
| 800 | while (pmu_res_depend_table_sz--) { |
| 801 | ASSERT(pmu_res_depend_table != NULL); |
| 802 | if (pmu_res_depend_table[pmu_res_depend_table_sz].filter != NULL |
| 803 | && !(pmu_res_depend_table[pmu_res_depend_table_sz]. |
| 804 | filter) (sih)) |
| 805 | continue; |
| 806 | for (i = 0; i < rsrcs; i++) { |
| 807 | if ((pmu_res_depend_table[pmu_res_depend_table_sz]. |
| 808 | res_mask & PMURES_BIT(i)) == 0) |
| 809 | continue; |
| 810 | W_REG(osh, &cc->res_table_sel, i); |
| 811 | switch (pmu_res_depend_table[pmu_res_depend_table_sz]. |
| 812 | action) { |
| 813 | case RES_DEPEND_SET: |
| 814 | PMU_MSG(("Changing rsrc %d res_dep_mask to 0x%x\n", i, pmu_res_depend_table[pmu_res_depend_table_sz].depend_mask)); |
| 815 | W_REG(osh, &cc->res_dep_mask, |
| 816 | pmu_res_depend_table |
| 817 | [pmu_res_depend_table_sz].depend_mask); |
| 818 | break; |
| 819 | case RES_DEPEND_ADD: |
| 820 | PMU_MSG(("Adding 0x%x to rsrc %d res_dep_mask\n", pmu_res_depend_table[pmu_res_depend_table_sz].depend_mask, i)); |
| 821 | OR_REG(osh, &cc->res_dep_mask, |
| 822 | pmu_res_depend_table |
| 823 | [pmu_res_depend_table_sz].depend_mask); |
| 824 | break; |
| 825 | case RES_DEPEND_REMOVE: |
| 826 | PMU_MSG(("Removing 0x%x from rsrc %d res_dep_mask\n", pmu_res_depend_table[pmu_res_depend_table_sz].depend_mask, i)); |
| 827 | AND_REG(osh, &cc->res_dep_mask, |
| 828 | ~pmu_res_depend_table |
| 829 | [pmu_res_depend_table_sz].depend_mask); |
| 830 | break; |
| 831 | default: |
| 832 | ASSERT(0); |
| 833 | break; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | /* Apply nvram overrides to dependancies masks */ |
| 838 | for (i = 0; i < rsrcs; i++) { |
| 839 | snprintf(name, sizeof(name), "r%dd", i); |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame] | 840 | val = getvar(NULL, name); |
| 841 | if (val == NULL) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 842 | continue; |
| 843 | PMU_MSG(("Applying %s=%s to rsrc %d res_dep_mask\n", name, val, |
| 844 | i)); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 845 | W_REG(osh, &cc->res_table_sel, (u32) i); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 846 | W_REG(osh, &cc->res_dep_mask, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 847 | (u32) simple_strtoul(val, NULL, 0)); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | /* Determine min/max rsrc masks */ |
| 851 | si_pmu_res_masks(sih, &min_mask, &max_mask); |
| 852 | |
| 853 | /* It is required to program max_mask first and then min_mask */ |
| 854 | |
| 855 | /* Program max resource mask */ |
| 856 | |
| 857 | if (max_mask) { |
| 858 | PMU_MSG(("Changing max_res_mask to 0x%x\n", max_mask)); |
| 859 | W_REG(osh, &cc->max_res_mask, max_mask); |
| 860 | } |
| 861 | |
| 862 | /* Program min resource mask */ |
| 863 | |
| 864 | if (min_mask) { |
| 865 | PMU_MSG(("Changing min_res_mask to 0x%x\n", min_mask)); |
| 866 | W_REG(osh, &cc->min_res_mask, min_mask); |
| 867 | } |
| 868 | |
| 869 | /* Add some delay; allow resources to come up and settle. */ |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 870 | mdelay(2); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 871 | |
| 872 | /* Return to original core */ |
| 873 | si_setcoreidx(sih, origidx); |
| 874 | } |
| 875 | |
| 876 | /* setup pll and query clock speed */ |
| 877 | typedef struct { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 878 | u16 freq; |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 879 | u8 xf; |
| 880 | u8 wbint; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 881 | u32 wbfrac; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 882 | } pmu0_xtaltab0_t; |
| 883 | |
| 884 | /* the following table is based on 880Mhz fvco */ |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 885 | static const pmu0_xtaltab0_t pmu0_xtaltab0[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 886 | { |
| 887 | 12000, 1, 73, 349525}, { |
| 888 | 13000, 2, 67, 725937}, { |
| 889 | 14400, 3, 61, 116508}, { |
| 890 | 15360, 4, 57, 305834}, { |
| 891 | 16200, 5, 54, 336579}, { |
| 892 | 16800, 6, 52, 399457}, { |
| 893 | 19200, 7, 45, 873813}, { |
| 894 | 19800, 8, 44, 466033}, { |
| 895 | 20000, 9, 44, 0}, { |
| 896 | 25000, 10, 70, 419430}, { |
| 897 | 26000, 11, 67, 725937}, { |
| 898 | 30000, 12, 58, 699050}, { |
| 899 | 38400, 13, 45, 873813}, { |
| 900 | 40000, 14, 45, 0}, { |
| 901 | 0, 0, 0, 0} |
| 902 | }; |
| 903 | |
| 904 | #define PMU0_XTAL0_DEFAULT 8 |
| 905 | |
| 906 | /* setup pll and query clock speed */ |
| 907 | typedef struct { |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 908 | u16 fref; |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 909 | u8 xf; |
| 910 | u8 p1div; |
| 911 | u8 p2div; |
| 912 | u8 ndiv_int; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 913 | u32 ndiv_frac; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 914 | } pmu1_xtaltab0_t; |
| 915 | |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 916 | static const pmu1_xtaltab0_t pmu1_xtaltab0_880_4329[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 917 | { |
| 918 | 12000, 1, 3, 22, 0x9, 0xFFFFEF}, { |
| 919 | 13000, 2, 1, 6, 0xb, 0x483483}, { |
| 920 | 14400, 3, 1, 10, 0xa, 0x1C71C7}, { |
| 921 | 15360, 4, 1, 5, 0xb, 0x755555}, { |
| 922 | 16200, 5, 1, 10, 0x5, 0x6E9E06}, { |
| 923 | 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, { |
| 924 | 19200, 7, 1, 4, 0xb, 0x755555}, { |
| 925 | 19800, 8, 1, 11, 0x4, 0xA57EB}, { |
| 926 | 20000, 9, 1, 11, 0x4, 0x0}, { |
| 927 | 24000, 10, 3, 11, 0xa, 0x0}, { |
| 928 | 25000, 11, 5, 16, 0xb, 0x0}, { |
| 929 | 26000, 12, 1, 1, 0x21, 0xD89D89}, { |
| 930 | 30000, 13, 3, 8, 0xb, 0x0}, { |
| 931 | 37400, 14, 3, 1, 0x46, 0x969696}, { |
| 932 | 38400, 15, 1, 1, 0x16, 0xEAAAAA}, { |
| 933 | 40000, 16, 1, 2, 0xb, 0}, { |
| 934 | 0, 0, 0, 0, 0, 0} |
| 935 | }; |
| 936 | |
| 937 | /* the following table is based on 880Mhz fvco */ |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 938 | static const pmu1_xtaltab0_t pmu1_xtaltab0_880[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 939 | { |
| 940 | 12000, 1, 3, 22, 0x9, 0xFFFFEF}, { |
| 941 | 13000, 2, 1, 6, 0xb, 0x483483}, { |
| 942 | 14400, 3, 1, 10, 0xa, 0x1C71C7}, { |
| 943 | 15360, 4, 1, 5, 0xb, 0x755555}, { |
| 944 | 16200, 5, 1, 10, 0x5, 0x6E9E06}, { |
| 945 | 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, { |
| 946 | 19200, 7, 1, 4, 0xb, 0x755555}, { |
| 947 | 19800, 8, 1, 11, 0x4, 0xA57EB}, { |
| 948 | 20000, 9, 1, 11, 0x4, 0x0}, { |
| 949 | 24000, 10, 3, 11, 0xa, 0x0}, { |
| 950 | 25000, 11, 5, 16, 0xb, 0x0}, { |
| 951 | 26000, 12, 1, 2, 0x10, 0xEC4EC4}, { |
| 952 | 30000, 13, 3, 8, 0xb, 0x0}, { |
| 953 | 33600, 14, 1, 2, 0xd, 0x186186}, { |
| 954 | 38400, 15, 1, 2, 0xb, 0x755555}, { |
| 955 | 40000, 16, 1, 2, 0xb, 0}, { |
| 956 | 0, 0, 0, 0, 0, 0} |
| 957 | }; |
| 958 | |
| 959 | #define PMU1_XTALTAB0_880_12000K 0 |
| 960 | #define PMU1_XTALTAB0_880_13000K 1 |
| 961 | #define PMU1_XTALTAB0_880_14400K 2 |
| 962 | #define PMU1_XTALTAB0_880_15360K 3 |
| 963 | #define PMU1_XTALTAB0_880_16200K 4 |
| 964 | #define PMU1_XTALTAB0_880_16800K 5 |
| 965 | #define PMU1_XTALTAB0_880_19200K 6 |
| 966 | #define PMU1_XTALTAB0_880_19800K 7 |
| 967 | #define PMU1_XTALTAB0_880_20000K 8 |
| 968 | #define PMU1_XTALTAB0_880_24000K 9 |
| 969 | #define PMU1_XTALTAB0_880_25000K 10 |
| 970 | #define PMU1_XTALTAB0_880_26000K 11 |
| 971 | #define PMU1_XTALTAB0_880_30000K 12 |
| 972 | #define PMU1_XTALTAB0_880_37400K 13 |
| 973 | #define PMU1_XTALTAB0_880_38400K 14 |
| 974 | #define PMU1_XTALTAB0_880_40000K 15 |
| 975 | |
| 976 | /* the following table is based on 1760Mhz fvco */ |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 977 | static const pmu1_xtaltab0_t pmu1_xtaltab0_1760[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 978 | { |
| 979 | 12000, 1, 3, 44, 0x9, 0xFFFFEF}, { |
| 980 | 13000, 2, 1, 12, 0xb, 0x483483}, { |
| 981 | 14400, 3, 1, 20, 0xa, 0x1C71C7}, { |
| 982 | 15360, 4, 1, 10, 0xb, 0x755555}, { |
| 983 | 16200, 5, 1, 20, 0x5, 0x6E9E06}, { |
| 984 | 16800, 6, 1, 20, 0x5, 0x3Cf3Cf}, { |
| 985 | 19200, 7, 1, 18, 0x5, 0x17B425}, { |
| 986 | 19800, 8, 1, 22, 0x4, 0xA57EB}, { |
| 987 | 20000, 9, 1, 22, 0x4, 0x0}, { |
| 988 | 24000, 10, 3, 22, 0xa, 0x0}, { |
| 989 | 25000, 11, 5, 32, 0xb, 0x0}, { |
| 990 | 26000, 12, 1, 4, 0x10, 0xEC4EC4}, { |
| 991 | 30000, 13, 3, 16, 0xb, 0x0}, { |
| 992 | 38400, 14, 1, 10, 0x4, 0x955555}, { |
| 993 | 40000, 15, 1, 4, 0xb, 0}, { |
| 994 | 0, 0, 0, 0, 0, 0} |
| 995 | }; |
| 996 | |
| 997 | /* table index */ |
| 998 | #define PMU1_XTALTAB0_1760_12000K 0 |
| 999 | #define PMU1_XTALTAB0_1760_13000K 1 |
| 1000 | #define PMU1_XTALTAB0_1760_14400K 2 |
| 1001 | #define PMU1_XTALTAB0_1760_15360K 3 |
| 1002 | #define PMU1_XTALTAB0_1760_16200K 4 |
| 1003 | #define PMU1_XTALTAB0_1760_16800K 5 |
| 1004 | #define PMU1_XTALTAB0_1760_19200K 6 |
| 1005 | #define PMU1_XTALTAB0_1760_19800K 7 |
| 1006 | #define PMU1_XTALTAB0_1760_20000K 8 |
| 1007 | #define PMU1_XTALTAB0_1760_24000K 9 |
| 1008 | #define PMU1_XTALTAB0_1760_25000K 10 |
| 1009 | #define PMU1_XTALTAB0_1760_26000K 11 |
| 1010 | #define PMU1_XTALTAB0_1760_30000K 12 |
| 1011 | #define PMU1_XTALTAB0_1760_38400K 13 |
| 1012 | #define PMU1_XTALTAB0_1760_40000K 14 |
| 1013 | |
| 1014 | /* the following table is based on 1440Mhz fvco */ |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 1015 | static const pmu1_xtaltab0_t pmu1_xtaltab0_1440[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1016 | { |
| 1017 | 12000, 1, 1, 1, 0x78, 0x0}, { |
| 1018 | 13000, 2, 1, 1, 0x6E, 0xC4EC4E}, { |
| 1019 | 14400, 3, 1, 1, 0x64, 0x0}, { |
| 1020 | 15360, 4, 1, 1, 0x5D, 0xC00000}, { |
| 1021 | 16200, 5, 1, 1, 0x58, 0xE38E38}, { |
| 1022 | 16800, 6, 1, 1, 0x55, 0xB6DB6D}, { |
| 1023 | 19200, 7, 1, 1, 0x4B, 0}, { |
| 1024 | 19800, 8, 1, 1, 0x48, 0xBA2E8B}, { |
| 1025 | 20000, 9, 1, 1, 0x48, 0x0}, { |
| 1026 | 25000, 10, 1, 1, 0x39, 0x999999}, { |
| 1027 | 26000, 11, 1, 1, 0x37, 0x627627}, { |
| 1028 | 30000, 12, 1, 1, 0x30, 0x0}, { |
| 1029 | 37400, 13, 2, 1, 0x4D, 0x15E76}, { |
| 1030 | 38400, 13, 2, 1, 0x4B, 0x0}, { |
| 1031 | 40000, 14, 2, 1, 0x48, 0x0}, { |
| 1032 | 48000, 15, 2, 1, 0x3c, 0x0}, { |
| 1033 | 0, 0, 0, 0, 0, 0} |
| 1034 | }; |
| 1035 | |
| 1036 | /* table index */ |
| 1037 | #define PMU1_XTALTAB0_1440_12000K 0 |
| 1038 | #define PMU1_XTALTAB0_1440_13000K 1 |
| 1039 | #define PMU1_XTALTAB0_1440_14400K 2 |
| 1040 | #define PMU1_XTALTAB0_1440_15360K 3 |
| 1041 | #define PMU1_XTALTAB0_1440_16200K 4 |
| 1042 | #define PMU1_XTALTAB0_1440_16800K 5 |
| 1043 | #define PMU1_XTALTAB0_1440_19200K 6 |
| 1044 | #define PMU1_XTALTAB0_1440_19800K 7 |
| 1045 | #define PMU1_XTALTAB0_1440_20000K 8 |
| 1046 | #define PMU1_XTALTAB0_1440_25000K 9 |
| 1047 | #define PMU1_XTALTAB0_1440_26000K 10 |
| 1048 | #define PMU1_XTALTAB0_1440_30000K 11 |
| 1049 | #define PMU1_XTALTAB0_1440_37400K 12 |
| 1050 | #define PMU1_XTALTAB0_1440_38400K 13 |
| 1051 | #define PMU1_XTALTAB0_1440_40000K 14 |
| 1052 | #define PMU1_XTALTAB0_1440_48000K 15 |
| 1053 | |
| 1054 | #define XTAL_FREQ_24000MHZ 24000 |
| 1055 | #define XTAL_FREQ_30000MHZ 30000 |
| 1056 | #define XTAL_FREQ_37400MHZ 37400 |
| 1057 | #define XTAL_FREQ_48000MHZ 48000 |
| 1058 | |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 1059 | static const pmu1_xtaltab0_t pmu1_xtaltab0_960[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1060 | { |
| 1061 | 12000, 1, 1, 1, 0x50, 0x0}, { |
| 1062 | 13000, 2, 1, 1, 0x49, 0xD89D89}, { |
| 1063 | 14400, 3, 1, 1, 0x42, 0xAAAAAA}, { |
| 1064 | 15360, 4, 1, 1, 0x3E, 0x800000}, { |
| 1065 | 16200, 5, 1, 1, 0x39, 0x425ED0}, { |
| 1066 | 16800, 6, 1, 1, 0x39, 0x249249}, { |
| 1067 | 19200, 7, 1, 1, 0x32, 0x0}, { |
| 1068 | 19800, 8, 1, 1, 0x30, 0x7C1F07}, { |
| 1069 | 20000, 9, 1, 1, 0x30, 0x0}, { |
| 1070 | 25000, 10, 1, 1, 0x26, 0x666666}, { |
| 1071 | 26000, 11, 1, 1, 0x24, 0xEC4EC4}, { |
| 1072 | 30000, 12, 1, 1, 0x20, 0x0}, { |
| 1073 | 37400, 13, 2, 1, 0x33, 0x563EF9}, { |
| 1074 | 38400, 14, 2, 1, 0x32, 0x0}, { |
| 1075 | 40000, 15, 2, 1, 0x30, 0x0}, { |
| 1076 | 48000, 16, 2, 1, 0x28, 0x0}, { |
| 1077 | 0, 0, 0, 0, 0, 0} |
| 1078 | }; |
| 1079 | |
| 1080 | /* table index */ |
| 1081 | #define PMU1_XTALTAB0_960_12000K 0 |
| 1082 | #define PMU1_XTALTAB0_960_13000K 1 |
| 1083 | #define PMU1_XTALTAB0_960_14400K 2 |
| 1084 | #define PMU1_XTALTAB0_960_15360K 3 |
| 1085 | #define PMU1_XTALTAB0_960_16200K 4 |
| 1086 | #define PMU1_XTALTAB0_960_16800K 5 |
| 1087 | #define PMU1_XTALTAB0_960_19200K 6 |
| 1088 | #define PMU1_XTALTAB0_960_19800K 7 |
| 1089 | #define PMU1_XTALTAB0_960_20000K 8 |
| 1090 | #define PMU1_XTALTAB0_960_25000K 9 |
| 1091 | #define PMU1_XTALTAB0_960_26000K 10 |
| 1092 | #define PMU1_XTALTAB0_960_30000K 11 |
| 1093 | #define PMU1_XTALTAB0_960_37400K 12 |
| 1094 | #define PMU1_XTALTAB0_960_38400K 13 |
| 1095 | #define PMU1_XTALTAB0_960_40000K 14 |
| 1096 | #define PMU1_XTALTAB0_960_48000K 15 |
| 1097 | |
| 1098 | /* select xtal table for each chip */ |
Jason Cooper | b4f790e | 2010-10-11 10:02:58 -0400 | [diff] [blame] | 1099 | static const pmu1_xtaltab0_t *si_pmu1_xtaltab0(si_t *sih) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1100 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1101 | #ifdef BCMDBG |
| 1102 | char chn[8]; |
| 1103 | #endif |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1104 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1105 | case BCM4329_CHIP_ID: |
| 1106 | return pmu1_xtaltab0_880_4329; |
| 1107 | case BCM4319_CHIP_ID: |
| 1108 | return pmu1_xtaltab0_1440; |
| 1109 | case BCM4336_CHIP_ID: |
| 1110 | return pmu1_xtaltab0_960; |
| 1111 | case BCM4330_CHIP_ID: |
| 1112 | if (CST4330_CHIPMODE_SDIOD(sih->chipst)) |
| 1113 | return pmu1_xtaltab0_960; |
| 1114 | else |
| 1115 | return pmu1_xtaltab0_1440; |
| 1116 | default: |
| 1117 | PMU_MSG(("si_pmu1_xtaltab0: Unknown chipid %s\n", |
| 1118 | bcm_chipname(sih->chip, chn, 8))); |
| 1119 | break; |
| 1120 | } |
| 1121 | ASSERT(0); |
| 1122 | return NULL; |
| 1123 | } |
| 1124 | |
| 1125 | /* select default xtal frequency for each chip */ |
Jason Cooper | b4f790e | 2010-10-11 10:02:58 -0400 | [diff] [blame] | 1126 | static const pmu1_xtaltab0_t *si_pmu1_xtaldef0(si_t *sih) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1127 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1128 | #ifdef BCMDBG |
| 1129 | char chn[8]; |
| 1130 | #endif |
| 1131 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1132 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1133 | case BCM4329_CHIP_ID: |
| 1134 | /* Default to 38400Khz */ |
| 1135 | return &pmu1_xtaltab0_880_4329[PMU1_XTALTAB0_880_38400K]; |
| 1136 | case BCM4319_CHIP_ID: |
| 1137 | /* Default to 30000Khz */ |
| 1138 | return &pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_30000K]; |
| 1139 | case BCM4336_CHIP_ID: |
| 1140 | /* Default to 26000Khz */ |
| 1141 | return &pmu1_xtaltab0_960[PMU1_XTALTAB0_960_26000K]; |
| 1142 | case BCM4330_CHIP_ID: |
| 1143 | /* Default to 37400Khz */ |
| 1144 | if (CST4330_CHIPMODE_SDIOD(sih->chipst)) |
| 1145 | return &pmu1_xtaltab0_960[PMU1_XTALTAB0_960_37400K]; |
| 1146 | else |
| 1147 | return &pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_37400K]; |
| 1148 | default: |
| 1149 | PMU_MSG(("si_pmu1_xtaldef0: Unknown chipid %s\n", |
| 1150 | bcm_chipname(sih->chip, chn, 8))); |
| 1151 | break; |
| 1152 | } |
| 1153 | ASSERT(0); |
| 1154 | return NULL; |
| 1155 | } |
| 1156 | |
| 1157 | /* select default pll fvco for each chip */ |
Jason Cooper | b4f790e | 2010-10-11 10:02:58 -0400 | [diff] [blame] | 1158 | static u32 si_pmu1_pllfvco0(si_t *sih) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1159 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1160 | #ifdef BCMDBG |
| 1161 | char chn[8]; |
| 1162 | #endif |
| 1163 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1164 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1165 | case BCM4329_CHIP_ID: |
| 1166 | return FVCO_880; |
| 1167 | case BCM4319_CHIP_ID: |
| 1168 | return FVCO_1440; |
| 1169 | case BCM4336_CHIP_ID: |
| 1170 | return FVCO_960; |
| 1171 | case BCM4330_CHIP_ID: |
| 1172 | if (CST4330_CHIPMODE_SDIOD(sih->chipst)) |
| 1173 | return FVCO_960; |
| 1174 | else |
| 1175 | return FVCO_1440; |
| 1176 | default: |
| 1177 | PMU_MSG(("si_pmu1_pllfvco0: Unknown chipid %s\n", |
| 1178 | bcm_chipname(sih->chip, chn, 8))); |
| 1179 | break; |
| 1180 | } |
| 1181 | ASSERT(0); |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | /* query alp/xtal clock frequency */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1186 | static u32 |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1187 | si_pmu1_alpclk0(si_t *sih, struct osl_info *osh, chipcregs_t *cc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1188 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1189 | const pmu1_xtaltab0_t *xt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1190 | u32 xf; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1191 | |
| 1192 | /* Find the frequency in the table */ |
| 1193 | xf = (R_REG(osh, &cc->pmucontrol) & PCTL_XTALFREQ_MASK) >> |
| 1194 | PCTL_XTALFREQ_SHIFT; |
| 1195 | for (xt = si_pmu1_xtaltab0(sih); xt != NULL && xt->fref != 0; xt++) |
| 1196 | if (xt->xf == xf) |
| 1197 | break; |
| 1198 | /* Could not find it so assign a default value */ |
| 1199 | if (xt == NULL || xt->fref == 0) |
| 1200 | xt = si_pmu1_xtaldef0(sih); |
| 1201 | ASSERT(xt != NULL && xt->fref != 0); |
| 1202 | |
| 1203 | return xt->fref * 1000; |
| 1204 | } |
| 1205 | |
| 1206 | /* Set up PLL registers in the PMU as per the crystal speed. |
| 1207 | * XtalFreq field in pmucontrol register being 0 indicates the PLL |
| 1208 | * is not programmed and the h/w default is assumed to work, in which |
| 1209 | * case the xtal frequency is unknown to the s/w so we need to call |
| 1210 | * si_pmu1_xtaldef0() wherever it is needed to return a default value. |
| 1211 | */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1212 | static void si_pmu1_pllinit0(si_t *sih, struct osl_info *osh, chipcregs_t *cc, |
| 1213 | u32 xtal) |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 1214 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1215 | const pmu1_xtaltab0_t *xt; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1216 | u32 tmp; |
| 1217 | u32 buf_strength = 0; |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 1218 | u8 ndiv_mode = 1; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1219 | |
| 1220 | /* Use h/w default PLL config */ |
| 1221 | if (xtal == 0) { |
| 1222 | PMU_MSG(("Unspecified xtal frequency, skip PLL configuration\n")); |
| 1223 | return; |
| 1224 | } |
| 1225 | |
| 1226 | /* Find the frequency in the table */ |
| 1227 | for (xt = si_pmu1_xtaltab0(sih); xt != NULL && xt->fref != 0; xt++) |
| 1228 | if (xt->fref == xtal) |
| 1229 | break; |
| 1230 | |
| 1231 | /* Check current PLL state, bail out if it has been programmed or |
| 1232 | * we don't know how to program it. |
| 1233 | */ |
| 1234 | if (xt == NULL || xt->fref == 0) { |
| 1235 | PMU_MSG(("Unsupported xtal frequency %d.%d MHz, skip PLL configuration\n", xtal / 1000, xtal % 1000)); |
| 1236 | return; |
| 1237 | } |
| 1238 | /* for 4319 bootloader already programs the PLL but bootloader does not program the |
| 1239 | PLL4 and PLL5. So Skip this check for 4319 |
| 1240 | */ |
| 1241 | if ((((R_REG(osh, &cc->pmucontrol) & PCTL_XTALFREQ_MASK) >> |
| 1242 | PCTL_XTALFREQ_SHIFT) == xt->xf) && |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1243 | !((sih->chip == BCM4319_CHIP_ID) |
| 1244 | || (sih->chip == BCM4330_CHIP_ID))) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1245 | PMU_MSG(("PLL already programmed for %d.%d MHz\n", |
| 1246 | xt->fref / 1000, xt->fref % 1000)); |
| 1247 | return; |
| 1248 | } |
| 1249 | |
| 1250 | PMU_MSG(("XTAL %d.%d MHz (%d)\n", xtal / 1000, xtal % 1000, xt->xf)); |
| 1251 | PMU_MSG(("Programming PLL for %d.%d MHz\n", xt->fref / 1000, |
| 1252 | xt->fref % 1000)); |
| 1253 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1254 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1255 | case BCM4329_CHIP_ID: |
| 1256 | /* Change the BBPLL drive strength to 8 for all channels */ |
| 1257 | buf_strength = 0x888888; |
| 1258 | AND_REG(osh, &cc->min_res_mask, |
| 1259 | ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) | |
| 1260 | PMURES_BIT(RES4329_HT_AVAIL))); |
| 1261 | AND_REG(osh, &cc->max_res_mask, |
| 1262 | ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) | |
| 1263 | PMURES_BIT(RES4329_HT_AVAIL))); |
| 1264 | SPINWAIT(R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL, |
| 1265 | PMU_MAX_TRANSITION_DLY); |
| 1266 | ASSERT(!(R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL)); |
| 1267 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); |
| 1268 | if (xt->fref == 38400) |
| 1269 | tmp = 0x200024C0; |
| 1270 | else if (xt->fref == 37400) |
| 1271 | tmp = 0x20004500; |
| 1272 | else if (xt->fref == 26000) |
| 1273 | tmp = 0x200024C0; |
| 1274 | else |
| 1275 | tmp = 0x200005C0; /* Chip Dflt Settings */ |
| 1276 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 1277 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 1278 | tmp = |
| 1279 | R_REG(osh, |
| 1280 | &cc->pllcontrol_data) & PMU1_PLL0_PC5_CLK_DRV_MASK; |
| 1281 | if ((xt->fref == 38400) || (xt->fref == 37400) |
| 1282 | || (xt->fref == 26000)) |
| 1283 | tmp |= 0x15; |
| 1284 | else |
| 1285 | tmp |= 0x25; /* Chip Dflt Settings */ |
| 1286 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 1287 | break; |
| 1288 | |
| 1289 | case BCM4319_CHIP_ID: |
| 1290 | /* Change the BBPLL drive strength to 2 for all channels */ |
| 1291 | buf_strength = 0x222222; |
| 1292 | |
| 1293 | /* Make sure the PLL is off */ |
| 1294 | /* WAR65104: Disable the HT_AVAIL resource first and then |
| 1295 | * after a delay (more than downtime for HT_AVAIL) remove the |
| 1296 | * BBPLL resource; backplane clock moves to ALP from HT. |
| 1297 | */ |
| 1298 | AND_REG(osh, &cc->min_res_mask, |
| 1299 | ~(PMURES_BIT(RES4319_HT_AVAIL))); |
| 1300 | AND_REG(osh, &cc->max_res_mask, |
| 1301 | ~(PMURES_BIT(RES4319_HT_AVAIL))); |
| 1302 | |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 1303 | udelay(100); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1304 | AND_REG(osh, &cc->min_res_mask, |
| 1305 | ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU))); |
| 1306 | AND_REG(osh, &cc->max_res_mask, |
| 1307 | ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU))); |
| 1308 | |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 1309 | udelay(100); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1310 | SPINWAIT(R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL, |
| 1311 | PMU_MAX_TRANSITION_DLY); |
| 1312 | ASSERT(!(R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL)); |
| 1313 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); |
| 1314 | tmp = 0x200005c0; |
| 1315 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 1316 | break; |
| 1317 | |
| 1318 | case BCM4336_CHIP_ID: |
| 1319 | AND_REG(osh, &cc->min_res_mask, |
| 1320 | ~(PMURES_BIT(RES4336_HT_AVAIL) | |
| 1321 | PMURES_BIT(RES4336_MACPHY_CLKAVAIL))); |
| 1322 | AND_REG(osh, &cc->max_res_mask, |
| 1323 | ~(PMURES_BIT(RES4336_HT_AVAIL) | |
| 1324 | PMURES_BIT(RES4336_MACPHY_CLKAVAIL))); |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 1325 | udelay(100); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1326 | SPINWAIT(R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL, |
| 1327 | PMU_MAX_TRANSITION_DLY); |
| 1328 | ASSERT(!(R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL)); |
| 1329 | break; |
| 1330 | |
| 1331 | case BCM4330_CHIP_ID: |
| 1332 | AND_REG(osh, &cc->min_res_mask, |
| 1333 | ~(PMURES_BIT(RES4330_HT_AVAIL) | |
| 1334 | PMURES_BIT(RES4330_MACPHY_CLKAVAIL))); |
| 1335 | AND_REG(osh, &cc->max_res_mask, |
| 1336 | ~(PMURES_BIT(RES4330_HT_AVAIL) | |
| 1337 | PMURES_BIT(RES4330_MACPHY_CLKAVAIL))); |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 1338 | udelay(100); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1339 | SPINWAIT(R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL, |
| 1340 | PMU_MAX_TRANSITION_DLY); |
| 1341 | ASSERT(!(R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL)); |
| 1342 | break; |
| 1343 | |
| 1344 | default: |
| 1345 | ASSERT(0); |
| 1346 | } |
| 1347 | |
| 1348 | PMU_MSG(("Done masking\n")); |
| 1349 | |
| 1350 | /* Write p1div and p2div to pllcontrol[0] */ |
| 1351 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 1352 | tmp = R_REG(osh, &cc->pllcontrol_data) & |
| 1353 | ~(PMU1_PLL0_PC0_P1DIV_MASK | PMU1_PLL0_PC0_P2DIV_MASK); |
| 1354 | tmp |= |
| 1355 | ((xt-> |
| 1356 | p1div << PMU1_PLL0_PC0_P1DIV_SHIFT) & PMU1_PLL0_PC0_P1DIV_MASK) | |
| 1357 | ((xt-> |
| 1358 | p2div << PMU1_PLL0_PC0_P2DIV_SHIFT) & PMU1_PLL0_PC0_P2DIV_MASK); |
| 1359 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 1360 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1361 | if ((sih->chip == BCM4330_CHIP_ID)) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1362 | si_pmu_set_4330_plldivs(sih); |
| 1363 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1364 | if ((sih->chip == BCM4329_CHIP_ID) |
Arend van Spriel | ff29ee8 | 2010-12-02 15:44:52 +0100 | [diff] [blame] | 1365 | && (sih->chiprev == 0)) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1366 | |
| 1367 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 1368 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 1369 | tmp = tmp & (~DOT11MAC_880MHZ_CLK_DIVISOR_MASK); |
| 1370 | tmp = tmp | DOT11MAC_880MHZ_CLK_DIVISOR_VAL; |
| 1371 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 1372 | } |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1373 | if ((sih->chip == BCM4319_CHIP_ID) || |
| 1374 | (sih->chip == BCM4336_CHIP_ID) || |
| 1375 | (sih->chip == BCM4330_CHIP_ID)) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1376 | ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MFB; |
| 1377 | else |
| 1378 | ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MASH; |
| 1379 | |
| 1380 | /* Write ndiv_int and ndiv_mode to pllcontrol[2] */ |
| 1381 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 1382 | tmp = R_REG(osh, &cc->pllcontrol_data) & |
| 1383 | ~(PMU1_PLL0_PC2_NDIV_INT_MASK | PMU1_PLL0_PC2_NDIV_MODE_MASK); |
| 1384 | tmp |= |
| 1385 | ((xt-> |
| 1386 | ndiv_int << PMU1_PLL0_PC2_NDIV_INT_SHIFT) & |
| 1387 | PMU1_PLL0_PC2_NDIV_INT_MASK) | ((ndiv_mode << |
| 1388 | PMU1_PLL0_PC2_NDIV_MODE_SHIFT) & |
| 1389 | PMU1_PLL0_PC2_NDIV_MODE_MASK); |
| 1390 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 1391 | |
| 1392 | /* Write ndiv_frac to pllcontrol[3] */ |
| 1393 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); |
| 1394 | tmp = R_REG(osh, &cc->pllcontrol_data) & ~PMU1_PLL0_PC3_NDIV_FRAC_MASK; |
| 1395 | tmp |= ((xt->ndiv_frac << PMU1_PLL0_PC3_NDIV_FRAC_SHIFT) & |
| 1396 | PMU1_PLL0_PC3_NDIV_FRAC_MASK); |
| 1397 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 1398 | |
| 1399 | /* Write clock driving strength to pllcontrol[5] */ |
| 1400 | if (buf_strength) { |
| 1401 | PMU_MSG(("Adjusting PLL buffer drive strength: %x\n", |
| 1402 | buf_strength)); |
| 1403 | |
| 1404 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 1405 | tmp = |
| 1406 | R_REG(osh, |
| 1407 | &cc->pllcontrol_data) & ~PMU1_PLL0_PC5_CLK_DRV_MASK; |
| 1408 | tmp |= (buf_strength << PMU1_PLL0_PC5_CLK_DRV_SHIFT); |
| 1409 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 1410 | } |
| 1411 | |
| 1412 | PMU_MSG(("Done pll\n")); |
| 1413 | |
| 1414 | /* to operate the 4319 usb in 24MHz/48MHz; chipcontrol[2][84:83] needs |
| 1415 | * to be updated. |
| 1416 | */ |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1417 | if ((sih->chip == BCM4319_CHIP_ID) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1418 | && (xt->fref != XTAL_FREQ_30000MHZ)) { |
| 1419 | W_REG(osh, &cc->chipcontrol_addr, PMU1_PLL0_CHIPCTL2); |
| 1420 | tmp = |
| 1421 | R_REG(osh, |
| 1422 | &cc->chipcontrol_data) & ~CCTL_4319USB_XTAL_SEL_MASK; |
| 1423 | if (xt->fref == XTAL_FREQ_24000MHZ) { |
| 1424 | tmp |= |
| 1425 | (CCTL_4319USB_24MHZ_PLL_SEL << |
| 1426 | CCTL_4319USB_XTAL_SEL_SHIFT); |
| 1427 | } else if (xt->fref == XTAL_FREQ_48000MHZ) { |
| 1428 | tmp |= |
| 1429 | (CCTL_4319USB_48MHZ_PLL_SEL << |
| 1430 | CCTL_4319USB_XTAL_SEL_SHIFT); |
| 1431 | } |
| 1432 | W_REG(osh, &cc->chipcontrol_data, tmp); |
| 1433 | } |
| 1434 | |
| 1435 | /* Flush deferred pll control registers writes */ |
| 1436 | if (sih->pmurev >= 2) |
| 1437 | OR_REG(osh, &cc->pmucontrol, PCTL_PLL_PLLCTL_UPD); |
| 1438 | |
| 1439 | /* Write XtalFreq. Set the divisor also. */ |
| 1440 | tmp = R_REG(osh, &cc->pmucontrol) & |
| 1441 | ~(PCTL_ILP_DIV_MASK | PCTL_XTALFREQ_MASK); |
| 1442 | tmp |= (((((xt->fref + 127) / 128) - 1) << PCTL_ILP_DIV_SHIFT) & |
| 1443 | PCTL_ILP_DIV_MASK) | |
| 1444 | ((xt->xf << PCTL_XTALFREQ_SHIFT) & PCTL_XTALFREQ_MASK); |
| 1445 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1446 | if ((sih->chip == BCM4329_CHIP_ID) |
Arend van Spriel | ff29ee8 | 2010-12-02 15:44:52 +0100 | [diff] [blame] | 1447 | && sih->chiprev == 0) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1448 | /* clear the htstretch before clearing HTReqEn */ |
| 1449 | AND_REG(osh, &cc->clkstretch, ~CSTRETCH_HT); |
| 1450 | tmp &= ~PCTL_HT_REQ_EN; |
| 1451 | } |
| 1452 | |
| 1453 | W_REG(osh, &cc->pmucontrol, tmp); |
| 1454 | } |
| 1455 | |
| 1456 | /* query the CPU clock frequency */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1457 | static u32 |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1458 | si_pmu1_cpuclk0(si_t *sih, struct osl_info *osh, chipcregs_t *cc) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1459 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1460 | u32 tmp, m1div; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1461 | #ifdef BCMDBG |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1462 | u32 ndiv_int, ndiv_frac, p2div, p1div, fvco; |
| 1463 | u32 fref; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1464 | #endif |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1465 | u32 FVCO = si_pmu1_pllfvco0(sih); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1466 | |
| 1467 | /* Read m1div from pllcontrol[1] */ |
| 1468 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 1469 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 1470 | m1div = (tmp & PMU1_PLL0_PC1_M1DIV_MASK) >> PMU1_PLL0_PC1_M1DIV_SHIFT; |
| 1471 | |
| 1472 | #ifdef BCMDBG |
| 1473 | /* Read p2div/p1div from pllcontrol[0] */ |
| 1474 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 1475 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 1476 | p2div = (tmp & PMU1_PLL0_PC0_P2DIV_MASK) >> PMU1_PLL0_PC0_P2DIV_SHIFT; |
| 1477 | p1div = (tmp & PMU1_PLL0_PC0_P1DIV_MASK) >> PMU1_PLL0_PC0_P1DIV_SHIFT; |
| 1478 | |
| 1479 | /* Calculate fvco based on xtal freq and ndiv and pdiv */ |
| 1480 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 1481 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 1482 | ndiv_int = |
| 1483 | (tmp & PMU1_PLL0_PC2_NDIV_INT_MASK) >> PMU1_PLL0_PC2_NDIV_INT_SHIFT; |
| 1484 | |
| 1485 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); |
| 1486 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 1487 | ndiv_frac = |
| 1488 | (tmp & PMU1_PLL0_PC3_NDIV_FRAC_MASK) >> |
| 1489 | PMU1_PLL0_PC3_NDIV_FRAC_SHIFT; |
| 1490 | |
| 1491 | fref = si_pmu1_alpclk0(sih, osh, cc) / 1000; |
| 1492 | |
| 1493 | fvco = (fref * ndiv_int) << 8; |
| 1494 | fvco += (fref * (ndiv_frac >> 12)) >> 4; |
| 1495 | fvco += (fref * (ndiv_frac & 0xfff)) >> 12; |
| 1496 | fvco >>= 8; |
| 1497 | fvco *= p2div; |
| 1498 | fvco /= p1div; |
| 1499 | fvco /= 1000; |
| 1500 | fvco *= 1000; |
| 1501 | |
| 1502 | PMU_MSG(("si_pmu1_cpuclk0: ndiv_int %u ndiv_frac %u p2div %u p1div %u fvco %u\n", ndiv_int, ndiv_frac, p2div, p1div, fvco)); |
| 1503 | |
| 1504 | FVCO = fvco; |
| 1505 | #endif /* BCMDBG */ |
| 1506 | |
| 1507 | /* Return ARM/SB clock */ |
| 1508 | return FVCO / m1div * 1000; |
| 1509 | } |
| 1510 | |
| 1511 | /* initialize PLL */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1512 | void si_pmu_pll_init(si_t *sih, struct osl_info *osh, uint xtalfreq) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1513 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1514 | chipcregs_t *cc; |
| 1515 | uint origidx; |
| 1516 | #ifdef BCMDBG |
| 1517 | char chn[8]; |
| 1518 | #endif |
| 1519 | |
| 1520 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 1521 | |
| 1522 | /* Remember original core before switch to chipc */ |
| 1523 | origidx = si_coreidx(sih); |
| 1524 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 1525 | ASSERT(cc != NULL); |
| 1526 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1527 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1528 | case BCM4329_CHIP_ID: |
| 1529 | if (xtalfreq == 0) |
| 1530 | xtalfreq = 38400; |
| 1531 | si_pmu1_pllinit0(sih, osh, cc, xtalfreq); |
| 1532 | break; |
| 1533 | case BCM4313_CHIP_ID: |
| 1534 | case BCM43224_CHIP_ID: |
| 1535 | case BCM43225_CHIP_ID: |
| 1536 | case BCM43421_CHIP_ID: |
| 1537 | case BCM43235_CHIP_ID: |
| 1538 | case BCM43236_CHIP_ID: |
| 1539 | case BCM43238_CHIP_ID: |
| 1540 | case BCM4331_CHIP_ID: |
| 1541 | case BCM6362_CHIP_ID: |
| 1542 | /* ??? */ |
| 1543 | break; |
| 1544 | case BCM4319_CHIP_ID: |
| 1545 | case BCM4336_CHIP_ID: |
| 1546 | case BCM4330_CHIP_ID: |
| 1547 | si_pmu1_pllinit0(sih, osh, cc, xtalfreq); |
| 1548 | break; |
| 1549 | default: |
| 1550 | PMU_MSG(("No PLL init done for chip %s rev %d pmurev %d\n", |
| 1551 | bcm_chipname(sih->chip, chn, 8), sih->chiprev, |
| 1552 | sih->pmurev)); |
| 1553 | break; |
| 1554 | } |
| 1555 | |
| 1556 | #ifdef BCMDBG_FORCEHT |
| 1557 | OR_REG(osh, &cc->clk_ctl_st, CCS_FORCEHT); |
| 1558 | #endif |
| 1559 | |
| 1560 | /* Return to original core */ |
| 1561 | si_setcoreidx(sih, origidx); |
| 1562 | } |
| 1563 | |
| 1564 | /* query alp/xtal clock frequency */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1565 | u32 si_pmu_alp_clock(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1566 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1567 | chipcregs_t *cc; |
| 1568 | uint origidx; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1569 | u32 clock = ALP_CLOCK; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1570 | #ifdef BCMDBG |
| 1571 | char chn[8]; |
| 1572 | #endif |
| 1573 | |
| 1574 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 1575 | |
| 1576 | /* Remember original core before switch to chipc */ |
| 1577 | origidx = si_coreidx(sih); |
| 1578 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 1579 | ASSERT(cc != NULL); |
| 1580 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1581 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1582 | case BCM43224_CHIP_ID: |
| 1583 | case BCM43225_CHIP_ID: |
| 1584 | case BCM43421_CHIP_ID: |
| 1585 | case BCM43235_CHIP_ID: |
| 1586 | case BCM43236_CHIP_ID: |
| 1587 | case BCM43238_CHIP_ID: |
| 1588 | case BCM4331_CHIP_ID: |
| 1589 | case BCM6362_CHIP_ID: |
| 1590 | case BCM4716_CHIP_ID: |
| 1591 | case BCM4748_CHIP_ID: |
| 1592 | case BCM47162_CHIP_ID: |
| 1593 | case BCM4313_CHIP_ID: |
| 1594 | case BCM5357_CHIP_ID: |
| 1595 | /* always 20Mhz */ |
| 1596 | clock = 20000 * 1000; |
| 1597 | break; |
| 1598 | case BCM4329_CHIP_ID: |
| 1599 | case BCM4319_CHIP_ID: |
| 1600 | case BCM4336_CHIP_ID: |
| 1601 | case BCM4330_CHIP_ID: |
| 1602 | |
| 1603 | clock = si_pmu1_alpclk0(sih, osh, cc); |
| 1604 | break; |
| 1605 | case BCM5356_CHIP_ID: |
| 1606 | /* always 25Mhz */ |
| 1607 | clock = 25000 * 1000; |
| 1608 | break; |
| 1609 | default: |
| 1610 | PMU_MSG(("No ALP clock specified " |
| 1611 | "for chip %s rev %d pmurev %d, using default %d Hz\n", |
| 1612 | bcm_chipname(sih->chip, chn, 8), sih->chiprev, |
| 1613 | sih->pmurev, clock)); |
| 1614 | break; |
| 1615 | } |
| 1616 | |
| 1617 | /* Return to original core */ |
| 1618 | si_setcoreidx(sih, origidx); |
| 1619 | return clock; |
| 1620 | } |
| 1621 | |
| 1622 | /* Find the output of the "m" pll divider given pll controls that start with |
| 1623 | * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc. |
| 1624 | */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1625 | static u32 |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1626 | si_pmu5_clock(si_t *sih, struct osl_info *osh, chipcregs_t *cc, uint pll0, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1627 | uint m) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1628 | u32 tmp, div, ndiv, p1, p2, fc; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1629 | |
| 1630 | if ((pll0 & 3) || (pll0 > PMU4716_MAINPLL_PLL0)) { |
| 1631 | PMU_ERROR(("%s: Bad pll0: %d\n", __func__, pll0)); |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
| 1635 | /* Strictly there is an m5 divider, but I'm not sure we use it */ |
| 1636 | if ((m == 0) || (m > 4)) { |
| 1637 | PMU_ERROR(("%s: Bad m divider: %d\n", __func__, m)); |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1641 | if (sih->chip == BCM5357_CHIP_ID) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1642 | /* Detect failure in clock setting */ |
| 1643 | if ((R_REG(osh, &cc->chipstatus) & 0x40000) != 0) { |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1644 | return 133 * 1000000; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | W_REG(osh, &cc->pllcontrol_addr, pll0 + PMU5_PLL_P1P2_OFF); |
| 1649 | (void)R_REG(osh, &cc->pllcontrol_addr); |
| 1650 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 1651 | p1 = (tmp & PMU5_PLL_P1_MASK) >> PMU5_PLL_P1_SHIFT; |
| 1652 | p2 = (tmp & PMU5_PLL_P2_MASK) >> PMU5_PLL_P2_SHIFT; |
| 1653 | |
| 1654 | W_REG(osh, &cc->pllcontrol_addr, pll0 + PMU5_PLL_M14_OFF); |
| 1655 | (void)R_REG(osh, &cc->pllcontrol_addr); |
| 1656 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 1657 | div = (tmp >> ((m - 1) * PMU5_PLL_MDIV_WIDTH)) & PMU5_PLL_MDIV_MASK; |
| 1658 | |
| 1659 | W_REG(osh, &cc->pllcontrol_addr, pll0 + PMU5_PLL_NM5_OFF); |
| 1660 | (void)R_REG(osh, &cc->pllcontrol_addr); |
| 1661 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 1662 | ndiv = (tmp & PMU5_PLL_NDIV_MASK) >> PMU5_PLL_NDIV_SHIFT; |
| 1663 | |
| 1664 | /* Do calculation in Mhz */ |
| 1665 | fc = si_pmu_alp_clock(sih, osh) / 1000000; |
| 1666 | fc = (p1 * ndiv * fc) / p2; |
| 1667 | |
| 1668 | PMU_NONE(("%s: p1=%d, p2=%d, ndiv=%d(0x%x), m%d=%d; fc=%d, clock=%d\n", |
| 1669 | __func__, p1, p2, ndiv, ndiv, m, div, fc, fc / div)); |
| 1670 | |
| 1671 | /* Return clock in Hertz */ |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1672 | return (fc / div) * 1000000; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | /* query backplane clock frequency */ |
| 1676 | /* For designs that feed the same clock to both backplane |
| 1677 | * and CPU just return the CPU clock speed. |
| 1678 | */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1679 | u32 si_pmu_si_clock(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1680 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1681 | chipcregs_t *cc; |
| 1682 | uint origidx; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1683 | u32 clock = HT_CLOCK; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1684 | #ifdef BCMDBG |
| 1685 | char chn[8]; |
| 1686 | #endif |
| 1687 | |
| 1688 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 1689 | |
| 1690 | /* Remember original core before switch to chipc */ |
| 1691 | origidx = si_coreidx(sih); |
| 1692 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 1693 | ASSERT(cc != NULL); |
| 1694 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1695 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1696 | case BCM43224_CHIP_ID: |
| 1697 | case BCM43225_CHIP_ID: |
| 1698 | case BCM43421_CHIP_ID: |
| 1699 | case BCM4331_CHIP_ID: |
| 1700 | case BCM6362_CHIP_ID: |
| 1701 | /* 96MHz backplane clock */ |
| 1702 | clock = 96000 * 1000; |
| 1703 | break; |
| 1704 | case BCM4716_CHIP_ID: |
| 1705 | case BCM4748_CHIP_ID: |
| 1706 | case BCM47162_CHIP_ID: |
| 1707 | clock = |
| 1708 | si_pmu5_clock(sih, osh, cc, PMU4716_MAINPLL_PLL0, |
| 1709 | PMU5_MAINPLL_SI); |
| 1710 | break; |
| 1711 | case BCM4329_CHIP_ID: |
Arend van Spriel | ff29ee8 | 2010-12-02 15:44:52 +0100 | [diff] [blame] | 1712 | if (sih->chiprev == 0) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1713 | clock = 38400 * 1000; |
| 1714 | else |
| 1715 | clock = si_pmu1_cpuclk0(sih, osh, cc); |
| 1716 | break; |
| 1717 | case BCM4319_CHIP_ID: |
| 1718 | case BCM4336_CHIP_ID: |
| 1719 | case BCM4330_CHIP_ID: |
| 1720 | clock = si_pmu1_cpuclk0(sih, osh, cc); |
| 1721 | break; |
| 1722 | case BCM4313_CHIP_ID: |
| 1723 | /* 80MHz backplane clock */ |
| 1724 | clock = 80000 * 1000; |
| 1725 | break; |
| 1726 | case BCM43235_CHIP_ID: |
| 1727 | case BCM43236_CHIP_ID: |
| 1728 | case BCM43238_CHIP_ID: |
| 1729 | clock = |
| 1730 | (cc->chipstatus & CST43236_BP_CLK) ? (120000 * |
| 1731 | 1000) : (96000 * |
| 1732 | 1000); |
| 1733 | break; |
| 1734 | case BCM5356_CHIP_ID: |
| 1735 | clock = |
| 1736 | si_pmu5_clock(sih, osh, cc, PMU5356_MAINPLL_PLL0, |
| 1737 | PMU5_MAINPLL_SI); |
| 1738 | break; |
| 1739 | case BCM5357_CHIP_ID: |
| 1740 | clock = |
| 1741 | si_pmu5_clock(sih, osh, cc, PMU5357_MAINPLL_PLL0, |
| 1742 | PMU5_MAINPLL_SI); |
| 1743 | break; |
| 1744 | default: |
| 1745 | PMU_MSG(("No backplane clock specified " |
| 1746 | "for chip %s rev %d pmurev %d, using default %d Hz\n", |
| 1747 | bcm_chipname(sih->chip, chn, 8), sih->chiprev, |
| 1748 | sih->pmurev, clock)); |
| 1749 | break; |
| 1750 | } |
| 1751 | |
| 1752 | /* Return to original core */ |
| 1753 | si_setcoreidx(sih, origidx); |
| 1754 | return clock; |
| 1755 | } |
| 1756 | |
| 1757 | /* query CPU clock frequency */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1758 | u32 si_pmu_cpu_clock(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1759 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1760 | chipcregs_t *cc; |
| 1761 | uint origidx; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1762 | u32 clock; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1763 | |
| 1764 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 1765 | |
| 1766 | if ((sih->pmurev >= 5) && |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1767 | !((sih->chip == BCM4329_CHIP_ID) || |
| 1768 | (sih->chip == BCM4319_CHIP_ID) || |
| 1769 | (sih->chip == BCM43236_CHIP_ID) || |
| 1770 | (sih->chip == BCM4336_CHIP_ID) || |
| 1771 | (sih->chip == BCM4330_CHIP_ID))) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1772 | uint pll; |
| 1773 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1774 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1775 | case BCM5356_CHIP_ID: |
| 1776 | pll = PMU5356_MAINPLL_PLL0; |
| 1777 | break; |
| 1778 | case BCM5357_CHIP_ID: |
| 1779 | pll = PMU5357_MAINPLL_PLL0; |
| 1780 | break; |
| 1781 | default: |
| 1782 | pll = PMU4716_MAINPLL_PLL0; |
| 1783 | break; |
| 1784 | } |
| 1785 | |
| 1786 | /* Remember original core before switch to chipc */ |
| 1787 | origidx = si_coreidx(sih); |
| 1788 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 1789 | ASSERT(cc != NULL); |
| 1790 | |
| 1791 | clock = si_pmu5_clock(sih, osh, cc, pll, PMU5_MAINPLL_CPU); |
| 1792 | |
| 1793 | /* Return to original core */ |
| 1794 | si_setcoreidx(sih, origidx); |
| 1795 | } else |
| 1796 | clock = si_pmu_si_clock(sih, osh); |
| 1797 | |
| 1798 | return clock; |
| 1799 | } |
| 1800 | |
| 1801 | /* query memory clock frequency */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1802 | u32 si_pmu_mem_clock(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1803 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1804 | chipcregs_t *cc; |
| 1805 | uint origidx; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1806 | u32 clock; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1807 | |
| 1808 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 1809 | |
| 1810 | if ((sih->pmurev >= 5) && |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1811 | !((sih->chip == BCM4329_CHIP_ID) || |
| 1812 | (sih->chip == BCM4319_CHIP_ID) || |
| 1813 | (sih->chip == BCM4330_CHIP_ID) || |
| 1814 | (sih->chip == BCM4336_CHIP_ID) || |
| 1815 | (sih->chip == BCM43236_CHIP_ID))) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1816 | uint pll; |
| 1817 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 1818 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1819 | case BCM5356_CHIP_ID: |
| 1820 | pll = PMU5356_MAINPLL_PLL0; |
| 1821 | break; |
| 1822 | case BCM5357_CHIP_ID: |
| 1823 | pll = PMU5357_MAINPLL_PLL0; |
| 1824 | break; |
| 1825 | default: |
| 1826 | pll = PMU4716_MAINPLL_PLL0; |
| 1827 | break; |
| 1828 | } |
| 1829 | |
| 1830 | /* Remember original core before switch to chipc */ |
| 1831 | origidx = si_coreidx(sih); |
| 1832 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 1833 | ASSERT(cc != NULL); |
| 1834 | |
| 1835 | clock = si_pmu5_clock(sih, osh, cc, pll, PMU5_MAINPLL_MEM); |
| 1836 | |
| 1837 | /* Return to original core */ |
| 1838 | si_setcoreidx(sih, origidx); |
| 1839 | } else { |
| 1840 | clock = si_pmu_si_clock(sih, osh); |
| 1841 | } |
| 1842 | |
| 1843 | return clock; |
| 1844 | } |
| 1845 | |
| 1846 | /* Measure ILP clock frequency */ |
| 1847 | #define ILP_CALC_DUR 10 /* ms, make sure 1000 can be divided by it. */ |
| 1848 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1849 | static u32 ilpcycles_per_sec; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1850 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1851 | u32 si_pmu_ilp_clock(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1852 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1853 | if (ISSIM_ENAB(sih)) |
| 1854 | return ILP_CLOCK; |
| 1855 | |
| 1856 | if (ilpcycles_per_sec == 0) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1857 | u32 start, end, delta; |
| 1858 | u32 origidx = si_coreidx(sih); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1859 | chipcregs_t *cc = si_setcoreidx(sih, SI_CC_IDX); |
| 1860 | ASSERT(cc != NULL); |
| 1861 | start = R_REG(osh, &cc->pmutimer); |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 1862 | mdelay(ILP_CALC_DUR); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1863 | end = R_REG(osh, &cc->pmutimer); |
| 1864 | delta = end - start; |
| 1865 | ilpcycles_per_sec = delta * (1000 / ILP_CALC_DUR); |
| 1866 | si_setcoreidx(sih, origidx); |
| 1867 | } |
| 1868 | |
| 1869 | return ilpcycles_per_sec; |
| 1870 | } |
| 1871 | |
| 1872 | /* SDIO Pad drive strength to select value mappings */ |
| 1873 | typedef struct { |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 1874 | u8 strength; /* Pad Drive Strength in mA */ |
| 1875 | u8 sel; /* Chip-specific select value */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1876 | } sdiod_drive_str_t; |
| 1877 | |
| 1878 | /* SDIO Drive Strength to sel value table for PMU Rev 1 */ |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 1879 | static const sdiod_drive_str_t sdiod_drive_strength_tab1[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1880 | { |
| 1881 | 4, 0x2}, { |
| 1882 | 2, 0x3}, { |
| 1883 | 1, 0x0}, { |
Jason Cooper | 914d69d | 2010-09-14 09:45:46 -0400 | [diff] [blame] | 1884 | 0, 0x0} |
| 1885 | }; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1886 | |
| 1887 | /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */ |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 1888 | static const sdiod_drive_str_t sdiod_drive_strength_tab2[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1889 | { |
| 1890 | 12, 0x7}, { |
| 1891 | 10, 0x6}, { |
| 1892 | 8, 0x5}, { |
| 1893 | 6, 0x4}, { |
| 1894 | 4, 0x2}, { |
| 1895 | 2, 0x1}, { |
Jason Cooper | 914d69d | 2010-09-14 09:45:46 -0400 | [diff] [blame] | 1896 | 0, 0x0} |
| 1897 | }; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1898 | |
| 1899 | /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */ |
Jason Cooper | 2184ccb | 2010-10-11 10:02:57 -0400 | [diff] [blame] | 1900 | static const sdiod_drive_str_t sdiod_drive_strength_tab3[] = { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1901 | { |
| 1902 | 32, 0x7}, { |
| 1903 | 26, 0x6}, { |
| 1904 | 22, 0x5}, { |
| 1905 | 16, 0x4}, { |
| 1906 | 12, 0x3}, { |
| 1907 | 8, 0x2}, { |
| 1908 | 4, 0x1}, { |
Jason Cooper | 914d69d | 2010-09-14 09:45:46 -0400 | [diff] [blame] | 1909 | 0, 0x0} |
| 1910 | }; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1911 | |
| 1912 | #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) |
| 1913 | |
| 1914 | void |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1915 | si_sdiod_drive_strength_init(si_t *sih, struct osl_info *osh, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1916 | u32 drivestrength) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1917 | chipcregs_t *cc; |
| 1918 | uint origidx, intr_val = 0; |
| 1919 | sdiod_drive_str_t *str_tab = NULL; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1920 | u32 str_mask = 0; |
| 1921 | u32 str_shift = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1922 | #ifdef BCMDBG |
| 1923 | char chn[8]; |
| 1924 | #endif |
| 1925 | |
| 1926 | if (!(sih->cccaps & CC_CAP_PMU)) { |
| 1927 | return; |
| 1928 | } |
| 1929 | |
| 1930 | /* Remember original core before switch to chipc */ |
| 1931 | cc = (chipcregs_t *) si_switch_core(sih, CC_CORE_ID, &origidx, |
| 1932 | &intr_val); |
| 1933 | |
| 1934 | switch (SDIOD_DRVSTR_KEY(sih->chip, sih->pmurev)) { |
Nohee Ko | 84b9fac | 2010-09-29 15:56:49 -0700 | [diff] [blame] | 1935 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1): |
| 1936 | str_tab = (sdiod_drive_str_t *)&sdiod_drive_strength_tab1; |
| 1937 | str_mask = 0x30000000; |
| 1938 | str_shift = 28; |
| 1939 | break; |
| 1940 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2): |
| 1941 | case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3): |
| 1942 | str_tab = (sdiod_drive_str_t *)&sdiod_drive_strength_tab2; |
| 1943 | str_mask = 0x00003800; |
| 1944 | str_shift = 11; |
| 1945 | break; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1946 | case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8): |
Jason Cooper | 29c4275 | 2010-09-14 09:45:43 -0400 | [diff] [blame] | 1947 | str_tab = (sdiod_drive_str_t *) &sdiod_drive_strength_tab3; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1948 | str_mask = 0x00003800; |
| 1949 | str_shift = 11; |
| 1950 | break; |
| 1951 | |
| 1952 | default: |
| 1953 | PMU_MSG(("No SDIO Drive strength init done for chip %s rev %d pmurev %d\n", bcm_chipname(sih->chip, chn, 8), sih->chiprev, sih->pmurev)); |
| 1954 | |
| 1955 | break; |
| 1956 | } |
| 1957 | |
| 1958 | if (str_tab != NULL) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 1959 | u32 drivestrength_sel = 0; |
| 1960 | u32 cc_data_temp; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1961 | int i; |
| 1962 | |
| 1963 | for (i = 0; str_tab[i].strength != 0; i++) { |
| 1964 | if (drivestrength >= str_tab[i].strength) { |
| 1965 | drivestrength_sel = str_tab[i].sel; |
| 1966 | break; |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | W_REG(osh, &cc->chipcontrol_addr, 1); |
| 1971 | cc_data_temp = R_REG(osh, &cc->chipcontrol_data); |
| 1972 | cc_data_temp &= ~str_mask; |
| 1973 | drivestrength_sel <<= str_shift; |
| 1974 | cc_data_temp |= drivestrength_sel; |
| 1975 | W_REG(osh, &cc->chipcontrol_data, cc_data_temp); |
| 1976 | |
| 1977 | PMU_MSG(("SDIO: %dmA drive strength selected, set to 0x%08x\n", |
| 1978 | drivestrength, cc_data_temp)); |
| 1979 | } |
| 1980 | |
| 1981 | /* Return to original core */ |
| 1982 | si_restore_core(sih, origidx, intr_val); |
| 1983 | } |
| 1984 | |
| 1985 | /* initialize PMU */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 1986 | void si_pmu_init(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 1987 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1988 | chipcregs_t *cc; |
| 1989 | uint origidx; |
| 1990 | |
| 1991 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 1992 | |
| 1993 | /* Remember original core before switch to chipc */ |
| 1994 | origidx = si_coreidx(sih); |
| 1995 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 1996 | ASSERT(cc != NULL); |
| 1997 | |
| 1998 | if (sih->pmurev == 1) |
| 1999 | AND_REG(osh, &cc->pmucontrol, ~PCTL_NOILP_ON_WAIT); |
| 2000 | else if (sih->pmurev >= 2) |
| 2001 | OR_REG(osh, &cc->pmucontrol, PCTL_NOILP_ON_WAIT); |
| 2002 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2003 | if ((sih->chip == BCM4329_CHIP_ID) && (sih->chiprev == 2)) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2004 | /* Fix for 4329b0 bad LPOM state. */ |
| 2005 | W_REG(osh, &cc->regcontrol_addr, 2); |
| 2006 | OR_REG(osh, &cc->regcontrol_data, 0x100); |
| 2007 | |
| 2008 | W_REG(osh, &cc->regcontrol_addr, 3); |
| 2009 | OR_REG(osh, &cc->regcontrol_data, 0x4); |
| 2010 | } |
| 2011 | |
| 2012 | /* Return to original core */ |
| 2013 | si_setcoreidx(sih, origidx); |
| 2014 | } |
| 2015 | |
| 2016 | /* Return up time in ILP cycles for the given resource. */ |
| 2017 | static uint |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2018 | si_pmu_res_uptime(si_t *sih, struct osl_info *osh, chipcregs_t *cc, |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 2019 | u8 rsrc) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2020 | u32 deps; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2021 | uint up, i, dup, dmax; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2022 | u32 min_mask = 0, max_mask = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2023 | |
| 2024 | /* uptime of resource 'rsrc' */ |
| 2025 | W_REG(osh, &cc->res_table_sel, rsrc); |
| 2026 | up = (R_REG(osh, &cc->res_updn_timer) >> 8) & 0xff; |
| 2027 | |
| 2028 | /* direct dependancies of resource 'rsrc' */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2029 | deps = si_pmu_res_deps(sih, osh, cc, PMURES_BIT(rsrc), false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2030 | for (i = 0; i <= PMURES_MAX_RESNUM; i++) { |
| 2031 | if (!(deps & PMURES_BIT(i))) |
| 2032 | continue; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2033 | deps &= ~si_pmu_res_deps(sih, osh, cc, PMURES_BIT(i), true); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2034 | } |
| 2035 | si_pmu_res_masks(sih, &min_mask, &max_mask); |
| 2036 | deps &= ~min_mask; |
| 2037 | |
| 2038 | /* max uptime of direct dependancies */ |
| 2039 | dmax = 0; |
| 2040 | for (i = 0; i <= PMURES_MAX_RESNUM; i++) { |
| 2041 | if (!(deps & PMURES_BIT(i))) |
| 2042 | continue; |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 2043 | dup = si_pmu_res_uptime(sih, osh, cc, (u8) i); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2044 | if (dmax < dup) |
| 2045 | dmax = dup; |
| 2046 | } |
| 2047 | |
| 2048 | PMU_MSG(("si_pmu_res_uptime: rsrc %u uptime %u(deps 0x%08x uptime %u)\n", rsrc, up, deps, dmax)); |
| 2049 | |
| 2050 | return up + dmax + PMURES_UP_TRANSITION; |
| 2051 | } |
| 2052 | |
| 2053 | /* Return dependancies (direct or all/indirect) for the given resources */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2054 | static u32 |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2055 | si_pmu_res_deps(si_t *sih, struct osl_info *osh, chipcregs_t *cc, u32 rsrcs, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2056 | bool all) |
| 2057 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2058 | u32 deps = 0; |
| 2059 | u32 i; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2060 | |
| 2061 | for (i = 0; i <= PMURES_MAX_RESNUM; i++) { |
| 2062 | if (!(rsrcs & PMURES_BIT(i))) |
| 2063 | continue; |
| 2064 | W_REG(osh, &cc->res_table_sel, i); |
| 2065 | deps |= R_REG(osh, &cc->res_dep_mask); |
| 2066 | } |
| 2067 | |
| 2068 | return !all ? deps : (deps |
| 2069 | ? (deps | |
| 2070 | si_pmu_res_deps(sih, osh, cc, deps, |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2071 | true)) : 0); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | /* power up/down OTP through PMU resources */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2075 | void si_pmu_otp_power(si_t *sih, struct osl_info *osh, bool on) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2076 | { |
| 2077 | chipcregs_t *cc; |
| 2078 | uint origidx; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2079 | u32 rsrcs = 0; /* rsrcs to turn on/off OTP power */ |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2080 | |
| 2081 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 2082 | |
| 2083 | /* Don't do anything if OTP is disabled */ |
| 2084 | if (si_is_otp_disabled(sih)) { |
| 2085 | PMU_MSG(("si_pmu_otp_power: OTP is disabled\n")); |
| 2086 | return; |
| 2087 | } |
| 2088 | |
| 2089 | /* Remember original core before switch to chipc */ |
| 2090 | origidx = si_coreidx(sih); |
| 2091 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 2092 | ASSERT(cc != NULL); |
| 2093 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2094 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2095 | case BCM4329_CHIP_ID: |
| 2096 | rsrcs = PMURES_BIT(RES4329_OTP_PU); |
| 2097 | break; |
| 2098 | case BCM4319_CHIP_ID: |
| 2099 | rsrcs = PMURES_BIT(RES4319_OTP_PU); |
| 2100 | break; |
| 2101 | case BCM4336_CHIP_ID: |
| 2102 | rsrcs = PMURES_BIT(RES4336_OTP_PU); |
| 2103 | break; |
| 2104 | case BCM4330_CHIP_ID: |
| 2105 | rsrcs = PMURES_BIT(RES4330_OTP_PU); |
| 2106 | break; |
| 2107 | default: |
| 2108 | break; |
| 2109 | } |
| 2110 | |
| 2111 | if (rsrcs != 0) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2112 | u32 otps; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2113 | |
| 2114 | /* Figure out the dependancies (exclude min_res_mask) */ |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2115 | u32 deps = si_pmu_res_deps(sih, osh, cc, rsrcs, true); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2116 | u32 min_mask = 0, max_mask = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2117 | si_pmu_res_masks(sih, &min_mask, &max_mask); |
| 2118 | deps &= ~min_mask; |
| 2119 | /* Turn on/off the power */ |
| 2120 | if (on) { |
| 2121 | PMU_MSG(("Adding rsrc 0x%x to min_res_mask\n", |
| 2122 | rsrcs | deps)); |
| 2123 | OR_REG(osh, &cc->min_res_mask, (rsrcs | deps)); |
| 2124 | SPINWAIT(!(R_REG(osh, &cc->res_state) & rsrcs), |
| 2125 | PMU_MAX_TRANSITION_DLY); |
| 2126 | ASSERT(R_REG(osh, &cc->res_state) & rsrcs); |
| 2127 | } else { |
| 2128 | PMU_MSG(("Removing rsrc 0x%x from min_res_mask\n", |
| 2129 | rsrcs | deps)); |
| 2130 | AND_REG(osh, &cc->min_res_mask, ~(rsrcs | deps)); |
| 2131 | } |
| 2132 | |
| 2133 | SPINWAIT((((otps = R_REG(osh, &cc->otpstatus)) & OTPS_READY) != |
| 2134 | (on ? OTPS_READY : 0)), 100); |
| 2135 | ASSERT((otps & OTPS_READY) == (on ? OTPS_READY : 0)); |
| 2136 | if ((otps & OTPS_READY) != (on ? OTPS_READY : 0)) |
| 2137 | PMU_MSG(("OTP ready bit not %s after wait\n", |
| 2138 | (on ? "ON" : "OFF"))); |
| 2139 | } |
| 2140 | |
| 2141 | /* Return to original core */ |
| 2142 | si_setcoreidx(sih, origidx); |
| 2143 | } |
| 2144 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2145 | void si_pmu_rcal(si_t *sih, struct osl_info *osh) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2146 | { |
| 2147 | chipcregs_t *cc; |
| 2148 | uint origidx; |
| 2149 | |
| 2150 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 2151 | |
| 2152 | /* Remember original core before switch to chipc */ |
| 2153 | origidx = si_coreidx(sih); |
| 2154 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 2155 | ASSERT(cc != NULL); |
| 2156 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2157 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2158 | case BCM4329_CHIP_ID:{ |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 2159 | u8 rcal_code; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2160 | u32 val; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2161 | |
| 2162 | /* Kick RCal */ |
| 2163 | W_REG(osh, &cc->chipcontrol_addr, 1); |
| 2164 | |
| 2165 | /* Power Down RCAL Block */ |
| 2166 | AND_REG(osh, &cc->chipcontrol_data, ~0x04); |
| 2167 | |
| 2168 | /* Power Up RCAL block */ |
| 2169 | OR_REG(osh, &cc->chipcontrol_data, 0x04); |
| 2170 | |
| 2171 | /* Wait for completion */ |
| 2172 | SPINWAIT(0 == (R_REG(osh, &cc->chipstatus) & 0x08), |
| 2173 | 10 * 1000 * 1000); |
| 2174 | ASSERT(R_REG(osh, &cc->chipstatus) & 0x08); |
| 2175 | |
| 2176 | /* Drop the LSB to convert from 5 bit code to 4 bit code */ |
| 2177 | rcal_code = |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 2178 | (u8) (R_REG(osh, &cc->chipstatus) >> 5) & 0x0f; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2179 | |
| 2180 | PMU_MSG(("RCal completed, status 0x%x, code 0x%x\n", |
| 2181 | R_REG(osh, &cc->chipstatus), rcal_code)); |
| 2182 | |
| 2183 | /* Write RCal code into pmu_vreg_ctrl[32:29] */ |
| 2184 | W_REG(osh, &cc->regcontrol_addr, 0); |
| 2185 | val = |
| 2186 | R_REG(osh, |
| 2187 | &cc-> |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2188 | regcontrol_data) & ~((u32) 0x07 << 29); |
| 2189 | val |= (u32) (rcal_code & 0x07) << 29; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2190 | W_REG(osh, &cc->regcontrol_data, val); |
| 2191 | W_REG(osh, &cc->regcontrol_addr, 1); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2192 | val = R_REG(osh, &cc->regcontrol_data) & ~(u32) 0x01; |
| 2193 | val |= (u32) ((rcal_code >> 3) & 0x01); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2194 | W_REG(osh, &cc->regcontrol_data, val); |
| 2195 | |
| 2196 | /* Write RCal code into pmu_chip_ctrl[33:30] */ |
| 2197 | W_REG(osh, &cc->chipcontrol_addr, 0); |
| 2198 | val = |
| 2199 | R_REG(osh, |
| 2200 | &cc-> |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2201 | chipcontrol_data) & ~((u32) 0x03 << 30); |
| 2202 | val |= (u32) (rcal_code & 0x03) << 30; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2203 | W_REG(osh, &cc->chipcontrol_data, val); |
| 2204 | W_REG(osh, &cc->chipcontrol_addr, 1); |
| 2205 | val = |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2206 | R_REG(osh, &cc->chipcontrol_data) & ~(u32) 0x03; |
| 2207 | val |= (u32) ((rcal_code >> 2) & 0x03); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2208 | W_REG(osh, &cc->chipcontrol_data, val); |
| 2209 | |
| 2210 | /* Set override in pmu_chip_ctrl[29] */ |
| 2211 | W_REG(osh, &cc->chipcontrol_addr, 0); |
| 2212 | OR_REG(osh, &cc->chipcontrol_data, (0x01 << 29)); |
| 2213 | |
| 2214 | /* Power off RCal block */ |
| 2215 | W_REG(osh, &cc->chipcontrol_addr, 1); |
| 2216 | AND_REG(osh, &cc->chipcontrol_data, ~0x04); |
| 2217 | |
| 2218 | break; |
| 2219 | } |
| 2220 | default: |
| 2221 | break; |
| 2222 | } |
| 2223 | |
| 2224 | /* Return to original core */ |
| 2225 | si_setcoreidx(sih, origidx); |
| 2226 | } |
| 2227 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2228 | void si_pmu_spuravoid(si_t *sih, struct osl_info *osh, u8 spuravoid) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2229 | { |
| 2230 | chipcregs_t *cc; |
| 2231 | uint origidx, intr_val; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2232 | u32 tmp = 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2233 | |
| 2234 | /* Remember original core before switch to chipc */ |
| 2235 | cc = (chipcregs_t *) si_switch_core(sih, CC_CORE_ID, &origidx, |
| 2236 | &intr_val); |
| 2237 | ASSERT(cc != NULL); |
| 2238 | |
| 2239 | /* force the HT off */ |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2240 | if (sih->chip == BCM4336_CHIP_ID) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2241 | tmp = R_REG(osh, &cc->max_res_mask); |
| 2242 | tmp &= ~RES4336_HT_AVAIL; |
| 2243 | W_REG(osh, &cc->max_res_mask, tmp); |
| 2244 | /* wait for the ht to really go away */ |
| 2245 | SPINWAIT(((R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL) == 0), |
| 2246 | 10000); |
| 2247 | ASSERT((R_REG(osh, &cc->clk_ctl_st) & CCS_HTAVAIL) == 0); |
| 2248 | } |
| 2249 | |
| 2250 | /* update the pll changes */ |
| 2251 | si_pmu_spuravoid_pllupdate(sih, cc, osh, spuravoid); |
| 2252 | |
| 2253 | /* enable HT back on */ |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2254 | if (sih->chip == BCM4336_CHIP_ID) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2255 | tmp = R_REG(osh, &cc->max_res_mask); |
| 2256 | tmp |= RES4336_HT_AVAIL; |
| 2257 | W_REG(osh, &cc->max_res_mask, tmp); |
| 2258 | } |
| 2259 | |
| 2260 | /* Return to original core */ |
| 2261 | si_restore_core(sih, origidx, intr_val); |
| 2262 | } |
| 2263 | |
| 2264 | static void |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2265 | si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, struct osl_info *osh, |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 2266 | u8 spuravoid) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2267 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2268 | u32 tmp = 0; |
Greg Kroah-Hartman | 36ef9a1 | 2010-10-05 10:02:49 -0700 | [diff] [blame] | 2269 | u8 phypll_offset = 0; |
| 2270 | u8 bcm5357_bcm43236_p1div[] = { 0x1, 0x5, 0x5 }; |
| 2271 | u8 bcm5357_bcm43236_ndiv[] = { 0x30, 0xf6, 0xfc }; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2272 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2273 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2274 | case BCM5357_CHIP_ID: |
| 2275 | case BCM43235_CHIP_ID: |
| 2276 | case BCM43236_CHIP_ID: |
| 2277 | case BCM43238_CHIP_ID: |
| 2278 | |
| 2279 | /* BCM5357 needs to touch PLL1_PLLCTL[02], so offset PLL0_PLLCTL[02] by 6 */ |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2280 | phypll_offset = (sih->chip == BCM5357_CHIP_ID) ? 6 : 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2281 | |
| 2282 | /* RMW only the P1 divider */ |
| 2283 | W_REG(osh, &cc->pllcontrol_addr, |
| 2284 | PMU1_PLL0_PLLCTL0 + phypll_offset); |
| 2285 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 2286 | tmp &= (~(PMU1_PLL0_PC0_P1DIV_MASK)); |
| 2287 | tmp |= |
| 2288 | (bcm5357_bcm43236_p1div[spuravoid] << |
| 2289 | PMU1_PLL0_PC0_P1DIV_SHIFT); |
| 2290 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 2291 | |
| 2292 | /* RMW only the int feedback divider */ |
| 2293 | W_REG(osh, &cc->pllcontrol_addr, |
| 2294 | PMU1_PLL0_PLLCTL2 + phypll_offset); |
| 2295 | tmp = R_REG(osh, &cc->pllcontrol_data); |
| 2296 | tmp &= ~(PMU1_PLL0_PC2_NDIV_INT_MASK); |
| 2297 | tmp |= |
| 2298 | (bcm5357_bcm43236_ndiv[spuravoid]) << |
| 2299 | PMU1_PLL0_PC2_NDIV_INT_SHIFT; |
| 2300 | W_REG(osh, &cc->pllcontrol_data, tmp); |
| 2301 | |
| 2302 | tmp = 1 << 10; |
| 2303 | break; |
| 2304 | |
| 2305 | case BCM4331_CHIP_ID: |
| 2306 | if (spuravoid == 2) { |
| 2307 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2308 | W_REG(osh, &cc->pllcontrol_data, 0x11500014); |
| 2309 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2310 | W_REG(osh, &cc->pllcontrol_data, 0x0FC00a08); |
| 2311 | } else if (spuravoid == 1) { |
| 2312 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2313 | W_REG(osh, &cc->pllcontrol_data, 0x11500014); |
| 2314 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2315 | W_REG(osh, &cc->pllcontrol_data, 0x0F600a08); |
| 2316 | } else { |
| 2317 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2318 | W_REG(osh, &cc->pllcontrol_data, 0x11100014); |
| 2319 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2320 | W_REG(osh, &cc->pllcontrol_data, 0x03000a08); |
| 2321 | } |
| 2322 | tmp = 1 << 10; |
| 2323 | break; |
| 2324 | |
| 2325 | case BCM43224_CHIP_ID: |
| 2326 | case BCM43225_CHIP_ID: |
| 2327 | case BCM43421_CHIP_ID: |
| 2328 | case BCM6362_CHIP_ID: |
| 2329 | if (spuravoid == 1) { |
| 2330 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2331 | W_REG(osh, &cc->pllcontrol_data, 0x11500010); |
| 2332 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 2333 | W_REG(osh, &cc->pllcontrol_data, 0x000C0C06); |
| 2334 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2335 | W_REG(osh, &cc->pllcontrol_data, 0x0F600a08); |
| 2336 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); |
| 2337 | W_REG(osh, &cc->pllcontrol_data, 0x00000000); |
| 2338 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); |
| 2339 | W_REG(osh, &cc->pllcontrol_data, 0x2001E920); |
| 2340 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 2341 | W_REG(osh, &cc->pllcontrol_data, 0x88888815); |
| 2342 | } else { |
| 2343 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2344 | W_REG(osh, &cc->pllcontrol_data, 0x11100010); |
| 2345 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 2346 | W_REG(osh, &cc->pllcontrol_data, 0x000c0c06); |
| 2347 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2348 | W_REG(osh, &cc->pllcontrol_data, 0x03000a08); |
| 2349 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); |
| 2350 | W_REG(osh, &cc->pllcontrol_data, 0x00000000); |
| 2351 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); |
| 2352 | W_REG(osh, &cc->pllcontrol_data, 0x200005c0); |
| 2353 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 2354 | W_REG(osh, &cc->pllcontrol_data, 0x88888815); |
| 2355 | } |
| 2356 | tmp = 1 << 10; |
| 2357 | break; |
| 2358 | |
| 2359 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2360 | W_REG(osh, &cc->pllcontrol_data, 0x11100008); |
| 2361 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 2362 | W_REG(osh, &cc->pllcontrol_data, 0x0c000c06); |
| 2363 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2364 | W_REG(osh, &cc->pllcontrol_data, 0x03000a08); |
| 2365 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); |
| 2366 | W_REG(osh, &cc->pllcontrol_data, 0x00000000); |
| 2367 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); |
| 2368 | W_REG(osh, &cc->pllcontrol_data, 0x200005c0); |
| 2369 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 2370 | W_REG(osh, &cc->pllcontrol_data, 0x88888855); |
| 2371 | |
| 2372 | tmp = 1 << 10; |
| 2373 | break; |
| 2374 | |
| 2375 | case BCM4716_CHIP_ID: |
| 2376 | case BCM4748_CHIP_ID: |
| 2377 | case BCM47162_CHIP_ID: |
| 2378 | if (spuravoid == 1) { |
| 2379 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2380 | W_REG(osh, &cc->pllcontrol_data, 0x11500060); |
| 2381 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 2382 | W_REG(osh, &cc->pllcontrol_data, 0x080C0C06); |
| 2383 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2384 | W_REG(osh, &cc->pllcontrol_data, 0x0F600000); |
| 2385 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); |
| 2386 | W_REG(osh, &cc->pllcontrol_data, 0x00000000); |
| 2387 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); |
| 2388 | W_REG(osh, &cc->pllcontrol_data, 0x2001E924); |
| 2389 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 2390 | W_REG(osh, &cc->pllcontrol_data, 0x88888815); |
| 2391 | } else { |
| 2392 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2393 | W_REG(osh, &cc->pllcontrol_data, 0x11100060); |
| 2394 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 2395 | W_REG(osh, &cc->pllcontrol_data, 0x080c0c06); |
| 2396 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2397 | W_REG(osh, &cc->pllcontrol_data, 0x03000000); |
| 2398 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); |
| 2399 | W_REG(osh, &cc->pllcontrol_data, 0x00000000); |
| 2400 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); |
| 2401 | W_REG(osh, &cc->pllcontrol_data, 0x200005c0); |
| 2402 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 2403 | W_REG(osh, &cc->pllcontrol_data, 0x88888815); |
| 2404 | } |
| 2405 | |
| 2406 | tmp = 3 << 9; |
| 2407 | break; |
| 2408 | |
| 2409 | case BCM4319_CHIP_ID: |
| 2410 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2411 | W_REG(osh, &cc->pllcontrol_data, 0x11100070); |
| 2412 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 2413 | W_REG(osh, &cc->pllcontrol_data, 0x1014140a); |
| 2414 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 2415 | W_REG(osh, &cc->pllcontrol_data, 0x88888854); |
| 2416 | |
| 2417 | if (spuravoid == 1) { /* spur_avoid ON, enable 41/82/164Mhz clock mode */ |
| 2418 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2419 | W_REG(osh, &cc->pllcontrol_data, 0x05201828); |
| 2420 | } else { /* enable 40/80/160Mhz clock mode */ |
| 2421 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2422 | W_REG(osh, &cc->pllcontrol_data, 0x05001828); |
| 2423 | } |
| 2424 | break; |
| 2425 | case BCM4336_CHIP_ID: |
| 2426 | /* Looks like these are only for default xtal freq 26MHz */ |
| 2427 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); |
| 2428 | W_REG(osh, &cc->pllcontrol_data, 0x02100020); |
| 2429 | |
| 2430 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); |
| 2431 | W_REG(osh, &cc->pllcontrol_data, 0x0C0C0C0C); |
| 2432 | |
| 2433 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); |
| 2434 | W_REG(osh, &cc->pllcontrol_data, 0x01240C0C); |
| 2435 | |
| 2436 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); |
| 2437 | W_REG(osh, &cc->pllcontrol_data, 0x202C2820); |
| 2438 | |
| 2439 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); |
| 2440 | W_REG(osh, &cc->pllcontrol_data, 0x88888825); |
| 2441 | |
| 2442 | W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); |
| 2443 | if (spuravoid == 1) { |
| 2444 | W_REG(osh, &cc->pllcontrol_data, 0x00EC4EC4); |
| 2445 | } else { |
| 2446 | W_REG(osh, &cc->pllcontrol_data, 0x00762762); |
| 2447 | } |
| 2448 | |
| 2449 | tmp = PCTL_PLL_PLLCTL_UPD; |
| 2450 | break; |
| 2451 | |
| 2452 | default: |
| 2453 | PMU_ERROR(("%s: unknown spuravoidance settings for chip %s, not changing PLL\n", __func__, bcm_chipname(sih->chip, chn, 8))); |
| 2454 | break; |
| 2455 | } |
| 2456 | |
| 2457 | tmp |= R_REG(osh, &cc->pmucontrol); |
| 2458 | W_REG(osh, &cc->pmucontrol, tmp); |
| 2459 | } |
| 2460 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2461 | bool si_pmu_is_otp_powered(si_t *sih, struct osl_info *osh) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2462 | { |
| 2463 | uint idx; |
| 2464 | chipcregs_t *cc; |
| 2465 | bool st; |
| 2466 | |
| 2467 | /* Remember original core before switch to chipc */ |
| 2468 | idx = si_coreidx(sih); |
| 2469 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 2470 | ASSERT(cc != NULL); |
| 2471 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2472 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2473 | case BCM4329_CHIP_ID: |
| 2474 | st = (R_REG(osh, &cc->res_state) & PMURES_BIT(RES4329_OTP_PU)) |
| 2475 | != 0; |
| 2476 | break; |
| 2477 | case BCM4319_CHIP_ID: |
| 2478 | st = (R_REG(osh, &cc->res_state) & PMURES_BIT(RES4319_OTP_PU)) |
| 2479 | != 0; |
| 2480 | break; |
| 2481 | case BCM4336_CHIP_ID: |
| 2482 | st = (R_REG(osh, &cc->res_state) & PMURES_BIT(RES4336_OTP_PU)) |
| 2483 | != 0; |
| 2484 | break; |
| 2485 | case BCM4330_CHIP_ID: |
| 2486 | st = (R_REG(osh, &cc->res_state) & PMURES_BIT(RES4330_OTP_PU)) |
| 2487 | != 0; |
| 2488 | break; |
| 2489 | |
| 2490 | /* These chip doesn't use PMU bit to power up/down OTP. OTP always on. |
| 2491 | * Use OTP_INIT command to reset/refresh state. |
| 2492 | */ |
| 2493 | case BCM43224_CHIP_ID: |
| 2494 | case BCM43225_CHIP_ID: |
| 2495 | case BCM43421_CHIP_ID: |
| 2496 | case BCM43236_CHIP_ID: |
| 2497 | case BCM43235_CHIP_ID: |
| 2498 | case BCM43238_CHIP_ID: |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2499 | st = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2500 | break; |
| 2501 | default: |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 2502 | st = true; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2503 | break; |
| 2504 | } |
| 2505 | |
| 2506 | /* Return to original core */ |
| 2507 | si_setcoreidx(sih, idx); |
| 2508 | return st; |
| 2509 | } |
| 2510 | |
Arend van Spriel | db3f94c | 2011-01-25 16:53:40 +0100 | [diff] [blame] | 2511 | void si_pmu_sprom_enable(si_t *sih, struct osl_info *osh, bool enable) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2512 | { |
| 2513 | chipcregs_t *cc; |
| 2514 | uint origidx; |
| 2515 | |
| 2516 | /* Remember original core before switch to chipc */ |
| 2517 | origidx = si_coreidx(sih); |
| 2518 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 2519 | ASSERT(cc != NULL); |
| 2520 | |
| 2521 | /* Return to original core */ |
| 2522 | si_setcoreidx(sih, origidx); |
| 2523 | } |
| 2524 | |
| 2525 | /* initialize PMU chip controls and other chip level stuff */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2526 | void si_pmu_chip_init(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2527 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2528 | uint origidx; |
| 2529 | |
| 2530 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 2531 | |
| 2532 | #ifdef CHIPC_UART_ALWAYS_ON |
Greg Kroah-Hartman | ce0f1b8 | 2010-10-08 11:44:45 -0700 | [diff] [blame] | 2533 | si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, clk_ctl_st), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2534 | CCS_FORCEALP, CCS_FORCEALP); |
| 2535 | #endif /* CHIPC_UART_ALWAYS_ON */ |
| 2536 | |
| 2537 | /* Gate off SPROM clock and chip select signals */ |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 2538 | si_pmu_sprom_enable(sih, osh, false); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2539 | |
| 2540 | /* Remember original core */ |
| 2541 | origidx = si_coreidx(sih); |
| 2542 | |
| 2543 | /* Return to original core */ |
| 2544 | si_setcoreidx(sih, origidx); |
| 2545 | } |
| 2546 | |
| 2547 | /* initialize PMU switch/regulators */ |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2548 | void si_pmu_swreg_init(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2549 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2550 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 2551 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2552 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2553 | case BCM4336_CHIP_ID: |
| 2554 | /* Reduce CLDO PWM output voltage to 1.2V */ |
| 2555 | si_pmu_set_ldo_voltage(sih, osh, SET_LDO_VOLTAGE_CLDO_PWM, 0xe); |
| 2556 | /* Reduce CLDO BURST output voltage to 1.2V */ |
| 2557 | si_pmu_set_ldo_voltage(sih, osh, SET_LDO_VOLTAGE_CLDO_BURST, |
| 2558 | 0xe); |
| 2559 | /* Reduce LNLDO1 output voltage to 1.2V */ |
| 2560 | si_pmu_set_ldo_voltage(sih, osh, SET_LDO_VOLTAGE_LNLDO1, 0xe); |
Arend van Spriel | ff29ee8 | 2010-12-02 15:44:52 +0100 | [diff] [blame] | 2561 | if (sih->chiprev == 0) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2562 | si_pmu_regcontrol(sih, 2, 0x400000, 0x400000); |
| 2563 | break; |
| 2564 | |
| 2565 | case BCM4330_CHIP_ID: |
| 2566 | /* CBUCK Voltage is 1.8 by default and set that to 1.5 */ |
| 2567 | si_pmu_set_ldo_voltage(sih, osh, SET_LDO_VOLTAGE_CBUCK_PWM, 0); |
| 2568 | break; |
| 2569 | default: |
| 2570 | break; |
| 2571 | } |
| 2572 | } |
| 2573 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2574 | void si_pmu_radio_enable(si_t *sih, bool enable) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2575 | { |
| 2576 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 2577 | |
Arend van Spriel | dfa2643 | 2010-12-02 15:44:51 +0100 | [diff] [blame] | 2578 | switch (sih->chip) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2579 | case BCM4319_CHIP_ID: |
| 2580 | if (enable) |
| 2581 | si_write_wrapperreg(sih, AI_OOBSELOUTB74, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2582 | (u32) 0x868584); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2583 | else |
| 2584 | si_write_wrapperreg(sih, AI_OOBSELOUTB74, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2585 | (u32) 0x060584); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2586 | break; |
| 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | /* Wait for a particular clock level to be on the backplane */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2591 | u32 |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2592 | si_pmu_waitforclk_on_backplane(si_t *sih, struct osl_info *osh, u32 clk, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2593 | u32 delay) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2594 | { |
| 2595 | chipcregs_t *cc; |
| 2596 | uint origidx; |
| 2597 | |
| 2598 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 2599 | |
| 2600 | /* Remember original core before switch to chipc */ |
| 2601 | origidx = si_coreidx(sih); |
| 2602 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 2603 | ASSERT(cc != NULL); |
| 2604 | |
| 2605 | if (delay) |
| 2606 | SPINWAIT(((R_REG(osh, &cc->pmustatus) & clk) != clk), delay); |
| 2607 | |
| 2608 | /* Return to original core */ |
| 2609 | si_setcoreidx(sih, origidx); |
| 2610 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2611 | return R_REG(osh, &cc->pmustatus) & clk; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | /* |
| 2615 | * Measures the ALP clock frequency in KHz. Returns 0 if not possible. |
| 2616 | * Possible only if PMU rev >= 10 and there is an external LPO 32768Hz crystal. |
| 2617 | */ |
| 2618 | |
| 2619 | #define EXT_ILP_HZ 32768 |
| 2620 | |
Brett Rudley | e69284f | 2010-11-16 15:45:48 -0800 | [diff] [blame] | 2621 | u32 si_pmu_measure_alpclk(si_t *sih, struct osl_info *osh) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2622 | { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2623 | chipcregs_t *cc; |
| 2624 | uint origidx; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2625 | u32 alp_khz; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2626 | |
| 2627 | if (sih->pmurev < 10) |
| 2628 | return 0; |
| 2629 | |
| 2630 | ASSERT(sih->cccaps & CC_CAP_PMU); |
| 2631 | |
| 2632 | /* Remember original core before switch to chipc */ |
| 2633 | origidx = si_coreidx(sih); |
| 2634 | cc = si_setcoreidx(sih, SI_CC_IDX); |
| 2635 | ASSERT(cc != NULL); |
| 2636 | |
| 2637 | if (R_REG(osh, &cc->pmustatus) & PST_EXTLPOAVAIL) { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2638 | u32 ilp_ctr, alp_hz; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2639 | |
| 2640 | /* Enable the reg to measure the freq, in case disabled before */ |
| 2641 | W_REG(osh, &cc->pmu_xtalfreq, |
| 2642 | 1U << PMU_XTALFREQ_REG_MEASURE_SHIFT); |
| 2643 | |
| 2644 | /* Delay for well over 4 ILP clocks */ |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 2645 | udelay(1000); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2646 | |
| 2647 | /* Read the latched number of ALP ticks per 4 ILP ticks */ |
| 2648 | ilp_ctr = |
| 2649 | R_REG(osh, |
| 2650 | &cc->pmu_xtalfreq) & PMU_XTALFREQ_REG_ILPCTR_MASK; |
| 2651 | |
| 2652 | /* Turn off the PMU_XTALFREQ_REG_MEASURE_SHIFT bit to save power */ |
| 2653 | W_REG(osh, &cc->pmu_xtalfreq, 0); |
| 2654 | |
| 2655 | /* Calculate ALP frequency */ |
| 2656 | alp_hz = (ilp_ctr * EXT_ILP_HZ) / 4; |
| 2657 | |
| 2658 | /* Round to nearest 100KHz, and at the same time convert to KHz */ |
| 2659 | alp_khz = (alp_hz + 50000) / 100000 * 100; |
| 2660 | } else |
| 2661 | alp_khz = 0; |
| 2662 | |
| 2663 | /* Return to original core */ |
| 2664 | si_setcoreidx(sih, origidx); |
| 2665 | |
| 2666 | return alp_khz; |
| 2667 | } |
| 2668 | |
Greg Kroah-Hartman | 0d2f072 | 2010-10-08 14:28:21 -0700 | [diff] [blame] | 2669 | static void si_pmu_set_4330_plldivs(si_t *sih) |
Jason Cooper | a2627bc | 2010-09-14 09:45:31 -0400 | [diff] [blame] | 2670 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 2671 | u32 FVCO = si_pmu1_pllfvco0(sih) / 1000; |
| 2672 | u32 m1div, m2div, m3div, m4div, m5div, m6div; |
| 2673 | u32 pllc1, pllc2; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2674 | |
| 2675 | m2div = m3div = m4div = m6div = FVCO / 80; |
| 2676 | m5div = FVCO / 160; |
| 2677 | |
| 2678 | if (CST4330_CHIPMODE_SDIOD(sih->chipst)) |
| 2679 | m1div = FVCO / 80; |
| 2680 | else |
| 2681 | m1div = FVCO / 90; |
| 2682 | pllc1 = |
| 2683 | (m1div << PMU1_PLL0_PC1_M1DIV_SHIFT) | (m2div << |
| 2684 | PMU1_PLL0_PC1_M2DIV_SHIFT) | |
| 2685 | (m3div << PMU1_PLL0_PC1_M3DIV_SHIFT) | (m4div << |
| 2686 | PMU1_PLL0_PC1_M4DIV_SHIFT); |
| 2687 | si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL1, ~0, pllc1); |
| 2688 | |
| 2689 | pllc2 = si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL1, 0, 0); |
| 2690 | pllc2 &= ~(PMU1_PLL0_PC2_M5DIV_MASK | PMU1_PLL0_PC2_M6DIV_MASK); |
| 2691 | pllc2 |= |
| 2692 | ((m5div << PMU1_PLL0_PC2_M5DIV_SHIFT) | |
| 2693 | (m6div << PMU1_PLL0_PC2_M6DIV_SHIFT)); |
| 2694 | si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL2, ~0, pllc2); |
| 2695 | } |