Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _bcmsdh_h_ |
| 18 | #define _bcmsdh_h_ |
| 19 | |
| 20 | #define BCMSDH_ERROR_VAL 0x0001 /* Error */ |
| 21 | #define BCMSDH_INFO_VAL 0x0002 /* Info */ |
| 22 | extern const uint bcmsdh_msglevel; |
| 23 | |
| 24 | #ifdef BCMDBG |
| 25 | #define BCMSDH_ERROR(x) do { if ((bcmsdh_msglevel & BCMSDH_ERROR_VAL) && net_ratelimit()) printf x; } while (0) |
| 26 | #define BCMSDH_INFO(x) do { if ((bcmsdh_msglevel & BCMSDH_INFO_VAL) && net_ratelimit()) printf x; } while (0) |
| 27 | #else /* BCMDBG */ |
| 28 | #define BCMSDH_ERROR(x) |
| 29 | #define BCMSDH_INFO(x) |
| 30 | #endif /* BCMDBG */ |
| 31 | |
| 32 | /* forward declarations */ |
| 33 | typedef struct bcmsdh_info bcmsdh_info_t; |
| 34 | typedef void (*bcmsdh_cb_fn_t) (void *); |
| 35 | |
| 36 | /* Attach and build an interface to the underlying SD host driver. |
| 37 | * - Allocates resources (structs, arrays, mem, OS handles, etc) needed by bcmsdh. |
| 38 | * - Returns the bcmsdh handle and virtual address base for register access. |
| 39 | * The returned handle should be used in all subsequent calls, but the bcmsh |
| 40 | * implementation may maintain a single "default" handle (e.g. the first or |
| 41 | * most recent one) to enable single-instance implementations to pass NULL. |
| 42 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 43 | extern bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 44 | uint irq); |
| 45 | |
| 46 | /* Detach - freeup resources allocated in attach */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 47 | extern int bcmsdh_detach(osl_t *osh, void *sdh); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 48 | |
| 49 | /* Query if SD device interrupts are enabled */ |
| 50 | extern bool bcmsdh_intr_query(void *sdh); |
| 51 | |
| 52 | /* Enable/disable SD interrupt */ |
| 53 | extern int bcmsdh_intr_enable(void *sdh); |
| 54 | extern int bcmsdh_intr_disable(void *sdh); |
| 55 | |
| 56 | /* Register/deregister device interrupt handler. */ |
| 57 | extern int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh); |
| 58 | extern int bcmsdh_intr_dereg(void *sdh); |
| 59 | |
| 60 | #if defined(BCMDBG) |
| 61 | /* Query pending interrupt status from the host controller */ |
| 62 | extern bool bcmsdh_intr_pending(void *sdh); |
| 63 | #endif |
| 64 | extern int bcmsdh_claim_host_and_lock(void *sdh); |
| 65 | extern int bcmsdh_release_host_and_unlock(void *sdh); |
| 66 | |
| 67 | /* Register a callback to be called if and when bcmsdh detects |
| 68 | * device removal. No-op in the case of non-removable/hardwired devices. |
| 69 | */ |
| 70 | extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh); |
| 71 | |
| 72 | /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface). |
| 73 | * fn: function number |
| 74 | * addr: unmodified SDIO-space address |
| 75 | * data: data byte to write |
| 76 | * err: pointer to error code (or NULL) |
| 77 | */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 78 | extern u8 bcmsdh_cfg_read(void *sdh, uint func, u32 addr, int *err); |
| 79 | extern void bcmsdh_cfg_write(void *sdh, uint func, u32 addr, u8 data, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 80 | int *err); |
| 81 | |
| 82 | /* Read/Write 4bytes from/to cfg space */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 83 | extern u32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, u32 addr, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 84 | int *err); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 85 | extern void bcmsdh_cfg_write_word(void *sdh, uint fnc_num, u32 addr, |
| 86 | u32 data, int *err); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 87 | |
| 88 | /* Read CIS content for specified function. |
| 89 | * fn: function whose CIS is being requested (0 is common CIS) |
| 90 | * cis: pointer to memory location to place results |
| 91 | * length: number of bytes to read |
| 92 | * Internally, this routine uses the values from the cis base regs (0x9-0xB) |
| 93 | * to form an SDIO-space address to read the data from. |
| 94 | */ |
Greg Kroah-Hartman | de9bca6 | 2010-10-05 10:23:40 -0700 | [diff] [blame] | 95 | extern int bcmsdh_cis_read(void *sdh, uint func, u8 *cis, uint length); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 96 | |
| 97 | /* Synchronous access to device (client) core registers via CMD53 to F1. |
| 98 | * addr: backplane address (i.e. >= regsva from attach) |
| 99 | * size: register width in bytes (2 or 4) |
| 100 | * data: data for register write |
| 101 | */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 102 | extern u32 bcmsdh_reg_read(void *sdh, u32 addr, uint size); |
| 103 | extern u32 bcmsdh_reg_write(void *sdh, u32 addr, uint size, u32 data); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 104 | |
| 105 | /* Indicate if last reg read/write failed */ |
| 106 | extern bool bcmsdh_regfail(void *sdh); |
| 107 | |
| 108 | /* Buffer transfer to/from device (client) core via cmd53. |
| 109 | * fn: function number |
| 110 | * addr: backplane address (i.e. >= regsva from attach) |
| 111 | * flags: backplane width, address increment, sync/async |
| 112 | * buf: pointer to memory data buffer |
| 113 | * nbytes: number of bytes to transfer to/from buf |
| 114 | * pkt: pointer to packet associated with buf (if any) |
| 115 | * complete: callback function for command completion (async only) |
| 116 | * handle: handle for completion callback (first arg in callback) |
| 117 | * Returns 0 or error code. |
| 118 | * NOTE: Async operation is not currently supported. |
| 119 | */ |
| 120 | typedef void (*bcmsdh_cmplt_fn_t) (void *handle, int status, bool sync_waiting); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 121 | extern int bcmsdh_send_buf(void *sdh, u32 addr, uint fn, uint flags, |
Greg Kroah-Hartman | de9bca6 | 2010-10-05 10:23:40 -0700 | [diff] [blame] | 122 | u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 123 | bcmsdh_cmplt_fn_t complete, void *handle); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 124 | extern int bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags, |
Greg Kroah-Hartman | de9bca6 | 2010-10-05 10:23:40 -0700 | [diff] [blame] | 125 | u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 126 | bcmsdh_cmplt_fn_t complete, void *handle); |
| 127 | |
| 128 | /* Flags bits */ |
| 129 | #define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */ |
| 130 | #define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */ |
| 131 | #define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */ |
| 132 | |
| 133 | /* Pending (non-error) return code */ |
| 134 | #define BCME_PENDING 1 |
| 135 | |
| 136 | /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only). |
| 137 | * rw: read or write (0/1) |
| 138 | * addr: direct SDIO address |
| 139 | * buf: pointer to memory data buffer |
| 140 | * nbytes: number of bytes to transfer to/from buf |
| 141 | * Returns 0 or error code. |
| 142 | */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 143 | extern int bcmsdh_rwdata(void *sdh, uint rw, u32 addr, u8 *buf, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 144 | uint nbytes); |
| 145 | |
| 146 | /* Issue an abort to the specified function */ |
| 147 | extern int bcmsdh_abort(void *sdh, uint fn); |
| 148 | |
| 149 | /* Start SDIO Host Controller communication */ |
| 150 | extern int bcmsdh_start(void *sdh, int stage); |
| 151 | |
| 152 | /* Stop SDIO Host Controller communication */ |
| 153 | extern int bcmsdh_stop(void *sdh); |
| 154 | |
| 155 | /* Returns the "Device ID" of target device on the SDIO bus. */ |
| 156 | extern int bcmsdh_query_device(void *sdh); |
| 157 | |
| 158 | /* Returns the number of IO functions reported by the device */ |
| 159 | extern uint bcmsdh_query_iofnum(void *sdh); |
| 160 | |
| 161 | /* Miscellaneous knob tweaker. */ |
| 162 | extern int bcmsdh_iovar_op(void *sdh, const char *name, |
| 163 | void *params, int plen, void *arg, int len, |
| 164 | bool set); |
| 165 | |
| 166 | /* Reset and reinitialize the device */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 167 | extern int bcmsdh_reset(bcmsdh_info_t *sdh); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 168 | |
| 169 | /* helper functions */ |
| 170 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 171 | extern void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 172 | |
| 173 | /* callback functions */ |
| 174 | typedef struct { |
| 175 | /* attach to device */ |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 176 | void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot, |
| 177 | u16 func, uint bustype, void *regsva, osl_t *osh, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 178 | void *param); |
| 179 | /* detach from device */ |
| 180 | void (*detach) (void *ch); |
| 181 | } bcmsdh_driver_t; |
| 182 | |
| 183 | /* platform specific/high level functions */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 184 | extern int bcmsdh_register(bcmsdh_driver_t *driver); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 185 | extern void bcmsdh_unregister(void); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 186 | extern bool bcmsdh_chipmatch(u16 vendor, u16 device); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 187 | extern void bcmsdh_device_remove(void *sdh); |
| 188 | |
| 189 | /* Function to pass device-status bits to DHD. */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 190 | extern u32 bcmsdh_get_dstatus(void *sdh); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 191 | |
| 192 | /* Function to return current window addr */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 193 | extern u32 bcmsdh_cur_sbwad(void *sdh); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 194 | |
| 195 | /* Function to pass chipid and rev to lower layers for controlling pr's */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame^] | 196 | extern void bcmsdh_chipinfo(void *sdh, u32 chip, u32 chiprev); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 197 | |
| 198 | #endif /* _bcmsdh_h_ */ |