1 /* 2 * SDIO host client driver interface of Broadcom HNBU 3 * export functions to client drivers 4 * abstract OS and BUS specific details of SDIO 5 * 6 * Copyright (C) 1999-2019, Broadcom. 7 * 8 * Unless you and Broadcom execute a separate written software license 9 * agreement governing use of this software, this software is licensed to you 10 * under the terms of the GNU General Public License version 2 (the "GPL"), 11 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 12 * following added to such license: 13 * 14 * As a special exception, the copyright holders of this software give you 15 * permission to link this software with independent modules, and to copy and 16 * distribute the resulting executable under terms of your choice, provided that 17 * you also meet, for each linked independent module, the terms and conditions 18 * of the license of that module. An independent module is a module which is 19 * not derived from this software. The special exception does not apply to any 20 * modifications of the software. 21 * 22 * Notwithstanding the above, under no circumstances may you combine this 23 * software in any way with any other Broadcom software provided under a license 24 * other than the GPL, without Broadcom's express prior written consent. 25 * 26 * 27 * <<Broadcom-WL-IPTag/Open:>> 28 * 29 * $Id: bcmsdh.h 727623 2017-10-21 01:00:32Z $ 30 */ 31 32 /** 33 * @file bcmsdh.h 34 */ 35 36 #ifndef _bcmsdh_h_ 37 #define _bcmsdh_h_ 38 39 #define BCMSDH_ERROR_VAL 0x0001 /* Error */ 40 #define BCMSDH_INFO_VAL 0x0002 /* Info */ 41 extern const uint bcmsdh_msglevel; 42 43 #define BCMSDH_ERROR(x) printf x 44 #define BCMSDH_INFO(x) 45 46 #if defined(BCMSDIO) && \ 47 (defined(BCMSDIOH_STD) || defined(BCMSDIOH_BCM) || defined(BCMSDIOH_SPI)) 48 #define BCMSDH_ADAPTER 49 #endif /* BCMSDIO && (BCMSDIOH_STD || BCMSDIOH_BCM || BCMSDIOH_SPI) */ 50 51 /* forward declarations */ 52 typedef struct bcmsdh_info bcmsdh_info_t; 53 typedef void (*bcmsdh_cb_fn_t)(void *); 54 55 #if defined(BT_OVER_SDIO) 56 typedef enum { 57 NO_HANG_STATE = 0, 58 HANG_START_STATE = 1, 59 HANG_RECOVERY_STATE = 2 60 } dhd_hang_state_t; 61 #endif // endif 62 63 extern bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *sdioh, ulong *regsva); 64 /** 65 * BCMSDH API context 66 */ 67 struct bcmsdh_info { 68 bool init_success; /* underlying driver successfully attached */ 69 void *sdioh; /* handler for sdioh */ 70 uint32 vendevid; /* Target Vendor and Device ID on SD bus */ 71 osl_t *osh; 72 bool regfail; /* Save status of last reg_read/reg_write call */ 73 uint32 sbwad; /* Save backplane window address */ 74 void *os_cxt; /* Pointer to per-OS private data */ 75 bool force_sbwad_calc; /* forces calculation of sbwad instead of using 76 cached value */ 77 #ifdef DHD_WAKE_STATUS 78 unsigned int total_wake_count; 79 int pkt_wake; 80 #endif /* DHD_WAKE_STATUS */ 81 }; 82 83 /* Detach - freeup resources allocated in attach */ 84 extern int bcmsdh_detach(osl_t *osh, void *sdh); 85 86 /* Query if SD device interrupts are enabled */ 87 extern bool bcmsdh_intr_query(void *sdh); 88 89 /* Enable/disable SD interrupt */ 90 extern int bcmsdh_intr_enable(void *sdh); 91 extern int bcmsdh_intr_disable(void *sdh); 92 93 /* Register/deregister device interrupt handler. */ 94 extern int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh); 95 extern int bcmsdh_intr_dereg(void *sdh); 96 /* Enable/disable SD card interrupt forward */ 97 extern void bcmsdh_intr_forward(void *sdh, bool pass); 98 99 #if defined(DHD_DEBUG) 100 /* Query pending interrupt status from the host controller */ 101 extern bool bcmsdh_intr_pending(void *sdh); 102 #endif // endif 103 104 /* Register a callback to be called if and when bcmsdh detects 105 * device removal. No-op in the case of non-removable/hardwired devices. 106 */ 107 extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh); 108 109 /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface). 110 * fn: function number 111 * addr: unmodified SDIO-space address 112 * data: data byte to write 113 * err: pointer to error code (or NULL) 114 */ 115 extern uint8 bcmsdh_cfg_read(void *sdh, uint func, uint32 addr, int *err); 116 extern void bcmsdh_cfg_write(void *sdh, uint func, uint32 addr, uint8 data, 117 int *err); 118 119 /* Read/Write 4bytes from/to cfg space */ 120 extern uint32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, 121 int *err); 122 extern void bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, 123 uint32 data, int *err); 124 125 /* Read CIS content for specified function. 126 * fn: function whose CIS is being requested (0 is common CIS) 127 * cis: pointer to memory location to place results 128 * length: number of bytes to read 129 * Internally, this routine uses the values from the cis base regs (0x9-0xB) 130 * to form an SDIO-space address to read the data from. 131 */ 132 extern int bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length); 133 extern int bcmsdh_cisaddr_read(void *sdh, uint func, uint8 *cisd, uint offset); 134 135 /* Synchronous access to device (client) core registers via CMD53 to F1. 136 * addr: backplane address (i.e. >= regsva from attach) 137 * size: register width in bytes (2 or 4) 138 * data: data for register write 139 */ 140 extern uint32 bcmsdh_reg_read(void *sdh, uintptr addr, uint size); 141 extern uint32 bcmsdh_reg_write(void *sdh, uintptr addr, uint size, uint32 data); 142 143 /* set sb address window */ 144 extern int bcmsdhsdio_set_sbaddr_window(void *sdh, uint32 address, 145 bool force_set); 146 147 /* Indicate if last reg read/write failed */ 148 extern bool bcmsdh_regfail(void *sdh); 149 150 /* Buffer transfer to/from device (client) core via cmd53. 151 * fn: function number 152 * addr: backplane address (i.e. >= regsva from attach) 153 * flags: backplane width, address increment, sync/async 154 * buf: pointer to memory data buffer 155 * nbytes: number of bytes to transfer to/from buf 156 * pkt: pointer to packet associated with buf (if any) 157 * complete: callback function for command completion (async only) 158 * handle: handle for completion callback (first arg in callback) 159 * Returns 0 or error code. 160 * NOTE: Async operation is not currently supported. 161 */ 162 typedef void (*bcmsdh_cmplt_fn_t)(void *handle, int status, bool sync_waiting); 163 extern int bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags, 164 uint8 *buf, uint nbytes, void *pkt, 165 bcmsdh_cmplt_fn_t complete_fn, void *handle); 166 extern int bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags, 167 uint8 *buf, uint nbytes, void *pkt, 168 bcmsdh_cmplt_fn_t complete_fn, void *handle); 169 170 extern void bcmsdh_glom_post(void *sdh, uint8 *frame, void *pkt, uint len); 171 extern void bcmsdh_glom_clear(void *sdh); 172 extern uint bcmsdh_set_mode(void *sdh, uint mode); 173 extern bool bcmsdh_glom_enabled(void); 174 #ifdef PKT_STATICS 175 extern uint32 bcmsdh_get_spend_time(void *sdh); 176 #endif 177 /* Flags bits */ 178 #define SDIO_REQ_4BYTE \ 179 0x1 /* Four-byte target (backplane) width (vs. two-byte) */ 180 #define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) \ 181 */ 182 #define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */ 183 #define SDIO_BYTE_MODE 0x8 /* Byte mode request(non-block mode) */ 184 185 /* Pending (non-error) return code */ 186 #define BCME_PENDING 1 187 188 /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only). 189 * rw: read or write (0/1) 190 * addr: direct SDIO address 191 * buf: pointer to memory data buffer 192 * nbytes: number of bytes to transfer to/from buf 193 * Returns 0 or error code. 194 */ 195 extern int bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, 196 uint nbytes); 197 198 /* Issue an abort to the specified function */ 199 extern int bcmsdh_abort(void *sdh, uint fn); 200 201 /* Start SDIO Host Controller communication */ 202 extern int bcmsdh_start(void *sdh, int stage); 203 204 /* Stop SDIO Host Controller communication */ 205 extern int bcmsdh_stop(void *sdh); 206 207 /* Wait system lock free */ 208 extern int bcmsdh_waitlockfree(void *sdh); 209 210 /* Returns the "Device ID" of target device on the SDIO bus. */ 211 extern int bcmsdh_query_device(void *sdh); 212 213 /* Returns the number of IO functions reported by the device */ 214 extern uint bcmsdh_query_iofnum(void *sdh); 215 216 /* Miscellaneous knob tweaker. */ 217 extern int bcmsdh_iovar_op(void *sdh, const char *name, void *params, uint plen, 218 void *arg, uint len, bool set); 219 220 /* Reset and reinitialize the device */ 221 extern int bcmsdh_reset(bcmsdh_info_t *sdh); 222 223 /* helper functions */ 224 225 /* callback functions */ 226 typedef struct { 227 /* probe the device */ 228 void *(*probe)(uint16 vend_id, uint16 dev_id, uint16 bus, uint16 slot, 229 uint16 func, uint bustype, void *regsva, osl_t *osh, 230 void *param); 231 /* remove the device */ 232 void (*remove)(void *context); 233 /* can we suspend now */ 234 int (*suspend)(void *context); 235 /* resume from suspend */ 236 int (*resume)(void *context); 237 } bcmsdh_driver_t; 238 239 /* platform specific/high level functions */ 240 extern int bcmsdh_register(bcmsdh_driver_t *driver); 241 extern void bcmsdh_unregister(void); 242 extern bool bcmsdh_chipmatch(uint16 vendor, uint16 device); 243 extern void bcmsdh_device_remove(void *sdh); 244 245 extern int bcmsdh_reg_sdio_notify(void *semaphore); 246 extern void bcmsdh_unreg_sdio_notify(void); 247 248 #if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) 249 extern int bcmsdh_oob_intr_register(bcmsdh_info_t *bcmsdh, 250 bcmsdh_cb_fn_t oob_irq_handler, 251 void *oob_irq_handler_context); 252 extern void bcmsdh_oob_intr_unregister(bcmsdh_info_t *sdh); 253 extern void bcmsdh_oob_intr_set(bcmsdh_info_t *sdh, bool enable); 254 #endif /* defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) */ 255 extern void bcmsdh_dev_pm_stay_awake(bcmsdh_info_t *sdh); 256 extern void bcmsdh_dev_relax(bcmsdh_info_t *sdh); 257 extern bool bcmsdh_dev_pm_enabled(bcmsdh_info_t *sdh); 258 259 int bcmsdh_suspend(bcmsdh_info_t *bcmsdh); 260 int bcmsdh_resume(bcmsdh_info_t *bcmsdh); 261 262 /* Function to pass device-status bits to DHD. */ 263 extern uint32 bcmsdh_get_dstatus(void *sdh); 264 265 /* Function to return current window addr */ 266 extern uint32 bcmsdh_cur_sbwad(void *sdh); 267 268 /* function to force sbwad calculation instead of using cached value */ 269 extern void bcmsdh_force_sbwad_calc(void *sdh, bool force); 270 271 /* Function to pass chipid and rev to lower layers for controlling pr's */ 272 extern void bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev); 273 274 #ifdef BCMSPI 275 extern void bcmsdh_dwordmode(void *sdh, bool set); 276 #endif /* BCMSPI */ 277 278 extern int bcmsdh_sleep(void *sdh, bool enab); 279 280 /* GPIO support */ 281 extern int bcmsdh_gpio_init(void *sd); 282 extern bool bcmsdh_gpioin(void *sd, uint32 gpio); 283 extern int bcmsdh_gpioouten(void *sd, uint32 gpio); 284 extern int bcmsdh_gpioout(void *sd, uint32 gpio, bool enab); 285 286 #endif /* _bcmsdh_h_ */ 287