Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -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 | /* ****************** BCMSDH Interface Functions *************************** */ |
| 17 | |
| 18 | #include <typedefs.h> |
| 19 | #include <bcmdevs.h> |
| 20 | #include <bcmendian.h> |
| 21 | #include <bcmutils.h> |
| 22 | #include <hndsoc.h> |
| 23 | #include <siutils.h> |
| 24 | #include <osl.h> |
| 25 | |
| 26 | #include <bcmsdh.h> /* BRCM API for SDIO |
| 27 | clients (such as wl, dhd) */ |
| 28 | #include <bcmsdbus.h> /* common SDIO/controller interface */ |
| 29 | #include <sbsdio.h> /* BRCM sdio device core */ |
| 30 | |
| 31 | #include <sdio.h> /* sdio spec */ |
| 32 | |
| 33 | #define SDIOH_API_ACCESS_RETRY_LIMIT 2 |
| 34 | const uint bcmsdh_msglevel = BCMSDH_ERROR_VAL; |
| 35 | |
| 36 | struct bcmsdh_info { |
| 37 | bool init_success; /* underlying driver successfully attached */ |
| 38 | void *sdioh; /* handler for sdioh */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 39 | u32 vendevid; /* Target Vendor and Device ID on SD bus */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 40 | osl_t *osh; |
| 41 | bool regfail; /* Save status of last |
| 42 | reg_read/reg_write call */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 43 | u32 sbwad; /* Save backplane window address */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 44 | }; |
| 45 | /* local copy of bcm sd handler */ |
Jason Cooper | 6998d33 | 2010-10-06 10:08:00 -0400 | [diff] [blame] | 46 | bcmsdh_info_t *l_bcmsdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 47 | |
| 48 | #if defined(OOB_INTR_ONLY) && defined(HW_OOB) |
| 49 | extern int sdioh_enable_hw_oob_intr(void *sdioh, bool enable); |
| 50 | |
| 51 | void bcmsdh_enable_hw_oob_intr(bcmsdh_info_t *sdh, bool enable) |
| 52 | { |
| 53 | sdioh_enable_hw_oob_intr(sdh->sdioh, enable); |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, uint irq) |
| 58 | { |
| 59 | bcmsdh_info_t *bcmsdh; |
| 60 | |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame^] | 61 | bcmsdh = kzalloc(sizeof(bcmsdh_info_t), GFP_ATOMIC); |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 62 | if (bcmsdh == NULL) { |
mike.rapoport@gmail.com | 97e17d0 | 2010-10-13 00:09:09 +0200 | [diff] [blame] | 63 | BCMSDH_ERROR(("bcmsdh_attach: out of memory")); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 64 | return NULL; |
| 65 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 66 | |
| 67 | /* save the handler locally */ |
| 68 | l_bcmsdh = bcmsdh; |
| 69 | |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 70 | bcmsdh->sdioh = sdioh_attach(osh, cfghdl, irq); |
| 71 | if (!bcmsdh->sdioh) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 72 | bcmsdh_detach(osh, bcmsdh); |
| 73 | return NULL; |
| 74 | } |
| 75 | |
| 76 | bcmsdh->osh = osh; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 77 | bcmsdh->init_success = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 78 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 79 | *regsva = (u32 *) SI_ENUM_BASE; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 80 | |
| 81 | /* Report the BAR, to fix if needed */ |
| 82 | bcmsdh->sbwad = SI_ENUM_BASE; |
| 83 | return bcmsdh; |
| 84 | } |
| 85 | |
| 86 | int bcmsdh_detach(osl_t *osh, void *sdh) |
| 87 | { |
| 88 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 89 | |
| 90 | if (bcmsdh != NULL) { |
| 91 | if (bcmsdh->sdioh) { |
| 92 | sdioh_detach(osh, bcmsdh->sdioh); |
| 93 | bcmsdh->sdioh = NULL; |
| 94 | } |
| 95 | MFREE(osh, bcmsdh, sizeof(bcmsdh_info_t)); |
| 96 | } |
| 97 | |
| 98 | l_bcmsdh = NULL; |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | int |
| 103 | bcmsdh_iovar_op(void *sdh, const char *name, |
| 104 | void *params, int plen, void *arg, int len, bool set) |
| 105 | { |
| 106 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 107 | return sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, len, set); |
| 108 | } |
| 109 | |
| 110 | bool bcmsdh_intr_query(void *sdh) |
| 111 | { |
| 112 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 113 | SDIOH_API_RC status; |
| 114 | bool on; |
| 115 | |
| 116 | ASSERT(bcmsdh); |
| 117 | status = sdioh_interrupt_query(bcmsdh->sdioh, &on); |
| 118 | if (SDIOH_API_SUCCESS(status)) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 119 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 120 | else |
| 121 | return on; |
| 122 | } |
| 123 | |
| 124 | int bcmsdh_intr_enable(void *sdh) |
| 125 | { |
| 126 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 127 | SDIOH_API_RC status; |
| 128 | ASSERT(bcmsdh); |
| 129 | |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 130 | status = sdioh_interrupt_set(bcmsdh->sdioh, true); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 131 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 132 | } |
| 133 | |
| 134 | int bcmsdh_intr_disable(void *sdh) |
| 135 | { |
| 136 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 137 | SDIOH_API_RC status; |
| 138 | ASSERT(bcmsdh); |
| 139 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 140 | status = sdioh_interrupt_set(bcmsdh->sdioh, false); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 141 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 142 | } |
| 143 | |
| 144 | int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
| 145 | { |
| 146 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 147 | SDIOH_API_RC status; |
| 148 | ASSERT(bcmsdh); |
| 149 | |
| 150 | status = sdioh_interrupt_register(bcmsdh->sdioh, fn, argh); |
| 151 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 152 | } |
| 153 | |
| 154 | int bcmsdh_intr_dereg(void *sdh) |
| 155 | { |
| 156 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 157 | SDIOH_API_RC status; |
| 158 | ASSERT(bcmsdh); |
| 159 | |
| 160 | status = sdioh_interrupt_deregister(bcmsdh->sdioh); |
| 161 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 162 | } |
| 163 | |
| 164 | #if defined(DHD_DEBUG) |
| 165 | bool bcmsdh_intr_pending(void *sdh) |
| 166 | { |
| 167 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 168 | |
| 169 | ASSERT(sdh); |
| 170 | return sdioh_interrupt_pending(bcmsdh->sdioh); |
| 171 | } |
| 172 | #endif |
| 173 | |
| 174 | int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
| 175 | { |
| 176 | ASSERT(sdh); |
| 177 | |
| 178 | /* don't support yet */ |
| 179 | return BCME_UNSUPPORTED; |
| 180 | } |
| 181 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 182 | u8 bcmsdh_cfg_read(void *sdh, uint fnc_num, u32 addr, int *err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 183 | { |
| 184 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 185 | SDIOH_API_RC status; |
| 186 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 187 | s32 retry = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 188 | #endif |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 189 | u8 data = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 190 | |
| 191 | if (!bcmsdh) |
| 192 | bcmsdh = l_bcmsdh; |
| 193 | |
| 194 | ASSERT(bcmsdh->init_success); |
| 195 | |
| 196 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 197 | do { |
| 198 | if (retry) /* wait for 1 ms till bus get settled down */ |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 199 | udelay(1000); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 200 | #endif |
| 201 | status = |
| 202 | sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 203 | (u8 *) &data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 204 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 205 | } while (!SDIOH_API_SUCCESS(status) |
| 206 | && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
| 207 | #endif |
| 208 | if (err) |
| 209 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 210 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 211 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 212 | __func__, fnc_num, addr, data)); |
| 213 | |
| 214 | return data; |
| 215 | } |
| 216 | |
| 217 | void |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 218 | bcmsdh_cfg_write(void *sdh, uint fnc_num, u32 addr, u8 data, int *err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 219 | { |
| 220 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 221 | SDIOH_API_RC status; |
| 222 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 223 | s32 retry = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 224 | #endif |
| 225 | |
| 226 | if (!bcmsdh) |
| 227 | bcmsdh = l_bcmsdh; |
| 228 | |
| 229 | ASSERT(bcmsdh->init_success); |
| 230 | |
| 231 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 232 | do { |
| 233 | if (retry) /* wait for 1 ms till bus get settled down */ |
mike.rapoport@gmail.com | 7383141 | 2010-10-13 00:09:07 +0200 | [diff] [blame] | 234 | udelay(1000); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 235 | #endif |
| 236 | status = |
| 237 | sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 238 | (u8 *) &data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 239 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 240 | } while (!SDIOH_API_SUCCESS(status) |
| 241 | && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
| 242 | #endif |
| 243 | if (err) |
| 244 | *err = SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR; |
| 245 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 246 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 247 | __func__, fnc_num, addr, data)); |
| 248 | } |
| 249 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 250 | u32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, u32 addr, int *err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 251 | { |
| 252 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 253 | SDIOH_API_RC status; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 254 | u32 data = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 255 | |
| 256 | if (!bcmsdh) |
| 257 | bcmsdh = l_bcmsdh; |
| 258 | |
| 259 | ASSERT(bcmsdh->init_success); |
| 260 | |
| 261 | status = |
| 262 | sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_READ, |
| 263 | fnc_num, addr, &data, 4); |
| 264 | |
| 265 | if (err) |
| 266 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 267 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 268 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u32data = 0x%x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 269 | __func__, fnc_num, addr, data)); |
| 270 | |
| 271 | return data; |
| 272 | } |
| 273 | |
| 274 | void |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 275 | bcmsdh_cfg_write_word(void *sdh, uint fnc_num, u32 addr, u32 data, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 276 | int *err) |
| 277 | { |
| 278 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 279 | SDIOH_API_RC status; |
| 280 | |
| 281 | if (!bcmsdh) |
| 282 | bcmsdh = l_bcmsdh; |
| 283 | |
| 284 | ASSERT(bcmsdh->init_success); |
| 285 | |
| 286 | status = |
| 287 | sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
| 288 | SDIOH_WRITE, fnc_num, addr, &data, 4); |
| 289 | |
| 290 | if (err) |
| 291 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 292 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 293 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u32data = 0x%x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 294 | __func__, fnc_num, addr, data)); |
| 295 | } |
| 296 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 297 | int bcmsdh_cis_read(void *sdh, uint func, u8 * cis, uint length) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 298 | { |
| 299 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 300 | SDIOH_API_RC status; |
| 301 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 302 | u8 *tmp_buf, *tmp_ptr; |
| 303 | u8 *ptr; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 304 | bool ascii = func & ~0xf; |
| 305 | func &= 0x7; |
| 306 | |
| 307 | if (!bcmsdh) |
| 308 | bcmsdh = l_bcmsdh; |
| 309 | |
| 310 | ASSERT(bcmsdh->init_success); |
| 311 | ASSERT(cis); |
| 312 | ASSERT(length <= SBSDIO_CIS_SIZE_LIMIT); |
| 313 | |
| 314 | status = sdioh_cis_read(bcmsdh->sdioh, func, cis, length); |
| 315 | |
| 316 | if (ascii) { |
| 317 | /* Move binary bits to tmp and format them |
| 318 | into the provided buffer. */ |
mike.rapoport@gmail.com | 5fcc1fc | 2010-10-13 00:09:10 +0200 | [diff] [blame^] | 319 | tmp_buf = kmalloc(length, GFP_ATOMIC); |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 320 | if (tmp_buf == NULL) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 321 | BCMSDH_ERROR(("%s: out of memory\n", __func__)); |
| 322 | return BCME_NOMEM; |
| 323 | } |
| 324 | bcopy(cis, tmp_buf, length); |
| 325 | for (tmp_ptr = tmp_buf, ptr = cis; ptr < (cis + length - 4); |
| 326 | tmp_ptr++) { |
| 327 | ptr += sprintf((char *)ptr, "%.2x ", *tmp_ptr & 0xff); |
| 328 | if ((((tmp_ptr - tmp_buf) + 1) & 0xf) == 0) |
| 329 | ptr += sprintf((char *)ptr, "\n"); |
| 330 | } |
| 331 | MFREE(bcmsdh->osh, tmp_buf, length); |
| 332 | } |
| 333 | |
| 334 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 335 | } |
| 336 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 337 | static int bcmsdhsdio_set_sbaddr_window(void *sdh, u32 address) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 338 | { |
| 339 | int err = 0; |
| 340 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 341 | bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
| 342 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 343 | if (!err) |
| 344 | bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID, |
| 345 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 346 | if (!err) |
| 347 | bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH, |
| 348 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 349 | &err); |
| 350 | |
| 351 | return err; |
| 352 | } |
| 353 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 354 | u32 bcmsdh_reg_read(void *sdh, u32 addr, uint size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 355 | { |
| 356 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 357 | SDIOH_API_RC status; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 358 | u32 word = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 359 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 360 | |
| 361 | BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, ", __func__, addr)); |
| 362 | |
| 363 | if (!bcmsdh) |
| 364 | bcmsdh = l_bcmsdh; |
| 365 | |
| 366 | ASSERT(bcmsdh->init_success); |
| 367 | |
| 368 | if (bar0 != bcmsdh->sbwad) { |
| 369 | if (bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0)) |
| 370 | return 0xFFFFFFFF; |
| 371 | |
| 372 | bcmsdh->sbwad = bar0; |
| 373 | } |
| 374 | |
| 375 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 376 | if (size == 4) |
| 377 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 378 | |
| 379 | status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
| 380 | SDIOH_READ, SDIO_FUNC_1, addr, &word, size); |
| 381 | |
| 382 | bcmsdh->regfail = !(SDIOH_API_SUCCESS(status)); |
| 383 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 384 | BCMSDH_INFO(("u32data = 0x%x\n", word)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 385 | |
| 386 | /* if ok, return appropriately masked word */ |
| 387 | if (SDIOH_API_SUCCESS(status)) { |
| 388 | switch (size) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 389 | case sizeof(u8): |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 390 | return word & 0xff; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 391 | case sizeof(u16): |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 392 | return word & 0xffff; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 393 | case sizeof(u32): |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 394 | return word; |
| 395 | default: |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 396 | bcmsdh->regfail = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 397 | |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | /* otherwise, bad sdio access or invalid size */ |
| 402 | BCMSDH_ERROR(("%s: error reading addr 0x%04x size %d\n", __func__, |
| 403 | addr, size)); |
| 404 | return 0xFFFFFFFF; |
| 405 | } |
| 406 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 407 | u32 bcmsdh_reg_write(void *sdh, u32 addr, uint size, u32 data) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 408 | { |
| 409 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 410 | SDIOH_API_RC status; |
| 411 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 412 | int err = 0; |
| 413 | |
| 414 | BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n", |
| 415 | __func__, addr, size * 8, data)); |
| 416 | |
| 417 | if (!bcmsdh) |
| 418 | bcmsdh = l_bcmsdh; |
| 419 | |
| 420 | ASSERT(bcmsdh->init_success); |
| 421 | |
| 422 | if (bar0 != bcmsdh->sbwad) { |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 423 | err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0); |
| 424 | if (err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 425 | return err; |
| 426 | |
| 427 | bcmsdh->sbwad = bar0; |
| 428 | } |
| 429 | |
| 430 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 431 | if (size == 4) |
| 432 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 433 | status = |
| 434 | sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
| 435 | SDIOH_WRITE, SDIO_FUNC_1, addr, &data, size); |
| 436 | bcmsdh->regfail = !(SDIOH_API_SUCCESS(status)); |
| 437 | |
| 438 | if (SDIOH_API_SUCCESS(status)) |
| 439 | return 0; |
| 440 | |
| 441 | BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n", |
| 442 | __func__, data, addr, size)); |
| 443 | return 0xFFFFFFFF; |
| 444 | } |
| 445 | |
| 446 | bool bcmsdh_regfail(void *sdh) |
| 447 | { |
| 448 | return ((bcmsdh_info_t *) sdh)->regfail; |
| 449 | } |
| 450 | |
| 451 | int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 452 | bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 453 | u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 454 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 455 | { |
| 456 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 457 | SDIOH_API_RC status; |
| 458 | uint incr_fix; |
| 459 | uint width; |
| 460 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 461 | int err = 0; |
| 462 | |
| 463 | ASSERT(bcmsdh); |
| 464 | ASSERT(bcmsdh->init_success); |
| 465 | |
| 466 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", |
| 467 | __func__, fn, addr, nbytes)); |
| 468 | |
| 469 | /* Async not implemented yet */ |
| 470 | ASSERT(!(flags & SDIO_REQ_ASYNC)); |
| 471 | if (flags & SDIO_REQ_ASYNC) |
| 472 | return BCME_UNSUPPORTED; |
| 473 | |
| 474 | if (bar0 != bcmsdh->sbwad) { |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 475 | err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0); |
| 476 | if (err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 477 | return err; |
| 478 | |
| 479 | bcmsdh->sbwad = bar0; |
| 480 | } |
| 481 | |
| 482 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 483 | |
| 484 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
| 485 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
| 486 | if (width == 4) |
| 487 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 488 | |
| 489 | status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix, |
| 490 | SDIOH_READ, fn, addr, width, nbytes, buf, |
| 491 | pkt); |
| 492 | |
| 493 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR; |
| 494 | } |
| 495 | |
| 496 | int |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 497 | bcmsdh_send_buf(void *sdh, u32 addr, uint fn, uint flags, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 498 | u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 499 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 500 | { |
| 501 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 502 | SDIOH_API_RC status; |
| 503 | uint incr_fix; |
| 504 | uint width; |
| 505 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 506 | int err = 0; |
| 507 | |
| 508 | ASSERT(bcmsdh); |
| 509 | ASSERT(bcmsdh->init_success); |
| 510 | |
| 511 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", |
| 512 | __func__, fn, addr, nbytes)); |
| 513 | |
| 514 | /* Async not implemented yet */ |
| 515 | ASSERT(!(flags & SDIO_REQ_ASYNC)); |
| 516 | if (flags & SDIO_REQ_ASYNC) |
| 517 | return BCME_UNSUPPORTED; |
| 518 | |
| 519 | if (bar0 != bcmsdh->sbwad) { |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 520 | err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0); |
| 521 | if (err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 522 | return err; |
| 523 | |
| 524 | bcmsdh->sbwad = bar0; |
| 525 | } |
| 526 | |
| 527 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 528 | |
| 529 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
| 530 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
| 531 | if (width == 4) |
| 532 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 533 | |
| 534 | status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix, |
| 535 | SDIOH_WRITE, fn, addr, width, nbytes, buf, |
| 536 | pkt); |
| 537 | |
| 538 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 539 | } |
| 540 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 541 | int bcmsdh_rwdata(void *sdh, uint rw, u32 addr, u8 *buf, uint nbytes) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 542 | { |
| 543 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 544 | SDIOH_API_RC status; |
| 545 | |
| 546 | ASSERT(bcmsdh); |
| 547 | ASSERT(bcmsdh->init_success); |
| 548 | ASSERT((addr & SBSDIO_SBWINDOW_MASK) == 0); |
| 549 | |
| 550 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 551 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 552 | |
| 553 | status = |
| 554 | sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, SDIOH_DATA_INC, |
| 555 | (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1, |
| 556 | addr, 4, nbytes, buf, NULL); |
| 557 | |
| 558 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 559 | } |
| 560 | |
| 561 | int bcmsdh_abort(void *sdh, uint fn) |
| 562 | { |
| 563 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 564 | |
| 565 | return sdioh_abort(bcmsdh->sdioh, fn); |
| 566 | } |
| 567 | |
| 568 | int bcmsdh_start(void *sdh, int stage) |
| 569 | { |
| 570 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 571 | |
| 572 | return sdioh_start(bcmsdh->sdioh, stage); |
| 573 | } |
| 574 | |
| 575 | int bcmsdh_stop(void *sdh) |
| 576 | { |
| 577 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 578 | |
| 579 | return sdioh_stop(bcmsdh->sdioh); |
| 580 | } |
| 581 | |
| 582 | int bcmsdh_query_device(void *sdh) |
| 583 | { |
| 584 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 585 | bcmsdh->vendevid = (VENDOR_BROADCOM << 16) | 0; |
| 586 | return bcmsdh->vendevid; |
| 587 | } |
| 588 | |
| 589 | uint bcmsdh_query_iofnum(void *sdh) |
| 590 | { |
| 591 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 592 | |
| 593 | if (!bcmsdh) |
| 594 | bcmsdh = l_bcmsdh; |
| 595 | |
| 596 | return sdioh_query_iofnum(bcmsdh->sdioh); |
| 597 | } |
| 598 | |
| 599 | int bcmsdh_reset(bcmsdh_info_t *sdh) |
| 600 | { |
| 601 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 602 | |
| 603 | return sdioh_sdio_reset(bcmsdh->sdioh); |
| 604 | } |
| 605 | |
| 606 | void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh) |
| 607 | { |
| 608 | ASSERT(sdh); |
| 609 | return sdh->sdioh; |
| 610 | } |
| 611 | |
| 612 | /* Function to pass device-status bits to DHD. */ |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 613 | u32 bcmsdh_get_dstatus(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 614 | { |
| 615 | return 0; |
| 616 | } |
| 617 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 618 | u32 bcmsdh_cur_sbwad(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 619 | { |
| 620 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 621 | |
| 622 | if (!bcmsdh) |
| 623 | bcmsdh = l_bcmsdh; |
| 624 | |
| 625 | return bcmsdh->sbwad; |
| 626 | } |
| 627 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 628 | void bcmsdh_chipinfo(void *sdh, u32 chip, u32 chiprev) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 629 | { |
| 630 | return; |
| 631 | } |