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