initial commit with v3.6.7
[linux-3.6.7-moxart.git] / drivers / net / wireless / brcm80211 / brcmfmac / sdio_host.h
blob29bf78d264e096d9b81cb2efd3ac527a34d80d61
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #ifndef _BRCM_SDH_H_
18 #define _BRCM_SDH_H_
20 #include <linux/skbuff.h>
22 #define SDIO_FUNC_0 0
23 #define SDIO_FUNC_1 1
24 #define SDIO_FUNC_2 2
26 #define SDIOD_FBR_SIZE 0x100
28 /* io_en */
29 #define SDIO_FUNC_ENABLE_1 0x02
30 #define SDIO_FUNC_ENABLE_2 0x04
32 /* io_rdys */
33 #define SDIO_FUNC_READY_1 0x02
34 #define SDIO_FUNC_READY_2 0x04
36 /* intr_status */
37 #define INTR_STATUS_FUNC1 0x2
38 #define INTR_STATUS_FUNC2 0x4
40 /* Maximum number of I/O funcs */
41 #define SDIOD_MAX_IOFUNCS 7
43 /* mask of register map */
44 #define REG_F0_REG_MASK 0x7FF
45 #define REG_F1_MISC_MASK 0x1FFFF
47 /* as of sdiod rev 0, supports 3 functions */
48 #define SBSDIO_NUM_FUNCTION 3
50 /* function 0 vendor specific CCCR registers */
51 #define SDIO_CCCR_BRCM_SEPINT 0xf2
53 #define SDIO_SEPINT_MASK 0x01
54 #define SDIO_SEPINT_OE 0x02
55 #define SDIO_SEPINT_ACT_HI 0x04
57 /* function 1 miscellaneous registers */
59 /* sprom command and status */
60 #define SBSDIO_SPROM_CS 0x10000
61 /* sprom info register */
62 #define SBSDIO_SPROM_INFO 0x10001
63 /* sprom indirect access data byte 0 */
64 #define SBSDIO_SPROM_DATA_LOW 0x10002
65 /* sprom indirect access data byte 1 */
66 #define SBSDIO_SPROM_DATA_HIGH 0x10003
67 /* sprom indirect access addr byte 0 */
68 #define SBSDIO_SPROM_ADDR_LOW 0x10004
69 /* sprom indirect access addr byte 0 */
70 #define SBSDIO_SPROM_ADDR_HIGH 0x10005
71 /* xtal_pu (gpio) output */
72 #define SBSDIO_CHIP_CTRL_DATA 0x10006
73 /* xtal_pu (gpio) enable */
74 #define SBSDIO_CHIP_CTRL_EN 0x10007
75 /* rev < 7, watermark for sdio device */
76 #define SBSDIO_WATERMARK 0x10008
77 /* control busy signal generation */
78 #define SBSDIO_DEVICE_CTL 0x10009
80 /* SB Address Window Low (b15) */
81 #define SBSDIO_FUNC1_SBADDRLOW 0x1000A
82 /* SB Address Window Mid (b23:b16) */
83 #define SBSDIO_FUNC1_SBADDRMID 0x1000B
84 /* SB Address Window High (b31:b24) */
85 #define SBSDIO_FUNC1_SBADDRHIGH 0x1000C
86 /* Frame Control (frame term/abort) */
87 #define SBSDIO_FUNC1_FRAMECTRL 0x1000D
88 /* ChipClockCSR (ALP/HT ctl/status) */
89 #define SBSDIO_FUNC1_CHIPCLKCSR 0x1000E
90 /* SdioPullUp (on cmd, d0-d2) */
91 #define SBSDIO_FUNC1_SDIOPULLUP 0x1000F
92 /* Write Frame Byte Count Low */
93 #define SBSDIO_FUNC1_WFRAMEBCLO 0x10019
94 /* Write Frame Byte Count High */
95 #define SBSDIO_FUNC1_WFRAMEBCHI 0x1001A
96 /* Read Frame Byte Count Low */
97 #define SBSDIO_FUNC1_RFRAMEBCLO 0x1001B
98 /* Read Frame Byte Count High */
99 #define SBSDIO_FUNC1_RFRAMEBCHI 0x1001C
101 #define SBSDIO_FUNC1_MISC_REG_START 0x10000 /* f1 misc register start */
102 #define SBSDIO_FUNC1_MISC_REG_LIMIT 0x1001C /* f1 misc register end */
104 /* function 1 OCP space */
106 /* sb offset addr is <= 15 bits, 32k */
107 #define SBSDIO_SB_OFT_ADDR_MASK 0x07FFF
108 #define SBSDIO_SB_OFT_ADDR_LIMIT 0x08000
109 /* with b15, maps to 32-bit SB access */
110 #define SBSDIO_SB_ACCESS_2_4B_FLAG 0x08000
112 /* valid bits in SBSDIO_FUNC1_SBADDRxxx regs */
114 #define SBSDIO_SBADDRLOW_MASK 0x80 /* Valid bits in SBADDRLOW */
115 #define SBSDIO_SBADDRMID_MASK 0xff /* Valid bits in SBADDRMID */
116 #define SBSDIO_SBADDRHIGH_MASK 0xffU /* Valid bits in SBADDRHIGH */
117 /* Address bits from SBADDR regs */
118 #define SBSDIO_SBWINDOW_MASK 0xffff8000
120 #define SDIOH_READ 0 /* Read request */
121 #define SDIOH_WRITE 1 /* Write request */
123 #define SDIOH_DATA_FIX 0 /* Fixed addressing */
124 #define SDIOH_DATA_INC 1 /* Incremental addressing */
126 /* internal return code */
127 #define SUCCESS 0
128 #define ERROR 1
130 /* Packet alignment for most efficient SDIO (can change based on platform) */
131 #define BRCMF_SDALIGN (1 << 6)
133 /* watchdog polling interval in ms */
134 #define BRCMF_WD_POLL_MS 10
136 struct brcmf_sdreg {
137 int func;
138 int offset;
139 int value;
142 struct brcmf_sdio;
144 struct brcmf_sdio_dev {
145 struct sdio_func *func[SDIO_MAX_FUNCS];
146 u8 num_funcs; /* Supported funcs on client */
147 u32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
148 u32 sbwad; /* Save backplane window address */
149 void *bus;
150 atomic_t suspend; /* suspend flag */
151 wait_queue_head_t request_byte_wait;
152 wait_queue_head_t request_word_wait;
153 wait_queue_head_t request_chain_wait;
154 wait_queue_head_t request_buffer_wait;
155 struct device *dev;
156 struct brcmf_bus *bus_if;
157 #ifdef CONFIG_BRCMFMAC_SDIO_OOB
158 unsigned int irq; /* oob interrupt number */
159 unsigned long irq_flags; /* board specific oob flags */
160 bool irq_en; /* irq enable flags */
161 spinlock_t irq_en_lock;
162 bool irq_wake; /* irq wake enable flags */
163 #endif /* CONFIG_BRCMFMAC_SDIO_OOB */
166 /* Register/deregister interrupt handler. */
167 extern int brcmf_sdio_intr_register(struct brcmf_sdio_dev *sdiodev);
168 extern int brcmf_sdio_intr_unregister(struct brcmf_sdio_dev *sdiodev);
170 /* sdio device register access interface */
171 extern u8 brcmf_sdio_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
172 extern u32 brcmf_sdio_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret);
173 extern void brcmf_sdio_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr,
174 u8 data, int *ret);
175 extern void brcmf_sdio_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr,
176 u32 data, int *ret);
178 /* Buffer transfer to/from device (client) core via cmd53.
179 * fn: function number
180 * addr: backplane address (i.e. >= regsva from attach)
181 * flags: backplane width, address increment, sync/async
182 * buf: pointer to memory data buffer
183 * nbytes: number of bytes to transfer to/from buf
184 * pkt: pointer to packet associated with buf (if any)
185 * complete: callback function for command completion (async only)
186 * handle: handle for completion callback (first arg in callback)
187 * Returns 0 or error code.
188 * NOTE: Async operation is not currently supported.
190 extern int
191 brcmf_sdcard_send_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
192 uint flags, struct sk_buff *pkt);
193 extern int
194 brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
195 uint flags, u8 *buf, uint nbytes);
197 extern int
198 brcmf_sdcard_recv_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
199 uint flags, struct sk_buff *pkt);
200 extern int
201 brcmf_sdcard_recv_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
202 uint flags, u8 *buf, uint nbytes);
203 extern int
204 brcmf_sdcard_recv_chain(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn,
205 uint flags, struct sk_buff_head *pktq);
207 /* Flags bits */
209 /* Four-byte target (backplane) width (vs. two-byte) */
210 #define SDIO_REQ_4BYTE 0x1
211 /* Fixed address (FIFO) (vs. incrementing address) */
212 #define SDIO_REQ_FIXED 0x2
213 /* Async request (vs. sync request) */
214 #define SDIO_REQ_ASYNC 0x4
216 /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
217 * rw: read or write (0/1)
218 * addr: direct SDIO address
219 * buf: pointer to memory data buffer
220 * nbytes: number of bytes to transfer to/from buf
221 * Returns 0 or error code.
223 extern int brcmf_sdcard_rwdata(struct brcmf_sdio_dev *sdiodev, uint rw,
224 u32 addr, u8 *buf, uint nbytes);
226 /* Issue an abort to the specified function */
227 extern int brcmf_sdcard_abort(struct brcmf_sdio_dev *sdiodev, uint fn);
229 /* platform specific/high level functions */
230 extern int brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev);
231 extern int brcmf_sdio_remove(struct brcmf_sdio_dev *sdiodev);
233 extern int brcmf_sdcard_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev,
234 u32 address);
236 /* attach, return handler on success, NULL if failed.
237 * The handler shall be provided by all subsequent calls. No local cache
238 * cfghdl points to the starting address of pci device mapped memory
240 extern int brcmf_sdioh_attach(struct brcmf_sdio_dev *sdiodev);
241 extern void brcmf_sdioh_detach(struct brcmf_sdio_dev *sdiodev);
243 /* read or write one byte using cmd52 */
244 extern int brcmf_sdioh_request_byte(struct brcmf_sdio_dev *sdiodev, uint rw,
245 uint fnc, uint addr, u8 *byte);
247 /* read or write 2/4 bytes using cmd53 */
248 extern int
249 brcmf_sdioh_request_word(struct brcmf_sdio_dev *sdiodev,
250 uint rw, uint fnc, uint addr,
251 u32 *word, uint nbyte);
253 /* read or write any buffer using cmd53 */
254 extern int
255 brcmf_sdioh_request_buffer(struct brcmf_sdio_dev *sdiodev,
256 uint fix_inc, uint rw, uint fnc_num, u32 addr,
257 struct sk_buff *pkt);
258 extern int
259 brcmf_sdioh_request_chain(struct brcmf_sdio_dev *sdiodev, uint fix_inc,
260 uint write, uint func, uint addr,
261 struct sk_buff_head *pktq);
263 /* Watchdog timer interface for pm ops */
264 extern void brcmf_sdio_wdtmr_enable(struct brcmf_sdio_dev *sdiodev,
265 bool enable);
267 extern void *brcmf_sdbrcm_probe(u32 regsva, struct brcmf_sdio_dev *sdiodev);
268 extern void brcmf_sdbrcm_disconnect(void *ptr);
269 extern void brcmf_sdbrcm_isr(void *arg);
271 extern void brcmf_sdbrcm_wd_timer(struct brcmf_sdio *bus, uint wdtick);
272 #endif /* _BRCM_SDH_H_ */