]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/brcm80211/util/siutils.c
9e181d60c201f5e2009b4a323ea9142b2cf05178
[mv-sheeva.git] / drivers / staging / brcm80211 / util / siutils.c
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include <linux/delay.h>
18 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <bcmdefs.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
23 #include <bcmutils.h>
24 #include <siutils.h>
25 #include <bcmdevs.h>
26 #include <hndsoc.h>
27 #include <sbchipc.h>
28 #include <pci_core.h>
29 #include <pcie_core.h>
30 #include <nicpci.h>
31 #include <bcmnvram.h>
32 #include <bcmsrom.h>
33 #include <pcicfg.h>
34 #include <sbsocram.h>
35 #ifdef BCMSDIO
36 #include <bcmsdh.h>
37 #include <sdio.h>
38 #include <sbsdio.h>
39 #include <sbhnddma.h>
40 #include <sbsdpcmdev.h>
41 #include <bcmsdpcm.h>
42 #endif                          /* BCMSDIO */
43 #include <hndpmu.h>
44
45 /* this file now contains only definitions for sb functions, only necessary
46 *for devices using Sonics backplanes (bcm4329)
47 */
48
49 /* if an amba SDIO device is supported, please further restrict the inclusion
50  * of this file
51  */
52 #ifdef BCMSDIO
53 #include "siutils_priv.h"
54 #endif
55
56 /* local prototypes */
57 static si_info_t *si_doattach(si_info_t *sii, uint devid, void *regs,
58                               uint bustype, void *sdh, char **vars,
59                               uint *varsz);
60 static bool si_buscore_prep(si_info_t *sii, uint bustype, uint devid,
61                             void *sdh);
62 static bool si_buscore_setup(si_info_t *sii, chipcregs_t *cc, uint bustype,
63                              u32 savewin, uint *origidx, void *regs);
64 static void si_nvram_process(si_info_t *sii, char *pvars);
65
66 /* dev path concatenation util */
67 static char *si_devpathvar(si_t *sih, char *var, int len, const char *name);
68 static bool _si_clkctl_cc(si_info_t *sii, uint mode);
69 static bool si_ispcie(si_info_t *sii);
70 static uint socram_banksize(si_info_t *sii, sbsocramregs_t *r,
71                                         u8 idx, u8 mtype);
72
73 /* global variable to indicate reservation/release of gpio's */
74 static u32 si_gpioreservation;
75
76 /*
77  * Allocate a si handle.
78  * devid - pci device id (used to determine chip#)
79  * osh - opaque OS handle
80  * regs - virtual address of initial core registers
81  * bustype - pci/sb/sdio/etc
82  * vars - pointer to a pointer area for "environment" variables
83  * varsz - pointer to int to return the size of the vars
84  */
85 si_t *si_attach(uint devid, void *regs, uint bustype,
86                 void *sdh, char **vars, uint *varsz)
87 {
88         si_info_t *sii;
89
90         /* alloc si_info_t */
91         sii = kmalloc(sizeof(si_info_t), GFP_ATOMIC);
92         if (sii == NULL) {
93                 SI_ERROR(("si_attach: malloc failed!\n"));
94                 return NULL;
95         }
96
97         if (si_doattach(sii, devid, regs, bustype, sdh, vars, varsz) ==
98             NULL) {
99                 kfree(sii);
100                 return NULL;
101         }
102         sii->vars = vars ? *vars : NULL;
103         sii->varsz = varsz ? *varsz : 0;
104
105         return (si_t *) sii;
106 }
107
108 /* global kernel resource */
109 static si_info_t ksii;
110
111 static bool si_buscore_prep(si_info_t *sii, uint bustype, uint devid,
112                             void *sdh)
113 {
114
115 #ifndef BRCM_FULLMAC
116         /* kludge to enable the clock on the 4306 which lacks a slowclock */
117         if (bustype == PCI_BUS && !si_ispcie(sii))
118                 si_clkctl_xtal(&sii->pub, XTAL | PLL, ON);
119 #endif
120
121 #if defined(BCMSDIO)
122         if (bustype == SDIO_BUS) {
123                 int err;
124                 u8 clkset;
125
126                 /* Try forcing SDIO core to do ALPAvail request only */
127                 clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ;
128                 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR,
129                                  clkset, &err);
130                 if (!err) {
131                         u8 clkval;
132
133                         /* If register supported, wait for ALPAvail and then force ALP */
134                         clkval =
135                             bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
136                                             SBSDIO_FUNC1_CHIPCLKCSR, NULL);
137                         if ((clkval & ~SBSDIO_AVBITS) == clkset) {
138                                 SPINWAIT(((clkval =
139                                            bcmsdh_cfg_read(sdh, SDIO_FUNC_1,
140                                                            SBSDIO_FUNC1_CHIPCLKCSR,
141                                                            NULL)),
142                                           !SBSDIO_ALPAV(clkval)),
143                                          PMU_MAX_TRANSITION_DLY);
144                                 if (!SBSDIO_ALPAV(clkval)) {
145                                         SI_ERROR(("timeout on ALPAV wait, clkval 0x%02x\n", clkval));
146                                         return false;
147                                 }
148                                 clkset =
149                                     SBSDIO_FORCE_HW_CLKREQ_OFF |
150                                     SBSDIO_FORCE_ALP;
151                                 bcmsdh_cfg_write(sdh, SDIO_FUNC_1,
152                                                  SBSDIO_FUNC1_CHIPCLKCSR,
153                                                  clkset, &err);
154                                 udelay(65);
155                         }
156                 }
157
158                 /* Also, disable the extra SDIO pull-ups */
159                 bcmsdh_cfg_write(sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, 0,
160                                  NULL);
161         }
162 #endif                          /* defined(BCMSDIO) */
163
164         return true;
165 }
166
167 static bool si_buscore_setup(si_info_t *sii, chipcregs_t *cc, uint bustype,
168                              u32 savewin, uint *origidx, void *regs)
169 {
170         bool pci, pcie;
171         uint i;
172         uint pciidx, pcieidx, pcirev, pcierev;
173
174         cc = si_setcoreidx(&sii->pub, SI_CC_IDX);
175         ASSERT(cc);
176
177         /* get chipcommon rev */
178         sii->pub.ccrev = (int)si_corerev(&sii->pub);
179
180         /* get chipcommon chipstatus */
181         if (sii->pub.ccrev >= 11)
182                 sii->pub.chipst = R_REG(&cc->chipstatus);
183
184         /* get chipcommon capabilites */
185         sii->pub.cccaps = R_REG(&cc->capabilities);
186         /* get chipcommon extended capabilities */
187
188 #ifndef BRCM_FULLMAC
189         if (sii->pub.ccrev >= 35)
190                 sii->pub.cccaps_ext = R_REG(&cc->capabilities_ext);
191 #endif
192         /* get pmu rev and caps */
193         if (sii->pub.cccaps & CC_CAP_PMU) {
194                 sii->pub.pmucaps = R_REG(&cc->pmucapabilities);
195                 sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;
196         }
197
198         /*
199            SI_MSG(("Chipc: rev %d, caps 0x%x, chipst 0x%x pmurev %d, pmucaps 0x%x\n",
200            sii->pub.ccrev, sii->pub.cccaps, sii->pub.chipst, sii->pub.pmurev,
201            sii->pub.pmucaps));
202          */
203
204         /* figure out bus/orignal core idx */
205         sii->pub.buscoretype = NODEV_CORE_ID;
206         sii->pub.buscorerev = NOREV;
207         sii->pub.buscoreidx = BADIDX;
208
209         pci = pcie = false;
210         pcirev = pcierev = NOREV;
211         pciidx = pcieidx = BADIDX;
212
213         for (i = 0; i < sii->numcores; i++) {
214                 uint cid, crev;
215
216                 si_setcoreidx(&sii->pub, i);
217                 cid = si_coreid(&sii->pub);
218                 crev = si_corerev(&sii->pub);
219
220                 /* Display cores found */
221                 SI_VMSG(("CORE[%d]: id 0x%x rev %d base 0x%x regs 0x%p\n",
222                          i, cid, crev, sii->coresba[i], sii->regs[i]));
223
224                 if (bustype == PCI_BUS) {
225                         if (cid == PCI_CORE_ID) {
226                                 pciidx = i;
227                                 pcirev = crev;
228                                 pci = true;
229                         } else if (cid == PCIE_CORE_ID) {
230                                 pcieidx = i;
231                                 pcierev = crev;
232                                 pcie = true;
233                         }
234                 }
235 #ifdef BCMSDIO
236                 else if (((bustype == SDIO_BUS) ||
237                           (bustype == SPI_BUS)) &&
238                          ((cid == PCMCIA_CORE_ID) || (cid == SDIOD_CORE_ID))) {
239                         sii->pub.buscorerev = crev;
240                         sii->pub.buscoretype = cid;
241                         sii->pub.buscoreidx = i;
242                 }
243 #endif                          /* BCMSDIO */
244
245                 /* find the core idx before entering this func. */
246                 if ((savewin && (savewin == sii->coresba[i])) ||
247                     (regs == sii->regs[i]))
248                         *origidx = i;
249         }
250
251 #ifdef BRCM_FULLMAC
252         SI_MSG(("Buscore id/type/rev %d/0x%x/%d\n", sii->pub.buscoreidx,
253                 sii->pub.buscoretype, sii->pub.buscorerev));
254
255         /* Make sure any on-chip ARM is off (in case strapping is wrong),
256         * or downloaded code was
257         * already running.
258         */
259         if ((bustype == SDIO_BUS) || (bustype == SPI_BUS)) {
260                 if (si_setcore(&sii->pub, ARM7S_CORE_ID, 0) ||
261                         si_setcore(&sii->pub, ARMCM3_CORE_ID, 0))
262                         si_core_disable(&sii->pub, 0);
263         }
264 #else
265         if (pci && pcie) {
266                 if (si_ispcie(sii))
267                         pci = false;
268                 else
269                         pcie = false;
270         }
271         if (pci) {
272                 sii->pub.buscoretype = PCI_CORE_ID;
273                 sii->pub.buscorerev = pcirev;
274                 sii->pub.buscoreidx = pciidx;
275         } else if (pcie) {
276                 sii->pub.buscoretype = PCIE_CORE_ID;
277                 sii->pub.buscorerev = pcierev;
278                 sii->pub.buscoreidx = pcieidx;
279         }
280
281         SI_VMSG(("Buscore id/type/rev %d/0x%x/%d\n", sii->pub.buscoreidx,
282                  sii->pub.buscoretype, sii->pub.buscorerev));
283
284         /* fixup necessary chip/core configurations */
285         if (sii->pub.bustype == PCI_BUS) {
286                 if (SI_FAST(sii)) {
287                         if (!sii->pch) {
288                                 sii->pch = (void *)pcicore_init(
289                                         &sii->pub, sii->pbus,
290                                         (void *)PCIEREGS(sii));
291                                 if (sii->pch == NULL)
292                                         return false;
293                         }
294                 }
295                 if (si_pci_fixcfg(&sii->pub)) {
296                         SI_ERROR(("si_doattach: sb_pci_fixcfg failed\n"));
297                         return false;
298                 }
299         }
300 #endif
301         /* return to the original core */
302         si_setcoreidx(&sii->pub, *origidx);
303
304         return true;
305 }
306
307 static __used void si_nvram_process(si_info_t *sii, char *pvars)
308 {
309         uint w = 0;
310
311         /* get boardtype and boardrev */
312         switch (sii->pub.bustype) {
313         case PCI_BUS:
314                 /* do a pci config read to get subsystem id and subvendor id */
315                 pci_read_config_dword(sii->pbus, PCI_SUBSYSTEM_VENDOR_ID,
316                                       &w);
317                 /* Let nvram variables override subsystem Vend/ID */
318                 sii->pub.boardvendor = (u16)si_getdevpathintvar(&sii->pub,
319                         "boardvendor");
320                 if (sii->pub.boardvendor == 0)
321                         sii->pub.boardvendor = w & 0xffff;
322                 else
323                         SI_ERROR(("Overriding boardvendor: 0x%x instead of 0x%x\n", sii->pub.boardvendor, w & 0xffff));
324                 sii->pub.boardtype = (u16)si_getdevpathintvar(&sii->pub,
325                         "boardtype");
326                 if (sii->pub.boardtype == 0)
327                         sii->pub.boardtype = (w >> 16) & 0xffff;
328                 else
329                         SI_ERROR(("Overriding boardtype: 0x%x instead of 0x%x\n", sii->pub.boardtype, (w >> 16) & 0xffff));
330                 break;
331
332 #ifdef BCMSDIO
333         case SDIO_BUS:
334 #endif
335                 sii->pub.boardvendor = getintvar(pvars, "manfid");
336                 sii->pub.boardtype = getintvar(pvars, "prodid");
337                 break;
338
339 #ifdef BCMSDIO
340         case SPI_BUS:
341                 sii->pub.boardvendor = PCI_VENDOR_ID_BROADCOM;
342                 sii->pub.boardtype = SPI_BOARD;
343                 break;
344 #endif
345
346         case SI_BUS:
347         case JTAG_BUS:
348                 sii->pub.boardvendor = PCI_VENDOR_ID_BROADCOM;
349                 sii->pub.boardtype = getintvar(pvars, "prodid");
350                 if (pvars == NULL || (sii->pub.boardtype == 0)) {
351                         sii->pub.boardtype = getintvar(NULL, "boardtype");
352                         if (sii->pub.boardtype == 0)
353                                 sii->pub.boardtype = 0xffff;
354                 }
355                 break;
356         }
357
358         if (sii->pub.boardtype == 0) {
359                 SI_ERROR(("si_doattach: unknown board type\n"));
360                 ASSERT(sii->pub.boardtype);
361         }
362
363         sii->pub.boardflags = getintvar(pvars, "boardflags");
364 }
365
366 /* this is will make Sonics calls directly, since Sonics is no longer supported in the Si abstraction */
367 /* this has been customized for the bcm 4329 ONLY */
368 #ifdef BRCM_FULLMAC
369 static si_info_t *si_doattach(si_info_t *sii, uint devid,
370                               void *regs, uint bustype, void *pbus,
371                               char **vars, uint *varsz)
372 {
373         struct si_pub *sih = &sii->pub;
374         u32 w, savewin;
375         chipcregs_t *cc;
376         uint origidx;
377
378         ASSERT(GOODREGS(regs));
379
380         memset((unsigned char *) sii, 0, sizeof(si_info_t));
381
382         savewin = 0;
383
384         sih->buscoreidx = BADIDX;
385
386         sii->curmap = regs;
387         sii->pbus = pbus;
388
389         /* find Chipcommon address */
390         cc = (chipcregs_t *) sii->curmap;
391         sih->bustype = bustype;
392
393         /* bus/core/clk setup for register access */
394         if (!si_buscore_prep(sii, bustype, devid, pbus)) {
395                 SI_ERROR(("si_doattach: si_core_clk_prep failed %d\n",
396                           bustype));
397                 return NULL;
398         }
399
400         /* ChipID recognition.
401          *   We assume we can read chipid at offset 0 from the regs arg.
402          *   If we add other chiptypes (or if we need to support old sdio hosts w/o chipcommon),
403          *   some way of recognizing them needs to be added here.
404          */
405         w = R_REG(&cc->chipid);
406         sih->socitype = (w & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
407         /* Might as wll fill in chip id rev & pkg */
408         sih->chip = w & CID_ID_MASK;
409         sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT;
410         sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT;
411
412         if ((sih->chip == BCM4329_CHIP_ID) &&
413                 (sih->chippkg != BCM4329_289PIN_PKG_ID))
414                         sih->chippkg = BCM4329_182PIN_PKG_ID;
415
416         sih->issim = IS_SIM(sih->chippkg);
417
418         /* scan for cores */
419         /* SI_MSG(("Found chip type SB (0x%08x)\n", w)); */
420         sb_scan(&sii->pub, regs, devid);
421
422         /* no cores found, bail out */
423         if (sii->numcores == 0) {
424                 SI_ERROR(("si_doattach: could not find any cores\n"));
425                 return NULL;
426         }
427         /* bus/core/clk setup */
428         origidx = SI_CC_IDX;
429         if (!si_buscore_setup(sii, cc, bustype, savewin, &origidx, regs)) {
430                 SI_ERROR(("si_doattach: si_buscore_setup failed\n"));
431                 goto exit;
432         }
433
434         cc = (chipcregs_t *) si_setcore(sih, CC_CORE_ID, 0);
435         W_REG(&cc->gpiopullup, 0);
436         W_REG(&cc->gpiopulldown, 0);
437         sb_setcoreidx(sih, origidx);
438
439         return sii;
440
441  exit:
442         return NULL;
443 }
444 #else /* BRCM_FULLMAC */
445 static si_info_t *si_doattach(si_info_t *sii, uint devid,
446                               void *regs, uint bustype, void *pbus,
447                               char **vars, uint *varsz)
448 {
449         struct si_pub *sih = &sii->pub;
450         u32 w, savewin;
451         chipcregs_t *cc;
452         char *pvars = NULL;
453         uint origidx;
454
455         ASSERT(GOODREGS(regs));
456
457         memset((unsigned char *) sii, 0, sizeof(si_info_t));
458
459         savewin = 0;
460
461         sih->buscoreidx = BADIDX;
462
463         sii->curmap = regs;
464         sii->pbus = pbus;
465
466         /* check to see if we are a si core mimic'ing a pci core */
467         if (bustype == PCI_BUS) {
468                 pci_read_config_dword(sii->pbus, PCI_SPROM_CONTROL,  &w);
469                 if (w == 0xffffffff) {
470                         SI_ERROR(("%s: incoming bus is PCI but it's a lie, "
471                                 " switching to SI devid:0x%x\n",
472                                 __func__, devid));
473                         bustype = SI_BUS;
474                 }
475         }
476
477         /* find Chipcommon address */
478         if (bustype == PCI_BUS) {
479                 pci_read_config_dword(sii->pbus, PCI_BAR0_WIN, &savewin);
480                 if (!GOODCOREADDR(savewin, SI_ENUM_BASE))
481                         savewin = SI_ENUM_BASE;
482                 pci_write_config_dword(sii->pbus, PCI_BAR0_WIN,
483                                        SI_ENUM_BASE);
484                 cc = (chipcregs_t *) regs;
485         } else {
486                 cc = (chipcregs_t *) REG_MAP(SI_ENUM_BASE, SI_CORE_SIZE);
487         }
488
489         sih->bustype = bustype;
490
491         /* bus/core/clk setup for register access */
492         if (!si_buscore_prep(sii, bustype, devid, pbus)) {
493                 SI_ERROR(("si_doattach: si_core_clk_prep failed %d\n",
494                           bustype));
495                 return NULL;
496         }
497
498         /* ChipID recognition.
499          *   We assume we can read chipid at offset 0 from the regs arg.
500          *   If we add other chiptypes (or if we need to support old sdio hosts w/o chipcommon),
501          *   some way of recognizing them needs to be added here.
502          */
503         w = R_REG(&cc->chipid);
504         sih->socitype = (w & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
505         /* Might as wll fill in chip id rev & pkg */
506         sih->chip = w & CID_ID_MASK;
507         sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT;
508         sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT;
509
510         sih->issim = IS_SIM(sih->chippkg);
511
512         /* scan for cores */
513         if (sii->pub.socitype == SOCI_AI) {
514                 SI_MSG(("Found chip type AI (0x%08x)\n", w));
515                 /* pass chipc address instead of original core base */
516                 ai_scan(&sii->pub, (void *)cc, devid);
517         } else {
518                 SI_ERROR(("Found chip of unknown type (0x%08x)\n", w));
519                 return NULL;
520         }
521         /* no cores found, bail out */
522         if (sii->numcores == 0) {
523                 SI_ERROR(("si_doattach: could not find any cores\n"));
524                 return NULL;
525         }
526         /* bus/core/clk setup */
527         origidx = SI_CC_IDX;
528         if (!si_buscore_setup(sii, cc, bustype, savewin, &origidx, regs)) {
529                 SI_ERROR(("si_doattach: si_buscore_setup failed\n"));
530                 goto exit;
531         }
532
533         /* assume current core is CC */
534         if ((sii->pub.ccrev == 0x25)
535             &&
536             ((sih->chip == BCM43236_CHIP_ID
537               || sih->chip == BCM43235_CHIP_ID
538               || sih->chip == BCM43238_CHIP_ID)
539              && (sii->pub.chiprev <= 2))) {
540
541                 if ((cc->chipstatus & CST43236_BP_CLK) != 0) {
542                         uint clkdiv;
543                         clkdiv = R_REG(&cc->clkdiv);
544                         /* otp_clk_div is even number, 120/14 < 9mhz */
545                         clkdiv = (clkdiv & ~CLKD_OTP) | (14 << CLKD_OTP_SHIFT);
546                         W_REG(&cc->clkdiv, clkdiv);
547                         SI_ERROR(("%s: set clkdiv to %x\n", __func__, clkdiv));
548                 }
549                 udelay(10);
550         }
551
552         /* Init nvram from flash if it exists */
553         nvram_init((void *)&(sii->pub));
554
555         /* Init nvram from sprom/otp if they exist */
556         if (srom_var_init
557             (&sii->pub, bustype, regs, vars, varsz)) {
558                 SI_ERROR(("si_doattach: srom_var_init failed: bad srom\n"));
559                 goto exit;
560         }
561         pvars = vars ? *vars : NULL;
562         si_nvram_process(sii, pvars);
563
564         /* === NVRAM, clock is ready === */
565         cc = (chipcregs_t *) si_setcore(sih, CC_CORE_ID, 0);
566         W_REG(&cc->gpiopullup, 0);
567         W_REG(&cc->gpiopulldown, 0);
568         si_setcoreidx(sih, origidx);
569
570         /* PMU specific initializations */
571         if (PMUCTL_ENAB(sih)) {
572                 u32 xtalfreq;
573                 si_pmu_init(sih);
574                 si_pmu_chip_init(sih);
575                 xtalfreq = getintvar(pvars, "xtalfreq");
576                 /* If xtalfreq var not available, try to measure it */
577                 if (xtalfreq == 0)
578                         xtalfreq = si_pmu_measure_alpclk(sih);
579                 si_pmu_pll_init(sih, xtalfreq);
580                 si_pmu_res_init(sih);
581                 si_pmu_swreg_init(sih);
582         }
583
584         /* setup the GPIO based LED powersave register */
585         w = getintvar(pvars, "leddc");
586         if (w == 0)
587                 w = DEFAULT_GPIOTIMERVAL;
588         si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, gpiotimerval), ~0, w);
589
590         if (PCIE(sii)) {
591                 ASSERT(sii->pch != NULL);
592                 pcicore_attach(sii->pch, pvars, SI_DOATTACH);
593         }
594
595         if ((sih->chip == BCM43224_CHIP_ID) ||
596             (sih->chip == BCM43421_CHIP_ID)) {
597                 /* enable 12 mA drive strenth for 43224 and set chipControl register bit 15 */
598                 if (sih->chiprev == 0) {
599                         SI_MSG(("Applying 43224A0 WARs\n"));
600                         si_corereg(sih, SI_CC_IDX,
601                                    offsetof(chipcregs_t, chipcontrol),
602                                    CCTRL43224_GPIO_TOGGLE,
603                                    CCTRL43224_GPIO_TOGGLE);
604                         si_pmu_chipcontrol(sih, 0, CCTRL_43224A0_12MA_LED_DRIVE,
605                                            CCTRL_43224A0_12MA_LED_DRIVE);
606                 }
607                 if (sih->chiprev >= 1) {
608                         SI_MSG(("Applying 43224B0+ WARs\n"));
609                         si_pmu_chipcontrol(sih, 0, CCTRL_43224B0_12MA_LED_DRIVE,
610                                            CCTRL_43224B0_12MA_LED_DRIVE);
611                 }
612         }
613
614         if (sih->chip == BCM4313_CHIP_ID) {
615                 /* enable 12 mA drive strenth for 4313 and set chipControl register bit 1 */
616                 SI_MSG(("Applying 4313 WARs\n"));
617                 si_pmu_chipcontrol(sih, 0, CCTRL_4313_12MA_LED_DRIVE,
618                                    CCTRL_4313_12MA_LED_DRIVE);
619         }
620
621         if (sih->chip == BCM4331_CHIP_ID) {
622                 /* Enable Ext PA lines depending on chip package option */
623                 si_chipcontrl_epa4331(sih, true);
624         }
625
626         return sii;
627  exit:
628         if (sih->bustype == PCI_BUS) {
629                 if (sii->pch)
630                         pcicore_deinit(sii->pch);
631                 sii->pch = NULL;
632         }
633
634         return NULL;
635 }
636 #endif /* BRCM_FULLMAC */
637
638 /* may be called with core in reset */
639 void si_detach(si_t *sih)
640 {
641         si_info_t *sii;
642         uint idx;
643
644         struct si_pub *si_local = NULL;
645         memcpy(&si_local, &sih, sizeof(si_t **));
646
647         sii = SI_INFO(sih);
648
649         if (sii == NULL)
650                 return;
651
652         if (sih->bustype == SI_BUS)
653                 for (idx = 0; idx < SI_MAXCORES; idx++)
654                         if (sii->regs[idx]) {
655                                 iounmap(sii->regs[idx]);
656                                 sii->regs[idx] = NULL;
657                         }
658
659 #ifndef BRCM_FULLMAC
660         nvram_exit((void *)si_local);   /* free up nvram buffers */
661
662         if (sih->bustype == PCI_BUS) {
663                 if (sii->pch)
664                         pcicore_deinit(sii->pch);
665                 sii->pch = NULL;
666         }
667 #endif
668 #if !defined(BCMBUSTYPE) || (BCMBUSTYPE == SI_BUS)
669         if (sii != &ksii)
670 #endif                          /* !BCMBUSTYPE || (BCMBUSTYPE == SI_BUS) */
671                 kfree(sii);
672 }
673
674 /* register driver interrupt disabling and restoring callback functions */
675 void
676 si_register_intr_callback(si_t *sih, void *intrsoff_fn, void *intrsrestore_fn,
677                           void *intrsenabled_fn, void *intr_arg)
678 {
679         si_info_t *sii;
680
681         sii = SI_INFO(sih);
682         sii->intr_arg = intr_arg;
683         sii->intrsoff_fn = (si_intrsoff_t) intrsoff_fn;
684         sii->intrsrestore_fn = (si_intrsrestore_t) intrsrestore_fn;
685         sii->intrsenabled_fn = (si_intrsenabled_t) intrsenabled_fn;
686         /* save current core id.  when this function called, the current core
687          * must be the core which provides driver functions(il, et, wl, etc.)
688          */
689         sii->dev_coreid = sii->coreid[sii->curidx];
690 }
691
692 void si_deregister_intr_callback(si_t *sih)
693 {
694         si_info_t *sii;
695
696         sii = SI_INFO(sih);
697         sii->intrsoff_fn = NULL;
698 }
699
700 uint si_flag(si_t *sih)
701 {
702         if (sih->socitype == SOCI_AI)
703                 return ai_flag(sih);
704         else {
705                 ASSERT(0);
706                 return 0;
707         }
708 }
709
710 void si_setint(si_t *sih, int siflag)
711 {
712         if (sih->socitype == SOCI_AI)
713                 ai_setint(sih, siflag);
714         else
715                 ASSERT(0);
716 }
717
718 #ifndef BCMSDIO
719 uint si_coreid(si_t *sih)
720 {
721         si_info_t *sii;
722
723         sii = SI_INFO(sih);
724         return sii->coreid[sii->curidx];
725 }
726 #endif
727
728 uint si_coreidx(si_t *sih)
729 {
730         si_info_t *sii;
731
732         sii = SI_INFO(sih);
733         return sii->curidx;
734 }
735
736 bool si_backplane64(si_t *sih)
737 {
738         return (sih->cccaps & CC_CAP_BKPLN64) != 0;
739 }
740
741 #ifndef BCMSDIO
742 uint si_corerev(si_t *sih)
743 {
744         if (sih->socitype == SOCI_AI)
745                 return ai_corerev(sih);
746         else {
747                 ASSERT(0);
748                 return 0;
749         }
750 }
751 #endif
752
753 /* return index of coreid or BADIDX if not found */
754 uint si_findcoreidx(si_t *sih, uint coreid, uint coreunit)
755 {
756         si_info_t *sii;
757         uint found;
758         uint i;
759
760         sii = SI_INFO(sih);
761
762         found = 0;
763
764         for (i = 0; i < sii->numcores; i++)
765                 if (sii->coreid[i] == coreid) {
766                         if (found == coreunit)
767                                 return i;
768                         found++;
769                 }
770
771         return BADIDX;
772 }
773
774 /*
775  * This function changes logical "focus" to the indicated core;
776  * must be called with interrupts off.
777  * Moreover, callers should keep interrupts off during switching out of and back to d11 core
778  */
779 void *si_setcore(si_t *sih, uint coreid, uint coreunit)
780 {
781         uint idx;
782
783         idx = si_findcoreidx(sih, coreid, coreunit);
784         if (!GOODIDX(idx))
785                 return NULL;
786
787         if (sih->socitype == SOCI_AI)
788                 return ai_setcoreidx(sih, idx);
789         else {
790 #ifdef BCMSDIO
791                 return sb_setcoreidx(sih, idx);
792 #else
793                 ASSERT(0);
794                 return NULL;
795 #endif
796         }
797 }
798
799 #ifndef BCMSDIO
800 void *si_setcoreidx(si_t *sih, uint coreidx)
801 {
802         if (sih->socitype == SOCI_AI)
803                 return ai_setcoreidx(sih, coreidx);
804         else {
805                 ASSERT(0);
806                 return NULL;
807         }
808 }
809 #endif
810
811 /* Turn off interrupt as required by sb_setcore, before switch core */
812 void *si_switch_core(si_t *sih, uint coreid, uint *origidx, uint *intr_val)
813 {
814         void *cc;
815         si_info_t *sii;
816
817         sii = SI_INFO(sih);
818
819         if (SI_FAST(sii)) {
820                 /* Overloading the origidx variable to remember the coreid,
821                  * this works because the core ids cannot be confused with
822                  * core indices.
823                  */
824                 *origidx = coreid;
825                 if (coreid == CC_CORE_ID)
826                         return (void *)CCREGS_FAST(sii);
827                 else if (coreid == sih->buscoretype)
828                         return (void *)PCIEREGS(sii);
829         }
830         INTR_OFF(sii, *intr_val);
831         *origidx = sii->curidx;
832         cc = si_setcore(sih, coreid, 0);
833         ASSERT(cc != NULL);
834
835         return cc;
836 }
837
838 /* restore coreidx and restore interrupt */
839 void si_restore_core(si_t *sih, uint coreid, uint intr_val)
840 {
841         si_info_t *sii;
842
843         sii = SI_INFO(sih);
844         if (SI_FAST(sii)
845             && ((coreid == CC_CORE_ID) || (coreid == sih->buscoretype)))
846                 return;
847
848         si_setcoreidx(sih, coreid);
849         INTR_RESTORE(sii, intr_val);
850 }
851
852 u32 si_core_cflags(si_t *sih, u32 mask, u32 val)
853 {
854         if (sih->socitype == SOCI_AI)
855                 return ai_core_cflags(sih, mask, val);
856         else {
857                 ASSERT(0);
858                 return 0;
859         }
860 }
861
862 u32 si_core_sflags(si_t *sih, u32 mask, u32 val)
863 {
864         if (sih->socitype == SOCI_AI)
865                 return ai_core_sflags(sih, mask, val);
866         else {
867                 ASSERT(0);
868                 return 0;
869         }
870 }
871
872 bool si_iscoreup(si_t *sih)
873 {
874         if (sih->socitype == SOCI_AI)
875                 return ai_iscoreup(sih);
876         else {
877 #ifdef BCMSDIO
878                 return sb_iscoreup(sih);
879 #else
880                 ASSERT(0);
881                 return false;
882 #endif
883         }
884 }
885
886 void si_write_wrapperreg(si_t *sih, u32 offset, u32 val)
887 {
888         /* only for 4319, no requirement for SOCI_SB */
889         if (sih->socitype == SOCI_AI) {
890                 ai_write_wrap_reg(sih, offset, val);
891         }
892 }
893
894 uint si_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
895 {
896
897         if (sih->socitype == SOCI_AI)
898                 return ai_corereg(sih, coreidx, regoff, mask, val);
899         else {
900 #ifdef BCMSDIO
901                 return sb_corereg(sih, coreidx, regoff, mask, val);
902 #else
903                 ASSERT(0);
904                 return 0;
905 #endif
906         }
907 }
908
909 void si_core_disable(si_t *sih, u32 bits)
910 {
911
912         if (sih->socitype == SOCI_AI)
913                 ai_core_disable(sih, bits);
914 #ifdef BCMSDIO
915         else
916                 sb_core_disable(sih, bits);
917 #endif
918 }
919
920 void si_core_reset(si_t *sih, u32 bits, u32 resetbits)
921 {
922         if (sih->socitype == SOCI_AI)
923                 ai_core_reset(sih, bits, resetbits);
924 #ifdef BCMSDIO
925         else
926                 sb_core_reset(sih, bits, resetbits);
927 #endif
928 }
929
930 u32 si_alp_clock(si_t *sih)
931 {
932         if (PMUCTL_ENAB(sih))
933                 return si_pmu_alp_clock(sih);
934
935         return ALP_CLOCK;
936 }
937
938 u32 si_ilp_clock(si_t *sih)
939 {
940         if (PMUCTL_ENAB(sih))
941                 return si_pmu_ilp_clock(sih);
942
943         return ILP_CLOCK;
944 }
945
946 /* set chip watchdog reset timer to fire in 'ticks' */
947 #ifdef BRCM_FULLMAC
948 void
949 si_watchdog(si_t *sih, uint ticks)
950 {
951         if (PMUCTL_ENAB(sih)) {
952
953                 if ((sih->chip == BCM4319_CHIP_ID) && (sih->chiprev == 0) &&
954                         (ticks != 0)) {
955                         si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t,
956                         clk_ctl_st), ~0, 0x2);
957                         si_setcore(sih, USB20D_CORE_ID, 0);
958                         si_core_disable(sih, 1);
959                         si_setcore(sih, CC_CORE_ID, 0);
960                 }
961
962                 if (ticks == 1)
963                         ticks = 2;
964                 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pmuwatchdog),
965                         ~0, ticks);
966         } else {
967                 /* instant NMI */
968                 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, watchdog),
969                         ~0, ticks);
970         }
971 }
972 #else
973 void si_watchdog(si_t *sih, uint ticks)
974 {
975         uint nb, maxt;
976
977         if (PMUCTL_ENAB(sih)) {
978
979                 if ((sih->chip == BCM4319_CHIP_ID) &&
980                     (sih->chiprev == 0) && (ticks != 0)) {
981                         si_corereg(sih, SI_CC_IDX,
982                                    offsetof(chipcregs_t, clk_ctl_st), ~0, 0x2);
983                         si_setcore(sih, USB20D_CORE_ID, 0);
984                         si_core_disable(sih, 1);
985                         si_setcore(sih, CC_CORE_ID, 0);
986                 }
987
988                 nb = (sih->ccrev < 26) ? 16 : ((sih->ccrev >= 37) ? 32 : 24);
989                 /* The mips compiler uses the sllv instruction,
990                  * so we specially handle the 32-bit case.
991                  */
992                 if (nb == 32)
993                         maxt = 0xffffffff;
994                 else
995                         maxt = ((1 << nb) - 1);
996
997                 if (ticks == 1)
998                         ticks = 2;
999                 else if (ticks > maxt)
1000                         ticks = maxt;
1001
1002                 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pmuwatchdog),
1003                            ~0, ticks);
1004         } else {
1005                 /* make sure we come up in fast clock mode; or if clearing, clear clock */
1006                 si_clkctl_cc(sih, ticks ? CLK_FAST : CLK_DYNAMIC);
1007                 maxt = (1 << 28) - 1;
1008                 if (ticks > maxt)
1009                         ticks = maxt;
1010
1011                 si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, watchdog), ~0,
1012                            ticks);
1013         }
1014 }
1015 #endif
1016
1017 /* return the slow clock source - LPO, XTAL, or PCI */
1018 static uint si_slowclk_src(si_info_t *sii)
1019 {
1020         chipcregs_t *cc;
1021         u32 val;
1022
1023         ASSERT(SI_FAST(sii) || si_coreid(&sii->pub) == CC_CORE_ID);
1024
1025         if (sii->pub.ccrev < 6) {
1026                 if (sii->pub.bustype == PCI_BUS) {
1027                         pci_read_config_dword(sii->pbus, PCI_GPIO_OUT,
1028                                               &val);
1029                         if (val & PCI_CFG_GPIO_SCS)
1030                                 return SCC_SS_PCI;
1031                 }
1032                 return SCC_SS_XTAL;
1033         } else if (sii->pub.ccrev < 10) {
1034                 cc = (chipcregs_t *) si_setcoreidx(&sii->pub, sii->curidx);
1035                 return R_REG(&cc->slow_clk_ctl) & SCC_SS_MASK;
1036         } else                  /* Insta-clock */
1037                 return SCC_SS_XTAL;
1038 }
1039
1040 /* return the ILP (slowclock) min or max frequency */
1041 static uint si_slowclk_freq(si_info_t *sii, bool max_freq, chipcregs_t *cc)
1042 {
1043         u32 slowclk;
1044         uint div;
1045
1046         ASSERT(SI_FAST(sii) || si_coreid(&sii->pub) == CC_CORE_ID);
1047
1048         /* shouldn't be here unless we've established the chip has dynamic clk control */
1049         ASSERT(R_REG(&cc->capabilities) & CC_CAP_PWR_CTL);
1050
1051         slowclk = si_slowclk_src(sii);
1052         if (sii->pub.ccrev < 6) {
1053                 if (slowclk == SCC_SS_PCI)
1054                         return max_freq ? (PCIMAXFREQ / 64)
1055                                 : (PCIMINFREQ / 64);
1056                 else
1057                         return max_freq ? (XTALMAXFREQ / 32)
1058                                 : (XTALMINFREQ / 32);
1059         } else if (sii->pub.ccrev < 10) {
1060                 div = 4 *
1061                     (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >>
1062                       SCC_CD_SHIFT) + 1);
1063                 if (slowclk == SCC_SS_LPO)
1064                         return max_freq ? LPOMAXFREQ : LPOMINFREQ;
1065                 else if (slowclk == SCC_SS_XTAL)
1066                         return max_freq ? (XTALMAXFREQ / div)
1067                                 : (XTALMINFREQ / div);
1068                 else if (slowclk == SCC_SS_PCI)
1069                         return max_freq ? (PCIMAXFREQ / div)
1070                                 : (PCIMINFREQ / div);
1071                 else
1072                         ASSERT(0);
1073         } else {
1074                 /* Chipc rev 10 is InstaClock */
1075                 div = R_REG(&cc->system_clk_ctl) >> SYCC_CD_SHIFT;
1076                 div = 4 * (div + 1);
1077                 return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);
1078         }
1079         return 0;
1080 }
1081
1082 static void si_clkctl_setdelay(si_info_t *sii, void *chipcregs)
1083 {
1084         chipcregs_t *cc = (chipcregs_t *) chipcregs;
1085         uint slowmaxfreq, pll_delay, slowclk;
1086         uint pll_on_delay, fref_sel_delay;
1087
1088         pll_delay = PLL_DELAY;
1089
1090         /* If the slow clock is not sourced by the xtal then add the xtal_on_delay
1091          * since the xtal will also be powered down by dynamic clk control logic.
1092          */
1093
1094         slowclk = si_slowclk_src(sii);
1095         if (slowclk != SCC_SS_XTAL)
1096                 pll_delay += XTAL_ON_DELAY;
1097
1098         /* Starting with 4318 it is ILP that is used for the delays */
1099         slowmaxfreq =
1100             si_slowclk_freq(sii, (sii->pub.ccrev >= 10) ? false : true, cc);
1101
1102         pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
1103         fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
1104
1105         W_REG(&cc->pll_on_delay, pll_on_delay);
1106         W_REG(&cc->fref_sel_delay, fref_sel_delay);
1107 }
1108
1109 /* initialize power control delay registers */
1110 void si_clkctl_init(si_t *sih)
1111 {
1112         si_info_t *sii;
1113         uint origidx = 0;
1114         chipcregs_t *cc;
1115         bool fast;
1116
1117         if (!CCCTL_ENAB(sih))
1118                 return;
1119
1120         sii = SI_INFO(sih);
1121         fast = SI_FAST(sii);
1122         if (!fast) {
1123                 origidx = sii->curidx;
1124                 cc = (chipcregs_t *) si_setcore(sih, CC_CORE_ID, 0);
1125                 if (cc == NULL)
1126                         return;
1127         } else {
1128                 cc = (chipcregs_t *) CCREGS_FAST(sii);
1129                 if (cc == NULL)
1130                         return;
1131         }
1132         ASSERT(cc != NULL);
1133
1134         /* set all Instaclk chip ILP to 1 MHz */
1135         if (sih->ccrev >= 10)
1136                 SET_REG(&cc->system_clk_ctl, SYCC_CD_MASK,
1137                         (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
1138
1139         si_clkctl_setdelay(sii, (void *)cc);
1140
1141         if (!fast)
1142                 si_setcoreidx(sih, origidx);
1143 }
1144
1145 /* return the value suitable for writing to the dot11 core FAST_PWRUP_DELAY register */
1146 u16 si_clkctl_fast_pwrup_delay(si_t *sih)
1147 {
1148         si_info_t *sii;
1149         uint origidx = 0;
1150         chipcregs_t *cc;
1151         uint slowminfreq;
1152         u16 fpdelay;
1153         uint intr_val = 0;
1154         bool fast;
1155
1156         sii = SI_INFO(sih);
1157         if (PMUCTL_ENAB(sih)) {
1158                 INTR_OFF(sii, intr_val);
1159                 fpdelay = si_pmu_fast_pwrup_delay(sih);
1160                 INTR_RESTORE(sii, intr_val);
1161                 return fpdelay;
1162         }
1163
1164         if (!CCCTL_ENAB(sih))
1165                 return 0;
1166
1167         fast = SI_FAST(sii);
1168         fpdelay = 0;
1169         if (!fast) {
1170                 origidx = sii->curidx;
1171                 INTR_OFF(sii, intr_val);
1172                 cc = (chipcregs_t *) si_setcore(sih, CC_CORE_ID, 0);
1173                 if (cc == NULL)
1174                         goto done;
1175         } else {
1176                 cc = (chipcregs_t *) CCREGS_FAST(sii);
1177                 if (cc == NULL)
1178                         goto done;
1179         }
1180         ASSERT(cc != NULL);
1181
1182         slowminfreq = si_slowclk_freq(sii, false, cc);
1183         fpdelay = (((R_REG(&cc->pll_on_delay) + 2) * 1000000) +
1184                    (slowminfreq - 1)) / slowminfreq;
1185
1186  done:
1187         if (!fast) {
1188                 si_setcoreidx(sih, origidx);
1189                 INTR_RESTORE(sii, intr_val);
1190         }
1191         return fpdelay;
1192 }
1193
1194 /* turn primary xtal and/or pll off/on */
1195 int si_clkctl_xtal(si_t *sih, uint what, bool on)
1196 {
1197         si_info_t *sii;
1198         u32 in, out, outen;
1199
1200         sii = SI_INFO(sih);
1201
1202         switch (sih->bustype) {
1203
1204 #ifdef BCMSDIO
1205         case SDIO_BUS:
1206                 return -1;
1207 #endif                          /* BCMSDIO */
1208
1209         case PCI_BUS:
1210                 /* pcie core doesn't have any mapping to control the xtal pu */
1211                 if (PCIE(sii))
1212                         return -1;
1213
1214                 pci_read_config_dword(sii->pbus, PCI_GPIO_IN, &in);
1215                 pci_read_config_dword(sii->pbus, PCI_GPIO_OUT, &out);
1216                 pci_read_config_dword(sii->pbus, PCI_GPIO_OUTEN, &outen);
1217
1218                 /*
1219                  * Avoid glitching the clock if GPRS is already using it.
1220                  * We can't actually read the state of the PLLPD so we infer it
1221                  * by the value of XTAL_PU which *is* readable via gpioin.
1222                  */
1223                 if (on && (in & PCI_CFG_GPIO_XTAL))
1224                         return 0;
1225
1226                 if (what & XTAL)
1227                         outen |= PCI_CFG_GPIO_XTAL;
1228                 if (what & PLL)
1229                         outen |= PCI_CFG_GPIO_PLL;
1230
1231                 if (on) {
1232                         /* turn primary xtal on */
1233                         if (what & XTAL) {
1234                                 out |= PCI_CFG_GPIO_XTAL;
1235                                 if (what & PLL)
1236                                         out |= PCI_CFG_GPIO_PLL;
1237                                 pci_write_config_dword(sii->pbus,
1238                                                        PCI_GPIO_OUT, out);
1239                                 pci_write_config_dword(sii->pbus,
1240                                                        PCI_GPIO_OUTEN, outen);
1241                                 udelay(XTAL_ON_DELAY);
1242                         }
1243
1244                         /* turn pll on */
1245                         if (what & PLL) {
1246                                 out &= ~PCI_CFG_GPIO_PLL;
1247                                 pci_write_config_dword(sii->pbus,
1248                                                        PCI_GPIO_OUT, out);
1249                                 mdelay(2);
1250                         }
1251                 } else {
1252                         if (what & XTAL)
1253                                 out &= ~PCI_CFG_GPIO_XTAL;
1254                         if (what & PLL)
1255                                 out |= PCI_CFG_GPIO_PLL;
1256                         pci_write_config_dword(sii->pbus,
1257                                                PCI_GPIO_OUT, out);
1258                         pci_write_config_dword(sii->pbus,
1259                                                PCI_GPIO_OUTEN, outen);
1260                 }
1261
1262         default:
1263                 return -1;
1264         }
1265
1266         return 0;
1267 }
1268
1269 /*
1270  *  clock control policy function through chipcommon
1271  *
1272  *    set dynamic clk control mode (forceslow, forcefast, dynamic)
1273  *    returns true if we are forcing fast clock
1274  *    this is a wrapper over the next internal function
1275  *      to allow flexible policy settings for outside caller
1276  */
1277 bool si_clkctl_cc(si_t *sih, uint mode)
1278 {
1279         si_info_t *sii;
1280
1281         sii = SI_INFO(sih);
1282
1283         /* chipcommon cores prior to rev6 don't support dynamic clock control */
1284         if (sih->ccrev < 6)
1285                 return false;
1286
1287         if (PCI_FORCEHT(sii))
1288                 return mode == CLK_FAST;
1289
1290         return _si_clkctl_cc(sii, mode);
1291 }
1292
1293 /* clk control mechanism through chipcommon, no policy checking */
1294 static bool _si_clkctl_cc(si_info_t *sii, uint mode)
1295 {
1296         uint origidx = 0;
1297         chipcregs_t *cc;
1298         u32 scc;
1299         uint intr_val = 0;
1300         bool fast = SI_FAST(sii);
1301
1302         /* chipcommon cores prior to rev6 don't support dynamic clock control */
1303         if (sii->pub.ccrev < 6)
1304                 return false;
1305
1306         /* Chips with ccrev 10 are EOL and they don't have SYCC_HR which we use below */
1307         ASSERT(sii->pub.ccrev != 10);
1308
1309         if (!fast) {
1310                 INTR_OFF(sii, intr_val);
1311                 origidx = sii->curidx;
1312
1313                 if ((sii->pub.bustype == SI_BUS) &&
1314                     si_setcore(&sii->pub, MIPS33_CORE_ID, 0) &&
1315                     (si_corerev(&sii->pub) <= 7) && (sii->pub.ccrev >= 10))
1316                         goto done;
1317
1318                 cc = (chipcregs_t *) si_setcore(&sii->pub, CC_CORE_ID, 0);
1319         } else {
1320                 cc = (chipcregs_t *) CCREGS_FAST(sii);
1321                 if (cc == NULL)
1322                         goto done;
1323         }
1324         ASSERT(cc != NULL);
1325
1326         if (!CCCTL_ENAB(&sii->pub) && (sii->pub.ccrev < 20))
1327                 goto done;
1328
1329         switch (mode) {
1330         case CLK_FAST:          /* FORCEHT, fast (pll) clock */
1331                 if (sii->pub.ccrev < 10) {
1332                         /* don't forget to force xtal back on before we clear SCC_DYN_XTAL.. */
1333                         si_clkctl_xtal(&sii->pub, XTAL, ON);
1334                         SET_REG(&cc->slow_clk_ctl,
1335                                 (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
1336                 } else if (sii->pub.ccrev < 20) {
1337                         OR_REG(&cc->system_clk_ctl, SYCC_HR);
1338                 } else {
1339                         OR_REG(&cc->clk_ctl_st, CCS_FORCEHT);
1340                 }
1341
1342                 /* wait for the PLL */
1343                 if (PMUCTL_ENAB(&sii->pub)) {
1344                         u32 htavail = CCS_HTAVAIL;
1345                         SPINWAIT(((R_REG(&cc->clk_ctl_st) & htavail)
1346                                   == 0), PMU_MAX_TRANSITION_DLY);
1347                         ASSERT(R_REG(&cc->clk_ctl_st) & htavail);
1348                 } else {
1349                         udelay(PLL_DELAY);
1350                 }
1351                 break;
1352
1353         case CLK_DYNAMIC:       /* enable dynamic clock control */
1354                 if (sii->pub.ccrev < 10) {
1355                         scc = R_REG(&cc->slow_clk_ctl);
1356                         scc &= ~(SCC_FS | SCC_IP | SCC_XC);
1357                         if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
1358                                 scc |= SCC_XC;
1359                         W_REG(&cc->slow_clk_ctl, scc);
1360
1361                         /* for dynamic control, we have to release our xtal_pu "force on" */
1362                         if (scc & SCC_XC)
1363                                 si_clkctl_xtal(&sii->pub, XTAL, OFF);
1364                 } else if (sii->pub.ccrev < 20) {
1365                         /* Instaclock */
1366                         AND_REG(&cc->system_clk_ctl, ~SYCC_HR);
1367                 } else {
1368                         AND_REG(&cc->clk_ctl_st, ~CCS_FORCEHT);
1369                 }
1370                 break;
1371
1372         default:
1373                 ASSERT(0);
1374         }
1375
1376  done:
1377         if (!fast) {
1378                 si_setcoreidx(&sii->pub, origidx);
1379                 INTR_RESTORE(sii, intr_val);
1380         }
1381         return mode == CLK_FAST;
1382 }
1383
1384 /* Build device path. Support SI, PCI, and JTAG for now. */
1385 int si_devpath(si_t *sih, char *path, int size)
1386 {
1387         int slen;
1388
1389         ASSERT(path != NULL);
1390         ASSERT(size >= SI_DEVPATH_BUFSZ);
1391
1392         if (!path || size <= 0)
1393                 return -1;
1394
1395         switch (sih->bustype) {
1396         case SI_BUS:
1397         case JTAG_BUS:
1398                 slen = snprintf(path, (size_t) size, "sb/%u/", si_coreidx(sih));
1399                 break;
1400         case PCI_BUS:
1401                 ASSERT((SI_INFO(sih))->pbus != NULL);
1402                 slen = snprintf(path, (size_t) size, "pci/%u/%u/",
1403                         ((struct pci_dev *)((SI_INFO(sih))->pbus))->bus->number,
1404                         PCI_SLOT(
1405                             ((struct pci_dev *)((SI_INFO(sih))->pbus))->devfn));
1406                 break;
1407
1408 #ifdef BCMSDIO
1409         case SDIO_BUS:
1410                 SI_ERROR(("si_devpath: device 0 assumed\n"));
1411                 slen = snprintf(path, (size_t) size, "sd/%u/", si_coreidx(sih));
1412                 break;
1413 #endif
1414         default:
1415                 slen = -1;
1416                 ASSERT(0);
1417                 break;
1418         }
1419
1420         if (slen < 0 || slen >= size) {
1421                 path[0] = '\0';
1422                 return -1;
1423         }
1424
1425         return 0;
1426 }
1427
1428 /* Get a variable, but only if it has a devpath prefix */
1429 char *si_getdevpathvar(si_t *sih, const char *name)
1430 {
1431         char varname[SI_DEVPATH_BUFSZ + 32];
1432
1433         si_devpathvar(sih, varname, sizeof(varname), name);
1434
1435         return getvar(NULL, varname);
1436 }
1437
1438 /* Get a variable, but only if it has a devpath prefix */
1439 int si_getdevpathintvar(si_t *sih, const char *name)
1440 {
1441 #if defined(BCMBUSTYPE) && (BCMBUSTYPE == SI_BUS)
1442         return getintvar(NULL, name);
1443 #else
1444         char varname[SI_DEVPATH_BUFSZ + 32];
1445
1446         si_devpathvar(sih, varname, sizeof(varname), name);
1447
1448         return getintvar(NULL, varname);
1449 #endif
1450 }
1451
1452 char *si_getnvramflvar(si_t *sih, const char *name)
1453 {
1454         return getvar(NULL, name);
1455 }
1456
1457 /* Concatenate the dev path with a varname into the given 'var' buffer
1458  * and return the 'var' pointer.
1459  * Nothing is done to the arguments if len == 0 or var is NULL, var is still returned.
1460  * On overflow, the first char will be set to '\0'.
1461  */
1462 static char *si_devpathvar(si_t *sih, char *var, int len, const char *name)
1463 {
1464         uint path_len;
1465
1466         if (!var || len <= 0)
1467                 return var;
1468
1469         if (si_devpath(sih, var, len) == 0) {
1470                 path_len = strlen(var);
1471
1472                 if (strlen(name) + 1 > (uint) (len - path_len))
1473                         var[0] = '\0';
1474                 else
1475                         strncpy(var + path_len, name, len - path_len - 1);
1476         }
1477
1478         return var;
1479 }
1480
1481 /* return true if PCIE capability exists in the pci config space */
1482 static __used bool si_ispcie(si_info_t *sii)
1483 {
1484         u8 cap_ptr;
1485
1486         if (sii->pub.bustype != PCI_BUS)
1487                 return false;
1488
1489         cap_ptr = pcicore_find_pci_capability(sii->pbus, PCI_CAP_ID_EXP, NULL,
1490                                               NULL);
1491         if (!cap_ptr)
1492                 return false;
1493
1494         return true;
1495 }
1496
1497 #ifdef BCMSDIO
1498 /* initialize the sdio core */
1499 void si_sdio_init(si_t *sih)
1500 {
1501         si_info_t *sii = SI_INFO(sih);
1502
1503         if (((sih->buscoretype == PCMCIA_CORE_ID) && (sih->buscorerev >= 8)) ||
1504             (sih->buscoretype == SDIOD_CORE_ID)) {
1505                 uint idx;
1506                 sdpcmd_regs_t *sdpregs;
1507
1508                 /* get the current core index */
1509                 idx = sii->curidx;
1510                 ASSERT(idx == si_findcoreidx(sih, D11_CORE_ID, 0));
1511
1512                 /* switch to sdio core */
1513                 sdpregs = (sdpcmd_regs_t *) si_setcore(sih, PCMCIA_CORE_ID, 0);
1514                 if (!sdpregs)
1515                         sdpregs =
1516                             (sdpcmd_regs_t *) si_setcore(sih, SDIOD_CORE_ID, 0);
1517                 ASSERT(sdpregs);
1518
1519                 SI_MSG(("si_sdio_init: For PCMCIA/SDIO Corerev %d, enable ints from core %d " "through SD core %d (%p)\n", sih->buscorerev, idx, sii->curidx, sdpregs));
1520
1521                 /* enable backplane error and core interrupts */
1522                 W_REG(&sdpregs->hostintmask, I_SBINT);
1523                 W_REG(&sdpregs->sbintmask,
1524                       (I_SB_SERR | I_SB_RESPERR | (1 << idx)));
1525
1526                 /* switch back to previous core */
1527                 si_setcoreidx(sih, idx);
1528         }
1529
1530         /* enable interrupts */
1531         bcmsdh_intr_enable(sii->pbus);
1532
1533 }
1534 #endif                          /* BCMSDIO */
1535
1536 bool si_pci_war16165(si_t *sih)
1537 {
1538         si_info_t *sii;
1539
1540         sii = SI_INFO(sih);
1541
1542         return PCI(sii) && (sih->buscorerev <= 10);
1543 }
1544
1545 void si_pci_up(si_t *sih)
1546 {
1547         si_info_t *sii;
1548
1549         sii = SI_INFO(sih);
1550
1551         /* if not pci bus, we're done */
1552         if (sih->bustype != PCI_BUS)
1553                 return;
1554
1555         if (PCI_FORCEHT(sii))
1556                 _si_clkctl_cc(sii, CLK_FAST);
1557
1558         if (PCIE(sii))
1559                 pcicore_up(sii->pch, SI_PCIUP);
1560
1561 }
1562
1563 /* Unconfigure and/or apply various WARs when system is going to sleep mode */
1564 void si_pci_sleep(si_t *sih)
1565 {
1566         si_info_t *sii;
1567
1568         sii = SI_INFO(sih);
1569
1570         pcicore_sleep(sii->pch);
1571 }
1572
1573 /* Unconfigure and/or apply various WARs when going down */
1574 void si_pci_down(si_t *sih)
1575 {
1576         si_info_t *sii;
1577
1578         sii = SI_INFO(sih);
1579
1580         /* if not pci bus, we're done */
1581         if (sih->bustype != PCI_BUS)
1582                 return;
1583
1584         /* release FORCEHT since chip is going to "down" state */
1585         if (PCI_FORCEHT(sii))
1586                 _si_clkctl_cc(sii, CLK_DYNAMIC);
1587
1588         pcicore_down(sii->pch, SI_PCIDOWN);
1589 }
1590
1591 /*
1592  * Configure the pci core for pci client (NIC) action
1593  * coremask is the bitvec of cores by index to be enabled.
1594  */
1595 void si_pci_setup(si_t *sih, uint coremask)
1596 {
1597         si_info_t *sii;
1598         struct sbpciregs *pciregs = NULL;
1599         u32 siflag = 0, w;
1600         uint idx = 0;
1601
1602         sii = SI_INFO(sih);
1603
1604         if (sii->pub.bustype != PCI_BUS)
1605                 return;
1606
1607         ASSERT(PCI(sii) || PCIE(sii));
1608         ASSERT(sii->pub.buscoreidx != BADIDX);
1609
1610         if (PCI(sii)) {
1611                 /* get current core index */
1612                 idx = sii->curidx;
1613
1614                 /* we interrupt on this backplane flag number */
1615                 siflag = si_flag(sih);
1616
1617                 /* switch over to pci core */
1618                 pciregs = (struct sbpciregs *)si_setcoreidx(sih, sii->pub.buscoreidx);
1619         }
1620
1621         /*
1622          * Enable sb->pci interrupts.  Assume
1623          * PCI rev 2.3 support was added in pci core rev 6 and things changed..
1624          */
1625         if (PCIE(sii) || (PCI(sii) && ((sii->pub.buscorerev) >= 6))) {
1626                 /* pci config write to set this core bit in PCIIntMask */
1627                 pci_read_config_dword(sii->pbus, PCI_INT_MASK, &w);
1628                 w |= (coremask << PCI_SBIM_SHIFT);
1629                 pci_write_config_dword(sii->pbus, PCI_INT_MASK, w);
1630         } else {
1631                 /* set sbintvec bit for our flag number */
1632                 si_setint(sih, siflag);
1633         }
1634
1635         if (PCI(sii)) {
1636                 OR_REG(&pciregs->sbtopci2,
1637                        (SBTOPCI_PREF | SBTOPCI_BURST));
1638                 if (sii->pub.buscorerev >= 11) {
1639                         OR_REG(&pciregs->sbtopci2,
1640                                SBTOPCI_RC_READMULTI);
1641                         w = R_REG(&pciregs->clkrun);
1642                         W_REG(&pciregs->clkrun,
1643                               (w | PCI_CLKRUN_DSBL));
1644                         w = R_REG(&pciregs->clkrun);
1645                 }
1646
1647                 /* switch back to previous core */
1648                 si_setcoreidx(sih, idx);
1649         }
1650 }
1651
1652 /*
1653  * Fixup SROMless PCI device's configuration.
1654  * The current core may be changed upon return.
1655  */
1656 int si_pci_fixcfg(si_t *sih)
1657 {
1658         uint origidx, pciidx;
1659         struct sbpciregs *pciregs = NULL;
1660         sbpcieregs_t *pcieregs = NULL;
1661         void *regs = NULL;
1662         u16 val16, *reg16 = NULL;
1663
1664         si_info_t *sii = SI_INFO(sih);
1665
1666         ASSERT(sii->pub.bustype == PCI_BUS);
1667
1668         /* Fixup PI in SROM shadow area to enable the correct PCI core access */
1669         /* save the current index */
1670         origidx = si_coreidx(&sii->pub);
1671
1672         /* check 'pi' is correct and fix it if not */
1673         if (sii->pub.buscoretype == PCIE_CORE_ID) {
1674                 pcieregs =
1675                     (sbpcieregs_t *) si_setcore(&sii->pub, PCIE_CORE_ID, 0);
1676                 regs = pcieregs;
1677                 ASSERT(pcieregs != NULL);
1678                 reg16 = &pcieregs->sprom[SRSH_PI_OFFSET];
1679         } else if (sii->pub.buscoretype == PCI_CORE_ID) {
1680                 pciregs = (struct sbpciregs *)si_setcore(&sii->pub, PCI_CORE_ID, 0);
1681                 regs = pciregs;
1682                 ASSERT(pciregs != NULL);
1683                 reg16 = &pciregs->sprom[SRSH_PI_OFFSET];
1684         }
1685         pciidx = si_coreidx(&sii->pub);
1686         val16 = R_REG(reg16);
1687         if (((val16 & SRSH_PI_MASK) >> SRSH_PI_SHIFT) != (u16) pciidx) {
1688                 val16 =
1689                     (u16) (pciidx << SRSH_PI_SHIFT) | (val16 &
1690                                                           ~SRSH_PI_MASK);
1691                 W_REG(reg16, val16);
1692         }
1693
1694         /* restore the original index */
1695         si_setcoreidx(&sii->pub, origidx);
1696
1697         pcicore_hwup(sii->pch);
1698         return 0;
1699 }
1700
1701 /* mask&set gpiocontrol bits */
1702 u32 si_gpiocontrol(si_t *sih, u32 mask, u32 val, u8 priority)
1703 {
1704         uint regoff;
1705
1706         regoff = 0;
1707
1708         /* gpios could be shared on router platforms
1709          * ignore reservation if it's high priority (e.g., test apps)
1710          */
1711         if ((priority != GPIO_HI_PRIORITY) &&
1712             (sih->bustype == SI_BUS) && (val || mask)) {
1713                 mask = priority ? (si_gpioreservation & mask) :
1714                     ((si_gpioreservation | mask) & ~(si_gpioreservation));
1715                 val &= mask;
1716         }
1717
1718         regoff = offsetof(chipcregs_t, gpiocontrol);
1719         return si_corereg(sih, SI_CC_IDX, regoff, mask, val);
1720 }
1721
1722 /* Return the size of the specified SOCRAM bank */
1723 static uint
1724 socram_banksize(si_info_t *sii, sbsocramregs_t *regs, u8 index,
1725                 u8 mem_type)
1726 {
1727         uint banksize, bankinfo;
1728         uint bankidx = index | (mem_type << SOCRAM_BANKIDX_MEMTYPE_SHIFT);
1729
1730         ASSERT(mem_type <= SOCRAM_MEMTYPE_DEVRAM);
1731
1732         W_REG(&regs->bankidx, bankidx);
1733         bankinfo = R_REG(&regs->bankinfo);
1734         banksize =
1735             SOCRAM_BANKINFO_SZBASE * ((bankinfo & SOCRAM_BANKINFO_SZMASK) + 1);
1736         return banksize;
1737 }
1738
1739 /* Return the RAM size of the SOCRAM core */
1740 u32 si_socram_size(si_t *sih)
1741 {
1742         si_info_t *sii;
1743         uint origidx;
1744         uint intr_val = 0;
1745
1746         sbsocramregs_t *regs;
1747         bool wasup;
1748         uint corerev;
1749         u32 coreinfo;
1750         uint memsize = 0;
1751
1752         sii = SI_INFO(sih);
1753
1754         /* Block ints and save current core */
1755         INTR_OFF(sii, intr_val);
1756         origidx = si_coreidx(sih);
1757
1758         /* Switch to SOCRAM core */
1759         regs = si_setcore(sih, SOCRAM_CORE_ID, 0);
1760         if (!regs)
1761                 goto done;
1762
1763         /* Get info for determining size */
1764         wasup = si_iscoreup(sih);
1765         if (!wasup)
1766                 si_core_reset(sih, 0, 0);
1767         corerev = si_corerev(sih);
1768         coreinfo = R_REG(&regs->coreinfo);
1769
1770         /* Calculate size from coreinfo based on rev */
1771         if (corerev == 0)
1772                 memsize = 1 << (16 + (coreinfo & SRCI_MS0_MASK));
1773         else if (corerev < 3) {
1774                 memsize = 1 << (SR_BSZ_BASE + (coreinfo & SRCI_SRBSZ_MASK));
1775                 memsize *= (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
1776         } else if ((corerev <= 7) || (corerev == 12)) {
1777                 uint nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
1778                 uint bsz = (coreinfo & SRCI_SRBSZ_MASK);
1779                 uint lss = (coreinfo & SRCI_LSS_MASK) >> SRCI_LSS_SHIFT;
1780                 if (lss != 0)
1781                         nb--;
1782                 memsize = nb * (1 << (bsz + SR_BSZ_BASE));
1783                 if (lss != 0)
1784                         memsize += (1 << ((lss - 1) + SR_BSZ_BASE));
1785         } else {
1786                 u8 i;
1787                 uint nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT;
1788                 for (i = 0; i < nb; i++)
1789                         memsize +=
1790                             socram_banksize(sii, regs, i, SOCRAM_MEMTYPE_RAM);
1791         }
1792
1793         /* Return to previous state and core */
1794         if (!wasup)
1795                 si_core_disable(sih, 0);
1796         si_setcoreidx(sih, origidx);
1797
1798  done:
1799         INTR_RESTORE(sii, intr_val);
1800
1801         return memsize;
1802 }
1803
1804 void si_chipcontrl_epa4331(si_t *sih, bool on)
1805 {
1806         si_info_t *sii;
1807         chipcregs_t *cc;
1808         uint origidx;
1809         u32 val;
1810
1811         sii = SI_INFO(sih);
1812         origidx = si_coreidx(sih);
1813
1814         cc = (chipcregs_t *) si_setcore(sih, CC_CORE_ID, 0);
1815
1816         val = R_REG(&cc->chipcontrol);
1817
1818         if (on) {
1819                 if (sih->chippkg == 9 || sih->chippkg == 0xb) {
1820                         /* Ext PA Controls for 4331 12x9 Package */
1821                         W_REG(&cc->chipcontrol, val |
1822                               (CCTRL4331_EXTPA_EN |
1823                                CCTRL4331_EXTPA_ON_GPIO2_5));
1824                 } else {
1825                         /* Ext PA Controls for 4331 12x12 Package */
1826                         W_REG(&cc->chipcontrol,
1827                               val | (CCTRL4331_EXTPA_EN));
1828                 }
1829         } else {
1830                 val &= ~(CCTRL4331_EXTPA_EN | CCTRL4331_EXTPA_ON_GPIO2_5);
1831                 W_REG(&cc->chipcontrol, val);
1832         }
1833
1834         si_setcoreidx(sih, origidx);
1835 }
1836
1837 /* Enable BT-COEX & Ex-PA for 4313 */
1838 void si_epa_4313war(si_t *sih)
1839 {
1840         si_info_t *sii;
1841         chipcregs_t *cc;
1842         uint origidx;
1843
1844         sii = SI_INFO(sih);
1845         origidx = si_coreidx(sih);
1846
1847         cc = (chipcregs_t *) si_setcore(sih, CC_CORE_ID, 0);
1848
1849         /* EPA Fix */
1850         W_REG(&cc->gpiocontrol,
1851               R_REG(&cc->gpiocontrol) | GPIO_CTRL_EPA_EN_MASK);
1852
1853         si_setcoreidx(sih, origidx);
1854 }
1855
1856 /* check if the device is removed */
1857 bool si_deviceremoved(si_t *sih)
1858 {
1859         u32 w;
1860         si_info_t *sii;
1861
1862         sii = SI_INFO(sih);
1863
1864         switch (sih->bustype) {
1865         case PCI_BUS:
1866                 ASSERT(sii->pbus != NULL);
1867                 pci_read_config_dword(sii->pbus, PCI_VENDOR_ID, &w);
1868                 if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)
1869                         return true;
1870                 break;
1871         }
1872         return false;
1873 }
1874
1875 bool si_is_sprom_available(si_t *sih)
1876 {
1877         if (sih->ccrev >= 31) {
1878                 si_info_t *sii;
1879                 uint origidx;
1880                 chipcregs_t *cc;
1881                 u32 sromctrl;
1882
1883                 if ((sih->cccaps & CC_CAP_SROM) == 0)
1884                         return false;
1885
1886                 sii = SI_INFO(sih);
1887                 origidx = sii->curidx;
1888                 cc = si_setcoreidx(sih, SI_CC_IDX);
1889                 sromctrl = R_REG(&cc->sromcontrol);
1890                 si_setcoreidx(sih, origidx);
1891                 return sromctrl & SRC_PRESENT;
1892         }
1893
1894         switch (sih->chip) {
1895         case BCM4329_CHIP_ID:
1896                 return (sih->chipst & CST4329_SPROM_SEL) != 0;
1897         case BCM4319_CHIP_ID:
1898                 return (sih->chipst & CST4319_SPROM_SEL) != 0;
1899         case BCM4336_CHIP_ID:
1900                 return (sih->chipst & CST4336_SPROM_PRESENT) != 0;
1901         case BCM4330_CHIP_ID:
1902                 return (sih->chipst & CST4330_SPROM_PRESENT) != 0;
1903         case BCM4313_CHIP_ID:
1904                 return (sih->chipst & CST4313_SPROM_PRESENT) != 0;
1905         case BCM4331_CHIP_ID:
1906                 return (sih->chipst & CST4331_SPROM_PRESENT) != 0;
1907         default:
1908                 return true;
1909         }
1910 }
1911
1912 bool si_is_otp_disabled(si_t *sih)
1913 {
1914         switch (sih->chip) {
1915         case BCM4329_CHIP_ID:
1916                 return (sih->chipst & CST4329_SPROM_OTP_SEL_MASK) ==
1917                     CST4329_OTP_PWRDN;
1918         case BCM4319_CHIP_ID:
1919                 return (sih->chipst & CST4319_SPROM_OTP_SEL_MASK) ==
1920                     CST4319_OTP_PWRDN;
1921         case BCM4336_CHIP_ID:
1922                 return (sih->chipst & CST4336_OTP_PRESENT) == 0;
1923         case BCM4330_CHIP_ID:
1924                 return (sih->chipst & CST4330_OTP_PRESENT) == 0;
1925         case BCM4313_CHIP_ID:
1926                 return (sih->chipst & CST4313_OTP_PRESENT) == 0;
1927                 /* These chips always have their OTP on */
1928         case BCM43224_CHIP_ID:
1929         case BCM43225_CHIP_ID:
1930         case BCM43421_CHIP_ID:
1931         case BCM43235_CHIP_ID:
1932         case BCM43236_CHIP_ID:
1933         case BCM43238_CHIP_ID:
1934         case BCM4331_CHIP_ID:
1935         default:
1936                 return false;
1937         }
1938 }
1939
1940 bool si_is_otp_powered(si_t *sih)
1941 {
1942         if (PMUCTL_ENAB(sih))
1943                 return si_pmu_is_otp_powered(sih);
1944         return true;
1945 }
1946
1947 void si_otp_power(si_t *sih, bool on)
1948 {
1949         if (PMUCTL_ENAB(sih))
1950                 si_pmu_otp_power(sih, on);
1951         udelay(1000);
1952 }
1953