xref: /freebsd/sys/contrib/dev/broadcom/brcm80211/brcmsmac/aiutils.h (revision b4c3e9b5b09c829b4135aff738bd2893ed052377)
1*b4c3e9b5SBjoern A. Zeeb /*
2*b4c3e9b5SBjoern A. Zeeb  * Copyright (c) 2011 Broadcom Corporation
3*b4c3e9b5SBjoern A. Zeeb  *
4*b4c3e9b5SBjoern A. Zeeb  * Permission to use, copy, modify, and/or distribute this software for any
5*b4c3e9b5SBjoern A. Zeeb  * purpose with or without fee is hereby granted, provided that the above
6*b4c3e9b5SBjoern A. Zeeb  * copyright notice and this permission notice appear in all copies.
7*b4c3e9b5SBjoern A. Zeeb  *
8*b4c3e9b5SBjoern A. Zeeb  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*b4c3e9b5SBjoern A. Zeeb  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*b4c3e9b5SBjoern A. Zeeb  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11*b4c3e9b5SBjoern A. Zeeb  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*b4c3e9b5SBjoern A. Zeeb  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13*b4c3e9b5SBjoern A. Zeeb  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14*b4c3e9b5SBjoern A. Zeeb  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*b4c3e9b5SBjoern A. Zeeb  */
16*b4c3e9b5SBjoern A. Zeeb 
17*b4c3e9b5SBjoern A. Zeeb #ifndef	_BRCM_AIUTILS_H_
18*b4c3e9b5SBjoern A. Zeeb #define	_BRCM_AIUTILS_H_
19*b4c3e9b5SBjoern A. Zeeb 
20*b4c3e9b5SBjoern A. Zeeb #include <linux/bcma/bcma.h>
21*b4c3e9b5SBjoern A. Zeeb 
22*b4c3e9b5SBjoern A. Zeeb #include "types.h"
23*b4c3e9b5SBjoern A. Zeeb 
24*b4c3e9b5SBjoern A. Zeeb /*
25*b4c3e9b5SBjoern A. Zeeb  * SOC Interconnect Address Map.
26*b4c3e9b5SBjoern A. Zeeb  * All regions may not exist on all chips.
27*b4c3e9b5SBjoern A. Zeeb  */
28*b4c3e9b5SBjoern A. Zeeb /* each core gets 4Kbytes for registers */
29*b4c3e9b5SBjoern A. Zeeb #define SI_CORE_SIZE		0x1000
30*b4c3e9b5SBjoern A. Zeeb /*
31*b4c3e9b5SBjoern A. Zeeb  * Max cores (this is arbitrary, for software
32*b4c3e9b5SBjoern A. Zeeb  * convenience and could be changed if we
33*b4c3e9b5SBjoern A. Zeeb  * make any larger chips
34*b4c3e9b5SBjoern A. Zeeb  */
35*b4c3e9b5SBjoern A. Zeeb #define	SI_MAXCORES		16
36*b4c3e9b5SBjoern A. Zeeb 
37*b4c3e9b5SBjoern A. Zeeb /* Client Mode sb2pcitranslation2 size in bytes */
38*b4c3e9b5SBjoern A. Zeeb #define SI_PCI_DMA_SZ		0x40000000
39*b4c3e9b5SBjoern A. Zeeb 
40*b4c3e9b5SBjoern A. Zeeb /* PCIE Client Mode sb2pcitranslation2 (2 ZettaBytes), high 32 bits */
41*b4c3e9b5SBjoern A. Zeeb #define SI_PCIE_DMA_H32		0x80000000
42*b4c3e9b5SBjoern A. Zeeb 
43*b4c3e9b5SBjoern A. Zeeb /* chipcommon being the first core: */
44*b4c3e9b5SBjoern A. Zeeb #define	SI_CC_IDX		0
45*b4c3e9b5SBjoern A. Zeeb 
46*b4c3e9b5SBjoern A. Zeeb /* SOC Interconnect types (aka chip types) */
47*b4c3e9b5SBjoern A. Zeeb #define	SOCI_AI			1
48*b4c3e9b5SBjoern A. Zeeb 
49*b4c3e9b5SBjoern A. Zeeb /* A register that is common to all cores to
50*b4c3e9b5SBjoern A. Zeeb  * communicate w/PMU regarding clock control.
51*b4c3e9b5SBjoern A. Zeeb  */
52*b4c3e9b5SBjoern A. Zeeb #define SI_CLK_CTL_ST		0x1e0	/* clock control and status */
53*b4c3e9b5SBjoern A. Zeeb 
54*b4c3e9b5SBjoern A. Zeeb /* clk_ctl_st register */
55*b4c3e9b5SBjoern A. Zeeb #define	CCS_FORCEALP		0x00000001	/* force ALP request */
56*b4c3e9b5SBjoern A. Zeeb #define	CCS_FORCEHT		0x00000002	/* force HT request */
57*b4c3e9b5SBjoern A. Zeeb #define	CCS_FORCEILP		0x00000004	/* force ILP request */
58*b4c3e9b5SBjoern A. Zeeb #define	CCS_ALPAREQ		0x00000008	/* ALP Avail Request */
59*b4c3e9b5SBjoern A. Zeeb #define	CCS_HTAREQ		0x00000010	/* HT Avail Request */
60*b4c3e9b5SBjoern A. Zeeb #define	CCS_FORCEHWREQOFF	0x00000020	/* Force HW Clock Request Off */
61*b4c3e9b5SBjoern A. Zeeb #define CCS_ERSRC_REQ_MASK	0x00000700	/* external resource requests */
62*b4c3e9b5SBjoern A. Zeeb #define CCS_ERSRC_REQ_SHIFT	8
63*b4c3e9b5SBjoern A. Zeeb #define	CCS_ALPAVAIL		0x00010000	/* ALP is available */
64*b4c3e9b5SBjoern A. Zeeb #define	CCS_HTAVAIL		0x00020000	/* HT is available */
65*b4c3e9b5SBjoern A. Zeeb #define CCS_BP_ON_APL		0x00040000	/* RO: running on ALP clock */
66*b4c3e9b5SBjoern A. Zeeb #define CCS_BP_ON_HT		0x00080000	/* RO: running on HT clock */
67*b4c3e9b5SBjoern A. Zeeb #define CCS_ERSRC_STS_MASK	0x07000000	/* external resource status */
68*b4c3e9b5SBjoern A. Zeeb #define CCS_ERSRC_STS_SHIFT	24
69*b4c3e9b5SBjoern A. Zeeb 
70*b4c3e9b5SBjoern A. Zeeb /* HT avail in chipc and pcmcia on 4328a0 */
71*b4c3e9b5SBjoern A. Zeeb #define	CCS0_HTAVAIL		0x00010000
72*b4c3e9b5SBjoern A. Zeeb /* ALP avail in chipc and pcmcia on 4328a0 */
73*b4c3e9b5SBjoern A. Zeeb #define	CCS0_ALPAVAIL		0x00020000
74*b4c3e9b5SBjoern A. Zeeb 
75*b4c3e9b5SBjoern A. Zeeb /* Not really related to SOC Interconnect, but a couple of software
76*b4c3e9b5SBjoern A. Zeeb  * conventions for the use the flash space:
77*b4c3e9b5SBjoern A. Zeeb  */
78*b4c3e9b5SBjoern A. Zeeb 
79*b4c3e9b5SBjoern A. Zeeb /* Minimum amount of flash we support */
80*b4c3e9b5SBjoern A. Zeeb #define FLASH_MIN		0x00020000	/* Minimum flash size */
81*b4c3e9b5SBjoern A. Zeeb 
82*b4c3e9b5SBjoern A. Zeeb #define	CC_SROM_OTP		0x800	/* SROM/OTP address space */
83*b4c3e9b5SBjoern A. Zeeb 
84*b4c3e9b5SBjoern A. Zeeb /* gpiotimerval */
85*b4c3e9b5SBjoern A. Zeeb #define GPIO_ONTIME_SHIFT	16
86*b4c3e9b5SBjoern A. Zeeb 
87*b4c3e9b5SBjoern A. Zeeb /* Fields in clkdiv */
88*b4c3e9b5SBjoern A. Zeeb #define	CLKD_OTP		0x000f0000
89*b4c3e9b5SBjoern A. Zeeb #define	CLKD_OTP_SHIFT		16
90*b4c3e9b5SBjoern A. Zeeb 
91*b4c3e9b5SBjoern A. Zeeb /* dynamic clock control defines */
92*b4c3e9b5SBjoern A. Zeeb #define	LPOMINFREQ		25000	/* low power oscillator min */
93*b4c3e9b5SBjoern A. Zeeb #define	LPOMAXFREQ		43000	/* low power oscillator max */
94*b4c3e9b5SBjoern A. Zeeb #define	XTALMINFREQ		19800000	/* 20 MHz - 1% */
95*b4c3e9b5SBjoern A. Zeeb #define	XTALMAXFREQ		20200000	/* 20 MHz + 1% */
96*b4c3e9b5SBjoern A. Zeeb #define	PCIMINFREQ		25000000	/* 25 MHz */
97*b4c3e9b5SBjoern A. Zeeb #define	PCIMAXFREQ		34000000	/* 33 MHz + fudge */
98*b4c3e9b5SBjoern A. Zeeb 
99*b4c3e9b5SBjoern A. Zeeb #define	ILP_DIV_5MHZ		0	/* ILP = 5 MHz */
100*b4c3e9b5SBjoern A. Zeeb #define	ILP_DIV_1MHZ		4	/* ILP = 1 MHz */
101*b4c3e9b5SBjoern A. Zeeb 
102*b4c3e9b5SBjoern A. Zeeb /* clkctl xtal what flags */
103*b4c3e9b5SBjoern A. Zeeb #define	XTAL			0x1	/* primary crystal oscillator (2050) */
104*b4c3e9b5SBjoern A. Zeeb #define	PLL			0x2	/* main chip pll */
105*b4c3e9b5SBjoern A. Zeeb 
106*b4c3e9b5SBjoern A. Zeeb /* GPIO usage priorities */
107*b4c3e9b5SBjoern A. Zeeb #define GPIO_DRV_PRIORITY	0	/* Driver */
108*b4c3e9b5SBjoern A. Zeeb #define GPIO_APP_PRIORITY	1	/* Application */
109*b4c3e9b5SBjoern A. Zeeb #define GPIO_HI_PRIORITY	2	/* Highest priority. Ignore GPIO
110*b4c3e9b5SBjoern A. Zeeb 					 * reservation
111*b4c3e9b5SBjoern A. Zeeb 					 */
112*b4c3e9b5SBjoern A. Zeeb 
113*b4c3e9b5SBjoern A. Zeeb /* GPIO pull up/down */
114*b4c3e9b5SBjoern A. Zeeb #define GPIO_PULLUP		0
115*b4c3e9b5SBjoern A. Zeeb #define GPIO_PULLDN		1
116*b4c3e9b5SBjoern A. Zeeb 
117*b4c3e9b5SBjoern A. Zeeb /* GPIO event regtype */
118*b4c3e9b5SBjoern A. Zeeb #define GPIO_REGEVT		0	/* GPIO register event */
119*b4c3e9b5SBjoern A. Zeeb #define GPIO_REGEVT_INTMSK	1	/* GPIO register event int mask */
120*b4c3e9b5SBjoern A. Zeeb #define GPIO_REGEVT_INTPOL	2	/* GPIO register event int polarity */
121*b4c3e9b5SBjoern A. Zeeb 
122*b4c3e9b5SBjoern A. Zeeb /* device path */
123*b4c3e9b5SBjoern A. Zeeb #define SI_DEVPATH_BUFSZ	16	/* min buffer size in bytes */
124*b4c3e9b5SBjoern A. Zeeb 
125*b4c3e9b5SBjoern A. Zeeb /* SI routine enumeration: to be used by update function with multiple hooks */
126*b4c3e9b5SBjoern A. Zeeb #define	SI_DOATTACH	1
127*b4c3e9b5SBjoern A. Zeeb #define SI_PCIDOWN	2
128*b4c3e9b5SBjoern A. Zeeb #define SI_PCIUP	3
129*b4c3e9b5SBjoern A. Zeeb 
130*b4c3e9b5SBjoern A. Zeeb /*
131*b4c3e9b5SBjoern A. Zeeb  * Data structure to export all chip specific common variables
132*b4c3e9b5SBjoern A. Zeeb  *   public (read-only) portion of aiutils handle returned by si_attach()
133*b4c3e9b5SBjoern A. Zeeb  */
134*b4c3e9b5SBjoern A. Zeeb struct si_pub {
135*b4c3e9b5SBjoern A. Zeeb 	int ccrev;		/* chip common core rev */
136*b4c3e9b5SBjoern A. Zeeb 	u32 cccaps;		/* chip common capabilities */
137*b4c3e9b5SBjoern A. Zeeb 	int pmurev;		/* pmu core rev */
138*b4c3e9b5SBjoern A. Zeeb 	u32 pmucaps;		/* pmu capabilities */
139*b4c3e9b5SBjoern A. Zeeb 	uint boardtype;		/* board type */
140*b4c3e9b5SBjoern A. Zeeb 	uint boardvendor;	/* board vendor */
141*b4c3e9b5SBjoern A. Zeeb 	uint chip;		/* chip number */
142*b4c3e9b5SBjoern A. Zeeb 	uint chiprev;		/* chip revision */
143*b4c3e9b5SBjoern A. Zeeb 	uint chippkg;		/* chip package option */
144*b4c3e9b5SBjoern A. Zeeb };
145*b4c3e9b5SBjoern A. Zeeb 
146*b4c3e9b5SBjoern A. Zeeb struct pci_dev;
147*b4c3e9b5SBjoern A. Zeeb 
148*b4c3e9b5SBjoern A. Zeeb /* misc si info needed by some of the routines */
149*b4c3e9b5SBjoern A. Zeeb struct si_info {
150*b4c3e9b5SBjoern A. Zeeb 	struct si_pub pub;	/* back plane public state (must be first) */
151*b4c3e9b5SBjoern A. Zeeb 	struct bcma_bus *icbus;	/* handle to soc interconnect bus */
152*b4c3e9b5SBjoern A. Zeeb 	struct pci_dev *pcibus;	/* handle to pci bus */
153*b4c3e9b5SBjoern A. Zeeb 
154*b4c3e9b5SBjoern A. Zeeb 	u32 chipst;		/* chip status */
155*b4c3e9b5SBjoern A. Zeeb };
156*b4c3e9b5SBjoern A. Zeeb 
157*b4c3e9b5SBjoern A. Zeeb /*
158*b4c3e9b5SBjoern A. Zeeb  * Many of the routines below take an 'sih' handle as their first arg.
159*b4c3e9b5SBjoern A. Zeeb  * Allocate this by calling si_attach().  Free it by calling si_detach().
160*b4c3e9b5SBjoern A. Zeeb  * At any one time, the sih is logically focused on one particular si core
161*b4c3e9b5SBjoern A. Zeeb  * (the "current core").
162*b4c3e9b5SBjoern A. Zeeb  * Use si_setcore() or si_setcoreidx() to change the association to another core
163*b4c3e9b5SBjoern A. Zeeb  */
164*b4c3e9b5SBjoern A. Zeeb 
165*b4c3e9b5SBjoern A. Zeeb 
166*b4c3e9b5SBjoern A. Zeeb /* AMBA Interconnect exported externs */
167*b4c3e9b5SBjoern A. Zeeb u32 ai_core_cflags(struct bcma_device *core, u32 mask, u32 val);
168*b4c3e9b5SBjoern A. Zeeb 
169*b4c3e9b5SBjoern A. Zeeb /* === exported functions === */
170*b4c3e9b5SBjoern A. Zeeb struct si_pub *ai_attach(struct bcma_bus *pbus);
171*b4c3e9b5SBjoern A. Zeeb void ai_detach(struct si_pub *sih);
172*b4c3e9b5SBjoern A. Zeeb uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val);
173*b4c3e9b5SBjoern A. Zeeb void ai_clkctl_init(struct si_pub *sih);
174*b4c3e9b5SBjoern A. Zeeb u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih);
175*b4c3e9b5SBjoern A. Zeeb bool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode);
176*b4c3e9b5SBjoern A. Zeeb bool ai_deviceremoved(struct si_pub *sih);
177*b4c3e9b5SBjoern A. Zeeb 
178*b4c3e9b5SBjoern A. Zeeb /* Enable Ex-PA for 4313 */
179*b4c3e9b5SBjoern A. Zeeb void ai_epa_4313war(struct si_pub *sih);
180*b4c3e9b5SBjoern A. Zeeb 
ai_get_cccaps(struct si_pub * sih)181*b4c3e9b5SBjoern A. Zeeb static inline u32 ai_get_cccaps(struct si_pub *sih)
182*b4c3e9b5SBjoern A. Zeeb {
183*b4c3e9b5SBjoern A. Zeeb 	return sih->cccaps;
184*b4c3e9b5SBjoern A. Zeeb }
185*b4c3e9b5SBjoern A. Zeeb 
ai_get_pmurev(struct si_pub * sih)186*b4c3e9b5SBjoern A. Zeeb static inline int ai_get_pmurev(struct si_pub *sih)
187*b4c3e9b5SBjoern A. Zeeb {
188*b4c3e9b5SBjoern A. Zeeb 	return sih->pmurev;
189*b4c3e9b5SBjoern A. Zeeb }
190*b4c3e9b5SBjoern A. Zeeb 
ai_get_pmucaps(struct si_pub * sih)191*b4c3e9b5SBjoern A. Zeeb static inline u32 ai_get_pmucaps(struct si_pub *sih)
192*b4c3e9b5SBjoern A. Zeeb {
193*b4c3e9b5SBjoern A. Zeeb 	return sih->pmucaps;
194*b4c3e9b5SBjoern A. Zeeb }
195*b4c3e9b5SBjoern A. Zeeb 
ai_get_boardtype(struct si_pub * sih)196*b4c3e9b5SBjoern A. Zeeb static inline uint ai_get_boardtype(struct si_pub *sih)
197*b4c3e9b5SBjoern A. Zeeb {
198*b4c3e9b5SBjoern A. Zeeb 	return sih->boardtype;
199*b4c3e9b5SBjoern A. Zeeb }
200*b4c3e9b5SBjoern A. Zeeb 
ai_get_boardvendor(struct si_pub * sih)201*b4c3e9b5SBjoern A. Zeeb static inline uint ai_get_boardvendor(struct si_pub *sih)
202*b4c3e9b5SBjoern A. Zeeb {
203*b4c3e9b5SBjoern A. Zeeb 	return sih->boardvendor;
204*b4c3e9b5SBjoern A. Zeeb }
205*b4c3e9b5SBjoern A. Zeeb 
ai_get_chip_id(struct si_pub * sih)206*b4c3e9b5SBjoern A. Zeeb static inline uint ai_get_chip_id(struct si_pub *sih)
207*b4c3e9b5SBjoern A. Zeeb {
208*b4c3e9b5SBjoern A. Zeeb 	return sih->chip;
209*b4c3e9b5SBjoern A. Zeeb }
210*b4c3e9b5SBjoern A. Zeeb 
ai_get_chiprev(struct si_pub * sih)211*b4c3e9b5SBjoern A. Zeeb static inline uint ai_get_chiprev(struct si_pub *sih)
212*b4c3e9b5SBjoern A. Zeeb {
213*b4c3e9b5SBjoern A. Zeeb 	return sih->chiprev;
214*b4c3e9b5SBjoern A. Zeeb }
215*b4c3e9b5SBjoern A. Zeeb 
ai_get_chippkg(struct si_pub * sih)216*b4c3e9b5SBjoern A. Zeeb static inline uint ai_get_chippkg(struct si_pub *sih)
217*b4c3e9b5SBjoern A. Zeeb {
218*b4c3e9b5SBjoern A. Zeeb 	return sih->chippkg;
219*b4c3e9b5SBjoern A. Zeeb }
220*b4c3e9b5SBjoern A. Zeeb 
221*b4c3e9b5SBjoern A. Zeeb #endif				/* _BRCM_AIUTILS_H_ */
222