2 * Misc utility routines for accessing chip-specific features
3 * of the SiliconBackplane-based Broadcom chips.
5 * Copyright 2007, Broadcom Corporation
8 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
9 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
11 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
33 #define SB_ERROR(args)
37 typedef uint32 (*sb_intrsoff_t
)(void *intr_arg
);
38 typedef void (*sb_intrsrestore_t
)(void *intr_arg
, uint32 arg
);
39 typedef bool (*sb_intrsenabled_t
)(void *intr_arg
);
41 typedef struct gpioh_item
{
44 gpio_handler_t handler
;
46 struct gpioh_item
*next
;
49 /* misc sb info needed by some of the routines */
50 typedef struct sb_info
{
52 struct sb_pub sb
; /* back plane public state (must be first field) */
54 void *osh
; /* osl os handle */
55 void *sdh
; /* bcmsdh handle */
57 void *curmap
; /* current regs va */
58 void *regs
[SB_MAXCORES
]; /* other regs va */
60 uint curidx
; /* current core index */
61 uint dev_coreid
; /* the core provides driver functions */
63 bool memseg
; /* flag to toggle MEM_SEG register */
65 uint numcores
; /* # discovered cores */
66 uint coreid
[SB_MAXCORES
]; /* id of each core */
67 uint32 coresba
[SB_MAXCORES
]; /* backplane address of each core */
69 void *intr_arg
; /* interrupt callback function arg */
70 sb_intrsoff_t intrsoff_fn
; /* turns chip interrupts off */
71 sb_intrsrestore_t intrsrestore_fn
; /* restore chip interrupts */
72 sb_intrsenabled_t intrsenabled_fn
; /* check if interrupts are enabled */
74 uint8 pciecap_lcreg_offset
; /* PCIE capability LCreg offset in the config space */
77 bool pcie_war_ovr
; /* Override ASPM/Clkreq settings */
79 uint8 pmecap_offset
; /* PM Capability offset in the config space */
80 bool pmecap
; /* Capable of generating PME */
82 gpioh_item_t
*gpioh_head
; /* GPIO event handlers list */
88 /* local prototypes */
89 static sb_info_t
* sb_doattach(sb_info_t
*si
, uint devid
, osl_t
*osh
, void *regs
,
90 uint bustype
, void *sdh
, char **vars
, uint
*varsz
);
91 static void sb_scan(sb_info_t
*si
, void *regs
, uint devid
);
92 static uint
_sb_coreidx(sb_info_t
*si
, uint32 sba
);
93 static uint
_sb_scan(sb_info_t
*si
, uint32 sba
, void *regs
, uint bus
, uint32 sbba
,
95 static uint32
_sb_coresba(sb_info_t
*si
);
96 static void *_sb_setcoreidx(sb_info_t
*si
, uint coreidx
);
97 static uint
sb_chip2numcores(uint chip
);
98 static bool sb_ispcie(sb_info_t
*si
);
99 static uint8
sb_find_pci_capability(sb_info_t
*si
, uint8 req_cap_id
,
100 uchar
*buf
, uint32
*buflen
);
101 static int sb_pci_fixcfg(sb_info_t
*si
);
102 /* routines to access mdio slave device registers */
103 static int sb_pcie_mdiowrite(sb_info_t
*si
, uint physmedia
, uint readdr
, uint val
);
104 static int sb_pcie_mdioread(sb_info_t
*si
, uint physmedia
, uint readdr
, uint
*ret_val
);
106 /* dev path concatenation util */
107 static char *sb_devpathvar(sb_t
*sbh
, char *var
, int len
, const char *name
);
110 static void sb_war43448(sb_t
*sbh
);
111 static void sb_war43448_aspm(sb_t
*sbh
);
112 static void sb_war32414_forceHT(sb_t
*sbh
, bool forceHT
);
113 static void sb_war30841(sb_info_t
*si
);
114 static void sb_war42767(sb_t
*sbh
);
115 static void sb_war42767_clkreq(sb_t
*sbh
);
117 /* delay needed between the mdio control/ mdiodata register data access */
118 #define PR28829_DELAY() OSL_DELAY(10)
120 /* size that can take bitfielddump */
121 #define BITFIELD_DUMP_SIZE 32
123 /* global variable to indicate reservation/release of gpio's */
124 static uint32 sb_gpioreservation
= 0;
126 /* global flag to prevent shared resources from being initialized multiple times in sb_attach() */
127 static bool sb_onetimeinit
= FALSE
;
129 #define SB_INFO(sbh) (sb_info_t*)(uintptr)sbh
130 #define SET_SBREG(si, r, mask, val) \
131 W_SBREG((si), (r), ((R_SBREG((si), (r)) & ~(mask)) | (val)))
132 #define GOODCOREADDR(x, b) (((x) >= (b)) && ((x) < ((b) + SB_MAXCORES * SB_CORE_SIZE)) && \
133 ISALIGNED((x), SB_CORE_SIZE))
134 #define GOODREGS(regs) ((regs) && ISALIGNED((uintptr)(regs), SB_CORE_SIZE))
135 #define REGS2SB(va) (sbconfig_t*) ((int8*)(va) + SBCONFIGOFF)
136 #define BADCOREADDR 0
137 #define GOODIDX(idx) (((uint)idx) < SB_MAXCORES)
138 #define BADIDX (SB_MAXCORES+1)
139 #define NOREV -1 /* Invalid rev */
141 #define PCI(si) ((BUSTYPE(si->sb.bustype) == PCI_BUS) && (si->sb.buscoretype == SB_PCI))
142 #define PCIE(si) ((BUSTYPE(si->sb.bustype) == PCI_BUS) && (si->sb.buscoretype == SB_PCIE))
143 #define PCMCIA(si) ((BUSTYPE(si->sb.bustype) == PCMCIA_BUS) && (si->memseg == TRUE))
146 #define SONICS_2_2 (SBIDL_RV_2_2 >> SBIDL_RV_SHIFT)
147 #define SONICS_2_3 (SBIDL_RV_2_3 >> SBIDL_RV_SHIFT)
149 #define R_SBREG(si, sbr) sb_read_sbreg((si), (sbr))
150 #define W_SBREG(si, sbr, v) sb_write_sbreg((si), (sbr), (v))
151 #define AND_SBREG(si, sbr, v) W_SBREG((si), (sbr), (R_SBREG((si), (sbr)) & (v)))
152 #define OR_SBREG(si, sbr, v) W_SBREG((si), (sbr), (R_SBREG((si), (sbr)) | (v)))
155 * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts before/
156 * after core switching to avoid invalid register accesss inside ISR.
158 #define INTR_OFF(si, intr_val) \
159 if ((si)->intrsoff_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) { \
160 intr_val = (*(si)->intrsoff_fn)((si)->intr_arg); }
161 #define INTR_RESTORE(si, intr_val) \
162 if ((si)->intrsrestore_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) { \
163 (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val); }
165 /* dynamic clock control defines */
166 #define LPOMINFREQ 25000 /* low power oscillator min */
167 #define LPOMAXFREQ 43000 /* low power oscillator max */
168 #define XTALMINFREQ 19800000 /* 20 MHz - 1% */
169 #define XTALMAXFREQ 20200000 /* 20 MHz + 1% */
170 #define PCIMINFREQ 25000000 /* 25 MHz */
171 #define PCIMAXFREQ 34000000 /* 33 MHz + fudge */
173 #define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */
174 #define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */
176 /* force HT war check */
177 #define FORCEHT_WAR32414(si) \
178 (((PCIE(si)) && (si->sb.chip == BCM4311_CHIP_ID) && ((si->sb.chiprev <= 1))) || \
179 ((PCI(si) || PCIE(si)) && (si->sb.chip == BCM4321_CHIP_ID) && (si->sb.chiprev <= 3)))
181 #define PCIE_ASPMWARS(si) \
182 ((PCIE(si)) && ((si->sb.buscorerev >= 3) && (si->sb.buscorerev <= 5)))
184 /* GPIO Based LED powersave defines */
185 #define DEFAULT_GPIO_ONTIME 10 /* Default: 10% on */
186 #define DEFAULT_GPIO_OFFTIME 90 /* Default: 10% on */
188 #define DEFAULT_GPIOTIMERVAL ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
191 sb_read_sbreg(sb_info_t
*si
, volatile uint32
*sbr
)
194 uint32 val
, intr_val
= 0;
198 * compact flash only has 11 bits address, while we needs 12 bits address.
199 * MEM_SEG will be OR'd with other 11 bits address in hardware,
200 * so we program MEM_SEG with 12th bit when necessary(access sb regsiters).
201 * For normal PCMCIA bus(CFTable_regwinsz > 2k), do nothing special
204 INTR_OFF(si
, intr_val
);
206 OSL_PCMCIA_WRITE_ATTR(si
->osh
, MEM_SEG
, &tmp
, 1);
207 sbr
= (volatile uint32
*)((uintptr
)sbr
& ~(1 << 11)); /* mask out bit 11 */
210 val
= R_REG(si
->osh
, sbr
);
214 OSL_PCMCIA_WRITE_ATTR(si
->osh
, MEM_SEG
, &tmp
, 1);
215 INTR_RESTORE(si
, intr_val
);
222 sb_write_sbreg(sb_info_t
*si
, volatile uint32
*sbr
, uint32 v
)
225 volatile uint32 dummy
;
230 * compact flash only has 11 bits address, while we needs 12 bits address.
231 * MEM_SEG will be OR'd with other 11 bits address in hardware,
232 * so we program MEM_SEG with 12th bit when necessary(access sb regsiters).
233 * For normal PCMCIA bus(CFTable_regwinsz > 2k), do nothing special
236 INTR_OFF(si
, intr_val
);
238 OSL_PCMCIA_WRITE_ATTR(si
->osh
, MEM_SEG
, &tmp
, 1);
239 sbr
= (volatile uint32
*)((uintptr
)sbr
& ~(1 << 11)); /* mask out bit 11 */
242 if (BUSTYPE(si
->sb
.bustype
) == PCMCIA_BUS
) {
244 dummy
= R_REG(si
->osh
, sbr
);
245 W_REG(si
->osh
, ((volatile uint16
*)sbr
+ 1), (uint16
)((v
>> 16) & 0xffff));
246 dummy
= R_REG(si
->osh
, sbr
);
247 W_REG(si
->osh
, (volatile uint16
*)sbr
, (uint16
)(v
& 0xffff));
249 dummy
= R_REG(si
->osh
, sbr
);
250 W_REG(si
->osh
, (volatile uint16
*)sbr
, (uint16
)(v
& 0xffff));
251 dummy
= R_REG(si
->osh
, sbr
);
252 W_REG(si
->osh
, ((volatile uint16
*)sbr
+ 1), (uint16
)((v
>> 16) & 0xffff));
253 #endif /* IL_BIGENDIAN */
255 W_REG(si
->osh
, sbr
, v
);
259 OSL_PCMCIA_WRITE_ATTR(si
->osh
, MEM_SEG
, &tmp
, 1);
260 INTR_RESTORE(si
, intr_val
);
265 * Allocate a sb handle.
266 * devid - pci device id (used to determine chip#)
267 * osh - opaque OS handle
268 * regs - virtual address of initial core registers
269 * bustype - pci/pcmcia/sb/sdio/etc
270 * vars - pointer to a pointer area for "environment" variables
271 * varsz - pointer to int to return the size of the vars
274 BCMINITFN(sb_attach
)(uint devid
, osl_t
*osh
, void *regs
,
275 uint bustype
, void *sdh
, char **vars
, uint
*varsz
)
279 /* alloc sb_info_t */
280 if ((si
= MALLOC(osh
, sizeof (sb_info_t
))) == NULL
) {
281 SB_ERROR(("sb_attach: malloc failed! malloced %d bytes\n", MALLOCED(osh
)));
285 if (sb_doattach(si
, devid
, osh
, regs
, bustype
, sdh
, vars
, varsz
) == NULL
) {
286 MFREE(osh
, si
, sizeof(sb_info_t
));
289 si
->vars
= vars
? *vars
: NULL
;
290 si
->varsz
= varsz
? *varsz
: 0;
295 /* Using sb_kattach depends on SB_BUS support, either implicit */
296 /* no limiting BCMBUSTYPE value) or explicit (value is SB_BUS). */
297 #if !defined(BCMBUSTYPE) || (BCMBUSTYPE == SB_BUS)
299 /* global kernel resource */
300 static sb_info_t ksi
;
302 /* generic kernel variant of sb_attach() */
304 BCMINITFN(sb_kattach
)(osl_t
*osh
)
306 static bool ksi_attached
= FALSE
;
309 void *regs
= (void *)REG_MAP(SB_ENUM_BASE
, SB_CORE_SIZE
);
311 if (sb_doattach(&ksi
, BCM4710_DEVICE_ID
, osh
, regs
,
313 osh
!= SB_OSH
? &ksi
.vars
: NULL
,
314 osh
!= SB_OSH
? &ksi
.varsz
: NULL
) == NULL
) {
315 SB_ERROR(("sb_kattach: sb_doattach failed\n"));
324 #endif /* !BCMBUSTYPE || (BCMBUSTYPE == SB_BUS) */
327 BCMINITFN(sb_doattach
)(sb_info_t
*si
, uint devid
, osl_t
*osh
, void *regs
,
328 uint bustype
, void *sdh
, char **vars
, uint
*varsz
)
336 ASSERT(GOODREGS(regs
));
338 bzero((uchar
*)si
, sizeof(sb_info_t
));
340 si
->sb
.buscoreidx
= BADIDX
;
346 /* check to see if we are a sb core mimic'ing a pci core */
347 if (bustype
== PCI_BUS
) {
348 if (OSL_PCI_READ_CONFIG(si
->osh
, PCI_SPROM_CONTROL
, sizeof(uint32
)) == 0xffffffff) {
349 SB_ERROR(("%s: incoming bus is PCI but it's a lie, switching to SB "
350 "devid:0x%x\n", __FUNCTION__
, devid
));
354 si
->sb
.bustype
= bustype
;
355 if (si
->sb
.bustype
!= BUSTYPE(si
->sb
.bustype
)) {
356 SB_ERROR(("sb_doattach: bus type %d does not match configured bus type %d\n",
357 si
->sb
.bustype
, BUSTYPE(si
->sb
.bustype
)));
361 /* need to set memseg flag for CF card first before any sb registers access */
362 if (BUSTYPE(si
->sb
.bustype
) == PCMCIA_BUS
)
365 /* kludge to enable the clock on the 4306 which lacks a slowclock */
366 if (BUSTYPE(si
->sb
.bustype
) == PCI_BUS
&& !sb_ispcie(si
))
367 sb_clkctl_xtal(&si
->sb
, XTAL
|PLL
, ON
);
369 if (BUSTYPE(si
->sb
.bustype
) == PCI_BUS
) {
370 w
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_BAR0_WIN
, sizeof(uint32
));
371 if (!GOODCOREADDR(w
, SB_ENUM_BASE
))
372 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_BAR0_WIN
, sizeof(uint32
), SB_ENUM_BASE
);
376 /* get sonics backplane revision */
378 si
->sb
.sonicsrev
= (R_SBREG(si
, &sb
->sbidlow
) & SBIDL_RV_MASK
) >> SBIDL_RV_SHIFT
;
381 sb_scan(si
, regs
, devid
);
383 /* no cores found, bail out */
384 if (si
->numcores
== 0) {
385 SB_ERROR(("sb_doattach: could not find any cores\n"));
389 /* save the current core index */
390 origidx
= si
->curidx
;
392 /* don't go beyond if there is no chipc core in the chip */
393 if (!(cc
= sb_setcore(&si
->sb
, SB_CC
, 0)))
396 if (BUSTYPE(si
->sb
.bustype
) == SB_BUS
&&
397 (si
->sb
.chip
== BCM4712_CHIP_ID
) &&
398 (si
->sb
.chippkg
!= BCM4712LARGE_PKG_ID
) &&
399 (si
->sb
.chiprev
<= 3))
400 OR_REG(si
->osh
, &cc
->slow_clk_ctl
, SCC_SS_XTAL
);
402 /* fixup necessary chip/core configurations */
403 if (BUSTYPE(si
->sb
.bustype
) == PCI_BUS
&& sb_pci_fixcfg(si
)) {
404 SB_ERROR(("sb_doattach: sb_pci_fixcfg failed\n"));
409 /* Switch back to the original core, nvram/srom init needs it */
410 sb_setcoreidx(&si
->sb
, origidx
);
412 /* Init nvram from flash if it exists */
413 nvram_init((void *)&si
->sb
);
415 /* Init nvram from sprom/otp if they exist */
416 if (srom_var_init(&si
->sb
, BUSTYPE(si
->sb
.bustype
), regs
, si
->osh
, vars
, varsz
)) {
417 SB_ERROR(("sb_doattach: srom_var_init failed: bad srom\n"));
420 pvars
= vars
? *vars
: NULL
;
422 /* PMU specific initializations */
423 if ((si
->sb
.cccaps
& CC_CAP_PMU
) && !sb_onetimeinit
) {
424 sb_pmu_init(&si
->sb
, si
->osh
);
425 /* Find out Crystal frequency and init PLL */
426 sb_pmu_pll_init(&si
->sb
, si
->osh
, getintvar(pvars
, "xtalfreq"));
427 /* Initialize PMU resources (up/dn timers, dep masks, etc.) */
428 sb_pmu_res_init(&si
->sb
, si
->osh
);
431 if (BUSTYPE(si
->sb
.bustype
) == PCMCIA_BUS
) {
432 w
= getintvar(pvars
, "regwindowsz");
433 si
->memseg
= (w
<= CFTABLE_REGWIN_2K
) ? TRUE
: FALSE
;
436 /* get boardtype and boardrev */
437 switch (BUSTYPE(si
->sb
.bustype
)) {
439 /* do a pci config read to get subsystem id and subvendor id */
440 w
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_CFG_SVID
, sizeof(uint32
));
441 /* Let nvram variables override subsystem Vend/ID */
442 if ((si
->sb
.boardvendor
= (uint16
)sb_getdevpathintvar(&si
->sb
, "boardvendor")) == 0)
443 si
->sb
.boardvendor
= w
& 0xffff;
445 SB_ERROR(("Overriding boardvendor: 0x%x instead of 0x%x\n",
446 si
->sb
.boardvendor
, w
& 0xffff));
447 if ((si
->sb
.boardtype
= (uint16
)sb_getdevpathintvar(&si
->sb
, "boardtype")) == 0)
448 si
->sb
.boardtype
= (w
>> 16) & 0xffff;
450 SB_ERROR(("Overriding boardtype: 0x%x instead of 0x%x\n",
451 si
->sb
.boardtype
, (w
>> 16) & 0xffff));
455 si
->sb
.boardvendor
= getintvar(pvars
, "manfid");
456 si
->sb
.boardtype
= getintvar(pvars
, "prodid");
461 si
->sb
.boardvendor
= VENDOR_BROADCOM
;
462 if (pvars
== NULL
|| ((si
->sb
.boardtype
= getintvar(pvars
, "prodid")) == 0))
463 if ((si
->sb
.boardtype
= getintvar(NULL
, "boardtype")) == 0)
464 si
->sb
.boardtype
= 0xffff;
468 if (si
->sb
.boardtype
== 0) {
469 SB_ERROR(("sb_doattach: unknown board type\n"));
470 ASSERT(si
->sb
.boardtype
);
473 si
->sb
.boardflags
= getintvar(pvars
, "boardflags");
475 /* setup the GPIO based LED powersave register */
476 if (si
->sb
.ccrev
>= 16) {
477 if ((pvars
== NULL
) || ((w
= getintvar(pvars
, "leddc")) == 0))
478 w
= DEFAULT_GPIOTIMERVAL
;
479 sb_corereg(&si
->sb
, SB_CC_IDX
, OFFSETOF(chipcregs_t
, gpiotimerval
), ~0, w
);
482 /* Determine if this board needs override */
483 if (PCIE(si
) && (si
->sb
.chip
== BCM4321_CHIP_ID
))
484 si
->pcie_war_ovr
= ((si
->sb
.boardvendor
== VENDOR_APPLE
) &&
485 ((uint8
)getintvar(pvars
, "sromrev") == 4) &&
486 ((uint8
)getintvar(pvars
, "boardrev") <= 0x71)) ||
487 ((uint32
)getintvar(pvars
, "boardflags2") & BFL2_PCIEWAR_OVR
);
489 if (PCIE_ASPMWARS(si
)) {
490 sb_war43448_aspm((void *)si
);
491 sb_war42767_clkreq((void *)si
);
494 if (FORCEHT_WAR32414(si
)) {
495 si
->sb
.pr32414
= TRUE
;
496 sb_clkctl_init(&si
->sb
);
497 sb_war32414_forceHT(&si
->sb
, 1);
500 if (PCIE(si
) && ((si
->sb
.buscorerev
== 6) || (si
->sb
.buscorerev
== 7)))
501 si
->sb
.pr42780
= TRUE
;
503 if (PCIE_ASPMWARS(si
))
504 sb_pcieclkreq(&si
->sb
, 1, 0);
507 (((si
->sb
.chip
== BCM4311_CHIP_ID
) && (si
->sb
.chiprev
== 2)) ||
508 ((si
->sb
.chip
== BCM4312_CHIP_ID
) && (si
->sb
.chiprev
== 0))))
509 sb_set_initiator_to(&si
->sb
, 0x3, sb_findcoreidx(&si
->sb
, SB_D11
, 0));
511 /* Disable gpiopullup and gpiopulldown */
512 if (!sb_onetimeinit
&& si
->sb
.ccrev
>= 20) {
513 cc
= (chipcregs_t
*)sb_setcore(&si
->sb
, SB_CC
, 0);
514 W_REG(osh
, &cc
->gpiopullup
, 0);
515 W_REG(osh
, &cc
->gpiopulldown
, 0);
516 sb_setcoreidx(&si
->sb
, origidx
);
521 sb_onetimeinit
= TRUE
;
527 /* Enable/Disable clkreq for PCIE (4311B0/4321B1) */
529 BCMINITFN(sb_war42780_clkreq
)(sb_t
*sbh
, bool clkreq
)
535 /* Don't change clkreq value if serdespll war has not yet been applied */
536 if (!si
->pr42767_war
&& PCIE_ASPMWARS(si
))
539 sb_pcieclkreq(sbh
, 1, (int32
)clkreq
);
543 BCMINITFN(sb_war43448
)(sb_t
*sbh
)
549 /* if not pcie bus, we're done */
550 if (!PCIE(si
) || !PCIE_ASPMWARS(si
))
553 /* Restore the polarity */
554 if (si
->pcie_polarity
!= 0)
555 sb_pcie_mdiowrite((void *)(uintptr
)&si
->sb
, MDIODATA_DEV_RX
,
556 SERDES_RX_CTRL
, si
->pcie_polarity
);
560 BCMINITFN(sb_war43448_aspm
)(sb_t
*sbh
)
563 uint16 val16
, *reg16
;
564 sbpcieregs_t
*pcieregs
;
569 /* if not pcie bus, we're done */
570 if (!PCIE(si
) || !PCIE_ASPMWARS(si
))
573 /* no ASPM stuff on QT or VSIM */
574 if (si
->sb
.chippkg
== HDLSIM_PKG_ID
|| si
->sb
.chippkg
== HWSIM_PKG_ID
)
577 pcieregs
= (sbpcieregs_t
*) sb_setcoreidx(sbh
, si
->sb
.buscoreidx
);
579 /* Enable ASPM in the shadow SROM and Link control */
580 reg16
= &pcieregs
->sprom
[SRSH_ASPM_OFFSET
];
581 val16
= R_REG(si
->osh
, reg16
);
582 if (!si
->pcie_war_ovr
)
583 val16
|= SRSH_ASPM_ENB
;
585 val16
&= ~SRSH_ASPM_ENB
;
586 W_REG(si
->osh
, reg16
, val16
);
588 w
= OSL_PCI_READ_CONFIG(si
->osh
, si
->pciecap_lcreg_offset
, sizeof(uint32
));
589 if (!si
->pcie_war_ovr
)
592 w
&= ~PCIE_ASPM_ENAB
;
593 OSL_PCI_WRITE_CONFIG(si
->osh
, si
->pciecap_lcreg_offset
, sizeof(uint32
), w
);
597 BCMINITFN(sb_war32414_forceHT
)(sb_t
*sbh
, bool forceHT
)
604 ASSERT(FORCEHT_WAR32414(si
));
609 sb_corereg(sbh
, SB_CC_IDX
, OFFSETOF(chipcregs_t
, system_clk_ctl
),
620 sb
= REGS2SB(si
->curmap
);
622 return ((R_SBREG(si
, &sb
->sbidhigh
) & SBIDH_CC_MASK
) >> SBIDH_CC_SHIFT
);
632 sb
= REGS2SB(si
->curmap
);
634 return R_SBREG(si
, &sb
->sbtpsflag
) & SBTPS_NUM0_MASK
;
638 sb_coreidx(sb_t
*sbh
)
646 /* return core index of the core with address 'sba' */
648 BCMINITFN(_sb_coreidx
)(sb_info_t
*si
, uint32 sba
)
652 for (i
= 0; i
< si
->numcores
; i
++)
653 if (sba
== si
->coresba
[i
])
658 /* return core address of the current core */
660 BCMINITFN(_sb_coresba
)(sb_info_t
*si
)
664 switch (BUSTYPE(si
->sb
.bustype
)) {
666 sbconfig_t
*sb
= REGS2SB(si
->curmap
);
667 sbaddr
= sb_base(R_SBREG(si
, &sb
->sbadmatch0
));
672 sbaddr
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_BAR0_WIN
, sizeof(uint32
));
677 OSL_PCMCIA_READ_ATTR(si
->osh
, PCMCIA_ADDR0
, &tmp
, 1);
678 sbaddr
= (uint32
)tmp
<< 12;
679 OSL_PCMCIA_READ_ATTR(si
->osh
, PCMCIA_ADDR1
, &tmp
, 1);
680 sbaddr
|= (uint32
)tmp
<< 16;
681 OSL_PCMCIA_READ_ATTR(si
->osh
, PCMCIA_ADDR2
, &tmp
, 1);
682 sbaddr
|= (uint32
)tmp
<< 24;
689 sbaddr
= (uint32
)(uintptr
)si
->curmap
;
694 sbaddr
= BADCOREADDR
;
698 SB_MSG(("_sb_coresba: current core is 0x%08x\n", sbaddr
));
703 sb_corevendor(sb_t
*sbh
)
709 sb
= REGS2SB(si
->curmap
);
711 return ((R_SBREG(si
, &sb
->sbidhigh
) & SBIDH_VC_MASK
) >> SBIDH_VC_SHIFT
);
715 sb_corerev(sb_t
*sbh
)
722 sb
= REGS2SB(si
->curmap
);
723 sbidh
= R_SBREG(si
, &sb
->sbidhigh
);
725 return (SBCOREREV(sbidh
));
738 sb_setosh(sb_t
*sbh
, osl_t
*osh
)
743 if (si
->osh
!= NULL
) {
744 SB_ERROR(("osh is already set....\n"));
750 /* set sbtmstatelow core-specific flags */
752 sb_coreflags_wo(sb_t
*sbh
, uint32 mask
, uint32 val
)
759 sb
= REGS2SB(si
->curmap
);
761 ASSERT((val
& ~mask
) == 0);
764 w
= (R_SBREG(si
, &sb
->sbtmstatelow
) & ~mask
) | val
;
765 W_SBREG(si
, &sb
->sbtmstatelow
, w
);
768 /* set/clear sbtmstatelow core-specific flags */
770 sb_coreflags(sb_t
*sbh
, uint32 mask
, uint32 val
)
777 sb
= REGS2SB(si
->curmap
);
779 ASSERT((val
& ~mask
) == 0);
783 w
= (R_SBREG(si
, &sb
->sbtmstatelow
) & ~mask
) | val
;
784 W_SBREG(si
, &sb
->sbtmstatelow
, w
);
787 /* return the new value
788 * for write operation, the following readback ensures the completion of write opration.
790 return (R_SBREG(si
, &sb
->sbtmstatelow
));
793 /* set/clear sbtmstatehigh core-specific flags */
795 sb_coreflagshi(sb_t
*sbh
, uint32 mask
, uint32 val
)
802 sb
= REGS2SB(si
->curmap
);
804 ASSERT((val
& ~mask
) == 0);
805 ASSERT((mask
& ~SBTMH_FL_MASK
) == 0);
809 w
= (R_SBREG(si
, &sb
->sbtmstatehigh
) & ~mask
) | val
;
810 W_SBREG(si
, &sb
->sbtmstatehigh
, w
);
813 /* return the new value */
814 return (R_SBREG(si
, &sb
->sbtmstatehigh
));
817 /* Run bist on current core. Caller needs to take care of core-specific bist hazards */
819 sb_corebist(sb_t
*sbh
)
827 sb
= REGS2SB(si
->curmap
);
829 sblo
= R_SBREG(si
, &sb
->sbtmstatelow
);
830 W_SBREG(si
, &sb
->sbtmstatelow
, (sblo
| SBTML_FGC
| SBTML_BE
));
832 SPINWAIT(((R_SBREG(si
, &sb
->sbtmstatehigh
) & SBTMH_BISTD
) == 0), 100000);
834 if (R_SBREG(si
, &sb
->sbtmstatehigh
) & SBTMH_BISTF
)
837 W_SBREG(si
, &sb
->sbtmstatelow
, sblo
);
843 sb_iscoreup(sb_t
*sbh
)
849 sb
= REGS2SB(si
->curmap
);
851 return ((R_SBREG(si
, &sb
->sbtmstatelow
) &
852 (SBTML_RESET
| SBTML_REJ_MASK
| SBTML_CLK
)) == SBTML_CLK
);
856 * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set operation,
857 * switch back to the original core, and return the new value.
859 * When using the silicon backplane, no fidleing with interrupts or core switches are needed.
861 * Also, when using pci/pcie, we can optimize away the core switching for pci registers
862 * and (on newer pci cores) chipcommon registers.
865 sb_corereg(sb_t
*sbh
, uint coreidx
, uint regoff
, uint mask
, uint val
)
876 ASSERT(GOODIDX(coreidx
));
877 ASSERT(regoff
< SB_CORE_SIZE
);
878 ASSERT((val
& ~mask
) == 0);
880 if (BUSTYPE(si
->sb
.bustype
) == SB_BUS
) {
881 /* If internal bus, we can always get at everything */
883 /* map if does not exist */
884 if (!si
->regs
[coreidx
]) {
885 si
->regs
[coreidx
] = (void*)REG_MAP(si
->coresba
[coreidx
],
887 ASSERT(GOODREGS(si
->regs
[coreidx
]));
889 r
= (uint32
*)((uchar
*)si
->regs
[coreidx
] + regoff
);
890 } else if (BUSTYPE(si
->sb
.bustype
) == PCI_BUS
) {
891 /* If pci/pcie, we can get at pci/pcie regs and on newer cores to chipc */
893 if ((si
->coreid
[coreidx
] == SB_CC
) &&
894 ((si
->sb
.buscoretype
== SB_PCIE
) ||
895 (si
->sb
.buscorerev
>= 13))) {
896 /* Chipc registers are mapped at 12KB */
899 r
= (uint32
*)((char *)si
->curmap
+ PCI_16KB0_CCREGS_OFFSET
+ regoff
);
900 } else if (si
->sb
.buscoreidx
== coreidx
) {
901 /* pci registers are at either in the last 2KB of an 8KB window
902 * or, in pcie and pci rev 13 at 8KB
905 if ((si
->sb
.buscoretype
== SB_PCIE
) ||
906 (si
->sb
.buscorerev
>= 13))
907 r
= (uint32
*)((char *)si
->curmap
+
908 PCI_16KB0_PCIREGS_OFFSET
+ regoff
);
910 r
= (uint32
*)((char *)si
->curmap
+
911 ((regoff
>= SBCONFIGOFF
) ?
912 PCI_BAR0_PCISBR_OFFSET
: PCI_BAR0_PCIREGS_OFFSET
) +
918 INTR_OFF(si
, intr_val
);
920 /* save current core index */
921 origidx
= sb_coreidx(&si
->sb
);
924 r
= (uint32
*) ((uchar
*) sb_setcoreidx(&si
->sb
, coreidx
) + regoff
);
930 if (regoff
>= SBCONFIGOFF
) {
931 w
= (R_SBREG(si
, r
) & ~mask
) | val
;
934 w
= (R_REG(si
->osh
, r
) & ~mask
) | val
;
935 W_REG(si
->osh
, r
, w
);
940 if (regoff
>= SBCONFIGOFF
)
944 if ((si
->sb
.chip
== BCM5354_CHIP_ID
) &&
945 (coreidx
== SB_CC_IDX
) &&
946 (regoff
== OFFSETOF(chipcregs_t
, watchdog
))) {
950 w
= R_REG(si
->osh
, r
);
954 /* restore core index */
955 if (origidx
!= coreidx
)
956 sb_setcoreidx(&si
->sb
, origidx
);
958 INTR_RESTORE(si
, intr_val
);
964 #define DWORD_ALIGN(x) (x & ~(0x03))
965 #define BYTE_POS(x) (x & 0x3)
966 #define WORD_POS(x) (x & 0x1)
968 #define BYTE_SHIFT(x) (8 * BYTE_POS(x))
969 #define WORD_SHIFT(x) (16 * WORD_POS(x))
971 #define BYTE_VAL(a, x) ((a >> BYTE_SHIFT(x)) & 0xFF)
972 #define WORD_VAL(a, x) ((a >> WORD_SHIFT(x)) & 0xFFFF)
974 #define read_pci_cfg_byte(a) \
975 (BYTE_VAL(OSL_PCI_READ_CONFIG(si->osh, DWORD_ALIGN(a), 4), a) & 0xff)
977 #define read_pci_cfg_word(a) \
978 (WORD_VAL(OSL_PCI_READ_CONFIG(si->osh, DWORD_ALIGN(a), 4), a) & 0xffff)
981 /* return cap_offset if requested capability exists in the PCI config space */
983 sb_find_pci_capability(sb_info_t
*si
, uint8 req_cap_id
, uchar
*buf
, uint32
*buflen
)
990 if (BUSTYPE(si
->sb
.bustype
) != PCI_BUS
)
993 /* check for Header type 0 */
994 byte_val
= read_pci_cfg_byte(PCI_CFG_HDR
);
995 if ((byte_val
& 0x7f) != PCI_HEADER_NORMAL
)
998 /* check if the capability pointer field exists */
999 byte_val
= read_pci_cfg_byte(PCI_CFG_STAT
);
1000 if (!(byte_val
& PCI_CAPPTR_PRESENT
))
1003 cap_ptr
= read_pci_cfg_byte(PCI_CFG_CAPPTR
);
1004 /* check if the capability pointer is 0x00 */
1005 if (cap_ptr
== 0x00)
1008 /* loop thr'u the capability list and see if the pcie capabilty exists */
1010 cap_id
= read_pci_cfg_byte(cap_ptr
);
1012 while (cap_id
!= req_cap_id
) {
1013 cap_ptr
= read_pci_cfg_byte((cap_ptr
+1));
1014 if (cap_ptr
== 0x00) break;
1015 cap_id
= read_pci_cfg_byte(cap_ptr
);
1017 if (cap_id
!= req_cap_id
) {
1020 /* found the caller requested capability */
1021 if ((buf
!= NULL
) && (buflen
!= NULL
)) {
1025 if (!bufsize
) goto end
;
1027 /* copy the cpability data excluding cap ID and next ptr */
1028 cap_data
= cap_ptr
+ 2;
1029 if ((bufsize
+ cap_data
) > SZPCR
)
1030 bufsize
= SZPCR
- cap_data
;
1033 *buf
= read_pci_cfg_byte(cap_data
);
1043 sb_pcieclkreq(sb_t
*sbh
, uint32 mask
, uint32 val
)
1051 offset
= si
->pciecap_lcreg_offset
;
1055 reg_val
= OSL_PCI_READ_CONFIG(si
->osh
, offset
, sizeof(uint32
));
1059 reg_val
|= PCIE_CLKREQ_ENAB
;
1061 reg_val
&= ~PCIE_CLKREQ_ENAB
;
1062 OSL_PCI_WRITE_CONFIG(si
->osh
, offset
, sizeof(uint32
), reg_val
);
1063 reg_val
= OSL_PCI_READ_CONFIG(si
->osh
, offset
, sizeof(uint32
));
1065 if (reg_val
& PCIE_CLKREQ_ENAB
)
1073 /* return TRUE if PCIE capability exists in the pci config space */
1075 sb_ispcie(sb_info_t
*si
)
1079 cap_ptr
= sb_find_pci_capability(si
, PCI_CAP_PCIECAP_ID
, NULL
, NULL
);
1083 si
->pciecap_lcreg_offset
= cap_ptr
+ PCIE_CAP_LINKCTRL_OFFSET
;
1088 /* Wake-on-wireless-LAN (WOWL) support functions */
1089 /* return TRUE if PM capability exists in the pci config space */
1091 sb_pci_pmecap(sb_t
*sbh
)
1099 if (si
== NULL
|| !(PCI(si
) || PCIE(si
)))
1102 if (!si
->pmecap_offset
) {
1103 cap_ptr
= sb_find_pci_capability(si
, PCI_CAP_POWERMGMTCAP_ID
, NULL
, NULL
);
1107 si
->pmecap_offset
= cap_ptr
;
1109 pmecap
= OSL_PCI_READ_CONFIG(si
->osh
, si
->pmecap_offset
, sizeof(uint32
));
1111 /* At least one state can generate PME */
1112 si
->pmecap
= (pmecap
& PME_CAP_PM_STATES
) != 0;
1115 return (si
->pmecap
);
1118 /* Enable PME generation and disable clkreq */
1120 sb_pci_pmeen(sb_t
*sbh
)
1126 /* if not pmecapable return */
1127 if (!sb_pci_pmecap(sbh
))
1130 w
= OSL_PCI_READ_CONFIG(si
->osh
, si
->pmecap_offset
+ PME_CSR_OFFSET
, sizeof(uint32
));
1131 w
|= (PME_CSR_PME_EN
);
1132 OSL_PCI_WRITE_CONFIG(si
->osh
, si
->pmecap_offset
+ PME_CSR_OFFSET
, sizeof(uint32
), w
);
1134 /* Disable clkreq */
1135 if (si
->pr42767_war
) {
1136 sb_pcieclkreq(sbh
, 1, 0);
1137 si
->pr42767_war
= FALSE
;
1138 } else if (si
->sb
.pr42780
) {
1139 sb_pcieclkreq(sbh
, 1, 1);
1143 /* Disable PME generation, clear the PME status bit if set and
1144 * return TRUE if PME status set
1147 sb_pci_pmeclr(sb_t
*sbh
)
1155 if (!sb_pci_pmecap(sbh
))
1158 w
= OSL_PCI_READ_CONFIG(si
->osh
, si
->pmecap_offset
+ PME_CSR_OFFSET
, sizeof(uint32
));
1160 SB_ERROR(("sb_pci_pmeclr PMECSR : 0x%x\n", w
));
1161 ret
= (w
& PME_CSR_PME_STAT
) == PME_CSR_PME_STAT
;
1163 /* PMESTAT is cleared by writing 1 to it */
1164 w
&= ~(PME_CSR_PME_EN
);
1166 OSL_PCI_WRITE_CONFIG(si
->osh
, si
->pmecap_offset
+ PME_CSR_OFFSET
, sizeof(uint32
), w
);
1171 /* Scan the enumeration space to find all cores starting from the given
1172 * bus 'sbba'. Append coreid and other info to the lists in 'si'. 'sba'
1173 * is the default core address at chip POR time and 'regs' is the virtual
1174 * address that the default core is mapped at. 'ncores' is the number of
1175 * cores expected on bus 'sbba'. It returns the total number of cores
1176 * starting from bus 'sbba', inclusive.
1178 #define SB_MAXBUSES 2
1180 BCMINITFN(_sb_scan
)(sb_info_t
*si
, uint32 sba
, void *regs
, uint bus
, uint32 sbba
, uint numcores
)
1186 if (bus
>= SB_MAXBUSES
) {
1187 SB_ERROR(("_sb_scan: bus 0x%08x at level %d is too deep to scan\n", sbba
, bus
));
1190 SB_MSG(("_sb_scan: scan bus 0x%08x assume %u cores\n", sbba
, numcores
));
1192 /* Scan all cores on the bus starting from core 0.
1193 * Core addresses must be contiguous on each bus.
1195 for (i
= 0, next
= si
->numcores
; i
< numcores
&& next
< SB_MAXCORES
; i
++, next
++) {
1196 si
->coresba
[next
] = sbba
+ i
* SB_CORE_SIZE
;
1198 /* keep and reuse the initial register mapping */
1199 if (BUSTYPE(si
->sb
.bustype
) == SB_BUS
&& si
->coresba
[next
] == sba
) {
1200 SB_MSG(("_sb_scan: reuse mapped regs %p for core %u\n", regs
, next
));
1201 si
->regs
[next
] = regs
;
1204 /* change core to 'next' and read its coreid */
1205 si
->curmap
= _sb_setcoreidx(si
, next
);
1208 si
->coreid
[next
] = sb_coreid(&si
->sb
);
1210 /* core specific processing... */
1211 /* chipc on bus SB_ENUM_BASE provides # cores in the chip and lots of
1214 if (sbba
== SB_ENUM_BASE
&& si
->coreid
[next
] == SB_CC
) {
1215 chipcregs_t
*cc
= (chipcregs_t
*)si
->curmap
;
1217 /* get chip id and rev */
1218 si
->sb
.chip
= R_REG(si
->osh
, &cc
->chipid
) & CID_ID_MASK
;
1219 si
->sb
.chiprev
= (R_REG(si
->osh
, &cc
->chipid
) & CID_REV_MASK
) >>
1221 si
->sb
.chippkg
= (R_REG(si
->osh
, &cc
->chipid
) & CID_PKG_MASK
) >>
1224 /* get chipcommon rev */
1225 si
->sb
.ccrev
= (int)sb_corerev(&si
->sb
);
1227 /* get chipcommon chipstatus */
1228 if (si
->sb
.ccrev
>= 11)
1229 si
->sb
.chipst
= R_REG(si
->osh
, &cc
->chipstatus
);
1231 /* get chipcommon capabilites */
1232 si
->sb
.cccaps
= R_REG(si
->osh
, &cc
->capabilities
);
1234 /* get pmu rev and caps */
1235 if ((si
->sb
.cccaps
& CC_CAP_PMU
)) {
1236 si
->sb
.pmucaps
= R_REG(si
->osh
, &cc
->pmucapabilities
);
1237 si
->sb
.pmurev
= si
->sb
.pmucaps
& PCAP_REV_MASK
;
1240 /* determine numcores - this is the total # cores in the chip */
1241 if (((si
->sb
.ccrev
== 4) || (si
->sb
.ccrev
>= 6)))
1242 numcores
= (R_REG(si
->osh
, &cc
->chipid
) & CID_CC_MASK
) >>
1245 numcores
= sb_chip2numcores(si
->sb
.chip
);
1246 SB_MSG(("_sb_scan: there are %u cores in the chip\n", numcores
));
1248 /* scan bridged SB(s) and add results to the end of the list */
1249 else if (si
->coreid
[next
] == SB_OCP
) {
1250 sbconfig_t
*sb
= REGS2SB(si
->curmap
);
1251 uint32 nsbba
= R_SBREG(si
, &sb
->sbadmatch1
);
1254 si
->numcores
= next
+ 1;
1256 if ((nsbba
& 0xfff00000) != SB_ENUM_BASE
)
1258 nsbba
&= 0xfffff000;
1259 if (_sb_coreidx(si
, nsbba
) != BADIDX
)
1262 nsbcc
= (R_SBREG(si
, &sb
->sbtmstatehigh
) & 0x000f0000) >> 16;
1263 nsbcc
= _sb_scan(si
, sba
, regs
, bus
+ 1, nsbba
, nsbcc
);
1264 if (sbba
== SB_ENUM_BASE
)
1270 SB_MSG(("_sb_scan: found %u cores on bus 0x%08x\n", i
, sbba
));
1272 si
->numcores
= i
+ ncc
;
1273 return si
->numcores
;
1276 /* scan the sb enumerated space to identify all cores */
1278 BCMINITFN(sb_scan
)(sb_info_t
*si
, void *regs
, uint devid
)
1291 /* Save the current core info and validate it later till we know
1292 * for sure what is good and what is bad.
1294 origsba
= _sb_coresba(si
);
1297 /* Use devid as initial chipid and we'll update it later in _sb_scan */
1298 si
->sb
.chip
= devid
;
1300 /* Support chipcommon-less chips for a little while longer so the old
1301 * sdio host fpga continues to work until we can get the new one working
1302 * reliably. This particular chip has 2 cores - codec/sdio and pci.
1304 if (devid
== SDIOH_FPGA_ID
)
1306 /* Expect at least one core on 0x18000000 and it must be chipcommon where
1307 * the core count for the whole chip is kept.
1312 /* scan all SB(s) starting from SB_ENUM_BASE */
1313 si
->numcores
= _sb_scan(si
, origsba
, regs
, 0, SB_ENUM_BASE
, numcores
);
1314 if (si
->numcores
== 0)
1317 /* figure out bus/orignal core idx */
1318 si
->sb
.buscorerev
= NOREV
;
1319 si
->sb
.buscoreidx
= BADIDX
;
1322 pcirev
= pcierev
= NOREV
;
1323 pciidx
= pcieidx
= BADIDX
;
1325 for (i
= 0; i
< si
->numcores
; i
++) {
1326 sb_setcoreidx(&si
->sb
, i
);
1328 if (BUSTYPE(si
->sb
.bustype
) == PCI_BUS
) {
1329 if (si
->coreid
[i
] == SB_PCI
) {
1331 pcirev
= sb_corerev(&si
->sb
);
1333 } else if (si
->coreid
[i
] == SB_PCIE
) {
1335 pcierev
= sb_corerev(&si
->sb
);
1338 } else if (BUSTYPE(si
->sb
.bustype
) == PCMCIA_BUS
) {
1339 if (si
->coreid
[i
] == SB_PCMCIA
) {
1340 si
->sb
.buscorerev
= sb_corerev(&si
->sb
);
1341 si
->sb
.buscoretype
= si
->coreid
[i
];
1342 si
->sb
.buscoreidx
= i
;
1346 /* find the core idx before entering this func. */
1347 if (origsba
== si
->coresba
[i
])
1358 si
->sb
.buscoretype
= SB_PCI
;
1359 si
->sb
.buscorerev
= pcirev
;
1360 si
->sb
.buscoreidx
= pciidx
;
1362 si
->sb
.buscoretype
= SB_PCIE
;
1363 si
->sb
.buscorerev
= pcierev
;
1364 si
->sb
.buscoreidx
= pcieidx
;
1367 /* return to the original core */
1368 if (origidx
!= BADIDX
)
1369 sb_setcoreidx(&si
->sb
, origidx
);
1370 ASSERT(origidx
!= BADIDX
);
1373 /* may be called with core in reset */
1375 sb_detach(sb_t
*sbh
)
1385 if (BUSTYPE(si
->sb
.bustype
) == SB_BUS
)
1386 for (idx
= 0; idx
< SB_MAXCORES
; idx
++)
1387 if (si
->regs
[idx
]) {
1388 REG_UNMAP(si
->regs
[idx
]);
1389 si
->regs
[idx
] = NULL
;
1391 #if !defined(BCMBUSTYPE) || (BCMBUSTYPE == SB_BUS)
1393 #endif /* !BCMBUSTYPE || (BCMBUSTYPE == SB_BUS) */
1394 MFREE(si
->osh
, si
, sizeof(sb_info_t
));
1397 /* convert chip number to number of i/o cores */
1399 BCMINITFN(sb_chip2numcores
)(uint chip
)
1401 if (chip
== BCM4306_CHIP_ID
) /* < 4306c0 */
1403 if (chip
== BCM4704_CHIP_ID
)
1405 if (chip
== BCM5365_CHIP_ID
)
1408 SB_ERROR(("sb_chip2numcores: unsupported chip 0x%x\n", chip
));
1413 /* return index of coreid or BADIDX if not found */
1415 sb_findcoreidx(sb_t
*sbh
, uint coreid
, uint coreunit
)
1425 for (i
= 0; i
< si
->numcores
; i
++)
1426 if (si
->coreid
[i
] == coreid
) {
1427 if (found
== coreunit
)
1436 * this function changes logical "focus" to the indiciated core,
1437 * must be called with interrupt off.
1438 * Moreover, callers should keep interrupts off during switching out of and back to d11 core
1441 sb_setcoreidx(sb_t
*sbh
, uint coreidx
)
1447 if (coreidx
>= si
->numcores
)
1451 * If the user has provided an interrupt mask enabled function,
1452 * then assert interrupts are disabled before switching the core.
1454 ASSERT((si
->intrsenabled_fn
== NULL
) || !(*(si
)->intrsenabled_fn
)((si
)->intr_arg
));
1456 si
->curmap
= _sb_setcoreidx(si
, coreidx
);
1457 si
->curidx
= coreidx
;
1459 return (si
->curmap
);
1462 /* This function changes the logical "focus" to the indiciated core.
1463 * Return the current core's virtual address.
1466 _sb_setcoreidx(sb_info_t
*si
, uint coreidx
)
1468 uint32 sbaddr
= si
->coresba
[coreidx
];
1471 switch (BUSTYPE(si
->sb
.bustype
)) {
1474 if (!si
->regs
[coreidx
]) {
1475 si
->regs
[coreidx
] = (void*)REG_MAP(sbaddr
, SB_CORE_SIZE
);
1476 ASSERT(GOODREGS(si
->regs
[coreidx
]));
1478 regs
= si
->regs
[coreidx
];
1482 /* point bar0 window */
1483 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_BAR0_WIN
, 4, sbaddr
);
1488 uint8 tmp
= (sbaddr
>> 12) & 0x0f;
1489 OSL_PCMCIA_WRITE_ATTR(si
->osh
, PCMCIA_ADDR0
, &tmp
, 1);
1490 tmp
= (sbaddr
>> 16) & 0xff;
1491 OSL_PCMCIA_WRITE_ATTR(si
->osh
, PCMCIA_ADDR1
, &tmp
, 1);
1492 tmp
= (sbaddr
>> 24) & 0xff;
1493 OSL_PCMCIA_WRITE_ATTR(si
->osh
, PCMCIA_ADDR2
, &tmp
, 1);
1501 if (!si
->regs
[coreidx
]) {
1502 si
->regs
[coreidx
] = (void *)(uintptr
)sbaddr
;
1503 ASSERT(GOODREGS(si
->regs
[coreidx
]));
1505 regs
= si
->regs
[coreidx
];
1507 #endif /* BCMJTAG */
1519 * this function changes logical "focus" to the indiciated core,
1520 * must be called with interrupt off.
1521 * Moreover, callers should keep interrupts off during switching out of and back to d11 core
1524 sb_setcore(sb_t
*sbh
, uint coreid
, uint coreunit
)
1528 idx
= sb_findcoreidx(sbh
, coreid
, coreunit
);
1532 return (sb_setcoreidx(sbh
, idx
));
1535 /* return chip number */
1537 BCMINITFN(sb_chip
)(sb_t
*sbh
)
1542 return (si
->sb
.chip
);
1545 /* return chip revision number */
1547 BCMINITFN(sb_chiprev
)(sb_t
*sbh
)
1552 return (si
->sb
.chiprev
);
1555 /* return chip common revision number */
1557 BCMINITFN(sb_chipcrev
)(sb_t
*sbh
)
1562 return (si
->sb
.ccrev
);
1565 /* return chip package option */
1567 BCMINITFN(sb_chippkg
)(sb_t
*sbh
)
1572 return (si
->sb
.chippkg
);
1575 /* return PCI core rev. */
1577 BCMINITFN(sb_pcirev
)(sb_t
*sbh
)
1582 return (si
->sb
.buscorerev
);
1586 BCMINITFN(sb_war16165
)(sb_t
*sbh
)
1592 return (PCI(si
) && (si
->sb
.buscorerev
<= 10));
1596 BCMINITFN(sb_war30841
)(sb_info_t
*si
)
1598 sb_pcie_mdiowrite(si
, MDIODATA_DEV_RX
, SERDES_RX_TIMER1
, 0x8128);
1599 sb_pcie_mdiowrite(si
, MDIODATA_DEV_RX
, SERDES_RX_CDR
, 0x0100);
1600 sb_pcie_mdiowrite(si
, MDIODATA_DEV_RX
, SERDES_RX_CDRBW
, 0x1466);
1603 /* return PCMCIA core rev. */
1605 BCMINITFN(sb_pcmciarev
)(sb_t
*sbh
)
1610 return (si
->sb
.buscorerev
);
1613 /* return board vendor id */
1615 BCMINITFN(sb_boardvendor
)(sb_t
*sbh
)
1620 return (si
->sb
.boardvendor
);
1623 /* return boardtype */
1625 BCMINITFN(sb_boardtype
)(sb_t
*sbh
)
1632 if (BUSTYPE(si
->sb
.bustype
) == SB_BUS
&& si
->sb
.boardtype
== 0xffff) {
1633 /* boardtype format is a hex string */
1634 si
->sb
.boardtype
= getintvar(NULL
, "boardtype");
1636 /* backward compatibility for older boardtype string format */
1637 if ((si
->sb
.boardtype
== 0) && (var
= getvar(NULL
, "boardtype"))) {
1638 if (!strcmp(var
, "bcm94710dev"))
1639 si
->sb
.boardtype
= BCM94710D_BOARD
;
1640 else if (!strcmp(var
, "bcm94710ap"))
1641 si
->sb
.boardtype
= BCM94710AP_BOARD
;
1642 else if (!strcmp(var
, "bu4710"))
1643 si
->sb
.boardtype
= BU4710_BOARD
;
1644 else if (!strcmp(var
, "bcm94702mn"))
1645 si
->sb
.boardtype
= BCM94702MN_BOARD
;
1646 else if (!strcmp(var
, "bcm94710r1"))
1647 si
->sb
.boardtype
= BCM94710R1_BOARD
;
1648 else if (!strcmp(var
, "bcm94710r4"))
1649 si
->sb
.boardtype
= BCM94710R4_BOARD
;
1650 else if (!strcmp(var
, "bcm94702cpci"))
1651 si
->sb
.boardtype
= BCM94702CPCI_BOARD
;
1652 else if (!strcmp(var
, "bcm95380_rr"))
1653 si
->sb
.boardtype
= BCM95380RR_BOARD
;
1657 return (si
->sb
.boardtype
);
1660 /* return bus type of sbh device */
1667 return (si
->sb
.bustype
);
1670 /* return bus core type */
1672 sb_buscoretype(sb_t
*sbh
)
1678 return (si
->sb
.buscoretype
);
1681 /* return bus core revision */
1683 sb_buscorerev(sb_t
*sbh
)
1688 return (si
->sb
.buscorerev
);
1691 /* return list of found cores */
1693 sb_corelist(sb_t
*sbh
, uint coreid
[])
1699 bcopy((uchar
*)si
->coreid
, (uchar
*)coreid
, (si
->numcores
* sizeof(uint
)));
1700 return (si
->numcores
);
1703 /* return current register mapping */
1705 sb_coreregs(sb_t
*sbh
)
1710 ASSERT(GOODREGS(si
->curmap
));
1712 return (si
->curmap
);
1715 #if defined(BCMDBG_ASSERT)
1716 /* traverse all cores to find and clear source of serror */
1718 sb_serr_clear(sb_info_t
*si
)
1722 uint i
, intr_val
= 0;
1723 void * corereg
= NULL
;
1725 INTR_OFF(si
, intr_val
);
1726 origidx
= sb_coreidx(&si
->sb
);
1728 for (i
= 0; i
< si
->numcores
; i
++) {
1729 corereg
= sb_setcoreidx(&si
->sb
, i
);
1730 if (NULL
!= corereg
) {
1731 sb
= REGS2SB(corereg
);
1732 if ((R_SBREG(si
, &sb
->sbtmstatehigh
)) & SBTMH_SERR
) {
1733 AND_SBREG(si
, &sb
->sbtmstatehigh
, ~SBTMH_SERR
);
1734 SB_ERROR(("sb_serr_clear: SError at core 0x%x\n",
1735 sb_coreid(&si
->sb
)));
1740 sb_setcoreidx(&si
->sb
, origidx
);
1741 INTR_RESTORE(si
, intr_val
);
1745 * Check if any inband, outband or timeout errors has happened and clear them.
1746 * Must be called with chip clk on !
1749 sb_taclear(sb_t
*sbh
)
1756 uint32 inband
= 0, serror
= 0, timeout
= 0;
1757 void *corereg
= NULL
;
1758 volatile uint32 imstate
, tmstate
;
1762 if (BUSTYPE(si
->sb
.bustype
) == PCI_BUS
) {
1763 volatile uint32 stcmd
;
1765 /* inband error is Target abort for PCI */
1766 stcmd
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_CFG_CMD
, sizeof(uint32
));
1767 inband
= stcmd
& PCI_CFG_CMD_STAT_TA
;
1769 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_CFG_CMD
, sizeof(uint32
), stcmd
);
1773 stcmd
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_INT_STATUS
, sizeof(uint32
));
1774 serror
= stcmd
& PCI_SBIM_STATUS_SERR
;
1777 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_INT_STATUS
, sizeof(uint32
), stcmd
);
1781 imstate
= sb_corereg(sbh
, si
->sb
.buscoreidx
,
1782 SBCONFIGOFF
+ OFFSETOF(sbconfig_t
, sbimstate
), 0, 0);
1783 if ((imstate
!= 0xffffffff) && (imstate
& (SBIM_IBE
| SBIM_TO
))) {
1784 sb_corereg(sbh
, si
->sb
.buscoreidx
,
1785 SBCONFIGOFF
+ OFFSETOF(sbconfig_t
, sbimstate
), ~0,
1786 (imstate
& ~(SBIM_IBE
| SBIM_TO
)));
1787 /* inband = imstate & SBIM_IBE; same as TA above */
1788 timeout
= imstate
& SBIM_TO
;
1794 /* dump errlog for sonics >= 2.3 */
1795 if (si
->sb
.sonicsrev
== SONICS_2_2
)
1798 uint32 imerrlog
, imerrloga
;
1799 imerrlog
= sb_corereg(sbh
, si
->sb
.buscoreidx
, SBIMERRLOG
, 0, 0);
1800 if (imerrlog
& SBTMEL_EC
) {
1801 imerrloga
= sb_corereg(sbh
, si
->sb
.buscoreidx
, SBIMERRLOGA
,
1804 sb_corereg(sbh
, si
->sb
.buscoreidx
, SBIMERRLOG
, ~0, 0);
1805 SB_ERROR(("sb_taclear: ImErrLog 0x%x, ImErrLogA 0x%x\n",
1806 imerrlog
, imerrloga
));
1812 } else if (BUSTYPE(si
->sb
.bustype
) == PCMCIA_BUS
) {
1814 INTR_OFF(si
, intr_val
);
1815 origidx
= sb_coreidx(sbh
);
1817 corereg
= sb_setcore(sbh
, SB_PCMCIA
, 0);
1818 if (NULL
!= corereg
) {
1819 sb
= REGS2SB(corereg
);
1821 imstate
= R_SBREG(si
, &sb
->sbimstate
);
1822 /* handle surprise removal */
1823 if ((imstate
!= 0xffffffff) && (imstate
& (SBIM_IBE
| SBIM_TO
))) {
1824 AND_SBREG(si
, &sb
->sbimstate
, ~(SBIM_IBE
| SBIM_TO
));
1825 inband
= imstate
& SBIM_IBE
;
1826 timeout
= imstate
& SBIM_TO
;
1828 tmstate
= R_SBREG(si
, &sb
->sbtmstatehigh
);
1829 if ((tmstate
!= 0xffffffff) && (tmstate
& SBTMH_INT_STATUS
)) {
1834 OR_SBREG(si
, &sb
->sbtmstatelow
, SBTML_INT_ACK
);
1835 AND_SBREG(si
, &sb
->sbtmstatelow
, ~SBTML_INT_ACK
);
1838 sb_setcoreidx(sbh
, origidx
);
1839 INTR_RESTORE(si
, intr_val
);
1844 if (inband
| timeout
| serror
) {
1846 SB_ERROR(("sb_taclear: inband 0x%x, serror 0x%x, timeout 0x%x!\n",
1847 inband
, serror
, timeout
));
1854 /* do buffered registers update */
1856 sb_commit(sb_t
*sbh
)
1864 origidx
= si
->curidx
;
1865 ASSERT(GOODIDX(origidx
));
1867 INTR_OFF(si
, intr_val
);
1869 /* switch over to chipcommon core if there is one, else use pci */
1870 if (si
->sb
.ccrev
!= NOREV
) {
1871 chipcregs_t
*ccregs
= (chipcregs_t
*)sb_setcore(sbh
, SB_CC
, 0);
1873 /* do the buffer registers update */
1874 W_REG(si
->osh
, &ccregs
->broadcastaddress
, SB_COMMIT
);
1875 W_REG(si
->osh
, &ccregs
->broadcastdata
, 0x0);
1876 } else if (PCI(si
)) {
1877 sbpciregs_t
*pciregs
= (sbpciregs_t
*)sb_setcore(sbh
, SB_PCI
, 0);
1879 /* do the buffer registers update */
1880 W_REG(si
->osh
, &pciregs
->bcastaddr
, SB_COMMIT
);
1881 W_REG(si
->osh
, &pciregs
->bcastdata
, 0x0);
1885 /* restore core index */
1886 sb_setcoreidx(sbh
, origidx
);
1887 INTR_RESTORE(si
, intr_val
);
1890 /* reset and re-enable a core
1892 * bits - core specific bits that are set during and after reset sequence
1893 * resetbits - core specific bits that are set only during reset sequence
1896 sb_core_reset(sb_t
*sbh
, uint32 bits
, uint32 resetbits
)
1900 volatile uint32 dummy
;
1903 ASSERT(GOODREGS(si
->curmap
));
1904 sb
= REGS2SB(si
->curmap
);
1907 * Must do the disable sequence first to work for arbitrary current core state.
1909 sb_core_disable(sbh
, (bits
| resetbits
));
1912 * Now do the initialization sequence.
1915 /* set reset while enabling the clock and forcing them on throughout the core */
1916 W_SBREG(si
, &sb
->sbtmstatelow
, (SBTML_FGC
| SBTML_CLK
| SBTML_RESET
| bits
| resetbits
));
1917 dummy
= R_SBREG(si
, &sb
->sbtmstatelow
);
1920 if (R_SBREG(si
, &sb
->sbtmstatehigh
) & SBTMH_SERR
) {
1921 W_SBREG(si
, &sb
->sbtmstatehigh
, 0);
1923 if ((dummy
= R_SBREG(si
, &sb
->sbimstate
)) & (SBIM_IBE
| SBIM_TO
)) {
1924 AND_SBREG(si
, &sb
->sbimstate
, ~(SBIM_IBE
| SBIM_TO
));
1927 /* clear reset and allow it to propagate throughout the core */
1928 W_SBREG(si
, &sb
->sbtmstatelow
, (SBTML_FGC
| SBTML_CLK
| bits
));
1929 dummy
= R_SBREG(si
, &sb
->sbtmstatelow
);
1932 /* leave clock enabled */
1933 W_SBREG(si
, &sb
->sbtmstatelow
, (SBTML_CLK
| bits
));
1934 dummy
= R_SBREG(si
, &sb
->sbtmstatelow
);
1939 sb_core_tofixup(sb_t
*sbh
)
1946 if ((BUSTYPE(si
->sb
.bustype
) != PCI_BUS
) || PCIE(si
) ||
1947 (PCI(si
) && (si
->sb
.buscorerev
>= 5)))
1950 ASSERT(GOODREGS(si
->curmap
));
1951 sb
= REGS2SB(si
->curmap
);
1953 if (BUSTYPE(si
->sb
.bustype
) == SB_BUS
) {
1954 SET_SBREG(si
, &sb
->sbimconfiglow
,
1955 SBIMCL_RTO_MASK
| SBIMCL_STO_MASK
,
1956 (0x5 << SBIMCL_RTO_SHIFT
) | 0x3);
1958 if (sb_coreid(sbh
) == SB_PCI
) {
1959 SET_SBREG(si
, &sb
->sbimconfiglow
,
1960 SBIMCL_RTO_MASK
| SBIMCL_STO_MASK
,
1961 (0x3 << SBIMCL_RTO_SHIFT
) | 0x2);
1963 SET_SBREG(si
, &sb
->sbimconfiglow
, (SBIMCL_RTO_MASK
| SBIMCL_STO_MASK
), 0);
1971 * Set the initiator timeout for the "master core".
1972 * The master core is defined to be the core in control
1973 * of the chip and so it issues accesses to non-memory
1974 * locations (Because of dma *any* core can access memeory).
1976 * The routine uses the bus to decide who is the master:
1979 * PCI_BUS => pci or pcie
1980 * PCMCIA_BUS => pcmcia
1981 * SDIO_BUS => pcmcia
1983 * This routine exists so callers can disable initiator
1984 * timeouts so accesses to very slow devices like otp
1985 * won't cause an abort. The routine allows arbitrary
1986 * settings of the service and request timeouts, though.
1988 * Returns the timeout state before changing it or -1
1992 #define TO_MASK (SBIMCL_RTO_MASK | SBIMCL_STO_MASK)
1995 sb_set_initiator_to(sb_t
*sbh
, uint32 to
, uint idx
)
2000 uint32 tmp
, ret
= 0xffffffff;
2005 if ((to
& ~TO_MASK
) != 0)
2008 /* Figure out the master core */
2009 if (idx
== BADIDX
) {
2010 switch (BUSTYPE(si
->sb
.bustype
)) {
2012 idx
= si
->sb
.buscoreidx
;
2018 idx
= sb_findcoreidx(sbh
, SB_PCMCIA
, 0);
2021 idx
= sb_findcoreidx(sbh
, SB_MIPS33
, 0);
2030 INTR_OFF(si
, intr_val
);
2031 origidx
= sb_coreidx(sbh
);
2033 sb
= REGS2SB(sb_setcoreidx(sbh
, idx
));
2035 tmp
= R_SBREG(si
, &sb
->sbimconfiglow
);
2036 ret
= tmp
& TO_MASK
;
2037 W_SBREG(si
, &sb
->sbimconfiglow
, (tmp
& ~TO_MASK
) | to
);
2040 sb_setcoreidx(sbh
, origidx
);
2041 INTR_RESTORE(si
, intr_val
);
2046 sb_core_disable(sb_t
*sbh
, uint32 bits
)
2049 volatile uint32 dummy
;
2055 ASSERT(GOODREGS(si
->curmap
));
2056 sb
= REGS2SB(si
->curmap
);
2058 /* if core is already in reset, just return */
2059 if (R_SBREG(si
, &sb
->sbtmstatelow
) & SBTML_RESET
)
2062 /* reject value changed between sonics 2.2 and 2.3 */
2063 if (si
->sb
.sonicsrev
== SONICS_2_2
)
2064 rej
= (1 << SBTML_REJ_SHIFT
);
2066 rej
= (2 << SBTML_REJ_SHIFT
);
2068 /* if clocks are not enabled, put into reset and return */
2069 if ((R_SBREG(si
, &sb
->sbtmstatelow
) & SBTML_CLK
) == 0)
2072 /* set target reject and spin until busy is clear (preserve core-specific bits) */
2073 OR_SBREG(si
, &sb
->sbtmstatelow
, rej
);
2074 dummy
= R_SBREG(si
, &sb
->sbtmstatelow
);
2076 SPINWAIT((R_SBREG(si
, &sb
->sbtmstatehigh
) & SBTMH_BUSY
), 100000);
2077 if (R_SBREG(si
, &sb
->sbtmstatehigh
) & SBTMH_BUSY
)
2078 SB_ERROR(("%s: target state still busy\n", __FUNCTION__
));
2080 if (R_SBREG(si
, &sb
->sbidlow
) & SBIDL_INIT
) {
2081 OR_SBREG(si
, &sb
->sbimstate
, SBIM_RJ
);
2082 dummy
= R_SBREG(si
, &sb
->sbimstate
);
2084 SPINWAIT((R_SBREG(si
, &sb
->sbimstate
) & SBIM_BY
), 100000);
2087 /* set reset and reject while enabling the clocks */
2088 W_SBREG(si
, &sb
->sbtmstatelow
, (bits
| SBTML_FGC
| SBTML_CLK
| rej
| SBTML_RESET
));
2089 dummy
= R_SBREG(si
, &sb
->sbtmstatelow
);
2092 /* don't forget to clear the initiator reject bit */
2093 if (R_SBREG(si
, &sb
->sbidlow
) & SBIDL_INIT
)
2094 AND_SBREG(si
, &sb
->sbimstate
, ~SBIM_RJ
);
2097 /* leave reset and reject asserted */
2098 W_SBREG(si
, &sb
->sbtmstatelow
, (bits
| rej
| SBTML_RESET
));
2102 /* set chip watchdog reset timer to fire in 'ticks' backplane cycles */
2104 sb_watchdog(sb_t
*sbh
, uint ticks
)
2106 /* make sure we come up in fast clock mode; or if clearing, clear clock */
2108 sb_clkctl_clk(sbh
, CLK_FAST
);
2110 sb_clkctl_clk(sbh
, CLK_DYNAMIC
);
2112 #if defined(BCM4328)
2113 if (sbh
->chip
== BCM4328_CHIP_ID
&& ticks
!= 0)
2114 sb_corereg(sbh
, SB_CC_IDX
, OFFSETOF(chipcregs_t
, min_res_mask
),
2115 PMURES_BIT(RES4328_ROM_SWITCH
),
2116 PMURES_BIT(RES4328_ROM_SWITCH
));
2120 sb_corereg(sbh
, SB_CC_IDX
, OFFSETOF(chipcregs_t
, watchdog
), ~0, ticks
);
2123 /* initialize the pcmcia core */
2125 sb_pcmcia_init(sb_t
*sbh
)
2132 /* enable d11 mac interrupts */
2133 OSL_PCMCIA_READ_ATTR(si
->osh
, PCMCIA_FCR0
+ PCMCIA_COR
, &cor
, 1);
2134 cor
|= COR_IRQEN
| COR_FUNEN
;
2135 OSL_PCMCIA_WRITE_ATTR(si
->osh
, PCMCIA_FCR0
+ PCMCIA_COR
, &cor
, 1);
2141 BCMINITFN(sb_pci_up
)(sb_t
*sbh
)
2147 /* if not pci bus, we're done */
2148 if (BUSTYPE(si
->sb
.bustype
) != PCI_BUS
)
2151 if (FORCEHT_WAR32414(si
))
2152 sb_war32414_forceHT(sbh
, 1);
2154 if (PCIE_ASPMWARS(si
) || si
->sb
.pr42780
)
2155 sb_pcieclkreq(sbh
, 1, 0);
2158 (((si
->sb
.chip
== BCM4311_CHIP_ID
) && (si
->sb
.chiprev
== 2)) ||
2159 ((si
->sb
.chip
== BCM4312_CHIP_ID
) && (si
->sb
.chiprev
== 0))))
2160 sb_set_initiator_to((void *)si
, 0x3, sb_findcoreidx((void *)si
, SB_D11
, 0));
2164 /* Unconfigure and/or apply various WARs when system is going to sleep mode */
2166 BCMUNINITFN(sb_pci_sleep
)(sb_t
*sbh
)
2172 /* if not pci bus, we're done */
2173 if (!PCIE(si
) || !PCIE_ASPMWARS(si
))
2176 w
= OSL_PCI_READ_CONFIG(si
->osh
, si
->pciecap_lcreg_offset
, sizeof(uint32
));
2177 w
&= ~PCIE_CAP_LCREG_ASPML1
;
2178 OSL_PCI_WRITE_CONFIG(si
->osh
, si
->pciecap_lcreg_offset
, sizeof(uint32
), w
);
2181 /* Unconfigure and/or apply various WARs when going down */
2183 BCMINITFN(sb_pci_down
)(sb_t
*sbh
)
2189 /* if not pci bus, we're done */
2190 if (BUSTYPE(si
->sb
.bustype
) != PCI_BUS
)
2193 if (FORCEHT_WAR32414(si
))
2194 sb_war32414_forceHT(sbh
, 0);
2196 if (si
->pr42767_war
) {
2197 sb_pcieclkreq(sbh
, 1, 1);
2198 si
->pr42767_war
= FALSE
;
2199 } else if (si
->sb
.pr42780
) {
2200 sb_pcieclkreq(sbh
, 1, 1);
2205 BCMINITFN(sb_war42767_clkreq
)(sb_t
*sbh
)
2207 sbpcieregs_t
*pcieregs
;
2208 uint16 val16
, *reg16
;
2213 /* if not pcie bus, we're done */
2214 if (!PCIE(si
) || !PCIE_ASPMWARS(si
))
2217 pcieregs
= (sbpcieregs_t
*) sb_setcoreidx(sbh
, si
->sb
.buscoreidx
);
2218 reg16
= &pcieregs
->sprom
[SRSH_CLKREQ_OFFSET
];
2219 val16
= R_REG(si
->osh
, reg16
);
2220 /* if clockreq is not advertized advertize it */
2221 if (!si
->pcie_war_ovr
) {
2222 val16
|= SRSH_CLKREQ_ENB
;
2223 si
->pr42767_war
= TRUE
;
2225 si
->sb
.pr42780
= TRUE
;
2227 val16
&= ~SRSH_CLKREQ_ENB
;
2228 W_REG(si
->osh
, reg16
, val16
);
2232 BCMINITFN(sb_war42767
)(sb_t
*sbh
)
2239 /* if not pcie bus, we're done */
2240 if (!PCIE(si
) || !PCIE_ASPMWARS(si
))
2243 sb_pcie_mdioread(si
, MDIODATA_DEV_PLL
, SERDES_PLL_CTRL
, &w
);
2244 if (w
& PLL_CTRL_FREQDET_EN
) {
2245 w
&= ~PLL_CTRL_FREQDET_EN
;
2246 sb_pcie_mdiowrite(si
, MDIODATA_DEV_PLL
, SERDES_PLL_CTRL
, w
);
2251 * Configure the pci core for pci client (NIC) action
2252 * coremask is the bitvec of cores by index to be enabled.
2255 BCMINITFN(sb_pci_setup
)(sb_t
*sbh
, uint coremask
)
2259 sbpciregs_t
*pciregs
;
2266 /* if not pci bus, we're done */
2267 if (BUSTYPE(si
->sb
.bustype
) != PCI_BUS
)
2270 ASSERT(PCI(si
) || PCIE(si
));
2271 ASSERT(si
->sb
.buscoreidx
!= BADIDX
);
2273 /* get current core index */
2276 /* we interrupt on this backplane flag number */
2277 ASSERT(GOODREGS(si
->curmap
));
2278 sb
= REGS2SB(si
->curmap
);
2279 sbflag
= R_SBREG(si
, &sb
->sbtpsflag
) & SBTPS_NUM0_MASK
;
2281 /* switch over to pci core */
2282 pciregs
= (sbpciregs_t
*) sb_setcoreidx(sbh
, si
->sb
.buscoreidx
);
2283 sb
= REGS2SB(pciregs
);
2286 * Enable sb->pci interrupts. Assume
2287 * PCI rev 2.3 support was added in pci core rev 6 and things changed..
2289 if (PCIE(si
) || (PCI(si
) && ((si
->sb
.buscorerev
) >= 6))) {
2290 /* pci config write to set this core bit in PCIIntMask */
2291 w
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_INT_MASK
, sizeof(uint32
));
2292 w
|= (coremask
<< PCI_SBIM_SHIFT
);
2293 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_INT_MASK
, sizeof(uint32
), w
);
2295 /* set sbintvec bit for our flag number */
2296 OR_SBREG(si
, &sb
->sbintvec
, (1 << sbflag
));
2300 OR_REG(si
->osh
, &pciregs
->sbtopci2
, (SBTOPCI_PREF
|SBTOPCI_BURST
));
2301 if (si
->sb
.buscorerev
>= 11)
2302 OR_REG(si
->osh
, &pciregs
->sbtopci2
, SBTOPCI_RC_READMULTI
);
2303 if (si
->sb
.buscorerev
< 5) {
2304 SET_SBREG(si
, &sb
->sbimconfiglow
, SBIMCL_RTO_MASK
| SBIMCL_STO_MASK
,
2305 (0x3 << SBIMCL_RTO_SHIFT
) | 0x2);
2310 /* PCIE workarounds */
2312 if ((si
->sb
.buscorerev
== 0) || (si
->sb
.buscorerev
== 1)) {
2313 w
= sb_pcie_readreg((void *)(uintptr
)sbh
,
2314 (void *)(uintptr
)PCIE_PCIEREGS
,
2315 PCIE_TLP_WORKAROUNDSREG
);
2317 sb_pcie_writereg((void *)(uintptr
)sbh
,
2318 (void *)(uintptr
)PCIE_PCIEREGS
,
2319 PCIE_TLP_WORKAROUNDSREG
, w
);
2322 if (si
->sb
.buscorerev
== 1) {
2323 w
= sb_pcie_readreg((void *)(uintptr
)sbh
,
2324 (void *)(uintptr
)PCIE_PCIEREGS
,
2327 sb_pcie_writereg((void *)(uintptr
)sbh
,
2328 (void *)(uintptr
)PCIE_PCIEREGS
, PCIE_DLLP_LCREG
, w
);
2331 if (si
->sb
.buscorerev
== 0)
2334 if ((si
->sb
.buscorerev
>= 3) && (si
->sb
.buscorerev
<= 5)) {
2335 w
= sb_pcie_readreg((void *)(uintptr
)sbh
,
2336 (void *)(uintptr
)PCIE_PCIEREGS
,
2337 PCIE_DLLP_PMTHRESHREG
);
2338 w
&= ~(PCIE_L1THRESHOLDTIME_MASK
);
2339 w
|= (PCIE_L1THRESHOLD_WARVAL
<< PCIE_L1THRESHOLDTIME_SHIFT
);
2340 sb_pcie_writereg((void *)(uintptr
)sbh
, (void *)(uintptr
)PCIE_PCIEREGS
,
2341 PCIE_DLLP_PMTHRESHREG
, w
);
2347 sb_war43448_aspm(sbh
);
2348 sb_war42767_clkreq(sbh
);
2352 /* switch back to previous core */
2353 sb_setcoreidx(sbh
, idx
);
2357 sb_base(uint32 admatch
)
2362 type
= admatch
& SBAM_TYPE_MASK
;
2368 base
= admatch
& SBAM_BASE0_MASK
;
2369 } else if (type
== 1) {
2370 ASSERT(!(admatch
& SBAM_ADNEG
)); /* neg not supported */
2371 base
= admatch
& SBAM_BASE1_MASK
;
2372 } else if (type
== 2) {
2373 ASSERT(!(admatch
& SBAM_ADNEG
)); /* neg not supported */
2374 base
= admatch
& SBAM_BASE2_MASK
;
2381 sb_size(uint32 admatch
)
2386 type
= admatch
& SBAM_TYPE_MASK
;
2392 size
= 1 << (((admatch
& SBAM_ADINT0_MASK
) >> SBAM_ADINT0_SHIFT
) + 1);
2393 } else if (type
== 1) {
2394 ASSERT(!(admatch
& SBAM_ADNEG
)); /* neg not supported */
2395 size
= 1 << (((admatch
& SBAM_ADINT1_MASK
) >> SBAM_ADINT1_SHIFT
) + 1);
2396 } else if (type
== 2) {
2397 ASSERT(!(admatch
& SBAM_ADNEG
)); /* neg not supported */
2398 size
= 1 << (((admatch
& SBAM_ADINT2_MASK
) >> SBAM_ADINT2_SHIFT
) + 1);
2404 /* return the core-type instantiation # of the current core */
2406 sb_coreunit(sb_t
*sbh
)
2419 ASSERT(GOODREGS(si
->curmap
));
2420 coreid
= sb_coreid(sbh
);
2422 /* count the cores of our type */
2423 for (i
= 0; i
< idx
; i
++)
2424 if (si
->coreid
[i
] == coreid
)
2431 BCMINITFN(factor6
)(uint32 x
)
2434 case CC_F6_2
: return 2;
2435 case CC_F6_3
: return 3;
2436 case CC_F6_4
: return 4;
2437 case CC_F6_5
: return 5;
2438 case CC_F6_6
: return 6;
2439 case CC_F6_7
: return 7;
2444 /* calculate the speed the SB would run at given a set of clockcontrol values */
2446 BCMINITFN(sb_clock_rate
)(uint32 pll_type
, uint32 n
, uint32 m
)
2448 uint32 n1
, n2
, clock
, m1
, m2
, m3
, mc
;
2450 n1
= n
& CN_N1_MASK
;
2451 n2
= (n
& CN_N2_MASK
) >> CN_N2_SHIFT
;
2453 if (pll_type
== PLL_TYPE6
) {
2454 if (m
& CC_T6_MMASK
)
2458 } else if ((pll_type
== PLL_TYPE1
) ||
2459 (pll_type
== PLL_TYPE3
) ||
2460 (pll_type
== PLL_TYPE4
) ||
2461 (pll_type
== PLL_TYPE7
)) {
2464 } else if (pll_type
== PLL_TYPE2
) {
2467 ASSERT((n1
>= 2) && (n1
<= 7));
2468 ASSERT((n2
>= 5) && (n2
<= 23));
2469 } else if (pll_type
== PLL_TYPE5
) {
2473 /* PLL types 3 and 7 use BASE2 (25Mhz) */
2474 if ((pll_type
== PLL_TYPE3
) ||
2475 (pll_type
== PLL_TYPE7
)) {
2476 clock
= CC_CLOCK_BASE2
* n1
* n2
;
2478 clock
= CC_CLOCK_BASE1
* n1
* n2
;
2483 m1
= m
& CC_M1_MASK
;
2484 m2
= (m
& CC_M2_MASK
) >> CC_M2_SHIFT
;
2485 m3
= (m
& CC_M3_MASK
) >> CC_M3_SHIFT
;
2486 mc
= (m
& CC_MC_MASK
) >> CC_MC_SHIFT
;
2488 if ((pll_type
== PLL_TYPE1
) ||
2489 (pll_type
== PLL_TYPE3
) ||
2490 (pll_type
== PLL_TYPE4
) ||
2491 (pll_type
== PLL_TYPE7
)) {
2493 if ((pll_type
== PLL_TYPE1
) || (pll_type
== PLL_TYPE3
))
2500 case CC_MC_BYPASS
: return (clock
);
2501 case CC_MC_M1
: return (clock
/ m1
);
2502 case CC_MC_M1M2
: return (clock
/ (m1
* m2
));
2503 case CC_MC_M1M2M3
: return (clock
/ (m1
* m2
* m3
));
2504 case CC_MC_M1M3
: return (clock
/ (m1
* m3
));
2505 default: return (0);
2508 ASSERT(pll_type
== PLL_TYPE2
);
2513 ASSERT((m1
>= 2) && (m1
<= 7));
2514 ASSERT((m2
>= 3) && (m2
<= 10));
2515 ASSERT((m3
>= 2) && (m3
<= 7));
2517 if ((mc
& CC_T2MC_M1BYP
) == 0)
2519 if ((mc
& CC_T2MC_M2BYP
) == 0)
2521 if ((mc
& CC_T2MC_M3BYP
) == 0)
2528 /* returns the current speed the SB is running at */
2530 BCMINITFN(sb_clock
)(sb_t
*sbh
)
2536 uint32 pll_type
, rate
;
2541 pll_type
= PLL_TYPE1
;
2543 INTR_OFF(si
, intr_val
);
2545 cc
= (chipcregs_t
*)sb_setcore(sbh
, SB_CC
, 0);
2548 if (sbh
->cccaps
& CC_CAP_PMU
) {
2549 rate
= sb_pmu_cpu_clock(sbh
, si
->osh
);
2553 pll_type
= sbh
->cccaps
& CC_CAP_PLL_MASK
;
2554 n
= R_REG(si
->osh
, &cc
->clockcontrol_n
);
2555 if (pll_type
== PLL_TYPE6
)
2556 m
= R_REG(si
->osh
, &cc
->clockcontrol_m3
);
2557 else if (pll_type
== PLL_TYPE3
)
2558 m
= R_REG(si
->osh
, &cc
->clockcontrol_m2
);
2560 m
= R_REG(si
->osh
, &cc
->clockcontrol_sb
);
2562 if (sb_chip(sbh
) == BCM5365_CHIP_ID
)
2564 rate
= 200000000; /* PLL_TYPE3 */
2566 /* calculate rate */
2567 rate
= sb_clock_rate(pll_type
, n
, m
);
2570 if (pll_type
== PLL_TYPE3
)
2574 /* switch back to previous core */
2575 sb_setcoreidx(sbh
, idx
);
2577 INTR_RESTORE(si
, intr_val
);
2583 BCMINITFN(sb_alp_clock
)(sb_t
*sbh
)
2585 uint32 clock
= ALP_CLOCK
;
2587 if (sbh
->cccaps
& CC_CAP_PMU
)
2588 clock
= sb_pmu_alp_clock(sbh
, sb_osh(sbh
));
2593 /* change logical "focus" to the gpio core for optimized access */
2595 sb_gpiosetcore(sb_t
*sbh
)
2601 return (sb_setcoreidx(sbh
, SB_CC_IDX
));
2604 /* mask&set gpiocontrol bits */
2606 sb_gpiocontrol(sb_t
*sbh
, uint32 mask
, uint32 val
, uint8 priority
)
2614 /* gpios could be shared on router platforms
2615 * ignore reservation if it's high priority (e.g., test apps)
2617 if ((priority
!= GPIO_HI_PRIORITY
) &&
2618 (BUSTYPE(si
->sb
.bustype
) == SB_BUS
) && (val
|| mask
)) {
2619 mask
= priority
? (sb_gpioreservation
& mask
) :
2620 ((sb_gpioreservation
| mask
) & ~(sb_gpioreservation
));
2624 regoff
= OFFSETOF(chipcregs_t
, gpiocontrol
);
2625 return (sb_corereg(sbh
, SB_CC_IDX
, regoff
, mask
, val
));
2628 /* mask&set gpio output enable bits */
2630 sb_gpioouten(sb_t
*sbh
, uint32 mask
, uint32 val
, uint8 priority
)
2638 /* gpios could be shared on router platforms
2639 * ignore reservation if it's high priority (e.g., test apps)
2641 if ((priority
!= GPIO_HI_PRIORITY
) &&
2642 (BUSTYPE(si
->sb
.bustype
) == SB_BUS
) && (val
|| mask
)) {
2643 mask
= priority
? (sb_gpioreservation
& mask
) :
2644 ((sb_gpioreservation
| mask
) & ~(sb_gpioreservation
));
2648 regoff
= OFFSETOF(chipcregs_t
, gpioouten
);
2649 return (sb_corereg(sbh
, SB_CC_IDX
, regoff
, mask
, val
));
2652 /* mask&set gpio output bits */
2654 sb_gpioout(sb_t
*sbh
, uint32 mask
, uint32 val
, uint8 priority
)
2662 /* gpios could be shared on router platforms
2663 * ignore reservation if it's high priority (e.g., test apps)
2665 if ((priority
!= GPIO_HI_PRIORITY
) &&
2666 (BUSTYPE(si
->sb
.bustype
) == SB_BUS
) && (val
|| mask
)) {
2667 mask
= priority
? (sb_gpioreservation
& mask
) :
2668 ((sb_gpioreservation
| mask
) & ~(sb_gpioreservation
));
2672 regoff
= OFFSETOF(chipcregs_t
, gpioout
);
2673 return (sb_corereg(sbh
, SB_CC_IDX
, regoff
, mask
, val
));
2676 /* reserve one gpio */
2678 sb_gpioreserve(sb_t
*sbh
, uint32 gpio_bitmask
, uint8 priority
)
2684 /* only cores on SB_BUS share GPIO's and only applcation users need to
2685 * reserve/release GPIO
2687 if ((BUSTYPE(si
->sb
.bustype
) != SB_BUS
) || (!priority
)) {
2688 ASSERT((BUSTYPE(si
->sb
.bustype
) == SB_BUS
) && (priority
));
2691 /* make sure only one bit is set */
2692 if ((!gpio_bitmask
) || ((gpio_bitmask
) & (gpio_bitmask
- 1))) {
2693 ASSERT((gpio_bitmask
) && !((gpio_bitmask
) & (gpio_bitmask
- 1)));
2697 /* already reserved */
2698 if (sb_gpioreservation
& gpio_bitmask
)
2700 /* set reservation */
2701 sb_gpioreservation
|= gpio_bitmask
;
2703 return sb_gpioreservation
;
2706 /* release one gpio */
2708 * releasing the gpio doesn't change the current value on the GPIO last write value
2709 * persists till some one overwrites it
2713 sb_gpiorelease(sb_t
*sbh
, uint32 gpio_bitmask
, uint8 priority
)
2719 /* only cores on SB_BUS share GPIO's and only applcation users need to
2720 * reserve/release GPIO
2722 if ((BUSTYPE(si
->sb
.bustype
) != SB_BUS
) || (!priority
)) {
2723 ASSERT((BUSTYPE(si
->sb
.bustype
) == SB_BUS
) && (priority
));
2726 /* make sure only one bit is set */
2727 if ((!gpio_bitmask
) || ((gpio_bitmask
) & (gpio_bitmask
- 1))) {
2728 ASSERT((gpio_bitmask
) && !((gpio_bitmask
) & (gpio_bitmask
- 1)));
2732 /* already released */
2733 if (!(sb_gpioreservation
& gpio_bitmask
))
2736 /* clear reservation */
2737 sb_gpioreservation
&= ~gpio_bitmask
;
2739 return sb_gpioreservation
;
2742 /* return the current gpioin register value */
2744 sb_gpioin(sb_t
*sbh
)
2752 regoff
= OFFSETOF(chipcregs_t
, gpioin
);
2753 return (sb_corereg(sbh
, SB_CC_IDX
, regoff
, 0, 0));
2756 /* mask&set gpio interrupt polarity bits */
2758 sb_gpiointpolarity(sb_t
*sbh
, uint32 mask
, uint32 val
, uint8 priority
)
2766 /* gpios could be shared on router platforms */
2767 if ((BUSTYPE(si
->sb
.bustype
) == SB_BUS
) && (val
|| mask
)) {
2768 mask
= priority
? (sb_gpioreservation
& mask
) :
2769 ((sb_gpioreservation
| mask
) & ~(sb_gpioreservation
));
2773 regoff
= OFFSETOF(chipcregs_t
, gpiointpolarity
);
2774 return (sb_corereg(sbh
, SB_CC_IDX
, regoff
, mask
, val
));
2777 /* mask&set gpio interrupt mask bits */
2779 sb_gpiointmask(sb_t
*sbh
, uint32 mask
, uint32 val
, uint8 priority
)
2787 /* gpios could be shared on router platforms */
2788 if ((BUSTYPE(si
->sb
.bustype
) == SB_BUS
) && (val
|| mask
)) {
2789 mask
= priority
? (sb_gpioreservation
& mask
) :
2790 ((sb_gpioreservation
| mask
) & ~(sb_gpioreservation
));
2794 regoff
= OFFSETOF(chipcregs_t
, gpiointmask
);
2795 return (sb_corereg(sbh
, SB_CC_IDX
, regoff
, mask
, val
));
2798 /* assign the gpio to an led */
2800 sb_gpioled(sb_t
*sbh
, uint32 mask
, uint32 val
)
2805 if (si
->sb
.ccrev
< 16)
2808 /* gpio led powersave reg */
2809 return (sb_corereg(sbh
, SB_CC_IDX
, OFFSETOF(chipcregs_t
, gpiotimeroutmask
), mask
, val
));
2812 /* mask&set gpio timer val */
2814 sb_gpiotimerval(sb_t
*sbh
, uint32 mask
, uint32 gpiotimerval
)
2819 if (si
->sb
.ccrev
< 16)
2822 return (sb_corereg(sbh
, SB_CC_IDX
,
2823 OFFSETOF(chipcregs_t
, gpiotimerval
), mask
, gpiotimerval
));
2827 sb_gpiopull(sb_t
*sbh
, bool updown
, uint32 mask
, uint32 val
)
2833 if (si
->sb
.ccrev
< 20)
2836 offs
= (updown
? OFFSETOF(chipcregs_t
, gpiopulldown
) : OFFSETOF(chipcregs_t
, gpiopullup
));
2837 return (sb_corereg(sbh
, SB_CC_IDX
, offs
, mask
, val
));
2841 sb_gpioevent(sb_t
*sbh
, uint regtype
, uint32 mask
, uint32 val
)
2847 if (si
->sb
.ccrev
< 11)
2850 if (regtype
== GPIO_REGEVT
)
2851 offs
= OFFSETOF(chipcregs_t
, gpioevent
);
2852 else if (regtype
== GPIO_REGEVT_INTMSK
)
2853 offs
= OFFSETOF(chipcregs_t
, gpioeventintmask
);
2854 else if (regtype
== GPIO_REGEVT_INTPOL
)
2855 offs
= OFFSETOF(chipcregs_t
, gpioeventintpolarity
);
2859 return (sb_corereg(sbh
, SB_CC_IDX
, offs
, mask
, val
));
2863 BCMINITFN(sb_gpio_handler_register
)(sb_t
*sbh
, uint32 event
,
2864 bool level
, gpio_handler_t cb
, void *arg
)
2873 if (si
->sb
.ccrev
< 11)
2876 if ((gi
= MALLOC(si
->osh
, sizeof(gpioh_item_t
))) == NULL
)
2879 bzero(gi
, sizeof(gpioh_item_t
));
2885 gi
->next
= si
->gpioh_head
;
2886 si
->gpioh_head
= gi
;
2892 BCMINITFN(sb_gpio_handler_unregister
)(sb_t
*sbh
, void* gpioh
)
2895 gpioh_item_t
*p
, *n
;
2898 if (si
->sb
.ccrev
< 11)
2901 ASSERT(si
->gpioh_head
);
2902 if ((void*)si
->gpioh_head
== gpioh
) {
2903 si
->gpioh_head
= si
->gpioh_head
->next
;
2904 MFREE(si
->osh
, gpioh
, sizeof(gpioh_item_t
));
2911 if ((void*)n
== gpioh
) {
2913 MFREE(si
->osh
, gpioh
, sizeof(gpioh_item_t
));
2921 ASSERT(0); /* Not found in list */
2925 sb_gpio_handler_process(sb_t
*sbh
)
2930 uint32 level
= sb_gpioin(sbh
);
2931 uint32 edge
= sb_gpioevent(sbh
, GPIO_REGEVT
, 0, 0);
2934 for (h
= si
->gpioh_head
; h
!= NULL
; h
= h
->next
) {
2936 status
= (h
->level
? level
: edge
);
2938 if (status
& h
->event
)
2939 h
->handler(status
, h
->arg
);
2943 sb_gpioevent(sbh
, GPIO_REGEVT
, edge
, edge
); /* clear edge-trigger status */
2947 sb_gpio_int_enable(sb_t
*sbh
, bool enable
)
2953 if (si
->sb
.ccrev
< 11)
2956 offs
= OFFSETOF(chipcregs_t
, intmask
);
2957 return (sb_corereg(sbh
, SB_CC_IDX
, offs
, CI_GPIO
, (enable
? CI_GPIO
: 0)));
2961 /* return the slow clock source - LPO, XTAL, or PCI */
2963 sb_slowclk_src(sb_info_t
*si
)
2968 ASSERT(sb_coreid(&si
->sb
) == SB_CC
);
2970 if (si
->sb
.ccrev
< 6) {
2971 if ((BUSTYPE(si
->sb
.bustype
) == PCI_BUS
) &&
2972 (OSL_PCI_READ_CONFIG(si
->osh
, PCI_GPIO_OUT
, sizeof(uint32
)) &
2974 return (SCC_SS_PCI
);
2976 return (SCC_SS_XTAL
);
2977 } else if (si
->sb
.ccrev
< 10) {
2978 cc
= (chipcregs_t
*) sb_setcoreidx(&si
->sb
, si
->curidx
);
2979 return (R_REG(si
->osh
, &cc
->slow_clk_ctl
) & SCC_SS_MASK
);
2980 } else /* Insta-clock */
2981 return (SCC_SS_XTAL
);
2984 /* return the ILP (slowclock) min or max frequency */
2986 sb_slowclk_freq(sb_info_t
*si
, bool max_freq
)
2993 ASSERT(sb_coreid(&si
->sb
) == SB_CC
);
2995 cc
= (chipcregs_t
*) sb_setcoreidx(&si
->sb
, si
->curidx
);
2997 /* shouldn't be here unless we've established the chip has dynamic clk control */
2998 ASSERT(R_REG(si
->osh
, &cc
->capabilities
) & CC_CAP_PWR_CTL
);
3000 slowclk
= sb_slowclk_src(si
);
3001 if (si
->sb
.ccrev
< 6) {
3002 if (slowclk
== SCC_SS_PCI
)
3003 return (max_freq
? (PCIMAXFREQ
/ 64) : (PCIMINFREQ
/ 64));
3005 return (max_freq
? (XTALMAXFREQ
/ 32) : (XTALMINFREQ
/ 32));
3006 } else if (si
->sb
.ccrev
< 10) {
3007 div
= 4 * (((R_REG(si
->osh
, &cc
->slow_clk_ctl
) & SCC_CD_MASK
) >> SCC_CD_SHIFT
) + 1);
3008 if (slowclk
== SCC_SS_LPO
)
3009 return (max_freq
? LPOMAXFREQ
: LPOMINFREQ
);
3010 else if (slowclk
== SCC_SS_XTAL
)
3011 return (max_freq
? (XTALMAXFREQ
/ div
) : (XTALMINFREQ
/ div
));
3012 else if (slowclk
== SCC_SS_PCI
)
3013 return (max_freq
? (PCIMAXFREQ
/ div
) : (PCIMINFREQ
/ div
));
3017 /* Chipc rev 10 is InstaClock */
3018 div
= R_REG(si
->osh
, &cc
->system_clk_ctl
) >> SYCC_CD_SHIFT
;
3019 div
= 4 * (div
+ 1);
3020 return (max_freq
? XTALMAXFREQ
: (XTALMINFREQ
/ div
));
3026 BCMINITFN(sb_clkctl_setdelay
)(sb_info_t
*si
, void *chipcregs
)
3029 uint slowmaxfreq
, pll_delay
, slowclk
;
3030 uint pll_on_delay
, fref_sel_delay
;
3032 pll_delay
= PLL_DELAY
;
3034 /* If the slow clock is not sourced by the xtal then add the xtal_on_delay
3035 * since the xtal will also be powered down by dynamic clk control logic.
3038 slowclk
= sb_slowclk_src(si
);
3039 if (slowclk
!= SCC_SS_XTAL
)
3040 pll_delay
+= XTAL_ON_DELAY
;
3042 /* Starting with 4318 it is ILP that is used for the delays */
3043 slowmaxfreq
= sb_slowclk_freq(si
, (si
->sb
.ccrev
>= 10) ? FALSE
: TRUE
);
3045 pll_on_delay
= ((slowmaxfreq
* pll_delay
) + 999999) / 1000000;
3046 fref_sel_delay
= ((slowmaxfreq
* FREF_DELAY
) + 999999) / 1000000;
3048 cc
= (chipcregs_t
*)chipcregs
;
3049 W_REG(si
->osh
, &cc
->pll_on_delay
, pll_on_delay
);
3050 W_REG(si
->osh
, &cc
->fref_sel_delay
, fref_sel_delay
);
3053 /* initialize power control delay registers */
3055 BCMINITFN(sb_clkctl_init
)(sb_t
*sbh
)
3063 origidx
= si
->curidx
;
3065 if ((cc
= (chipcregs_t
*) sb_setcore(sbh
, SB_CC
, 0)) == NULL
)
3068 if ((si
->sb
.chip
== BCM4321_CHIP_ID
) && (si
->sb
.chiprev
< 2))
3069 W_REG(si
->osh
, &cc
->chipcontrol
,
3070 (si
->sb
.chiprev
== 0) ? CHIPCTRL_4321A0_DEFAULT
: CHIPCTRL_4321A1_DEFAULT
);
3072 if (!(R_REG(si
->osh
, &cc
->capabilities
) & CC_CAP_PWR_CTL
))
3075 /* set all Instaclk chip ILP to 1 MHz */
3076 if (si
->sb
.ccrev
>= 10)
3077 SET_REG(si
->osh
, &cc
->system_clk_ctl
, SYCC_CD_MASK
,
3078 (ILP_DIV_1MHZ
<< SYCC_CD_SHIFT
));
3080 sb_clkctl_setdelay(si
, (void *)(uintptr
)cc
);
3083 sb_setcoreidx(sbh
, origidx
);
3086 /* return the value suitable for writing to the dot11 core FAST_PWRUP_DELAY register */
3088 BCMINITFN(sb_clkctl_fast_pwrup_delay
)(sb_t
*sbh
)
3099 origidx
= si
->curidx
;
3101 INTR_OFF(si
, intr_val
);
3103 if ((cc
= (chipcregs_t
*) sb_setcore(sbh
, SB_CC
, 0)) == NULL
)
3106 if (sbh
->cccaps
& CC_CAP_PMU
) {
3107 fpdelay
= sb_pmu_fast_pwrup_delay(sbh
, si
->osh
);
3111 if (!(sbh
->cccaps
& CC_CAP_PWR_CTL
))
3114 slowminfreq
= sb_slowclk_freq(si
, FALSE
);
3115 fpdelay
= (((R_REG(si
->osh
, &cc
->pll_on_delay
) + 2) * 1000000) +
3116 (slowminfreq
- 1)) / slowminfreq
;
3119 sb_setcoreidx(sbh
, origidx
);
3120 INTR_RESTORE(si
, intr_val
);
3124 /* turn primary xtal and/or pll off/on */
3126 sb_clkctl_xtal(sb_t
*sbh
, uint what
, bool on
)
3129 uint32 in
, out
, outen
;
3133 switch (BUSTYPE(si
->sb
.bustype
)) {
3142 /* pcie core doesn't have any mapping to control the xtal pu */
3146 in
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_GPIO_IN
, sizeof(uint32
));
3147 out
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_GPIO_OUT
, sizeof(uint32
));
3148 outen
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_GPIO_OUTEN
, sizeof(uint32
));
3151 * Avoid glitching the clock if GPRS is already using it.
3152 * We can't actually read the state of the PLLPD so we infer it
3153 * by the value of XTAL_PU which *is* readable via gpioin.
3155 if (on
&& (in
& PCI_CFG_GPIO_XTAL
))
3159 outen
|= PCI_CFG_GPIO_XTAL
;
3161 outen
|= PCI_CFG_GPIO_PLL
;
3164 /* turn primary xtal on */
3166 out
|= PCI_CFG_GPIO_XTAL
;
3168 out
|= PCI_CFG_GPIO_PLL
;
3169 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_GPIO_OUT
,
3170 sizeof(uint32
), out
);
3171 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_GPIO_OUTEN
,
3172 sizeof(uint32
), outen
);
3173 OSL_DELAY(XTAL_ON_DELAY
);
3178 out
&= ~PCI_CFG_GPIO_PLL
;
3179 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_GPIO_OUT
,
3180 sizeof(uint32
), out
);
3185 out
&= ~PCI_CFG_GPIO_XTAL
;
3187 out
|= PCI_CFG_GPIO_PLL
;
3188 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_GPIO_OUT
, sizeof(uint32
), out
);
3189 OSL_PCI_WRITE_CONFIG(si
->osh
, PCI_GPIO_OUTEN
, sizeof(uint32
),
3200 /* set dynamic clk control mode (forceslow, forcefast, dynamic) */
3201 /* returns true if we are forcing fast clock */
3203 sb_clkctl_clk(sb_t
*sbh
, uint mode
)
3213 /* chipcommon cores prior to rev6 don't support dynamic clock control */
3214 if (si
->sb
.ccrev
< 6)
3218 /* Chips with ccrev 10 are EOL and they don't have SYCC_HR which we use below */
3219 ASSERT(si
->sb
.ccrev
!= 10);
3221 INTR_OFF(si
, intr_val
);
3223 origidx
= si
->curidx
;
3225 if (sb_setcore(sbh
, SB_MIPS33
, 0) && (sb_corerev(&si
->sb
) <= 7) &&
3226 (BUSTYPE(si
->sb
.bustype
) == SB_BUS
) && (si
->sb
.ccrev
>= 10))
3229 if (FORCEHT_WAR32414(si
))
3232 cc
= (chipcregs_t
*) sb_setcore(sbh
, SB_CC
, 0);
3235 if (!(R_REG(si
->osh
, &cc
->capabilities
) & CC_CAP_PWR_CTL
) && (si
->sb
.ccrev
< 20))
3239 case CLK_FAST
: /* force fast (pll) clock */
3240 if (si
->sb
.ccrev
< 10) {
3241 /* don't forget to force xtal back on before we clear SCC_DYN_XTAL.. */
3242 sb_clkctl_xtal(&si
->sb
, XTAL
, ON
);
3244 SET_REG(si
->osh
, &cc
->slow_clk_ctl
, (SCC_XC
| SCC_FS
| SCC_IP
), SCC_IP
);
3245 } else if (si
->sb
.ccrev
< 20) {
3246 OR_REG(si
->osh
, &cc
->system_clk_ctl
, SYCC_HR
);
3248 OR_REG(si
->osh
, &cc
->clk_ctl_st
, CCS_FORCEHT
);
3251 /* wait for the PLL */
3252 if (R_REG(si
->osh
, &cc
->capabilities
) & CC_CAP_PMU
) {
3253 SPINWAIT(((R_REG(si
->osh
, &cc
->clk_ctl_st
) & CCS_HTAVAIL
) == 0),
3254 PMU_MAX_TRANSITION_DLY
);
3255 ASSERT(R_REG(si
->osh
, &cc
->clk_ctl_st
) & CCS_HTAVAIL
);
3257 OSL_DELAY(PLL_DELAY
);
3261 case CLK_DYNAMIC
: /* enable dynamic clock control */
3262 if (si
->sb
.ccrev
< 10) {
3263 scc
= R_REG(si
->osh
, &cc
->slow_clk_ctl
);
3264 scc
&= ~(SCC_FS
| SCC_IP
| SCC_XC
);
3265 if ((scc
& SCC_SS_MASK
) != SCC_SS_XTAL
)
3267 W_REG(si
->osh
, &cc
->slow_clk_ctl
, scc
);
3269 /* for dynamic control, we have to release our xtal_pu "force on" */
3271 sb_clkctl_xtal(&si
->sb
, XTAL
, OFF
);
3272 } else if (si
->sb
.ccrev
< 20) {
3274 AND_REG(si
->osh
, &cc
->system_clk_ctl
, ~SYCC_HR
);
3276 AND_REG(si
->osh
, &cc
->clk_ctl_st
, ~CCS_FORCEHT
);
3285 sb_setcoreidx(sbh
, origidx
);
3286 INTR_RESTORE(si
, intr_val
);
3287 return (mode
== CLK_FAST
);
3290 /* register driver interrupt disabling and restoring callback functions */
3292 sb_register_intr_callback(sb_t
*sbh
, void *intrsoff_fn
, void *intrsrestore_fn
,
3293 void *intrsenabled_fn
, void *intr_arg
)
3298 si
->intr_arg
= intr_arg
;
3299 si
->intrsoff_fn
= (sb_intrsoff_t
)intrsoff_fn
;
3300 si
->intrsrestore_fn
= (sb_intrsrestore_t
)intrsrestore_fn
;
3301 si
->intrsenabled_fn
= (sb_intrsenabled_t
)intrsenabled_fn
;
3302 /* save current core id. when this function called, the current core
3303 * must be the core which provides driver functions(il, et, wl, etc.)
3305 si
->dev_coreid
= si
->coreid
[si
->curidx
];
3309 sb_deregister_intr_callback(sb_t
*sbh
)
3314 si
->intrsoff_fn
= NULL
;
3319 BCMINITFN(sb_d11_devid
)(sb_t
*sbh
)
3321 sb_info_t
*si
= SB_INFO(sbh
);
3324 #if defined(BCM4328)
3325 /* Fix device id for dual band BCM4328 */
3326 if (sbh
->chip
== BCM4328_CHIP_ID
&&
3327 (sbh
->chippkg
== BCM4328USBDUAL_PKG_ID
|| sbh
->chippkg
== BCM4328SDIODUAL_PKG_ID
))
3328 device
= BCM4328_D11DUAL_ID
;
3330 #endif /* BCM4328 */
3331 /* Let an nvram variable with devpath override devid */
3332 if ((device
= (uint16
)sb_getdevpathintvar(sbh
, "devid")) != 0)
3334 /* Get devid from OTP/SPROM depending on where the SROM is read */
3335 else if ((device
= (uint16
)getintvar(si
->vars
, "devid")) != 0)
3338 * no longer support wl0id, but keep the code
3339 * here for backward compatibility.
3341 else if ((device
= (uint16
)getintvar(si
->vars
, "wl0id")) != 0)
3343 /* Chip specific conversion */
3344 else if (sbh
->chip
== BCM4712_CHIP_ID
) {
3345 if (sbh
->chippkg
== BCM4712SMALL_PKG_ID
)
3346 device
= BCM4306_D11G_ID
;
3348 device
= BCM4306_D11DUAL_ID
;
3358 BCMINITFN(sb_corepciid
)(sb_t
*sbh
, uint func
, uint16
*pcivendor
, uint16
*pcidevice
,
3359 uint8
*pciclass
, uint8
*pcisubclass
, uint8
*pciprogif
,
3362 uint16 vendor
= 0xffff, device
= 0xffff;
3363 uint8
class, subclass
, progif
= 0;
3364 uint8 header
= PCI_HEADER_NORMAL
;
3365 uint32 core
= sb_coreid(sbh
);
3367 /* Verify whether the function exists for the core */
3368 if (func
>= (uint
)(core
== SB_USB20H
? 2 : 1))
3371 /* Known vendor translations */
3372 switch (sb_corevendor(sbh
)) {
3374 vendor
= VENDOR_BROADCOM
;
3380 /* Determine class based on known core codes */
3383 class = PCI_CLASS_NET
;
3384 subclass
= PCI_NET_ETHER
;
3385 device
= BCM47XX_ILINE_ID
;
3388 class = PCI_CLASS_NET
;
3389 subclass
= PCI_NET_ETHER
;
3390 device
= BCM47XX_ENET_ID
;
3393 class = PCI_CLASS_NET
;
3394 subclass
= PCI_NET_ETHER
;
3395 device
= BCM47XX_GIGETH_ID
;
3399 class = PCI_CLASS_MEMORY
;
3400 subclass
= PCI_MEMORY_RAM
;
3401 device
= (uint16
)core
;
3405 class = PCI_CLASS_BRIDGE
;
3406 subclass
= PCI_BRIDGE_PCI
;
3407 device
= (uint16
)core
;
3408 header
= PCI_HEADER_BRIDGE
;
3411 class = PCI_CLASS_CPU
;
3412 subclass
= PCI_CPU_MIPS
;
3413 device
= (uint16
)core
;
3416 class = PCI_CLASS_COMM
;
3417 subclass
= PCI_COMM_MODEM
;
3418 device
= BCM47XX_V90_ID
;
3421 class = PCI_CLASS_SERIAL
;
3422 subclass
= PCI_SERIAL_USB
;
3423 progif
= 0x10; /* OHCI */
3424 device
= BCM47XX_USB_ID
;
3427 class = PCI_CLASS_SERIAL
;
3428 subclass
= PCI_SERIAL_USB
;
3429 progif
= 0x10; /* OHCI */
3430 device
= BCM47XX_USBH_ID
;
3433 class = PCI_CLASS_SERIAL
;
3434 subclass
= PCI_SERIAL_USB
;
3435 progif
= func
== 0 ? 0x10 : 0x20; /* OHCI/EHCI */
3436 device
= BCM47XX_USB20H_ID
;
3437 header
= 0x80; /* multifunction */
3440 class = PCI_CLASS_CRYPT
;
3441 subclass
= PCI_CRYPT_NETWORK
;
3442 device
= BCM47XX_IPSEC_ID
;
3445 class = PCI_CLASS_NET
;
3446 subclass
= PCI_NET_OTHER
;
3447 device
= BCM47XX_ROBO_ID
;
3450 class = PCI_CLASS_MEMORY
;
3451 subclass
= PCI_MEMORY_FLASH
;
3452 device
= (uint16
)core
;
3455 class = PCI_CLASS_XOR
;
3456 subclass
= PCI_XOR_QDMA
;
3457 device
= BCM47XX_SATAXOR_ID
;
3460 class = PCI_CLASS_DASDI
;
3461 subclass
= PCI_DASDI_IDE
;
3462 device
= BCM47XX_ATA100_ID
;
3465 class = PCI_CLASS_SERIAL
;
3466 subclass
= PCI_SERIAL_USB
;
3467 device
= BCM47XX_USBD_ID
;
3470 class = PCI_CLASS_SERIAL
;
3471 subclass
= PCI_SERIAL_USB
;
3472 device
= BCM47XX_USB20D_ID
;
3475 class = PCI_CLASS_NET
;
3476 subclass
= PCI_NET_OTHER
;
3477 device
= sb_d11_devid(sbh
);
3481 class = subclass
= progif
= 0xff;
3482 device
= (uint16
)core
;
3486 *pcivendor
= vendor
;
3487 *pcidevice
= device
;
3489 *pcisubclass
= subclass
;
3490 *pciprogif
= progif
;
3491 *pciheader
= header
;
3496 /* use the mdio interface to read from mdio slaves */
3498 sb_pcie_mdioread(sb_info_t
*si
, uint physmedia
, uint regaddr
, uint
*regval
)
3502 sbpcieregs_t
*pcieregs
;
3504 pcieregs
= (sbpcieregs_t
*) sb_setcoreidx(&si
->sb
, si
->sb
.buscoreidx
);
3507 /* enable mdio access to SERDES */
3508 W_REG(si
->osh
, (&pcieregs
->mdiocontrol
), MDIOCTL_PREAM_EN
| MDIOCTL_DIVISOR_VAL
);
3510 mdiodata
= MDIODATA_START
| MDIODATA_READ
|
3511 (physmedia
<< MDIODATA_DEVADDR_SHF
) |
3512 (regaddr
<< MDIODATA_REGADDR_SHF
) | MDIODATA_TA
;
3514 W_REG(si
->osh
, &pcieregs
->mdiodata
, mdiodata
);
3518 /* retry till the transaction is complete */
3520 if (R_REG(si
->osh
, &(pcieregs
->mdiocontrol
)) & MDIOCTL_ACCESS_DONE
) {
3522 *regval
= (R_REG(si
->osh
, &(pcieregs
->mdiodata
)) & MDIODATA_MASK
);
3523 /* Disable mdio access to SERDES */
3524 W_REG(si
->osh
, (&pcieregs
->mdiocontrol
), 0);
3531 SB_ERROR(("sb_pcie_mdioread: timed out\n"));
3532 /* Disable mdio access to SERDES */
3533 W_REG(si
->osh
, (&pcieregs
->mdiocontrol
), 0);
3538 /* use the mdio interface to write to mdio slaves */
3540 sb_pcie_mdiowrite(sb_info_t
*si
, uint physmedia
, uint regaddr
, uint val
)
3544 sbpcieregs_t
*pcieregs
;
3546 pcieregs
= (sbpcieregs_t
*) sb_setcoreidx(&si
->sb
, si
->sb
.buscoreidx
);
3549 /* enable mdio access to SERDES */
3550 W_REG(si
->osh
, (&pcieregs
->mdiocontrol
), MDIOCTL_PREAM_EN
| MDIOCTL_DIVISOR_VAL
);
3552 mdiodata
= MDIODATA_START
| MDIODATA_WRITE
|
3553 (physmedia
<< MDIODATA_DEVADDR_SHF
) |
3554 (regaddr
<< MDIODATA_REGADDR_SHF
) | MDIODATA_TA
| val
;
3556 W_REG(si
->osh
, (&pcieregs
->mdiodata
), mdiodata
);
3560 /* retry till the transaction is complete */
3562 if (R_REG(si
->osh
, &(pcieregs
->mdiocontrol
)) & MDIOCTL_ACCESS_DONE
) {
3563 /* Disable mdio access to SERDES */
3564 W_REG(si
->osh
, (&pcieregs
->mdiocontrol
), 0);
3571 SB_ERROR(("sb_pcie_mdiowrite: timed out\n"));
3572 /* Disable mdio access to SERDES */
3573 W_REG(si
->osh
, (&pcieregs
->mdiocontrol
), 0);
3578 /* indirect way to read pcie config regs */
3580 sb_pcie_readreg(void *sb
, void* arg1
, uint offset
)
3584 uint retval
= 0xFFFFFFFF;
3585 sbpcieregs_t
*pcieregs
;
3592 pcieregs
= (sbpcieregs_t
*)sb_setcore(sbh
, SB_PCIE
, 0);
3595 addrtype
= (uint
)((uintptr
)arg1
);
3597 case PCIE_CONFIGREGS
:
3598 W_REG(si
->osh
, (&pcieregs
->configaddr
), offset
);
3599 retval
= R_REG(si
->osh
, &(pcieregs
->configdata
));
3602 W_REG(si
->osh
, &(pcieregs
->pcieindaddr
), offset
);
3603 retval
= R_REG(si
->osh
, &(pcieregs
->pcieinddata
));
3612 /* indirect way to write pcie config/mdio/pciecore regs */
3614 sb_pcie_writereg(sb_t
*sbh
, void *arg1
, uint offset
, uint val
)
3617 sbpcieregs_t
*pcieregs
;
3623 pcieregs
= (sbpcieregs_t
*)sb_setcore(sbh
, SB_PCIE
, 0);
3626 addrtype
= (uint
)((uintptr
)arg1
);
3629 case PCIE_CONFIGREGS
:
3630 W_REG(si
->osh
, (&pcieregs
->configaddr
), offset
);
3631 W_REG(si
->osh
, (&pcieregs
->configdata
), val
);
3634 W_REG(si
->osh
, (&pcieregs
->pcieindaddr
), offset
);
3635 W_REG(si
->osh
, (&pcieregs
->pcieinddata
), val
);
3645 /* Build device path. Support SB, PCI, and JTAG for now. */
3647 BCMINITFN(sb_devpath
)(sb_t
*sbh
, char *path
, int size
)
3651 ASSERT(size
>= SB_DEVPATH_BUFSZ
);
3653 if (!path
|| size
<= 0)
3656 switch (BUSTYPE((SB_INFO(sbh
))->sb
.bustype
)) {
3659 slen
= snprintf(path
, (size_t)size
, "sb/%u/", sb_coreidx(sbh
));
3662 ASSERT((SB_INFO(sbh
))->osh
);
3663 slen
= snprintf(path
, (size_t)size
, "pci/%u/%u/",
3664 OSL_PCI_BUS((SB_INFO(sbh
))->osh
),
3665 OSL_PCI_SLOT((SB_INFO(sbh
))->osh
));
3668 SB_ERROR(("sb_devpath: OSL_PCMCIA_BUS() not implemented, bus 1 assumed\n"));
3669 SB_ERROR(("sb_devpath: OSL_PCMCIA_SLOT() not implemented, slot 1 assumed\n"));
3670 slen
= snprintf(path
, (size_t)size
, "pc/1/1/");
3678 if (slen
< 0 || slen
>= size
) {
3686 /* Get a variable, but only if it has a devpath prefix */
3688 BCMINITFN(sb_getdevpathvar
)(sb_t
*sbh
, const char *name
)
3690 char varname
[SB_DEVPATH_BUFSZ
+ 32];
3692 sb_devpathvar(sbh
, varname
, sizeof(varname
), name
);
3694 return (getvar(NULL
, varname
));
3697 /* Get a variable, but only if it has a devpath prefix */
3699 BCMINITFN(sb_getdevpathintvar
)(sb_t
*sbh
, const char *name
)
3701 char varname
[SB_DEVPATH_BUFSZ
+ 32];
3703 sb_devpathvar(sbh
, varname
, sizeof(varname
), name
);
3705 return (getintvar(NULL
, varname
));
3708 /* Concatenate the dev path with a varname into the given 'var' buffer
3709 * and return the 'var' pointer.
3710 * Nothing is done to the arguments if len == 0 or var is NULL, var is still returned.
3711 * On overflow, the first char will be set to '\0'.
3714 BCMINITFN(sb_devpathvar
)(sb_t
*sbh
, char *var
, int len
, const char *name
)
3718 if (!var
|| len
<= 0)
3721 if (sb_devpath(sbh
, var
, len
) == 0) {
3722 path_len
= strlen(var
);
3724 if (strlen(name
) + 1 > (uint
)(len
- path_len
))
3727 strncpy(var
+ path_len
, name
, len
- path_len
- 1);
3735 * Fixup SROMless PCI device's configuration.
3736 * The current core may be changed upon return.
3739 sb_pci_fixcfg(sb_info_t
*si
)
3741 uint origidx
, pciidx
;
3742 sbpciregs_t
*pciregs
;
3743 sbpcieregs_t
*pcieregs
= NULL
;
3744 uint16 val16
, *reg16
;
3747 ASSERT(BUSTYPE(si
->sb
.bustype
) == PCI_BUS
);
3749 /* Fixup PI in SROM shadow area to enable the correct PCI core access */
3750 /* save the current index */
3751 origidx
= sb_coreidx(&si
->sb
);
3753 /* check 'pi' is correct and fix it if not */
3754 if (si
->sb
.buscoretype
== SB_PCIE
) {
3755 pcieregs
= (sbpcieregs_t
*)sb_setcore(&si
->sb
, SB_PCIE
, 0);
3757 reg16
= &pcieregs
->sprom
[SRSH_PI_OFFSET
];
3758 } else if (si
->sb
.buscoretype
== SB_PCI
) {
3759 pciregs
= (sbpciregs_t
*)sb_setcore(&si
->sb
, SB_PCI
, 0);
3761 reg16
= &pciregs
->sprom
[SRSH_PI_OFFSET
];
3766 pciidx
= sb_coreidx(&si
->sb
);
3767 val16
= R_REG(si
->osh
, reg16
);
3768 if (((val16
& SRSH_PI_MASK
) >> SRSH_PI_SHIFT
) != (uint16
)pciidx
) {
3769 val16
= (uint16
)(pciidx
<< SRSH_PI_SHIFT
) | (val16
& ~SRSH_PI_MASK
);
3770 W_REG(si
->osh
, reg16
, val16
);
3773 if (PCIE_ASPMWARS(si
)) {
3774 w
= sb_pcie_readreg((void *)(uintptr
)&si
->sb
, (void *)PCIE_PCIEREGS
,
3775 PCIE_PLP_STATUSREG
);
3777 /* Detect the current polarity at attach and force that polarity and
3778 * disable changing the polarity
3780 if ((w
& PCIE_PLP_POLARITYINV_STAT
) == 0) {
3781 si
->pcie_polarity
= (SERDES_RX_CTRL_FORCE
);
3783 si
->pcie_polarity
= (SERDES_RX_CTRL_FORCE
|
3784 SERDES_RX_CTRL_POLARITY
);
3787 w
= OSL_PCI_READ_CONFIG(si
->osh
, si
->pciecap_lcreg_offset
, sizeof(uint32
));
3788 if (w
& PCIE_CLKREQ_ENAB
) {
3789 reg16
= &pcieregs
->sprom
[SRSH_CLKREQ_OFFSET
];
3790 val16
= R_REG(si
->osh
, reg16
);
3791 /* if clockreq is not advertized clkreq should not be enabled */
3792 if (!(val16
& SRSH_CLKREQ_ENB
))
3793 SB_ERROR(("WARNING: CLK REQ enabled already 0x%x\n", w
));
3796 sb_war43448(&si
->sb
);
3798 sb_war42767(&si
->sb
);
3802 /* restore the original index */
3803 sb_setcoreidx(&si
->sb
, origidx
);
3808 /* Return ADDR64 capability of the backplane */
3810 sb_backplane64(sb_t
*sbh
)
3815 return ((si
->sb
.cccaps
& CC_CAP_BKPLN64
) != 0);
3819 sb_btcgpiowar(sb_t
*sbh
)
3827 /* Make sure that there is ChipCommon core present &&
3828 * UART_TX is strapped to 1
3830 if (!(si
->sb
.cccaps
& CC_CAP_UARTGPIO
))
3833 /* sb_corereg cannot be used as we have to guarantee 8-bit read/writes */
3834 INTR_OFF(si
, intr_val
);
3836 origidx
= sb_coreidx(sbh
);
3838 cc
= (chipcregs_t
*)sb_setcore(sbh
, SB_CC
, 0);
3841 W_REG(si
->osh
, &cc
->uart0mcr
, R_REG(si
->osh
, &cc
->uart0mcr
) | 0x04);
3843 /* restore the original index */
3844 sb_setcoreidx(sbh
, origidx
);
3846 INTR_RESTORE(si
, intr_val
);
3849 /* check if the device is removed */
3851 sb_deviceremoved(sb_t
*sbh
)
3858 switch (BUSTYPE(si
->sb
.bustype
)) {
3861 w
= OSL_PCI_READ_CONFIG(si
->osh
, PCI_CFG_VID
, sizeof(uint32
));
3862 if ((w
& 0xFFFF) != VENDOR_BROADCOM
)
3872 /* Return the RAM size of the SOCRAM core */
3874 BCMINITFN(sb_socram_size
)(sb_t
*sbh
)
3880 sbsocramregs_t
*regs
;
3889 /* Block ints and save current core */
3890 INTR_OFF(si
, intr_val
);
3891 origidx
= sb_coreidx(sbh
);
3893 /* Switch to SOCRAM core */
3894 if (!(regs
= sb_setcore(sbh
, SB_SOCRAM
, 0)))
3897 /* Get info for determining size */
3898 if (!(wasup
= sb_iscoreup(sbh
)))
3899 sb_core_reset(sbh
, 0, 0);
3900 corerev
= sb_corerev(sbh
);
3901 coreinfo
= R_REG(si
->osh
, ®s
->coreinfo
);
3903 /* Calculate size from coreinfo based on rev */
3905 memsize
= 1 << (16 + (coreinfo
& SRCI_MS0_MASK
));
3906 else if (corerev
< 3) {
3907 memsize
= 1 << (SR_BSZ_BASE
+ (coreinfo
& SRCI_SRBSZ_MASK
));
3908 memsize
*= (coreinfo
& SRCI_SRNB_MASK
) >> SRCI_SRNB_SHIFT
;
3911 uint nb
= (coreinfo
& SRCI_SRNB_MASK
) >> SRCI_SRNB_SHIFT
;
3912 uint bsz
= (coreinfo
& SRCI_SRBSZ_MASK
);
3913 uint lss
= (coreinfo
& SRCI_LSS_MASK
) >> SRCI_LSS_SHIFT
;
3916 memsize
= nb
* (1 << (bsz
+ SR_BSZ_BASE
));
3918 memsize
+= (1 << ((lss
- 1) + SR_BSZ_BASE
));
3920 /* Return to previous state and core */
3922 sb_core_disable(sbh
, 0);
3923 sb_setcoreidx(sbh
, origidx
);
3926 INTR_RESTORE(si
, intr_val
);