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