2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * File contents: support functions for PCI/PCIe
19 #include <linux/delay.h>
20 #include <linux/pci.h>
23 #include <chipcommon.h>
24 #include <brcmu_utils.h>
25 #include <brcm_hw_ids.h>
35 /* slow clock source mask */
36 #define SCC_SS_MASK 0x00000007
37 /* source of slow clock is LPO */
38 #define SCC_SS_LPO 0x00000000
39 /* source of slow clock is crystal */
40 #define SCC_SS_XTAL 0x00000001
41 /* source of slow clock is PCI */
42 #define SCC_SS_PCI 0x00000002
43 /* LPOFreqSel, 1: 160Khz, 0: 32KHz */
44 #define SCC_LF 0x00000200
45 /* LPOPowerDown, 1: LPO is disabled, 0: LPO is enabled */
46 #define SCC_LP 0x00000400
47 /* ForceSlowClk, 1: sb/cores running on slow clock, 0: power logic control */
48 #define SCC_FS 0x00000800
49 /* IgnorePllOffReq, 1/0:
50 * power logic ignores/honors PLL clock disable requests from core
52 #define SCC_IP 0x00001000
53 /* XtalControlEn, 1/0:
54 * power logic does/doesn't disable crystal when appropriate
56 #define SCC_XC 0x00002000
57 /* XtalPU (RO), 1/0: crystal running/disabled */
58 #define SCC_XP 0x00004000
59 /* ClockDivider (SlowClk = 1/(4+divisor)) */
60 #define SCC_CD_MASK 0xffff0000
61 #define SCC_CD_SHIFT 16
64 /* ILPen: Enable Idle Low Power */
65 #define SYCC_IE 0x00000001
66 /* ALPen: Enable Active Low Power */
67 #define SYCC_AE 0x00000002
69 #define SYCC_FP 0x00000004
70 /* Force ALP (or HT if ALPen is not set */
71 #define SYCC_AR 0x00000008
73 #define SYCC_HR 0x00000010
74 /* ClkDiv (ILP = 1/(4 * (divisor + 1)) */
75 #define SYCC_CD_MASK 0xffff0000
76 #define SYCC_CD_SHIFT 16
78 #define CST4329_SPROM_OTP_SEL_MASK 0x00000003
79 /* OTP is powered up, use def. CIS, no SPROM */
80 #define CST4329_DEFCIS_SEL 0
81 /* OTP is powered up, SPROM is present */
82 #define CST4329_SPROM_SEL 1
83 /* OTP is powered up, no SPROM */
84 #define CST4329_OTP_SEL 2
85 /* OTP is powered down, SPROM is present */
86 #define CST4329_OTP_PWRDN 3
88 #define CST4329_SPI_SDIO_MODE_MASK 0x00000004
89 #define CST4329_SPI_SDIO_MODE_SHIFT 2
91 /* 43224 chip-specific ChipControl register bits */
92 #define CCTRL43224_GPIO_TOGGLE 0x8000
93 /* 12 mA drive strength */
94 #define CCTRL_43224A0_12MA_LED_DRIVE 0x00F000F0
95 /* 12 mA drive strength for later 43224s */
96 #define CCTRL_43224B0_12MA_LED_DRIVE 0xF0
98 /* 43236 Chip specific ChipStatus register bits */
99 #define CST43236_SFLASH_MASK 0x00000040
100 #define CST43236_OTP_MASK 0x00000080
101 #define CST43236_HSIC_MASK 0x00000100 /* USB/HSIC */
102 #define CST43236_BP_CLK 0x00000200 /* 120/96Mbps */
103 #define CST43236_BOOT_MASK 0x00001800
104 #define CST43236_BOOT_SHIFT 11
105 #define CST43236_BOOT_FROM_SRAM 0 /* boot from SRAM, ARM in reset */
106 #define CST43236_BOOT_FROM_ROM 1 /* boot from ROM */
107 #define CST43236_BOOT_FROM_FLASH 2 /* boot from FLASH */
108 #define CST43236_BOOT_FROM_INVALID 3
110 /* 4331 chip-specific ChipControl register bits */
112 #define CCTRL4331_BT_COEXIST (1<<0)
113 /* 0 SECI is disabled (JTAG functional) */
114 #define CCTRL4331_SECI (1<<1)
116 #define CCTRL4331_EXT_LNA (1<<2)
117 /* sprom/gpio13-15 mux */
118 #define CCTRL4331_SPROM_GPIO13_15 (1<<3)
119 /* 0 ext pa disable, 1 ext pa enabled */
120 #define CCTRL4331_EXTPA_EN (1<<4)
121 /* set drive out GPIO_CLK on sprom_cs pin */
122 #define CCTRL4331_GPIOCLK_ON_SPROMCS (1<<5)
123 /* use sprom_cs pin as PCIE mdio interface */
124 #define CCTRL4331_PCIE_MDIO_ON_SPROMCS (1<<6)
125 /* aband extpa will be at gpio2/5 and sprom_dout */
126 #define CCTRL4331_EXTPA_ON_GPIO2_5 (1<<7)
127 /* override core control on pipe_AuxClkEnable */
128 #define CCTRL4331_OVR_PIPEAUXCLKEN (1<<8)
129 /* override core control on pipe_AuxPowerDown */
130 #define CCTRL4331_OVR_PIPEAUXPWRDOWN (1<<9)
131 /* pcie_auxclkenable */
132 #define CCTRL4331_PCIE_AUXCLKEN (1<<10)
133 /* pcie_pipe_pllpowerdown */
134 #define CCTRL4331_PCIE_PIPE_PLLDOWN (1<<11)
135 /* enable bt_shd0 at gpio4 */
136 #define CCTRL4331_BT_SHD0_ON_GPIO4 (1<<16)
137 /* enable bt_shd1 at gpio5 */
138 #define CCTRL4331_BT_SHD1_ON_GPIO5 (1<<17)
140 /* 4331 Chip specific ChipStatus register bits */
141 /* crystal frequency 20/40Mhz */
142 #define CST4331_XTAL_FREQ 0x00000001
143 #define CST4331_SPROM_PRESENT 0x00000002
144 #define CST4331_OTP_PRESENT 0x00000004
145 #define CST4331_LDO_RF 0x00000008
146 #define CST4331_LDO_PAR 0x00000010
148 /* 4319 chip-specific ChipStatus register bits */
149 #define CST4319_SPI_CPULESSUSB 0x00000001
150 #define CST4319_SPI_CLK_POL 0x00000002
151 #define CST4319_SPI_CLK_PH 0x00000008
152 /* gpio [7:6], SDIO CIS selection */
153 #define CST4319_SPROM_OTP_SEL_MASK 0x000000c0
154 #define CST4319_SPROM_OTP_SEL_SHIFT 6
155 /* use default CIS, OTP is powered up */
156 #define CST4319_DEFCIS_SEL 0x00000000
157 /* use SPROM, OTP is powered up */
158 #define CST4319_SPROM_SEL 0x00000040
159 /* use OTP, OTP is powered up */
160 #define CST4319_OTP_SEL 0x00000080
161 /* use SPROM, OTP is powered down */
162 #define CST4319_OTP_PWRDN 0x000000c0
163 /* gpio [8], sdio/usb mode */
164 #define CST4319_SDIO_USB_MODE 0x00000100
165 #define CST4319_REMAP_SEL_MASK 0x00000600
166 #define CST4319_ILPDIV_EN 0x00000800
167 #define CST4319_XTAL_PD_POL 0x00001000
168 #define CST4319_LPO_SEL 0x00002000
169 #define CST4319_RES_INIT_MODE 0x0000c000
170 /* PALDO is configured with external PNP */
171 #define CST4319_PALDO_EXTPNP 0x00010000
172 #define CST4319_CBUCK_MODE_MASK 0x00060000
173 #define CST4319_CBUCK_MODE_BURST 0x00020000
174 #define CST4319_CBUCK_MODE_LPBURST 0x00060000
175 #define CST4319_RCAL_VALID 0x01000000
176 #define CST4319_RCAL_VALUE_MASK 0x3e000000
177 #define CST4319_RCAL_VALUE_SHIFT 25
179 /* 4336 chip-specific ChipStatus register bits */
180 #define CST4336_SPI_MODE_MASK 0x00000001
181 #define CST4336_SPROM_PRESENT 0x00000002
182 #define CST4336_OTP_PRESENT 0x00000004
183 #define CST4336_ARMREMAP_0 0x00000008
184 #define CST4336_ILPDIV_EN_MASK 0x00000010
185 #define CST4336_ILPDIV_EN_SHIFT 4
186 #define CST4336_XTAL_PD_POL_MASK 0x00000020
187 #define CST4336_XTAL_PD_POL_SHIFT 5
188 #define CST4336_LPO_SEL_MASK 0x00000040
189 #define CST4336_LPO_SEL_SHIFT 6
190 #define CST4336_RES_INIT_MODE_MASK 0x00000180
191 #define CST4336_RES_INIT_MODE_SHIFT 7
192 #define CST4336_CBUCK_MODE_MASK 0x00000600
193 #define CST4336_CBUCK_MODE_SHIFT 9
195 /* 4313 chip-specific ChipStatus register bits */
196 #define CST4313_SPROM_PRESENT 1
197 #define CST4313_OTP_PRESENT 2
198 #define CST4313_SPROM_OTP_SEL_MASK 0x00000002
199 #define CST4313_SPROM_OTP_SEL_SHIFT 0
201 /* 4313 Chip specific ChipControl register bits */
202 /* 12 mA drive strengh for later 4313 */
203 #define CCTRL_4313_12MA_LED_DRIVE 0x00000007
205 /* Manufacturer Ids */
206 #define MFGID_ARM 0x43b
207 #define MFGID_BRCM 0x4bf
208 #define MFGID_MIPS 0x4a7
210 /* Enumeration ROM registers */
211 #define ER_EROMENTRY 0x000
212 #define ER_REMAPCONTROL 0xe00
213 #define ER_REMAPSELECT 0xe04
214 #define ER_MASTERSELECT 0xe10
215 #define ER_ITCR 0xf00
216 #define ER_ITIP 0xf04
226 #define ER_BAD 0xffffffff
228 /* EROM CompIdentA */
229 #define CIA_MFG_MASK 0xfff00000
230 #define CIA_MFG_SHIFT 20
231 #define CIA_CID_MASK 0x000fff00
232 #define CIA_CID_SHIFT 8
233 #define CIA_CCL_MASK 0x000000f0
234 #define CIA_CCL_SHIFT 4
236 /* EROM CompIdentB */
237 #define CIB_REV_MASK 0xff000000
238 #define CIB_REV_SHIFT 24
239 #define CIB_NSW_MASK 0x00f80000
240 #define CIB_NSW_SHIFT 19
241 #define CIB_NMW_MASK 0x0007c000
242 #define CIB_NMW_SHIFT 14
243 #define CIB_NSP_MASK 0x00003e00
244 #define CIB_NSP_SHIFT 9
245 #define CIB_NMP_MASK 0x000001f0
246 #define CIB_NMP_SHIFT 4
249 #define AD_ADDR_MASK 0xfffff000
250 #define AD_SP_MASK 0x00000f00
251 #define AD_SP_SHIFT 8
252 #define AD_ST_MASK 0x000000c0
253 #define AD_ST_SHIFT 6
254 #define AD_ST_SLAVE 0x00000000
255 #define AD_ST_BRIDGE 0x00000040
256 #define AD_ST_SWRAP 0x00000080
257 #define AD_ST_MWRAP 0x000000c0
258 #define AD_SZ_MASK 0x00000030
259 #define AD_SZ_SHIFT 4
260 #define AD_SZ_4K 0x00000000
261 #define AD_SZ_8K 0x00000010
262 #define AD_SZ_16K 0x00000020
263 #define AD_SZ_SZD 0x00000030
264 #define AD_AG32 0x00000008
265 #define AD_ADDR_ALIGN 0x00000fff
266 #define AD_SZ_BASE 0x00001000 /* 4KB */
269 #define SD_SZ_MASK 0xfffff000
270 #define SD_SG32 0x00000008
271 #define SD_SZ_ALIGN 0x00000fff
273 /* PCI config space bit 4 for 4306c0 slow clock source */
274 #define PCI_CFG_GPIO_SCS 0x10
275 /* PCI config space GPIO 14 for Xtal power-up */
276 #define PCI_CFG_GPIO_XTAL 0x40
277 /* PCI config space GPIO 15 for PLL power-down */
278 #define PCI_CFG_GPIO_PLL 0x80
280 /* power control defines */
281 #define PLL_DELAY 150 /* us pll on delay */
282 #define FREF_DELAY 200 /* us fref change delay */
283 #define XTAL_ON_DELAY 1000 /* us crystal power-on delay */
288 #define NOREV -1 /* Invalid rev */
290 /* GPIO Based LED powersave defines */
291 #define DEFAULT_GPIO_ONTIME 10 /* Default: 10% on */
292 #define DEFAULT_GPIO_OFFTIME 90 /* Default: 10% on */
294 /* When Srom support present, fields in sromcontrol */
295 #define SRC_START 0x80000000
296 #define SRC_BUSY 0x80000000
297 #define SRC_OPCODE 0x60000000
298 #define SRC_OP_READ 0x00000000
299 #define SRC_OP_WRITE 0x20000000
300 #define SRC_OP_WRDIS 0x40000000
301 #define SRC_OP_WREN 0x60000000
302 #define SRC_OTPSEL 0x00000010
303 #define SRC_LOCK 0x00000008
304 #define SRC_SIZE_MASK 0x00000006
305 #define SRC_SIZE_1K 0x00000000
306 #define SRC_SIZE_4K 0x00000002
307 #define SRC_SIZE_16K 0x00000004
308 #define SRC_SIZE_SHIFT 1
309 #define SRC_PRESENT 0x00000001
311 /* External PA enable mask */
312 #define GPIO_CTRL_EPA_EN_MASK 0x40
314 #define DEFAULT_GPIOTIMERVAL \
315 ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
317 #define BADIDX (SI_MAXCORES + 1)
319 /* Newer chips can access PCI/PCIE and CC core without requiring to change
322 #define SI_FAST(si) (((si)->pub.buscoretype == PCIE_CORE_ID) || \
323 (((si)->pub.buscoretype == PCI_CORE_ID) && \
324 (si)->pub.buscorerev >= 13))
326 #define CCREGS_FAST(si) (((char __iomem *)((si)->curmap) + \
327 PCI_16KB0_CCREGS_OFFSET))
329 #define IS_SIM(chippkg) \
330 ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
333 * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts
334 * before after core switching to avoid invalid register accesss inside ISR.
336 #define INTR_OFF(si, intr_val) \
337 if ((si)->intrsoff_fn && \
338 (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
339 intr_val = (*(si)->intrsoff_fn)((si)->intr_arg)
341 #define INTR_RESTORE(si, intr_val) \
342 if ((si)->intrsrestore_fn && \
343 (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
344 (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val)
346 #define PCI(si) ((si)->pub.buscoretype == PCI_CORE_ID)
347 #define PCIE(si) ((si)->pub.buscoretype == PCIE_CORE_ID)
349 #define PCI_FORCEHT(si) (PCIE(si) && (si->pub.chip == BCM4716_CHIP_ID))
352 #define SI_MSG(args) printk args
357 #define GOODCOREADDR(x, b) \
358 (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
359 IS_ALIGNED((x), SI_CORE_SIZE))
361 #define PCIEREGS(si) ((__iomem char *)((si)->curmap) + \
362 PCI_16KB0_PCIREGS_OFFSET)
365 u32 oobselina30
; /* 0x000 */
366 u32 oobselina74
; /* 0x004 */
368 u32 oobselinb30
; /* 0x020 */
369 u32 oobselinb74
; /* 0x024 */
371 u32 oobselinc30
; /* 0x040 */
372 u32 oobselinc74
; /* 0x044 */
374 u32 oobselind30
; /* 0x060 */
375 u32 oobselind74
; /* 0x064 */
377 u32 oobselouta30
; /* 0x100 */
378 u32 oobselouta74
; /* 0x104 */
380 u32 oobseloutb30
; /* 0x120 */
381 u32 oobseloutb74
; /* 0x124 */
383 u32 oobseloutc30
; /* 0x140 */
384 u32 oobseloutc74
; /* 0x144 */
386 u32 oobseloutd30
; /* 0x160 */
387 u32 oobseloutd74
; /* 0x164 */
389 u32 oobsynca
; /* 0x200 */
390 u32 oobseloutaen
; /* 0x204 */
392 u32 oobsyncb
; /* 0x220 */
393 u32 oobseloutben
; /* 0x224 */
395 u32 oobsyncc
; /* 0x240 */
396 u32 oobseloutcen
; /* 0x244 */
398 u32 oobsyncd
; /* 0x260 */
399 u32 oobseloutden
; /* 0x264 */
401 u32 oobaextwidth
; /* 0x300 */
402 u32 oobainwidth
; /* 0x304 */
403 u32 oobaoutwidth
; /* 0x308 */
405 u32 oobbextwidth
; /* 0x320 */
406 u32 oobbinwidth
; /* 0x324 */
407 u32 oobboutwidth
; /* 0x328 */
409 u32 oobcextwidth
; /* 0x340 */
410 u32 oobcinwidth
; /* 0x344 */
411 u32 oobcoutwidth
; /* 0x348 */
413 u32 oobdextwidth
; /* 0x360 */
414 u32 oobdinwidth
; /* 0x364 */
415 u32 oobdoutwidth
; /* 0x368 */
417 u32 ioctrlset
; /* 0x400 */
418 u32 ioctrlclear
; /* 0x404 */
419 u32 ioctrl
; /* 0x408 */
421 u32 iostatus
; /* 0x500 */
423 u32 ioctrlwidth
; /* 0x700 */
424 u32 iostatuswidth
; /* 0x704 */
426 u32 resetctrl
; /* 0x800 */
427 u32 resetstatus
; /* 0x804 */
428 u32 resetreadid
; /* 0x808 */
429 u32 resetwriteid
; /* 0x80c */
431 u32 errlogctrl
; /* 0x900 */
432 u32 errlogdone
; /* 0x904 */
433 u32 errlogstatus
; /* 0x908 */
434 u32 errlogaddrlo
; /* 0x90c */
435 u32 errlogaddrhi
; /* 0x910 */
436 u32 errlogid
; /* 0x914 */
437 u32 errloguser
; /* 0x918 */
438 u32 errlogflags
; /* 0x91c */
440 u32 intstatus
; /* 0xa00 */
442 u32 config
; /* 0xe00 */
444 u32 itcr
; /* 0xf00 */
446 u32 itipooba
; /* 0xf10 */
447 u32 itipoobb
; /* 0xf14 */
448 u32 itipoobc
; /* 0xf18 */
449 u32 itipoobd
; /* 0xf1c */
451 u32 itipoobaout
; /* 0xf30 */
452 u32 itipoobbout
; /* 0xf34 */
453 u32 itipoobcout
; /* 0xf38 */
454 u32 itipoobdout
; /* 0xf3c */
456 u32 itopooba
; /* 0xf50 */
457 u32 itopoobb
; /* 0xf54 */
458 u32 itopoobc
; /* 0xf58 */
459 u32 itopoobd
; /* 0xf5c */
461 u32 itopoobain
; /* 0xf70 */
462 u32 itopoobbin
; /* 0xf74 */
463 u32 itopoobcin
; /* 0xf78 */
464 u32 itopoobdin
; /* 0xf7c */
466 u32 itopreset
; /* 0xf90 */
468 u32 peripherialid4
; /* 0xfd0 */
469 u32 peripherialid5
; /* 0xfd4 */
470 u32 peripherialid6
; /* 0xfd8 */
471 u32 peripherialid7
; /* 0xfdc */
472 u32 peripherialid0
; /* 0xfe0 */
473 u32 peripherialid1
; /* 0xfe4 */
474 u32 peripherialid2
; /* 0xfe8 */
475 u32 peripherialid3
; /* 0xfec */
476 u32 componentid0
; /* 0xff0 */
477 u32 componentid1
; /* 0xff4 */
478 u32 componentid2
; /* 0xff8 */
479 u32 componentid3
; /* 0xffc */
485 get_erom_ent(struct si_pub
*sih
, u32 __iomem
**eromptr
, u32 mask
, u32 match
)
488 uint inv
= 0, nom
= 0;
491 ent
= R_REG(*eromptr
);
497 if ((ent
& ER_VALID
) == 0) {
502 if (ent
== (ER_END
| ER_VALID
))
505 if ((ent
& mask
) == match
)
515 get_asd(struct si_pub
*sih
, u32 __iomem
**eromptr
, uint sp
, uint ad
, uint st
,
516 u32
*addrl
, u32
*addrh
, u32
*sizel
, u32
*sizeh
)
520 asd
= get_erom_ent(sih
, eromptr
, ER_VALID
, ER_VALID
);
521 if (((asd
& ER_TAG1
) != ER_ADD
) ||
522 (((asd
& AD_SP_MASK
) >> AD_SP_SHIFT
) != sp
) ||
523 ((asd
& AD_ST_MASK
) != st
)) {
524 /* This is not what we want, "push" it back */
528 *addrl
= asd
& AD_ADDR_MASK
;
530 *addrh
= get_erom_ent(sih
, eromptr
, 0, 0);
534 sz
= asd
& AD_SZ_MASK
;
535 if (sz
== AD_SZ_SZD
) {
536 szd
= get_erom_ent(sih
, eromptr
, 0, 0);
537 *sizel
= szd
& SD_SZ_MASK
;
539 *sizeh
= get_erom_ent(sih
, eromptr
, 0, 0);
541 *sizel
= AD_SZ_BASE
<< (sz
>> AD_SZ_SHIFT
);
546 static void ai_hwfixup(struct si_info
*sii
)
550 /* parse the enumeration rom to identify all cores */
551 static void ai_scan(struct si_pub
*sih
, struct chipcregs __iomem
*cc
)
553 struct si_info
*sii
= (struct si_info
*)sih
;
556 u32 __iomem
*eromptr
, *eromlim
;
557 void __iomem
*regs
= cc
;
559 erombase
= R_REG(&cc
->eromptr
);
561 /* Set wrappers address */
562 sii
->curwrap
= (void *)((unsigned long)cc
+ SI_CORE_SIZE
);
564 /* Now point the window at the erom */
565 pci_write_config_dword(sii
->pbus
, PCI_BAR0_WIN
, erombase
);
567 eromlim
= eromptr
+ (ER_REMAPCONTROL
/ sizeof(u32
));
569 while (eromptr
< eromlim
) {
570 u32 cia
, cib
, cid
, mfg
, crev
, nmw
, nsw
, nmp
, nsp
;
571 u32 mpd
, asd
, addrl
, addrh
, sizel
, sizeh
;
578 /* Grok a component */
579 cia
= get_erom_ent(sih
, &eromptr
, ER_TAG
, ER_CI
);
580 if (cia
== (ER_END
| ER_VALID
)) {
581 /* Found END of erom */
586 cib
= get_erom_ent(sih
, &eromptr
, 0, 0);
588 if ((cib
& ER_TAG
) != ER_CI
) {
589 /* CIA not followed by CIB */
593 cid
= (cia
& CIA_CID_MASK
) >> CIA_CID_SHIFT
;
594 mfg
= (cia
& CIA_MFG_MASK
) >> CIA_MFG_SHIFT
;
595 crev
= (cib
& CIB_REV_MASK
) >> CIB_REV_SHIFT
;
596 nmw
= (cib
& CIB_NMW_MASK
) >> CIB_NMW_SHIFT
;
597 nsw
= (cib
& CIB_NSW_MASK
) >> CIB_NSW_SHIFT
;
598 nmp
= (cib
& CIB_NMP_MASK
) >> CIB_NMP_SHIFT
;
599 nsp
= (cib
& CIB_NSP_MASK
) >> CIB_NSP_SHIFT
;
601 if (((mfg
== MFGID_ARM
) && (cid
== DEF_AI_COMP
)) || (nsp
== 0))
603 if ((nmw
+ nsw
== 0)) {
604 /* A component which is not a core */
605 if (cid
== OOB_ROUTER_CORE_ID
) {
606 asd
= get_asd(sih
, &eromptr
, 0, 0, AD_ST_SLAVE
,
607 &addrl
, &addrh
, &sizel
, &sizeh
);
609 sii
->oob_router
= addrl
;
615 /* sii->eromptr[idx] = base; */
618 sii
->coreid
[idx
] = cid
;
620 for (i
= 0; i
< nmp
; i
++) {
621 mpd
= get_erom_ent(sih
, &eromptr
, ER_VALID
, ER_VALID
);
622 if ((mpd
& ER_TAG
) != ER_MP
) {
623 /* Not enough MP entries for component */
628 /* First Slave Address Descriptor should be port 0:
629 * the main register space for the core
632 get_asd(sih
, &eromptr
, 0, 0, AD_ST_SLAVE
, &addrl
, &addrh
,
635 /* Try again to see if it is a bridge */
637 get_asd(sih
, &eromptr
, 0, 0, AD_ST_BRIDGE
, &addrl
,
638 &addrh
, &sizel
, &sizeh
);
641 else if ((addrh
!= 0) || (sizeh
!= 0)
642 || (sizel
!= SI_CORE_SIZE
)) {
643 /* First Slave ASD for core malformed */
647 sii
->coresba
[idx
] = addrl
;
648 sii
->coresba_size
[idx
] = sizel
;
649 /* Get any more ASDs in port 0 */
653 get_asd(sih
, &eromptr
, 0, j
, AD_ST_SLAVE
, &addrl
,
654 &addrh
, &sizel
, &sizeh
);
655 if ((asd
!= 0) && (j
== 1) && (sizel
== SI_CORE_SIZE
)) {
656 sii
->coresba2
[idx
] = addrl
;
657 sii
->coresba2_size
[idx
] = sizel
;
662 /* Go through the ASDs for other slave ports */
663 for (i
= 1; i
< nsp
; i
++) {
667 get_asd(sih
, &eromptr
, i
, j
++, AD_ST_SLAVE
,
668 &addrl
, &addrh
, &sizel
, &sizeh
);
671 /* SP has no address descriptors */
676 /* Now get master wrappers */
677 for (i
= 0; i
< nmw
; i
++) {
679 get_asd(sih
, &eromptr
, i
, 0, AD_ST_MWRAP
, &addrl
,
680 &addrh
, &sizel
, &sizeh
);
682 /* Missing descriptor for MW */
685 if ((sizeh
!= 0) || (sizel
!= SI_CORE_SIZE
)) {
686 /* Master wrapper %d is not 4KB */
690 sii
->wrapba
[idx
] = addrl
;
693 /* And finally slave wrappers */
694 for (i
= 0; i
< nsw
; i
++) {
695 uint fwp
= (nsp
== 1) ? 0 : 1;
697 get_asd(sih
, &eromptr
, fwp
+ i
, 0, AD_ST_SWRAP
,
698 &addrl
, &addrh
, &sizel
, &sizeh
);
700 /* Missing descriptor for SW */
703 if ((sizeh
!= 0) || (sizel
!= SI_CORE_SIZE
)) {
704 /* Slave wrapper is not 4KB */
707 if ((nmw
== 0) && (i
== 0))
708 sii
->wrapba
[idx
] = addrl
;
711 /* Don't record bridges */
720 /* Reached end of erom without finding END */
726 * This function changes the logical "focus" to the indicated core.
727 * Return the current core's virtual address. Since each core starts with the
728 * same set of registers (BIST, clock control, etc), the returned address
729 * contains the first register of this 'common' register block (not to be
730 * confused with 'common core').
732 void __iomem
*ai_setcoreidx(struct si_pub
*sih
, uint coreidx
)
734 struct si_info
*sii
= (struct si_info
*)sih
;
735 u32 addr
= sii
->coresba
[coreidx
];
736 u32 wrap
= sii
->wrapba
[coreidx
];
738 if (coreidx
>= sii
->numcores
)
741 /* point bar0 window */
742 pci_write_config_dword(sii
->pbus
, PCI_BAR0_WIN
, addr
);
743 /* point bar0 2nd 4KB window */
744 pci_write_config_dword(sii
->pbus
, PCI_BAR0_WIN2
, wrap
);
745 sii
->curidx
= coreidx
;
750 /* Return the number of address spaces in current core */
751 int ai_numaddrspaces(struct si_pub
*sih
)
756 /* Return the address of the nth address space in the current core */
757 u32
ai_addrspace(struct si_pub
*sih
, uint asidx
)
762 sii
= (struct si_info
*)sih
;
766 return sii
->coresba
[cidx
];
768 return sii
->coresba2
[cidx
];
770 /* Need to parse the erom again to find addr space */
775 /* Return the size of the nth address space in the current core */
776 u32
ai_addrspacesize(struct si_pub
*sih
, uint asidx
)
781 sii
= (struct si_info
*)sih
;
785 return sii
->coresba_size
[cidx
];
787 return sii
->coresba2_size
[cidx
];
789 /* Need to parse the erom again to find addr */
794 uint
ai_flag(struct si_pub
*sih
)
799 sii
= (struct si_info
*)sih
;
802 return R_REG(&ai
->oobselouta30
) & 0x1f;
805 void ai_setint(struct si_pub
*sih
, int siflag
)
809 uint
ai_corevendor(struct si_pub
*sih
)
814 sii
= (struct si_info
*)sih
;
815 cia
= sii
->cia
[sii
->curidx
];
816 return (cia
& CIA_MFG_MASK
) >> CIA_MFG_SHIFT
;
819 uint
ai_corerev(struct si_pub
*sih
)
824 sii
= (struct si_info
*)sih
;
825 cib
= sii
->cib
[sii
->curidx
];
826 return (cib
& CIB_REV_MASK
) >> CIB_REV_SHIFT
;
829 bool ai_iscoreup(struct si_pub
*sih
)
834 sii
= (struct si_info
*)sih
;
837 return (((R_REG(&ai
->ioctrl
) & (SICF_FGC
| SICF_CLOCK_EN
)) ==
839 && ((R_REG(&ai
->resetctrl
) & AIRC_RESET
) == 0));
842 void ai_core_cflags_wo(struct si_pub
*sih
, u32 mask
, u32 val
)
848 sii
= (struct si_info
*)sih
;
853 w
= ((R_REG(&ai
->ioctrl
) & ~mask
) | val
);
854 W_REG(&ai
->ioctrl
, w
);
858 u32
ai_core_cflags(struct si_pub
*sih
, u32 mask
, u32 val
)
864 sii
= (struct si_info
*)sih
;
868 w
= ((R_REG(&ai
->ioctrl
) & ~mask
) | val
);
869 W_REG(&ai
->ioctrl
, w
);
872 return R_REG(&ai
->ioctrl
);
875 /* return true if PCIE capability exists in the pci config space */
876 static bool ai_ispcie(struct si_info
*sii
)
881 pcicore_find_pci_capability(sii
->pbus
, PCI_CAP_ID_EXP
, NULL
,
889 static bool ai_buscore_prep(struct si_info
*sii
)
891 /* kludge to enable the clock on the 4306 which lacks a slowclock */
893 ai_clkctl_xtal(&sii
->pub
, XTAL
| PLL
, ON
);
897 u32
ai_core_sflags(struct si_pub
*sih
, u32 mask
, u32 val
)
903 sii
= (struct si_info
*)sih
;
907 w
= ((R_REG(&ai
->iostatus
) & ~mask
) | val
);
908 W_REG(&ai
->iostatus
, w
);
911 return R_REG(&ai
->iostatus
);
915 ai_buscore_setup(struct si_info
*sii
, u32 savewin
, uint
*origidx
)
919 uint pciidx
, pcieidx
, pcirev
, pcierev
;
920 struct chipcregs __iomem
*cc
;
922 cc
= ai_setcoreidx(&sii
->pub
, SI_CC_IDX
);
924 /* get chipcommon rev */
925 sii
->pub
.ccrev
= (int)ai_corerev(&sii
->pub
);
927 /* get chipcommon chipstatus */
928 if (sii
->pub
.ccrev
>= 11)
929 sii
->pub
.chipst
= R_REG(&cc
->chipstatus
);
931 /* get chipcommon capabilites */
932 sii
->pub
.cccaps
= R_REG(&cc
->capabilities
);
933 /* get chipcommon extended capabilities */
935 if (sii
->pub
.ccrev
>= 35)
936 sii
->pub
.cccaps_ext
= R_REG(&cc
->capabilities_ext
);
938 /* get pmu rev and caps */
939 if (sii
->pub
.cccaps
& CC_CAP_PMU
) {
940 sii
->pub
.pmucaps
= R_REG(&cc
->pmucapabilities
);
941 sii
->pub
.pmurev
= sii
->pub
.pmucaps
& PCAP_REV_MASK
;
944 /* figure out bus/orignal core idx */
945 sii
->pub
.buscoretype
= NODEV_CORE_ID
;
946 sii
->pub
.buscorerev
= NOREV
;
947 sii
->pub
.buscoreidx
= BADIDX
;
950 pcirev
= pcierev
= NOREV
;
951 pciidx
= pcieidx
= BADIDX
;
953 for (i
= 0; i
< sii
->numcores
; i
++) {
956 ai_setcoreidx(&sii
->pub
, i
);
957 cid
= ai_coreid(&sii
->pub
);
958 crev
= ai_corerev(&sii
->pub
);
960 if (cid
== PCI_CORE_ID
) {
964 } else if (cid
== PCIE_CORE_ID
) {
970 /* find the core idx before entering this func. */
971 if ((savewin
&& (savewin
== sii
->coresba
[i
])) ||
972 (cc
== sii
->regs
[i
]))
983 sii
->pub
.buscoretype
= PCI_CORE_ID
;
984 sii
->pub
.buscorerev
= pcirev
;
985 sii
->pub
.buscoreidx
= pciidx
;
987 sii
->pub
.buscoretype
= PCIE_CORE_ID
;
988 sii
->pub
.buscorerev
= pcierev
;
989 sii
->pub
.buscoreidx
= pcieidx
;
992 /* fixup necessary chip/core configurations */
995 sii
->pch
= pcicore_init(&sii
->pub
, sii
->pbus
,
996 (__iomem
void *)PCIEREGS(sii
));
997 if (sii
->pch
== NULL
)
1001 if (ai_pci_fixcfg(&sii
->pub
)) {
1002 /* si_doattach: si_pci_fixcfg failed */
1006 /* return to the original core */
1007 ai_setcoreidx(&sii
->pub
, *origidx
);
1013 * get boardtype and boardrev
1015 static __used
void ai_nvram_process(struct si_info
*sii
, char *pvars
)
1019 /* do a pci config read to get subsystem id and subvendor id */
1020 pci_read_config_dword(sii
->pbus
, PCI_SUBSYSTEM_VENDOR_ID
, &w
);
1022 sii
->pub
.boardvendor
= w
& 0xffff;
1023 sii
->pub
.boardtype
= (w
>> 16) & 0xffff;
1024 sii
->pub
.boardflags
= getintvar(pvars
, "boardflags");
1027 static struct si_info
*ai_doattach(struct si_info
*sii
,
1028 void __iomem
*regs
, struct pci_dev
*pbus
,
1029 char **vars
, uint
*varsz
)
1031 struct si_pub
*sih
= &sii
->pub
;
1033 struct chipcregs __iomem
*cc
;
1038 memset((unsigned char *) sii
, 0, sizeof(struct si_info
));
1042 sih
->buscoreidx
= BADIDX
;
1047 /* find Chipcommon address */
1048 pci_read_config_dword(sii
->pbus
, PCI_BAR0_WIN
, &savewin
);
1049 if (!GOODCOREADDR(savewin
, SI_ENUM_BASE
))
1050 savewin
= SI_ENUM_BASE
;
1052 pci_write_config_dword(sii
->pbus
, PCI_BAR0_WIN
,
1054 cc
= (struct chipcregs __iomem
*) regs
;
1056 /* bus/core/clk setup for register access */
1057 if (!ai_buscore_prep(sii
))
1061 * ChipID recognition.
1062 * We assume we can read chipid at offset 0 from the regs arg.
1063 * If we add other chiptypes (or if we need to support old sdio
1064 * hosts w/o chipcommon), some way of recognizing them needs to
1067 w
= R_REG(&cc
->chipid
);
1068 socitype
= (w
& CID_TYPE_MASK
) >> CID_TYPE_SHIFT
;
1069 /* Might as wll fill in chip id rev & pkg */
1070 sih
->chip
= w
& CID_ID_MASK
;
1071 sih
->chiprev
= (w
& CID_REV_MASK
) >> CID_REV_SHIFT
;
1072 sih
->chippkg
= (w
& CID_PKG_MASK
) >> CID_PKG_SHIFT
;
1076 /* scan for cores */
1077 if (socitype
== SOCI_AI
) {
1078 SI_MSG(("Found chip type AI (0x%08x)\n", w
));
1079 /* pass chipc address instead of original core base */
1080 ai_scan(&sii
->pub
, cc
);
1082 /* Found chip of unknown type */
1085 /* no cores found, bail out */
1086 if (sii
->numcores
== 0)
1089 /* bus/core/clk setup */
1090 origidx
= SI_CC_IDX
;
1091 if (!ai_buscore_setup(sii
, savewin
, &origidx
))
1094 /* Init nvram from sprom/otp if they exist */
1095 if (srom_var_init(&sii
->pub
, cc
, vars
, varsz
))
1098 pvars
= vars
? *vars
: NULL
;
1099 ai_nvram_process(sii
, pvars
);
1101 /* === NVRAM, clock is ready === */
1102 cc
= (struct chipcregs __iomem
*) ai_setcore(sih
, CC_CORE_ID
, 0);
1103 W_REG(&cc
->gpiopullup
, 0);
1104 W_REG(&cc
->gpiopulldown
, 0);
1105 ai_setcoreidx(sih
, origidx
);
1107 /* PMU specific initializations */
1108 if (sih
->cccaps
& CC_CAP_PMU
) {
1111 si_pmu_chip_init(sih
);
1112 xtalfreq
= getintvar(pvars
, "xtalfreq");
1113 /* If xtalfreq var not available, try to measure it */
1115 xtalfreq
= si_pmu_measure_alpclk(sih
);
1116 si_pmu_pll_init(sih
, xtalfreq
);
1117 si_pmu_res_init(sih
);
1118 si_pmu_swreg_init(sih
);
1121 /* setup the GPIO based LED powersave register */
1122 w
= getintvar(pvars
, "leddc");
1124 w
= DEFAULT_GPIOTIMERVAL
;
1125 ai_corereg(sih
, SI_CC_IDX
, offsetof(struct chipcregs
, gpiotimerval
),
1129 pcicore_attach(sii
->pch
, pvars
, SI_DOATTACH
);
1131 if (sih
->chip
== BCM43224_CHIP_ID
) {
1133 * enable 12 mA drive strenth for 43224 and
1134 * set chipControl register bit 15
1136 if (sih
->chiprev
== 0) {
1137 SI_MSG(("Applying 43224A0 WARs\n"));
1138 ai_corereg(sih
, SI_CC_IDX
,
1139 offsetof(struct chipcregs
, chipcontrol
),
1140 CCTRL43224_GPIO_TOGGLE
,
1141 CCTRL43224_GPIO_TOGGLE
);
1142 si_pmu_chipcontrol(sih
, 0, CCTRL_43224A0_12MA_LED_DRIVE
,
1143 CCTRL_43224A0_12MA_LED_DRIVE
);
1145 if (sih
->chiprev
>= 1) {
1146 SI_MSG(("Applying 43224B0+ WARs\n"));
1147 si_pmu_chipcontrol(sih
, 0, CCTRL_43224B0_12MA_LED_DRIVE
,
1148 CCTRL_43224B0_12MA_LED_DRIVE
);
1152 if (sih
->chip
== BCM4313_CHIP_ID
) {
1154 * enable 12 mA drive strenth for 4313 and
1155 * set chipControl register bit 1
1157 SI_MSG(("Applying 4313 WARs\n"));
1158 si_pmu_chipcontrol(sih
, 0, CCTRL_4313_12MA_LED_DRIVE
,
1159 CCTRL_4313_12MA_LED_DRIVE
);
1166 pcicore_deinit(sii
->pch
);
1173 * Allocate a si handle.
1174 * devid - pci device id (used to determine chip#)
1175 * osh - opaque OS handle
1176 * regs - virtual address of initial core registers
1177 * vars - pointer to a pointer area for "environment" variables
1178 * varsz - pointer to int to return the size of the vars
1181 ai_attach(void __iomem
*regs
, struct pci_dev
*sdh
, char **vars
, uint
*varsz
)
1183 struct si_info
*sii
;
1185 /* alloc struct si_info */
1186 sii
= kmalloc(sizeof(struct si_info
), GFP_ATOMIC
);
1190 if (ai_doattach(sii
, regs
, sdh
, vars
, varsz
) == NULL
) {
1194 sii
->vars
= vars
? *vars
: NULL
;
1195 sii
->varsz
= varsz
? *varsz
: 0;
1197 return (struct si_pub
*) sii
;
1200 /* may be called with core in reset */
1201 void ai_detach(struct si_pub
*sih
)
1203 struct si_info
*sii
;
1205 struct si_pub
*si_local
= NULL
;
1206 memcpy(&si_local
, &sih
, sizeof(struct si_pub
**));
1208 sii
= (struct si_info
*)sih
;
1214 pcicore_deinit(sii
->pch
);
1220 /* register driver interrupt disabling and restoring callback functions */
1222 ai_register_intr_callback(struct si_pub
*sih
, void *intrsoff_fn
,
1223 void *intrsrestore_fn
,
1224 void *intrsenabled_fn
, void *intr_arg
)
1226 struct si_info
*sii
;
1228 sii
= (struct si_info
*)sih
;
1229 sii
->intr_arg
= intr_arg
;
1230 sii
->intrsoff_fn
= (u32 (*)(void *)) intrsoff_fn
;
1231 sii
->intrsrestore_fn
= (void (*) (void *, u32
)) intrsrestore_fn
;
1232 sii
->intrsenabled_fn
= (bool (*)(void *)) intrsenabled_fn
;
1233 /* save current core id. when this function called, the current core
1234 * must be the core which provides driver functions(il, et, wl, etc.)
1236 sii
->dev_coreid
= sii
->coreid
[sii
->curidx
];
1239 void ai_deregister_intr_callback(struct si_pub
*sih
)
1241 struct si_info
*sii
;
1243 sii
= (struct si_info
*)sih
;
1244 sii
->intrsoff_fn
= NULL
;
1247 uint
ai_coreid(struct si_pub
*sih
)
1249 struct si_info
*sii
;
1251 sii
= (struct si_info
*)sih
;
1252 return sii
->coreid
[sii
->curidx
];
1255 uint
ai_coreidx(struct si_pub
*sih
)
1257 struct si_info
*sii
;
1259 sii
= (struct si_info
*)sih
;
1263 bool ai_backplane64(struct si_pub
*sih
)
1265 return (sih
->cccaps
& CC_CAP_BKPLN64
) != 0;
1268 /* return index of coreid or BADIDX if not found */
1269 uint
ai_findcoreidx(struct si_pub
*sih
, uint coreid
, uint coreunit
)
1271 struct si_info
*sii
;
1275 sii
= (struct si_info
*)sih
;
1279 for (i
= 0; i
< sii
->numcores
; i
++)
1280 if (sii
->coreid
[i
] == coreid
) {
1281 if (found
== coreunit
)
1290 * This function changes logical "focus" to the indicated core;
1291 * must be called with interrupts off.
1292 * Moreover, callers should keep interrupts off during switching
1293 * out of and back to d11 core.
1295 void __iomem
*ai_setcore(struct si_pub
*sih
, uint coreid
, uint coreunit
)
1299 idx
= ai_findcoreidx(sih
, coreid
, coreunit
);
1300 if (idx
>= SI_MAXCORES
)
1303 return ai_setcoreidx(sih
, idx
);
1306 /* Turn off interrupt as required by ai_setcore, before switch core */
1307 void __iomem
*ai_switch_core(struct si_pub
*sih
, uint coreid
, uint
*origidx
,
1311 struct si_info
*sii
;
1313 sii
= (struct si_info
*)sih
;
1316 /* Overloading the origidx variable to remember the coreid,
1317 * this works because the core ids cannot be confused with
1321 if (coreid
== CC_CORE_ID
)
1322 return CCREGS_FAST(sii
);
1323 else if (coreid
== sih
->buscoretype
)
1324 return PCIEREGS(sii
);
1326 INTR_OFF(sii
, *intr_val
);
1327 *origidx
= sii
->curidx
;
1328 cc
= ai_setcore(sih
, coreid
, 0);
1332 /* restore coreidx and restore interrupt */
1333 void ai_restore_core(struct si_pub
*sih
, uint coreid
, uint intr_val
)
1335 struct si_info
*sii
;
1337 sii
= (struct si_info
*)sih
;
1339 && ((coreid
== CC_CORE_ID
) || (coreid
== sih
->buscoretype
)))
1342 ai_setcoreidx(sih
, coreid
);
1343 INTR_RESTORE(sii
, intr_val
);
1346 void ai_write_wrapperreg(struct si_pub
*sih
, u32 offset
, u32 val
)
1348 struct si_info
*sii
= (struct si_info
*)sih
;
1349 u32
*w
= (u32
*) sii
->curwrap
;
1350 W_REG(w
+ (offset
/ 4), val
);
1355 * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set
1356 * operation, switch back to the original core, and return the new value.
1358 * When using the silicon backplane, no fiddling with interrupts or core
1359 * switches is needed.
1361 * Also, when using pci/pcie, we can optimize away the core switching for pci
1362 * registers and (on newer pci cores) chipcommon registers.
1364 uint
ai_corereg(struct si_pub
*sih
, uint coreidx
, uint regoff
, uint mask
,
1368 u32 __iomem
*r
= NULL
;
1372 struct si_info
*sii
;
1374 sii
= (struct si_info
*)sih
;
1376 if (coreidx
>= SI_MAXCORES
)
1380 * If pci/pcie, we can get at pci/pcie regs
1381 * and on newer cores to chipc
1383 if ((sii
->coreid
[coreidx
] == CC_CORE_ID
) && SI_FAST(sii
)) {
1384 /* Chipc registers are mapped at 12KB */
1386 r
= (u32 __iomem
*)((__iomem
char *)sii
->curmap
+
1387 PCI_16KB0_CCREGS_OFFSET
+ regoff
);
1388 } else if (sii
->pub
.buscoreidx
== coreidx
) {
1390 * pci registers are at either in the last 2KB of
1391 * an 8KB window or, in pcie and pci rev 13 at 8KB
1395 r
= (u32 __iomem
*)((__iomem
char *)sii
->curmap
+
1396 PCI_16KB0_PCIREGS_OFFSET
+ regoff
);
1398 r
= (u32 __iomem
*)((__iomem
char *)sii
->curmap
+
1399 ((regoff
>= SBCONFIGOFF
) ?
1400 PCI_BAR0_PCISBR_OFFSET
:
1401 PCI_BAR0_PCIREGS_OFFSET
) + regoff
);
1405 INTR_OFF(sii
, intr_val
);
1407 /* save current core index */
1408 origidx
= ai_coreidx(&sii
->pub
);
1411 r
= (u32 __iomem
*) ((unsigned char __iomem
*)
1412 ai_setcoreidx(&sii
->pub
, coreidx
) + regoff
);
1417 w
= (R_REG(r
) & ~mask
) | val
;
1425 /* restore core index */
1426 if (origidx
!= coreidx
)
1427 ai_setcoreidx(&sii
->pub
, origidx
);
1429 INTR_RESTORE(sii
, intr_val
);
1435 void ai_core_disable(struct si_pub
*sih
, u32 bits
)
1437 struct si_info
*sii
;
1441 sii
= (struct si_info
*)sih
;
1445 /* if core is already in reset, just return */
1446 if (R_REG(&ai
->resetctrl
) & AIRC_RESET
)
1449 W_REG(&ai
->ioctrl
, bits
);
1450 dummy
= R_REG(&ai
->ioctrl
);
1453 W_REG(&ai
->resetctrl
, AIRC_RESET
);
1457 /* reset and re-enable a core
1459 * bits - core specific bits that are set during and after reset sequence
1460 * resetbits - core specific bits that are set only during reset sequence
1462 void ai_core_reset(struct si_pub
*sih
, u32 bits
, u32 resetbits
)
1464 struct si_info
*sii
;
1468 sii
= (struct si_info
*)sih
;
1472 * Must do the disable sequence first to work
1473 * for arbitrary current core state.
1475 ai_core_disable(sih
, (bits
| resetbits
));
1478 * Now do the initialization sequence.
1480 W_REG(&ai
->ioctrl
, (bits
| SICF_FGC
| SICF_CLOCK_EN
));
1481 dummy
= R_REG(&ai
->ioctrl
);
1482 W_REG(&ai
->resetctrl
, 0);
1485 W_REG(&ai
->ioctrl
, (bits
| SICF_CLOCK_EN
));
1486 dummy
= R_REG(&ai
->ioctrl
);
1490 /* return the slow clock source - LPO, XTAL, or PCI */
1491 static uint
ai_slowclk_src(struct si_info
*sii
)
1493 struct chipcregs __iomem
*cc
;
1496 if (sii
->pub
.ccrev
< 6) {
1497 pci_read_config_dword(sii
->pbus
, PCI_GPIO_OUT
,
1499 if (val
& PCI_CFG_GPIO_SCS
)
1502 } else if (sii
->pub
.ccrev
< 10) {
1503 cc
= (struct chipcregs __iomem
*)
1504 ai_setcoreidx(&sii
->pub
, sii
->curidx
);
1505 return R_REG(&cc
->slow_clk_ctl
) & SCC_SS_MASK
;
1506 } else /* Insta-clock */
1511 * return the ILP (slowclock) min or max frequency
1512 * precondition: we've established the chip has dynamic clk control
1514 static uint
ai_slowclk_freq(struct si_info
*sii
, bool max_freq
,
1515 struct chipcregs __iomem
*cc
)
1520 slowclk
= ai_slowclk_src(sii
);
1521 if (sii
->pub
.ccrev
< 6) {
1522 if (slowclk
== SCC_SS_PCI
)
1523 return max_freq
? (PCIMAXFREQ
/ 64)
1524 : (PCIMINFREQ
/ 64);
1526 return max_freq
? (XTALMAXFREQ
/ 32)
1527 : (XTALMINFREQ
/ 32);
1528 } else if (sii
->pub
.ccrev
< 10) {
1530 (((R_REG(&cc
->slow_clk_ctl
) & SCC_CD_MASK
) >>
1532 if (slowclk
== SCC_SS_LPO
)
1533 return max_freq
? LPOMAXFREQ
: LPOMINFREQ
;
1534 else if (slowclk
== SCC_SS_XTAL
)
1535 return max_freq
? (XTALMAXFREQ
/ div
)
1536 : (XTALMINFREQ
/ div
);
1537 else if (slowclk
== SCC_SS_PCI
)
1538 return max_freq
? (PCIMAXFREQ
/ div
)
1539 : (PCIMINFREQ
/ div
);
1541 /* Chipc rev 10 is InstaClock */
1542 div
= R_REG(&cc
->system_clk_ctl
) >> SYCC_CD_SHIFT
;
1543 div
= 4 * (div
+ 1);
1544 return max_freq
? XTALMAXFREQ
: (XTALMINFREQ
/ div
);
1550 ai_clkctl_setdelay(struct si_info
*sii
, struct chipcregs __iomem
*cc
)
1552 uint slowmaxfreq
, pll_delay
, slowclk
;
1553 uint pll_on_delay
, fref_sel_delay
;
1555 pll_delay
= PLL_DELAY
;
1558 * If the slow clock is not sourced by the xtal then
1559 * add the xtal_on_delay since the xtal will also be
1560 * powered down by dynamic clk control logic.
1563 slowclk
= ai_slowclk_src(sii
);
1564 if (slowclk
!= SCC_SS_XTAL
)
1565 pll_delay
+= XTAL_ON_DELAY
;
1567 /* Starting with 4318 it is ILP that is used for the delays */
1569 ai_slowclk_freq(sii
, (sii
->pub
.ccrev
>= 10) ? false : true, cc
);
1571 pll_on_delay
= ((slowmaxfreq
* pll_delay
) + 999999) / 1000000;
1572 fref_sel_delay
= ((slowmaxfreq
* FREF_DELAY
) + 999999) / 1000000;
1574 W_REG(&cc
->pll_on_delay
, pll_on_delay
);
1575 W_REG(&cc
->fref_sel_delay
, fref_sel_delay
);
1578 /* initialize power control delay registers */
1579 void ai_clkctl_init(struct si_pub
*sih
)
1581 struct si_info
*sii
;
1583 struct chipcregs __iomem
*cc
;
1586 if (!(sih
->cccaps
& CC_CAP_PWR_CTL
))
1589 sii
= (struct si_info
*)sih
;
1590 fast
= SI_FAST(sii
);
1592 origidx
= sii
->curidx
;
1593 cc
= (struct chipcregs __iomem
*)
1594 ai_setcore(sih
, CC_CORE_ID
, 0);
1598 cc
= (struct chipcregs __iomem
*) CCREGS_FAST(sii
);
1603 /* set all Instaclk chip ILP to 1 MHz */
1604 if (sih
->ccrev
>= 10)
1605 SET_REG(&cc
->system_clk_ctl
, SYCC_CD_MASK
,
1606 (ILP_DIV_1MHZ
<< SYCC_CD_SHIFT
));
1608 ai_clkctl_setdelay(sii
, cc
);
1611 ai_setcoreidx(sih
, origidx
);
1615 * return the value suitable for writing to the
1616 * dot11 core FAST_PWRUP_DELAY register
1618 u16
ai_clkctl_fast_pwrup_delay(struct si_pub
*sih
)
1620 struct si_info
*sii
;
1622 struct chipcregs __iomem
*cc
;
1628 sii
= (struct si_info
*)sih
;
1629 if (sih
->cccaps
& CC_CAP_PMU
) {
1630 INTR_OFF(sii
, intr_val
);
1631 fpdelay
= si_pmu_fast_pwrup_delay(sih
);
1632 INTR_RESTORE(sii
, intr_val
);
1636 if (!(sih
->cccaps
& CC_CAP_PWR_CTL
))
1639 fast
= SI_FAST(sii
);
1642 origidx
= sii
->curidx
;
1643 INTR_OFF(sii
, intr_val
);
1644 cc
= (struct chipcregs __iomem
*)
1645 ai_setcore(sih
, CC_CORE_ID
, 0);
1649 cc
= (struct chipcregs __iomem
*) CCREGS_FAST(sii
);
1654 slowminfreq
= ai_slowclk_freq(sii
, false, cc
);
1655 fpdelay
= (((R_REG(&cc
->pll_on_delay
) + 2) * 1000000) +
1656 (slowminfreq
- 1)) / slowminfreq
;
1660 ai_setcoreidx(sih
, origidx
);
1661 INTR_RESTORE(sii
, intr_val
);
1666 /* turn primary xtal and/or pll off/on */
1667 int ai_clkctl_xtal(struct si_pub
*sih
, uint what
, bool on
)
1669 struct si_info
*sii
;
1672 sii
= (struct si_info
*)sih
;
1674 /* pcie core doesn't have any mapping to control the xtal pu */
1678 pci_read_config_dword(sii
->pbus
, PCI_GPIO_IN
, &in
);
1679 pci_read_config_dword(sii
->pbus
, PCI_GPIO_OUT
, &out
);
1680 pci_read_config_dword(sii
->pbus
, PCI_GPIO_OUTEN
, &outen
);
1683 * Avoid glitching the clock if GPRS is already using it.
1684 * We can't actually read the state of the PLLPD so we infer it
1685 * by the value of XTAL_PU which *is* readable via gpioin.
1687 if (on
&& (in
& PCI_CFG_GPIO_XTAL
))
1691 outen
|= PCI_CFG_GPIO_XTAL
;
1693 outen
|= PCI_CFG_GPIO_PLL
;
1696 /* turn primary xtal on */
1698 out
|= PCI_CFG_GPIO_XTAL
;
1700 out
|= PCI_CFG_GPIO_PLL
;
1701 pci_write_config_dword(sii
->pbus
,
1703 pci_write_config_dword(sii
->pbus
,
1704 PCI_GPIO_OUTEN
, outen
);
1705 udelay(XTAL_ON_DELAY
);
1710 out
&= ~PCI_CFG_GPIO_PLL
;
1711 pci_write_config_dword(sii
->pbus
,
1717 out
&= ~PCI_CFG_GPIO_XTAL
;
1719 out
|= PCI_CFG_GPIO_PLL
;
1720 pci_write_config_dword(sii
->pbus
,
1722 pci_write_config_dword(sii
->pbus
,
1723 PCI_GPIO_OUTEN
, outen
);
1729 /* clk control mechanism through chipcommon, no policy checking */
1730 static bool _ai_clkctl_cc(struct si_info
*sii
, uint mode
)
1733 struct chipcregs __iomem
*cc
;
1736 bool fast
= SI_FAST(sii
);
1738 /* chipcommon cores prior to rev6 don't support dynamic clock control */
1739 if (sii
->pub
.ccrev
< 6)
1743 INTR_OFF(sii
, intr_val
);
1744 origidx
= sii
->curidx
;
1745 cc
= (struct chipcregs __iomem
*)
1746 ai_setcore(&sii
->pub
, CC_CORE_ID
, 0);
1748 cc
= (struct chipcregs __iomem
*) CCREGS_FAST(sii
);
1753 if (!(sii
->pub
.cccaps
& CC_CAP_PWR_CTL
) && (sii
->pub
.ccrev
< 20))
1757 case CLK_FAST
: /* FORCEHT, fast (pll) clock */
1758 if (sii
->pub
.ccrev
< 10) {
1760 * don't forget to force xtal back
1761 * on before we clear SCC_DYN_XTAL..
1763 ai_clkctl_xtal(&sii
->pub
, XTAL
, ON
);
1764 SET_REG(&cc
->slow_clk_ctl
,
1765 (SCC_XC
| SCC_FS
| SCC_IP
), SCC_IP
);
1766 } else if (sii
->pub
.ccrev
< 20) {
1767 OR_REG(&cc
->system_clk_ctl
, SYCC_HR
);
1769 OR_REG(&cc
->clk_ctl_st
, CCS_FORCEHT
);
1772 /* wait for the PLL */
1773 if (sii
->pub
.cccaps
& CC_CAP_PMU
) {
1774 u32 htavail
= CCS_HTAVAIL
;
1775 SPINWAIT(((R_REG(&cc
->clk_ctl_st
) & htavail
)
1776 == 0), PMU_MAX_TRANSITION_DLY
);
1782 case CLK_DYNAMIC
: /* enable dynamic clock control */
1783 if (sii
->pub
.ccrev
< 10) {
1784 scc
= R_REG(&cc
->slow_clk_ctl
);
1785 scc
&= ~(SCC_FS
| SCC_IP
| SCC_XC
);
1786 if ((scc
& SCC_SS_MASK
) != SCC_SS_XTAL
)
1788 W_REG(&cc
->slow_clk_ctl
, scc
);
1791 * for dynamic control, we have to
1792 * release our xtal_pu "force on"
1795 ai_clkctl_xtal(&sii
->pub
, XTAL
, OFF
);
1796 } else if (sii
->pub
.ccrev
< 20) {
1798 AND_REG(&cc
->system_clk_ctl
, ~SYCC_HR
);
1800 AND_REG(&cc
->clk_ctl_st
, ~CCS_FORCEHT
);
1810 ai_setcoreidx(&sii
->pub
, origidx
);
1811 INTR_RESTORE(sii
, intr_val
);
1813 return mode
== CLK_FAST
;
1817 * clock control policy function throught chipcommon
1819 * set dynamic clk control mode (forceslow, forcefast, dynamic)
1820 * returns true if we are forcing fast clock
1821 * this is a wrapper over the next internal function
1822 * to allow flexible policy settings for outside caller
1824 bool ai_clkctl_cc(struct si_pub
*sih
, uint mode
)
1826 struct si_info
*sii
;
1828 sii
= (struct si_info
*)sih
;
1830 /* chipcommon cores prior to rev6 don't support dynamic clock control */
1834 if (PCI_FORCEHT(sii
))
1835 return mode
== CLK_FAST
;
1837 return _ai_clkctl_cc(sii
, mode
);
1840 /* Build device path */
1841 int ai_devpath(struct si_pub
*sih
, char *path
, int size
)
1845 if (!path
|| size
<= 0)
1848 slen
= snprintf(path
, (size_t) size
, "pci/%u/%u/",
1849 ((struct si_info
*)sih
)->pbus
->bus
->number
,
1850 PCI_SLOT(((struct pci_dev
*)
1851 (((struct si_info
*)(sih
))->pbus
))->devfn
));
1853 if (slen
< 0 || slen
>= size
) {
1861 void ai_pci_up(struct si_pub
*sih
)
1863 struct si_info
*sii
;
1865 sii
= (struct si_info
*)sih
;
1867 if (PCI_FORCEHT(sii
))
1868 _ai_clkctl_cc(sii
, CLK_FAST
);
1871 pcicore_up(sii
->pch
, SI_PCIUP
);
1875 /* Unconfigure and/or apply various WARs when system is going to sleep mode */
1876 void ai_pci_sleep(struct si_pub
*sih
)
1878 struct si_info
*sii
;
1880 sii
= (struct si_info
*)sih
;
1882 pcicore_sleep(sii
->pch
);
1885 /* Unconfigure and/or apply various WARs when going down */
1886 void ai_pci_down(struct si_pub
*sih
)
1888 struct si_info
*sii
;
1890 sii
= (struct si_info
*)sih
;
1892 /* release FORCEHT since chip is going to "down" state */
1893 if (PCI_FORCEHT(sii
))
1894 _ai_clkctl_cc(sii
, CLK_DYNAMIC
);
1896 pcicore_down(sii
->pch
, SI_PCIDOWN
);
1900 * Configure the pci core for pci client (NIC) action
1901 * coremask is the bitvec of cores by index to be enabled.
1903 void ai_pci_setup(struct si_pub
*sih
, uint coremask
)
1905 struct si_info
*sii
;
1906 struct sbpciregs __iomem
*regs
= NULL
;
1910 sii
= (struct si_info
*)sih
;
1913 /* get current core index */
1916 /* we interrupt on this backplane flag number */
1917 siflag
= ai_flag(sih
);
1919 /* switch over to pci core */
1920 regs
= ai_setcoreidx(sih
, sii
->pub
.buscoreidx
);
1924 * Enable sb->pci interrupts. Assume
1925 * PCI rev 2.3 support was added in pci core rev 6 and things changed..
1927 if (PCIE(sii
) || (PCI(sii
) && ((sii
->pub
.buscorerev
) >= 6))) {
1928 /* pci config write to set this core bit in PCIIntMask */
1929 pci_read_config_dword(sii
->pbus
, PCI_INT_MASK
, &w
);
1930 w
|= (coremask
<< PCI_SBIM_SHIFT
);
1931 pci_write_config_dword(sii
->pbus
, PCI_INT_MASK
, w
);
1933 /* set sbintvec bit for our flag number */
1934 ai_setint(sih
, siflag
);
1938 pcicore_pci_setup(sii
->pch
, regs
);
1940 /* switch back to previous core */
1941 ai_setcoreidx(sih
, idx
);
1946 * Fixup SROMless PCI device's configuration.
1947 * The current core may be changed upon return.
1949 int ai_pci_fixcfg(struct si_pub
*sih
)
1952 void __iomem
*regs
= NULL
;
1953 struct si_info
*sii
= (struct si_info
*)sih
;
1955 /* Fixup PI in SROM shadow area to enable the correct PCI core access */
1956 /* save the current index */
1957 origidx
= ai_coreidx(&sii
->pub
);
1959 /* check 'pi' is correct and fix it if not */
1960 regs
= ai_setcore(&sii
->pub
, sii
->pub
.buscoretype
, 0);
1961 if (sii
->pub
.buscoretype
== PCIE_CORE_ID
)
1962 pcicore_fixcfg_pcie(sii
->pch
,
1963 (struct sbpcieregs __iomem
*)regs
);
1964 else if (sii
->pub
.buscoretype
== PCI_CORE_ID
)
1965 pcicore_fixcfg_pci(sii
->pch
, (struct sbpciregs __iomem
*)regs
);
1967 /* restore the original index */
1968 ai_setcoreidx(&sii
->pub
, origidx
);
1970 pcicore_hwup(sii
->pch
);
1974 /* mask&set gpiocontrol bits */
1975 u32
ai_gpiocontrol(struct si_pub
*sih
, u32 mask
, u32 val
, u8 priority
)
1979 regoff
= offsetof(struct chipcregs
, gpiocontrol
);
1980 return ai_corereg(sih
, SI_CC_IDX
, regoff
, mask
, val
);
1983 void ai_chipcontrl_epa4331(struct si_pub
*sih
, bool on
)
1985 struct si_info
*sii
;
1986 struct chipcregs __iomem
*cc
;
1990 sii
= (struct si_info
*)sih
;
1991 origidx
= ai_coreidx(sih
);
1993 cc
= (struct chipcregs __iomem
*) ai_setcore(sih
, CC_CORE_ID
, 0);
1995 val
= R_REG(&cc
->chipcontrol
);
1998 if (sih
->chippkg
== 9 || sih
->chippkg
== 0xb)
1999 /* Ext PA Controls for 4331 12x9 Package */
2000 W_REG(&cc
->chipcontrol
, val
|
2001 CCTRL4331_EXTPA_EN
|
2002 CCTRL4331_EXTPA_ON_GPIO2_5
);
2004 /* Ext PA Controls for 4331 12x12 Package */
2005 W_REG(&cc
->chipcontrol
,
2006 val
| CCTRL4331_EXTPA_EN
);
2008 val
&= ~(CCTRL4331_EXTPA_EN
| CCTRL4331_EXTPA_ON_GPIO2_5
);
2009 W_REG(&cc
->chipcontrol
, val
);
2012 ai_setcoreidx(sih
, origidx
);
2015 /* Enable BT-COEX & Ex-PA for 4313 */
2016 void ai_epa_4313war(struct si_pub
*sih
)
2018 struct si_info
*sii
;
2019 struct chipcregs __iomem
*cc
;
2022 sii
= (struct si_info
*)sih
;
2023 origidx
= ai_coreidx(sih
);
2025 cc
= ai_setcore(sih
, CC_CORE_ID
, 0);
2028 W_REG(&cc
->gpiocontrol
,
2029 R_REG(&cc
->gpiocontrol
) | GPIO_CTRL_EPA_EN_MASK
);
2031 ai_setcoreidx(sih
, origidx
);
2034 /* check if the device is removed */
2035 bool ai_deviceremoved(struct si_pub
*sih
)
2038 struct si_info
*sii
;
2040 sii
= (struct si_info
*)sih
;
2042 pci_read_config_dword(sii
->pbus
, PCI_VENDOR_ID
, &w
);
2043 if ((w
& 0xFFFF) != PCI_VENDOR_ID_BROADCOM
)
2049 bool ai_is_sprom_available(struct si_pub
*sih
)
2051 if (sih
->ccrev
>= 31) {
2052 struct si_info
*sii
;
2054 struct chipcregs __iomem
*cc
;
2057 if ((sih
->cccaps
& CC_CAP_SROM
) == 0)
2060 sii
= (struct si_info
*)sih
;
2061 origidx
= sii
->curidx
;
2062 cc
= ai_setcoreidx(sih
, SI_CC_IDX
);
2063 sromctrl
= R_REG(&cc
->sromcontrol
);
2064 ai_setcoreidx(sih
, origidx
);
2065 return sromctrl
& SRC_PRESENT
;
2068 switch (sih
->chip
) {
2069 case BCM4313_CHIP_ID
:
2070 return (sih
->chipst
& CST4313_SPROM_PRESENT
) != 0;
2076 bool ai_is_otp_disabled(struct si_pub
*sih
)
2078 switch (sih
->chip
) {
2079 case BCM4313_CHIP_ID
:
2080 return (sih
->chipst
& CST4313_OTP_PRESENT
) == 0;
2081 /* These chips always have their OTP on */
2082 case BCM43224_CHIP_ID
:
2083 case BCM43225_CHIP_ID
: