2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
16 #include <linux/delay.h>
17 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/module.h>
20 #include <linux/pci.h>
28 #include "siutils_priv.h"
30 #define PMU_ERROR(args)
33 #define PMU_MSG(args) printk args
35 /* debug-only definitions */
36 /* #define BCMDBG_FORCEHT */
41 /* To check in verbose debugging messages not intended
42 * to be on except on private builds.
44 #define PMU_NONE(args)
46 /* PLL controls/clocks */
47 static void si_pmu1_pllinit0(si_t *sih, chipcregs_t *cc, u32 xtal);
48 static u32 si_pmu1_alpclk0(si_t *sih, chipcregs_t *cc);
51 static bool si_pmu_res_depfltr_bb(si_t *sih);
52 static bool si_pmu_res_depfltr_ncb(si_t *sih);
53 static bool si_pmu_res_depfltr_paldo(si_t *sih);
54 static bool si_pmu_res_depfltr_npaldo(si_t *sih);
55 static u32 si_pmu_res_deps(si_t *sih, chipcregs_t *cc, u32 rsrcs, bool all);
56 static uint si_pmu_res_uptime(si_t *sih, chipcregs_t *cc, u8 rsrc);
57 static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax);
58 static void si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc,
61 static void si_pmu_set_4330_plldivs(si_t *sih);
64 #define FVCO_880 880000 /* 880MHz */
65 #define FVCO_1760 1760000 /* 1760MHz */
66 #define FVCO_1440 1440000 /* 1440MHz */
67 #define FVCO_960 960000 /* 960MHz */
69 /* Read/write a chipcontrol reg */
70 u32 si_pmu_chipcontrol(si_t *sih, uint reg, u32 mask, u32 val)
72 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol_addr), ~0,
74 return si_corereg(sih, SI_CC_IDX,
75 offsetof(chipcregs_t, chipcontrol_data), mask, val);
78 /* Read/write a regcontrol reg */
79 u32 si_pmu_regcontrol(si_t *sih, uint reg, u32 mask, u32 val)
81 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_addr), ~0,
83 return si_corereg(sih, SI_CC_IDX,
84 offsetof(chipcregs_t, regcontrol_data), mask, val);
87 /* Read/write a pllcontrol reg */
88 u32 si_pmu_pllcontrol(si_t *sih, uint reg, u32 mask, u32 val)
90 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pllcontrol_addr), ~0,
92 return si_corereg(sih, SI_CC_IDX,
93 offsetof(chipcregs_t, pllcontrol_data), mask, val);
97 void si_pmu_pllupd(si_t *sih)
99 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pmucontrol),
100 PCTL_PLL_PLLCTL_UPD, PCTL_PLL_PLLCTL_UPD);
103 void si_pmu_set_ldo_voltage(si_t *sih, u8 ldo, u8 voltage)
105 u8 sr_cntl_shift = 0, rc_shift = 0, shift = 0, mask = 0;
109 case BCM4336_CHIP_ID:
111 case SET_LDO_VOLTAGE_CLDO_PWM:
116 case SET_LDO_VOLTAGE_CLDO_BURST:
121 case SET_LDO_VOLTAGE_LNLDO1:
130 case BCM4330_CHIP_ID:
132 case SET_LDO_VOLTAGE_CBUCK_PWM:
145 shift = sr_cntl_shift + rc_shift;
147 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_addr),
149 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_data),
150 mask << shift, (voltage & mask) << shift);
153 /* d11 slow to fast clock transition time in slow clock cycles */
154 #define D11SCC_SLOW2FAST_TRANSITION 2
156 u16 si_pmu_fast_pwrup_delay(si_t *sih)
158 uint delay = PMU_MAX_TRANSITION_DLY;
163 chn[0] = 0; /* to suppress compile error */
167 /* Remember original core before switch to chipc */
168 origidx = si_coreidx(sih);
169 cc = si_setcoreidx(sih, SI_CC_IDX);
172 case BCM43224_CHIP_ID:
173 case BCM43225_CHIP_ID:
174 case BCM43421_CHIP_ID:
175 case BCM43235_CHIP_ID:
176 case BCM43236_CHIP_ID:
177 case BCM43238_CHIP_ID:
178 case BCM4331_CHIP_ID:
179 case BCM6362_CHIP_ID:
180 case BCM4313_CHIP_ID:
181 delay = ISSIM_ENAB(sih) ? 70 : 3700;
183 case BCM4329_CHIP_ID:
187 u32 ilp = si_ilp_clock(sih);
189 (si_pmu_res_uptime(sih, cc, RES4329_HT_AVAIL) +
190 D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp -
192 delay = (11 * delay) / 10;
195 case BCM4319_CHIP_ID:
196 delay = ISSIM_ENAB(sih) ? 70 : 3700;
198 case BCM4336_CHIP_ID:
202 u32 ilp = si_ilp_clock(sih);
204 (si_pmu_res_uptime(sih, cc, RES4336_HT_AVAIL) +
205 D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp -
207 delay = (11 * delay) / 10;
210 case BCM4330_CHIP_ID:
214 u32 ilp = si_ilp_clock(sih);
216 (si_pmu_res_uptime(sih, cc, RES4330_HT_AVAIL) +
217 D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp -
219 delay = (11 * delay) / 10;
225 /* Return to original core */
226 si_setcoreidx(sih, origidx);
231 /* Setup resource up/down timers */
237 /* Change resource dependancies masks */
239 u32 res_mask; /* resources (chip specific) */
240 s8 action; /* action */
241 u32 depend_mask; /* changes to the dependancies mask */
242 bool(*filter) (si_t *sih); /* action is taken when filter is NULL or return true */
245 /* Resource dependancies mask change action */
246 #define RES_DEPEND_SET 0 /* Override the dependancies mask */
247 #define RES_DEPEND_ADD 1 /* Add to the dependancies mask */
248 #define RES_DEPEND_REMOVE -1 /* Remove from the dependancies mask */
250 static const pmu_res_updown_t bcm4328a0_res_updown[] = {
252 RES4328_EXT_SWITCHER_PWM, 0x0101}, {
253 RES4328_BB_SWITCHER_PWM, 0x1f01}, {
254 RES4328_BB_SWITCHER_BURST, 0x010f}, {
255 RES4328_BB_EXT_SWITCHER_BURST, 0x0101}, {
256 RES4328_ILP_REQUEST, 0x0202}, {
257 RES4328_RADIO_SWITCHER_PWM, 0x0f01}, {
258 RES4328_RADIO_SWITCHER_BURST, 0x0f01}, {
259 RES4328_ROM_SWITCH, 0x0101}, {
260 RES4328_PA_REF_LDO, 0x0f01}, {
261 RES4328_RADIO_LDO, 0x0f01}, {
262 RES4328_AFE_LDO, 0x0f01}, {
263 RES4328_PLL_LDO, 0x0f01}, {
264 RES4328_BG_FILTBYP, 0x0101}, {
265 RES4328_TX_FILTBYP, 0x0101}, {
266 RES4328_RX_FILTBYP, 0x0101}, {
267 RES4328_XTAL_PU, 0x0101}, {
268 RES4328_XTAL_EN, 0xa001}, {
269 RES4328_BB_PLL_FILTBYP, 0x0101}, {
270 RES4328_RF_PLL_FILTBYP, 0x0101}, {
271 RES4328_BB_PLL_PU, 0x0701}
274 static const pmu_res_depend_t bcm4328a0_res_depend[] = {
275 /* Adjust ILP request resource not to force ext/BB switchers into burst mode */
277 PMURES_BIT(RES4328_ILP_REQUEST),
279 PMURES_BIT(RES4328_EXT_SWITCHER_PWM) |
280 PMURES_BIT(RES4328_BB_SWITCHER_PWM), NULL}
283 static const pmu_res_updown_t bcm4325a0_res_updown_qt[] = {
285 RES4325_HT_AVAIL, 0x0300}, {
286 RES4325_BBPLL_PWRSW_PU, 0x0101}, {
287 RES4325_RFPLL_PWRSW_PU, 0x0101}, {
288 RES4325_ALP_AVAIL, 0x0100}, {
289 RES4325_XTAL_PU, 0x1000}, {
290 RES4325_LNLDO1_PU, 0x0800}, {
291 RES4325_CLDO_CBUCK_PWM, 0x0101}, {
292 RES4325_CBUCK_PWM, 0x0803}
295 static const pmu_res_updown_t bcm4325a0_res_updown[] = {
297 RES4325_XTAL_PU, 0x1501}
300 static const pmu_res_depend_t bcm4325a0_res_depend[] = {
301 /* Adjust OTP PU resource dependencies - remove BB BURST */
303 PMURES_BIT(RES4325_OTP_PU),
305 PMURES_BIT(RES4325_BUCK_BOOST_BURST), NULL},
306 /* Adjust ALP/HT Avail resource dependencies - bring up BB along if it is used. */
308 PMURES_BIT(RES4325_ALP_AVAIL) | PMURES_BIT(RES4325_HT_AVAIL),
310 PMURES_BIT(RES4325_BUCK_BOOST_BURST) |
311 PMURES_BIT(RES4325_BUCK_BOOST_PWM), si_pmu_res_depfltr_bb},
312 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
314 PMURES_BIT(RES4325_HT_AVAIL),
316 PMURES_BIT(RES4325_RX_PWRSW_PU) |
317 PMURES_BIT(RES4325_TX_PWRSW_PU) |
318 PMURES_BIT(RES4325_LOGEN_PWRSW_PU) |
319 PMURES_BIT(RES4325_AFE_PWRSW_PU), NULL},
320 /* Adjust ALL resource dependencies - remove CBUCK dependancies if it is not used. */
322 PMURES_BIT(RES4325_ILP_REQUEST) |
323 PMURES_BIT(RES4325_ABUCK_BURST) |
324 PMURES_BIT(RES4325_ABUCK_PWM) |
325 PMURES_BIT(RES4325_LNLDO1_PU) |
326 PMURES_BIT(RES4325C1_LNLDO2_PU) |
327 PMURES_BIT(RES4325_XTAL_PU) |
328 PMURES_BIT(RES4325_ALP_AVAIL) |
329 PMURES_BIT(RES4325_RX_PWRSW_PU) |
330 PMURES_BIT(RES4325_TX_PWRSW_PU) |
331 PMURES_BIT(RES4325_RFPLL_PWRSW_PU) |
332 PMURES_BIT(RES4325_LOGEN_PWRSW_PU) |
333 PMURES_BIT(RES4325_AFE_PWRSW_PU) |
334 PMURES_BIT(RES4325_BBPLL_PWRSW_PU) |
335 PMURES_BIT(RES4325_HT_AVAIL), RES_DEPEND_REMOVE,
336 PMURES_BIT(RES4325B0_CBUCK_LPOM) |
337 PMURES_BIT(RES4325B0_CBUCK_BURST) |
338 PMURES_BIT(RES4325B0_CBUCK_PWM), si_pmu_res_depfltr_ncb}
341 static const pmu_res_updown_t bcm4315a0_res_updown_qt[] = {
343 RES4315_HT_AVAIL, 0x0101}, {
344 RES4315_XTAL_PU, 0x0100}, {
345 RES4315_LNLDO1_PU, 0x0100}, {
346 RES4315_PALDO_PU, 0x0100}, {
347 RES4315_CLDO_PU, 0x0100}, {
348 RES4315_CBUCK_PWM, 0x0100}, {
349 RES4315_CBUCK_BURST, 0x0100}, {
350 RES4315_CBUCK_LPOM, 0x0100}
353 static const pmu_res_updown_t bcm4315a0_res_updown[] = {
355 RES4315_XTAL_PU, 0x2501}
358 static const pmu_res_depend_t bcm4315a0_res_depend[] = {
359 /* Adjust OTP PU resource dependencies - not need PALDO unless write */
361 PMURES_BIT(RES4315_OTP_PU),
363 PMURES_BIT(RES4315_PALDO_PU), si_pmu_res_depfltr_npaldo},
364 /* Adjust ALP/HT Avail resource dependencies - bring up PALDO along if it is used. */
366 PMURES_BIT(RES4315_ALP_AVAIL) | PMURES_BIT(RES4315_HT_AVAIL),
368 PMURES_BIT(RES4315_PALDO_PU), si_pmu_res_depfltr_paldo},
369 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
371 PMURES_BIT(RES4315_HT_AVAIL),
373 PMURES_BIT(RES4315_RX_PWRSW_PU) |
374 PMURES_BIT(RES4315_TX_PWRSW_PU) |
375 PMURES_BIT(RES4315_LOGEN_PWRSW_PU) |
376 PMURES_BIT(RES4315_AFE_PWRSW_PU), NULL},
377 /* Adjust ALL resource dependencies - remove CBUCK dependancies if it is not used. */
379 PMURES_BIT(RES4315_CLDO_PU) | PMURES_BIT(RES4315_ILP_REQUEST) |
380 PMURES_BIT(RES4315_LNLDO1_PU) |
381 PMURES_BIT(RES4315_OTP_PU) |
382 PMURES_BIT(RES4315_LNLDO2_PU) |
383 PMURES_BIT(RES4315_XTAL_PU) |
384 PMURES_BIT(RES4315_ALP_AVAIL) |
385 PMURES_BIT(RES4315_RX_PWRSW_PU) |
386 PMURES_BIT(RES4315_TX_PWRSW_PU) |
387 PMURES_BIT(RES4315_RFPLL_PWRSW_PU) |
388 PMURES_BIT(RES4315_LOGEN_PWRSW_PU) |
389 PMURES_BIT(RES4315_AFE_PWRSW_PU) |
390 PMURES_BIT(RES4315_BBPLL_PWRSW_PU) |
391 PMURES_BIT(RES4315_HT_AVAIL), RES_DEPEND_REMOVE,
392 PMURES_BIT(RES4315_CBUCK_LPOM) |
393 PMURES_BIT(RES4315_CBUCK_BURST) |
394 PMURES_BIT(RES4315_CBUCK_PWM), si_pmu_res_depfltr_ncb}
397 /* 4329 specific. needs to come back this issue later */
398 static const pmu_res_updown_t bcm4329_res_updown[] = {
400 RES4329_XTAL_PU, 0x1501}
403 static const pmu_res_depend_t bcm4329_res_depend[] = {
404 /* Adjust HT Avail resource dependencies */
406 PMURES_BIT(RES4329_HT_AVAIL),
408 PMURES_BIT(RES4329_CBUCK_LPOM) |
409 PMURES_BIT(RES4329_CBUCK_BURST) |
410 PMURES_BIT(RES4329_CBUCK_PWM) |
411 PMURES_BIT(RES4329_CLDO_PU) |
412 PMURES_BIT(RES4329_PALDO_PU) |
413 PMURES_BIT(RES4329_LNLDO1_PU) |
414 PMURES_BIT(RES4329_XTAL_PU) |
415 PMURES_BIT(RES4329_ALP_AVAIL) |
416 PMURES_BIT(RES4329_RX_PWRSW_PU) |
417 PMURES_BIT(RES4329_TX_PWRSW_PU) |
418 PMURES_BIT(RES4329_RFPLL_PWRSW_PU) |
419 PMURES_BIT(RES4329_LOGEN_PWRSW_PU) |
420 PMURES_BIT(RES4329_AFE_PWRSW_PU) |
421 PMURES_BIT(RES4329_BBPLL_PWRSW_PU), NULL}
424 static const pmu_res_updown_t bcm4319a0_res_updown_qt[] = {
426 RES4319_HT_AVAIL, 0x0101}, {
427 RES4319_XTAL_PU, 0x0100}, {
428 RES4319_LNLDO1_PU, 0x0100}, {
429 RES4319_PALDO_PU, 0x0100}, {
430 RES4319_CLDO_PU, 0x0100}, {
431 RES4319_CBUCK_PWM, 0x0100}, {
432 RES4319_CBUCK_BURST, 0x0100}, {
433 RES4319_CBUCK_LPOM, 0x0100}
436 static const pmu_res_updown_t bcm4319a0_res_updown[] = {
438 RES4319_XTAL_PU, 0x3f01}
441 static const pmu_res_depend_t bcm4319a0_res_depend[] = {
442 /* Adjust OTP PU resource dependencies - not need PALDO unless write */
444 PMURES_BIT(RES4319_OTP_PU),
446 PMURES_BIT(RES4319_PALDO_PU), si_pmu_res_depfltr_npaldo},
447 /* Adjust HT Avail resource dependencies - bring up PALDO along if it is used. */
449 PMURES_BIT(RES4319_HT_AVAIL),
451 PMURES_BIT(RES4319_PALDO_PU), si_pmu_res_depfltr_paldo},
452 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
454 PMURES_BIT(RES4319_HT_AVAIL),
456 PMURES_BIT(RES4319_RX_PWRSW_PU) |
457 PMURES_BIT(RES4319_TX_PWRSW_PU) |
458 PMURES_BIT(RES4319_RFPLL_PWRSW_PU) |
459 PMURES_BIT(RES4319_LOGEN_PWRSW_PU) |
460 PMURES_BIT(RES4319_AFE_PWRSW_PU), NULL}
463 static const pmu_res_updown_t bcm4336a0_res_updown_qt[] = {
465 RES4336_HT_AVAIL, 0x0101}, {
466 RES4336_XTAL_PU, 0x0100}, {
467 RES4336_CLDO_PU, 0x0100}, {
468 RES4336_CBUCK_PWM, 0x0100}, {
469 RES4336_CBUCK_BURST, 0x0100}, {
470 RES4336_CBUCK_LPOM, 0x0100}
473 static const pmu_res_updown_t bcm4336a0_res_updown[] = {
475 RES4336_HT_AVAIL, 0x0D01}
478 static const pmu_res_depend_t bcm4336a0_res_depend[] = {
479 /* Just a dummy entry for now */
481 PMURES_BIT(RES4336_RSVD), RES_DEPEND_ADD, 0, NULL}
484 static const pmu_res_updown_t bcm4330a0_res_updown_qt[] = {
486 RES4330_HT_AVAIL, 0x0101}, {
487 RES4330_XTAL_PU, 0x0100}, {
488 RES4330_CLDO_PU, 0x0100}, {
489 RES4330_CBUCK_PWM, 0x0100}, {
490 RES4330_CBUCK_BURST, 0x0100}, {
491 RES4330_CBUCK_LPOM, 0x0100}
494 static const pmu_res_updown_t bcm4330a0_res_updown[] = {
496 RES4330_HT_AVAIL, 0x0e02}
499 static const pmu_res_depend_t bcm4330a0_res_depend[] = {
500 /* Just a dummy entry for now */
502 PMURES_BIT(RES4330_HT_AVAIL), RES_DEPEND_ADD, 0, NULL}
505 /* true if the power topology uses the buck boost to provide 3.3V to VDDIO_RF and WLAN PA */
506 static bool si_pmu_res_depfltr_bb(si_t *sih)
508 return (sih->boardflags & BFL_BUCKBOOST) != 0;
511 /* true if the power topology doesn't use the cbuck. Key on chiprev also if the chip is BCM4325. */
512 static bool si_pmu_res_depfltr_ncb(si_t *sih)
515 return (sih->boardflags & BFL_NOCBUCK) != 0;
518 /* true if the power topology uses the PALDO */
519 static bool si_pmu_res_depfltr_paldo(si_t *sih)
521 return (sih->boardflags & BFL_PALDO) != 0;
524 /* true if the power topology doesn't use the PALDO */
525 static bool si_pmu_res_depfltr_npaldo(si_t *sih)
527 return (sih->boardflags & BFL_PALDO) == 0;
530 #define BCM94325_BBVDDIOSD_BOARDS(sih) (sih->boardtype == BCM94325DEVBU_BOARD || \
531 sih->boardtype == BCM94325BGABU_BOARD)
533 /* Determine min/max rsrc masks. Value 0 leaves hardware at default. */
534 static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax)
536 u32 min_mask = 0, max_mask = 0;
541 rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT;
543 /* determine min/max rsrc masks */
545 case BCM43224_CHIP_ID:
546 case BCM43225_CHIP_ID:
547 case BCM43421_CHIP_ID:
548 case BCM43235_CHIP_ID:
549 case BCM43236_CHIP_ID:
550 case BCM43238_CHIP_ID:
551 case BCM4331_CHIP_ID:
552 case BCM6362_CHIP_ID:
556 case BCM4329_CHIP_ID:
557 /* 4329 spedific issue. Needs to come back this issue later */
558 /* Down to save the power. */
560 PMURES_BIT(RES4329_CBUCK_LPOM) |
561 PMURES_BIT(RES4329_CLDO_PU);
562 /* Allow (but don't require) PLL to turn on */
565 case BCM4319_CHIP_ID:
566 /* We only need a few resources to be kept on all the time */
567 min_mask = PMURES_BIT(RES4319_CBUCK_LPOM) |
568 PMURES_BIT(RES4319_CLDO_PU);
570 /* Allow everything else to be turned on upon requests */
571 max_mask = ~(~0 << rsrcs);
573 case BCM4336_CHIP_ID:
574 /* Down to save the power. */
576 PMURES_BIT(RES4336_CBUCK_LPOM) | PMURES_BIT(RES4336_CLDO_PU)
577 | PMURES_BIT(RES4336_LDO3P3_PU) | PMURES_BIT(RES4336_OTP_PU)
578 | PMURES_BIT(RES4336_DIS_INT_RESET_PD);
579 /* Allow (but don't require) PLL to turn on */
580 max_mask = 0x1ffffff;
583 case BCM4330_CHIP_ID:
584 /* Down to save the power. */
586 PMURES_BIT(RES4330_CBUCK_LPOM) | PMURES_BIT(RES4330_CLDO_PU)
587 | PMURES_BIT(RES4330_DIS_INT_RESET_PD) |
588 PMURES_BIT(RES4330_LDO3P3_PU) | PMURES_BIT(RES4330_OTP_PU);
589 /* Allow (but don't require) PLL to turn on */
590 max_mask = 0xfffffff;
593 case BCM4313_CHIP_ID:
594 min_mask = PMURES_BIT(RES4313_BB_PU_RSRC) |
595 PMURES_BIT(RES4313_XTAL_PU_RSRC) |
596 PMURES_BIT(RES4313_ALP_AVAIL_RSRC) |
597 PMURES_BIT(RES4313_BB_PLL_PWRSW_RSRC);
604 /* Apply nvram override to min mask */
605 val = getvar(NULL, "rmin");
607 PMU_MSG(("Applying rmin=%s to min_mask\n", val));
608 min_mask = (u32) simple_strtoul(val, NULL, 0);
610 /* Apply nvram override to max mask */
611 val = getvar(NULL, "rmax");
613 PMU_MSG(("Applying rmax=%s to max_mask\n", val));
614 max_mask = (u32) simple_strtoul(val, NULL, 0);
621 /* initialize PMU resources */
622 void si_pmu_res_init(si_t *sih)
626 const pmu_res_updown_t *pmu_res_updown_table = NULL;
627 uint pmu_res_updown_table_sz = 0;
628 const pmu_res_depend_t *pmu_res_depend_table = NULL;
629 uint pmu_res_depend_table_sz = 0;
630 u32 min_mask = 0, max_mask = 0;
634 /* Remember original core before switch to chipc */
635 origidx = si_coreidx(sih);
636 cc = si_setcoreidx(sih, SI_CC_IDX);
639 case BCM4329_CHIP_ID:
640 /* Optimize resources up/down timers */
641 if (ISSIM_ENAB(sih)) {
642 pmu_res_updown_table = NULL;
643 pmu_res_updown_table_sz = 0;
645 pmu_res_updown_table = bcm4329_res_updown;
646 pmu_res_updown_table_sz = ARRAY_SIZE(bcm4329_res_updown);
648 /* Optimize resources dependencies */
649 pmu_res_depend_table = bcm4329_res_depend;
650 pmu_res_depend_table_sz = ARRAY_SIZE(bcm4329_res_depend);
653 case BCM4319_CHIP_ID:
654 /* Optimize resources up/down timers */
655 if (ISSIM_ENAB(sih)) {
656 pmu_res_updown_table = bcm4319a0_res_updown_qt;
657 pmu_res_updown_table_sz =
658 ARRAY_SIZE(bcm4319a0_res_updown_qt);
660 pmu_res_updown_table = bcm4319a0_res_updown;
661 pmu_res_updown_table_sz =
662 ARRAY_SIZE(bcm4319a0_res_updown);
664 /* Optimize resources dependancies masks */
665 pmu_res_depend_table = bcm4319a0_res_depend;
666 pmu_res_depend_table_sz = ARRAY_SIZE(bcm4319a0_res_depend);
669 case BCM4336_CHIP_ID:
670 /* Optimize resources up/down timers */
671 if (ISSIM_ENAB(sih)) {
672 pmu_res_updown_table = bcm4336a0_res_updown_qt;
673 pmu_res_updown_table_sz =
674 ARRAY_SIZE(bcm4336a0_res_updown_qt);
676 pmu_res_updown_table = bcm4336a0_res_updown;
677 pmu_res_updown_table_sz =
678 ARRAY_SIZE(bcm4336a0_res_updown);
680 /* Optimize resources dependancies masks */
681 pmu_res_depend_table = bcm4336a0_res_depend;
682 pmu_res_depend_table_sz = ARRAY_SIZE(bcm4336a0_res_depend);
685 case BCM4330_CHIP_ID:
686 /* Optimize resources up/down timers */
687 if (ISSIM_ENAB(sih)) {
688 pmu_res_updown_table = bcm4330a0_res_updown_qt;
689 pmu_res_updown_table_sz =
690 ARRAY_SIZE(bcm4330a0_res_updown_qt);
692 pmu_res_updown_table = bcm4330a0_res_updown;
693 pmu_res_updown_table_sz =
694 ARRAY_SIZE(bcm4330a0_res_updown);
696 /* Optimize resources dependancies masks */
697 pmu_res_depend_table = bcm4330a0_res_depend;
698 pmu_res_depend_table_sz = ARRAY_SIZE(bcm4330a0_res_depend);
706 rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT;
708 /* Program up/down timers */
709 while (pmu_res_updown_table_sz--) {
710 PMU_MSG(("Changing rsrc %d res_updn_timer to 0x%x\n",
711 pmu_res_updown_table[pmu_res_updown_table_sz].resnum,
712 pmu_res_updown_table[pmu_res_updown_table_sz].updown));
713 W_REG(&cc->res_table_sel,
714 pmu_res_updown_table[pmu_res_updown_table_sz].resnum);
715 W_REG(&cc->res_updn_timer,
716 pmu_res_updown_table[pmu_res_updown_table_sz].updown);
718 /* Apply nvram overrides to up/down timers */
719 for (i = 0; i < rsrcs; i++) {
720 snprintf(name, sizeof(name), "r%dt", i);
721 val = getvar(NULL, name);
724 PMU_MSG(("Applying %s=%s to rsrc %d res_updn_timer\n", name,
726 W_REG(&cc->res_table_sel, (u32) i);
727 W_REG(&cc->res_updn_timer,
728 (u32) simple_strtoul(val, NULL, 0));
731 /* Program resource dependencies table */
732 while (pmu_res_depend_table_sz--) {
733 if (pmu_res_depend_table[pmu_res_depend_table_sz].filter != NULL
734 && !(pmu_res_depend_table[pmu_res_depend_table_sz].
737 for (i = 0; i < rsrcs; i++) {
738 if ((pmu_res_depend_table[pmu_res_depend_table_sz].
739 res_mask & PMURES_BIT(i)) == 0)
741 W_REG(&cc->res_table_sel, i);
742 switch (pmu_res_depend_table[pmu_res_depend_table_sz].
745 PMU_MSG(("Changing rsrc %d res_dep_mask to 0x%x\n", i, pmu_res_depend_table[pmu_res_depend_table_sz].depend_mask));
746 W_REG(&cc->res_dep_mask,
748 [pmu_res_depend_table_sz].depend_mask);
751 PMU_MSG(("Adding 0x%x to rsrc %d res_dep_mask\n", pmu_res_depend_table[pmu_res_depend_table_sz].depend_mask, i));
752 OR_REG(&cc->res_dep_mask,
754 [pmu_res_depend_table_sz].depend_mask);
756 case RES_DEPEND_REMOVE:
757 PMU_MSG(("Removing 0x%x from rsrc %d res_dep_mask\n", pmu_res_depend_table[pmu_res_depend_table_sz].depend_mask, i));
758 AND_REG(&cc->res_dep_mask,
759 ~pmu_res_depend_table
760 [pmu_res_depend_table_sz].depend_mask);
767 /* Apply nvram overrides to dependancies masks */
768 for (i = 0; i < rsrcs; i++) {
769 snprintf(name, sizeof(name), "r%dd", i);
770 val = getvar(NULL, name);
773 PMU_MSG(("Applying %s=%s to rsrc %d res_dep_mask\n", name, val,
775 W_REG(&cc->res_table_sel, (u32) i);
776 W_REG(&cc->res_dep_mask,
777 (u32) simple_strtoul(val, NULL, 0));
780 /* Determine min/max rsrc masks */
781 si_pmu_res_masks(sih, &min_mask, &max_mask);
783 /* It is required to program max_mask first and then min_mask */
785 /* Program max resource mask */
788 PMU_MSG(("Changing max_res_mask to 0x%x\n", max_mask));
789 W_REG(&cc->max_res_mask, max_mask);
792 /* Program min resource mask */
795 PMU_MSG(("Changing min_res_mask to 0x%x\n", min_mask));
796 W_REG(&cc->min_res_mask, min_mask);
799 /* Add some delay; allow resources to come up and settle. */
802 /* Return to original core */
803 si_setcoreidx(sih, origidx);
806 /* setup pll and query clock speed */
814 /* the following table is based on 880Mhz fvco */
815 static const pmu0_xtaltab0_t pmu0_xtaltab0[] = {
817 12000, 1, 73, 349525}, {
818 13000, 2, 67, 725937}, {
819 14400, 3, 61, 116508}, {
820 15360, 4, 57, 305834}, {
821 16200, 5, 54, 336579}, {
822 16800, 6, 52, 399457}, {
823 19200, 7, 45, 873813}, {
824 19800, 8, 44, 466033}, {
826 25000, 10, 70, 419430}, {
827 26000, 11, 67, 725937}, {
828 30000, 12, 58, 699050}, {
829 38400, 13, 45, 873813}, {
834 #define PMU0_XTAL0_DEFAULT 8
836 /* setup pll and query clock speed */
846 static const pmu1_xtaltab0_t pmu1_xtaltab0_880_4329[] = {
848 12000, 1, 3, 22, 0x9, 0xFFFFEF}, {
849 13000, 2, 1, 6, 0xb, 0x483483}, {
850 14400, 3, 1, 10, 0xa, 0x1C71C7}, {
851 15360, 4, 1, 5, 0xb, 0x755555}, {
852 16200, 5, 1, 10, 0x5, 0x6E9E06}, {
853 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, {
854 19200, 7, 1, 4, 0xb, 0x755555}, {
855 19800, 8, 1, 11, 0x4, 0xA57EB}, {
856 20000, 9, 1, 11, 0x4, 0x0}, {
857 24000, 10, 3, 11, 0xa, 0x0}, {
858 25000, 11, 5, 16, 0xb, 0x0}, {
859 26000, 12, 1, 1, 0x21, 0xD89D89}, {
860 30000, 13, 3, 8, 0xb, 0x0}, {
861 37400, 14, 3, 1, 0x46, 0x969696}, {
862 38400, 15, 1, 1, 0x16, 0xEAAAAA}, {
863 40000, 16, 1, 2, 0xb, 0}, {
867 /* the following table is based on 880Mhz fvco */
868 static const pmu1_xtaltab0_t pmu1_xtaltab0_880[] = {
870 12000, 1, 3, 22, 0x9, 0xFFFFEF}, {
871 13000, 2, 1, 6, 0xb, 0x483483}, {
872 14400, 3, 1, 10, 0xa, 0x1C71C7}, {
873 15360, 4, 1, 5, 0xb, 0x755555}, {
874 16200, 5, 1, 10, 0x5, 0x6E9E06}, {
875 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, {
876 19200, 7, 1, 4, 0xb, 0x755555}, {
877 19800, 8, 1, 11, 0x4, 0xA57EB}, {
878 20000, 9, 1, 11, 0x4, 0x0}, {
879 24000, 10, 3, 11, 0xa, 0x0}, {
880 25000, 11, 5, 16, 0xb, 0x0}, {
881 26000, 12, 1, 2, 0x10, 0xEC4EC4}, {
882 30000, 13, 3, 8, 0xb, 0x0}, {
883 33600, 14, 1, 2, 0xd, 0x186186}, {
884 38400, 15, 1, 2, 0xb, 0x755555}, {
885 40000, 16, 1, 2, 0xb, 0}, {
889 #define PMU1_XTALTAB0_880_12000K 0
890 #define PMU1_XTALTAB0_880_13000K 1
891 #define PMU1_XTALTAB0_880_14400K 2
892 #define PMU1_XTALTAB0_880_15360K 3
893 #define PMU1_XTALTAB0_880_16200K 4
894 #define PMU1_XTALTAB0_880_16800K 5
895 #define PMU1_XTALTAB0_880_19200K 6
896 #define PMU1_XTALTAB0_880_19800K 7
897 #define PMU1_XTALTAB0_880_20000K 8
898 #define PMU1_XTALTAB0_880_24000K 9
899 #define PMU1_XTALTAB0_880_25000K 10
900 #define PMU1_XTALTAB0_880_26000K 11
901 #define PMU1_XTALTAB0_880_30000K 12
902 #define PMU1_XTALTAB0_880_37400K 13
903 #define PMU1_XTALTAB0_880_38400K 14
904 #define PMU1_XTALTAB0_880_40000K 15
906 /* the following table is based on 1760Mhz fvco */
907 static const pmu1_xtaltab0_t pmu1_xtaltab0_1760[] = {
909 12000, 1, 3, 44, 0x9, 0xFFFFEF}, {
910 13000, 2, 1, 12, 0xb, 0x483483}, {
911 14400, 3, 1, 20, 0xa, 0x1C71C7}, {
912 15360, 4, 1, 10, 0xb, 0x755555}, {
913 16200, 5, 1, 20, 0x5, 0x6E9E06}, {
914 16800, 6, 1, 20, 0x5, 0x3Cf3Cf}, {
915 19200, 7, 1, 18, 0x5, 0x17B425}, {
916 19800, 8, 1, 22, 0x4, 0xA57EB}, {
917 20000, 9, 1, 22, 0x4, 0x0}, {
918 24000, 10, 3, 22, 0xa, 0x0}, {
919 25000, 11, 5, 32, 0xb, 0x0}, {
920 26000, 12, 1, 4, 0x10, 0xEC4EC4}, {
921 30000, 13, 3, 16, 0xb, 0x0}, {
922 38400, 14, 1, 10, 0x4, 0x955555}, {
923 40000, 15, 1, 4, 0xb, 0}, {
928 #define PMU1_XTALTAB0_1760_12000K 0
929 #define PMU1_XTALTAB0_1760_13000K 1
930 #define PMU1_XTALTAB0_1760_14400K 2
931 #define PMU1_XTALTAB0_1760_15360K 3
932 #define PMU1_XTALTAB0_1760_16200K 4
933 #define PMU1_XTALTAB0_1760_16800K 5
934 #define PMU1_XTALTAB0_1760_19200K 6
935 #define PMU1_XTALTAB0_1760_19800K 7
936 #define PMU1_XTALTAB0_1760_20000K 8
937 #define PMU1_XTALTAB0_1760_24000K 9
938 #define PMU1_XTALTAB0_1760_25000K 10
939 #define PMU1_XTALTAB0_1760_26000K 11
940 #define PMU1_XTALTAB0_1760_30000K 12
941 #define PMU1_XTALTAB0_1760_38400K 13
942 #define PMU1_XTALTAB0_1760_40000K 14
944 /* the following table is based on 1440Mhz fvco */
945 static const pmu1_xtaltab0_t pmu1_xtaltab0_1440[] = {
947 12000, 1, 1, 1, 0x78, 0x0}, {
948 13000, 2, 1, 1, 0x6E, 0xC4EC4E}, {
949 14400, 3, 1, 1, 0x64, 0x0}, {
950 15360, 4, 1, 1, 0x5D, 0xC00000}, {
951 16200, 5, 1, 1, 0x58, 0xE38E38}, {
952 16800, 6, 1, 1, 0x55, 0xB6DB6D}, {
953 19200, 7, 1, 1, 0x4B, 0}, {
954 19800, 8, 1, 1, 0x48, 0xBA2E8B}, {
955 20000, 9, 1, 1, 0x48, 0x0}, {
956 25000, 10, 1, 1, 0x39, 0x999999}, {
957 26000, 11, 1, 1, 0x37, 0x627627}, {
958 30000, 12, 1, 1, 0x30, 0x0}, {
959 37400, 13, 2, 1, 0x4D, 0x15E76}, {
960 38400, 13, 2, 1, 0x4B, 0x0}, {
961 40000, 14, 2, 1, 0x48, 0x0}, {
962 48000, 15, 2, 1, 0x3c, 0x0}, {
967 #define PMU1_XTALTAB0_1440_12000K 0
968 #define PMU1_XTALTAB0_1440_13000K 1
969 #define PMU1_XTALTAB0_1440_14400K 2
970 #define PMU1_XTALTAB0_1440_15360K 3
971 #define PMU1_XTALTAB0_1440_16200K 4
972 #define PMU1_XTALTAB0_1440_16800K 5
973 #define PMU1_XTALTAB0_1440_19200K 6
974 #define PMU1_XTALTAB0_1440_19800K 7
975 #define PMU1_XTALTAB0_1440_20000K 8
976 #define PMU1_XTALTAB0_1440_25000K 9
977 #define PMU1_XTALTAB0_1440_26000K 10
978 #define PMU1_XTALTAB0_1440_30000K 11
979 #define PMU1_XTALTAB0_1440_37400K 12
980 #define PMU1_XTALTAB0_1440_38400K 13
981 #define PMU1_XTALTAB0_1440_40000K 14
982 #define PMU1_XTALTAB0_1440_48000K 15
984 #define XTAL_FREQ_24000MHZ 24000
985 #define XTAL_FREQ_30000MHZ 30000
986 #define XTAL_FREQ_37400MHZ 37400
987 #define XTAL_FREQ_48000MHZ 48000
989 static const pmu1_xtaltab0_t pmu1_xtaltab0_960[] = {
991 12000, 1, 1, 1, 0x50, 0x0}, {
992 13000, 2, 1, 1, 0x49, 0xD89D89}, {
993 14400, 3, 1, 1, 0x42, 0xAAAAAA}, {
994 15360, 4, 1, 1, 0x3E, 0x800000}, {
995 16200, 5, 1, 1, 0x39, 0x425ED0}, {
996 16800, 6, 1, 1, 0x39, 0x249249}, {
997 19200, 7, 1, 1, 0x32, 0x0}, {
998 19800, 8, 1, 1, 0x30, 0x7C1F07}, {
999 20000, 9, 1, 1, 0x30, 0x0}, {
1000 25000, 10, 1, 1, 0x26, 0x666666}, {
1001 26000, 11, 1, 1, 0x24, 0xEC4EC4}, {
1002 30000, 12, 1, 1, 0x20, 0x0}, {
1003 37400, 13, 2, 1, 0x33, 0x563EF9}, {
1004 38400, 14, 2, 1, 0x32, 0x0}, {
1005 40000, 15, 2, 1, 0x30, 0x0}, {
1006 48000, 16, 2, 1, 0x28, 0x0}, {
1011 #define PMU1_XTALTAB0_960_12000K 0
1012 #define PMU1_XTALTAB0_960_13000K 1
1013 #define PMU1_XTALTAB0_960_14400K 2
1014 #define PMU1_XTALTAB0_960_15360K 3
1015 #define PMU1_XTALTAB0_960_16200K 4
1016 #define PMU1_XTALTAB0_960_16800K 5
1017 #define PMU1_XTALTAB0_960_19200K 6
1018 #define PMU1_XTALTAB0_960_19800K 7
1019 #define PMU1_XTALTAB0_960_20000K 8
1020 #define PMU1_XTALTAB0_960_25000K 9
1021 #define PMU1_XTALTAB0_960_26000K 10
1022 #define PMU1_XTALTAB0_960_30000K 11
1023 #define PMU1_XTALTAB0_960_37400K 12
1024 #define PMU1_XTALTAB0_960_38400K 13
1025 #define PMU1_XTALTAB0_960_40000K 14
1026 #define PMU1_XTALTAB0_960_48000K 15
1028 /* select xtal table for each chip */
1029 static const pmu1_xtaltab0_t *si_pmu1_xtaltab0(si_t *sih)
1034 switch (sih->chip) {
1035 case BCM4329_CHIP_ID:
1036 return pmu1_xtaltab0_880_4329;
1037 case BCM4319_CHIP_ID:
1038 return pmu1_xtaltab0_1440;
1039 case BCM4336_CHIP_ID:
1040 return pmu1_xtaltab0_960;
1041 case BCM4330_CHIP_ID:
1042 if (CST4330_CHIPMODE_SDIOD(sih->chipst))
1043 return pmu1_xtaltab0_960;
1045 return pmu1_xtaltab0_1440;
1047 PMU_MSG(("si_pmu1_xtaltab0: Unknown chipid %s\n",
1048 bcm_chipname(sih->chip, chn, 8)));
1054 /* select default xtal frequency for each chip */
1055 static const pmu1_xtaltab0_t *si_pmu1_xtaldef0(si_t *sih)
1061 switch (sih->chip) {
1062 case BCM4329_CHIP_ID:
1063 /* Default to 38400Khz */
1064 return &pmu1_xtaltab0_880_4329[PMU1_XTALTAB0_880_38400K];
1065 case BCM4319_CHIP_ID:
1066 /* Default to 30000Khz */
1067 return &pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_30000K];
1068 case BCM4336_CHIP_ID:
1069 /* Default to 26000Khz */
1070 return &pmu1_xtaltab0_960[PMU1_XTALTAB0_960_26000K];
1071 case BCM4330_CHIP_ID:
1072 /* Default to 37400Khz */
1073 if (CST4330_CHIPMODE_SDIOD(sih->chipst))
1074 return &pmu1_xtaltab0_960[PMU1_XTALTAB0_960_37400K];
1076 return &pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_37400K];
1078 PMU_MSG(("si_pmu1_xtaldef0: Unknown chipid %s\n",
1079 bcm_chipname(sih->chip, chn, 8)));
1085 /* select default pll fvco for each chip */
1086 static u32 si_pmu1_pllfvco0(si_t *sih)
1092 switch (sih->chip) {
1093 case BCM4329_CHIP_ID:
1095 case BCM4319_CHIP_ID:
1097 case BCM4336_CHIP_ID:
1099 case BCM4330_CHIP_ID:
1100 if (CST4330_CHIPMODE_SDIOD(sih->chipst))
1105 PMU_MSG(("si_pmu1_pllfvco0: Unknown chipid %s\n",
1106 bcm_chipname(sih->chip, chn, 8)));
1112 /* query alp/xtal clock frequency */
1114 si_pmu1_alpclk0(si_t *sih, chipcregs_t *cc)
1116 const pmu1_xtaltab0_t *xt;
1119 /* Find the frequency in the table */
1120 xf = (R_REG(&cc->pmucontrol) & PCTL_XTALFREQ_MASK) >>
1121 PCTL_XTALFREQ_SHIFT;
1122 for (xt = si_pmu1_xtaltab0(sih); xt != NULL && xt->fref != 0; xt++)
1125 /* Could not find it so assign a default value */
1126 if (xt == NULL || xt->fref == 0)
1127 xt = si_pmu1_xtaldef0(sih);
1128 return xt->fref * 1000;
1131 /* Set up PLL registers in the PMU as per the crystal speed.
1132 * XtalFreq field in pmucontrol register being 0 indicates the PLL
1133 * is not programmed and the h/w default is assumed to work, in which
1134 * case the xtal frequency is unknown to the s/w so we need to call
1135 * si_pmu1_xtaldef0() wherever it is needed to return a default value.
1137 static void si_pmu1_pllinit0(si_t *sih, chipcregs_t *cc, u32 xtal)
1139 const pmu1_xtaltab0_t *xt;
1141 u32 buf_strength = 0;
1144 /* Use h/w default PLL config */
1146 PMU_MSG(("Unspecified xtal frequency, skip PLL configuration\n"));
1150 /* Find the frequency in the table */
1151 for (xt = si_pmu1_xtaltab0(sih); xt != NULL && xt->fref != 0; xt++)
1152 if (xt->fref == xtal)
1155 /* Check current PLL state, bail out if it has been programmed or
1156 * we don't know how to program it.
1158 if (xt == NULL || xt->fref == 0) {
1159 PMU_MSG(("Unsupported xtal frequency %d.%d MHz, skip PLL configuration\n", xtal / 1000, xtal % 1000));
1162 /* for 4319 bootloader already programs the PLL but bootloader does not program the
1163 PLL4 and PLL5. So Skip this check for 4319
1165 if ((((R_REG(&cc->pmucontrol) & PCTL_XTALFREQ_MASK) >>
1166 PCTL_XTALFREQ_SHIFT) == xt->xf) &&
1167 !((sih->chip == BCM4319_CHIP_ID)
1168 || (sih->chip == BCM4330_CHIP_ID))) {
1169 PMU_MSG(("PLL already programmed for %d.%d MHz\n",
1170 xt->fref / 1000, xt->fref % 1000));
1174 PMU_MSG(("XTAL %d.%d MHz (%d)\n", xtal / 1000, xtal % 1000, xt->xf));
1175 PMU_MSG(("Programming PLL for %d.%d MHz\n", xt->fref / 1000,
1178 switch (sih->chip) {
1179 case BCM4329_CHIP_ID:
1180 /* Change the BBPLL drive strength to 8 for all channels */
1181 buf_strength = 0x888888;
1182 AND_REG(&cc->min_res_mask,
1183 ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) |
1184 PMURES_BIT(RES4329_HT_AVAIL)));
1185 AND_REG(&cc->max_res_mask,
1186 ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) |
1187 PMURES_BIT(RES4329_HT_AVAIL)));
1188 SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL,
1189 PMU_MAX_TRANSITION_DLY);
1190 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1191 if (xt->fref == 38400)
1193 else if (xt->fref == 37400)
1195 else if (xt->fref == 26000)
1198 tmp = 0x200005C0; /* Chip Dflt Settings */
1199 W_REG(&cc->pllcontrol_data, tmp);
1200 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1202 R_REG(&cc->pllcontrol_data) & PMU1_PLL0_PC5_CLK_DRV_MASK;
1203 if ((xt->fref == 38400) || (xt->fref == 37400)
1204 || (xt->fref == 26000))
1207 tmp |= 0x25; /* Chip Dflt Settings */
1208 W_REG(&cc->pllcontrol_data, tmp);
1211 case BCM4319_CHIP_ID:
1212 /* Change the BBPLL drive strength to 2 for all channels */
1213 buf_strength = 0x222222;
1215 /* Make sure the PLL is off */
1216 /* WAR65104: Disable the HT_AVAIL resource first and then
1217 * after a delay (more than downtime for HT_AVAIL) remove the
1218 * BBPLL resource; backplane clock moves to ALP from HT.
1220 AND_REG(&cc->min_res_mask,
1221 ~(PMURES_BIT(RES4319_HT_AVAIL)));
1222 AND_REG(&cc->max_res_mask,
1223 ~(PMURES_BIT(RES4319_HT_AVAIL)));
1226 AND_REG(&cc->min_res_mask,
1227 ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU)));
1228 AND_REG(&cc->max_res_mask,
1229 ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU)));
1232 SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL,
1233 PMU_MAX_TRANSITION_DLY);
1234 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1236 W_REG(&cc->pllcontrol_data, tmp);
1239 case BCM4336_CHIP_ID:
1240 AND_REG(&cc->min_res_mask,
1241 ~(PMURES_BIT(RES4336_HT_AVAIL) |
1242 PMURES_BIT(RES4336_MACPHY_CLKAVAIL)));
1243 AND_REG(&cc->max_res_mask,
1244 ~(PMURES_BIT(RES4336_HT_AVAIL) |
1245 PMURES_BIT(RES4336_MACPHY_CLKAVAIL)));
1247 SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL,
1248 PMU_MAX_TRANSITION_DLY);
1251 case BCM4330_CHIP_ID:
1252 AND_REG(&cc->min_res_mask,
1253 ~(PMURES_BIT(RES4330_HT_AVAIL) |
1254 PMURES_BIT(RES4330_MACPHY_CLKAVAIL)));
1255 AND_REG(&cc->max_res_mask,
1256 ~(PMURES_BIT(RES4330_HT_AVAIL) |
1257 PMURES_BIT(RES4330_MACPHY_CLKAVAIL)));
1259 SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL,
1260 PMU_MAX_TRANSITION_DLY);
1267 PMU_MSG(("Done masking\n"));
1269 /* Write p1div and p2div to pllcontrol[0] */
1270 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1271 tmp = R_REG(&cc->pllcontrol_data) &
1272 ~(PMU1_PLL0_PC0_P1DIV_MASK | PMU1_PLL0_PC0_P2DIV_MASK);
1275 p1div << PMU1_PLL0_PC0_P1DIV_SHIFT) & PMU1_PLL0_PC0_P1DIV_MASK) |
1277 p2div << PMU1_PLL0_PC0_P2DIV_SHIFT) & PMU1_PLL0_PC0_P2DIV_MASK);
1278 W_REG(&cc->pllcontrol_data, tmp);
1280 if ((sih->chip == BCM4330_CHIP_ID))
1281 si_pmu_set_4330_plldivs(sih);
1283 if ((sih->chip == BCM4329_CHIP_ID)
1284 && (sih->chiprev == 0)) {
1286 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1287 tmp = R_REG(&cc->pllcontrol_data);
1288 tmp = tmp & (~DOT11MAC_880MHZ_CLK_DIVISOR_MASK);
1289 tmp = tmp | DOT11MAC_880MHZ_CLK_DIVISOR_VAL;
1290 W_REG(&cc->pllcontrol_data, tmp);
1292 if ((sih->chip == BCM4319_CHIP_ID) ||
1293 (sih->chip == BCM4336_CHIP_ID) ||
1294 (sih->chip == BCM4330_CHIP_ID))
1295 ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MFB;
1297 ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MASH;
1299 /* Write ndiv_int and ndiv_mode to pllcontrol[2] */
1300 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1301 tmp = R_REG(&cc->pllcontrol_data) &
1302 ~(PMU1_PLL0_PC2_NDIV_INT_MASK | PMU1_PLL0_PC2_NDIV_MODE_MASK);
1305 ndiv_int << PMU1_PLL0_PC2_NDIV_INT_SHIFT) &
1306 PMU1_PLL0_PC2_NDIV_INT_MASK) | ((ndiv_mode <<
1307 PMU1_PLL0_PC2_NDIV_MODE_SHIFT) &
1308 PMU1_PLL0_PC2_NDIV_MODE_MASK);
1309 W_REG(&cc->pllcontrol_data, tmp);
1311 /* Write ndiv_frac to pllcontrol[3] */
1312 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
1313 tmp = R_REG(&cc->pllcontrol_data) & ~PMU1_PLL0_PC3_NDIV_FRAC_MASK;
1314 tmp |= ((xt->ndiv_frac << PMU1_PLL0_PC3_NDIV_FRAC_SHIFT) &
1315 PMU1_PLL0_PC3_NDIV_FRAC_MASK);
1316 W_REG(&cc->pllcontrol_data, tmp);
1318 /* Write clock driving strength to pllcontrol[5] */
1320 PMU_MSG(("Adjusting PLL buffer drive strength: %x\n",
1323 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1325 R_REG(&cc->pllcontrol_data) & ~PMU1_PLL0_PC5_CLK_DRV_MASK;
1326 tmp |= (buf_strength << PMU1_PLL0_PC5_CLK_DRV_SHIFT);
1327 W_REG(&cc->pllcontrol_data, tmp);
1330 PMU_MSG(("Done pll\n"));
1332 /* to operate the 4319 usb in 24MHz/48MHz; chipcontrol[2][84:83] needs
1335 if ((sih->chip == BCM4319_CHIP_ID)
1336 && (xt->fref != XTAL_FREQ_30000MHZ)) {
1337 W_REG(&cc->chipcontrol_addr, PMU1_PLL0_CHIPCTL2);
1339 R_REG(&cc->chipcontrol_data) & ~CCTL_4319USB_XTAL_SEL_MASK;
1340 if (xt->fref == XTAL_FREQ_24000MHZ) {
1342 (CCTL_4319USB_24MHZ_PLL_SEL <<
1343 CCTL_4319USB_XTAL_SEL_SHIFT);
1344 } else if (xt->fref == XTAL_FREQ_48000MHZ) {
1346 (CCTL_4319USB_48MHZ_PLL_SEL <<
1347 CCTL_4319USB_XTAL_SEL_SHIFT);
1349 W_REG(&cc->chipcontrol_data, tmp);
1352 /* Flush deferred pll control registers writes */
1353 if (sih->pmurev >= 2)
1354 OR_REG(&cc->pmucontrol, PCTL_PLL_PLLCTL_UPD);
1356 /* Write XtalFreq. Set the divisor also. */
1357 tmp = R_REG(&cc->pmucontrol) &
1358 ~(PCTL_ILP_DIV_MASK | PCTL_XTALFREQ_MASK);
1359 tmp |= (((((xt->fref + 127) / 128) - 1) << PCTL_ILP_DIV_SHIFT) &
1360 PCTL_ILP_DIV_MASK) |
1361 ((xt->xf << PCTL_XTALFREQ_SHIFT) & PCTL_XTALFREQ_MASK);
1363 if ((sih->chip == BCM4329_CHIP_ID)
1364 && sih->chiprev == 0) {
1365 /* clear the htstretch before clearing HTReqEn */
1366 AND_REG(&cc->clkstretch, ~CSTRETCH_HT);
1367 tmp &= ~PCTL_HT_REQ_EN;
1370 W_REG(&cc->pmucontrol, tmp);
1373 /* initialize PLL */
1374 void si_pmu_pll_init(si_t *sih, uint xtalfreq)
1382 /* Remember original core before switch to chipc */
1383 origidx = si_coreidx(sih);
1384 cc = si_setcoreidx(sih, SI_CC_IDX);
1386 switch (sih->chip) {
1387 case BCM4329_CHIP_ID:
1390 si_pmu1_pllinit0(sih, cc, xtalfreq);
1392 case BCM4313_CHIP_ID:
1393 case BCM43224_CHIP_ID:
1394 case BCM43225_CHIP_ID:
1395 case BCM43421_CHIP_ID:
1396 case BCM43235_CHIP_ID:
1397 case BCM43236_CHIP_ID:
1398 case BCM43238_CHIP_ID:
1399 case BCM4331_CHIP_ID:
1400 case BCM6362_CHIP_ID:
1403 case BCM4319_CHIP_ID:
1404 case BCM4336_CHIP_ID:
1405 case BCM4330_CHIP_ID:
1406 si_pmu1_pllinit0(sih, cc, xtalfreq);
1409 PMU_MSG(("No PLL init done for chip %s rev %d pmurev %d\n",
1410 bcm_chipname(sih->chip, chn, 8), sih->chiprev,
1415 /* Return to original core */
1416 si_setcoreidx(sih, origidx);
1419 /* query alp/xtal clock frequency */
1420 u32 si_pmu_alp_clock(si_t *sih)
1424 u32 clock = ALP_CLOCK;
1429 /* Remember original core before switch to chipc */
1430 origidx = si_coreidx(sih);
1431 cc = si_setcoreidx(sih, SI_CC_IDX);
1433 switch (sih->chip) {
1434 case BCM43224_CHIP_ID:
1435 case BCM43225_CHIP_ID:
1436 case BCM43421_CHIP_ID:
1437 case BCM43235_CHIP_ID:
1438 case BCM43236_CHIP_ID:
1439 case BCM43238_CHIP_ID:
1440 case BCM4331_CHIP_ID:
1441 case BCM6362_CHIP_ID:
1442 case BCM4716_CHIP_ID:
1443 case BCM4748_CHIP_ID:
1444 case BCM47162_CHIP_ID:
1445 case BCM4313_CHIP_ID:
1446 case BCM5357_CHIP_ID:
1448 clock = 20000 * 1000;
1450 case BCM4329_CHIP_ID:
1451 case BCM4319_CHIP_ID:
1452 case BCM4336_CHIP_ID:
1453 case BCM4330_CHIP_ID:
1455 clock = si_pmu1_alpclk0(sih, cc);
1457 case BCM5356_CHIP_ID:
1459 clock = 25000 * 1000;
1462 PMU_MSG(("No ALP clock specified "
1463 "for chip %s rev %d pmurev %d, using default %d Hz\n",
1464 bcm_chipname(sih->chip, chn, 8), sih->chiprev,
1465 sih->pmurev, clock));
1469 /* Return to original core */
1470 si_setcoreidx(sih, origidx);
1474 /* Measure ILP clock frequency */
1475 #define ILP_CALC_DUR 10 /* ms, make sure 1000 can be divided by it. */
1477 static u32 ilpcycles_per_sec;
1479 u32 si_pmu_ilp_clock(si_t *sih)
1481 if (ISSIM_ENAB(sih))
1484 if (ilpcycles_per_sec == 0) {
1485 u32 start, end, delta;
1486 u32 origidx = si_coreidx(sih);
1487 chipcregs_t *cc = si_setcoreidx(sih, SI_CC_IDX);
1488 start = R_REG(&cc->pmutimer);
1489 mdelay(ILP_CALC_DUR);
1490 end = R_REG(&cc->pmutimer);
1491 delta = end - start;
1492 ilpcycles_per_sec = delta * (1000 / ILP_CALC_DUR);
1493 si_setcoreidx(sih, origidx);
1496 return ilpcycles_per_sec;
1499 /* SDIO Pad drive strength to select value mappings */
1501 u8 strength; /* Pad Drive Strength in mA */
1502 u8 sel; /* Chip-specific select value */
1503 } sdiod_drive_str_t;
1505 /* SDIO Drive Strength to sel value table for PMU Rev 1 */
1506 static const sdiod_drive_str_t sdiod_drive_strength_tab1[] = {
1514 /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */
1515 static const sdiod_drive_str_t sdiod_drive_strength_tab2[] = {
1526 /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */
1527 static const sdiod_drive_str_t sdiod_drive_strength_tab3[] = {
1539 #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu))
1542 si_sdiod_drive_strength_init(si_t *sih, u32 drivestrength) {
1544 uint origidx, intr_val = 0;
1545 sdiod_drive_str_t *str_tab = NULL;
1552 if (!(sih->cccaps & CC_CAP_PMU)) {
1556 /* Remember original core before switch to chipc */
1557 cc = (chipcregs_t *) si_switch_core(sih, CC_CORE_ID, &origidx,
1560 switch (SDIOD_DRVSTR_KEY(sih->chip, sih->pmurev)) {
1561 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 1):
1562 str_tab = (sdiod_drive_str_t *)&sdiod_drive_strength_tab1;
1563 str_mask = 0x30000000;
1566 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 2):
1567 case SDIOD_DRVSTR_KEY(BCM4325_CHIP_ID, 3):
1568 str_tab = (sdiod_drive_str_t *)&sdiod_drive_strength_tab2;
1569 str_mask = 0x00003800;
1572 case SDIOD_DRVSTR_KEY(BCM4336_CHIP_ID, 8):
1573 str_tab = (sdiod_drive_str_t *) &sdiod_drive_strength_tab3;
1574 str_mask = 0x00003800;
1579 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));
1584 if (str_tab != NULL) {
1585 u32 drivestrength_sel = 0;
1589 for (i = 0; str_tab[i].strength != 0; i++) {
1590 if (drivestrength >= str_tab[i].strength) {
1591 drivestrength_sel = str_tab[i].sel;
1596 W_REG(&cc->chipcontrol_addr, 1);
1597 cc_data_temp = R_REG(&cc->chipcontrol_data);
1598 cc_data_temp &= ~str_mask;
1599 drivestrength_sel <<= str_shift;
1600 cc_data_temp |= drivestrength_sel;
1601 W_REG(&cc->chipcontrol_data, cc_data_temp);
1603 PMU_MSG(("SDIO: %dmA drive strength selected, set to 0x%08x\n",
1604 drivestrength, cc_data_temp));
1607 /* Return to original core */
1608 si_restore_core(sih, origidx, intr_val);
1611 /* initialize PMU */
1612 void si_pmu_init(si_t *sih)
1617 /* Remember original core before switch to chipc */
1618 origidx = si_coreidx(sih);
1619 cc = si_setcoreidx(sih, SI_CC_IDX);
1621 if (sih->pmurev == 1)
1622 AND_REG(&cc->pmucontrol, ~PCTL_NOILP_ON_WAIT);
1623 else if (sih->pmurev >= 2)
1624 OR_REG(&cc->pmucontrol, PCTL_NOILP_ON_WAIT);
1626 if ((sih->chip == BCM4329_CHIP_ID) && (sih->chiprev == 2)) {
1627 /* Fix for 4329b0 bad LPOM state. */
1628 W_REG(&cc->regcontrol_addr, 2);
1629 OR_REG(&cc->regcontrol_data, 0x100);
1631 W_REG(&cc->regcontrol_addr, 3);
1632 OR_REG(&cc->regcontrol_data, 0x4);
1635 /* Return to original core */
1636 si_setcoreidx(sih, origidx);
1639 /* Return up time in ILP cycles for the given resource. */
1641 si_pmu_res_uptime(si_t *sih, chipcregs_t *cc, u8 rsrc) {
1643 uint up, i, dup, dmax;
1644 u32 min_mask = 0, max_mask = 0;
1646 /* uptime of resource 'rsrc' */
1647 W_REG(&cc->res_table_sel, rsrc);
1648 up = (R_REG(&cc->res_updn_timer) >> 8) & 0xff;
1650 /* direct dependancies of resource 'rsrc' */
1651 deps = si_pmu_res_deps(sih, cc, PMURES_BIT(rsrc), false);
1652 for (i = 0; i <= PMURES_MAX_RESNUM; i++) {
1653 if (!(deps & PMURES_BIT(i)))
1655 deps &= ~si_pmu_res_deps(sih, cc, PMURES_BIT(i), true);
1657 si_pmu_res_masks(sih, &min_mask, &max_mask);
1660 /* max uptime of direct dependancies */
1662 for (i = 0; i <= PMURES_MAX_RESNUM; i++) {
1663 if (!(deps & PMURES_BIT(i)))
1665 dup = si_pmu_res_uptime(sih, cc, (u8) i);
1670 PMU_MSG(("si_pmu_res_uptime: rsrc %u uptime %u(deps 0x%08x uptime %u)\n", rsrc, up, deps, dmax));
1672 return up + dmax + PMURES_UP_TRANSITION;
1675 /* Return dependancies (direct or all/indirect) for the given resources */
1677 si_pmu_res_deps(si_t *sih, chipcregs_t *cc, u32 rsrcs,
1683 for (i = 0; i <= PMURES_MAX_RESNUM; i++) {
1684 if (!(rsrcs & PMURES_BIT(i)))
1686 W_REG(&cc->res_table_sel, i);
1687 deps |= R_REG(&cc->res_dep_mask);
1690 return !all ? deps : (deps
1692 si_pmu_res_deps(sih, cc, deps,
1696 /* power up/down OTP through PMU resources */
1697 void si_pmu_otp_power(si_t *sih, bool on)
1701 u32 rsrcs = 0; /* rsrcs to turn on/off OTP power */
1703 /* Don't do anything if OTP is disabled */
1704 if (si_is_otp_disabled(sih)) {
1705 PMU_MSG(("si_pmu_otp_power: OTP is disabled\n"));
1709 /* Remember original core before switch to chipc */
1710 origidx = si_coreidx(sih);
1711 cc = si_setcoreidx(sih, SI_CC_IDX);
1713 switch (sih->chip) {
1714 case BCM4329_CHIP_ID:
1715 rsrcs = PMURES_BIT(RES4329_OTP_PU);
1717 case BCM4319_CHIP_ID:
1718 rsrcs = PMURES_BIT(RES4319_OTP_PU);
1720 case BCM4336_CHIP_ID:
1721 rsrcs = PMURES_BIT(RES4336_OTP_PU);
1723 case BCM4330_CHIP_ID:
1724 rsrcs = PMURES_BIT(RES4330_OTP_PU);
1733 /* Figure out the dependancies (exclude min_res_mask) */
1734 u32 deps = si_pmu_res_deps(sih, cc, rsrcs, true);
1735 u32 min_mask = 0, max_mask = 0;
1736 si_pmu_res_masks(sih, &min_mask, &max_mask);
1738 /* Turn on/off the power */
1740 PMU_MSG(("Adding rsrc 0x%x to min_res_mask\n",
1742 OR_REG(&cc->min_res_mask, (rsrcs | deps));
1743 SPINWAIT(!(R_REG(&cc->res_state) & rsrcs),
1744 PMU_MAX_TRANSITION_DLY);
1746 PMU_MSG(("Removing rsrc 0x%x from min_res_mask\n",
1748 AND_REG(&cc->min_res_mask, ~(rsrcs | deps));
1751 SPINWAIT((((otps = R_REG(&cc->otpstatus)) & OTPS_READY) !=
1752 (on ? OTPS_READY : 0)), 100);
1753 if ((otps & OTPS_READY) != (on ? OTPS_READY : 0))
1754 PMU_MSG(("OTP ready bit not %s after wait\n",
1755 (on ? "ON" : "OFF")));
1758 /* Return to original core */
1759 si_setcoreidx(sih, origidx);
1762 void si_pmu_spuravoid(si_t *sih, u8 spuravoid)
1765 uint origidx, intr_val;
1768 /* Remember original core before switch to chipc */
1769 cc = (chipcregs_t *) si_switch_core(sih, CC_CORE_ID, &origidx,
1772 /* force the HT off */
1773 if (sih->chip == BCM4336_CHIP_ID) {
1774 tmp = R_REG(&cc->max_res_mask);
1775 tmp &= ~RES4336_HT_AVAIL;
1776 W_REG(&cc->max_res_mask, tmp);
1777 /* wait for the ht to really go away */
1778 SPINWAIT(((R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL) == 0),
1782 /* update the pll changes */
1783 si_pmu_spuravoid_pllupdate(sih, cc, spuravoid);
1785 /* enable HT back on */
1786 if (sih->chip == BCM4336_CHIP_ID) {
1787 tmp = R_REG(&cc->max_res_mask);
1788 tmp |= RES4336_HT_AVAIL;
1789 W_REG(&cc->max_res_mask, tmp);
1792 /* Return to original core */
1793 si_restore_core(sih, origidx, intr_val);
1797 si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, u8 spuravoid)
1800 u8 phypll_offset = 0;
1801 u8 bcm5357_bcm43236_p1div[] = { 0x1, 0x5, 0x5 };
1802 u8 bcm5357_bcm43236_ndiv[] = { 0x30, 0xf6, 0xfc };
1804 switch (sih->chip) {
1805 case BCM5357_CHIP_ID:
1806 case BCM43235_CHIP_ID:
1807 case BCM43236_CHIP_ID:
1808 case BCM43238_CHIP_ID:
1810 /* BCM5357 needs to touch PLL1_PLLCTL[02], so offset PLL0_PLLCTL[02] by 6 */
1811 phypll_offset = (sih->chip == BCM5357_CHIP_ID) ? 6 : 0;
1813 /* RMW only the P1 divider */
1814 W_REG(&cc->pllcontrol_addr,
1815 PMU1_PLL0_PLLCTL0 + phypll_offset);
1816 tmp = R_REG(&cc->pllcontrol_data);
1817 tmp &= (~(PMU1_PLL0_PC0_P1DIV_MASK));
1819 (bcm5357_bcm43236_p1div[spuravoid] <<
1820 PMU1_PLL0_PC0_P1DIV_SHIFT);
1821 W_REG(&cc->pllcontrol_data, tmp);
1823 /* RMW only the int feedback divider */
1824 W_REG(&cc->pllcontrol_addr,
1825 PMU1_PLL0_PLLCTL2 + phypll_offset);
1826 tmp = R_REG(&cc->pllcontrol_data);
1827 tmp &= ~(PMU1_PLL0_PC2_NDIV_INT_MASK);
1829 (bcm5357_bcm43236_ndiv[spuravoid]) <<
1830 PMU1_PLL0_PC2_NDIV_INT_SHIFT;
1831 W_REG(&cc->pllcontrol_data, tmp);
1836 case BCM4331_CHIP_ID:
1837 if (spuravoid == 2) {
1838 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1839 W_REG(&cc->pllcontrol_data, 0x11500014);
1840 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1841 W_REG(&cc->pllcontrol_data, 0x0FC00a08);
1842 } else if (spuravoid == 1) {
1843 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1844 W_REG(&cc->pllcontrol_data, 0x11500014);
1845 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1846 W_REG(&cc->pllcontrol_data, 0x0F600a08);
1848 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1849 W_REG(&cc->pllcontrol_data, 0x11100014);
1850 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1851 W_REG(&cc->pllcontrol_data, 0x03000a08);
1856 case BCM43224_CHIP_ID:
1857 case BCM43225_CHIP_ID:
1858 case BCM43421_CHIP_ID:
1859 case BCM6362_CHIP_ID:
1860 if (spuravoid == 1) {
1861 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1862 W_REG(&cc->pllcontrol_data, 0x11500010);
1863 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1864 W_REG(&cc->pllcontrol_data, 0x000C0C06);
1865 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1866 W_REG(&cc->pllcontrol_data, 0x0F600a08);
1867 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
1868 W_REG(&cc->pllcontrol_data, 0x00000000);
1869 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1870 W_REG(&cc->pllcontrol_data, 0x2001E920);
1871 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1872 W_REG(&cc->pllcontrol_data, 0x88888815);
1874 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1875 W_REG(&cc->pllcontrol_data, 0x11100010);
1876 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1877 W_REG(&cc->pllcontrol_data, 0x000c0c06);
1878 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1879 W_REG(&cc->pllcontrol_data, 0x03000a08);
1880 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
1881 W_REG(&cc->pllcontrol_data, 0x00000000);
1882 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1883 W_REG(&cc->pllcontrol_data, 0x200005c0);
1884 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1885 W_REG(&cc->pllcontrol_data, 0x88888815);
1890 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1891 W_REG(&cc->pllcontrol_data, 0x11100008);
1892 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1893 W_REG(&cc->pllcontrol_data, 0x0c000c06);
1894 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1895 W_REG(&cc->pllcontrol_data, 0x03000a08);
1896 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
1897 W_REG(&cc->pllcontrol_data, 0x00000000);
1898 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1899 W_REG(&cc->pllcontrol_data, 0x200005c0);
1900 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1901 W_REG(&cc->pllcontrol_data, 0x88888855);
1906 case BCM4716_CHIP_ID:
1907 case BCM4748_CHIP_ID:
1908 case BCM47162_CHIP_ID:
1909 if (spuravoid == 1) {
1910 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1911 W_REG(&cc->pllcontrol_data, 0x11500060);
1912 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1913 W_REG(&cc->pllcontrol_data, 0x080C0C06);
1914 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1915 W_REG(&cc->pllcontrol_data, 0x0F600000);
1916 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
1917 W_REG(&cc->pllcontrol_data, 0x00000000);
1918 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1919 W_REG(&cc->pllcontrol_data, 0x2001E924);
1920 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1921 W_REG(&cc->pllcontrol_data, 0x88888815);
1923 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1924 W_REG(&cc->pllcontrol_data, 0x11100060);
1925 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1926 W_REG(&cc->pllcontrol_data, 0x080c0c06);
1927 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1928 W_REG(&cc->pllcontrol_data, 0x03000000);
1929 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
1930 W_REG(&cc->pllcontrol_data, 0x00000000);
1931 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1932 W_REG(&cc->pllcontrol_data, 0x200005c0);
1933 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1934 W_REG(&cc->pllcontrol_data, 0x88888815);
1940 case BCM4319_CHIP_ID:
1941 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1942 W_REG(&cc->pllcontrol_data, 0x11100070);
1943 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1944 W_REG(&cc->pllcontrol_data, 0x1014140a);
1945 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1946 W_REG(&cc->pllcontrol_data, 0x88888854);
1948 if (spuravoid == 1) { /* spur_avoid ON, enable 41/82/164Mhz clock mode */
1949 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1950 W_REG(&cc->pllcontrol_data, 0x05201828);
1951 } else { /* enable 40/80/160Mhz clock mode */
1952 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1953 W_REG(&cc->pllcontrol_data, 0x05001828);
1956 case BCM4336_CHIP_ID:
1957 /* Looks like these are only for default xtal freq 26MHz */
1958 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0);
1959 W_REG(&cc->pllcontrol_data, 0x02100020);
1961 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1962 W_REG(&cc->pllcontrol_data, 0x0C0C0C0C);
1964 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2);
1965 W_REG(&cc->pllcontrol_data, 0x01240C0C);
1967 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4);
1968 W_REG(&cc->pllcontrol_data, 0x202C2820);
1970 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5);
1971 W_REG(&cc->pllcontrol_data, 0x88888825);
1973 W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3);
1974 if (spuravoid == 1) {
1975 W_REG(&cc->pllcontrol_data, 0x00EC4EC4);
1977 W_REG(&cc->pllcontrol_data, 0x00762762);
1980 tmp = PCTL_PLL_PLLCTL_UPD;
1984 PMU_ERROR(("%s: unknown spuravoidance settings for chip %s, not changing PLL\n", __func__, bcm_chipname(sih->chip, chn, 8)));
1988 tmp |= R_REG(&cc->pmucontrol);
1989 W_REG(&cc->pmucontrol, tmp);
1992 bool si_pmu_is_otp_powered(si_t *sih)
1998 /* Remember original core before switch to chipc */
1999 idx = si_coreidx(sih);
2000 cc = si_setcoreidx(sih, SI_CC_IDX);
2002 switch (sih->chip) {
2003 case BCM4329_CHIP_ID:
2004 st = (R_REG(&cc->res_state) & PMURES_BIT(RES4329_OTP_PU))
2007 case BCM4319_CHIP_ID:
2008 st = (R_REG(&cc->res_state) & PMURES_BIT(RES4319_OTP_PU))
2011 case BCM4336_CHIP_ID:
2012 st = (R_REG(&cc->res_state) & PMURES_BIT(RES4336_OTP_PU))
2015 case BCM4330_CHIP_ID:
2016 st = (R_REG(&cc->res_state) & PMURES_BIT(RES4330_OTP_PU))
2020 /* These chip doesn't use PMU bit to power up/down OTP. OTP always on.
2021 * Use OTP_INIT command to reset/refresh state.
2023 case BCM43224_CHIP_ID:
2024 case BCM43225_CHIP_ID:
2025 case BCM43421_CHIP_ID:
2026 case BCM43236_CHIP_ID:
2027 case BCM43235_CHIP_ID:
2028 case BCM43238_CHIP_ID:
2036 /* Return to original core */
2037 si_setcoreidx(sih, idx);
2041 void si_pmu_sprom_enable(si_t *sih, bool enable)
2046 /* Remember original core before switch to chipc */
2047 origidx = si_coreidx(sih);
2048 cc = si_setcoreidx(sih, SI_CC_IDX);
2050 /* Return to original core */
2051 si_setcoreidx(sih, origidx);
2054 /* initialize PMU chip controls and other chip level stuff */
2055 void si_pmu_chip_init(si_t *sih)
2059 /* Gate off SPROM clock and chip select signals */
2060 si_pmu_sprom_enable(sih, false);
2062 /* Remember original core */
2063 origidx = si_coreidx(sih);
2065 /* Return to original core */
2066 si_setcoreidx(sih, origidx);
2069 /* initialize PMU switch/regulators */
2070 void si_pmu_swreg_init(si_t *sih)
2072 switch (sih->chip) {
2073 case BCM4336_CHIP_ID:
2074 /* Reduce CLDO PWM output voltage to 1.2V */
2075 si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CLDO_PWM, 0xe);
2076 /* Reduce CLDO BURST output voltage to 1.2V */
2077 si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CLDO_BURST,
2079 /* Reduce LNLDO1 output voltage to 1.2V */
2080 si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_LNLDO1, 0xe);
2081 if (sih->chiprev == 0)
2082 si_pmu_regcontrol(sih, 2, 0x400000, 0x400000);
2085 case BCM4330_CHIP_ID:
2086 /* CBUCK Voltage is 1.8 by default and set that to 1.5 */
2087 si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CBUCK_PWM, 0);
2095 * Measures the ALP clock frequency in KHz. Returns 0 if not possible.
2096 * Possible only if PMU rev >= 10 and there is an external LPO 32768Hz crystal.
2099 #define EXT_ILP_HZ 32768
2101 u32 si_pmu_measure_alpclk(si_t *sih)
2107 if (sih->pmurev < 10)
2110 /* Remember original core before switch to chipc */
2111 origidx = si_coreidx(sih);
2112 cc = si_setcoreidx(sih, SI_CC_IDX);
2114 if (R_REG(&cc->pmustatus) & PST_EXTLPOAVAIL) {
2115 u32 ilp_ctr, alp_hz;
2117 /* Enable the reg to measure the freq, in case disabled before */
2118 W_REG(&cc->pmu_xtalfreq,
2119 1U << PMU_XTALFREQ_REG_MEASURE_SHIFT);
2121 /* Delay for well over 4 ILP clocks */
2124 /* Read the latched number of ALP ticks per 4 ILP ticks */
2126 R_REG(&cc->pmu_xtalfreq) & PMU_XTALFREQ_REG_ILPCTR_MASK;
2128 /* Turn off the PMU_XTALFREQ_REG_MEASURE_SHIFT bit to save power */
2129 W_REG(&cc->pmu_xtalfreq, 0);
2131 /* Calculate ALP frequency */
2132 alp_hz = (ilp_ctr * EXT_ILP_HZ) / 4;
2134 /* Round to nearest 100KHz, and at the same time convert to KHz */
2135 alp_khz = (alp_hz + 50000) / 100000 * 100;
2139 /* Return to original core */
2140 si_setcoreidx(sih, origidx);
2145 static void si_pmu_set_4330_plldivs(si_t *sih)
2147 u32 FVCO = si_pmu1_pllfvco0(sih) / 1000;
2148 u32 m1div, m2div, m3div, m4div, m5div, m6div;
2151 m2div = m3div = m4div = m6div = FVCO / 80;
2154 if (CST4330_CHIPMODE_SDIOD(sih->chipst))
2159 (m1div << PMU1_PLL0_PC1_M1DIV_SHIFT) | (m2div <<
2160 PMU1_PLL0_PC1_M2DIV_SHIFT) |
2161 (m3div << PMU1_PLL0_PC1_M3DIV_SHIFT) | (m4div <<
2162 PMU1_PLL0_PC1_M4DIV_SHIFT);
2163 si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL1, ~0, pllc1);
2165 pllc2 = si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL1, 0, 0);
2166 pllc2 &= ~(PMU1_PLL0_PC2_M5DIV_MASK | PMU1_PLL0_PC2_M6DIV_MASK);
2168 ((m5div << PMU1_PLL0_PC2_M5DIV_SHIFT) |
2169 (m6div << PMU1_PLL0_PC2_M6DIV_SHIFT));
2170 si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL2, ~0, pllc2);