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