staging: brcm80211: cleaned sb* header files
[pandora-kernel.git] / drivers / staging / brcm80211 / brcmsmac / aiutils.h
1 /*
2  * Copyright (c) 2011 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 #ifndef _aiutils_h_
18 #define _aiutils_h_
19
20 /* cpp contortions to concatenate w/arg prescan */
21 #ifndef PAD
22 #define _PADLINE(line)  pad ## line
23 #define _XSTR(line)     _PADLINE(line)
24 #define PAD             _XSTR(__LINE__)
25 #endif
26
27 /* Include the soci specific files */
28 #include <aidmp.h>
29
30 /*
31  * SOC Interconnect Address Map.
32  * All regions may not exist on all chips.
33  */
34 /* Physical SDRAM */
35 #define SI_SDRAM_BASE           0x00000000
36 /* Host Mode sb2pcitranslation0 (64 MB) */
37 #define SI_PCI_MEM              0x08000000
38 #define SI_PCI_MEM_SZ           (64 * 1024 * 1024)
39 /* Host Mode sb2pcitranslation1 (64 MB) */
40 #define SI_PCI_CFG              0x0c000000
41 /* Byteswapped Physical SDRAM */
42 #define SI_SDRAM_SWAPPED        0x10000000
43 /* Region 2 for sdram (512 MB) */
44 #define SI_SDRAM_R2             0x80000000
45
46 #ifdef SI_ENUM_BASE_VARIABLE
47 #define SI_ENUM_BASE            (sii->pub.si_enum_base)
48 #else
49 #define SI_ENUM_BASE            0x18000000      /* Enumeration space base */
50 #endif                          /* SI_ENUM_BASE_VARIABLE */
51
52 /* Wrapper space base */
53 #define SI_WRAP_BASE            0x18100000
54 /* each core gets 4Kbytes for registers */
55 #define SI_CORE_SIZE            0x1000
56 /*
57  * Max cores (this is arbitrary, for software
58  * convenience and could be changed if we
59  * make any larger chips
60  */
61 #define SI_MAXCORES             16
62
63 /* On-chip RAM on chips that also have DDR */
64 #define SI_FASTRAM              0x19000000
65 #define SI_FASTRAM_SWAPPED      0x19800000
66
67 /* Flash Region 2 (region 1 shadowed here) */
68 #define SI_FLASH2               0x1c000000
69 /* Size of Flash Region 2 */
70 #define SI_FLASH2_SZ            0x02000000
71 /* ARM Cortex-M3 ROM */
72 #define SI_ARMCM3_ROM           0x1e000000
73 /* MIPS Flash Region 1 */
74 #define SI_FLASH1               0x1fc00000
75 /* MIPS Size of Flash Region 1 */
76 #define SI_FLASH1_SZ            0x00400000
77 /* ARM7TDMI-S ROM */
78 #define SI_ARM7S_ROM            0x20000000
79 /* ARM Cortex-M3 SRAM Region 2 */
80 #define SI_ARMCM3_SRAM2         0x60000000
81 /* ARM7TDMI-S SRAM Region 2 */
82 #define SI_ARM7S_SRAM2          0x80000000
83 /* ARM Flash Region 1 */
84 #define SI_ARM_FLASH1           0xffff0000
85 /* ARM Size of Flash Region 1 */
86 #define SI_ARM_FLASH1_SZ        0x00010000
87
88 /* Client Mode sb2pcitranslation2 (1 GB) */
89 #define SI_PCI_DMA              0x40000000
90 /* Client Mode sb2pcitranslation2 (1 GB) */
91 #define SI_PCI_DMA2             0x80000000
92 /* Client Mode sb2pcitranslation2 size in bytes */
93 #define SI_PCI_DMA_SZ           0x40000000
94 /* PCIE Client Mode sb2pcitranslation2 (2 ZettaBytes), low 32 bits */
95 #define SI_PCIE_DMA_L32         0x00000000
96 /* PCIE Client Mode sb2pcitranslation2 (2 ZettaBytes), high 32 bits */
97 #define SI_PCIE_DMA_H32         0x80000000
98
99 /* core codes */
100 #define NODEV_CORE_ID           0x700   /* Invalid coreid */
101 #define CC_CORE_ID              0x800   /* chipcommon core */
102 #define ILINE20_CORE_ID         0x801   /* iline20 core */
103 #define SRAM_CORE_ID            0x802   /* sram core */
104 #define SDRAM_CORE_ID           0x803   /* sdram core */
105 #define PCI_CORE_ID             0x804   /* pci core */
106 #define MIPS_CORE_ID            0x805   /* mips core */
107 #define ENET_CORE_ID            0x806   /* enet mac core */
108 #define CODEC_CORE_ID           0x807   /* v90 codec core */
109 #define USB_CORE_ID             0x808   /* usb 1.1 host/device core */
110 #define ADSL_CORE_ID            0x809   /* ADSL core */
111 #define ILINE100_CORE_ID        0x80a   /* iline100 core */
112 #define IPSEC_CORE_ID           0x80b   /* ipsec core */
113 #define UTOPIA_CORE_ID          0x80c   /* utopia core */
114 #define PCMCIA_CORE_ID          0x80d   /* pcmcia core */
115 #define SOCRAM_CORE_ID          0x80e   /* internal memory core */
116 #define MEMC_CORE_ID            0x80f   /* memc sdram core */
117 #define OFDM_CORE_ID            0x810   /* OFDM phy core */
118 #define EXTIF_CORE_ID           0x811   /* external interface core */
119 #define D11_CORE_ID             0x812   /* 802.11 MAC core */
120 #define APHY_CORE_ID            0x813   /* 802.11a phy core */
121 #define BPHY_CORE_ID            0x814   /* 802.11b phy core */
122 #define GPHY_CORE_ID            0x815   /* 802.11g phy core */
123 #define MIPS33_CORE_ID          0x816   /* mips3302 core */
124 #define USB11H_CORE_ID          0x817   /* usb 1.1 host core */
125 #define USB11D_CORE_ID          0x818   /* usb 1.1 device core */
126 #define USB20H_CORE_ID          0x819   /* usb 2.0 host core */
127 #define USB20D_CORE_ID          0x81a   /* usb 2.0 device core */
128 #define SDIOH_CORE_ID           0x81b   /* sdio host core */
129 #define ROBO_CORE_ID            0x81c   /* roboswitch core */
130 #define ATA100_CORE_ID          0x81d   /* parallel ATA core */
131 #define SATAXOR_CORE_ID         0x81e   /* serial ATA & XOR DMA core */
132 #define GIGETH_CORE_ID          0x81f   /* gigabit ethernet core */
133 #define PCIE_CORE_ID            0x820   /* pci express core */
134 #define NPHY_CORE_ID            0x821   /* 802.11n 2x2 phy core */
135 #define SRAMC_CORE_ID           0x822   /* SRAM controller core */
136 #define MINIMAC_CORE_ID         0x823   /* MINI MAC/phy core */
137 #define ARM11_CORE_ID           0x824   /* ARM 1176 core */
138 #define ARM7S_CORE_ID           0x825   /* ARM7tdmi-s core */
139 #define LPPHY_CORE_ID           0x826   /* 802.11a/b/g phy core */
140 #define PMU_CORE_ID             0x827   /* PMU core */
141 #define SSNPHY_CORE_ID          0x828   /* 802.11n single-stream phy core */
142 #define SDIOD_CORE_ID           0x829   /* SDIO device core */
143 #define ARMCM3_CORE_ID          0x82a   /* ARM Cortex M3 core */
144 #define HTPHY_CORE_ID           0x82b   /* 802.11n 4x4 phy core */
145 #define MIPS74K_CORE_ID         0x82c   /* mips 74k core */
146 #define GMAC_CORE_ID            0x82d   /* Gigabit MAC core */
147 #define DMEMC_CORE_ID           0x82e   /* DDR1/2 memory controller core */
148 #define PCIERC_CORE_ID          0x82f   /* PCIE Root Complex core */
149 #define OCP_CORE_ID             0x830   /* OCP2OCP bridge core */
150 #define SC_CORE_ID              0x831   /* shared common core */
151 #define AHB_CORE_ID             0x832   /* OCP2AHB bridge core */
152 #define SPIH_CORE_ID            0x833   /* SPI host core */
153 #define I2S_CORE_ID             0x834   /* I2S core */
154 #define DMEMS_CORE_ID           0x835   /* SDR/DDR1 memory controller core */
155 #define DEF_SHIM_COMP           0x837   /* SHIM component in ubus/6362 */
156 #define OOB_ROUTER_CORE_ID      0x367   /* OOB router core ID */
157 #define DEF_AI_COMP             0xfff   /* Default component, in ai chips it
158                                          * maps all unused address ranges
159                                          */
160
161 /* There are TWO constants on all HND chips: SI_ENUM_BASE above,
162  * and chipcommon being the first core:
163  */
164 #define SI_CC_IDX               0
165
166 /* SOC Interconnect types (aka chip types) */
167 #define SOCI_AI                 1
168
169 /* Common core control flags */
170 #define SICF_BIST_EN            0x8000
171 #define SICF_PME_EN             0x4000
172 #define SICF_CORE_BITS          0x3ffc
173 #define SICF_FGC                0x0002
174 #define SICF_CLOCK_EN           0x0001
175
176 /* Common core status flags */
177 #define SISF_BIST_DONE          0x8000
178 #define SISF_BIST_ERROR         0x4000
179 #define SISF_GATED_CLK          0x2000
180 #define SISF_DMA64              0x1000
181 #define SISF_CORE_BITS          0x0fff
182
183 /* A register that is common to all cores to
184  * communicate w/PMU regarding clock control.
185  */
186 #define SI_CLK_CTL_ST           0x1e0   /* clock control and status */
187
188 /* clk_ctl_st register */
189 #define CCS_FORCEALP            0x00000001      /* force ALP request */
190 #define CCS_FORCEHT             0x00000002      /* force HT request */
191 #define CCS_FORCEILP            0x00000004      /* force ILP request */
192 #define CCS_ALPAREQ             0x00000008      /* ALP Avail Request */
193 #define CCS_HTAREQ              0x00000010      /* HT Avail Request */
194 #define CCS_FORCEHWREQOFF       0x00000020      /* Force HW Clock Request Off */
195 #define CCS_ERSRC_REQ_MASK      0x00000700      /* external resource requests */
196 #define CCS_ERSRC_REQ_SHIFT     8
197 #define CCS_ALPAVAIL            0x00010000      /* ALP is available */
198 #define CCS_HTAVAIL             0x00020000      /* HT is available */
199 #define CCS_BP_ON_APL           0x00040000      /* RO: running on ALP clock */
200 #define CCS_BP_ON_HT            0x00080000      /* RO: running on HT clock */
201 #define CCS_ERSRC_STS_MASK      0x07000000      /* external resource status */
202 #define CCS_ERSRC_STS_SHIFT     24
203
204 /* HT avail in chipc and pcmcia on 4328a0 */
205 #define CCS0_HTAVAIL            0x00010000
206 /* ALP avail in chipc and pcmcia on 4328a0 */
207 #define CCS0_ALPAVAIL           0x00020000
208
209 /* Not really related to SOC Interconnect, but a couple of software
210  * conventions for the use the flash space:
211  */
212
213 /* Minumum amount of flash we support */
214 #define FLASH_MIN               0x00020000      /* Minimum flash size */
215
216 /* A boot/binary may have an embedded block that describes its size  */
217 #define BISZ_OFFSET             0x3e0   /* At this offset into the binary */
218 #define BISZ_MAGIC              0x4249535a      /* Marked with value: 'BISZ' */
219 #define BISZ_MAGIC_IDX          0       /* Word 0: magic */
220 #define BISZ_TXTST_IDX          1       /*      1: text start */
221 #define BISZ_TXTEND_IDX         2       /*      2: text end */
222 #define BISZ_DATAST_IDX         3       /*      3: data start */
223 #define BISZ_DATAEND_IDX        4       /*      4: data end */
224 #define BISZ_BSSST_IDX          5       /*      5: bss start */
225 #define BISZ_BSSEND_IDX         6       /*      6: bss end */
226 #define BISZ_SIZE               7       /* descriptor size in 32-bit integers */
227
228 #define CC_SROM_OTP             0x800   /* SROM/OTP address space */
229
230 /* gpiotimerval */
231 #define GPIO_ONTIME_SHIFT       16
232
233 /* Fields in clkdiv */
234 #define CLKD_OTP                0x000f0000
235 #define CLKD_OTP_SHIFT          16
236
237 /* When Srom support present, fields in sromcontrol */
238 #define SRC_START               0x80000000
239 #define SRC_BUSY                0x80000000
240 #define SRC_OPCODE              0x60000000
241 #define SRC_OP_READ             0x00000000
242 #define SRC_OP_WRITE            0x20000000
243 #define SRC_OP_WRDIS            0x40000000
244 #define SRC_OP_WREN             0x60000000
245 #define SRC_OTPSEL              0x00000010
246 #define SRC_LOCK                0x00000008
247 #define SRC_SIZE_MASK           0x00000006
248 #define SRC_SIZE_1K             0x00000000
249 #define SRC_SIZE_4K             0x00000002
250 #define SRC_SIZE_16K            0x00000004
251 #define SRC_SIZE_SHIFT          1
252 #define SRC_PRESENT             0x00000001
253
254 /* 4330 chip-specific ChipStatus register bits */
255 #define CST4330_CHIPMODE_SDIOD(cs)      (((cs) & 0x7) < 6)      /* SDIO || gSPI */
256 #define CST4330_CHIPMODE_USB20D(cs)     (((cs) & 0x7) >= 6)     /* USB || USBDA */
257 #define CST4330_CHIPMODE_SDIO(cs)       (((cs) & 0x4) == 0)     /* SDIO */
258 #define CST4330_CHIPMODE_GSPI(cs)       (((cs) & 0x6) == 4)     /* gSPI */
259 #define CST4330_CHIPMODE_USB(cs)        (((cs) & 0x7) == 6)     /* USB packet-oriented */
260 #define CST4330_CHIPMODE_USBDA(cs)      (((cs) & 0x7) == 7)     /* USB Direct Access */
261 #define CST4330_OTP_PRESENT             0x00000010
262 #define CST4330_LPO_AUTODET_EN          0x00000020
263 #define CST4330_ARMREMAP_0              0x00000040
264 #define CST4330_SPROM_PRESENT           0x00000080      /* takes priority over OTP if both set */
265 #define CST4330_ILPDIV_EN               0x00000100
266 #define CST4330_LPO_SEL                 0x00000200
267 #define CST4330_RES_INIT_MODE_SHIFT     10
268 #define CST4330_RES_INIT_MODE_MASK      0x00000c00
269 #define CST4330_CBUCK_MODE_SHIFT        12
270 #define CST4330_CBUCK_MODE_MASK         0x00003000
271 #define CST4330_CBUCK_POWER_OK          0x00004000
272 #define CST4330_BB_PLL_LOCKED           0x00008000
273
274 #define SI_INFO(sih)    (si_info_t *)sih
275
276 #define GOODCOREADDR(x, b) \
277         (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
278                 IS_ALIGNED((x), SI_CORE_SIZE))
279 #define GOODREGS(regs) \
280         ((regs) != NULL && IS_ALIGNED((unsigned long)(regs), SI_CORE_SIZE))
281 #define BADCOREADDR     0
282 #define GOODIDX(idx)    (((uint)idx) < SI_MAXCORES)
283 #define NOREV           -1      /* Invalid rev */
284
285 /* Newer chips can access PCI/PCIE and CC core without requiring to change
286  * PCI BAR0 WIN
287  */
288 #define SI_FAST(si) (((si)->pub.buscoretype == PCIE_CORE_ID) || \
289                      (((si)->pub.buscoretype == PCI_CORE_ID) && \
290                       (si)->pub.buscorerev >= 13))
291
292 #define PCIEREGS(si) (((char *)((si)->curmap) + PCI_16KB0_PCIREGS_OFFSET))
293 #define CCREGS_FAST(si) (((char *)((si)->curmap) + PCI_16KB0_CCREGS_OFFSET))
294
295 /*
296  * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts
297  * before after core switching to avoid invalid register accesss inside ISR.
298  */
299 #define INTR_OFF(si, intr_val) \
300         if ((si)->intrsoff_fn && \
301             (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
302                 intr_val = (*(si)->intrsoff_fn)((si)->intr_arg)
303 #define INTR_RESTORE(si, intr_val) \
304         if ((si)->intrsrestore_fn && \
305             (si)->coreid[(si)->curidx] == (si)->dev_coreid) \
306                 (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val)
307
308 /* dynamic clock control defines */
309 #define LPOMINFREQ              25000   /* low power oscillator min */
310 #define LPOMAXFREQ              43000   /* low power oscillator max */
311 #define XTALMINFREQ             19800000        /* 20 MHz - 1% */
312 #define XTALMAXFREQ             20200000        /* 20 MHz + 1% */
313 #define PCIMINFREQ              25000000        /* 25 MHz */
314 #define PCIMAXFREQ              34000000        /* 33 MHz + fudge */
315
316 #define ILP_DIV_5MHZ            0       /* ILP = 5 MHz */
317 #define ILP_DIV_1MHZ            4       /* ILP = 1 MHz */
318
319 #define PCI(si)         (((si)->pub.bustype == PCI_BUS) &&      \
320                          ((si)->pub.buscoretype == PCI_CORE_ID))
321 #define PCIE(si)        (((si)->pub.bustype == PCI_BUS) &&      \
322                          ((si)->pub.buscoretype == PCIE_CORE_ID))
323 #define PCI_FORCEHT(si) \
324         (PCIE(si) && (si->pub.chip == BCM4716_CHIP_ID))
325
326 /* GPIO Based LED powersave defines */
327 #define DEFAULT_GPIO_ONTIME     10      /* Default: 10% on */
328 #define DEFAULT_GPIO_OFFTIME    90      /* Default: 10% on */
329
330 #ifndef DEFAULT_GPIOTIMERVAL
331 #define DEFAULT_GPIOTIMERVAL \
332         ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
333 #endif
334
335 /*
336  * Data structure to export all chip specific common variables
337  *   public (read-only) portion of aiutils handle returned by si_attach()
338  */
339 struct si_pub {
340         uint bustype;           /* SI_BUS, PCI_BUS */
341         uint buscoretype;       /* PCI_CORE_ID, PCIE_CORE_ID, PCMCIA_CORE_ID */
342         uint buscorerev;        /* buscore rev */
343         uint buscoreidx;        /* buscore index */
344         int ccrev;              /* chip common core rev */
345         u32 cccaps;             /* chip common capabilities */
346         u32 cccaps_ext; /* chip common capabilities extension */
347         int pmurev;             /* pmu core rev */
348         u32 pmucaps;            /* pmu capabilities */
349         uint boardtype;         /* board type */
350         uint boardvendor;       /* board vendor */
351         uint boardflags;        /* board flags */
352         uint boardflags2;       /* board flags2 */
353         uint chip;              /* chip number */
354         uint chiprev;           /* chip revision */
355         uint chippkg;           /* chip package option */
356         u32 chipst;             /* chip status */
357         bool issim;             /* chip is in simulation or emulation */
358         uint socirev;           /* SOC interconnect rev */
359         bool pci_pr32414;
360
361 };
362
363 /*
364  * for HIGH_ONLY driver, the si_t must be writable to allow states sync from
365  * BMAC to HIGH driver for monolithic driver, it is readonly to prevent accident
366  * change
367  */
368 typedef const struct si_pub si_t;
369
370 /*
371  * Many of the routines below take an 'sih' handle as their first arg.
372  * Allocate this by calling si_attach().  Free it by calling si_detach().
373  * At any one time, the sih is logically focused on one particular si core
374  * (the "current core").
375  * Use si_setcore() or si_setcoreidx() to change the association to another core
376  */
377
378 #define BADIDX          (SI_MAXCORES + 1)
379
380 /* clkctl xtal what flags */
381 #define XTAL                    0x1     /* primary crystal oscillator (2050) */
382 #define PLL                     0x2     /* main chip pll */
383
384 /* clkctl clk mode */
385 #define CLK_FAST                0       /* force fast (pll) clock */
386 #define CLK_DYNAMIC             2       /* enable dynamic clock control */
387
388 /* GPIO usage priorities */
389 #define GPIO_DRV_PRIORITY       0       /* Driver */
390 #define GPIO_APP_PRIORITY       1       /* Application */
391 #define GPIO_HI_PRIORITY        2       /* Highest priority. Ignore GPIO
392                                          * reservation
393                                          */
394
395 /* GPIO pull up/down */
396 #define GPIO_PULLUP             0
397 #define GPIO_PULLDN             1
398
399 /* GPIO event regtype */
400 #define GPIO_REGEVT             0       /* GPIO register event */
401 #define GPIO_REGEVT_INTMSK      1       /* GPIO register event int mask */
402 #define GPIO_REGEVT_INTPOL      2       /* GPIO register event int polarity */
403
404 /* device path */
405 #define SI_DEVPATH_BUFSZ        16      /* min buffer size in bytes */
406
407 /* SI routine enumeration: to be used by update function with multiple hooks */
408 #define SI_DOATTACH     1
409 #define SI_PCIDOWN      2
410 #define SI_PCIUP        3
411
412 #define ISSIM_ENAB(sih) 0
413
414 /* PMU clock/power control */
415 #if defined(BCMPMUCTL)
416 #define PMUCTL_ENAB(sih)        (BCMPMUCTL)
417 #else
418 #define PMUCTL_ENAB(sih)        ((sih)->cccaps & CC_CAP_PMU)
419 #endif
420
421 /* chipcommon clock/power control (exclusive with PMU's) */
422 #if defined(BCMPMUCTL) && BCMPMUCTL
423 #define CCCTL_ENAB(sih)         (0)
424 #define CCPLL_ENAB(sih)         (0)
425 #else
426 #define CCCTL_ENAB(sih)         ((sih)->cccaps & CC_CAP_PWR_CTL)
427 #define CCPLL_ENAB(sih)         ((sih)->cccaps & CC_CAP_PLL_MASK)
428 #endif
429
430 typedef void (*gpio_handler_t) (u32 stat, void *arg);
431
432 /* External PA enable mask */
433 #define GPIO_CTRL_EPA_EN_MASK 0x40
434
435 #define SI_ERROR(args)
436
437 #ifdef BCMDBG
438 #define SI_MSG(args)    printk args
439 #else
440 #define SI_MSG(args)
441 #endif                          /* BCMDBG */
442
443 /* Define SI_VMSG to printf for verbose debugging, but don't check it in */
444 #define SI_VMSG(args)
445
446 #define IS_SIM(chippkg) \
447         ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
448
449 typedef u32(*si_intrsoff_t) (void *intr_arg);
450 typedef void (*si_intrsrestore_t) (void *intr_arg, u32 arg);
451 typedef bool(*si_intrsenabled_t) (void *intr_arg);
452
453 typedef struct gpioh_item {
454         void *arg;
455         bool level;
456         gpio_handler_t handler;
457         u32 event;
458         struct gpioh_item *next;
459 } gpioh_item_t;
460
461 /* misc si info needed by some of the routines */
462 typedef struct si_info {
463         struct si_pub pub;      /* back plane public state (must be first) */
464         void *pbus;             /* handle to bus (pci/sdio/..) */
465         uint dev_coreid;        /* the core provides driver functions */
466         void *intr_arg;         /* interrupt callback function arg */
467         si_intrsoff_t intrsoff_fn;      /* turns chip interrupts off */
468         si_intrsrestore_t intrsrestore_fn; /* restore chip interrupts */
469         si_intrsenabled_t intrsenabled_fn; /* check if interrupts are enabled */
470
471         void *pch;              /* PCI/E core handle */
472
473         gpioh_item_t *gpioh_head;       /* GPIO event handlers list */
474
475         bool memseg;            /* flag to toggle MEM_SEG register */
476
477         char *vars;
478         uint varsz;
479
480         void *curmap;           /* current regs va */
481         void *regs[SI_MAXCORES];        /* other regs va */
482
483         uint curidx;            /* current core index */
484         uint numcores;          /* # discovered cores */
485         uint coreid[SI_MAXCORES]; /* id of each core */
486         u32 coresba[SI_MAXCORES]; /* backplane address of each core */
487         void *regs2[SI_MAXCORES]; /* 2nd virtual address per core (usbh20) */
488         u32 coresba2[SI_MAXCORES]; /* 2nd phys address per core (usbh20) */
489         u32 coresba_size[SI_MAXCORES]; /* backplane address space size */
490         u32 coresba2_size[SI_MAXCORES]; /* second address space size */
491
492         void *curwrap;          /* current wrapper va */
493         void *wrappers[SI_MAXCORES];    /* other cores wrapper va */
494         u32 wrapba[SI_MAXCORES];        /* address of controlling wrapper */
495
496         u32 cia[SI_MAXCORES];   /* erom cia entry for each core */
497         u32 cib[SI_MAXCORES];   /* erom cia entry for each core */
498         u32 oob_router; /* oob router registers for axi */
499 } si_info_t;
500
501 /* AMBA Interconnect exported externs */
502 extern void ai_scan(si_t *sih, void *regs, uint devid);
503
504 extern uint ai_flag(si_t *sih);
505 extern void ai_setint(si_t *sih, int siflag);
506 extern uint ai_coreidx(si_t *sih);
507 extern uint ai_corevendor(si_t *sih);
508 extern uint ai_corerev(si_t *sih);
509 extern bool ai_iscoreup(si_t *sih);
510 extern void *ai_setcoreidx(si_t *sih, uint coreidx);
511 extern u32 ai_core_cflags(si_t *sih, u32 mask, u32 val);
512 extern void ai_core_cflags_wo(si_t *sih, u32 mask, u32 val);
513 extern u32 ai_core_sflags(si_t *sih, u32 mask, u32 val);
514 extern uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask,
515                        uint val);
516 extern void ai_core_reset(si_t *sih, u32 bits, u32 resetbits);
517 extern void ai_core_disable(si_t *sih, u32 bits);
518 extern int ai_numaddrspaces(si_t *sih);
519 extern u32 ai_addrspace(si_t *sih, uint asidx);
520 extern u32 ai_addrspacesize(si_t *sih, uint asidx);
521 extern void ai_write_wrap_reg(si_t *sih, u32 offset, u32 val);
522
523 /* === exported functions === */
524 extern si_t *ai_attach(uint pcidev, void *regs, uint bustype,
525                        void *sdh, char **vars, uint *varsz);
526
527 extern void ai_detach(si_t *sih);
528 extern bool ai_pci_war16165(si_t *sih);
529
530 extern uint ai_coreid(si_t *sih);
531 extern uint ai_corerev(si_t *sih);
532 extern uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask,
533                 uint val);
534 extern void ai_write_wrapperreg(si_t *sih, u32 offset, u32 val);
535 extern u32 ai_core_cflags(si_t *sih, u32 mask, u32 val);
536 extern u32 ai_core_sflags(si_t *sih, u32 mask, u32 val);
537 extern bool ai_iscoreup(si_t *sih);
538 extern uint ai_findcoreidx(si_t *sih, uint coreid, uint coreunit);
539 extern void *ai_setcoreidx(si_t *sih, uint coreidx);
540 extern void *ai_setcore(si_t *sih, uint coreid, uint coreunit);
541 extern void *ai_switch_core(si_t *sih, uint coreid, uint *origidx,
542                             uint *intr_val);
543 extern void ai_restore_core(si_t *sih, uint coreid, uint intr_val);
544 extern void ai_core_reset(si_t *sih, u32 bits, u32 resetbits);
545 extern void ai_core_disable(si_t *sih, u32 bits);
546 extern u32 ai_alp_clock(si_t *sih);
547 extern u32 ai_ilp_clock(si_t *sih);
548 extern void ai_pci_setup(si_t *sih, uint coremask);
549 extern void ai_setint(si_t *sih, int siflag);
550 extern bool ai_backplane64(si_t *sih);
551 extern void ai_register_intr_callback(si_t *sih, void *intrsoff_fn,
552                                       void *intrsrestore_fn,
553                                       void *intrsenabled_fn, void *intr_arg);
554 extern void ai_deregister_intr_callback(si_t *sih);
555 extern void ai_clkctl_init(si_t *sih);
556 extern u16 ai_clkctl_fast_pwrup_delay(si_t *sih);
557 extern bool ai_clkctl_cc(si_t *sih, uint mode);
558 extern int ai_clkctl_xtal(si_t *sih, uint what, bool on);
559 extern bool ai_deviceremoved(si_t *sih);
560 extern u32 ai_gpiocontrol(si_t *sih, u32 mask, u32 val,
561                              u8 priority);
562
563 /* OTP status */
564 extern bool ai_is_otp_disabled(si_t *sih);
565 extern bool ai_is_otp_powered(si_t *sih);
566 extern void ai_otp_power(si_t *sih, bool on);
567
568 /* SPROM availability */
569 extern bool ai_is_sprom_available(si_t *sih);
570
571 /*
572  * Build device path. Path size must be >= SI_DEVPATH_BUFSZ.
573  * The returned path is NULL terminated and has trailing '/'.
574  * Return 0 on success, nonzero otherwise.
575  */
576 extern int ai_devpath(si_t *sih, char *path, int size);
577 /* Read variable with prepending the devpath to the name */
578 extern char *ai_getdevpathvar(si_t *sih, const char *name);
579 extern int ai_getdevpathintvar(si_t *sih, const char *name);
580
581 extern void ai_pci_sleep(si_t *sih);
582 extern void ai_pci_down(si_t *sih);
583 extern void ai_pci_up(si_t *sih);
584 extern int ai_pci_fixcfg(si_t *sih);
585
586 extern void ai_chipcontrl_epa4331(si_t *sih, bool on);
587 /* Enable Ex-PA for 4313 */
588 extern void ai_epa_4313war(si_t *sih);
589
590 char *ai_getnvramflvar(si_t *sih, const char *name);
591
592 #endif                          /* _aiutils_h_ */