Merge branch 'for-linus' of git://git.kernel.dk/linux-block
[pandora-kernel.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 #define SBSDIO_NUM_FUNCTION             3       /* as of sdiod rev 0, supports 3 functions */
45
46 /* function 1 miscellaneous registers */
47 #define SBSDIO_SPROM_CS                 0x10000 /* sprom command and status */
48 #define SBSDIO_SPROM_INFO               0x10001 /* sprom info register */
49 #define SBSDIO_SPROM_DATA_LOW           0x10002 /* sprom indirect access data byte 0 */
50 #define SBSDIO_SPROM_DATA_HIGH          0x10003 /* sprom indirect access data byte 1 */
51 #define SBSDIO_SPROM_ADDR_LOW           0x10004 /* sprom indirect access addr byte 0 */
52 #define SBSDIO_SPROM_ADDR_HIGH          0x10005 /* sprom indirect access addr byte 0 */
53 #define SBSDIO_CHIP_CTRL_DATA           0x10006 /* xtal_pu (gpio) output */
54 #define SBSDIO_CHIP_CTRL_EN             0x10007 /* xtal_pu (gpio) enable */
55 #define SBSDIO_WATERMARK                0x10008 /* rev < 7, watermark for sdio device */
56 #define SBSDIO_DEVICE_CTL               0x10009 /* control busy signal generation */
57
58 /* registers introduced in rev 8, some content (mask/bits) defs in sbsdpcmdev.h */
59 #define SBSDIO_FUNC1_SBADDRLOW          0x1000A /* SB Address Window Low (b15) */
60 #define SBSDIO_FUNC1_SBADDRMID          0x1000B /* SB Address Window Mid (b23:b16) */
61 #define SBSDIO_FUNC1_SBADDRHIGH         0x1000C /* SB Address Window High (b31:b24)    */
62 #define SBSDIO_FUNC1_FRAMECTRL          0x1000D /* Frame Control (frame term/abort) */
63 #define SBSDIO_FUNC1_CHIPCLKCSR         0x1000E /* ChipClockCSR (ALP/HT ctl/status) */
64 #define SBSDIO_FUNC1_SDIOPULLUP         0x1000F /* SdioPullUp (on cmd, d0-d2) */
65 #define SBSDIO_FUNC1_WFRAMEBCLO         0x10019 /* Write Frame Byte Count Low */
66 #define SBSDIO_FUNC1_WFRAMEBCHI         0x1001A /* Write Frame Byte Count High */
67 #define SBSDIO_FUNC1_RFRAMEBCLO         0x1001B /* Read Frame Byte Count Low */
68 #define SBSDIO_FUNC1_RFRAMEBCHI         0x1001C /* Read Frame Byte Count High */
69
70 #define SBSDIO_FUNC1_MISC_REG_START     0x10000 /* f1 misc register start */
71 #define SBSDIO_FUNC1_MISC_REG_LIMIT     0x1001C /* f1 misc register end */
72
73 /* function 1 OCP space */
74 #define SBSDIO_SB_OFT_ADDR_MASK         0x07FFF /* sb offset addr is <= 15 bits, 32k */
75 #define SBSDIO_SB_OFT_ADDR_LIMIT        0x08000
76 #define SBSDIO_SB_ACCESS_2_4B_FLAG      0x08000 /* with b15, maps to 32-bit SB access */
77
78 /* some duplication with sbsdpcmdev.h here */
79 /* valid bits in SBSDIO_FUNC1_SBADDRxxx regs */
80 #define SBSDIO_SBADDRLOW_MASK           0x80    /* Valid bits in SBADDRLOW */
81 #define SBSDIO_SBADDRMID_MASK           0xff    /* Valid bits in SBADDRMID */
82 #define SBSDIO_SBADDRHIGH_MASK          0xffU   /* Valid bits in SBADDRHIGH */
83 #define SBSDIO_SBWINDOW_MASK            0xffff8000      /* Address bits from SBADDR regs */
84
85 #define SDIOH_READ              0       /* Read request */
86 #define SDIOH_WRITE             1       /* Write request */
87
88 #define SDIOH_DATA_FIX          0       /* Fixed addressing */
89 #define SDIOH_DATA_INC          1       /* Incremental addressing */
90
91 /* internal return code */
92 #define SUCCESS 0
93 #define ERROR   1
94
95 /* forward declarations */
96 struct brcmf_sdio_card;
97
98 struct brcmf_sdreg {
99         int func;
100         int offset;
101         int value;
102 };
103
104 struct sdioh_info {
105         struct osl_info *osh;           /* osh handler */
106         bool client_intr_enabled;       /* interrupt connnected flag */
107         bool intr_handler_valid;        /* client driver interrupt handler valid */
108         void (*intr_handler)(void *);   /* registered interrupt handler */
109         void *intr_handler_arg; /* argument to call interrupt handler */
110         u16 intmask;            /* Current active interrupts */
111         void *sdos_info;        /* Pointer to per-OS private data */
112
113         uint irq;               /* Client irq */
114         int intrcount;          /* Client interrupts */
115         bool sd_blockmode;      /* sd_blockmode == false => 64 Byte Cmd 53s. */
116         /*  Must be on for sd_multiblock to be effective */
117         bool use_client_ints;   /* If this is false, make sure to restore */
118         int client_block_size[SDIOD_MAX_IOFUNCS];       /* Blocksize */
119         u8 num_funcs;   /* Supported funcs on client */
120         u32 com_cis_ptr;
121         u32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
122         uint max_dma_len;
123         uint max_dma_descriptors;       /* DMA Descriptors supported by this controller. */
124         /*      SDDMA_DESCRIPTOR        SGList[32]; *//* Scatter/Gather DMA List */
125 };
126
127 struct brcmf_sdmmc_instance {
128         struct sdioh_info *sd;
129         struct sdio_func *func[SDIOD_MAX_IOFUNCS];
130         u32 host_claimed;
131 };
132
133 /* Attach and build an interface to the underlying SD host driver.
134  *  - Allocates resources (structs, arrays, mem, OS handles, etc) needed by
135  *    brcmf_sdcard.
136  *  - Returns the sdio card handle and virtual address base for register access.
137  *    The returned handle should be used in all subsequent calls, but the bcmsh
138  *    implementation may maintain a single "default" handle (e.g. the first or
139  *    most recent one) to enable single-instance implementations to pass NULL.
140  */
141 extern struct brcmf_sdio_card*
142 brcmf_sdcard_attach(void *cfghdl, u32 *regsva, uint irq);
143
144 /* Detach - freeup resources allocated in attach */
145 extern int brcmf_sdcard_detach(struct brcmf_sdio_card *card);
146
147 /* Enable/disable SD interrupt */
148 extern int brcmf_sdcard_intr_enable(struct brcmf_sdio_card *card);
149 extern int brcmf_sdcard_intr_disable(struct brcmf_sdio_card *card);
150
151 /* Register/deregister device interrupt handler. */
152 extern int
153 brcmf_sdcard_intr_reg(struct brcmf_sdio_card *card,
154                       void (*fn)(void *), void *argh);
155
156 extern int brcmf_sdcard_intr_dereg(struct brcmf_sdio_card *card);
157
158 /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
159  *   fn:   function number
160  *   addr: unmodified SDIO-space address
161  *   data: data byte to write
162  *   err:  pointer to error code (or NULL)
163  */
164 extern u8 brcmf_sdcard_cfg_read(struct brcmf_sdio_card *card, uint func,
165                                 u32 addr, int *err);
166 extern void brcmf_sdcard_cfg_write(struct brcmf_sdio_card *card, uint func,
167                                    u32 addr, u8 data, int *err);
168
169 /* Read/Write 4bytes from/to cfg space */
170 extern u32
171 brcmf_sdcard_cfg_read_word(struct brcmf_sdio_card *card, uint fnc_num,
172                            u32 addr, int *err);
173
174 extern void brcmf_sdcard_cfg_write_word(struct brcmf_sdio_card *card,
175                                         uint fnc_num, u32 addr,
176                                         u32 data, int *err);
177
178 /* Read CIS content for specified function.
179  *   fn:     function whose CIS is being requested (0 is common CIS)
180  *   cis:    pointer to memory location to place results
181  *   length: number of bytes to read
182  * Internally, this routine uses the values from the cis base regs (0x9-0xB)
183  * to form an SDIO-space address to read the data from.
184  */
185 extern int brcmf_sdcard_cis_read(struct brcmf_sdio_card *card, uint func,
186                                  u8 *cis, uint length);
187
188 /* Synchronous access to device (client) core registers via CMD53 to F1.
189  *   addr: backplane address (i.e. >= regsva from attach)
190  *   size: register width in bytes (2 or 4)
191  *   data: data for register write
192  */
193 extern u32
194 brcmf_sdcard_reg_read(struct brcmf_sdio_card *card, u32 addr, uint size);
195
196 extern u32
197 brcmf_sdcard_reg_write(struct brcmf_sdio_card *card, u32 addr, uint size,
198                        u32 data);
199
200 /* Indicate if last reg read/write failed */
201 extern bool brcmf_sdcard_regfail(struct brcmf_sdio_card *card);
202
203 /* Buffer transfer to/from device (client) core via cmd53.
204  *   fn:       function number
205  *   addr:     backplane address (i.e. >= regsva from attach)
206  *   flags:    backplane width, address increment, sync/async
207  *   buf:      pointer to memory data buffer
208  *   nbytes:   number of bytes to transfer to/from buf
209  *   pkt:      pointer to packet associated with buf (if any)
210  *   complete: callback function for command completion (async only)
211  *   handle:   handle for completion callback (first arg in callback)
212  * Returns 0 or error code.
213  * NOTE: Async operation is not currently supported.
214  */
215 extern int
216 brcmf_sdcard_send_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
217                       uint flags, u8 *buf, uint nbytes, void *pkt,
218                       void (*complete)(void *handle, int status,
219                                        bool sync_waiting),
220                       void *handle);
221 extern int
222 brcmf_sdcard_recv_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
223                       uint flags, u8 *buf, uint nbytes, struct sk_buff *pkt,
224                       void (*complete)(void *handle, int status,
225                                        bool sync_waiting),
226                       void *handle);
227
228 /* Flags bits */
229 #define SDIO_REQ_4BYTE  0x1     /* Four-byte target (backplane) width (vs. two-byte) */
230 #define SDIO_REQ_FIXED  0x2     /* Fixed address (FIFO) (vs. incrementing address) */
231 #define SDIO_REQ_ASYNC  0x4     /* Async request (vs. sync request) */
232
233 /* Pending (non-error) return code */
234 #define BCME_PENDING    1
235
236 /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
237  *   rw:       read or write (0/1)
238  *   addr:     direct SDIO address
239  *   buf:      pointer to memory data buffer
240  *   nbytes:   number of bytes to transfer to/from buf
241  * Returns 0 or error code.
242  */
243 extern int brcmf_sdcard_rwdata(struct brcmf_sdio_card *card, uint rw, u32 addr,
244                                u8 *buf, uint nbytes);
245
246 /* Issue an abort to the specified function */
247 extern int brcmf_sdcard_abort(struct brcmf_sdio_card *card, uint fn);
248
249 /* Returns the "Device ID" of target device on the SDIO bus. */
250 extern int brcmf_sdcard_query_device(struct brcmf_sdio_card *card);
251
252 /* Miscellaneous knob tweaker. */
253 extern int brcmf_sdcard_iovar_op(struct brcmf_sdio_card *card, const char *name,
254                                  void *params, int plen, void *arg, int len,
255                                  bool set);
256
257 /* helper functions */
258
259 /* callback functions */
260 struct brcmf_sdioh_driver {
261         /* attach to device */
262         void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot,
263                          u16 func, uint bustype, u32 regsva, void *param);
264         /* detach from device */
265         void (*detach) (void *ch);
266 };
267
268 struct sdioh_info;
269
270 /* platform specific/high level functions */
271 extern int brcmf_sdio_function_init(void);
272 extern int brcmf_sdio_register(struct brcmf_sdioh_driver *driver);
273 extern void brcmf_sdio_unregister(void);
274 extern void brcmf_sdio_function_cleanup(void);
275 extern int brcmf_sdio_probe(struct device *dev);
276 extern int brcmf_sdio_remove(struct device *dev);
277
278 /* Function to return current window addr */
279 extern u32 brcmf_sdcard_cur_sbwad(struct brcmf_sdio_card *card);
280
281 /* Allocate/init/free per-OS private data */
282 extern int  brcmf_sdioh_osinit(struct sdioh_info *sd);
283 extern void brcmf_sdioh_osfree(struct sdioh_info *sd);
284
285 /* Core interrupt enable/disable of device interrupts */
286 extern void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd);
287 extern void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd);
288
289 /* attach, return handler on success, NULL if failed.
290  *  The handler shall be provided by all subsequent calls. No local cache
291  *  cfghdl points to the starting address of pci device mapped memory
292  */
293 extern struct sdioh_info *brcmf_sdioh_attach(void *cfghdl, uint irq);
294 extern int brcmf_sdioh_detach(struct sdioh_info *si);
295
296 extern int
297 brcmf_sdioh_interrupt_register(struct sdioh_info *si,
298                                void (*sdioh_cb_fn)(void *), void *argh);
299
300 extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *si);
301
302 /* enable or disable SD interrupt */
303 extern int
304 brcmf_sdioh_interrupt_set(struct sdioh_info *si, bool enable_disable);
305
306 /* read or write one byte using cmd52 */
307 extern int
308 brcmf_sdioh_request_byte(struct sdioh_info *si, uint rw, uint fnc, uint addr,
309                          u8 *byte);
310
311 /* read or write 2/4 bytes using cmd53 */
312 extern int
313 brcmf_sdioh_request_word(struct sdioh_info *si, uint cmd_type,
314                          uint rw, uint fnc, uint addr,
315                          u32 *word, uint nbyte);
316
317 /* read or write any buffer using cmd53 */
318 extern int
319 brcmf_sdioh_request_buffer(struct sdioh_info *si, uint pio_dma,
320                            uint fix_inc, uint rw, uint fnc_num,
321                            u32 addr, uint regwidth,
322                            u32 buflen, u8 *buffer, struct sk_buff *pkt);
323
324 /* get cis data */
325 extern int
326 brcmf_sdioh_cis_read(struct sdioh_info *si, uint fuc, u8 *cis, u32 length);
327
328 extern int
329 brcmf_sdioh_cfg_read(struct sdioh_info *si, uint fuc, u32 addr, u8 *data);
330 extern int
331 brcmf_sdioh_cfg_write(struct sdioh_info *si, uint fuc, u32 addr, u8 *data);
332
333 /* handle iovars */
334 extern int brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name,
335                           void *params, int plen, void *arg, int len, bool set);
336
337 /* Issue abort to the specified function and clear controller as needed */
338 extern int brcmf_sdioh_abort(struct sdioh_info *si, uint fnc);
339
340 /* Watchdog timer interface for pm ops */
341 extern void brcmf_sdio_wdtmr_enable(bool enable);
342
343 extern uint sd_msglevel;        /* Debug message level */
344
345 extern struct brcmf_sdmmc_instance *gInstance;
346
347 #endif                          /* _BRCM_SDH_H_ */