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