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