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-2013, Broadcom Corporation 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 * 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 * $Id: bcmsdh.h 414953 2013-07-26 17:36:27Z $ 27 */ 28 29 /** 30 * @file bcmsdh.h 31 */ 32 33 #ifndef _bcmsdh_h_ 34 #define _bcmsdh_h_ 35 36 #define BCMSDH_ERROR_VAL 0x0001 /* Error */ 37 #define BCMSDH_INFO_VAL 0x0002 /* Info */ 38 extern const uint bcmsdh_msglevel; 39 40 #define BCMSDH_ERROR(x) 41 #define BCMSDH_INFO(x) 42 43 #if (defined(BCMSDIOH_STD) || defined(BCMSDIOH_BCM) || defined(BCMSDIOH_SPI)) 44 #define BCMSDH_ADAPTER 45 #endif /* BCMSDIO && (BCMSDIOH_STD || BCMSDIOH_BCM || BCMSDIOH_SPI) */ 46 47 /* forward declarations */ 48 typedef struct bcmsdh_info bcmsdh_info_t; 49 typedef void (*bcmsdh_cb_fn_t)(void *); 50 51 extern struct device *pm_dev; 52 53 /* Attach and build an interface to the underlying SD host driver. 54 * - Allocates resources (structs, arrays, mem, OS handles, etc) needed by bcmsdh. 55 * - Returns the bcmsdh handle and virtual address base for register access. 56 * The returned handle should be used in all subsequent calls, but the bcmsh 57 * implementation may maintain a single "default" handle (e.g. the first or 58 * most recent one) to enable single-instance implementations to pass NULL. 59 */ 60 extern bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, uint irq); 61 62 /* Detach - freeup resources allocated in attach */ 63 extern int bcmsdh_detach(osl_t *osh, void *sdh); 64 65 /* Query if SD device interrupts are enabled */ 66 extern bool bcmsdh_intr_query(void *sdh); 67 68 /* Enable/disable SD interrupt */ 69 extern int bcmsdh_intr_enable(void *sdh); 70 extern int bcmsdh_intr_disable(void *sdh); 71 72 /* Register/deregister device interrupt handler. */ 73 extern int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh); 74 extern int bcmsdh_intr_dereg(void *sdh); 75 /* Enable/disable SD card interrupt forward */ 76 extern void bcmsdh_intr_forward(void *sdh, bool pass); 77 78 #if defined(DHD_DEBUG) 79 /* Query pending interrupt status from the host controller */ 80 extern bool bcmsdh_intr_pending(void *sdh); 81 #endif 82 83 /* Register a callback to be called if and when bcmsdh detects 84 * device removal. No-op in the case of non-removable/hardwired devices. 85 */ 86 extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh); 87 88 /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface). 89 * fn: function number 90 * addr: unmodified SDIO-space address 91 * data: data byte to write 92 * err: pointer to error code (or NULL) 93 */ 94 extern uint8 bcmsdh_cfg_read(void *sdh, uint func, uint32 addr, int *err); 95 extern void bcmsdh_cfg_write(void *sdh, uint func, uint32 addr, uint8 data, int *err); 96 97 /* Read/Write 4bytes from/to cfg space */ 98 extern uint32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, int *err); 99 extern void bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, uint32 data, int *err); 100 101 /* Read CIS content for specified function. 102 * fn: function whose CIS is being requested (0 is common CIS) 103 * cis: pointer to memory location to place results 104 * length: number of bytes to read 105 * Internally, this routine uses the values from the cis base regs (0x9-0xB) 106 * to form an SDIO-space address to read the data from. 107 */ 108 extern int bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length); 109 110 /* Synchronous access to device (client) core registers via CMD53 to F1. 111 * addr: backplane address (i.e. >= regsva from attach) 112 * size: register width in bytes (2 or 4) 113 * data: data for register write 114 */ 115 extern uint32 bcmsdh_reg_read(void *sdh, uint32 addr, uint size); 116 extern uint32 bcmsdh_reg_write(void *sdh, uint32 addr, uint size, uint32 data); 117 118 /* set sb address window */ 119 extern int bcmsdhsdio_set_sbaddr_window(void *sdh, uint32 address, bool force_set); 120 121 /* Indicate if last reg read/write failed */ 122 extern bool bcmsdh_regfail(void *sdh); 123 124 /* Buffer transfer to/from device (client) core via cmd53. 125 * fn: function number 126 * addr: backplane address (i.e. >= regsva from attach) 127 * flags: backplane width, address increment, sync/async 128 * buf: pointer to memory data buffer 129 * nbytes: number of bytes to transfer to/from buf 130 * pkt: pointer to packet associated with buf (if any) 131 * complete: callback function for command completion (async only) 132 * handle: handle for completion callback (first arg in callback) 133 * Returns 0 or error code. 134 * NOTE: Async operation is not currently supported. 135 */ 136 typedef void (*bcmsdh_cmplt_fn_t)(void *handle, int status, bool sync_waiting); 137 extern int bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags, 138 uint8 *buf, uint nbytes, void *pkt, 139 bcmsdh_cmplt_fn_t complete_fn, void *handle); 140 extern int bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags, 141 uint8 *buf, uint nbytes, void *pkt, 142 bcmsdh_cmplt_fn_t complete_fn, void *handle); 143 144 extern void bcmsdh_glom_post(void *sdh, uint8 *frame, void *pkt, uint len); 145 extern void bcmsdh_glom_clear(void *sdh); 146 extern uint bcmsdh_set_mode(void *sdh, uint mode); 147 extern bool bcmsdh_glom_enabled(void); 148 /* Flags bits */ 149 #define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */ 150 #define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */ 151 #define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */ 152 #define SDIO_BYTE_MODE 0x8 /* Byte mode request(non-block mode) */ 153 154 /* Pending (non-error) return code */ 155 #define BCME_PENDING 1 156 157 /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only). 158 * rw: read or write (0/1) 159 * addr: direct SDIO address 160 * buf: pointer to memory data buffer 161 * nbytes: number of bytes to transfer to/from buf 162 * Returns 0 or error code. 163 */ 164 extern int bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes); 165 166 /* Issue an abort to the specified function */ 167 extern int bcmsdh_abort(void *sdh, uint fn); 168 169 /* Start SDIO Host Controller communication */ 170 extern int bcmsdh_start(void *sdh, int stage); 171 172 /* Stop SDIO Host Controller communication */ 173 extern int bcmsdh_stop(void *sdh); 174 175 /* Wait system lock free */ 176 extern int bcmsdh_waitlockfree(void *sdh); 177 178 /* Returns the "Device ID" of target device on the SDIO bus. */ 179 extern int bcmsdh_query_device(void *sdh); 180 181 /* Returns the number of IO functions reported by the device */ 182 extern uint bcmsdh_query_iofnum(void *sdh); 183 184 /* Miscellaneous knob tweaker. */ 185 extern int bcmsdh_iovar_op(void *sdh, const char *name, 186 void *params, int plen, void *arg, int len, bool set); 187 188 /* Reset and reinitialize the device */ 189 extern int bcmsdh_reset(bcmsdh_info_t *sdh); 190 191 /* helper functions */ 192 193 extern void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh); 194 195 /* callback functions */ 196 typedef struct { 197 /* attach to device */ 198 void *(*attach)(uint16 vend_id, uint16 dev_id, uint16 bus, uint16 slot, 199 uint16 func, uint bustype, void * regsva, osl_t * osh, 200 void * param); 201 /* detach from device */ 202 void (*detach)(void *ch); 203 } bcmsdh_driver_t; 204 205 /* platform specific/high level functions */ 206 extern int bcmsdh_register(bcmsdh_driver_t *driver); 207 extern void bcmsdh_unregister(void); 208 extern bool bcmsdh_chipmatch(uint16 vendor, uint16 device); 209 extern void bcmsdh_device_remove(void * sdh); 210 211 extern int bcmsdh_reg_sdio_notify(void* semaphore); 212 extern void bcmsdh_unreg_sdio_notify(void); 213 214 #if defined(OOB_INTR_ONLY) 215 extern int bcmsdh_register_oob_intr(void * dhdp); 216 extern void bcmsdh_unregister_oob_intr(void); 217 extern void bcmsdh_oob_intr_set(bool enable); 218 extern bool bcmsdh_is_oob_intr_registered(void); 219 #endif 220 221 /* Function to pass device-status bits to DHD. */ 222 extern uint32 bcmsdh_get_dstatus(void *sdh); 223 224 /* Function to return current window addr */ 225 extern uint32 bcmsdh_cur_sbwad(void *sdh); 226 227 /* Function to pass chipid and rev to lower layers for controlling pr's */ 228 extern void bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev); 229 230 231 extern int bcmsdh_sleep(void *sdh, bool enab); 232 233 /* GPIO support */ 234 extern int bcmsdh_gpio_init(void *sd); 235 extern bool bcmsdh_gpioin(void *sd, uint32 gpio); 236 extern int bcmsdh_gpioouten(void *sd, uint32 gpio); 237 extern int bcmsdh_gpioout(void *sd, uint32 gpio, bool enab); 238 239 #endif /* _bcmsdh_h_ */ 240