5d2178db0144358ab36100f7ee46371200a00d8d
[deliverable/linux.git] / drivers / staging / brcm80211 / brcmfmac / sdio_host.h
1 /*
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
17 #ifndef _BRCM_SDH_H_
18 #define _BRCM_SDH_H_
19
20 #include <linux/skbuff.h>
21 extern const uint brcmf_sdio_msglevel;
22
23 #define SDIO_FUNC_0 0
24 #define SDIO_FUNC_1 1
25 #define SDIO_FUNC_2 2
26
27 #define SDIOD_FBR_SIZE 0x100
28
29 /* io_en */
30 #define SDIO_FUNC_ENABLE_1 0x02
31 #define SDIO_FUNC_ENABLE_2 0x04
32
33 /* io_rdys */
34 #define SDIO_FUNC_READY_1 0x02
35 #define SDIO_FUNC_READY_2 0x04
36
37 /* intr_status */
38 #define INTR_STATUS_FUNC1 0x2
39 #define INTR_STATUS_FUNC2 0x4
40
41 /* Maximum number of I/O funcs */
42 #define SDIOD_MAX_IOFUNCS 7
43
44 /* forward declarations */
45 struct brcmf_sdio_card;
46
47 /* Attach and build an interface to the underlying SD host driver.
48 * - Allocates resources (structs, arrays, mem, OS handles, etc) needed by
49 * brcmf_sdcard.
50 * - Returns the sdio card handle and virtual address base for register access.
51 * The returned handle should be used in all subsequent calls, but the bcmsh
52 * implementation may maintain a single "default" handle (e.g. the first or
53 * most recent one) to enable single-instance implementations to pass NULL.
54 */
55 extern struct brcmf_sdio_card *brcmf_sdcard_attach(void *cfghdl, void **regsva,
56 uint irq);
57
58 /* Detach - freeup resources allocated in attach */
59 extern int brcmf_sdcard_detach(struct brcmf_sdio_card *card);
60
61 /* Query if SD device interrupts are enabled */
62 extern bool brcmf_sdcard_intr_query(struct brcmf_sdio_card *card);
63
64 /* Enable/disable SD interrupt */
65 extern int brcmf_sdcard_intr_enable(struct brcmf_sdio_card *card);
66 extern int brcmf_sdcard_intr_disable(struct brcmf_sdio_card *card);
67
68 /* Register/deregister device interrupt handler. */
69 extern int
70 brcmf_sdcard_intr_reg(struct brcmf_sdio_card *card,
71 void (*fn)(void *), void *argh);
72
73 extern int brcmf_sdcard_intr_dereg(struct brcmf_sdio_card *card);
74
75 /* Register a callback to be called on device removal.
76 * No-op in the case of non-removable/hardwired devices.
77 */
78 extern int
79 brcmf_sdcard_devremove_reg(struct brcmf_sdio_card *card,
80 void (*fn)(void *), void *argh);
81
82 /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
83 * fn: function number
84 * addr: unmodified SDIO-space address
85 * data: data byte to write
86 * err: pointer to error code (or NULL)
87 */
88 extern u8 brcmf_sdcard_cfg_read(struct brcmf_sdio_card *card, uint func,
89 u32 addr, int *err);
90 extern void brcmf_sdcard_cfg_write(struct brcmf_sdio_card *card, uint func,
91 u32 addr, u8 data, int *err);
92
93 /* Read/Write 4bytes from/to cfg space */
94 extern u32
95 brcmf_sdcard_cfg_read_word(struct brcmf_sdio_card *card, uint fnc_num,
96 u32 addr, int *err);
97
98 extern void brcmf_sdcard_cfg_write_word(struct brcmf_sdio_card *card,
99 uint fnc_num, u32 addr,
100 u32 data, int *err);
101
102 /* Read CIS content for specified function.
103 * fn: function whose CIS is being requested (0 is common CIS)
104 * cis: pointer to memory location to place results
105 * length: number of bytes to read
106 * Internally, this routine uses the values from the cis base regs (0x9-0xB)
107 * to form an SDIO-space address to read the data from.
108 */
109 extern int brcmf_sdcard_cis_read(struct brcmf_sdio_card *card, uint func,
110 u8 *cis, uint length);
111
112 /* Synchronous access to device (client) core registers via CMD53 to F1.
113 * addr: backplane address (i.e. >= regsva from attach)
114 * size: register width in bytes (2 or 4)
115 * data: data for register write
116 */
117 extern u32
118 brcmf_sdcard_reg_read(struct brcmf_sdio_card *card, u32 addr, uint size);
119
120 extern u32
121 brcmf_sdcard_reg_write(struct brcmf_sdio_card *card, u32 addr, uint size,
122 u32 data);
123
124 /* Indicate if last reg read/write failed */
125 extern bool brcmf_sdcard_regfail(struct brcmf_sdio_card *card);
126
127 /* Buffer transfer to/from device (client) core via cmd53.
128 * fn: function number
129 * addr: backplane address (i.e. >= regsva from attach)
130 * flags: backplane width, address increment, sync/async
131 * buf: pointer to memory data buffer
132 * nbytes: number of bytes to transfer to/from buf
133 * pkt: pointer to packet associated with buf (if any)
134 * complete: callback function for command completion (async only)
135 * handle: handle for completion callback (first arg in callback)
136 * Returns 0 or error code.
137 * NOTE: Async operation is not currently supported.
138 */
139 extern int
140 brcmf_sdcard_send_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
141 uint flags, u8 *buf, uint nbytes, void *pkt,
142 void (*complete)(void *handle, int status,
143 bool sync_waiting),
144 void *handle);
145 extern int
146 brcmf_sdcard_recv_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
147 uint flags, u8 *buf, uint nbytes, struct sk_buff *pkt,
148 void (*complete)(void *handle, int status,
149 bool sync_waiting),
150 void *handle);
151
152 /* Flags bits */
153 #define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */
154 #define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */
155 #define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */
156
157 /* Pending (non-error) return code */
158 #define BCME_PENDING 1
159
160 /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
161 * rw: read or write (0/1)
162 * addr: direct SDIO address
163 * buf: pointer to memory data buffer
164 * nbytes: number of bytes to transfer to/from buf
165 * Returns 0 or error code.
166 */
167 extern int brcmf_sdcard_rwdata(struct brcmf_sdio_card *card, uint rw, u32 addr,
168 u8 *buf, uint nbytes);
169
170 /* Issue an abort to the specified function */
171 extern int brcmf_sdcard_abort(struct brcmf_sdio_card *card, uint fn);
172
173 /* Returns the "Device ID" of target device on the SDIO bus. */
174 extern int brcmf_sdcard_query_device(struct brcmf_sdio_card *card);
175
176 /* Returns the number of IO functions reported by the device */
177 extern uint brcmf_sdcard_query_iofnum(struct brcmf_sdio_card *card);
178
179 /* Miscellaneous knob tweaker. */
180 extern int brcmf_sdcard_iovar_op(struct brcmf_sdio_card *card, const char *name,
181 void *params, int plen, void *arg, int len,
182 bool set);
183
184 /* helper functions */
185
186 extern void *brcmf_sdcard_get_sdioh(struct brcmf_sdio_card *card);
187
188 /* callback functions */
189 struct brcmf_sdioh_driver {
190 /* attach to device */
191 void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot,
192 u16 func, uint bustype, void *regsva, void *param);
193 /* detach from device */
194 void (*detach) (void *ch);
195 };
196
197 struct sdioh_info;
198
199 /* platform specific/high level functions */
200 extern int brcmf_sdio_function_init(void);
201 extern int brcmf_sdio_register(struct brcmf_sdioh_driver *driver);
202 extern void brcmf_sdio_unregister(void);
203 extern bool brcmf_sdio_chipmatch(u16 vendor, u16 device);
204 extern void brcmf_sdio_function_cleanup(void);
205 extern int brcmf_sdio_probe(struct device *dev);
206 extern int brcmf_sdio_remove(struct device *dev);
207
208 /* Function to pass device-status bits to DHD. */
209 extern u32 brcmf_sdcard_get_dstatus(struct brcmf_sdio_card *card);
210
211 /* Function to return current window addr */
212 extern u32 brcmf_sdcard_cur_sbwad(struct brcmf_sdio_card *card);
213
214 /* Function to pass chipid and rev to lower layers for controlling pr's */
215 extern void brcmf_sdcard_chipinfo(struct brcmf_sdio_card *card, u32 chip,
216 u32 chiprev);
217
218 #endif /* _BRCM_SDH_H_ */
This page took 0.040837 seconds and 4 git commands to generate.