2 * Copyright (c) 2016 Landon Fuller <landonf@FreeBSD.org>
3 * Copyright (C) 2010, Broadcom Corporation.
6 * This file is derived from the hndpmu.c source contributed by Broadcom
7 * to to the Linux staging repository, as well as later revisions of hndpmu.c
8 * distributed with the Asus RT-N16 firmware source code release.
10 * Permission to use, copy, modify, and/or distribute this software for any
11 * purpose with or without fee is hereby granted, provided that the above
12 * copyright notice and this permission notice appear in all copies.
14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #include <sys/cdefs.h>
24 __FBSDID("$FreeBSD$");
26 #include <sys/types.h>
28 #include <dev/bhnd/bhnd.h>
29 #include <dev/bhnd/cores/chipc/chipc.h>
30 #include <dev/bhnd/cores/chipc/chipcreg.h>
32 #include <dev/bhnd/bcma/bcma_dmp.h>
34 #include "bhnd_nvram_map.h"
36 #include "bhnd_pmureg.h"
37 #include "bhnd_pmuvar.h"
39 #include "bhnd_pmu_private.h"
41 #define PMU_LOG(_sc, _fmt, ...) do { \
42 if (_sc->dev != NULL) \
43 device_printf(_sc->dev, _fmt, ##__VA_ARGS__); \
45 printf(_fmt, ##__VA_ARGS__); \
49 #define PMU_DEBUG(_sc, _fmt, ...) PMU_LOG(_sc, _fmt, ##__VA_ARGS__)
51 #define PMU_DEBUG(_sc, _fmt, ...)
54 typedef struct pmu0_xtaltab0 pmu0_xtaltab0_t;
55 typedef struct pmu1_xtaltab0 pmu1_xtaltab0_t;
57 /* PLL controls/clocks */
58 static const pmu1_xtaltab0_t *bhnd_pmu1_xtaltab0(struct bhnd_pmu_query *sc);
59 static const pmu1_xtaltab0_t *bhnd_pmu1_xtaldef0(struct bhnd_pmu_query *sc);
61 static void bhnd_pmu0_pllinit0(struct bhnd_pmu_softc *sc, uint32_t xtal);
62 static uint32_t bhnd_pmu0_cpuclk0(struct bhnd_pmu_query *sc);
63 static uint32_t bhnd_pmu0_alpclk0(struct bhnd_pmu_query *sc);
65 static void bhnd_pmu1_pllinit0(struct bhnd_pmu_softc *sc, uint32_t xtal);
66 static uint32_t bhnd_pmu1_pllfvco0(struct bhnd_pmu_query *sc);
67 static uint32_t bhnd_pmu1_cpuclk0(struct bhnd_pmu_query *sc);
68 static uint32_t bhnd_pmu1_alpclk0(struct bhnd_pmu_query *sc);
70 static uint32_t bhnd_pmu5_clock(struct bhnd_pmu_query *sc, u_int pll0, u_int m);
73 static bool bhnd_pmu_res_depfltr_bb(struct bhnd_pmu_softc *sc);
74 static bool bhnd_pmu_res_depfltr_ncb(struct bhnd_pmu_softc *sc);
75 static bool bhnd_pmu_res_depfltr_paldo(struct bhnd_pmu_softc *sc);
76 static bool bhnd_pmu_res_depfltr_npaldo(struct bhnd_pmu_softc *sc);
77 static uint32_t bhnd_pmu_res_deps(struct bhnd_pmu_softc *sc, uint32_t rsrcs,
79 static int bhnd_pmu_res_uptime(struct bhnd_pmu_softc *sc, uint8_t rsrc,
81 static int bhnd_pmu_res_masks(struct bhnd_pmu_softc *sc, uint32_t *pmin,
84 static void bhnd_pmu_spuravoid_pllupdate(struct bhnd_pmu_softc *sc,
86 static void bhnd_pmu_set_4330_plldivs(struct bhnd_pmu_softc *sc);
88 #define BHND_PMU_REV(_sc) \
89 ((uint8_t)BHND_PMU_GET_BITS((_sc)->caps, BHND_PMU_CAP_REV))
91 #define PMU_WAIT_CLKST(_sc, _val, _mask) \
92 bhnd_pmu_wait_clkst((_sc), (_sc)->dev, (_sc)->res, \
93 BHND_CLK_CTL_ST, (_val), (_mask))
95 #define PMURES_BIT(_bit) \
96 (1 << (BHND_PMU_ ## _bit))
98 #define PMU_CST4330_SDIOD_CHIPMODE(_sc) \
99 CHIPC_CST4330_CHIPMODE_SDIOD((_sc)->io->rd_chipst((_sc)->io_ctx))
102 * Initialize @p query state.
104 * @param[out] query On success, will be populated with a valid query instance
106 * @param dev The device owning @p query, or NULL.
107 * @param id The bhnd chip identification.
108 * @param io I/O callback functions.
109 * @param ctx I/O callback context.
112 * @retval non-zero if the query state could not be initialized.
115 bhnd_pmu_query_init(struct bhnd_pmu_query *query, device_t dev,
116 struct bhnd_chipid id, const struct bhnd_pmu_io *io, void *ctx)
122 query->caps = BHND_PMU_READ_4(query, BHND_PMU_CAP);
128 * Release any resources held by @p query.
130 * @param query A query instance previously initialized via
131 * bhnd_pmu_query_init().
134 bhnd_pmu_query_fini(struct bhnd_pmu_query *query)
140 * Perform an indirect register read.
142 * @param addr Offset of the address register.
143 * @param data Offset of the data register.
144 * @param reg Indirect register to be read.
147 bhnd_pmu_ind_read(const struct bhnd_pmu_io *io, void *io_ctx, bus_size_t addr,
148 bus_size_t data, uint32_t reg)
150 io->wr4(addr, reg, io_ctx);
151 return (io->rd4(data, io_ctx));
155 * Perform an indirect register write.
157 * @param addr Offset of the address register.
158 * @param data Offset of the data register.
159 * @param reg Indirect register to be written.
160 * @param val Value to be written to @p reg.
161 * @param mask Only the bits defined by @p mask will be updated from @p val.
164 bhnd_pmu_ind_write(const struct bhnd_pmu_io *io, void *io_ctx, bus_size_t addr,
165 bus_size_t data, uint32_t reg, uint32_t val, uint32_t mask)
169 io->wr4(addr, reg, io_ctx);
171 if (mask != UINT32_MAX) {
172 rval = io->rd4(data, io_ctx);
173 rval &= ~mask | (val & mask);
178 io->wr4(data, rval, io_ctx);
182 * Wait for up to BHND_PMU_MAX_TRANSITION_DLY microseconds for the per-core
183 * clock status to be equal to @p value after applying @p mask.
185 * @param sc PMU driver state.
186 * @param dev Requesting device.
187 * @param r An active resource mapping the clock status register.
188 * @param clkst_reg Offset to the CLK_CTL_ST register.
189 * @param value Value to wait for.
190 * @param mask Mask to apply prior to value comparison.
193 bhnd_pmu_wait_clkst(struct bhnd_pmu_softc *sc, device_t dev,
194 struct bhnd_resource *r, bus_size_t clkst_reg, uint32_t value,
199 /* Bitswapped HTAVAIL/ALPAVAIL work-around */
200 if (sc->quirks & BPMU_QUIRK_CLKCTL_CCS0) {
201 uint32_t fmask, fval;
203 fmask = mask & ~(BHND_CCS_HTAVAIL | BHND_CCS_ALPAVAIL);
204 fval = value & ~(BHND_CCS_HTAVAIL | BHND_CCS_ALPAVAIL);
206 if (mask & BHND_CCS_HTAVAIL)
207 fmask |= BHND_CCS0_HTAVAIL;
208 if (value & BHND_CCS_HTAVAIL)
209 fval |= BHND_CCS0_HTAVAIL;
211 if (mask & BHND_CCS_ALPAVAIL)
212 fmask |= BHND_CCS0_ALPAVAIL;
213 if (value & BHND_CCS_ALPAVAIL)
214 fval |= BHND_CCS0_ALPAVAIL;
220 for (uint32_t i = 0; i < BHND_PMU_MAX_TRANSITION_DLY; i += 10) {
221 clkst = bhnd_bus_read_4(r, clkst_reg);
222 if ((clkst & mask) == (value & mask))
228 device_printf(dev, "clkst wait timeout (value=%#x, "
229 "mask=%#x)\n", value, mask);
234 /* Setup switcher voltage */
236 bhnd_pmu_set_switcher_voltage(struct bhnd_pmu_softc *sc, uint8_t bb_voltage,
239 BHND_PMU_REGCTRL_WRITE(sc, 0x01, (bb_voltage & 0x1f) << 22, ~0);
240 BHND_PMU_REGCTRL_WRITE(sc, 0x00, (rf_voltage & 0x1f) << 14, ~0);
244 bhnd_pmu_set_ldo_voltage(struct bhnd_pmu_softc *sc, uint8_t ldo,
253 switch (sc->cid.chip_id) {
254 case BHND_CHIPID_BCM4328:
255 case BHND_CHIPID_BCM5354:
257 case SET_LDO_VOLTAGE_LDO1:
262 case SET_LDO_VOLTAGE_LDO2:
267 case SET_LDO_VOLTAGE_LDO3:
272 case SET_LDO_VOLTAGE_PAREF:
278 panic("unknown BCM4328/BCM5354 LDO %hhu\n", ldo);
281 case BHND_CHIPID_BCM4312:
283 case SET_LDO_VOLTAGE_PAREF:
289 panic("unknown BCM4312 LDO %hhu\n", ldo);
292 case BHND_CHIPID_BCM4325:
294 case SET_LDO_VOLTAGE_CLDO_PWM:
299 case SET_LDO_VOLTAGE_CLDO_BURST:
304 case SET_LDO_VOLTAGE_CBUCK_PWM:
308 /* Bit 116 & 119 are inverted in CLB for opt 2b */
309 chipst = BHND_CHIPC_READ_CHIPST(sc->chipc_dev);
310 if (BHND_PMU_GET_BITS(chipst, CHIPC_CST4325_PMUTOP_2B))
313 case SET_LDO_VOLTAGE_CBUCK_BURST:
317 /* Bit 121 & 124 are inverted in CLB for opt 2b */
318 chipst = BHND_CHIPC_READ_CHIPST(sc->chipc_dev);
319 if (BHND_PMU_GET_BITS(chipst, CHIPC_CST4325_PMUTOP_2B))
322 case SET_LDO_VOLTAGE_LNLDO1:
327 case SET_LDO_VOLTAGE_LNLDO2_SEL:
333 panic("unknown BCM4325 LDO %hhu\n", ldo);
336 case BHND_CHIPID_BCM4336:
338 case SET_LDO_VOLTAGE_CLDO_PWM:
343 case SET_LDO_VOLTAGE_CLDO_BURST:
348 case SET_LDO_VOLTAGE_LNLDO1:
354 panic("unknown BCM4336 LDO %hhu\n", ldo);
357 case BHND_CHIPID_BCM4330:
359 case SET_LDO_VOLTAGE_CBUCK_PWM:
365 panic("unknown BCM4330 LDO %hhu\n", ldo);
368 case BHND_CHIPID_BCM4331:
370 case SET_LDO_VOLTAGE_PAREF:
376 panic("unknown BCM4331 LDO %hhu\n", ldo);
380 panic("cannot set LDO voltage on unsupported chip %hu\n",
385 regctrl = (voltage & mask) << shift;
386 BHND_PMU_REGCTRL_WRITE(sc, addr, regctrl, mask << shift);
389 /* d11 slow to fast clock transition time in slow clock cycles */
390 #define D11SCC_SLOW2FAST_TRANSITION 2
393 bhnd_pmu_fast_pwrup_delay(struct bhnd_pmu_softc *sc, uint16_t *pwrup_delay)
400 switch (sc->cid.chip_id) {
401 case BHND_CHIPID_BCM43224:
402 case BHND_CHIPID_BCM43225:
403 case BHND_CHIPID_BCM43421:
404 case BHND_CHIPID_BCM43235:
405 case BHND_CHIPID_BCM43236:
406 case BHND_CHIPID_BCM43238:
407 case BHND_CHIPID_BCM4331:
408 case BHND_CHIPID_BCM6362:
409 case BHND_CHIPID_BCM4313:
413 case BHND_CHIPID_BCM4325:
414 error = bhnd_pmu_res_uptime(sc, BHND_PMU_RES4325_HT_AVAIL,
419 ilp = bhnd_pmu_ilp_clock(&sc->query);
420 delay = (uptime + D11SCC_SLOW2FAST_TRANSITION) *
421 ((1000000 + ilp - 1) / ilp);
422 delay = (11 * delay) / 10;
425 case BHND_CHIPID_BCM4329:
426 error = bhnd_pmu_res_uptime(sc, BHND_PMU_RES4329_HT_AVAIL,
431 ilp = bhnd_pmu_ilp_clock(&sc->query);
432 delay = (uptime + D11SCC_SLOW2FAST_TRANSITION) *
433 ((1000000 + ilp - 1) / ilp);
434 delay = (11 * delay) / 10;
437 case BHND_CHIPID_BCM4319:
441 case BHND_CHIPID_BCM4336:
442 error = bhnd_pmu_res_uptime(sc, BHND_PMU_RES4336_HT_AVAIL,
447 ilp = bhnd_pmu_ilp_clock(&sc->query);
448 delay = (uptime + D11SCC_SLOW2FAST_TRANSITION) *
449 ((1000000 + ilp - 1) / ilp);
450 delay = (11 * delay) / 10;
453 case BHND_CHIPID_BCM4330:
454 error = bhnd_pmu_res_uptime(sc, BHND_PMU_RES4330_HT_AVAIL,
459 ilp = bhnd_pmu_ilp_clock(&sc->query);
460 delay = (uptime + D11SCC_SLOW2FAST_TRANSITION) *
461 ((1000000 + ilp - 1) / ilp);
462 delay = (11 * delay) / 10;
466 delay = BHND_PMU_MAX_TRANSITION_DLY;
470 *pwrup_delay = (uint16_t)delay;
475 bhnd_pmu_force_ilp(struct bhnd_pmu_softc *sc, bool force)
480 pctrl = BHND_PMU_READ_4(sc, BHND_PMU_CTRL);
484 pctrl &= ~(BHND_PMU_CTRL_HT_REQ_EN | BHND_PMU_CTRL_ALP_REQ_EN);
486 pctrl |= (BHND_PMU_CTRL_HT_REQ_EN | BHND_PMU_CTRL_ALP_REQ_EN);
488 BHND_PMU_WRITE_4(sc, BHND_PMU_CTRL, pctrl);
493 /* Setup resource up/down timers */
499 typedef bool (*pmu_res_filter) (struct bhnd_pmu_softc *sc);
501 /* Change resource dependencies masks */
503 uint32_t res_mask; /* resources (chip specific) */
504 int8_t action; /* action */
505 uint32_t depend_mask; /* changes to the dependencies mask */
506 pmu_res_filter filter; /* action is taken when filter is NULL or returns true */
509 /* Resource dependencies mask change action */
510 #define RES_DEPEND_SET 0 /* Override the dependencies mask */
511 #define RES_DEPEND_ADD 1 /* Add to the dependencies mask */
512 #define RES_DEPEND_REMOVE -1 /* Remove from the dependencies mask */
514 static const pmu_res_updown_t bcm4328a0_res_updown[] = {
516 BHND_PMU_RES4328_EXT_SWITCHER_PWM, 0x0101}, {
517 BHND_PMU_RES4328_BB_SWITCHER_PWM, 0x1f01}, {
518 BHND_PMU_RES4328_BB_SWITCHER_BURST, 0x010f}, {
519 BHND_PMU_RES4328_BB_EXT_SWITCHER_BURST, 0x0101}, {
520 BHND_PMU_RES4328_ILP_REQUEST, 0x0202}, {
521 BHND_PMU_RES4328_RADIO_SWITCHER_PWM, 0x0f01}, {
522 BHND_PMU_RES4328_RADIO_SWITCHER_BURST, 0x0f01}, {
523 BHND_PMU_RES4328_ROM_SWITCH, 0x0101}, {
524 BHND_PMU_RES4328_PA_REF_LDO, 0x0f01}, {
525 BHND_PMU_RES4328_RADIO_LDO, 0x0f01}, {
526 BHND_PMU_RES4328_AFE_LDO, 0x0f01}, {
527 BHND_PMU_RES4328_PLL_LDO, 0x0f01}, {
528 BHND_PMU_RES4328_BG_FILTBYP, 0x0101}, {
529 BHND_PMU_RES4328_TX_FILTBYP, 0x0101}, {
530 BHND_PMU_RES4328_RX_FILTBYP, 0x0101}, {
531 BHND_PMU_RES4328_XTAL_PU, 0x0101}, {
532 BHND_PMU_RES4328_XTAL_EN, 0xa001}, {
533 BHND_PMU_RES4328_BB_PLL_FILTBYP, 0x0101}, {
534 BHND_PMU_RES4328_RF_PLL_FILTBYP, 0x0101}, {
535 BHND_PMU_RES4328_BB_PLL_PU, 0x0701}
538 static const pmu_res_depend_t bcm4328a0_res_depend[] = {
539 /* Adjust ILP request resource not to force ext/BB switchers into burst mode */
541 PMURES_BIT(RES4328_ILP_REQUEST),
543 PMURES_BIT(RES4328_EXT_SWITCHER_PWM) |
544 PMURES_BIT(RES4328_BB_SWITCHER_PWM), NULL}
547 static const pmu_res_updown_t bcm4325a0_res_updown[] = {
549 BHND_PMU_RES4325_XTAL_PU, 0x1501}
552 static const pmu_res_depend_t bcm4325a0_res_depend[] = {
553 /* Adjust OTP PU resource dependencies - remove BB BURST */
555 PMURES_BIT(RES4325_OTP_PU),
557 PMURES_BIT(RES4325_BUCK_BOOST_BURST), NULL},
558 /* Adjust ALP/HT Avail resource dependencies - bring up BB along if it is used. */
560 PMURES_BIT(RES4325_ALP_AVAIL) | PMURES_BIT(RES4325_HT_AVAIL),
562 PMURES_BIT(RES4325_BUCK_BOOST_BURST) |
563 PMURES_BIT(RES4325_BUCK_BOOST_PWM), bhnd_pmu_res_depfltr_bb},
564 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
566 PMURES_BIT(RES4325_HT_AVAIL),
568 PMURES_BIT(RES4325_RX_PWRSW_PU) |
569 PMURES_BIT(RES4325_TX_PWRSW_PU) |
570 PMURES_BIT(RES4325_LOGEN_PWRSW_PU) |
571 PMURES_BIT(RES4325_AFE_PWRSW_PU), NULL},
572 /* Adjust ALL resource dependencies - remove CBUCK dependencies if it is not used. */
574 PMURES_BIT(RES4325_ILP_REQUEST) |
575 PMURES_BIT(RES4325_ABUCK_BURST) |
576 PMURES_BIT(RES4325_ABUCK_PWM) |
577 PMURES_BIT(RES4325_LNLDO1_PU) |
578 PMURES_BIT(RES4325C1_LNLDO2_PU) |
579 PMURES_BIT(RES4325_XTAL_PU) |
580 PMURES_BIT(RES4325_ALP_AVAIL) |
581 PMURES_BIT(RES4325_RX_PWRSW_PU) |
582 PMURES_BIT(RES4325_TX_PWRSW_PU) |
583 PMURES_BIT(RES4325_RFPLL_PWRSW_PU) |
584 PMURES_BIT(RES4325_LOGEN_PWRSW_PU) |
585 PMURES_BIT(RES4325_AFE_PWRSW_PU) |
586 PMURES_BIT(RES4325_BBPLL_PWRSW_PU) |
587 PMURES_BIT(RES4325_HT_AVAIL), RES_DEPEND_REMOVE,
588 PMURES_BIT(RES4325B0_CBUCK_LPOM) |
589 PMURES_BIT(RES4325B0_CBUCK_BURST) |
590 PMURES_BIT(RES4325B0_CBUCK_PWM), bhnd_pmu_res_depfltr_ncb}
593 static const pmu_res_updown_t bcm4315a0_res_updown[] = {
595 BHND_PMU_RES4315_XTAL_PU, 0x2501}
598 static const pmu_res_depend_t bcm4315a0_res_depend[] = {
599 /* Adjust OTP PU resource dependencies - not need PALDO unless write */
601 PMURES_BIT(RES4315_OTP_PU),
603 PMURES_BIT(RES4315_PALDO_PU), bhnd_pmu_res_depfltr_npaldo},
604 /* Adjust ALP/HT Avail resource dependencies - bring up PALDO along if it is used. */
606 PMURES_BIT(RES4315_ALP_AVAIL) | PMURES_BIT(RES4315_HT_AVAIL),
608 PMURES_BIT(RES4315_PALDO_PU), bhnd_pmu_res_depfltr_paldo},
609 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
611 PMURES_BIT(RES4315_HT_AVAIL),
613 PMURES_BIT(RES4315_RX_PWRSW_PU) |
614 PMURES_BIT(RES4315_TX_PWRSW_PU) |
615 PMURES_BIT(RES4315_LOGEN_PWRSW_PU) |
616 PMURES_BIT(RES4315_AFE_PWRSW_PU), NULL},
617 /* Adjust ALL resource dependencies - remove CBUCK dependencies if it is not used. */
619 PMURES_BIT(RES4315_CLDO_PU) | PMURES_BIT(RES4315_ILP_REQUEST) |
620 PMURES_BIT(RES4315_LNLDO1_PU) |
621 PMURES_BIT(RES4315_OTP_PU) |
622 PMURES_BIT(RES4315_LNLDO2_PU) |
623 PMURES_BIT(RES4315_XTAL_PU) |
624 PMURES_BIT(RES4315_ALP_AVAIL) |
625 PMURES_BIT(RES4315_RX_PWRSW_PU) |
626 PMURES_BIT(RES4315_TX_PWRSW_PU) |
627 PMURES_BIT(RES4315_RFPLL_PWRSW_PU) |
628 PMURES_BIT(RES4315_LOGEN_PWRSW_PU) |
629 PMURES_BIT(RES4315_AFE_PWRSW_PU) |
630 PMURES_BIT(RES4315_BBPLL_PWRSW_PU) |
631 PMURES_BIT(RES4315_HT_AVAIL), RES_DEPEND_REMOVE,
632 PMURES_BIT(RES4315_CBUCK_LPOM) |
633 PMURES_BIT(RES4315_CBUCK_BURST) |
634 PMURES_BIT(RES4315_CBUCK_PWM), bhnd_pmu_res_depfltr_ncb}
637 /* 4329 specific. needs to come back this issue later */
638 static const pmu_res_updown_t bcm4329_res_updown[] = {
640 BHND_PMU_RES4329_XTAL_PU, 0x1501}
643 static const pmu_res_depend_t bcm4329_res_depend[] = {
644 /* Adjust HT Avail resource dependencies */
646 PMURES_BIT(RES4329_HT_AVAIL),
648 PMURES_BIT(RES4329_CBUCK_LPOM) |
649 PMURES_BIT(RES4329_CBUCK_BURST) |
650 PMURES_BIT(RES4329_CBUCK_PWM) |
651 PMURES_BIT(RES4329_CLDO_PU) |
652 PMURES_BIT(RES4329_PALDO_PU) |
653 PMURES_BIT(RES4329_LNLDO1_PU) |
654 PMURES_BIT(RES4329_XTAL_PU) |
655 PMURES_BIT(RES4329_ALP_AVAIL) |
656 PMURES_BIT(RES4329_RX_PWRSW_PU) |
657 PMURES_BIT(RES4329_TX_PWRSW_PU) |
658 PMURES_BIT(RES4329_RFPLL_PWRSW_PU) |
659 PMURES_BIT(RES4329_LOGEN_PWRSW_PU) |
660 PMURES_BIT(RES4329_AFE_PWRSW_PU) |
661 PMURES_BIT(RES4329_BBPLL_PWRSW_PU), NULL}
664 static const pmu_res_updown_t bcm4319a0_res_updown[] = {
666 BHND_PMU_RES4319_XTAL_PU, 0x3f01}
669 static const pmu_res_depend_t bcm4319a0_res_depend[] = {
670 /* Adjust OTP PU resource dependencies - not need PALDO unless write */
672 PMURES_BIT(RES4319_OTP_PU),
674 PMURES_BIT(RES4319_PALDO_PU), bhnd_pmu_res_depfltr_npaldo},
675 /* Adjust HT Avail resource dependencies - bring up PALDO along if it is used. */
677 PMURES_BIT(RES4319_HT_AVAIL),
679 PMURES_BIT(RES4319_PALDO_PU), bhnd_pmu_res_depfltr_paldo},
680 /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */
682 PMURES_BIT(RES4319_HT_AVAIL),
684 PMURES_BIT(RES4319_RX_PWRSW_PU) |
685 PMURES_BIT(RES4319_TX_PWRSW_PU) |
686 PMURES_BIT(RES4319_RFPLL_PWRSW_PU) |
687 PMURES_BIT(RES4319_LOGEN_PWRSW_PU) |
688 PMURES_BIT(RES4319_AFE_PWRSW_PU), NULL}
691 static const pmu_res_updown_t bcm4336a0_res_updown[] = {
693 BHND_PMU_RES4336_HT_AVAIL, 0x0D01}
696 static const pmu_res_depend_t bcm4336a0_res_depend[] = {
697 /* Just a dummy entry for now */
699 PMURES_BIT(RES4336_RSVD), RES_DEPEND_ADD, 0, NULL}
702 static const pmu_res_updown_t bcm4330a0_res_updown[] = {
704 BHND_PMU_RES4330_HT_AVAIL, 0x0e02}
707 static const pmu_res_depend_t bcm4330a0_res_depend[] = {
708 /* Just a dummy entry for now */
710 PMURES_BIT(RES4330_HT_AVAIL), RES_DEPEND_ADD, 0, NULL}
713 /* true if the power topology uses the buck boost to provide 3.3V to VDDIO_RF
716 bhnd_pmu_res_depfltr_bb(struct bhnd_pmu_softc *sc)
718 return (BHND_PMU_GET_FLAG(sc->board.board_flags, BHND_BFL_BUCKBOOST));
721 /* true if the power topology doesn't use the cbuck. Key on chiprev also if
722 * the chip is BCM4325. */
724 bhnd_pmu_res_depfltr_ncb(struct bhnd_pmu_softc *sc)
726 if (sc->cid.chip_id == BHND_CHIPID_BCM4325 && sc->cid.chip_rev <= 1)
729 return (BHND_PMU_GET_FLAG(sc->board.board_flags, BHND_BFL_NOCBUCK));
732 /* true if the power topology uses the PALDO */
734 bhnd_pmu_res_depfltr_paldo(struct bhnd_pmu_softc *sc)
736 return (BHND_PMU_GET_FLAG(sc->board.board_flags, BHND_BFL_PALDO));
739 /* true if the power topology doesn't use the PALDO */
741 bhnd_pmu_res_depfltr_npaldo(struct bhnd_pmu_softc *sc)
743 return (!BHND_PMU_GET_FLAG(sc->board.board_flags, BHND_BFL_PALDO));
746 /* Determine min/max rsrc masks. Value 0 leaves hardware at default. */
748 bhnd_pmu_res_masks(struct bhnd_pmu_softc *sc, uint32_t *pmin, uint32_t *pmax)
750 uint32_t max_mask, min_mask;
751 uint32_t chipst, otpsel;
760 rsrcs = BHND_PMU_GET_BITS(sc->caps, BHND_PMU_CAP_RC);
762 /* determine min/max rsrc masks */
763 switch (sc->cid.chip_id) {
764 case BHND_CHIPID_BCM4325:
765 /* If used by this device, enable the CBUCK */
766 if (!bhnd_pmu_res_depfltr_ncb(sc))
767 min_mask |= PMURES_BIT(RES4325B0_CBUCK_LPOM);
769 chipst = BHND_CHIPC_READ_CHIPST(sc->chipc_dev);
770 if (BHND_PMU_GET_BITS(chipst, CHIPC_CST4325_PMUTOP_2B))
771 min_mask |= PMURES_BIT(RES4325B0_CLDO_PU);
773 /* Is OTP required? */
774 otpsel = BHND_PMU_GET_BITS(chipst, CHIPC_CST4325_SPROM_OTP_SEL);
775 if (otpsel != CHIPC_CST_OTP_PWRDN)
776 min_mask |= PMURES_BIT(RES4325_OTP_PU);
778 /* Leave buck boost on in burst mode for certain boards */
779 if (sc->board.board_flags & BHND_BFL_BUCKBOOST) {
780 switch (sc->board.board_type) {
781 case BHND_BOARD_BCM94325DEVBU:
782 case BHND_BOARD_BCM94325BGABU:
783 min_mask |= PMURES_BIT(
784 RES4325_BUCK_BOOST_BURST);
789 /* Allow all resources to be turned on upon requests */
790 max_mask = ~(~0 << rsrcs);
793 case BHND_CHIPID_BCM4312:
794 /* default min_mask = 0x80000cbb is wrong */
798 * pmu_res_updown_table_sz = 0;
799 * pmu_res_depend_table_sz = 0;
803 case BHND_CHIPID_BCM4322:
804 case BHND_CHIPID_BCM43221:
805 case BHND_CHIPID_BCM43231:
806 case BHND_CHIPID_BCM4342:
807 if (sc->cid.chip_rev >= 2)
810 /* request ALP(can skip for A1) */
811 min_mask = PMURES_BIT(RES4322_RF_LDO) |
812 PMURES_BIT(RES4322_XTAL_PU) |
813 PMURES_BIT(RES4322_ALP_AVAIL);
815 if (bhnd_get_attach_type(sc->chipc_dev) == BHND_ATTACH_NATIVE) {
817 PMURES_BIT(RES4322_SI_PLL_ON) |
818 PMURES_BIT(RES4322_HT_SI_AVAIL) |
819 PMURES_BIT(RES4322_PHY_PLL_ON) |
820 PMURES_BIT(RES4322_OTP_PU) |
821 PMURES_BIT(RES4322_HT_PHY_AVAIL);
826 case BHND_CHIPID_BCM43222:
827 case BHND_CHIPID_BCM43111:
828 case BHND_CHIPID_BCM43112:
829 case BHND_CHIPID_BCM43224:
830 case BHND_CHIPID_BCM43225:
831 case BHND_CHIPID_BCM43421:
832 case BHND_CHIPID_BCM43226:
833 case BHND_CHIPID_BCM43420:
834 case BHND_CHIPID_BCM43235:
835 case BHND_CHIPID_BCM43236:
836 case BHND_CHIPID_BCM43238:
837 case BHND_CHIPID_BCM43234:
838 case BHND_CHIPID_BCM43237:
839 case BHND_CHIPID_BCM4331:
840 case BHND_CHIPID_BCM43431:
841 case BHND_CHIPID_BCM6362:
842 /* use chip default */
845 case BHND_CHIPID_BCM4328:
847 PMURES_BIT(RES4328_BB_SWITCHER_PWM) |
848 PMURES_BIT(RES4328_EXT_SWITCHER_PWM) |
849 PMURES_BIT(RES4328_XTAL_EN);
850 max_mask = 0xfffffff;
853 case BHND_CHIPID_BCM5354:
854 /* Allow (but don't require) PLL to turn on */
855 max_mask = 0xfffffff;
858 case BHND_CHIPID_BCM4329:
859 /* Down to save the power. */
860 if (sc->cid.chip_rev >= 0x2) {
862 PMURES_BIT(RES4329_CBUCK_LPOM) |
863 PMURES_BIT(RES4329_LNLDO1_PU) |
864 PMURES_BIT(RES4329_CLDO_PU);
867 PMURES_BIT(RES4329_CBUCK_LPOM) |
868 PMURES_BIT(RES4329_CLDO_PU);
871 /* Is OTP required? */
872 chipst = BHND_CHIPC_READ_CHIPST(sc->chipc_dev);
873 otpsel = BHND_PMU_GET_BITS(chipst, CHIPC_CST4329_SPROM_OTP_SEL);
874 if (otpsel != CHIPC_CST_OTP_PWRDN)
875 min_mask |= PMURES_BIT(RES4329_OTP_PU);
877 /* Allow (but don't require) PLL to turn on */
881 case BHND_CHIPID_BCM4319:
882 /* We only need a few resources to be kept on all the time */
883 min_mask = PMURES_BIT(RES4319_CBUCK_LPOM) |
884 PMURES_BIT(RES4319_CLDO_PU);
886 /* Allow everything else to be turned on upon requests */
887 max_mask = ~(~0 << rsrcs);
890 case BHND_CHIPID_BCM4336:
891 /* Down to save the power. */
893 PMURES_BIT(RES4336_CBUCK_LPOM) |
894 PMURES_BIT(RES4336_CLDO_PU) |
895 PMURES_BIT(RES4336_LDO3P3_PU) |
896 PMURES_BIT(RES4336_OTP_PU) |
897 PMURES_BIT(RES4336_DIS_INT_RESET_PD);
898 /* Allow (but don't require) PLL to turn on */
899 max_mask = 0x1ffffff;
902 case BHND_CHIPID_BCM4330:
903 /* Down to save the power. */
905 PMURES_BIT(RES4330_CBUCK_LPOM) | PMURES_BIT(RES4330_CLDO_PU)
906 | PMURES_BIT(RES4330_DIS_INT_RESET_PD) |
907 PMURES_BIT(RES4330_LDO3P3_PU) | PMURES_BIT(RES4330_OTP_PU);
908 /* Allow (but don't require) PLL to turn on */
909 max_mask = 0xfffffff;
912 case BHND_CHIPID_BCM4313:
913 min_mask = PMURES_BIT(RES4313_BB_PU_RSRC) |
914 PMURES_BIT(RES4313_XTAL_PU_RSRC) |
915 PMURES_BIT(RES4313_ALP_AVAIL_RSRC) |
916 PMURES_BIT(RES4313_BB_PLL_PWRSW_RSRC);
923 /* Apply nvram override to min mask */
924 error = bhnd_nvram_getvar_uint32(sc->chipc_dev, BHND_NVAR_RMIN, &nval);
925 if (error && error != ENOENT) {
926 PMU_LOG(sc, "NVRAM error reading %s: %d\n",
927 BHND_NVAR_RMIN, error);
930 PMU_DEBUG(sc, "Applying rmin=%#x to min_mask\n", nval);
934 /* Apply nvram override to max mask */
935 error = bhnd_nvram_getvar_uint32(sc->chipc_dev, BHND_NVAR_RMAX, &nval);
936 if (error && error != ENOENT) {
937 PMU_LOG(sc, "NVRAM error reading %s: %d\n",
938 BHND_NVAR_RMAX, error);
941 PMU_DEBUG(sc, "Applying rmax=%#x to max_mask\n", nval);
954 /* initialize PMU resources */
956 bhnd_pmu_res_init(struct bhnd_pmu_softc *sc)
958 const pmu_res_updown_t *pmu_res_updown_table;
959 const pmu_res_depend_t *pmu_res_depend_table;
960 size_t pmu_res_updown_table_sz;
961 size_t pmu_res_depend_table_sz;
962 uint32_t max_mask, min_mask;
966 pmu_res_depend_table = NULL;
967 pmu_res_depend_table_sz = 0;
969 pmu_res_updown_table = NULL;
970 pmu_res_updown_table_sz = 0;
972 switch (sc->cid.chip_id) {
973 case BHND_CHIPID_BCM4315:
974 /* Optimize resources up/down timers */
975 pmu_res_updown_table = bcm4315a0_res_updown;
976 pmu_res_updown_table_sz = nitems(bcm4315a0_res_updown);
978 /* Optimize resources dependencies */
979 pmu_res_depend_table = bcm4315a0_res_depend;
980 pmu_res_depend_table_sz = nitems(bcm4315a0_res_depend);
983 case BHND_CHIPID_BCM4325:
984 /* Optimize resources up/down timers */
985 pmu_res_updown_table = bcm4325a0_res_updown;
986 pmu_res_updown_table_sz = nitems(bcm4325a0_res_updown);
988 /* Optimize resources dependencies */
989 pmu_res_depend_table = bcm4325a0_res_depend;
990 pmu_res_depend_table_sz = nitems(bcm4325a0_res_depend);
993 case BHND_CHIPID_BCM4328:
994 /* Optimize resources up/down timers */
995 pmu_res_updown_table = bcm4328a0_res_updown;
996 pmu_res_updown_table_sz = nitems(bcm4328a0_res_updown);
998 /* Optimize resources dependencies */
999 pmu_res_depend_table = bcm4328a0_res_depend;
1000 pmu_res_depend_table_sz = nitems(bcm4328a0_res_depend);
1003 case BHND_CHIPID_BCM4329:
1004 /* Optimize resources up/down timers */
1005 pmu_res_updown_table = bcm4329_res_updown;
1006 pmu_res_updown_table_sz = nitems(bcm4329_res_updown);
1008 /* Optimize resources dependencies */
1009 pmu_res_depend_table = bcm4329_res_depend;
1010 pmu_res_depend_table_sz = nitems(bcm4329_res_depend);
1013 case BHND_CHIPID_BCM4319:
1014 /* Optimize resources up/down timers */
1015 pmu_res_updown_table = bcm4319a0_res_updown;
1016 pmu_res_updown_table_sz = nitems(bcm4319a0_res_updown);
1018 /* Optimize resources dependencies masks */
1019 pmu_res_depend_table = bcm4319a0_res_depend;
1020 pmu_res_depend_table_sz = nitems(bcm4319a0_res_depend);
1023 case BHND_CHIPID_BCM4336:
1024 /* Optimize resources up/down timers */
1025 pmu_res_updown_table = bcm4336a0_res_updown;
1026 pmu_res_updown_table_sz = nitems(bcm4336a0_res_updown);
1028 /* Optimize resources dependencies masks */
1029 pmu_res_depend_table = bcm4336a0_res_depend;
1030 pmu_res_depend_table_sz = nitems(bcm4336a0_res_depend);
1033 case BHND_CHIPID_BCM4330:
1034 /* Optimize resources up/down timers */
1035 pmu_res_updown_table = bcm4330a0_res_updown;
1036 pmu_res_updown_table_sz = nitems(bcm4330a0_res_updown);
1038 /* Optimize resources dependencies masks */
1039 pmu_res_depend_table = bcm4330a0_res_depend;
1040 pmu_res_depend_table_sz = nitems(bcm4330a0_res_depend);
1047 rsrcs = BHND_PMU_GET_BITS(sc->caps, BHND_PMU_CAP_RC);
1049 /* Program up/down timers */
1050 for (size_t i = 0; i < pmu_res_updown_table_sz; i++) {
1051 const pmu_res_updown_t *updt;
1053 KASSERT(pmu_res_updown_table != NULL, ("no updown tables"));
1055 updt = &pmu_res_updown_table[pmu_res_updown_table_sz - i - 1];
1057 PMU_DEBUG(sc, "Changing rsrc %d res_updn_timer to %#x\n",
1058 updt->resnum, updt->updown);
1060 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_TABLE_SEL, updt->resnum);
1061 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_UPDN_TIMER, updt->updown);
1064 /* Apply nvram overrides to up/down timers */
1065 for (uint8_t i = 0; i < rsrcs; i++) {
1069 snprintf(name, sizeof(name), "r%dt", i);
1070 error = bhnd_nvram_getvar_uint32(sc->chipc_dev, name, &val);
1072 if (error == ENOENT) {
1075 PMU_LOG(sc, "NVRAM error reading %s: %d\n",
1080 PMU_DEBUG(sc, "Applying %s=%s to rsrc %d res_updn_timer\n",
1083 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_TABLE_SEL, i);
1084 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_UPDN_TIMER, val);
1087 /* Program resource dependencies table */
1088 for (size_t i = 0; i < pmu_res_depend_table_sz; i++) {
1089 const pmu_res_depend_t *rdep;
1090 pmu_res_filter filter;
1091 uint32_t depend_mask;
1093 KASSERT(pmu_res_depend_table != NULL, ("no depend tables"));
1095 rdep = &pmu_res_depend_table[pmu_res_depend_table_sz - i - 1];
1096 filter = rdep->filter;
1098 if (filter != NULL && !filter(sc))
1101 for (uint8_t i = 0; i < rsrcs; i++) {
1102 if ((rdep->res_mask & BHND_PMURES_BIT(i)) == 0)
1105 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_TABLE_SEL, i);
1106 depend_mask = BHND_PMU_READ_4(sc,
1107 BHND_PMU_RES_DEP_MASK);
1108 switch (rdep->action) {
1109 case RES_DEPEND_SET:
1110 PMU_DEBUG(sc, "Changing rsrc %hhu res_dep_mask to "
1111 "%#x\n", i, table->depend_mask);
1112 depend_mask = rdep->depend_mask;
1115 case RES_DEPEND_ADD:
1116 PMU_DEBUG(sc, "Adding %#x to rsrc %hhu "
1117 "res_dep_mask\n", table->depend_mask, i);
1119 depend_mask |= rdep->depend_mask;
1122 case RES_DEPEND_REMOVE:
1123 PMU_DEBUG(sc, "Removing %#x from rsrc %hhu "
1124 "res_dep_mask\n", table->depend_mask, i);
1126 depend_mask &= ~(rdep->depend_mask);
1130 panic("unknown RES_DEPEND action: %d\n",
1139 /* Apply nvram overrides to dependencies masks */
1140 for (uint8_t i = 0; i < rsrcs; i++) {
1144 snprintf(name, sizeof(name), "r%dd", i);
1145 error = bhnd_nvram_getvar_uint32(sc->chipc_dev, name, &val);
1147 if (error == ENOENT) {
1150 PMU_LOG(sc, "NVRAM error reading %s: %d\n", name,
1155 PMU_DEBUG(sc, "Applying %s=%s to rsrc %d res_dep_mask\n", name,
1158 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_TABLE_SEL, i);
1159 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_DEP_MASK, val);
1162 /* Determine min/max rsrc masks */
1163 if ((error = bhnd_pmu_res_masks(sc, &min_mask, &max_mask)))
1166 /* It is required to program max_mask first and then min_mask */
1168 /* Program max resource mask */
1169 if (max_mask != 0) {
1170 PMU_DEBUG(sc, "Changing max_res_mask to 0x%x\n", max_mask);
1171 BHND_PMU_WRITE_4(sc, BHND_PMU_MAX_RES_MASK, max_mask);
1174 /* Program min resource mask */
1176 if (min_mask != 0) {
1177 PMU_DEBUG(sc, "Changing min_res_mask to 0x%x\n", min_mask);
1178 BHND_PMU_WRITE_4(sc, BHND_PMU_MIN_RES_MASK, min_mask);
1181 /* Add some delay; allow resources to come up and settle. */
1187 /* setup pll and query clock speed */
1188 struct pmu0_xtaltab0 {
1195 /* the following table is based on 880Mhz fvco */
1196 static const pmu0_xtaltab0_t pmu0_xtaltab0[] = {
1198 12000, 1, 73, 349525}, {
1199 13000, 2, 67, 725937}, {
1200 14400, 3, 61, 116508}, {
1201 15360, 4, 57, 305834}, {
1202 16200, 5, 54, 336579}, {
1203 16800, 6, 52, 399457}, {
1204 19200, 7, 45, 873813}, {
1205 19800, 8, 44, 466033}, {
1207 25000, 10, 70, 419430}, {
1208 26000, 11, 67, 725937}, {
1209 30000, 12, 58, 699050}, {
1210 38400, 13, 45, 873813}, {
1211 40000, 14, 45, 0}, {
1215 #define PMU0_XTAL0_DEFAULT 8
1217 /* setup pll and query clock speed */
1218 struct pmu1_xtaltab0 {
1227 static const pmu1_xtaltab0_t pmu1_xtaltab0_880_4329[] = {
1229 12000, 1, 3, 22, 0x9, 0xFFFFEF}, {
1230 13000, 2, 1, 6, 0xb, 0x483483}, {
1231 14400, 3, 1, 10, 0xa, 0x1C71C7}, {
1232 15360, 4, 1, 5, 0xb, 0x755555}, {
1233 16200, 5, 1, 10, 0x5, 0x6E9E06}, {
1234 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, {
1235 19200, 7, 1, 4, 0xb, 0x755555}, {
1236 19800, 8, 1, 11, 0x4, 0xA57EB}, {
1237 20000, 9, 1, 11, 0x4, 0x0}, {
1238 24000, 10, 3, 11, 0xa, 0x0}, {
1239 25000, 11, 5, 16, 0xb, 0x0}, {
1240 26000, 12, 1, 1, 0x21, 0xD89D89}, {
1241 30000, 13, 3, 8, 0xb, 0x0}, {
1242 37400, 14, 3, 1, 0x46, 0x969696}, {
1243 38400, 15, 1, 1, 0x16, 0xEAAAAA}, {
1244 40000, 16, 1, 2, 0xb, 0}, {
1248 /* the following table is based on 880Mhz fvco */
1249 static const pmu1_xtaltab0_t pmu1_xtaltab0_880[] = {
1251 12000, 1, 3, 22, 0x9, 0xFFFFEF}, {
1252 13000, 2, 1, 6, 0xb, 0x483483}, {
1253 14400, 3, 1, 10, 0xa, 0x1C71C7}, {
1254 15360, 4, 1, 5, 0xb, 0x755555}, {
1255 16200, 5, 1, 10, 0x5, 0x6E9E06}, {
1256 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, {
1257 19200, 7, 1, 4, 0xb, 0x755555}, {
1258 19800, 8, 1, 11, 0x4, 0xA57EB}, {
1259 20000, 9, 1, 11, 0x4, 0x0}, {
1260 24000, 10, 3, 11, 0xa, 0x0}, {
1261 25000, 11, 5, 16, 0xb, 0x0}, {
1262 26000, 12, 1, 2, 0x10, 0xEC4EC4}, {
1263 30000, 13, 3, 8, 0xb, 0x0}, {
1264 33600, 14, 1, 2, 0xd, 0x186186}, {
1265 38400, 15, 1, 2, 0xb, 0x755555}, {
1266 40000, 16, 1, 2, 0xb, 0}, {
1270 #define PMU1_XTALTAB0_880_12000K 0
1271 #define PMU1_XTALTAB0_880_13000K 1
1272 #define PMU1_XTALTAB0_880_14400K 2
1273 #define PMU1_XTALTAB0_880_15360K 3
1274 #define PMU1_XTALTAB0_880_16200K 4
1275 #define PMU1_XTALTAB0_880_16800K 5
1276 #define PMU1_XTALTAB0_880_19200K 6
1277 #define PMU1_XTALTAB0_880_19800K 7
1278 #define PMU1_XTALTAB0_880_20000K 8
1279 #define PMU1_XTALTAB0_880_24000K 9
1280 #define PMU1_XTALTAB0_880_25000K 10
1281 #define PMU1_XTALTAB0_880_26000K 11
1282 #define PMU1_XTALTAB0_880_30000K 12
1283 #define PMU1_XTALTAB0_880_37400K 13
1284 #define PMU1_XTALTAB0_880_38400K 14
1285 #define PMU1_XTALTAB0_880_40000K 15
1287 /* the following table is based on 1760Mhz fvco */
1288 static const pmu1_xtaltab0_t pmu1_xtaltab0_1760[] = {
1290 12000, 1, 3, 44, 0x9, 0xFFFFEF}, {
1291 13000, 2, 1, 12, 0xb, 0x483483}, {
1292 14400, 3, 1, 20, 0xa, 0x1C71C7}, {
1293 15360, 4, 1, 10, 0xb, 0x755555}, {
1294 16200, 5, 1, 20, 0x5, 0x6E9E06}, {
1295 16800, 6, 1, 20, 0x5, 0x3Cf3Cf}, {
1296 19200, 7, 1, 18, 0x5, 0x17B425}, {
1297 19800, 8, 1, 22, 0x4, 0xA57EB}, {
1298 20000, 9, 1, 22, 0x4, 0x0}, {
1299 24000, 10, 3, 22, 0xa, 0x0}, {
1300 25000, 11, 5, 32, 0xb, 0x0}, {
1301 26000, 12, 1, 4, 0x10, 0xEC4EC4}, {
1302 30000, 13, 3, 16, 0xb, 0x0}, {
1303 38400, 14, 1, 10, 0x4, 0x955555}, {
1304 40000, 15, 1, 4, 0xb, 0}, {
1309 #define PMU1_XTALTAB0_1760_12000K 0
1310 #define PMU1_XTALTAB0_1760_13000K 1
1311 #define PMU1_XTALTAB0_1760_14400K 2
1312 #define PMU1_XTALTAB0_1760_15360K 3
1313 #define PMU1_XTALTAB0_1760_16200K 4
1314 #define PMU1_XTALTAB0_1760_16800K 5
1315 #define PMU1_XTALTAB0_1760_19200K 6
1316 #define PMU1_XTALTAB0_1760_19800K 7
1317 #define PMU1_XTALTAB0_1760_20000K 8
1318 #define PMU1_XTALTAB0_1760_24000K 9
1319 #define PMU1_XTALTAB0_1760_25000K 10
1320 #define PMU1_XTALTAB0_1760_26000K 11
1321 #define PMU1_XTALTAB0_1760_30000K 12
1322 #define PMU1_XTALTAB0_1760_38400K 13
1323 #define PMU1_XTALTAB0_1760_40000K 14
1325 /* the following table is based on 1440Mhz fvco */
1326 static const pmu1_xtaltab0_t pmu1_xtaltab0_1440[] = {
1328 12000, 1, 1, 1, 0x78, 0x0}, {
1329 13000, 2, 1, 1, 0x6E, 0xC4EC4E}, {
1330 14400, 3, 1, 1, 0x64, 0x0}, {
1331 15360, 4, 1, 1, 0x5D, 0xC00000}, {
1332 16200, 5, 1, 1, 0x58, 0xE38E38}, {
1333 16800, 6, 1, 1, 0x55, 0xB6DB6D}, {
1334 19200, 7, 1, 1, 0x4B, 0}, {
1335 19800, 8, 1, 1, 0x48, 0xBA2E8B}, {
1336 20000, 9, 1, 1, 0x48, 0x0}, {
1337 25000, 10, 1, 1, 0x39, 0x999999}, {
1338 26000, 11, 1, 1, 0x37, 0x627627}, {
1339 30000, 12, 1, 1, 0x30, 0x0}, {
1340 37400, 13, 2, 1, 0x4D, 0x15E76}, {
1341 38400, 13, 2, 1, 0x4B, 0x0}, {
1342 40000, 14, 2, 1, 0x48, 0x0}, {
1343 48000, 15, 2, 1, 0x3c, 0x0}, {
1348 #define PMU1_XTALTAB0_1440_12000K 0
1349 #define PMU1_XTALTAB0_1440_13000K 1
1350 #define PMU1_XTALTAB0_1440_14400K 2
1351 #define PMU1_XTALTAB0_1440_15360K 3
1352 #define PMU1_XTALTAB0_1440_16200K 4
1353 #define PMU1_XTALTAB0_1440_16800K 5
1354 #define PMU1_XTALTAB0_1440_19200K 6
1355 #define PMU1_XTALTAB0_1440_19800K 7
1356 #define PMU1_XTALTAB0_1440_20000K 8
1357 #define PMU1_XTALTAB0_1440_25000K 9
1358 #define PMU1_XTALTAB0_1440_26000K 10
1359 #define PMU1_XTALTAB0_1440_30000K 11
1360 #define PMU1_XTALTAB0_1440_37400K 12
1361 #define PMU1_XTALTAB0_1440_38400K 13
1362 #define PMU1_XTALTAB0_1440_40000K 14
1363 #define PMU1_XTALTAB0_1440_48000K 15
1365 #define XTAL_FREQ_24000MHZ 24000
1366 #define XTAL_FREQ_30000MHZ 30000
1367 #define XTAL_FREQ_37400MHZ 37400
1368 #define XTAL_FREQ_48000MHZ 48000
1370 static const pmu1_xtaltab0_t pmu1_xtaltab0_960[] = {
1372 12000, 1, 1, 1, 0x50, 0x0}, {
1373 13000, 2, 1, 1, 0x49, 0xD89D89}, {
1374 14400, 3, 1, 1, 0x42, 0xAAAAAA}, {
1375 15360, 4, 1, 1, 0x3E, 0x800000}, {
1376 16200, 5, 1, 1, 0x39, 0x425ED0}, {
1377 16800, 6, 1, 1, 0x39, 0x249249}, {
1378 19200, 7, 1, 1, 0x32, 0x0}, {
1379 19800, 8, 1, 1, 0x30, 0x7C1F07}, {
1380 20000, 9, 1, 1, 0x30, 0x0}, {
1381 25000, 10, 1, 1, 0x26, 0x666666}, {
1382 26000, 11, 1, 1, 0x24, 0xEC4EC4}, {
1383 30000, 12, 1, 1, 0x20, 0x0}, {
1384 37400, 13, 2, 1, 0x33, 0x563EF9}, {
1385 38400, 14, 2, 1, 0x32, 0x0}, {
1386 40000, 15, 2, 1, 0x30, 0x0}, {
1387 48000, 16, 2, 1, 0x28, 0x0}, {
1392 #define PMU1_XTALTAB0_960_12000K 0
1393 #define PMU1_XTALTAB0_960_13000K 1
1394 #define PMU1_XTALTAB0_960_14400K 2
1395 #define PMU1_XTALTAB0_960_15360K 3
1396 #define PMU1_XTALTAB0_960_16200K 4
1397 #define PMU1_XTALTAB0_960_16800K 5
1398 #define PMU1_XTALTAB0_960_19200K 6
1399 #define PMU1_XTALTAB0_960_19800K 7
1400 #define PMU1_XTALTAB0_960_20000K 8
1401 #define PMU1_XTALTAB0_960_25000K 9
1402 #define PMU1_XTALTAB0_960_26000K 10
1403 #define PMU1_XTALTAB0_960_30000K 11
1404 #define PMU1_XTALTAB0_960_37400K 12
1405 #define PMU1_XTALTAB0_960_38400K 13
1406 #define PMU1_XTALTAB0_960_40000K 14
1407 #define PMU1_XTALTAB0_960_48000K 15
1409 /* select xtal table for each chip */
1410 static const pmu1_xtaltab0_t *
1411 bhnd_pmu1_xtaltab0(struct bhnd_pmu_query *sc)
1413 switch (sc->cid.chip_id) {
1414 case BHND_CHIPID_BCM4315:
1415 return (pmu1_xtaltab0_1760);
1416 case BHND_CHIPID_BCM4319:
1417 return (pmu1_xtaltab0_1440);
1418 case BHND_CHIPID_BCM4325:
1419 return (pmu1_xtaltab0_880);
1420 case BHND_CHIPID_BCM4329:
1421 return (pmu1_xtaltab0_880_4329);
1422 case BHND_CHIPID_BCM4336:
1423 return (pmu1_xtaltab0_960);
1424 case BHND_CHIPID_BCM4330:
1425 if (PMU_CST4330_SDIOD_CHIPMODE(sc))
1426 return (pmu1_xtaltab0_960);
1428 return (pmu1_xtaltab0_1440);
1430 PMU_DEBUG(sc, "bhnd_pmu1_xtaltab0: Unknown chipid %#hx\n",
1436 /* select default xtal frequency for each chip */
1437 static const pmu1_xtaltab0_t *
1438 bhnd_pmu1_xtaldef0(struct bhnd_pmu_query *sc)
1440 switch (sc->cid.chip_id) {
1441 case BHND_CHIPID_BCM4315:
1442 /* Default to 26000Khz */
1443 return (&pmu1_xtaltab0_1760[PMU1_XTALTAB0_1760_26000K]);
1444 case BHND_CHIPID_BCM4319:
1445 /* Default to 30000Khz */
1446 return (&pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_30000K]);
1447 case BHND_CHIPID_BCM4325:
1448 /* Default to 26000Khz */
1449 return (&pmu1_xtaltab0_880[PMU1_XTALTAB0_880_26000K]);
1450 case BHND_CHIPID_BCM4329:
1451 /* Default to 38400Khz */
1452 return (&pmu1_xtaltab0_880_4329[PMU1_XTALTAB0_880_38400K]);
1453 case BHND_CHIPID_BCM4336:
1454 /* Default to 26000Khz */
1455 return (&pmu1_xtaltab0_960[PMU1_XTALTAB0_960_26000K]);
1456 case BHND_CHIPID_BCM4330:
1457 /* Default to 37400Khz */
1458 if (PMU_CST4330_SDIOD_CHIPMODE(sc))
1459 return (&pmu1_xtaltab0_960[PMU1_XTALTAB0_960_37400K]);
1461 return (&pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_37400K]);
1463 PMU_DEBUG(sc, "bhnd_pmu1_xtaldef0: Unknown chipid %#hx\n",
1469 /* select default pll fvco for each chip */
1471 bhnd_pmu1_pllfvco0(struct bhnd_pmu_query *sc)
1473 switch (sc->cid.chip_id) {
1474 case BHND_CHIPID_BCM4329:
1476 case BHND_CHIPID_BCM4319:
1478 case BHND_CHIPID_BCM4336:
1480 case BHND_CHIPID_BCM4330:
1481 if (PMU_CST4330_SDIOD_CHIPMODE(sc))
1486 PMU_DEBUG(sc, "bhnd_pmu1_pllfvco0: Unknown chipid %#hx\n",
1492 /* query alp/xtal clock frequency */
1494 bhnd_pmu1_alpclk0(struct bhnd_pmu_query *sc)
1496 const pmu1_xtaltab0_t *xt;
1499 /* Find the frequency in the table */
1500 xf = BHND_PMU_READ_4(sc, BHND_PMU_CTRL);
1501 xf = BHND_PMU_GET_BITS(xf, BHND_PMU_CTRL_XTALFREQ);
1503 for (xt = bhnd_pmu1_xtaltab0(sc); xt != NULL && xt->fref != 0; xt++) {
1508 /* Could not find it so assign a default value */
1509 if (xt == NULL || xt->fref == 0)
1510 xt = bhnd_pmu1_xtaldef0(sc);
1512 if (xt == NULL || xt->fref == 0) {
1513 PMU_LOG(sc, "no matching ALP/XTAL frequency found\n");
1517 return (xt->fref * 1000);
1520 /* Set up PLL registers in the PMU as per the crystal speed. */
1522 bhnd_pmu0_pllinit0(struct bhnd_pmu_softc *sc, uint32_t xtal)
1524 const pmu0_xtaltab0_t *xt;
1525 uint32_t pll_data, pll_mask;
1530 /* Use h/w default PLL config */
1532 PMU_DEBUG(sc, "Unspecified xtal frequency, skipping PLL "
1537 /* Find the frequency in the table */
1538 for (xt = pmu0_xtaltab0; xt->freq; xt ++) {
1539 if (xt->freq == xtal)
1544 xt = &pmu0_xtaltab0[PMU0_XTAL0_DEFAULT];
1546 PMU_DEBUG(sc, "XTAL %d.%d MHz (%d)\n", xtal / 1000, xtal % 1000,
1549 /* Check current PLL state */
1550 pmu_ctrl = BHND_PMU_READ_4(sc, BHND_PMU_CTRL);
1551 xf = BHND_PMU_GET_BITS(pmu_ctrl, BHND_PMU_CTRL_XTALFREQ);
1554 if (sc->cid.chip_id == BHND_CHIPID_BCM4328) {
1555 bhnd_pmu0_sbclk4328(sc,
1556 BHND_PMU0_PLL0_PC0_DIV_ARM_88MHZ);
1559 #endif /* BCMUSBDEV */
1561 PMU_DEBUG(sc, "PLL already programmed for %d.%d MHz\n",
1562 xt->freq / 1000, xt->freq % 1000);
1568 "Reprogramming PLL for %d.%d MHz (was %d.%dMHz)\n",
1569 xt->freq / 1000, xt->freq % 1000,
1570 pmu0_xtaltab0[tmp-1].freq / 1000,
1571 pmu0_xtaltab0[tmp-1].freq % 1000);
1573 PMU_DEBUG(sc, "Programming PLL for %d.%d MHz\n",
1574 xt->freq / 1000, xt->freq % 1000);
1577 /* Make sure the PLL is off */
1578 switch (sc->cid.chip_id) {
1579 case BHND_CHIPID_BCM4328:
1580 pll_res = PMURES_BIT(RES4328_BB_PLL_PU);
1582 case BHND_CHIPID_BCM5354:
1583 pll_res = PMURES_BIT(RES5354_BB_PLL_PU);
1586 panic("unsupported chipid %#hx\n", sc->cid.chip_id);
1588 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK, ~pll_res);
1589 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK, ~pll_res);
1591 /* Wait for HT clock to shutdown. */
1592 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
1594 PMU_DEBUG(sc, "Done masking\n");
1596 /* Write PDIV in pllcontrol[0] */
1597 if (xt->freq >= BHND_PMU0_PLL0_PC0_PDIV_FREQ) {
1598 BHND_PMU_PLL_WRITE(sc, BHND_PMU0_PLL0_PLLCTL0,
1599 BHND_PMU0_PLL0_PC0_PDIV_MASK, BHND_PMU0_PLL0_PC0_PDIV_MASK);
1601 BHND_PMU_PLL_WRITE(sc, BHND_PMU0_PLL0_PLLCTL0, 0,
1602 BHND_PMU0_PLL0_PC0_PDIV_MASK);
1605 /* Write WILD in pllcontrol[1] */
1607 BHND_PMU_SET_BITS(xt->wbint, BHND_PMU0_PLL0_PC1_WILD_INT) |
1608 BHND_PMU_SET_BITS(xt->wbfrac, BHND_PMU0_PLL0_PC1_WILD_FRAC);
1610 if (xt->wbfrac == 0) {
1611 pll_data |= BHND_PMU0_PLL0_PC1_STOP_MOD;
1613 pll_data &= ~BHND_PMU0_PLL0_PC1_STOP_MOD;
1617 BHND_PMU0_PLL0_PC1_WILD_INT_MASK |
1618 BHND_PMU0_PLL0_PC1_WILD_FRAC_MASK;
1620 BHND_PMU_PLL_WRITE(sc, BHND_PMU0_PLL0_PLLCTL1, pll_data, pll_mask);
1622 /* Write WILD in pllcontrol[2] */
1623 pll_data = BHND_PMU_SET_BITS(xt->wbint, BHND_PMU0_PLL0_PC2_WILD_INT);
1624 pll_mask = BHND_PMU0_PLL0_PC2_WILD_INT_MASK;
1625 BHND_PMU_PLL_WRITE(sc, BHND_PMU0_PLL0_PLLCTL2, pll_data, pll_mask);
1627 PMU_DEBUG(sc, "Done pll\n");
1629 /* Write XtalFreq. Set the divisor also. */
1630 pmu_ctrl = BHND_PMU_READ_4(sc, BHND_PMU_CTRL);
1631 pmu_ctrl &= ~(BHND_PMU_CTRL_ILP_DIV_MASK|BHND_PMU_CTRL_XTALFREQ_MASK);
1633 pmu_ctrl |= BHND_PMU_SET_BITS(((xt->freq + 127) / 128) - 1,
1634 BHND_PMU_CTRL_ILP_DIV);
1635 pmu_ctrl |= BHND_PMU_SET_BITS(xt->xf, BHND_PMU_CTRL_XTALFREQ);
1637 BHND_PMU_WRITE_4(sc, BHND_PMU_CTRL, pmu_ctrl);
1640 /* query alp/xtal clock frequency */
1642 bhnd_pmu0_alpclk0(struct bhnd_pmu_query *sc)
1644 const pmu0_xtaltab0_t *xt;
1647 /* Find the frequency in the table */
1648 xf = BHND_PMU_READ_4(sc, BHND_PMU_CTRL);
1649 xf = BHND_PMU_GET_BITS(xf, BHND_PMU_CTRL_XTALFREQ);
1650 for (xt = pmu0_xtaltab0; xt->freq; xt++)
1654 /* PLL must be configured before */
1655 if (xt == NULL || xt->freq == 0)
1656 panic("unsupported frequency: %u", xf);
1658 return (xt->freq * 1000);
1661 /* query CPU clock frequency */
1663 bhnd_pmu0_cpuclk0(struct bhnd_pmu_query *sc)
1665 uint32_t tmp, divarm;
1668 uint32_t pdiv, wbint, wbfrac, fvco;
1674 /* Read divarm from pllcontrol[0] */
1675 tmp = BHND_PMU_PLL_READ(sc, BHND_PMU0_PLL0_PLLCTL0);
1676 divarm = BHND_PMU_GET_BITS(tmp, BHND_PMU0_PLL0_PC0_DIV_ARM);
1679 /* Calculate fvco based on xtal freq, pdiv, and wild */
1680 pdiv = tmp & BHND_PMU0_PLL0_PC0_PDIV_MASK;
1682 tmp = BHND_PMU_PLL_READ(sc, BHND_PMU0_PLL0_PLLCTL1);
1683 wbfrac = BHND_PMU_GET_BITS(tmp, BHND_PMU0_PLL0_PC1_WILD_FRAC);
1684 wbint = BHND_PMU_GET_BITS(tmp, PMU0_PLL0_PC1_WILD_INT);
1686 tmp = BHND_PMU_PLL_READ(sc, BHND_PMU0_PLL0_PLLCTL2);
1687 wbint += BHND_PMU_GET_BITS(tmp, BHND_PMU0_PLL0_PC2_WILD_INT);
1689 freq = bhnd_pmu0_alpclk0(sih, osh, cc) / 1000;
1691 fvco = (freq * wbint) << 8;
1692 fvco += (freq * (wbfrac >> 10)) >> 2;
1693 fvco += (freq * (wbfrac & 0x3ff)) >> 10;
1699 PMU_DEBUG(sc, "bhnd_pmu0_cpuclk0: wbint %u wbfrac %u fvco %u\n",
1700 wbint, wbfrac, fvco);
1705 /* Return ARM/SB clock */
1706 return FVCO / (divarm + BHND_PMU0_PLL0_PC0_DIV_ARM_BASE) * 1000;
1711 /* Set up PLL registers in the PMU as per the crystal speed. */
1713 bhnd_pmu1_pllinit0(struct bhnd_pmu_softc *sc, uint32_t xtal)
1715 const pmu1_xtaltab0_t *xt;
1716 uint32_t buf_strength;
1717 uint32_t plladdr, plldata, pllmask;
1722 FVCO = bhnd_pmu1_pllfvco0(&sc->query) / 1000;
1726 /* Use h/w default PLL config */
1728 PMU_DEBUG(sc, "Unspecified xtal frequency, skipping PLL "
1733 /* Find the frequency in the table */
1734 for (xt = bhnd_pmu1_xtaltab0(&sc->query); xt != NULL && xt->fref != 0;
1737 if (xt->fref == xtal)
1741 /* Check current PLL state, bail out if it has been programmed or
1742 * we don't know how to program it.
1744 if (xt == NULL || xt->fref == 0) {
1745 PMU_LOG(sc, "Unsupported XTAL frequency %d.%dMHz, skipping PLL "
1746 "configuration\n", xtal / 1000, xtal % 1000);
1750 /* For 4319 bootloader already programs the PLL but bootloader does not
1751 * program the PLL4 and PLL5. So Skip this check for 4319. */
1752 pmuctrl = BHND_PMU_READ_4(sc, BHND_PMU_CTRL);
1753 if (BHND_PMU_GET_BITS(pmuctrl, BHND_PMU_CTRL_XTALFREQ) == xt->xf &&
1754 sc->cid.chip_id != BHND_CHIPID_BCM4319 &&
1755 sc->cid.chip_id != BHND_CHIPID_BCM4330)
1757 PMU_DEBUG(sc, "PLL already programmed for %d.%dMHz\n",
1758 xt->fref / 1000, xt->fref % 1000);
1762 PMU_DEBUG(sc, "XTAL %d.%dMHz (%d)\n", xtal / 1000, xtal % 1000, xt->xf);
1763 PMU_DEBUG(sc, "Programming PLL for %d.%dMHz\n", xt->fref / 1000,
1766 switch (sc->cid.chip_id) {
1767 case BHND_CHIPID_BCM4325:
1768 /* Change the BBPLL drive strength to 2 for all channels */
1769 buf_strength = 0x222222;
1771 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK,
1772 ~(PMURES_BIT(RES4325_BBPLL_PWRSW_PU) |
1773 PMURES_BIT(RES4325_HT_AVAIL)));
1774 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK,
1775 ~(PMURES_BIT(RES4325_BBPLL_PWRSW_PU) |
1776 PMURES_BIT(RES4325_HT_AVAIL)));
1778 /* Wait for HT clock to shutdown. */
1779 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
1782 case BHND_CHIPID_BCM4329:
1783 /* Change the BBPLL drive strength to 8 for all channels */
1784 buf_strength = 0x888888;
1786 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK,
1787 ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) |
1788 PMURES_BIT(RES4329_HT_AVAIL)));
1789 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK,
1790 ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) |
1791 PMURES_BIT(RES4329_HT_AVAIL)));
1793 /* Wait for HT clock to shutdown. */
1794 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
1796 /* Initialize PLL4 */
1797 plladdr = BHND_PMU1_PLL0_PLLCTL4;
1798 if (xt->fref == 38400)
1799 plldata = 0x200024C0;
1800 else if (xt->fref == 37400)
1801 plldata = 0x20004500;
1802 else if (xt->fref == 26000)
1803 plldata = 0x200024C0;
1805 plldata = 0x200005C0; /* Chip Dflt Settings */
1807 BHND_PMU_PLL_WRITE(sc, plladdr, plldata, ~0);
1809 /* Initialize PLL5 */
1810 plladdr = BHND_PMU1_PLL0_PLLCTL5;
1812 plldata = BHND_PMU_PLL_READ(sc, plladdr);
1813 plldata &= BHND_PMU1_PLL0_PC5_CLK_DRV_MASK;
1815 if (xt->fref == 38400 ||
1816 xt->fref == 37400 ||
1817 xt->fref == 26000) {
1820 plldata |= 0x25; /* Chip Dflt Settings */
1823 BHND_PMU_PLL_WRITE(sc, plladdr, plldata, ~0);
1826 case BHND_CHIPID_BCM4319:
1827 /* Change the BBPLL drive strength to 2 for all channels */
1828 buf_strength = 0x222222;
1830 /* Make sure the PLL is off */
1831 /* WAR65104: Disable the HT_AVAIL resource first and then
1832 * after a delay (more than downtime for HT_AVAIL) remove the
1833 * BBPLL resource; backplane clock moves to ALP from HT.
1835 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK,
1836 ~(PMURES_BIT(RES4319_HT_AVAIL)));
1837 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK,
1838 ~(PMURES_BIT(RES4319_HT_AVAIL)));
1841 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK,
1842 ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU)));
1843 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK,
1844 ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU)));
1848 /* Wait for HT clock to shutdown. */
1849 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
1851 plldata = 0x200005c0;
1852 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4, plldata, ~0);
1855 case BHND_CHIPID_BCM4336:
1856 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK,
1857 ~(PMURES_BIT(RES4336_HT_AVAIL) |
1858 PMURES_BIT(RES4336_MACPHY_CLKAVAIL)));
1859 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK,
1860 ~(PMURES_BIT(RES4336_HT_AVAIL) |
1861 PMURES_BIT(RES4336_MACPHY_CLKAVAIL)));
1864 /* Wait for HT clock to shutdown. */
1865 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
1869 case BHND_CHIPID_BCM4330:
1870 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK,
1871 ~(PMURES_BIT(RES4330_HT_AVAIL) |
1872 PMURES_BIT(RES4330_MACPHY_CLKAVAIL)));
1873 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK,
1874 ~(PMURES_BIT(RES4330_HT_AVAIL) |
1875 PMURES_BIT(RES4330_MACPHY_CLKAVAIL)));
1878 /* Wait for HT clock to shutdown. */
1879 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
1884 panic("unsupported chipid %#hx\n", sc->cid.chip_id);
1887 PMU_DEBUG(sc, "Done masking\n");
1889 /* Write p1div and p2div to pllcontrol[0] */
1891 BHND_PMU_SET_BITS(xt->p1div, BHND_PMU1_PLL0_PC0_P1DIV) |
1892 BHND_PMU_SET_BITS(xt->p2div, BHND_PMU1_PLL0_PC0_P2DIV);
1893 pllmask = BHND_PMU1_PLL0_PC0_P1DIV_MASK|BHND_PMU1_PLL0_PC0_P2DIV_MASK;
1895 if (sc->cid.chip_id == BHND_CHIPID_BCM4319) {
1896 plldata &= ~(BHND_PMU1_PLL0_PC0_BYPASS_SDMOD_MASK);
1897 pllmask |= BHND_PMU1_PLL0_PC0_BYPASS_SDMOD_MASK;
1898 if (!xt->ndiv_frac) {
1899 plldata |= BHND_PMU_SET_BITS(1,
1900 BHND_PMU1_PLL0_PC0_BYPASS_SDMOD);
1904 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0, plldata, pllmask);
1907 if (sc->cid.chip_id == BHND_CHIPID_BCM4330)
1908 bhnd_pmu_set_4330_plldivs(sc);
1910 if (sc->cid.chip_id == BHND_CHIPID_BCM4329 && sc->cid.chip_rev == 0) {
1911 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
1912 BHND_PMU_DOT11MAC_880MHZ_CLK_DIVISOR_VAL,
1913 BHND_PMU_DOT11MAC_880MHZ_CLK_DIVISOR_MASK);
1916 /* Write ndiv_int and ndiv_mode to pllcontrol[2] */
1917 if (sc->cid.chip_id == BHND_CHIPID_BCM4336 ||
1918 sc->cid.chip_id == BHND_CHIPID_BCM4330)
1920 ndiv_mode = BHND_PMU1_PLL0_PC2_NDIV_MODE_MFB;
1921 } else if (sc->cid.chip_id == BHND_CHIPID_BCM4319) {
1922 if (!(xt->ndiv_frac))
1923 ndiv_mode = BHND_PMU1_PLL0_PC2_NDIV_MODE_INT;
1925 ndiv_mode = BHND_PMU1_PLL0_PC2_NDIV_MODE_MFB;
1927 ndiv_mode = BHND_PMU1_PLL0_PC2_NDIV_MODE_MASH;
1931 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
1932 BHND_PMU_SET_BITS(xt->ndiv_int, BHND_PMU1_PLL0_PC2_NDIV_INT) |
1933 BHND_PMU_SET_BITS(ndiv_mode, BHND_PMU1_PLL0_PC2_NDIV_MODE),
1934 BHND_PMU1_PLL0_PC2_NDIV_INT_MASK |
1935 BHND_PMU1_PLL0_PC2_NDIV_MODE_MASK);
1937 /* Write ndiv_frac to pllcontrol[3] */
1938 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
1939 BHND_PMU_SET_BITS(xt->ndiv_frac, BHND_PMU1_PLL0_PC3_NDIV_FRAC),
1940 BHND_PMU1_PLL0_PC3_NDIV_FRAC_MASK);
1942 /* Writing to pllcontrol[4] */
1943 if (sc->cid.chip_id == BHND_CHIPID_BCM4319) {
1947 plldata = 0x200005c0;
1949 plldata = 0x202C2820;
1956 plldata &= ~(BHND_PMU1_PLL0_PC4_KVCO_XS_MASK);
1957 plldata |= BHND_PMU_SET_BITS(xs, BHND_PMU1_PLL0_PC4_KVCO_XS);
1958 BHND_PMU_WRITE_4(sc, BHND_PMU1_PLL0_PLLCTL4, plldata);
1961 /* Write clock driving strength to pllcontrol[5] */
1963 PMU_DEBUG(sc, "Adjusting PLL buffer drive strength: %x\n",
1966 plldata = BHND_PMU_SET_BITS(buf_strength,
1967 BHND_PMU1_PLL0_PC5_CLK_DRV);
1968 pllmask = BHND_PMU1_PLL0_PC5_CLK_DRV_MASK;
1970 if (sc->cid.chip_id == BHND_CHIPID_BCM4319) {
1972 BHND_PMU1_PLL0_PC5_VCO_RNG_MASK |
1973 BHND_PMU1_PLL0_PC5_PLL_CTRL_37_32_MASK;
1975 if (!xt->ndiv_frac) {
1976 plldata |= BHND_PMU_SET_BITS(0x25,
1977 BHND_PMU1_PLL0_PC5_PLL_CTRL_37_32);
1979 plldata |= BHND_PMU_SET_BITS(0x15,
1980 BHND_PMU1_PLL0_PC5_PLL_CTRL_37_32);
1984 plldata |= BHND_PMU_SET_BITS(0x1,
1985 BHND_PMU1_PLL0_PC5_VCO_RNG);
1989 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5, plldata,
1993 PMU_DEBUG(sc, "Done pll\n");
1995 /* to operate the 4319 usb in 24MHz/48MHz; chipcontrol[2][84:83] needs
1998 if (sc->cid.chip_id == BHND_CHIPID_BCM4319 &&
1999 xt->fref != XTAL_FREQ_30000MHZ)
2004 case XTAL_FREQ_24000MHZ:
2005 pll_sel = BHND_PMU_CCTL_4319USB_24MHZ_PLL_SEL;
2007 case XTAL_FREQ_48000MHZ:
2008 pll_sel = BHND_PMU_CCTL_4319USB_48MHZ_PLL_SEL;
2011 panic("unsupported 4319USB XTAL frequency: %hu\n",
2015 BHND_PMU_CCTRL_WRITE(sc, BHND_PMU1_PLL0_CHIPCTL2,
2016 BHND_PMU_SET_BITS(pll_sel, BHND_PMU_CCTL_4319USB_XTAL_SEL),
2017 BHND_PMU_CCTL_4319USB_XTAL_SEL_MASK);
2020 /* Flush deferred pll control registers writes */
2021 if (BHND_PMU_REV(sc) >= 2)
2022 BHND_PMU_OR_4(sc, BHND_PMU_CTRL, BHND_PMU_CTRL_PLL_PLLCTL_UPD);
2024 /* Write XtalFreq. Set the divisor also. */
2025 pmuctrl = BHND_PMU_READ_4(sc, BHND_PMU_CTRL);
2026 pmuctrl = ~(BHND_PMU_CTRL_ILP_DIV_MASK | BHND_PMU_CTRL_XTALFREQ_MASK);
2027 pmuctrl |= BHND_PMU_SET_BITS(((xt->fref + 127) / 128) - 1,
2028 BHND_PMU_CTRL_ILP_DIV);
2029 pmuctrl |= BHND_PMU_SET_BITS(xt->xf, BHND_PMU_CTRL_XTALFREQ);
2031 if (sc->cid.chip_id == BHND_CHIPID_BCM4329 && sc->cid.chip_rev == 0) {
2032 /* clear the htstretch before clearing HTReqEn */
2033 BHND_PMU_AND_4(sc, BHND_PMU_CLKSTRETCH, ~BHND_PMU_CLKSTRETCH);
2034 pmuctrl &= ~BHND_PMU_CTRL_HT_REQ_EN;
2037 BHND_PMU_WRITE_4(sc, BHND_PMU_CTRL, pmuctrl);
2040 /* query the CPU clock frequency */
2042 bhnd_pmu1_cpuclk0(struct bhnd_pmu_query *sc)
2044 uint32_t tmp, m1div;
2046 uint32_t ndiv_int, ndiv_frac, p2div, p1div, fvco;
2049 uint32_t FVCO = bhnd_pmu1_pllfvco0(sc);
2051 /* Read m1div from pllcontrol[1] */
2052 tmp = BHND_PMU_PLL_READ(sc, BHND_PMU1_PLL0_PLLCTL1);
2053 m1div = BHND_PMU_GET_BITS(tmp, BHND_PMU1_PLL0_PC1_M1DIV);
2056 /* Read p2div/p1div from pllcontrol[0] */
2057 tmp = BHND_PMU_PLL_READ(sc, BHND_PMU1_PLL0_PLLCTL0);
2058 p2div = BHND_PMU_GET_BITS(tmp, BHND_PMU1_PLL0_PC0_P2DIV);
2059 p1div = BHND_PMU_GET_BITS(tmp, BHND_PMU1_PLL0_PC0_P1DIV);
2061 /* Calculate fvco based on xtal freq and ndiv and pdiv */
2062 tmp = BHND_PMU_PLL_READ(sc, BHND_PMU1_PLL0_PLLCTL2);
2063 ndiv_int = BHND_PMU_GET_BITS(tmp, BHND_PMU1_PLL0_PC2_NDIV_INT);
2065 tmp = BHND_PMU_PLL_READ(sc, BHND_PMU1_PLL0_PLLCTL3);
2066 ndiv_frac = BHND_PMU_GET_BITS(tmp, BHND_PMU1_PLL0_PC3_NDIV_FRAC);
2068 fref = bhnd_pmu1_alpclk0(sc) / 1000;
2070 fvco = (fref * ndiv_int) << 8;
2071 fvco += (fref * (ndiv_frac >> 12)) >> 4;
2072 fvco += (fref * (ndiv_frac & 0xfff)) >> 12;
2079 PMU_DEBUG(sc, "bhnd_pmu1_cpuclk0: ndiv_int %u ndiv_frac %u p2div %u "
2080 "p1div %u fvco %u\n", ndiv_int, ndiv_frac, p2div, p1div, fvco);
2085 /* Return ARM/SB clock */
2086 return (FVCO / m1div * 1000);
2089 /* initialize PLL */
2091 bhnd_pmu_pll_init(struct bhnd_pmu_softc *sc, u_int xtalfreq)
2093 uint32_t max_mask, min_mask;
2094 uint32_t res_ht, res_pll;
2096 switch (sc->cid.chip_id) {
2097 case BHND_CHIPID_BCM4312:
2098 /* assume default works */
2100 case BHND_CHIPID_BCM4322:
2101 case BHND_CHIPID_BCM43221:
2102 case BHND_CHIPID_BCM43231:
2103 case BHND_CHIPID_BCM4342:
2104 if (sc->cid.chip_rev != 0)
2107 min_mask = BHND_PMU_READ_4(sc, BHND_PMU_MIN_RES_MASK);
2108 max_mask = BHND_PMU_READ_4(sc, BHND_PMU_MIN_RES_MASK);
2109 res_ht = PMURES_BIT(RES4322_HT_SI_AVAIL);
2110 res_pll = PMURES_BIT(RES4322_SI_PLL_ON);
2112 /* Have to remove HT Avail request before powering off PLL */
2113 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK, ~res_ht);
2114 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK, ~res_ht);
2115 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
2117 /* Make sure the PLL is off */
2118 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK, ~res_pll);
2119 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK, ~res_pll);
2120 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
2124 BHND_PMU_PLL_WRITE(sc, BHND_PMU2_SI_PLL_PLLCTL, 0x380005c0, ~0);
2127 BHND_PMU_WRITE_4(sc, BHND_PMU_MAX_RES_MASK, max_mask);
2129 BHND_PMU_WRITE_4(sc, BHND_PMU_MIN_RES_MASK, min_mask);
2133 case BHND_CHIPID_BCM4325:
2134 bhnd_pmu1_pllinit0(sc, xtalfreq);
2136 case BHND_CHIPID_BCM4328:
2137 bhnd_pmu0_pllinit0(sc, xtalfreq);
2139 case BHND_CHIPID_BCM5354:
2142 bhnd_pmu0_pllinit0(sc, xtalfreq);
2144 case BHND_CHIPID_BCM4329:
2147 bhnd_pmu1_pllinit0(sc, xtalfreq);
2150 case BHND_CHIPID_BCM4313:
2151 case BHND_CHIPID_BCM43222:
2152 case BHND_CHIPID_BCM43111:
2153 case BHND_CHIPID_BCM43112:
2154 case BHND_CHIPID_BCM43224:
2155 case BHND_CHIPID_BCM43225:
2156 case BHND_CHIPID_BCM43420:
2157 case BHND_CHIPID_BCM43421:
2158 case BHND_CHIPID_BCM43226:
2159 case BHND_CHIPID_BCM43235:
2160 case BHND_CHIPID_BCM43236:
2161 case BHND_CHIPID_BCM43238:
2162 case BHND_CHIPID_BCM43234:
2163 case BHND_CHIPID_BCM43237:
2164 case BHND_CHIPID_BCM4331:
2165 case BHND_CHIPID_BCM43431:
2166 case BHND_CHIPID_BCM43131:
2167 case BHND_CHIPID_BCM43227:
2168 case BHND_CHIPID_BCM43228:
2169 case BHND_CHIPID_BCM43428:
2170 case BHND_CHIPID_BCM6362:
2171 /* assume default works */
2174 case BHND_CHIPID_BCM4315:
2175 case BHND_CHIPID_BCM4319:
2176 case BHND_CHIPID_BCM4336:
2177 case BHND_CHIPID_BCM4330:
2178 bhnd_pmu1_pllinit0(sc, xtalfreq);
2181 PMU_DEBUG("No PLL init done for chip %#hx rev %d pmurev %d\n",
2182 sc->cid.chip_id, sc->cid.chip_rev, BHND_PMU_REV(sc));
2188 * Return the ALP/XTAL clock frequency, in Hz.
2190 * @param sc PMU query instance.
2193 bhnd_pmu_alp_clock(struct bhnd_pmu_query *sc)
2197 clock = BHND_PMU_ALP_CLOCK;
2198 switch (sc->cid.chip_id) {
2199 case BHND_CHIPID_BCM4328:
2200 case BHND_CHIPID_BCM5354:
2201 clock = bhnd_pmu0_alpclk0(sc);
2203 case BHND_CHIPID_BCM4315:
2204 case BHND_CHIPID_BCM4319:
2205 case BHND_CHIPID_BCM4325:
2206 case BHND_CHIPID_BCM4329:
2207 case BHND_CHIPID_BCM4330:
2208 case BHND_CHIPID_BCM4336:
2209 clock = bhnd_pmu1_alpclk0(sc);
2211 case BHND_CHIPID_BCM4312:
2212 case BHND_CHIPID_BCM4322:
2213 case BHND_CHIPID_BCM43221:
2214 case BHND_CHIPID_BCM43231:
2215 case BHND_CHIPID_BCM43222:
2216 case BHND_CHIPID_BCM43111:
2217 case BHND_CHIPID_BCM43112:
2218 case BHND_CHIPID_BCM43224:
2219 case BHND_CHIPID_BCM43225:
2220 case BHND_CHIPID_BCM43420:
2221 case BHND_CHIPID_BCM43421:
2222 case BHND_CHIPID_BCM43226:
2223 case BHND_CHIPID_BCM43235:
2224 case BHND_CHIPID_BCM43236:
2225 case BHND_CHIPID_BCM43238:
2226 case BHND_CHIPID_BCM43234:
2227 case BHND_CHIPID_BCM43237:
2228 case BHND_CHIPID_BCM4331:
2229 case BHND_CHIPID_BCM43431:
2230 case BHND_CHIPID_BCM43131:
2231 case BHND_CHIPID_BCM43227:
2232 case BHND_CHIPID_BCM43228:
2233 case BHND_CHIPID_BCM43428:
2234 case BHND_CHIPID_BCM6362:
2235 case BHND_CHIPID_BCM4342:
2236 case BHND_CHIPID_BCM4716:
2237 case BHND_CHIPID_BCM4748:
2238 case BHND_CHIPID_BCM47162:
2239 case BHND_CHIPID_BCM4313:
2240 case BHND_CHIPID_BCM5357:
2241 case BHND_CHIPID_BCM4749:
2242 case BHND_CHIPID_BCM53572:
2244 clock = 20000 * 1000;
2246 case BHND_CHIPID_BCM5356:
2247 case BHND_CHIPID_BCM4706:
2249 clock = 25000 * 1000;
2252 PMU_DEBUG("No ALP clock specified "
2253 "for chip %s rev %d pmurev %d, using default %d Hz\n",
2254 bcm_chipname(sih->chip, chn, 8), sih->chiprev,
2255 sih->pmurev, clock);
2262 /* Find the output of the "m" pll divider given pll controls that start with
2263 * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
2266 bhnd_pmu5_clock(struct bhnd_pmu_query *sc, u_int pll0, u_int m)
2274 if ((pll0 & 3) || (pll0 > BHND_PMU4716_MAINPLL_PLL0)) {
2275 PMU_LOG(sc, "%s: Bad pll0: %d", __func__, pll0);
2279 /* Strictly there is an m5 divider, but I'm not sure we use it */
2280 if ((m == 0) || (m > 4)) {
2281 PMU_LOG(sc, "%s: Bad m divider: %d", __func__, m);
2285 if (sc->cid.chip_id == BHND_CHIPID_BCM5357 ||
2286 sc->cid.chip_id == BHND_CHIPID_BCM4749)
2288 /* Detect failure in clock setting */
2289 tmp = sc->io->rd_chipst(sc->io_ctx);
2290 if ((tmp & 0x40000) != 0)
2291 return (133 * 1000000);
2295 /* Fetch p1 and p2 */
2296 BHND_PMU_WRITE_4(sc, BHND_PMU_PLL_CONTROL_ADDR,
2297 pll0 + BHND_PMU5_PLL_P1P2_OFF);
2298 BHND_PMU_READ_4(sc, BHND_PMU_PLL_CONTROL_ADDR);
2300 tmp = BHND_PMU_READ_4(sc, BHND_PMU_PLL_CONTROL_DATA);
2301 p1 = BHND_PMU_GET_BITS(tmp, BHND_PMU5_PLL_P1);
2302 p2 = BHND_PMU_GET_BITS(tmp, BHND_PMU5_PLL_P2);
2305 BHND_PMU_WRITE_4(sc, BHND_PMU_PLL_CONTROL_ADDR,
2306 pll0 + BHND_PMU5_PLL_M14_OFF);
2307 BHND_PMU_READ_4(sc, BHND_PMU_PLL_CONTROL_ADDR);
2309 tmp = BHND_PMU_READ_4(sc, BHND_PMU_PLL_CONTROL_DATA);
2310 div = (tmp >> ((m - 1) * BHND_PMU5_PLL_MDIV_WIDTH));
2311 div &= BHND_PMU5_PLL_MDIV_MASK;
2314 BHND_PMU_WRITE_4(sc, BHND_PMU_PLL_CONTROL_ADDR,
2315 pll0 + BHND_PMU5_PLL_NM5_OFF);
2316 BHND_PMU_READ_4(sc, BHND_PMU_PLL_CONTROL_ADDR);
2318 tmp = BHND_PMU_READ_4(sc, BHND_PMU_PLL_CONTROL_DATA);
2319 ndiv = BHND_PMU_GET_BITS(tmp, BHND_PMU5_PLL_NDIV);
2321 /* Do calculation in Mhz */
2322 fc = bhnd_pmu_alp_clock(sc) / 1000000;
2323 fc = (p1 * ndiv * fc) / p2;
2325 PMU_DEBUG(sc, "%s: p1=%d, p2=%d, ndiv=%d(0x%x), m%d=%d; fc=%d, "
2326 "clock=%d\n", __func__, p1, p2, ndiv, ndiv, m, div, fc, fc / div);
2328 /* Return clock in Hertz */
2329 return ((fc / div) * 1000000);
2333 * Return the backplane clock frequency, in Hz.
2335 * On designs that feed the same clock to both backplane
2336 * and CPU, this returns the CPU clock speed.
2338 * @param sc PMU query instance.
2341 bhnd_pmu_si_clock(struct bhnd_pmu_query *sc)
2346 clock = BHND_PMU_HT_CLOCK;
2348 switch (sc->cid.chip_id) {
2349 case BHND_CHIPID_BCM4322:
2350 case BHND_CHIPID_BCM43221:
2351 case BHND_CHIPID_BCM43231:
2352 case BHND_CHIPID_BCM43222:
2353 case BHND_CHIPID_BCM43111:
2354 case BHND_CHIPID_BCM43112:
2355 case BHND_CHIPID_BCM43224:
2356 case BHND_CHIPID_BCM43420:
2357 case BHND_CHIPID_BCM43225:
2358 case BHND_CHIPID_BCM43421:
2359 case BHND_CHIPID_BCM43226:
2360 case BHND_CHIPID_BCM4331:
2361 case BHND_CHIPID_BCM43431:
2362 case BHND_CHIPID_BCM6362:
2363 case BHND_CHIPID_BCM4342:
2364 /* 96MHz backplane clock */
2365 clock = 96000 * 1000;
2368 case BHND_CHIPID_BCM4716:
2369 case BHND_CHIPID_BCM4748:
2370 case BHND_CHIPID_BCM47162:
2371 clock = bhnd_pmu5_clock(sc, BHND_PMU4716_MAINPLL_PLL0,
2372 BHND_PMU5_MAINPLL_SI);
2375 case BHND_CHIPID_BCM4325:
2376 clock = bhnd_pmu1_cpuclk0(sc);
2379 case BHND_CHIPID_BCM4328:
2380 clock = bhnd_pmu0_cpuclk0(sc);
2383 case BHND_CHIPID_BCM4329:
2384 if (sc->cid.chip_rev == 0)
2385 clock = 38400 * 1000;
2387 clock = bhnd_pmu1_cpuclk0(sc);
2390 case BHND_CHIPID_BCM4315:
2391 case BHND_CHIPID_BCM4319:
2392 case BHND_CHIPID_BCM4336:
2393 case BHND_CHIPID_BCM4330:
2394 clock = bhnd_pmu1_cpuclk0(sc);
2397 case BHND_CHIPID_BCM4313:
2398 /* 80MHz backplane clock */
2399 clock = 80000 * 1000;
2402 case BHND_CHIPID_BCM43234:
2403 case BHND_CHIPID_BCM43235:
2404 case BHND_CHIPID_BCM43236:
2405 case BHND_CHIPID_BCM43238:
2406 chipst = sc->io->rd_chipst(sc->io_ctx);
2407 if (chipst & CHIPC_CST43236_BP_CLK)
2408 clock = 120000 * 1000;
2410 clock = 96000 * 1000;
2412 case BHND_CHIPID_BCM43237:
2413 chipst = sc->io->rd_chipst(sc->io_ctx);
2414 if (chipst & CHIPC_CST43237_BP_CLK)
2415 clock = 96000 * 1000;
2417 clock = 80000 * 1000;
2419 case BHND_CHIPID_BCM5356:
2420 clock = bhnd_pmu5_clock(sc, BHND_PMU5356_MAINPLL_PLL0,
2421 BHND_PMU5_MAINPLL_SI);
2423 case BHND_CHIPID_BCM5357:
2424 case BHND_CHIPID_BCM4749:
2425 clock = bhnd_pmu5_clock(sc, BHND_PMU5357_MAINPLL_PLL0,
2426 BHND_PMU5_MAINPLL_SI);
2428 case BHND_CHIPID_BCM53572:
2432 PMU_LOG(sc, "No backplane clock specified for chip %#hx rev "
2433 "%hhd pmurev %hhd, using default %dHz\n",
2434 sc->cid.chip_id, sc->cid.chip_rev, BHND_PMU_REV(sc), clock);
2442 * Return the CPU clock frequency, in Hz.
2444 * @param sc PMU query instance.
2447 bhnd_pmu_cpu_clock(struct bhnd_pmu_query *sc)
2451 /* 5354 chip uses a non programmable PLL of frequency 240MHz */
2452 if (sc->cid.chip_id == BHND_CHIPID_BCM5354)
2453 return (240 * 1000 * 1000); /* 240MHz */
2455 if (sc->cid.chip_id == BHND_CHIPID_BCM53572)
2458 if (BHND_PMU_REV(sc) >= 5 &&
2459 sc->cid.chip_id != BHND_CHIPID_BCM4329 &&
2460 sc->cid.chip_id != BHND_CHIPID_BCM4319 &&
2461 sc->cid.chip_id != BHND_CHIPID_BCM43234 &&
2462 sc->cid.chip_id != BHND_CHIPID_BCM43235 &&
2463 sc->cid.chip_id != BHND_CHIPID_BCM43236 &&
2464 sc->cid.chip_id != BHND_CHIPID_BCM43237 &&
2465 sc->cid.chip_id != BHND_CHIPID_BCM43238 &&
2466 sc->cid.chip_id != BHND_CHIPID_BCM4336 &&
2467 sc->cid.chip_id != BHND_CHIPID_BCM4330)
2471 switch (sc->cid.chip_id) {
2472 case BHND_CHIPID_BCM5356:
2473 pll = BHND_PMU5356_MAINPLL_PLL0;
2475 case BHND_CHIPID_BCM5357:
2476 case BHND_CHIPID_BCM4749:
2477 pll = BHND_PMU5357_MAINPLL_PLL0;
2480 pll = BHND_PMU4716_MAINPLL_PLL0;
2484 clock = bhnd_pmu5_clock(sc, pll, BHND_PMU5_MAINPLL_CPU);
2486 clock = bhnd_pmu_si_clock(sc);
2493 * Return the memory clock frequency, in Hz.
2495 * @param sc PMU query instance.
2498 bhnd_pmu_mem_clock(struct bhnd_pmu_query *sc)
2502 if (BHND_PMU_REV(sc) >= 5 &&
2503 sc->cid.chip_id != BHND_CHIPID_BCM4329 &&
2504 sc->cid.chip_id != BHND_CHIPID_BCM4319 &&
2505 sc->cid.chip_id != BHND_CHIPID_BCM43234 &&
2506 sc->cid.chip_id != BHND_CHIPID_BCM43235 &&
2507 sc->cid.chip_id != BHND_CHIPID_BCM43236 &&
2508 sc->cid.chip_id != BHND_CHIPID_BCM43237 &&
2509 sc->cid.chip_id != BHND_CHIPID_BCM43238 &&
2510 sc->cid.chip_id != BHND_CHIPID_BCM4336 &&
2511 sc->cid.chip_id != BHND_CHIPID_BCM4330)
2515 switch (sc->cid.chip_id) {
2516 case BHND_CHIPID_BCM5356:
2517 pll = BHND_PMU5356_MAINPLL_PLL0;
2519 case BHND_CHIPID_BCM5357:
2520 case BHND_CHIPID_BCM4749:
2521 pll = BHND_PMU5357_MAINPLL_PLL0;
2524 pll = BHND_PMU4716_MAINPLL_PLL0;
2528 clock = bhnd_pmu5_clock(sc, pll, BHND_PMU5_MAINPLL_MEM);
2530 clock = bhnd_pmu_si_clock(sc);
2536 /* Measure ILP clock frequency */
2537 #define ILP_CALC_DUR 10 /* ms, make sure 1000 can be divided by it. */
2540 * Measure and return the ILP clock frequency, in Hz.
2542 * @param sc PMU query instance.
2545 bhnd_pmu_ilp_clock(struct bhnd_pmu_query *sc)
2547 uint32_t start, end, delta;
2549 if (sc->ilp_cps == 0) {
2550 start = BHND_PMU_READ_4(sc, BHND_PMU_TIMER);
2551 DELAY(ILP_CALC_DUR);
2552 end = BHND_PMU_READ_4(sc, BHND_PMU_TIMER);
2553 delta = end - start;
2554 sc->ilp_cps = delta * (1000 / ILP_CALC_DUR);
2557 return (sc->ilp_cps);
2560 /* SDIO Pad drive strength to select value mappings */
2562 uint8_t strength; /* Pad Drive Strength in mA */
2563 uint8_t sel; /* Chip-specific select value */
2564 } sdiod_drive_str_t;
2566 /* SDIO Drive Strength to sel value table for PMU Rev 1 */
2567 static const sdiod_drive_str_t sdiod_drive_strength_tab1[] = {
2575 /* SDIO Drive Strength to sel value table for PMU Rev 2, 3 */
2576 static const sdiod_drive_str_t sdiod_drive_strength_tab2[] = {
2587 /* SDIO Drive Strength to sel value table for PMU Rev 8 (1.8V) */
2588 static const sdiod_drive_str_t sdiod_drive_strength_tab3[] = {
2600 #define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu))
2603 bhnd_pmu_sdiod_drive_strength_init(struct bhnd_pmu_softc *sc,
2604 uint32_t drivestrength)
2606 const sdiod_drive_str_t *str_tab;
2616 switch (SDIOD_DRVSTR_KEY(sc->cid.chip_id, BHND_PMU_REV(sc))) {
2617 case SDIOD_DRVSTR_KEY(BHND_CHIPID_BCM4325, 1):
2618 str_tab = sdiod_drive_strength_tab1;
2619 str_mask = 0x30000000;
2622 case SDIOD_DRVSTR_KEY(BHND_CHIPID_BCM4325, 2):
2623 case SDIOD_DRVSTR_KEY(BHND_CHIPID_BCM4325, 3):
2624 case SDIOD_DRVSTR_KEY(BHND_CHIPID_BCM4315, 4):
2625 case SDIOD_DRVSTR_KEY(BHND_CHIPID_BCM4319, 7):
2626 str_tab = sdiod_drive_strength_tab2;
2627 str_mask = 0x00003800;
2630 case SDIOD_DRVSTR_KEY(BHND_CHIPID_BCM4336, 8):
2631 str_tab = sdiod_drive_strength_tab3;
2632 str_mask = 0x00003800;
2637 PMU_LOG(sc, "No SDIO Drive strength init done for chip %#x "
2638 "rev %hhd pmurev %hhd\n", sc->cid.chip_id, sc->cid.chip_rev,
2643 if (str_tab != NULL) {
2644 uint32_t drivestrength_sel = 0;
2645 uint32_t cc_data_temp;
2647 for (u_int i = 0; str_tab[i].strength != 0; i++) {
2648 if (drivestrength >= str_tab[i].strength) {
2649 drivestrength_sel = str_tab[i].sel;
2654 cc_data_temp = BHND_PMU_CCTRL_READ(sc, 1);
2655 cc_data_temp &= ~str_mask;
2656 drivestrength_sel <<= str_shift;
2657 cc_data_temp |= drivestrength_sel;
2658 BHND_PMU_CCTRL_WRITE(sc, 1, cc_data_temp, ~0);
2660 PMU_DEBUG(sc, "SDIO: %dmA drive strength selected, set to "
2661 "0x%08x\n", drivestrength, cc_data_temp);
2666 * Initialize the PMU.
2669 bhnd_pmu_init(struct bhnd_pmu_softc *sc)
2674 if (BHND_PMU_REV(sc) == 1) {
2675 BHND_PMU_AND_4(sc, BHND_PMU_CTRL, ~BHND_PMU_CTRL_NOILP_ON_WAIT);
2676 } else if (BHND_PMU_REV(sc) >= 2) {
2677 BHND_PMU_OR_4(sc, BHND_PMU_CTRL, BHND_PMU_CTRL_NOILP_ON_WAIT);
2680 if (sc->cid.chip_id == BHND_CHIPID_BCM4329 && sc->cid.chip_rev == 2) {
2681 /* Fix for 4329b0 bad LPOM state. */
2682 BHND_PMU_REGCTRL_WRITE(sc, 2, 0x100, ~0);
2683 BHND_PMU_REGCTRL_WRITE(sc, 3, 0x4, ~0);
2686 if (sc->cid.chip_id == BHND_CHIPID_BCM4319) {
2687 /* Limiting the PALDO spike during init time */
2688 BHND_PMU_REGCTRL_WRITE(sc, 2, 0x00000005, 0x00000007);
2692 /* Fetch target xtalfreq, in KHz */
2693 error = bhnd_nvram_getvar_uint32(sc->chipc_dev, BHND_NVAR_XTALFREQ,
2696 /* If not available, log any real errors, and then try to measure it */
2698 if (error != ENOENT)
2699 PMU_LOG(sc, "error fetching xtalfreq: %d\n", error);
2701 xtalfreq = bhnd_pmu_measure_alpclk(sc);
2704 /* Perform PLL initialization */
2705 bhnd_pmu_pll_init(sc, xtalfreq);
2707 if ((error = bhnd_pmu_res_init(sc)))
2710 bhnd_pmu_swreg_init(sc);
2715 /* Return up time in ILP cycles for the given resource. */
2717 bhnd_pmu_res_uptime(struct bhnd_pmu_softc *sc, uint8_t rsrc, uint32_t *uptime)
2720 uint32_t up, dup, dmax;
2724 /* uptime of resource 'rsrc' */
2725 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_TABLE_SEL, rsrc);
2726 up = BHND_PMU_READ_4(sc, BHND_PMU_RES_UPDN_TIMER);
2727 up = BHND_PMU_GET_BITS(up, BHND_PMU_RES_UPDN_UPTME);
2729 /* Find direct dependencies of resource 'rsrc' */
2730 deps = bhnd_pmu_res_deps(sc, BHND_PMURES_BIT(rsrc), false);
2731 for (uint8_t i = 0; i <= BHND_PMU_RESNUM_MAX; i++) {
2732 if (!(deps & BHND_PMURES_BIT(i)))
2734 deps &= ~bhnd_pmu_res_deps(sc, BHND_PMURES_BIT(i), true);
2737 /* Exclude the minimum resource set */
2738 if ((error = bhnd_pmu_res_masks(sc, &min_mask, NULL)))
2743 /* max uptime of direct dependencies */
2745 for (uint8_t i = 0; i <= BHND_PMU_RESNUM_MAX; i++) {
2746 if (!(deps & BHND_PMURES_BIT(i)))
2749 if ((error = bhnd_pmu_res_uptime(sc, i, &dup)))
2756 PMU_DEBUG(sc, "bhnd_pmu_res_uptime: rsrc %hhu uptime %u(deps 0x%08x "
2757 "uptime %u)\n", rsrc, up, deps, dmax);
2759 *uptime = (up + dmax + BHND_PMURES_UP_TRANSITION);
2763 /* Return dependencies (direct or all/indirect) for the given resources */
2765 bhnd_pmu_res_deps(struct bhnd_pmu_softc *sc, uint32_t rsrcs, bool all)
2770 for (uint8_t i = 0; i <= BHND_PMU_RESNUM_MAX; i++) {
2771 if (!(rsrcs & BHND_PMURES_BIT(i)))
2774 BHND_PMU_WRITE_4(sc, BHND_PMU_RES_TABLE_SEL, i);
2775 deps |= BHND_PMU_READ_4(sc, BHND_PMU_RES_DEP_MASK);
2782 /* Recurse dependencies */
2784 deps |= bhnd_pmu_res_deps(sc, deps, true);
2789 /* power up/down OTP through PMU resources */
2791 bhnd_pmu_otp_power(struct bhnd_pmu_softc *sc, bool on)
2798 /* Determine rsrcs to turn on/off OTP power */
2799 switch (sc->cid.chip_id) {
2800 case BHND_CHIPID_BCM4322:
2801 case BHND_CHIPID_BCM43221:
2802 case BHND_CHIPID_BCM43231:
2803 case BHND_CHIPID_BCM4342:
2804 rsrcs = PMURES_BIT(RES4322_OTP_PU);
2806 case BHND_CHIPID_BCM4315:
2807 rsrcs = PMURES_BIT(RES4315_OTP_PU);
2809 case BHND_CHIPID_BCM4325:
2810 rsrcs = PMURES_BIT(RES4325_OTP_PU);
2812 case BHND_CHIPID_BCM4329:
2813 rsrcs = PMURES_BIT(RES4329_OTP_PU);
2815 case BHND_CHIPID_BCM4319:
2816 rsrcs = PMURES_BIT(RES4319_OTP_PU);
2818 case BHND_CHIPID_BCM4336:
2819 rsrcs = PMURES_BIT(RES4336_OTP_PU);
2821 case BHND_CHIPID_BCM4330:
2822 rsrcs = PMURES_BIT(RES4330_OTP_PU);
2829 /* Fetch all dependencies */
2830 deps = bhnd_pmu_res_deps(sc, rsrcs, true);
2832 /* Exclude the minimum resource set */
2833 if ((error = bhnd_pmu_res_masks(sc, &min_mask, NULL)))
2838 /* Turn on/off the power */
2842 PMU_DEBUG(sc, "Adding rsrc 0x%x to min_res_mask\n",
2844 BHND_PMU_OR_4(sc, BHND_PMU_MIN_RES_MASK, (rsrcs|deps));
2846 /* Wait for all resources to become available */
2847 for (int i = 0; i < BHND_PMU_MAX_TRANSITION_DLY; i += 10) {
2848 state = BHND_PMU_READ_4(sc, BHND_PMU_RES_STATE);
2849 if ((state & rsrcs) == rsrcs)
2855 if ((state & rsrcs) != rsrcs) {
2856 PMU_LOG(sc, "timeout waiting for OTP resource "
2861 PMU_DEBUG(sc, "Removing rsrc 0x%x from min_res_mask\n",
2863 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK, ~(rsrcs|deps));
2870 bhnd_pmu_rcal(struct bhnd_pmu_softc *sc)
2875 bool bluetooth_rcal;
2878 bluetooth_rcal = false;
2880 switch (sc->cid.chip_id) {
2881 case BHND_CHIPID_BCM4325:
2882 case BHND_CHIPID_BCM4329:
2884 BHND_PMU_WRITE_4(sc, BHND_PMU_CHIPCTL_ADDR, 1);
2886 /* Power Down RCAL Block */
2887 BHND_PMU_AND_4(sc, BHND_PMU_CHIPCTL_DATA, ~0x04);
2889 if (sc->cid.chip_id == BHND_CHIPID_BCM4325) {
2890 chipst = BHND_CHIPC_READ_CHIPST(sc->chipc_dev);
2891 if (BHND_PMU_GET_BITS(chipst, CHIPC_CST4325_RCAL_VALID))
2892 bluetooth_rcal = true;
2895 /* Power Up RCAL block */
2896 BHND_PMU_AND_4(sc, BHND_PMU_CHIPCTL_DATA, 0x04);
2898 /* Wait for completion */
2899 for (int i = 0; i < (10 * 1000 * 1000); i++) {
2900 chipst = BHND_CHIPC_READ_CHIPST(sc->chipc_dev);
2907 KASSERT((chipst & 0x08) != 0, ("rcal completion timeout"));
2909 if (bluetooth_rcal) {
2912 /* Drop LSB to convert from 5 bit code to 4 bit code */
2913 rcal_code = (uint8_t) (chipst >> 5) & 0x0f;
2916 PMU_DEBUG("RCal completed, status 0x%x, code 0x%x\n",
2917 R_REG(&cc->chipstatus), rcal_code);
2919 /* Write RCal code into pmu_vreg_ctrl[32:29] */
2920 BHND_PMU_WRITE_4(sc, BHND_PMU_REG_CONTROL_ADDR, 0);
2921 val = BHND_PMU_READ_4(sc, BHND_PMU_REG_CONTROL_DATA);
2922 val &= ~((uint32_t) 0x07 << 29);
2923 val |= (uint32_t) (rcal_code & 0x07) << 29;
2924 BHND_PMU_WRITE_4(sc, BHND_PMU_REG_CONTROL_DATA, val);
2926 BHND_PMU_WRITE_4(sc, BHND_PMU_REG_CONTROL_ADDR, 1);
2927 val = BHND_PMU_READ_4(sc, BHND_PMU_REG_CONTROL_DATA);
2928 val &= ~(uint32_t) 0x01;
2929 val |= (uint32_t) ((rcal_code >> 3) & 0x01);
2930 BHND_PMU_WRITE_4(sc, BHND_PMU_REG_CONTROL_DATA, val);
2932 /* Write RCal code into pmu_chip_ctrl[33:30] */
2933 BHND_PMU_WRITE_4(sc, BHND_PMU_CHIPCTL_ADDR, 0);
2934 val = BHND_PMU_READ_4(sc, BHND_PMU_CHIPCTL_DATA);
2935 val &= ~((uint32_t) 0x03 << 30);
2936 val |= (uint32_t) (rcal_code & 0x03) << 30;
2937 BHND_PMU_WRITE_4(sc, BHND_PMU_CHIPCTL_DATA, val);
2939 BHND_PMU_WRITE_4(sc, BHND_PMU_CHIPCTL_ADDR, 1);
2940 val = BHND_PMU_READ_4(sc, BHND_PMU_CHIPCTL_DATA);
2941 val &= ~(uint32_t) 0x03;
2942 val |= (uint32_t) ((rcal_code >> 2) & 0x03);
2943 BHND_PMU_WRITE_4(sc, BHND_PMU_CHIPCTL_DATA, val);
2945 /* Set override in pmu_chip_ctrl[29] */
2946 BHND_PMU_WRITE_4(sc, BHND_PMU_CHIPCTL_ADDR, 0);
2947 BHND_PMU_OR_4(sc, BHND_PMU_CHIPCTL_DATA, (0x01 << 29));
2949 /* Power off RCal block */
2950 BHND_PMU_WRITE_4(sc, BHND_PMU_CHIPCTL_ADDR, 1);
2951 BHND_PMU_AND_4(sc, BHND_PMU_CHIPCTL_DATA, ~0x04);
2959 bhnd_pmu_spuravoid(struct bhnd_pmu_softc *sc, uint8_t spuravoid)
2961 /* force the HT off */
2962 if (sc->cid.chip_id == BHND_CHIPID_BCM4336) {
2963 BHND_PMU_AND_4(sc, BHND_PMU_MAX_RES_MASK,
2964 ~BHND_PMU_RES4336_HT_AVAIL);
2966 /* wait for the ht to really go away */
2967 PMU_WAIT_CLKST(sc, 0, BHND_CCS_HTAVAIL);
2970 /* update the pll changes */
2971 bhnd_pmu_spuravoid_pllupdate(sc, spuravoid);
2973 /* enable HT back on */
2974 if (sc->cid.chip_id == BHND_CHIPID_BCM4336) {
2975 BHND_PMU_OR_4(sc, BHND_PMU_MAX_RES_MASK,
2976 BHND_PMU_RES4336_HT_AVAIL);
2981 bhnd_pmu_spuravoid_pllupdate(struct bhnd_pmu_softc *sc, uint8_t spuravoid)
2986 uint8_t phypll_offset;
2988 uint8_t bcm5357_bcm43236_p1div[] = { 0x1, 0x5, 0x5 };
2989 uint8_t bcm5357_bcm43236_ndiv[] = { 0x30, 0xf6, 0xfc };
2991 /* 6362a0 has same clks as 4322[4-6] */
2992 chip_id = sc->cid.chip_id;
2993 if (chip_id == BHND_CHIPID_BCM6362 && sc->cid.chip_rev == 0) {
2994 chip_id = BHND_CHIPID_BCM43224;
2998 case BHND_CHIPID_BCM6362:
2999 KASSERT(sc->cid.chip_rev != 0, ("invalid clock config"));
3001 case BHND_CHIPID_BCM5357:
3002 case BHND_CHIPID_BCM4749:
3003 case BHND_CHIPID_BCM43235:
3004 case BHND_CHIPID_BCM43236:
3005 case BHND_CHIPID_BCM43238:
3006 case BHND_CHIPID_BCM43234:
3007 case BHND_CHIPID_BCM43237:
3008 case BHND_CHIPID_BCM53572:
3009 KASSERT(spuravoid < nitems(bcm5357_bcm43236_p1div),
3010 ("spuravoid %hhu outside p1div table\n", spuravoid));
3012 KASSERT(spuravoid < nitems(bcm5357_bcm43236_ndiv),
3013 ("spuravoid %hhu outside ndiv table\n", spuravoid));
3015 /* BCM5357 needs to touch PLL1_PLLCTL[02], so offset
3016 * PLL0_PLLCTL[02] by 6 */
3018 if (sc->cid.chip_id == BHND_CHIPID_BCM5357)
3021 /* RMW only the P1 divider */
3022 tmp = BHND_PMU_SET_BITS(bcm5357_bcm43236_p1div[spuravoid],
3023 BHND_PMU1_PLL0_PC0_P1DIV);
3024 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0 + phypll_offset,
3025 tmp, BHND_PMU1_PLL0_PC0_P1DIV_MASK);
3027 /* RMW only the int feedback divider */
3028 tmp = BHND_PMU_SET_BITS(bcm5357_bcm43236_ndiv[spuravoid],
3029 BHND_PMU1_PLL0_PC2_NDIV_INT);
3030 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2 + phypll_offset,
3031 tmp, BHND_PMU1_PLL0_PC0_P1DIV_MASK);
3033 pmuctrl = BHND_PMU_CTRL_PLL_PLLCTL_UPD;
3036 case BHND_CHIPID_BCM4331:
3037 if (spuravoid == 2) {
3038 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3040 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3042 } else if (spuravoid == 1) {
3043 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3045 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3048 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3050 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3053 pmuctrl = BHND_PMU_CTRL_PLL_PLLCTL_UPD;
3056 case BHND_CHIPID_BCM43224:
3057 case BHND_CHIPID_BCM43225:
3058 case BHND_CHIPID_BCM43226:
3059 case BHND_CHIPID_BCM43421:
3060 if (spuravoid == 1) {
3061 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3063 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
3065 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3067 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
3069 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4,
3071 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5,
3074 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3076 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
3078 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3080 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
3082 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4,
3084 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5,
3087 pmuctrl = BHND_PMU_CTRL_PLL_PLLCTL_UPD;
3090 case BHND_CHIPID_BCM43111:
3091 case BHND_CHIPID_BCM43112:
3092 case BHND_CHIPID_BCM43222:
3093 case BHND_CHIPID_BCM43420:
3094 if (spuravoid == 1) {
3095 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3097 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
3099 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3101 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
3103 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4,
3105 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5,
3108 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3110 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
3112 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3114 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
3116 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4,
3118 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5,
3122 pmuctrl = BHND_PMU_CTRL_PLL_PLLCTL_UPD;
3125 case BHND_CHIPID_BCM4716:
3126 case BHND_CHIPID_BCM4748:
3127 case BHND_CHIPID_BCM47162:
3128 if (spuravoid == 1) {
3129 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3131 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
3133 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3135 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
3137 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4,
3139 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5,
3142 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3144 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
3146 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3148 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
3150 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4,
3152 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5,
3156 pmuctrl = BHND_PMU_CTRL_NOILP_ON_WAIT |
3157 BHND_PMU_CTRL_PLL_PLLCTL_UPD;
3160 case BHND_CHIPID_BCM4319:
3164 case BHND_CHIPID_BCM4322:
3165 case BHND_CHIPID_BCM43221:
3166 case BHND_CHIPID_BCM43231:
3167 case BHND_CHIPID_BCM4342:
3168 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0, 0x11100070, ~0);
3169 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1, 0x1014140a, ~0);
3170 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5, 0x88888854, ~0);
3172 if (spuravoid == 1) {
3173 /* spur_avoid ON, enable 41/82/164Mhz clock mode */
3174 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3177 /* enable 40/80/160Mhz clock mode */
3178 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3182 pmuctrl = BHND_PMU_CTRL_PLL_PLLCTL_UPD;
3185 case BHND_CHIPID_BCM4336:
3186 /* Looks like these are only for default xtal freq 26MHz */
3187 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0, 0x02100020, ~0);
3188 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1, 0x0C0C0C0C, ~0);
3189 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2, 0x01240C0C, ~0);
3190 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4, 0x202C2820, ~0);
3191 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5, 0x88888825, ~0);
3193 if (spuravoid == 1) {
3198 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3, tmp, ~0);
3200 pmuctrl = BHND_PMU_CTRL_PLL_PLLCTL_UPD;
3202 case BHND_CHIPID_BCM43131:
3203 case BHND_CHIPID_BCM43227:
3204 case BHND_CHIPID_BCM43228:
3205 case BHND_CHIPID_BCM43428:
3207 /* PLL Settings for spur avoidance on/off mode, no on2 support
3209 if (spuravoid == 1) {
3210 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3212 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
3214 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3216 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
3218 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4,
3220 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5,
3223 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL0,
3225 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1,
3227 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2,
3229 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL3,
3231 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL4,
3233 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL5,
3236 pmuctrl = BHND_PMU_CTRL_PLL_PLLCTL_UPD;
3239 PMU_LOG(sc, "%s: unknown spuravoidance settings for chip %#hx, "
3240 "not changing PLL", __func__, sc->cid.chip_id);
3246 BHND_PMU_OR_4(sc, BHND_PMU_CTRL, pmuctrl);
3250 bhnd_pmu_is_otp_powered(struct bhnd_pmu_softc *sc)
3254 /* Determine per-chip OTP resource */
3255 switch (sc->cid.chip_id) {
3256 case BHND_CHIPID_BCM4329:
3257 otp_res = PMURES_BIT(RES4329_OTP_PU);
3259 case BHND_CHIPID_BCM4319:
3260 otp_res = PMURES_BIT(RES4319_OTP_PU);
3262 case BHND_CHIPID_BCM4336:
3263 otp_res = PMURES_BIT(RES4336_OTP_PU);
3265 case BHND_CHIPID_BCM4330:
3266 otp_res = PMURES_BIT(RES4330_OTP_PU);
3269 /* These chips don't use PMU bit to power up/down OTP. OTP always on.
3270 * Use OTP_INIT command to reset/refresh state.
3272 case BHND_CHIPID_BCM43224:
3273 case BHND_CHIPID_BCM43225:
3274 case BHND_CHIPID_BCM43421:
3275 case BHND_CHIPID_BCM43236:
3276 case BHND_CHIPID_BCM43235:
3277 case BHND_CHIPID_BCM43238:
3284 /* Check resource state */
3285 if ((BHND_PMU_READ_4(sc, BHND_PMU_RES_STATE) & otp_res) == 0)
3292 bhnd_pmu_paref_ldo_enable(struct bhnd_pmu_softc *sc, bool enable)
3296 switch (sc->cid.chip_id) {
3297 case BHND_CHIPID_BCM4328:
3298 ldo = PMURES_BIT(RES4328_PA_REF_LDO);
3300 case BHND_CHIPID_BCM5354:
3301 ldo = PMURES_BIT(RES5354_PA_REF_LDO);
3303 case BHND_CHIPID_BCM4312:
3304 ldo = PMURES_BIT(RES4312_PA_REF_LDO);
3311 BHND_PMU_OR_4(sc, BHND_PMU_MIN_RES_MASK, ldo);
3313 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK, ~ldo);
3317 /* initialize PMU switch/regulators */
3319 bhnd_pmu_swreg_init(struct bhnd_pmu_softc *sc)
3323 switch (sc->cid.chip_id) {
3324 case BHND_CHIPID_BCM4325:
3325 if (sc->cid.chip_rev <= 2)
3328 chipst = BHND_CHIPC_READ_CHIPST(sc->chipc_dev);
3329 if (BHND_PMU_GET_BITS(chipst, CHIPC_CST4325_PMUTOP_2B)) {
3330 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_CLDO_PWM,
3332 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_CLDO_BURST,
3336 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_CBUCK_PWM, 0xb);
3337 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_CBUCK_BURST, 0xb);
3339 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_LNLDO1, 0x1);
3340 if (sc->board.board_flags & BHND_BFL_LNLDO2_2P5) {
3341 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_LNLDO2_SEL,
3346 case BHND_CHIPID_BCM4336:
3347 /* Reduce CLDO PWM output voltage to 1.2V */
3348 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_CLDO_PWM, 0xe);
3349 /* Reduce CLDO BURST output voltage to 1.2V */
3350 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_CLDO_BURST, 0xe);
3351 /* Reduce LNLDO1 output voltage to 1.2V */
3352 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_LNLDO1, 0xe);
3353 if (sc->cid.chip_rev == 0)
3354 BHND_PMU_REGCTRL_WRITE(sc, 2, 0x400000, 0x400000);
3357 case BHND_CHIPID_BCM4330:
3358 /* CBUCK Voltage is 1.8 by default and set that to 1.5 */
3359 bhnd_pmu_set_ldo_voltage(sc, SET_LDO_VOLTAGE_CBUCK_PWM, 0);
3367 bhnd_pmu_radio_enable(struct bhnd_pmu_softc *sc, device_t d11core, bool enable)
3373 if (bhnd_get_device(d11core) != BHND_COREID_D11) {
3374 device_printf(sc->dev,
3375 "bhnd_pmu_radio_enable() called on non-D11 core");
3379 switch (sc->cid.chip_id) {
3380 case BHND_CHIPID_BCM4325:
3381 if (sc->board.board_flags & BHND_BFL_FASTPWR)
3384 if ((sc->board.board_flags & BHND_BFL_BUCKBOOST) == 0)
3387 rsrcs = PMURES_BIT(RES4325_BUCK_BOOST_BURST);
3390 BHND_PMU_OR_4(sc, BHND_PMU_MIN_RES_MASK, rsrcs);
3391 DELAY(100 * 1000); /* 100ms */
3393 BHND_PMU_AND_4(sc, BHND_PMU_MIN_RES_MASK, ~rsrcs);
3398 case BHND_CHIPID_BCM4319:
3399 error = bhnd_read_config(d11core, BCMA_DMP_OOBSELOUTB74,
3405 oobsel |= BHND_PMU_SET_BITS(BCMA_DMP_OOBSEL_EN,
3407 oobsel |= BHND_PMU_SET_BITS(BCMA_DMP_OOBSEL_EN,
3410 oobsel &= ~BHND_PMU_SET_BITS(BCMA_DMP_OOBSEL_EN,
3412 oobsel &= ~BHND_PMU_SET_BITS(BCMA_DMP_OOBSEL_EN,
3416 return (bhnd_write_config(d11core, BCMA_DMP_OOBSELOUTB74,
3423 /* Wait for a particular clock level to be on the backplane */
3425 bhnd_pmu_waitforclk_on_backplane(struct bhnd_pmu_softc *sc, uint32_t clk,
3430 for (uint32_t i = 0; i < delay; i += 10) {
3431 pmu_st = BHND_PMU_READ_4(sc, BHND_PMU_ST);
3432 if ((pmu_st & clk) == clk)
3438 pmu_st = BHND_PMU_READ_4(sc, BHND_PMU_ST);
3439 return (pmu_st & clk);
3443 * Measures the ALP clock frequency in KHz. Returns 0 if not possible.
3444 * Possible only if PMU rev >= 10 and there is an external LPO 32768Hz crystal.
3447 #define EXT_ILP_HZ 32768
3450 bhnd_pmu_measure_alpclk(struct bhnd_pmu_softc *sc)
3455 if (BHND_PMU_REV(sc) < 10)
3458 pmu_st = BHND_PMU_READ_4(sc, BHND_PMU_ST);
3459 if (pmu_st & BHND_PMU_ST_EXTLPOAVAIL) {
3460 uint32_t alp_hz, ilp_ctr;
3462 /* Enable frequency measurement */
3463 BHND_PMU_WRITE_4(sc, BHND_PMU_XTALFREQ, 1U <<
3464 BHND_PMU_XTALFREQ_REG_MEASURE_SHIFT);
3466 /* Delay for well over 4 ILP clocks */
3469 /* Read the latched number of ALP ticks per 4 ILP ticks */
3470 ilp_ctr = BHND_PMU_READ_4(sc, BHND_PMU_XTALFREQ);
3471 ilp_ctr = BHND_PMU_GET_BITS(ilp_ctr,
3472 BHND_PMU_XTALFREQ_REG_ILPCTR);
3474 /* Turn off PMU_XTALFREQ_REG_MEASURE to save power */
3475 BHND_PMU_WRITE_4(sc, BHND_PMU_XTALFREQ, 0);
3477 /* Calculate ALP frequency */
3478 alp_hz = (ilp_ctr * EXT_ILP_HZ) / 4;
3480 /* Round to nearest 100KHz and convert to KHz */
3481 alp_khz = (alp_hz + 50000) / 100000 * 100;
3490 bhnd_pmu_set_4330_plldivs(struct bhnd_pmu_softc *sc)
3492 uint32_t FVCO = bhnd_pmu1_pllfvco0(&sc->query) / 1000;
3493 uint32_t m1div, m2div, m3div, m4div, m5div, m6div;
3494 uint32_t pllc1, pllc2;
3496 m2div = m3div = m4div = m6div = FVCO / 80;
3499 if (PMU_CST4330_SDIOD_CHIPMODE(sc))
3505 pllc1 |= BHND_PMU_SET_BITS(m1div, BHND_PMU1_PLL0_PC1_M1DIV);
3506 pllc1 |= BHND_PMU_SET_BITS(m2div, BHND_PMU1_PLL0_PC1_M2DIV);
3507 pllc1 |= BHND_PMU_SET_BITS(m3div, BHND_PMU1_PLL0_PC1_M3DIV);
3508 pllc1 |= BHND_PMU_SET_BITS(m4div, BHND_PMU1_PLL0_PC1_M4DIV);
3510 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL1, pllc1, ~0);
3513 pllc2 |= BHND_PMU_SET_BITS(m5div, BHND_PMU1_PLL0_PC2_M5DIV);
3514 pllc2 |= BHND_PMU_SET_BITS(m6div, BHND_PMU1_PLL0_PC2_M6DIV);
3516 BHND_PMU_PLL_WRITE(sc, BHND_PMU1_PLL0_PLLCTL2, pllc2,
3517 BHND_PMU1_PLL0_PC2_M5DIV_MASK | BHND_PMU1_PLL0_PC2_M6DIV_MASK);