blob: 4361a44774afbd0439c9fddf73a8d0b3529a53ba [file] [log] [blame]
Dmitry Shmidt8ce17272011-05-24 11:14:33 -07001/*
2 * Misc utility routines for accessing chip-specific features
3 * of the SiliconBackplane-based Broadcom chips.
4 *
Dmitry Shmidt83252322012-03-16 12:52:00 -07005 * Copyright (C) 1999-2012, Broadcom Corporation
Dmitry Shmidt8ce17272011-05-24 11:14:33 -07006 *
Dmitry Shmidt83252322012-03-16 12:52:00 -07007 * Unless you and Broadcom execute a separate written software license
Dmitry Shmidt8ce17272011-05-24 11:14:33 -07008 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the "GPL"),
10 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 * following added to such license:
12 *
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions of
17 * the license of that module. An independent module is a module which is not
18 * derived from this software. The special exception does not apply to any
19 * modifications of the software.
20 *
21 * Notwithstanding the above, under no circumstances may you combine this
22 * software in any way with any other Broadcom software provided under a license
23 * other than the GPL, without Broadcom's express prior written consent.
24 *
Dmitry Shmidt83252322012-03-16 12:52:00 -070025 * $Id: aiutils.c 309193 2012-01-19 00:03:57Z $
Dmitry Shmidt8ce17272011-05-24 11:14:33 -070026 */
Dmitry Shmidt83252322012-03-16 12:52:00 -070027#include <bcm_cfg.h>
Dmitry Shmidt8ce17272011-05-24 11:14:33 -070028#include <typedefs.h>
29#include <bcmdefs.h>
30#include <osl.h>
31#include <bcmutils.h>
32#include <siutils.h>
33#include <hndsoc.h>
34#include <sbchipc.h>
35#include <pcicfg.h>
36
37#include "siutils_priv.h"
38
Dmitry Shmidt83252322012-03-16 12:52:00 -070039#define BCM47162_DMP() (0)
40#define BCM5357_DMP() (0)
41#define remap_coreid(sih, coreid) (coreid)
42#define remap_corerev(sih, corerev) (corerev)
Dmitry Shmidt8ce17272011-05-24 11:14:33 -070043
44
45
46static uint32
47get_erom_ent(si_t *sih, uint32 **eromptr, uint32 mask, uint32 match)
48{
49 uint32 ent;
50 uint inv = 0, nom = 0;
51
52 while (TRUE) {
53 ent = R_REG(si_osh(sih), *eromptr);
54 (*eromptr)++;
55
56 if (mask == 0)
57 break;
58
59 if ((ent & ER_VALID) == 0) {
60 inv++;
61 continue;
62 }
63
64 if (ent == (ER_END | ER_VALID))
65 break;
66
67 if ((ent & mask) == match)
68 break;
69
70 nom++;
71 }
72
73 SI_VMSG(("%s: Returning ent 0x%08x\n", __FUNCTION__, ent));
74 if (inv + nom) {
75 SI_VMSG((" after %d invalid and %d non-matching entries\n", inv, nom));
76 }
77 return ent;
78}
79
80static uint32
81get_asd(si_t *sih, uint32 **eromptr, uint sp, uint ad, uint st, uint32 *addrl, uint32 *addrh,
82 uint32 *sizel, uint32 *sizeh)
83{
84 uint32 asd, sz, szd;
85
86 asd = get_erom_ent(sih, eromptr, ER_VALID, ER_VALID);
87 if (((asd & ER_TAG1) != ER_ADD) ||
88 (((asd & AD_SP_MASK) >> AD_SP_SHIFT) != sp) ||
89 ((asd & AD_ST_MASK) != st)) {
90
91 (*eromptr)--;
92 return 0;
93 }
94 *addrl = asd & AD_ADDR_MASK;
95 if (asd & AD_AG32)
96 *addrh = get_erom_ent(sih, eromptr, 0, 0);
97 else
98 *addrh = 0;
99 *sizeh = 0;
100 sz = asd & AD_SZ_MASK;
101 if (sz == AD_SZ_SZD) {
102 szd = get_erom_ent(sih, eromptr, 0, 0);
103 *sizel = szd & SD_SZ_MASK;
104 if (szd & SD_SG32)
105 *sizeh = get_erom_ent(sih, eromptr, 0, 0);
106 } else
107 *sizel = AD_SZ_BASE << (sz >> AD_SZ_SHIFT);
108
109 SI_VMSG((" SP %d, ad %d: st = %d, 0x%08x_0x%08x @ 0x%08x_0x%08x\n",
110 sp, ad, st, *sizeh, *sizel, *addrh, *addrl));
111
112 return asd;
113}
114
115static void
116ai_hwfixup(si_info_t *sii)
117{
118}
119
120
Dmitry Shmidt83252322012-03-16 12:52:00 -0700121
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700122void
123ai_scan(si_t *sih, void *regs, uint devid)
124{
125 si_info_t *sii = SI_INFO(sih);
126 chipcregs_t *cc = (chipcregs_t *)regs;
127 uint32 erombase, *eromptr, *eromlim;
128
129 erombase = R_REG(sii->osh, &cc->eromptr);
130
131 switch (BUSTYPE(sih->bustype)) {
132 case SI_BUS:
133 eromptr = (uint32 *)REG_MAP(erombase, SI_CORE_SIZE);
134 break;
135
136 case PCI_BUS:
137
138 sii->curwrap = (void *)((uintptr)regs + SI_CORE_SIZE);
139
140
141 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, erombase);
142 eromptr = regs;
143 break;
144
145 case SPI_BUS:
146 case SDIO_BUS:
147 eromptr = (uint32 *)(uintptr)erombase;
148 break;
149
150 case PCMCIA_BUS:
151 default:
152 SI_ERROR(("Don't know how to do AXI enumertion on bus %d\n", sih->bustype));
153 ASSERT(0);
154 return;
155 }
156 eromlim = eromptr + (ER_REMAPCONTROL / sizeof(uint32));
157
158 SI_VMSG(("ai_scan: regs = 0x%p, erombase = 0x%08x, eromptr = 0x%p, eromlim = 0x%p\n",
159 regs, erombase, eromptr, eromlim));
160 while (eromptr < eromlim) {
161 uint32 cia, cib, cid, mfg, crev, nmw, nsw, nmp, nsp;
162 uint32 mpd, asd, addrl, addrh, sizel, sizeh;
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700163 uint i, j, idx;
164 bool br;
165
166 br = FALSE;
167
168
169 cia = get_erom_ent(sih, &eromptr, ER_TAG, ER_CI);
170 if (cia == (ER_END | ER_VALID)) {
171 SI_VMSG(("Found END of erom after %d cores\n", sii->numcores));
172 ai_hwfixup(sii);
173 return;
174 }
Dmitry Shmidt83252322012-03-16 12:52:00 -0700175
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700176 cib = get_erom_ent(sih, &eromptr, 0, 0);
177
178 if ((cib & ER_TAG) != ER_CI) {
179 SI_ERROR(("CIA not followed by CIB\n"));
180 goto error;
181 }
182
183 cid = (cia & CIA_CID_MASK) >> CIA_CID_SHIFT;
184 mfg = (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
185 crev = (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
186 nmw = (cib & CIB_NMW_MASK) >> CIB_NMW_SHIFT;
187 nsw = (cib & CIB_NSW_MASK) >> CIB_NSW_SHIFT;
188 nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT;
189 nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT;
190
Dmitry Shmidt83252322012-03-16 12:52:00 -0700191#ifdef BCMDBG_SI
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700192 SI_VMSG(("Found component 0x%04x/0x%04x rev %d at erom addr 0x%p, with nmw = %d, "
193 "nsw = %d, nmp = %d & nsp = %d\n",
Dmitry Shmidt83252322012-03-16 12:52:00 -0700194 mfg, cid, crev, eromptr - 1, nmw, nsw, nmp, nsp));
195#else
196 BCM_REFERENCE(crev);
197#endif
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700198
199 if (((mfg == MFGID_ARM) && (cid == DEF_AI_COMP)) || (nsp == 0))
200 continue;
201 if ((nmw + nsw == 0)) {
202
203 if (cid == OOB_ROUTER_CORE_ID) {
204 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE,
205 &addrl, &addrh, &sizel, &sizeh);
206 if (asd != 0) {
207 sii->oob_router = addrl;
208 }
209 }
Dmitry Shmidt83252322012-03-16 12:52:00 -0700210 if (cid != GMAC_COMMON_4706_CORE_ID)
211 continue;
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700212 }
213
214 idx = sii->numcores;
215
216 sii->cia[idx] = cia;
217 sii->cib[idx] = cib;
Dmitry Shmidt83252322012-03-16 12:52:00 -0700218 sii->coreid[idx] = remap_coreid(sih, cid);
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700219
220 for (i = 0; i < nmp; i++) {
221 mpd = get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID);
222 if ((mpd & ER_TAG) != ER_MP) {
223 SI_ERROR(("Not enough MP entries for component 0x%x\n", cid));
224 goto error;
225 }
226 SI_VMSG((" Master port %d, mp: %d id: %d\n", i,
227 (mpd & MPD_MP_MASK) >> MPD_MP_SHIFT,
228 (mpd & MPD_MUI_MASK) >> MPD_MUI_SHIFT));
229 }
230
231
232 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh, &sizel, &sizeh);
233 if (asd == 0) {
234
235 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl, &addrh,
236 &sizel, &sizeh);
237 if (asd != 0)
238 br = TRUE;
239 else
240 if ((addrh != 0) || (sizeh != 0) || (sizel != SI_CORE_SIZE)) {
241 SI_ERROR(("First Slave ASD for core 0x%04x malformed "
242 "(0x%08x)\n", cid, asd));
243 goto error;
244 }
245 }
246 sii->coresba[idx] = addrl;
247 sii->coresba_size[idx] = sizel;
248
249 j = 1;
250 do {
251 asd = get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl, &addrh,
252 &sizel, &sizeh);
253 if ((asd != 0) && (j == 1) && (sizel == SI_CORE_SIZE)) {
254 sii->coresba2[idx] = addrl;
255 sii->coresba2_size[idx] = sizel;
256 }
257 j++;
258 } while (asd != 0);
259
260
261 for (i = 1; i < nsp; i++) {
262 j = 0;
263 do {
Dmitry Shmidt83252322012-03-16 12:52:00 -0700264 asd = get_asd(sih, &eromptr, i, j, AD_ST_SLAVE, &addrl, &addrh,
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700265 &sizel, &sizeh);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700266
267 if (asd == 0)
268 break;
269 j++;
270 } while (1);
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700271 if (j == 0) {
272 SI_ERROR((" SP %d has no address descriptors\n", i));
273 goto error;
274 }
275 }
276
277
278 for (i = 0; i < nmw; i++) {
279 asd = get_asd(sih, &eromptr, i, 0, AD_ST_MWRAP, &addrl, &addrh,
280 &sizel, &sizeh);
281 if (asd == 0) {
282 SI_ERROR(("Missing descriptor for MW %d\n", i));
283 goto error;
284 }
285 if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
286 SI_ERROR(("Master wrapper %d is not 4KB\n", i));
287 goto error;
288 }
289 if (i == 0)
290 sii->wrapba[idx] = addrl;
291 }
292
293
294 for (i = 0; i < nsw; i++) {
295 uint fwp = (nsp == 1) ? 0 : 1;
296 asd = get_asd(sih, &eromptr, fwp + i, 0, AD_ST_SWRAP, &addrl, &addrh,
297 &sizel, &sizeh);
298 if (asd == 0) {
299 SI_ERROR(("Missing descriptor for SW %d\n", i));
300 goto error;
301 }
302 if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
303 SI_ERROR(("Slave wrapper %d is not 4KB\n", i));
304 goto error;
305 }
306 if ((nmw == 0) && (i == 0))
307 sii->wrapba[idx] = addrl;
308 }
309
Dmitry Shmidt83252322012-03-16 12:52:00 -0700310
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700311
312 if (br)
313 continue;
314
315
316 sii->numcores++;
317 }
318
319 SI_ERROR(("Reached end of erom without finding END"));
320
321error:
322 sii->numcores = 0;
323 return;
324}
325
326
327void *
328ai_setcoreidx(si_t *sih, uint coreidx)
329{
330 si_info_t *sii = SI_INFO(sih);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700331 uint32 addr, wrap;
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700332 void *regs;
333
Dmitry Shmidt83252322012-03-16 12:52:00 -0700334 if (coreidx >= MIN(sii->numcores, SI_MAXCORES))
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700335 return (NULL);
336
Dmitry Shmidt83252322012-03-16 12:52:00 -0700337 addr = sii->coresba[coreidx];
338 wrap = sii->wrapba[coreidx];
339
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700340
341 ASSERT((sii->intrsenabled_fn == NULL) || !(*(sii)->intrsenabled_fn)((sii)->intr_arg));
342
343 switch (BUSTYPE(sih->bustype)) {
344 case SI_BUS:
345
346 if (!sii->regs[coreidx]) {
347 sii->regs[coreidx] = REG_MAP(addr, SI_CORE_SIZE);
348 ASSERT(GOODREGS(sii->regs[coreidx]));
349 }
350 sii->curmap = regs = sii->regs[coreidx];
351 if (!sii->wrappers[coreidx]) {
352 sii->wrappers[coreidx] = REG_MAP(wrap, SI_CORE_SIZE);
353 ASSERT(GOODREGS(sii->wrappers[coreidx]));
354 }
355 sii->curwrap = sii->wrappers[coreidx];
356 break;
357
358
359 case SPI_BUS:
360 case SDIO_BUS:
361 sii->curmap = regs = (void *)((uintptr)addr);
362 sii->curwrap = (void *)((uintptr)wrap);
363 break;
364
365 case PCMCIA_BUS:
366 default:
367 ASSERT(0);
368 regs = NULL;
369 break;
370 }
371
372 sii->curmap = regs;
373 sii->curidx = coreidx;
374
375 return regs;
376}
377
Dmitry Shmidt83252322012-03-16 12:52:00 -0700378void
379ai_coreaddrspaceX(si_t *sih, uint asidx, uint32 *addr, uint32 *size)
380{
381 si_info_t *sii = SI_INFO(sih);
382 chipcregs_t *cc = NULL;
383 uint32 erombase, *eromptr, *eromlim;
384 uint i, j, cidx;
385 uint32 cia, cib, nmp, nsp;
386 uint32 asd, addrl, addrh, sizel, sizeh;
387
388 for (i = 0; i < sii->numcores; i++) {
389 if (sii->coreid[i] == CC_CORE_ID) {
390 cc = (chipcregs_t *)sii->regs[i];
391 break;
392 }
393 }
394 if (cc == NULL)
395 goto error;
396
397 erombase = R_REG(sii->osh, &cc->eromptr);
398 eromptr = (uint32 *)REG_MAP(erombase, SI_CORE_SIZE);
399 eromlim = eromptr + (ER_REMAPCONTROL / sizeof(uint32));
400
401 cidx = sii->curidx;
402 cia = sii->cia[cidx];
403 cib = sii->cib[cidx];
404
405 nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT;
406 nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT;
407
408
409 while (eromptr < eromlim) {
410 if ((get_erom_ent(sih, &eromptr, ER_TAG, ER_CI) == cia) &&
411 (get_erom_ent(sih, &eromptr, 0, 0) == cib)) {
412 break;
413 }
414 }
415
416
417 for (i = 0; i < nmp; i++)
418 get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID);
419
420
421 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh, &sizel, &sizeh);
422 if (asd == 0) {
423
424 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl, &addrh,
425 &sizel, &sizeh);
426 }
427
428 j = 1;
429 do {
430 asd = get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl, &addrh,
431 &sizel, &sizeh);
432 j++;
433 } while (asd != 0);
434
435
436 for (i = 1; i < nsp; i++) {
437 j = 0;
438 do {
439 asd = get_asd(sih, &eromptr, i, j, AD_ST_SLAVE, &addrl, &addrh,
440 &sizel, &sizeh);
441 if (asd == 0)
442 break;
443
444 if (!asidx--) {
445 *addr = addrl;
446 *size = sizel;
447 return;
448 }
449 j++;
450 } while (1);
451
452 if (j == 0) {
453 SI_ERROR((" SP %d has no address descriptors\n", i));
454 break;
455 }
456 }
457
458error:
459 *size = 0;
460 return;
461}
462
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700463
464int
465ai_numaddrspaces(si_t *sih)
466{
467 return 2;
468}
469
470
471uint32
472ai_addrspace(si_t *sih, uint asidx)
473{
474 si_info_t *sii;
475 uint cidx;
476
477 sii = SI_INFO(sih);
478 cidx = sii->curidx;
479
480 if (asidx == 0)
481 return sii->coresba[cidx];
482 else if (asidx == 1)
483 return sii->coresba2[cidx];
484 else {
485 SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n",
486 __FUNCTION__, asidx));
487 return 0;
488 }
489}
490
491
492uint32
493ai_addrspacesize(si_t *sih, uint asidx)
494{
495 si_info_t *sii;
496 uint cidx;
497
498 sii = SI_INFO(sih);
499 cidx = sii->curidx;
500
501 if (asidx == 0)
502 return sii->coresba_size[cidx];
503 else if (asidx == 1)
504 return sii->coresba2_size[cidx];
505 else {
506 SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n",
507 __FUNCTION__, asidx));
508 return 0;
509 }
510}
511
512uint
513ai_flag(si_t *sih)
514{
515 si_info_t *sii;
516 aidmp_t *ai;
517
518 sii = SI_INFO(sih);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700519 if (BCM47162_DMP()) {
520 SI_ERROR(("%s: Attempting to read MIPS DMP registers on 47162a0", __FUNCTION__));
521 return sii->curidx;
522 }
523 if (BCM5357_DMP()) {
524 SI_ERROR(("%s: Attempting to read USB20H DMP registers on 5357b0\n", __FUNCTION__));
525 return sii->curidx;
526 }
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700527 ai = sii->curwrap;
528
529 return (R_REG(sii->osh, &ai->oobselouta30) & 0x1f);
530}
531
532void
533ai_setint(si_t *sih, int siflag)
534{
535}
536
537uint
538ai_wrap_reg(si_t *sih, uint32 offset, uint32 mask, uint32 val)
539{
540 si_info_t *sii = SI_INFO(sih);
541 uint32 *map = (uint32 *) sii->curwrap;
542
543 if (mask || val) {
544 uint32 w = R_REG(sii->osh, map+(offset/4));
545 w &= ~mask;
546 w |= val;
547 W_REG(sii->osh, map+(offset/4), val);
548 }
549
550 return (R_REG(sii->osh, map+(offset/4)));
551}
552
553uint
554ai_corevendor(si_t *sih)
555{
556 si_info_t *sii;
557 uint32 cia;
558
559 sii = SI_INFO(sih);
560 cia = sii->cia[sii->curidx];
561 return ((cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT);
562}
563
564uint
565ai_corerev(si_t *sih)
566{
567 si_info_t *sii;
568 uint32 cib;
569
570 sii = SI_INFO(sih);
571 cib = sii->cib[sii->curidx];
Dmitry Shmidt83252322012-03-16 12:52:00 -0700572 return remap_corerev(sih, (cib & CIB_REV_MASK) >> CIB_REV_SHIFT);
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700573}
574
575bool
576ai_iscoreup(si_t *sih)
577{
578 si_info_t *sii;
579 aidmp_t *ai;
580
581 sii = SI_INFO(sih);
582 ai = sii->curwrap;
583
584 return (((R_REG(sii->osh, &ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) == SICF_CLOCK_EN) &&
585 ((R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET) == 0));
586}
587
588
589uint
590ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
591{
592 uint origidx = 0;
593 uint32 *r = NULL;
594 uint w;
595 uint intr_val = 0;
596 bool fast = FALSE;
597 si_info_t *sii;
598
599 sii = SI_INFO(sih);
600
601 ASSERT(GOODIDX(coreidx));
602 ASSERT(regoff < SI_CORE_SIZE);
603 ASSERT((val & ~mask) == 0);
604
605 if (coreidx >= SI_MAXCORES)
606 return 0;
607
608 if (BUSTYPE(sih->bustype) == SI_BUS) {
609
610 fast = TRUE;
611
612 if (!sii->regs[coreidx]) {
613 sii->regs[coreidx] = REG_MAP(sii->coresba[coreidx],
614 SI_CORE_SIZE);
615 ASSERT(GOODREGS(sii->regs[coreidx]));
616 }
617 r = (uint32 *)((uchar *)sii->regs[coreidx] + regoff);
618 } else if (BUSTYPE(sih->bustype) == PCI_BUS) {
619
620
621 if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) {
622
623
624 fast = TRUE;
625 r = (uint32 *)((char *)sii->curmap + PCI_16KB0_CCREGS_OFFSET + regoff);
626 } else if (sii->pub.buscoreidx == coreidx) {
627
628 fast = TRUE;
629 if (SI_FAST(sii))
630 r = (uint32 *)((char *)sii->curmap +
631 PCI_16KB0_PCIREGS_OFFSET + regoff);
632 else
633 r = (uint32 *)((char *)sii->curmap +
634 ((regoff >= SBCONFIGOFF) ?
635 PCI_BAR0_PCISBR_OFFSET : PCI_BAR0_PCIREGS_OFFSET) +
636 regoff);
637 }
638 }
639
640 if (!fast) {
641 INTR_OFF(sii, intr_val);
642
643
644 origidx = si_coreidx(&sii->pub);
645
646
647 r = (uint32*) ((uchar*) ai_setcoreidx(&sii->pub, coreidx) + regoff);
648 }
649 ASSERT(r != NULL);
650
651
652 if (mask || val) {
653 w = (R_REG(sii->osh, r) & ~mask) | val;
654 W_REG(sii->osh, r, w);
655 }
656
657
658 w = R_REG(sii->osh, r);
659
660 if (!fast) {
661
662 if (origidx != coreidx)
663 ai_setcoreidx(&sii->pub, origidx);
664
665 INTR_RESTORE(sii, intr_val);
666 }
667
668 return (w);
669}
670
671void
672ai_core_disable(si_t *sih, uint32 bits)
673{
674 si_info_t *sii;
675 volatile uint32 dummy;
676 aidmp_t *ai;
677
678 sii = SI_INFO(sih);
679
680 ASSERT(GOODREGS(sii->curwrap));
681 ai = sii->curwrap;
682
683
684 if (R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET)
685 return;
686
687 W_REG(sii->osh, &ai->ioctrl, bits);
688 dummy = R_REG(sii->osh, &ai->ioctrl);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700689 BCM_REFERENCE(dummy);
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700690 OSL_DELAY(10);
691
692 W_REG(sii->osh, &ai->resetctrl, AIRC_RESET);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700693 dummy = R_REG(sii->osh, &ai->resetctrl);
694 BCM_REFERENCE(dummy);
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700695 OSL_DELAY(1);
696}
697
698
699void
700ai_core_reset(si_t *sih, uint32 bits, uint32 resetbits)
701{
702 si_info_t *sii;
703 aidmp_t *ai;
704 volatile uint32 dummy;
705
706 sii = SI_INFO(sih);
707 ASSERT(GOODREGS(sii->curwrap));
708 ai = sii->curwrap;
709
710
711 ai_core_disable(sih, (bits | resetbits));
712
713
714 W_REG(sii->osh, &ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
715 dummy = R_REG(sii->osh, &ai->ioctrl);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700716 BCM_REFERENCE(dummy);
717
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700718 W_REG(sii->osh, &ai->resetctrl, 0);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700719 dummy = R_REG(sii->osh, &ai->resetctrl);
720 BCM_REFERENCE(dummy);
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700721 OSL_DELAY(1);
722
723 W_REG(sii->osh, &ai->ioctrl, (bits | SICF_CLOCK_EN));
724 dummy = R_REG(sii->osh, &ai->ioctrl);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700725 BCM_REFERENCE(dummy);
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700726 OSL_DELAY(1);
727}
728
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700729void
730ai_core_cflags_wo(si_t *sih, uint32 mask, uint32 val)
731{
732 si_info_t *sii;
733 aidmp_t *ai;
734 uint32 w;
735
736 sii = SI_INFO(sih);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700737
738 if (BCM47162_DMP()) {
739 SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0",
740 __FUNCTION__));
741 return;
742 }
743 if (BCM5357_DMP()) {
744 SI_ERROR(("%s: Accessing USB20H DMP register (ioctrl) on 5357\n",
745 __FUNCTION__));
746 return;
747 }
748
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700749 ASSERT(GOODREGS(sii->curwrap));
750 ai = sii->curwrap;
751
752 ASSERT((val & ~mask) == 0);
753
754 if (mask || val) {
755 w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val);
756 W_REG(sii->osh, &ai->ioctrl, w);
757 }
758}
759
760uint32
761ai_core_cflags(si_t *sih, uint32 mask, uint32 val)
762{
763 si_info_t *sii;
764 aidmp_t *ai;
765 uint32 w;
766
767 sii = SI_INFO(sih);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700768 if (BCM47162_DMP()) {
769 SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0",
770 __FUNCTION__));
771 return 0;
772 }
773 if (BCM5357_DMP()) {
774 SI_ERROR(("%s: Accessing USB20H DMP register (ioctrl) on 5357\n",
775 __FUNCTION__));
776 return 0;
777 }
778
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700779 ASSERT(GOODREGS(sii->curwrap));
780 ai = sii->curwrap;
781
782 ASSERT((val & ~mask) == 0);
783
784 if (mask || val) {
785 w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val);
786 W_REG(sii->osh, &ai->ioctrl, w);
787 }
788
789 return R_REG(sii->osh, &ai->ioctrl);
790}
791
792uint32
793ai_core_sflags(si_t *sih, uint32 mask, uint32 val)
794{
795 si_info_t *sii;
796 aidmp_t *ai;
797 uint32 w;
798
799 sii = SI_INFO(sih);
Dmitry Shmidt83252322012-03-16 12:52:00 -0700800 if (BCM47162_DMP()) {
801 SI_ERROR(("%s: Accessing MIPS DMP register (iostatus) on 47162a0",
802 __FUNCTION__));
803 return 0;
804 }
805 if (BCM5357_DMP()) {
806 SI_ERROR(("%s: Accessing USB20H DMP register (iostatus) on 5357\n",
807 __FUNCTION__));
808 return 0;
809 }
810
Dmitry Shmidt8ce17272011-05-24 11:14:33 -0700811 ASSERT(GOODREGS(sii->curwrap));
812 ai = sii->curwrap;
813
814 ASSERT((val & ~mask) == 0);
815 ASSERT((mask & ~SISF_CORE_BITS) == 0);
816
817 if (mask || val) {
818 w = ((R_REG(sii->osh, &ai->iostatus) & ~mask) | val);
819 W_REG(sii->osh, &ai->iostatus, w);
820 }
821
822 return R_REG(sii->osh, &ai->iostatus);
823}