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 */ |
| 39 | uint32 vendevid; /* Target Vendor and Device ID on SD bus */ |
| 40 | osl_t *osh; |
| 41 | bool regfail; /* Save status of last |
| 42 | reg_read/reg_write call */ |
| 43 | uint32 sbwad; /* Save backplane window address */ |
| 44 | }; |
| 45 | /* local copy of bcm sd handler */ |
| 46 | bcmsdh_info_t *l_bcmsdh = NULL; |
| 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 | |
| 61 | if ((bcmsdh = |
| 62 | (bcmsdh_info_t *) MALLOC(osh, sizeof(bcmsdh_info_t))) == NULL) { |
| 63 | BCMSDH_ERROR(("bcmsdh_attach: out of memory, " |
| 64 | "malloced %d bytes\n", MALLOCED(osh))); |
| 65 | return NULL; |
| 66 | } |
| 67 | bzero((char *)bcmsdh, sizeof(bcmsdh_info_t)); |
| 68 | |
| 69 | /* save the handler locally */ |
| 70 | l_bcmsdh = bcmsdh; |
| 71 | |
| 72 | if (!(bcmsdh->sdioh = sdioh_attach(osh, cfghdl, irq))) { |
| 73 | bcmsdh_detach(osh, bcmsdh); |
| 74 | return NULL; |
| 75 | } |
| 76 | |
| 77 | bcmsdh->osh = osh; |
| 78 | bcmsdh->init_success = TRUE; |
| 79 | |
| 80 | *regsva = (uint32 *) SI_ENUM_BASE; |
| 81 | |
| 82 | /* Report the BAR, to fix if needed */ |
| 83 | bcmsdh->sbwad = SI_ENUM_BASE; |
| 84 | return bcmsdh; |
| 85 | } |
| 86 | |
| 87 | int bcmsdh_detach(osl_t *osh, void *sdh) |
| 88 | { |
| 89 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 90 | |
| 91 | if (bcmsdh != NULL) { |
| 92 | if (bcmsdh->sdioh) { |
| 93 | sdioh_detach(osh, bcmsdh->sdioh); |
| 94 | bcmsdh->sdioh = NULL; |
| 95 | } |
| 96 | MFREE(osh, bcmsdh, sizeof(bcmsdh_info_t)); |
| 97 | } |
| 98 | |
| 99 | l_bcmsdh = NULL; |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | int |
| 104 | bcmsdh_iovar_op(void *sdh, const char *name, |
| 105 | void *params, int plen, void *arg, int len, bool set) |
| 106 | { |
| 107 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 108 | return sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, len, set); |
| 109 | } |
| 110 | |
| 111 | bool bcmsdh_intr_query(void *sdh) |
| 112 | { |
| 113 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 114 | SDIOH_API_RC status; |
| 115 | bool on; |
| 116 | |
| 117 | ASSERT(bcmsdh); |
| 118 | status = sdioh_interrupt_query(bcmsdh->sdioh, &on); |
| 119 | if (SDIOH_API_SUCCESS(status)) |
| 120 | return FALSE; |
| 121 | else |
| 122 | return on; |
| 123 | } |
| 124 | |
| 125 | int bcmsdh_intr_enable(void *sdh) |
| 126 | { |
| 127 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 128 | SDIOH_API_RC status; |
| 129 | ASSERT(bcmsdh); |
| 130 | |
| 131 | status = sdioh_interrupt_set(bcmsdh->sdioh, TRUE); |
| 132 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 133 | } |
| 134 | |
| 135 | int bcmsdh_intr_disable(void *sdh) |
| 136 | { |
| 137 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 138 | SDIOH_API_RC status; |
| 139 | ASSERT(bcmsdh); |
| 140 | |
| 141 | status = sdioh_interrupt_set(bcmsdh->sdioh, FALSE); |
| 142 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 143 | } |
| 144 | |
| 145 | int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
| 146 | { |
| 147 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 148 | SDIOH_API_RC status; |
| 149 | ASSERT(bcmsdh); |
| 150 | |
| 151 | status = sdioh_interrupt_register(bcmsdh->sdioh, fn, argh); |
| 152 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 153 | } |
| 154 | |
| 155 | int bcmsdh_intr_dereg(void *sdh) |
| 156 | { |
| 157 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 158 | SDIOH_API_RC status; |
| 159 | ASSERT(bcmsdh); |
| 160 | |
| 161 | status = sdioh_interrupt_deregister(bcmsdh->sdioh); |
| 162 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 163 | } |
| 164 | |
| 165 | #if defined(DHD_DEBUG) |
| 166 | bool bcmsdh_intr_pending(void *sdh) |
| 167 | { |
| 168 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 169 | |
| 170 | ASSERT(sdh); |
| 171 | return sdioh_interrupt_pending(bcmsdh->sdioh); |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
| 176 | { |
| 177 | ASSERT(sdh); |
| 178 | |
| 179 | /* don't support yet */ |
| 180 | return BCME_UNSUPPORTED; |
| 181 | } |
| 182 | |
| 183 | uint8 bcmsdh_cfg_read(void *sdh, uint fnc_num, uint32 addr, int *err) |
| 184 | { |
| 185 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 186 | SDIOH_API_RC status; |
| 187 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 188 | int32 retry = 0; |
| 189 | #endif |
| 190 | uint8 data = 0; |
| 191 | |
| 192 | if (!bcmsdh) |
| 193 | bcmsdh = l_bcmsdh; |
| 194 | |
| 195 | ASSERT(bcmsdh->init_success); |
| 196 | |
| 197 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 198 | do { |
| 199 | if (retry) /* wait for 1 ms till bus get settled down */ |
| 200 | OSL_DELAY(1000); |
| 201 | #endif |
| 202 | status = |
| 203 | sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr, |
| 204 | (uint8 *) &data); |
| 205 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 206 | } while (!SDIOH_API_SUCCESS(status) |
| 207 | && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
| 208 | #endif |
| 209 | if (err) |
| 210 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 211 | |
| 212 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", |
| 213 | __func__, fnc_num, addr, data)); |
| 214 | |
| 215 | return data; |
| 216 | } |
| 217 | |
| 218 | void |
| 219 | bcmsdh_cfg_write(void *sdh, uint fnc_num, uint32 addr, uint8 data, int *err) |
| 220 | { |
| 221 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 222 | SDIOH_API_RC status; |
| 223 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 224 | int32 retry = 0; |
| 225 | #endif |
| 226 | |
| 227 | if (!bcmsdh) |
| 228 | bcmsdh = l_bcmsdh; |
| 229 | |
| 230 | ASSERT(bcmsdh->init_success); |
| 231 | |
| 232 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 233 | do { |
| 234 | if (retry) /* wait for 1 ms till bus get settled down */ |
| 235 | OSL_DELAY(1000); |
| 236 | #endif |
| 237 | status = |
| 238 | sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr, |
| 239 | (uint8 *) &data); |
| 240 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 241 | } while (!SDIOH_API_SUCCESS(status) |
| 242 | && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
| 243 | #endif |
| 244 | if (err) |
| 245 | *err = SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR; |
| 246 | |
| 247 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", |
| 248 | __func__, fnc_num, addr, data)); |
| 249 | } |
| 250 | |
| 251 | uint32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, int *err) |
| 252 | { |
| 253 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 254 | SDIOH_API_RC status; |
| 255 | uint32 data = 0; |
| 256 | |
| 257 | if (!bcmsdh) |
| 258 | bcmsdh = l_bcmsdh; |
| 259 | |
| 260 | ASSERT(bcmsdh->init_success); |
| 261 | |
| 262 | status = |
| 263 | sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_READ, |
| 264 | fnc_num, addr, &data, 4); |
| 265 | |
| 266 | if (err) |
| 267 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 268 | |
| 269 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", |
| 270 | __func__, fnc_num, addr, data)); |
| 271 | |
| 272 | return data; |
| 273 | } |
| 274 | |
| 275 | void |
| 276 | bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, uint32 data, |
| 277 | int *err) |
| 278 | { |
| 279 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 280 | SDIOH_API_RC status; |
| 281 | |
| 282 | if (!bcmsdh) |
| 283 | bcmsdh = l_bcmsdh; |
| 284 | |
| 285 | ASSERT(bcmsdh->init_success); |
| 286 | |
| 287 | status = |
| 288 | sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
| 289 | SDIOH_WRITE, fnc_num, addr, &data, 4); |
| 290 | |
| 291 | if (err) |
| 292 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 293 | |
| 294 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", |
| 295 | __func__, fnc_num, addr, data)); |
| 296 | } |
| 297 | |
| 298 | int bcmsdh_cis_read(void *sdh, uint func, uint8 * cis, uint length) |
| 299 | { |
| 300 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 301 | SDIOH_API_RC status; |
| 302 | |
| 303 | uint8 *tmp_buf, *tmp_ptr; |
| 304 | uint8 *ptr; |
| 305 | bool ascii = func & ~0xf; |
| 306 | func &= 0x7; |
| 307 | |
| 308 | if (!bcmsdh) |
| 309 | bcmsdh = l_bcmsdh; |
| 310 | |
| 311 | ASSERT(bcmsdh->init_success); |
| 312 | ASSERT(cis); |
| 313 | ASSERT(length <= SBSDIO_CIS_SIZE_LIMIT); |
| 314 | |
| 315 | status = sdioh_cis_read(bcmsdh->sdioh, func, cis, length); |
| 316 | |
| 317 | if (ascii) { |
| 318 | /* Move binary bits to tmp and format them |
| 319 | into the provided buffer. */ |
| 320 | if ((tmp_buf = (uint8 *) MALLOC(bcmsdh->osh, length)) == NULL) { |
| 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 | |
| 337 | static int bcmsdhsdio_set_sbaddr_window(void *sdh, uint32 address) |
| 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 | |
| 354 | uint32 bcmsdh_reg_read(void *sdh, uint32 addr, uint size) |
| 355 | { |
| 356 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 357 | SDIOH_API_RC status; |
| 358 | uint32 word = 0; |
| 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 | |
| 384 | BCMSDH_INFO(("uint32data = 0x%x\n", word)); |
| 385 | |
| 386 | /* if ok, return appropriately masked word */ |
| 387 | if (SDIOH_API_SUCCESS(status)) { |
| 388 | switch (size) { |
| 389 | case sizeof(uint8): |
| 390 | return word & 0xff; |
| 391 | case sizeof(uint16): |
| 392 | return word & 0xffff; |
| 393 | case sizeof(uint32): |
| 394 | return word; |
| 395 | default: |
| 396 | bcmsdh->regfail = TRUE; |
| 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 | |
| 407 | uint32 bcmsdh_reg_write(void *sdh, uint32 addr, uint size, uint32 data) |
| 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) { |
| 423 | if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0))) |
| 424 | return err; |
| 425 | |
| 426 | bcmsdh->sbwad = bar0; |
| 427 | } |
| 428 | |
| 429 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 430 | if (size == 4) |
| 431 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 432 | status = |
| 433 | sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
| 434 | SDIOH_WRITE, SDIO_FUNC_1, addr, &data, size); |
| 435 | bcmsdh->regfail = !(SDIOH_API_SUCCESS(status)); |
| 436 | |
| 437 | if (SDIOH_API_SUCCESS(status)) |
| 438 | return 0; |
| 439 | |
| 440 | BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n", |
| 441 | __func__, data, addr, size)); |
| 442 | return 0xFFFFFFFF; |
| 443 | } |
| 444 | |
| 445 | bool bcmsdh_regfail(void *sdh) |
| 446 | { |
| 447 | return ((bcmsdh_info_t *) sdh)->regfail; |
| 448 | } |
| 449 | |
| 450 | int |
| 451 | bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags, |
| 452 | uint8 *buf, uint nbytes, void *pkt, |
| 453 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 454 | { |
| 455 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 456 | SDIOH_API_RC status; |
| 457 | uint incr_fix; |
| 458 | uint width; |
| 459 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 460 | int err = 0; |
| 461 | |
| 462 | ASSERT(bcmsdh); |
| 463 | ASSERT(bcmsdh->init_success); |
| 464 | |
| 465 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", |
| 466 | __func__, fn, addr, nbytes)); |
| 467 | |
| 468 | /* Async not implemented yet */ |
| 469 | ASSERT(!(flags & SDIO_REQ_ASYNC)); |
| 470 | if (flags & SDIO_REQ_ASYNC) |
| 471 | return BCME_UNSUPPORTED; |
| 472 | |
| 473 | if (bar0 != bcmsdh->sbwad) { |
| 474 | if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0))) |
| 475 | return err; |
| 476 | |
| 477 | bcmsdh->sbwad = bar0; |
| 478 | } |
| 479 | |
| 480 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 481 | |
| 482 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
| 483 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
| 484 | if (width == 4) |
| 485 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 486 | |
| 487 | status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix, |
| 488 | SDIOH_READ, fn, addr, width, nbytes, buf, |
| 489 | pkt); |
| 490 | |
| 491 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR; |
| 492 | } |
| 493 | |
| 494 | int |
| 495 | bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags, |
| 496 | uint8 *buf, uint nbytes, void *pkt, |
| 497 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 498 | { |
| 499 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 500 | SDIOH_API_RC status; |
| 501 | uint incr_fix; |
| 502 | uint width; |
| 503 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 504 | int err = 0; |
| 505 | |
| 506 | ASSERT(bcmsdh); |
| 507 | ASSERT(bcmsdh->init_success); |
| 508 | |
| 509 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", |
| 510 | __func__, fn, addr, nbytes)); |
| 511 | |
| 512 | /* Async not implemented yet */ |
| 513 | ASSERT(!(flags & SDIO_REQ_ASYNC)); |
| 514 | if (flags & SDIO_REQ_ASYNC) |
| 515 | return BCME_UNSUPPORTED; |
| 516 | |
| 517 | if (bar0 != bcmsdh->sbwad) { |
| 518 | if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, bar0))) |
| 519 | return err; |
| 520 | |
| 521 | bcmsdh->sbwad = bar0; |
| 522 | } |
| 523 | |
| 524 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 525 | |
| 526 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
| 527 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
| 528 | if (width == 4) |
| 529 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 530 | |
| 531 | status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix, |
| 532 | SDIOH_WRITE, fn, addr, width, nbytes, buf, |
| 533 | pkt); |
| 534 | |
| 535 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 536 | } |
| 537 | |
| 538 | int bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes) |
| 539 | { |
| 540 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 541 | SDIOH_API_RC status; |
| 542 | |
| 543 | ASSERT(bcmsdh); |
| 544 | ASSERT(bcmsdh->init_success); |
| 545 | ASSERT((addr & SBSDIO_SBWINDOW_MASK) == 0); |
| 546 | |
| 547 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 548 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 549 | |
| 550 | status = |
| 551 | sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, SDIOH_DATA_INC, |
| 552 | (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1, |
| 553 | addr, 4, nbytes, buf, NULL); |
| 554 | |
| 555 | return SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR; |
| 556 | } |
| 557 | |
| 558 | int bcmsdh_abort(void *sdh, uint fn) |
| 559 | { |
| 560 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 561 | |
| 562 | return sdioh_abort(bcmsdh->sdioh, fn); |
| 563 | } |
| 564 | |
| 565 | int bcmsdh_start(void *sdh, int stage) |
| 566 | { |
| 567 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 568 | |
| 569 | return sdioh_start(bcmsdh->sdioh, stage); |
| 570 | } |
| 571 | |
| 572 | int bcmsdh_stop(void *sdh) |
| 573 | { |
| 574 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 575 | |
| 576 | return sdioh_stop(bcmsdh->sdioh); |
| 577 | } |
| 578 | |
| 579 | int bcmsdh_query_device(void *sdh) |
| 580 | { |
| 581 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 582 | bcmsdh->vendevid = (VENDOR_BROADCOM << 16) | 0; |
| 583 | return bcmsdh->vendevid; |
| 584 | } |
| 585 | |
| 586 | uint bcmsdh_query_iofnum(void *sdh) |
| 587 | { |
| 588 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 589 | |
| 590 | if (!bcmsdh) |
| 591 | bcmsdh = l_bcmsdh; |
| 592 | |
| 593 | return sdioh_query_iofnum(bcmsdh->sdioh); |
| 594 | } |
| 595 | |
| 596 | int bcmsdh_reset(bcmsdh_info_t *sdh) |
| 597 | { |
| 598 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 599 | |
| 600 | return sdioh_sdio_reset(bcmsdh->sdioh); |
| 601 | } |
| 602 | |
| 603 | void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh) |
| 604 | { |
| 605 | ASSERT(sdh); |
| 606 | return sdh->sdioh; |
| 607 | } |
| 608 | |
| 609 | /* Function to pass device-status bits to DHD. */ |
| 610 | uint32 bcmsdh_get_dstatus(void *sdh) |
| 611 | { |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | uint32 bcmsdh_cur_sbwad(void *sdh) |
| 616 | { |
| 617 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; |
| 618 | |
| 619 | if (!bcmsdh) |
| 620 | bcmsdh = l_bcmsdh; |
| 621 | |
| 622 | return bcmsdh->sbwad; |
| 623 | } |
| 624 | |
| 625 | void bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev) |
| 626 | { |
| 627 | return; |
| 628 | } |