blob: 75a7e3a5c0094023abf0eeea75e6a5ae40cfbaf2 [file] [log] [blame]
Henry Ptasinskia9533e72010-09-08 21:04:42 -07001/*
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
Brett Rudley33279892010-10-01 18:03:27 -070017#include <linux/kernel.h>
18#include <linux/string.h>
Greg Kroah-Hartmana1c16ed2010-10-21 11:17:44 -070019#include <bcmdefs.h>
20#include <osl.h>
Brett Rudley33279892010-10-01 18:03:27 -070021#include <linuxver.h>
Henry Ptasinskia9533e72010-09-08 21:04:42 -070022#include <bcmutils.h>
23#include <siutils.h>
24#include <hndsoc.h>
25#include <sbchipc.h>
26#include <pcicfg.h>
27#include <bcmdevs.h>
28
29#define BCM47162_DMP() ((CHIPID(sih->chip) == BCM47162_CHIP_ID) && \
30 (CHIPREV(sih->chiprev) == 0) && \
31 (sii->coreid[sii->curidx] == MIPS74K_CORE_ID))
32
33/* EROM parsing */
34
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070035static u32
36get_erom_ent(si_t *sih, u32 **eromptr, u32 mask, u32 match)
Henry Ptasinskia9533e72010-09-08 21:04:42 -070037{
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070038 u32 ent;
Henry Ptasinskia9533e72010-09-08 21:04:42 -070039 uint inv = 0, nom = 0;
40
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -070041 while (true) {
Henry Ptasinskia9533e72010-09-08 21:04:42 -070042 ent = R_REG(si_osh(sih), *eromptr);
43 (*eromptr)++;
44
45 if (mask == 0)
46 break;
47
48 if ((ent & ER_VALID) == 0) {
49 inv++;
50 continue;
51 }
52
53 if (ent == (ER_END | ER_VALID))
54 break;
55
56 if ((ent & mask) == match)
57 break;
58
59 nom++;
60 }
61
62 SI_VMSG(("%s: Returning ent 0x%08x\n", __func__, ent));
63 if (inv + nom) {
64 SI_VMSG((" after %d invalid and %d non-matching entries\n",
65 inv, nom));
66 }
67 return ent;
68}
69
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070070static u32
71get_asd(si_t *sih, u32 **eromptr, uint sp, uint ad, uint st,
72 u32 *addrl, u32 *addrh, u32 *sizel, u32 *sizeh)
Henry Ptasinskia9533e72010-09-08 21:04:42 -070073{
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070074 u32 asd, sz, szd;
Henry Ptasinskia9533e72010-09-08 21:04:42 -070075
76 asd = get_erom_ent(sih, eromptr, ER_VALID, ER_VALID);
77 if (((asd & ER_TAG1) != ER_ADD) ||
78 (((asd & AD_SP_MASK) >> AD_SP_SHIFT) != sp) ||
79 ((asd & AD_ST_MASK) != st)) {
80 /* This is not what we want, "push" it back */
81 (*eromptr)--;
82 return 0;
83 }
84 *addrl = asd & AD_ADDR_MASK;
85 if (asd & AD_AG32)
86 *addrh = get_erom_ent(sih, eromptr, 0, 0);
87 else
88 *addrh = 0;
89 *sizeh = 0;
90 sz = asd & AD_SZ_MASK;
91 if (sz == AD_SZ_SZD) {
92 szd = get_erom_ent(sih, eromptr, 0, 0);
93 *sizel = szd & SD_SZ_MASK;
94 if (szd & SD_SG32)
95 *sizeh = get_erom_ent(sih, eromptr, 0, 0);
96 } else
97 *sizel = AD_SZ_BASE << (sz >> AD_SZ_SHIFT);
98
99 SI_VMSG((" SP %d, ad %d: st = %d, 0x%08x_0x%08x @ 0x%08x_0x%08x\n",
100 sp, ad, st, *sizeh, *sizel, *addrh, *addrl));
101
102 return asd;
103}
104
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400105static void ai_hwfixup(si_info_t *sii)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700106{
107}
108
109/* parse the enumeration rom to identify all cores */
Greg Kroah-Hartman0d2f0722010-10-08 14:28:21 -0700110void ai_scan(si_t *sih, void *regs, uint devid)
Jason Coopera2627bc2010-09-14 09:45:31 -0400111{
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700112 si_info_t *sii = SI_INFO(sih);
113 chipcregs_t *cc = (chipcregs_t *) regs;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700114 u32 erombase, *eromptr, *eromlim;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700115
116 erombase = R_REG(sii->osh, &cc->eromptr);
117
118 switch (BUSTYPE(sih->bustype)) {
119 case SI_BUS:
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700120 eromptr = (u32 *) REG_MAP(erombase, SI_CORE_SIZE);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700121 break;
122
123 case PCI_BUS:
124 /* Set wrappers address */
Greg Kroah-Hartmanf024c482010-10-21 10:50:21 -0700125 sii->curwrap = (void *)((unsigned long)regs + SI_CORE_SIZE);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700126
127 /* Now point the window at the erom */
128 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, erombase);
129 eromptr = regs;
130 break;
131
132#ifdef BCMSDIO
133 case SPI_BUS:
134 case SDIO_BUS:
135#endif /* BCMSDIO */
Greg Kroah-Hartman6ddcfdc2010-10-14 12:26:08 -0700136 eromptr = (u32 *)(unsigned long)erombase;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700137 break;
138
139 default:
140 SI_ERROR(("Don't know how to do AXI enumertion on bus %d\n",
141 sih->bustype));
142 ASSERT(0);
143 return;
144 }
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700145 eromlim = eromptr + (ER_REMAPCONTROL / sizeof(u32));
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700146
147 SI_VMSG(("ai_scan: regs = 0x%p, erombase = 0x%08x, eromptr = 0x%p, eromlim = 0x%p\n", regs, erombase, eromptr, eromlim));
148 while (eromptr < eromlim) {
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700149 u32 cia, cib, cid, mfg, crev, nmw, nsw, nmp, nsp;
150 u32 mpd, asd, addrl, addrh, sizel, sizeh;
151 u32 *base;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700152 uint i, j, idx;
153 bool br;
154
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700155 br = false;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700156
157 /* Grok a component */
158 cia = get_erom_ent(sih, &eromptr, ER_TAG, ER_CI);
159 if (cia == (ER_END | ER_VALID)) {
160 SI_VMSG(("Found END of erom after %d cores\n",
161 sii->numcores));
162 ai_hwfixup(sii);
163 return;
164 }
165 base = eromptr - 1;
166 cib = get_erom_ent(sih, &eromptr, 0, 0);
167
168 if ((cib & ER_TAG) != ER_CI) {
169 SI_ERROR(("CIA not followed by CIB\n"));
170 goto error;
171 }
172
173 cid = (cia & CIA_CID_MASK) >> CIA_CID_SHIFT;
174 mfg = (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
175 crev = (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
176 nmw = (cib & CIB_NMW_MASK) >> CIB_NMW_SHIFT;
177 nsw = (cib & CIB_NSW_MASK) >> CIB_NSW_SHIFT;
178 nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT;
179 nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT;
180
181 SI_VMSG(("Found component 0x%04x/0x%04x rev %d at erom addr 0x%p, with nmw = %d, " "nsw = %d, nmp = %d & nsp = %d\n", mfg, cid, crev, base, nmw, nsw, nmp, nsp));
182
183 if (((mfg == MFGID_ARM) && (cid == DEF_AI_COMP)) || (nsp == 0))
184 continue;
185 if ((nmw + nsw == 0)) {
186 /* A component which is not a core */
187 if (cid == OOB_ROUTER_CORE_ID) {
188 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE,
189 &addrl, &addrh, &sizel, &sizeh);
190 if (asd != 0) {
191 sii->oob_router = addrl;
192 }
193 }
194 continue;
195 }
196
197 idx = sii->numcores;
198/* sii->eromptr[idx] = base; */
199 sii->cia[idx] = cia;
200 sii->cib[idx] = cib;
201 sii->coreid[idx] = cid;
202
203 for (i = 0; i < nmp; i++) {
204 mpd = get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID);
205 if ((mpd & ER_TAG) != ER_MP) {
206 SI_ERROR(("Not enough MP entries for component 0x%x\n", cid));
207 goto error;
208 }
209 SI_VMSG((" Master port %d, mp: %d id: %d\n", i,
210 (mpd & MPD_MP_MASK) >> MPD_MP_SHIFT,
211 (mpd & MPD_MUI_MASK) >> MPD_MUI_SHIFT));
212 }
213
214 /* First Slave Address Descriptor should be port 0:
215 * the main register space for the core
216 */
217 asd =
218 get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh,
219 &sizel, &sizeh);
220 if (asd == 0) {
221 /* Try again to see if it is a bridge */
222 asd =
223 get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl,
224 &addrh, &sizel, &sizeh);
225 if (asd != 0)
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700226 br = true;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700227 else if ((addrh != 0) || (sizeh != 0)
228 || (sizel != SI_CORE_SIZE)) {
229 SI_ERROR(("First Slave ASD for core 0x%04x malformed " "(0x%08x)\n", cid, asd));
230 goto error;
231 }
232 }
233 sii->coresba[idx] = addrl;
234 sii->coresba_size[idx] = sizel;
235 /* Get any more ASDs in port 0 */
236 j = 1;
237 do {
238 asd =
239 get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl,
240 &addrh, &sizel, &sizeh);
241 if ((asd != 0) && (j == 1) && (sizel == SI_CORE_SIZE)) {
242 sii->coresba2[idx] = addrl;
243 sii->coresba2_size[idx] = sizel;
244 }
245 j++;
246 } while (asd != 0);
247
248 /* Go through the ASDs for other slave ports */
249 for (i = 1; i < nsp; i++) {
250 j = 0;
251 do {
252 asd =
253 get_asd(sih, &eromptr, i, j++, AD_ST_SLAVE,
254 &addrl, &addrh, &sizel, &sizeh);
255 } while (asd != 0);
256 if (j == 0) {
257 SI_ERROR((" SP %d has no address descriptors\n",
258 i));
259 goto error;
260 }
261 }
262
263 /* Now get master wrappers */
264 for (i = 0; i < nmw; i++) {
265 asd =
266 get_asd(sih, &eromptr, i, 0, AD_ST_MWRAP, &addrl,
267 &addrh, &sizel, &sizeh);
268 if (asd == 0) {
269 SI_ERROR(("Missing descriptor for MW %d\n", i));
270 goto error;
271 }
272 if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
273 SI_ERROR(("Master wrapper %d is not 4KB\n", i));
274 goto error;
275 }
276 if (i == 0)
277 sii->wrapba[idx] = addrl;
278 }
279
280 /* And finally slave wrappers */
281 for (i = 0; i < nsw; i++) {
282 uint fwp = (nsp == 1) ? 0 : 1;
283 asd =
284 get_asd(sih, &eromptr, fwp + i, 0, AD_ST_SWRAP,
285 &addrl, &addrh, &sizel, &sizeh);
286 if (asd == 0) {
287 SI_ERROR(("Missing descriptor for SW %d\n", i));
288 goto error;
289 }
290 if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
291 SI_ERROR(("Slave wrapper %d is not 4KB\n", i));
292 goto error;
293 }
294 if ((nmw == 0) && (i == 0))
295 sii->wrapba[idx] = addrl;
296 }
297
298 /* Don't record bridges */
299 if (br)
300 continue;
301
302 /* Done with core */
303 sii->numcores++;
304 }
305
306 SI_ERROR(("Reached end of erom without finding END"));
307
308 error:
309 sii->numcores = 0;
310 return;
311}
312
313/* This function changes the logical "focus" to the indicated core.
314 * Return the current core's virtual address.
315 */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400316void *ai_setcoreidx(si_t *sih, uint coreidx)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700317{
318 si_info_t *sii = SI_INFO(sih);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700319 u32 addr = sii->coresba[coreidx];
320 u32 wrap = sii->wrapba[coreidx];
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700321 void *regs;
322
323 if (coreidx >= sii->numcores)
Jason Cooper90ea2292010-09-14 09:45:32 -0400324 return NULL;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700325
326 /*
327 * If the user has provided an interrupt mask enabled function,
328 * then assert interrupts are disabled before switching the core.
329 */
330 ASSERT((sii->intrsenabled_fn == NULL)
331 || !(*(sii)->intrsenabled_fn) ((sii)->intr_arg));
332
333 switch (BUSTYPE(sih->bustype)) {
334 case SI_BUS:
335 /* map new one */
336 if (!sii->regs[coreidx]) {
337 sii->regs[coreidx] = REG_MAP(addr, SI_CORE_SIZE);
338 ASSERT(GOODREGS(sii->regs[coreidx]));
339 }
340 sii->curmap = regs = sii->regs[coreidx];
341 if (!sii->wrappers[coreidx]) {
342 sii->wrappers[coreidx] = REG_MAP(wrap, SI_CORE_SIZE);
343 ASSERT(GOODREGS(sii->wrappers[coreidx]));
344 }
345 sii->curwrap = sii->wrappers[coreidx];
346 break;
347
348 case PCI_BUS:
349 /* point bar0 window */
350 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, addr);
351 regs = sii->curmap;
352 /* point bar0 2nd 4KB window */
353 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN2, 4, wrap);
354 break;
355
356#ifdef BCMSDIO
357 case SPI_BUS:
358 case SDIO_BUS:
359#endif /* BCMSDIO */
Greg Kroah-Hartman6ddcfdc2010-10-14 12:26:08 -0700360 sii->curmap = regs = (void *)(unsigned long)addr;
361 sii->curwrap = (void *)(unsigned long)wrap;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700362 break;
363
364 default:
365 ASSERT(0);
366 regs = NULL;
367 break;
368 }
369
370 sii->curmap = regs;
371 sii->curidx = coreidx;
372
373 return regs;
374}
375
376/* Return the number of address spaces in current core */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400377int ai_numaddrspaces(si_t *sih)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700378{
379 return 2;
380}
381
382/* Return the address of the nth address space in the current core */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700383u32 ai_addrspace(si_t *sih, uint asidx)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700384{
385 si_info_t *sii;
386 uint cidx;
387
388 sii = SI_INFO(sih);
389 cidx = sii->curidx;
390
391 if (asidx == 0)
392 return sii->coresba[cidx];
393 else if (asidx == 1)
394 return sii->coresba2[cidx];
395 else {
396 SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n", __func__, asidx));
397 return 0;
398 }
399}
400
401/* Return the size of the nth address space in the current core */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700402u32 ai_addrspacesize(si_t *sih, uint asidx)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700403{
404 si_info_t *sii;
405 uint cidx;
406
407 sii = SI_INFO(sih);
408 cidx = sii->curidx;
409
410 if (asidx == 0)
411 return sii->coresba_size[cidx];
412 else if (asidx == 1)
413 return sii->coresba2_size[cidx];
414 else {
415 SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n", __func__, asidx));
416 return 0;
417 }
418}
419
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400420uint ai_flag(si_t *sih)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700421{
422 si_info_t *sii;
423 aidmp_t *ai;
424
425 sii = SI_INFO(sih);
426 if (BCM47162_DMP()) {
427 SI_ERROR(("%s: Attempting to read MIPS DMP registers on 47162a0", __func__));
428 return sii->curidx;
429 }
430 ai = sii->curwrap;
431
Jason Cooper90ea2292010-09-14 09:45:32 -0400432 return R_REG(sii->osh, &ai->oobselouta30) & 0x1f;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700433}
434
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400435void ai_setint(si_t *sih, int siflag)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700436{
437}
438
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700439void ai_write_wrap_reg(si_t *sih, u32 offset, u32 val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700440{
441 si_info_t *sii = SI_INFO(sih);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700442 u32 *w = (u32 *) sii->curwrap;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700443 W_REG(sii->osh, w + (offset / 4), val);
444 return;
445}
446
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400447uint ai_corevendor(si_t *sih)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700448{
449 si_info_t *sii;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700450 u32 cia;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700451
452 sii = SI_INFO(sih);
453 cia = sii->cia[sii->curidx];
Jason Cooper90ea2292010-09-14 09:45:32 -0400454 return (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700455}
456
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400457uint ai_corerev(si_t *sih)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700458{
459 si_info_t *sii;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700460 u32 cib;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700461
462 sii = SI_INFO(sih);
463 cib = sii->cib[sii->curidx];
Jason Cooper90ea2292010-09-14 09:45:32 -0400464 return (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700465}
466
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400467bool ai_iscoreup(si_t *sih)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700468{
469 si_info_t *sii;
470 aidmp_t *ai;
471
472 sii = SI_INFO(sih);
473 ai = sii->curwrap;
474
475 return (((R_REG(sii->osh, &ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) ==
476 SICF_CLOCK_EN)
477 && ((R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET) == 0));
478}
479
480/*
481 * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set operation,
482 * switch back to the original core, and return the new value.
483 *
484 * When using the silicon backplane, no fiddling with interrupts or core switches is needed.
485 *
486 * Also, when using pci/pcie, we can optimize away the core switching for pci registers
487 * and (on newer pci cores) chipcommon registers.
488 */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400489uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700490{
491 uint origidx = 0;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700492 u32 *r = NULL;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700493 uint w;
494 uint intr_val = 0;
Greg Kroah-Hartman0965ae82010-10-12 12:50:15 -0700495 bool fast = false;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700496 si_info_t *sii;
497
498 sii = SI_INFO(sih);
499
500 ASSERT(GOODIDX(coreidx));
501 ASSERT(regoff < SI_CORE_SIZE);
502 ASSERT((val & ~mask) == 0);
503
504 if (coreidx >= SI_MAXCORES)
505 return 0;
506
507 if (BUSTYPE(sih->bustype) == SI_BUS) {
508 /* If internal bus, we can always get at everything */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700509 fast = true;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700510 /* map if does not exist */
511 if (!sii->regs[coreidx]) {
512 sii->regs[coreidx] = REG_MAP(sii->coresba[coreidx],
513 SI_CORE_SIZE);
514 ASSERT(GOODREGS(sii->regs[coreidx]));
515 }
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700516 r = (u32 *) ((unsigned char *) sii->regs[coreidx] + regoff);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700517 } else if (BUSTYPE(sih->bustype) == PCI_BUS) {
518 /* If pci/pcie, we can get at pci/pcie regs and on newer cores to chipc */
519
520 if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) {
521 /* Chipc registers are mapped at 12KB */
522
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700523 fast = true;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700524 r = (u32 *) ((char *)sii->curmap +
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700525 PCI_16KB0_CCREGS_OFFSET + regoff);
526 } else if (sii->pub.buscoreidx == coreidx) {
527 /* pci registers are at either in the last 2KB of an 8KB window
528 * or, in pcie and pci rev 13 at 8KB
529 */
Greg Kroah-Hartman0f0881b2010-10-12 12:15:18 -0700530 fast = true;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700531 if (SI_FAST(sii))
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700532 r = (u32 *) ((char *)sii->curmap +
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700533 PCI_16KB0_PCIREGS_OFFSET +
534 regoff);
535 else
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700536 r = (u32 *) ((char *)sii->curmap +
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700537 ((regoff >= SBCONFIGOFF) ?
538 PCI_BAR0_PCISBR_OFFSET :
539 PCI_BAR0_PCIREGS_OFFSET) +
540 regoff);
541 }
542 }
543
544 if (!fast) {
545 INTR_OFF(sii, intr_val);
546
547 /* save current core index */
548 origidx = si_coreidx(&sii->pub);
549
550 /* switch core */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700551 r = (u32 *) ((unsigned char *) ai_setcoreidx(&sii->pub, coreidx) +
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700552 regoff);
553 }
554 ASSERT(r != NULL);
555
556 /* mask and set */
557 if (mask || val) {
558 w = (R_REG(sii->osh, r) & ~mask) | val;
559 W_REG(sii->osh, r, w);
560 }
561
562 /* readback */
563 w = R_REG(sii->osh, r);
564
565 if (!fast) {
566 /* restore core index */
567 if (origidx != coreidx)
568 ai_setcoreidx(&sii->pub, origidx);
569
570 INTR_RESTORE(sii, intr_val);
571 }
572
Jason Cooper90ea2292010-09-14 09:45:32 -0400573 return w;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700574}
575
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700576void ai_core_disable(si_t *sih, u32 bits)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700577{
578 si_info_t *sii;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700579 volatile u32 dummy;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700580 aidmp_t *ai;
581
582 sii = SI_INFO(sih);
583
584 ASSERT(GOODREGS(sii->curwrap));
585 ai = sii->curwrap;
586
587 /* if core is already in reset, just return */
588 if (R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET)
589 return;
590
591 W_REG(sii->osh, &ai->ioctrl, bits);
592 dummy = R_REG(sii->osh, &ai->ioctrl);
mike.rapoport@gmail.com73831412010-10-13 00:09:07 +0200593 udelay(10);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700594
595 W_REG(sii->osh, &ai->resetctrl, AIRC_RESET);
mike.rapoport@gmail.com73831412010-10-13 00:09:07 +0200596 udelay(1);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700597}
598
599/* reset and re-enable a core
600 * inputs:
601 * bits - core specific bits that are set during and after reset sequence
602 * resetbits - core specific bits that are set only during reset sequence
603 */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700604void ai_core_reset(si_t *sih, u32 bits, u32 resetbits)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700605{
606 si_info_t *sii;
607 aidmp_t *ai;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700608 volatile u32 dummy;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700609
610 sii = SI_INFO(sih);
611 ASSERT(GOODREGS(sii->curwrap));
612 ai = sii->curwrap;
613
614 /*
615 * Must do the disable sequence first to work for arbitrary current core state.
616 */
617 ai_core_disable(sih, (bits | resetbits));
618
619 /*
620 * Now do the initialization sequence.
621 */
622 W_REG(sii->osh, &ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
623 dummy = R_REG(sii->osh, &ai->ioctrl);
624 W_REG(sii->osh, &ai->resetctrl, 0);
mike.rapoport@gmail.com73831412010-10-13 00:09:07 +0200625 udelay(1);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700626
627 W_REG(sii->osh, &ai->ioctrl, (bits | SICF_CLOCK_EN));
628 dummy = R_REG(sii->osh, &ai->ioctrl);
mike.rapoport@gmail.com73831412010-10-13 00:09:07 +0200629 udelay(1);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700630}
631
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700632void ai_core_cflags_wo(si_t *sih, u32 mask, u32 val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700633{
634 si_info_t *sii;
635 aidmp_t *ai;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700636 u32 w;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700637
638 sii = SI_INFO(sih);
639
640 if (BCM47162_DMP()) {
641 SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0",
642 __func__));
643 return;
644 }
645
646 ASSERT(GOODREGS(sii->curwrap));
647 ai = sii->curwrap;
648
649 ASSERT((val & ~mask) == 0);
650
651 if (mask || val) {
652 w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val);
653 W_REG(sii->osh, &ai->ioctrl, w);
654 }
655}
656
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700657u32 ai_core_cflags(si_t *sih, u32 mask, u32 val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700658{
659 si_info_t *sii;
660 aidmp_t *ai;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700661 u32 w;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700662
663 sii = SI_INFO(sih);
664 if (BCM47162_DMP()) {
665 SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0",
666 __func__));
667 return 0;
668 }
669
670 ASSERT(GOODREGS(sii->curwrap));
671 ai = sii->curwrap;
672
673 ASSERT((val & ~mask) == 0);
674
675 if (mask || val) {
676 w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val);
677 W_REG(sii->osh, &ai->ioctrl, w);
678 }
679
680 return R_REG(sii->osh, &ai->ioctrl);
681}
682
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700683u32 ai_core_sflags(si_t *sih, u32 mask, u32 val)
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700684{
685 si_info_t *sii;
686 aidmp_t *ai;
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700687 u32 w;
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700688
689 sii = SI_INFO(sih);
690 if (BCM47162_DMP()) {
691 SI_ERROR(("%s: Accessing MIPS DMP register (iostatus) on 47162a0", __func__));
692 return 0;
693 }
694
695 ASSERT(GOODREGS(sii->curwrap));
696 ai = sii->curwrap;
697
698 ASSERT((val & ~mask) == 0);
699 ASSERT((mask & ~SISF_CORE_BITS) == 0);
700
701 if (mask || val) {
702 w = ((R_REG(sii->osh, &ai->iostatus) & ~mask) | val);
703 W_REG(sii->osh, &ai->iostatus, w);
704 }
705
706 return R_REG(sii->osh, &ai->iostatus);
707}
708