1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef _siutils_h_
18#define _siutils_h_
19
20#include <hndsoc.h>
21
22#if !defined(WLC_LOW)
23#include "bcm_rpc.h"
24#endif
25
26
27
28
29struct si_pub {
30 uint socitype;
31
32 uint bustype;
33 uint buscoretype;
34 uint buscorerev;
35 uint buscoreidx;
36 int ccrev;
37 u32 cccaps;
38 u32 cccaps_ext;
39 int pmurev;
40 u32 pmucaps;
41 uint boardtype;
42 uint boardvendor;
43 uint boardflags;
44 uint boardflags2;
45 uint chip;
46 uint chiprev;
47 uint chippkg;
48 u32 chipst;
49 bool issim;
50 uint socirev;
51 bool pci_pr32414;
52
53#if !defined(WLC_LOW)
54 rpc_info_t *rpc;
55#endif
56};
57
58
59
60
61#if !defined(WLC_LOW)
62typedef struct si_pub si_t;
63#else
64typedef const struct si_pub si_t;
65#endif
66
67
68
69
70
71
72
73
74
75#define BADIDX (SI_MAXCORES + 1)
76
77
78#define XTAL 0x1
79#define PLL 0x2
80
81
82#define CLK_FAST 0
83#define CLK_DYNAMIC 2
84
85
86#define GPIO_DRV_PRIORITY 0
87#define GPIO_APP_PRIORITY 1
88#define GPIO_HI_PRIORITY 2
89
90
91#define GPIO_PULLUP 0
92#define GPIO_PULLDN 1
93
94
95#define GPIO_REGEVT 0
96#define GPIO_REGEVT_INTMSK 1
97#define GPIO_REGEVT_INTPOL 2
98
99
100#define SI_DEVPATH_BUFSZ 16
101
102
103#define SI_DOATTACH 1
104#define SI_PCIDOWN 2
105#define SI_PCIUP 3
106
107#define ISSIM_ENAB(sih) 0
108
109
110#if defined(BCMPMUCTL)
111#define PMUCTL_ENAB(sih) (BCMPMUCTL)
112#else
113#define PMUCTL_ENAB(sih) ((sih)->cccaps & CC_CAP_PMU)
114#endif
115
116
117#if defined(BCMPMUCTL) && BCMPMUCTL
118#define CCCTL_ENAB(sih) (0)
119#define CCPLL_ENAB(sih) (0)
120#else
121#define CCCTL_ENAB(sih) ((sih)->cccaps & CC_CAP_PWR_CTL)
122#define CCPLL_ENAB(sih) ((sih)->cccaps & CC_CAP_PLL_MASK)
123#endif
124
125typedef void (*gpio_handler_t) (u32 stat, void *arg);
126
127
128#define GPIO_CTRL_EPA_EN_MASK 0x40
129
130
131extern si_t *si_attach(uint pcidev, osl_t *osh, void *regs, uint bustype,
132 void *sdh, char **vars, uint *varsz);
133
134extern void si_detach(si_t *sih);
135extern bool si_pci_war16165(si_t *sih);
136
137extern uint si_coreid(si_t *sih);
138extern uint si_flag(si_t *sih);
139extern uint si_coreidx(si_t *sih);
140extern uint si_corerev(si_t *sih);
141extern void *si_osh(si_t *sih);
142extern uint si_corereg(si_t *sih, uint coreidx, uint regoff, uint mask,
143 uint val);
144extern void si_write_wrapperreg(si_t *sih, u32 offset, u32 val);
145extern u32 si_core_cflags(si_t *sih, u32 mask, u32 val);
146extern u32 si_core_sflags(si_t *sih, u32 mask, u32 val);
147extern bool si_iscoreup(si_t *sih);
148extern uint si_findcoreidx(si_t *sih, uint coreid, uint coreunit);
149#ifndef BCMSDIO
150extern void *si_setcoreidx(si_t *sih, uint coreidx);
151#endif
152extern void *si_setcore(si_t *sih, uint coreid, uint coreunit);
153extern void *si_switch_core(si_t *sih, uint coreid, uint *origidx,
154 uint *intr_val);
155extern void si_restore_core(si_t *sih, uint coreid, uint intr_val);
156extern void si_core_reset(si_t *sih, u32 bits, u32 resetbits);
157extern void si_core_disable(si_t *sih, u32 bits);
158extern u32 si_alp_clock(si_t *sih);
159extern u32 si_ilp_clock(si_t *sih);
160extern void si_pci_setup(si_t *sih, uint coremask);
161extern void si_setint(si_t *sih, int siflag);
162extern bool si_backplane64(si_t *sih);
163extern void si_register_intr_callback(si_t *sih, void *intrsoff_fn,
164 void *intrsrestore_fn,
165 void *intrsenabled_fn, void *intr_arg);
166extern void si_deregister_intr_callback(si_t *sih);
167extern void si_clkctl_init(si_t *sih);
168extern u16 si_clkctl_fast_pwrup_delay(si_t *sih);
169extern bool si_clkctl_cc(si_t *sih, uint mode);
170extern int si_clkctl_xtal(si_t *sih, uint what, bool on);
171extern bool si_deviceremoved(si_t *sih);
172extern u32 si_socram_size(si_t *sih);
173
174extern void si_watchdog(si_t *sih, uint ticks);
175extern u32 si_gpiocontrol(si_t *sih, u32 mask, u32 val,
176 u8 priority);
177
178#ifdef BCMSDIO
179extern void si_sdio_init(si_t *sih);
180#endif
181
182#define si_eci(sih) 0
183#define si_eci_init(sih) (0)
184#define si_eci_notify_bt(sih, type, val) (0)
185#define si_seci(sih) 0
186static inline void *si_seci_init(si_t *sih, u8 use_seci)
187{
188 return NULL;
189}
190
191
192extern bool si_is_otp_disabled(si_t *sih);
193extern bool si_is_otp_powered(si_t *sih);
194extern void si_otp_power(si_t *sih, bool on);
195
196
197extern bool si_is_sprom_available(si_t *sih);
198#ifdef SI_SPROM_PROBE
199extern void si_sprom_init(si_t *sih);
200#endif
201
202#define SI_ERROR(args)
203
204#ifdef BCMDBG
205#define SI_MSG(args) printf args
206#else
207#define SI_MSG(args)
208#endif
209
210
211#define SI_VMSG(args)
212
213#define IS_SIM(chippkg) ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
214
215typedef u32(*si_intrsoff_t) (void *intr_arg);
216typedef void (*si_intrsrestore_t) (void *intr_arg, u32 arg);
217typedef bool(*si_intrsenabled_t) (void *intr_arg);
218
219typedef struct gpioh_item {
220 void *arg;
221 bool level;
222 gpio_handler_t handler;
223 u32 event;
224 struct gpioh_item *next;
225} gpioh_item_t;
226
227
228typedef struct si_info {
229 struct si_pub pub;
230 void *osh;
231 void *sdh;
232 uint dev_coreid;
233 void *intr_arg;
234 si_intrsoff_t intrsoff_fn;
235 si_intrsrestore_t intrsrestore_fn;
236 si_intrsenabled_t intrsenabled_fn;
237
238 void *pch;
239
240 gpioh_item_t *gpioh_head;
241
242 bool memseg;
243
244 char *vars;
245 uint varsz;
246
247 void *curmap;
248 void *regs[SI_MAXCORES];
249
250 uint curidx;
251 uint numcores;
252 uint coreid[SI_MAXCORES];
253 u32 coresba[SI_MAXCORES];
254 void *regs2[SI_MAXCORES];
255 u32 coresba2[SI_MAXCORES];
256 u32 coresba_size[SI_MAXCORES];
257 u32 coresba2_size[SI_MAXCORES];
258
259 void *curwrap;
260 void *wrappers[SI_MAXCORES];
261 u32 wrapba[SI_MAXCORES];
262
263 u32 cia[SI_MAXCORES];
264 u32 cib[SI_MAXCORES];
265 u32 oob_router;
266} si_info_t;
267
268#define SI_INFO(sih) (si_info_t *)sih
269
270#define GOODCOREADDR(x, b) (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
271 IS_ALIGNED((x), SI_CORE_SIZE))
272#define GOODREGS(regs) ((regs) != NULL && IS_ALIGNED((unsigned long)(regs), SI_CORE_SIZE))
273#define BADCOREADDR 0
274#define GOODIDX(idx) (((uint)idx) < SI_MAXCORES)
275#define NOREV -1
276
277
278
279
280#define SI_FAST(si) (((si)->pub.buscoretype == PCIE_CORE_ID) || \
281 (((si)->pub.buscoretype == PCI_CORE_ID) && (si)->pub.buscorerev >= 13))
282
283#define PCIEREGS(si) (((char *)((si)->curmap) + PCI_16KB0_PCIREGS_OFFSET))
284#define CCREGS_FAST(si) (((char *)((si)->curmap) + PCI_16KB0_CCREGS_OFFSET))
285
286
287
288
289
290#define INTR_OFF(si, intr_val) \
291 if ((si)->intrsoff_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) { \
292 intr_val = (*(si)->intrsoff_fn)((si)->intr_arg); }
293#define INTR_RESTORE(si, intr_val) \
294 if ((si)->intrsrestore_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) { \
295 (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val); }
296
297
298#define LPOMINFREQ 25000
299#define LPOMAXFREQ 43000
300#define XTALMINFREQ 19800000
301#define XTALMAXFREQ 20200000
302#define PCIMINFREQ 25000000
303#define PCIMAXFREQ 34000000
304
305#define ILP_DIV_5MHZ 0
306#define ILP_DIV_1MHZ 4
307
308#define PCI(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \
309 ((si)->pub.buscoretype == PCI_CORE_ID))
310#define PCIE(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \
311 ((si)->pub.buscoretype == PCIE_CORE_ID))
312#define PCI_FORCEHT(si) \
313 (PCIE(si) && (si->pub.chip == BCM4716_CHIP_ID))
314
315
316#define DEFAULT_GPIO_ONTIME 10
317#define DEFAULT_GPIO_OFFTIME 90
318
319#ifndef DEFAULT_GPIOTIMERVAL
320#define DEFAULT_GPIOTIMERVAL ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
321#endif
322
323
324
325
326
327
328extern int si_devpath(si_t *sih, char *path, int size);
329
330extern char *si_getdevpathvar(si_t *sih, const char *name);
331extern int si_getdevpathintvar(si_t *sih, const char *name);
332
333extern void si_war42780_clkreq(si_t *sih, bool clkreq);
334extern void si_pci_sleep(si_t *sih);
335extern void si_pci_down(si_t *sih);
336extern void si_pci_up(si_t *sih);
337extern void si_pcie_extendL1timer(si_t *sih, bool extend);
338extern int si_pci_fixcfg(si_t *sih);
339
340extern void si_chipcontrl_epa4331(si_t *sih, bool on);
341
342extern void si_epa_4313war(si_t *sih);
343
344char *si_getnvramflvar(si_t *sih, const char *name);
345
346
347extern si_t *ai_attach(uint pcidev, osl_t *osh, void *regs, uint bustype,
348 void *sdh, char **vars, uint *varsz);
349extern si_t *ai_kattach(osl_t *osh);
350extern void ai_scan(si_t *sih, void *regs, uint devid);
351
352extern uint ai_flag(si_t *sih);
353extern void ai_setint(si_t *sih, int siflag);
354extern uint ai_coreidx(si_t *sih);
355extern uint ai_corevendor(si_t *sih);
356extern uint ai_corerev(si_t *sih);
357extern bool ai_iscoreup(si_t *sih);
358extern void *ai_setcoreidx(si_t *sih, uint coreidx);
359extern u32 ai_core_cflags(si_t *sih, u32 mask, u32 val);
360extern void ai_core_cflags_wo(si_t *sih, u32 mask, u32 val);
361extern u32 ai_core_sflags(si_t *sih, u32 mask, u32 val);
362extern uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask,
363 uint val);
364extern void ai_core_reset(si_t *sih, u32 bits, u32 resetbits);
365extern void ai_core_disable(si_t *sih, u32 bits);
366extern int ai_numaddrspaces(si_t *sih);
367extern u32 ai_addrspace(si_t *sih, uint asidx);
368extern u32 ai_addrspacesize(si_t *sih, uint asidx);
369extern void ai_write_wrap_reg(si_t *sih, u32 offset, u32 val);
370
371#ifdef BCMSDIO
372#define si_setcoreidx(sih, idx) sb_setcoreidx(sih, idx)
373#define si_coreid(sih) sb_coreid(sih)
374#define si_corerev(sih) sb_corerev(sih)
375#endif
376
377#endif
378