Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BCMSDH interface glue |
| 3 | * implement bcmsdh API for SDIOH driver |
| 4 | * |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame^] | 5 | * Copyright (C) 1999-2012, Broadcom Corporation |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 6 | * |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame^] | 7 | * Unless you and Broadcom execute a separate written software license |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 8 | * agreement governing use of this software, this software is licensed to you |
| 9 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
| 10 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
| 11 | * following added to such license: |
| 12 | * |
| 13 | * As a special exception, the copyright holders of this software give you |
| 14 | * permission to link this software with independent modules, and to copy and |
| 15 | * distribute the resulting executable under terms of your choice, provided that |
| 16 | * you also meet, for each linked independent module, the terms and conditions of |
| 17 | * the license of that module. An independent module is a module which is not |
| 18 | * derived from this software. The special exception does not apply to any |
| 19 | * modifications of the software. |
| 20 | * |
| 21 | * Notwithstanding the above, under no circumstances may you combine this |
| 22 | * software in any way with any other Broadcom software provided under a license |
| 23 | * other than the GPL, without Broadcom's express prior written consent. |
| 24 | * |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame^] | 25 | * $Id: bcmsdh.c 300445 2011-12-03 05:37:20Z $ |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * @file bcmsdh.c |
| 30 | */ |
| 31 | |
| 32 | /* ****************** BCMSDH Interface Functions *************************** */ |
| 33 | |
| 34 | #include <typedefs.h> |
| 35 | #include <bcmdevs.h> |
| 36 | #include <bcmendian.h> |
| 37 | #include <bcmutils.h> |
| 38 | #include <hndsoc.h> |
| 39 | #include <siutils.h> |
| 40 | #include <osl.h> |
| 41 | |
| 42 | #include <bcmsdh.h> /* BRCM API for SDIO clients (such as wl, dhd) */ |
| 43 | #include <bcmsdbus.h> /* common SDIO/controller interface */ |
| 44 | #include <sbsdio.h> /* SDIO device core hardware definitions. */ |
| 45 | |
| 46 | #include <sdio.h> /* SDIO Device and Protocol Specs */ |
| 47 | |
| 48 | #define SDIOH_API_ACCESS_RETRY_LIMIT 2 |
| 49 | const uint bcmsdh_msglevel = BCMSDH_ERROR_VAL; |
| 50 | |
| 51 | /** |
| 52 | * BCMSDH API context |
| 53 | */ |
| 54 | struct bcmsdh_info |
| 55 | { |
| 56 | bool init_success; /* underlying driver successfully attached */ |
| 57 | void *sdioh; /* handler for sdioh */ |
| 58 | uint32 vendevid; /* Target Vendor and Device ID on SD bus */ |
| 59 | osl_t *osh; |
| 60 | bool regfail; /* Save status of last reg_read/reg_write call */ |
| 61 | uint32 sbwad; /* Save backplane window address */ |
| 62 | }; |
| 63 | /* local copy of bcm sd handler */ |
| 64 | bcmsdh_info_t * l_bcmsdh = NULL; |
| 65 | |
| 66 | #if defined(OOB_INTR_ONLY) && defined(HW_OOB) |
| 67 | extern int |
| 68 | sdioh_enable_hw_oob_intr(void *sdioh, bool enable); |
| 69 | |
| 70 | void |
| 71 | bcmsdh_enable_hw_oob_intr(bcmsdh_info_t *sdh, bool enable) |
| 72 | { |
| 73 | sdioh_enable_hw_oob_intr(sdh->sdioh, enable); |
| 74 | } |
| 75 | #endif |
| 76 | |
| 77 | /* Attach BCMSDH layer to SDIO Host Controller Driver |
| 78 | * |
| 79 | * @param osh OSL Handle. |
| 80 | * @param cfghdl Configuration Handle. |
| 81 | * @param regsva Virtual address of controller registers. |
| 82 | * @param irq Interrupt number of SDIO controller. |
| 83 | * |
| 84 | * @return bcmsdh_info_t Handle to BCMSDH context. |
| 85 | */ |
| 86 | bcmsdh_info_t * |
| 87 | bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, uint irq) |
| 88 | { |
| 89 | bcmsdh_info_t *bcmsdh; |
| 90 | |
| 91 | if ((bcmsdh = (bcmsdh_info_t *)MALLOC(osh, sizeof(bcmsdh_info_t))) == NULL) { |
| 92 | BCMSDH_ERROR(("bcmsdh_attach: out of memory, malloced %d bytes\n", MALLOCED(osh))); |
| 93 | return NULL; |
| 94 | } |
| 95 | bzero((char *)bcmsdh, sizeof(bcmsdh_info_t)); |
| 96 | |
| 97 | /* save the handler locally */ |
| 98 | l_bcmsdh = bcmsdh; |
| 99 | |
| 100 | if (!(bcmsdh->sdioh = sdioh_attach(osh, cfghdl, irq))) { |
| 101 | bcmsdh_detach(osh, bcmsdh); |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | bcmsdh->osh = osh; |
| 106 | bcmsdh->init_success = TRUE; |
| 107 | |
| 108 | *regsva = (uint32 *)SI_ENUM_BASE; |
| 109 | |
| 110 | /* Report the BAR, to fix if needed */ |
| 111 | bcmsdh->sbwad = SI_ENUM_BASE; |
| 112 | return bcmsdh; |
| 113 | } |
| 114 | |
| 115 | int |
| 116 | bcmsdh_detach(osl_t *osh, void *sdh) |
| 117 | { |
| 118 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 119 | |
| 120 | if (bcmsdh != NULL) { |
| 121 | if (bcmsdh->sdioh) { |
| 122 | sdioh_detach(osh, bcmsdh->sdioh); |
| 123 | bcmsdh->sdioh = NULL; |
| 124 | } |
| 125 | MFREE(osh, bcmsdh, sizeof(bcmsdh_info_t)); |
| 126 | } |
| 127 | |
| 128 | l_bcmsdh = NULL; |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | int |
| 133 | bcmsdh_iovar_op(void *sdh, const char *name, |
| 134 | void *params, int plen, void *arg, int len, bool set) |
| 135 | { |
| 136 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 137 | return sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, len, set); |
| 138 | } |
| 139 | |
| 140 | bool |
| 141 | bcmsdh_intr_query(void *sdh) |
| 142 | { |
| 143 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 144 | SDIOH_API_RC status; |
| 145 | bool on; |
| 146 | |
| 147 | ASSERT(bcmsdh); |
| 148 | status = sdioh_interrupt_query(bcmsdh->sdioh, &on); |
| 149 | if (SDIOH_API_SUCCESS(status)) |
| 150 | return FALSE; |
| 151 | else |
| 152 | return on; |
| 153 | } |
| 154 | |
| 155 | int |
| 156 | bcmsdh_intr_enable(void *sdh) |
| 157 | { |
| 158 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 159 | SDIOH_API_RC status; |
| 160 | ASSERT(bcmsdh); |
| 161 | |
| 162 | status = sdioh_interrupt_set(bcmsdh->sdioh, TRUE); |
| 163 | return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR); |
| 164 | } |
| 165 | |
| 166 | int |
| 167 | bcmsdh_intr_disable(void *sdh) |
| 168 | { |
| 169 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 170 | SDIOH_API_RC status; |
| 171 | ASSERT(bcmsdh); |
| 172 | |
| 173 | status = sdioh_interrupt_set(bcmsdh->sdioh, FALSE); |
| 174 | return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR); |
| 175 | } |
| 176 | |
| 177 | int |
| 178 | bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
| 179 | { |
| 180 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 181 | SDIOH_API_RC status; |
| 182 | ASSERT(bcmsdh); |
| 183 | |
| 184 | status = sdioh_interrupt_register(bcmsdh->sdioh, fn, argh); |
| 185 | return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR); |
| 186 | } |
| 187 | |
| 188 | int |
| 189 | bcmsdh_intr_dereg(void *sdh) |
| 190 | { |
| 191 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 192 | SDIOH_API_RC status; |
| 193 | ASSERT(bcmsdh); |
| 194 | |
| 195 | status = sdioh_interrupt_deregister(bcmsdh->sdioh); |
| 196 | return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR); |
| 197 | } |
| 198 | |
| 199 | #if defined(DHD_DEBUG) |
| 200 | bool |
| 201 | bcmsdh_intr_pending(void *sdh) |
| 202 | { |
| 203 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 204 | |
| 205 | ASSERT(sdh); |
| 206 | return sdioh_interrupt_pending(bcmsdh->sdioh); |
| 207 | } |
| 208 | #endif |
| 209 | |
| 210 | |
| 211 | int |
| 212 | bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
| 213 | { |
| 214 | ASSERT(sdh); |
| 215 | |
| 216 | /* don't support yet */ |
| 217 | return BCME_UNSUPPORTED; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Read from SDIO Configuration Space |
| 222 | * @param sdh SDIO Host context. |
| 223 | * @param func_num Function number to read from. |
| 224 | * @param addr Address to read from. |
| 225 | * @param err Error return. |
| 226 | * @return value read from SDIO configuration space. |
| 227 | */ |
| 228 | uint8 |
| 229 | bcmsdh_cfg_read(void *sdh, uint fnc_num, uint32 addr, int *err) |
| 230 | { |
| 231 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 232 | SDIOH_API_RC status; |
| 233 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 234 | int32 retry = 0; |
| 235 | #endif |
| 236 | uint8 data = 0; |
| 237 | |
| 238 | if (!bcmsdh) |
| 239 | bcmsdh = l_bcmsdh; |
| 240 | |
| 241 | ASSERT(bcmsdh->init_success); |
| 242 | |
| 243 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 244 | do { |
| 245 | if (retry) /* wait for 1 ms till bus get settled down */ |
| 246 | OSL_DELAY(1000); |
| 247 | #endif |
| 248 | status = sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr, (uint8 *)&data); |
| 249 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 250 | } while (!SDIOH_API_SUCCESS(status) && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
| 251 | #endif |
| 252 | if (err) |
| 253 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 254 | |
| 255 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", __FUNCTION__, |
| 256 | fnc_num, addr, data)); |
| 257 | |
| 258 | return data; |
| 259 | } |
| 260 | |
| 261 | void |
| 262 | bcmsdh_cfg_write(void *sdh, uint fnc_num, uint32 addr, uint8 data, int *err) |
| 263 | { |
| 264 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 265 | SDIOH_API_RC status; |
| 266 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 267 | int32 retry = 0; |
| 268 | #endif |
| 269 | |
| 270 | if (!bcmsdh) |
| 271 | bcmsdh = l_bcmsdh; |
| 272 | |
| 273 | ASSERT(bcmsdh->init_success); |
| 274 | |
| 275 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 276 | do { |
| 277 | if (retry) /* wait for 1 ms till bus get settled down */ |
| 278 | OSL_DELAY(1000); |
| 279 | #endif |
| 280 | status = sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr, (uint8 *)&data); |
| 281 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 282 | } while (!SDIOH_API_SUCCESS(status) && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
| 283 | #endif |
| 284 | if (err) |
| 285 | *err = SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR; |
| 286 | |
| 287 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint8data = 0x%x\n", __FUNCTION__, |
| 288 | fnc_num, addr, data)); |
| 289 | } |
| 290 | |
| 291 | uint32 |
| 292 | bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, int *err) |
| 293 | { |
| 294 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 295 | SDIOH_API_RC status; |
| 296 | uint32 data = 0; |
| 297 | |
| 298 | if (!bcmsdh) |
| 299 | bcmsdh = l_bcmsdh; |
| 300 | |
| 301 | ASSERT(bcmsdh->init_success); |
| 302 | |
| 303 | status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_READ, fnc_num, |
| 304 | addr, &data, 4); |
| 305 | |
| 306 | if (err) |
| 307 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 308 | |
| 309 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", __FUNCTION__, |
| 310 | fnc_num, addr, data)); |
| 311 | |
| 312 | return data; |
| 313 | } |
| 314 | |
| 315 | void |
| 316 | bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, uint32 data, int *err) |
| 317 | { |
| 318 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 319 | SDIOH_API_RC status; |
| 320 | |
| 321 | if (!bcmsdh) |
| 322 | bcmsdh = l_bcmsdh; |
| 323 | |
| 324 | ASSERT(bcmsdh->init_success); |
| 325 | |
| 326 | status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_WRITE, fnc_num, |
| 327 | addr, &data, 4); |
| 328 | |
| 329 | if (err) |
| 330 | *err = (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 331 | |
| 332 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, uint32data = 0x%x\n", __FUNCTION__, fnc_num, |
| 333 | addr, data)); |
| 334 | } |
| 335 | |
| 336 | |
| 337 | int |
| 338 | bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length) |
| 339 | { |
| 340 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 341 | SDIOH_API_RC status; |
| 342 | |
| 343 | uint8 *tmp_buf, *tmp_ptr; |
| 344 | uint8 *ptr; |
| 345 | bool ascii = func & ~0xf; |
| 346 | func &= 0x7; |
| 347 | |
| 348 | if (!bcmsdh) |
| 349 | bcmsdh = l_bcmsdh; |
| 350 | |
| 351 | ASSERT(bcmsdh->init_success); |
| 352 | ASSERT(cis); |
| 353 | ASSERT(length <= SBSDIO_CIS_SIZE_LIMIT); |
| 354 | |
| 355 | status = sdioh_cis_read(bcmsdh->sdioh, func, cis, length); |
| 356 | |
| 357 | if (ascii) { |
| 358 | /* Move binary bits to tmp and format them into the provided buffer. */ |
| 359 | if ((tmp_buf = (uint8 *)MALLOC(bcmsdh->osh, length)) == NULL) { |
| 360 | BCMSDH_ERROR(("%s: out of memory\n", __FUNCTION__)); |
| 361 | return BCME_NOMEM; |
| 362 | } |
| 363 | bcopy(cis, tmp_buf, length); |
| 364 | for (tmp_ptr = tmp_buf, ptr = cis; ptr < (cis + length - 4); tmp_ptr++) { |
| 365 | ptr += sprintf((char*)ptr, "%.2x ", *tmp_ptr & 0xff); |
| 366 | if ((((tmp_ptr - tmp_buf) + 1) & 0xf) == 0) |
| 367 | ptr += sprintf((char *)ptr, "\n"); |
| 368 | } |
| 369 | MFREE(bcmsdh->osh, tmp_buf, length); |
| 370 | } |
| 371 | |
| 372 | return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR); |
| 373 | } |
| 374 | |
| 375 | |
| 376 | int |
| 377 | bcmsdhsdio_set_sbaddr_window(void *sdh, uint32 address, bool force_set) |
| 378 | { |
| 379 | int err = 0; |
| 380 | uint bar0 = address & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 381 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 382 | |
| 383 | if (bar0 != bcmsdh->sbwad || force_set) { |
| 384 | bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
| 385 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 386 | if (!err) |
| 387 | bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRMID, |
| 388 | (address >> 16) & SBSDIO_SBADDRMID_MASK, &err); |
| 389 | if (!err) |
| 390 | bcmsdh_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRHIGH, |
| 391 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, &err); |
| 392 | |
| 393 | if (!err) |
| 394 | bcmsdh->sbwad = bar0; |
| 395 | else |
| 396 | /* invalidate cached window var */ |
| 397 | bcmsdh->sbwad = 0; |
| 398 | |
| 399 | } |
| 400 | |
| 401 | return err; |
| 402 | } |
| 403 | |
| 404 | uint32 |
| 405 | bcmsdh_reg_read(void *sdh, uint32 addr, uint size) |
| 406 | { |
| 407 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 408 | SDIOH_API_RC status; |
| 409 | uint32 word = 0; |
| 410 | |
| 411 | BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, ", __FUNCTION__, addr)); |
| 412 | |
| 413 | if (!bcmsdh) |
| 414 | bcmsdh = l_bcmsdh; |
| 415 | |
| 416 | ASSERT(bcmsdh->init_success); |
| 417 | |
| 418 | if (bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE)) |
| 419 | return 0xFFFFFFFF; |
| 420 | |
| 421 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 422 | if (size == 4) |
| 423 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 424 | |
| 425 | status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
| 426 | SDIOH_READ, SDIO_FUNC_1, addr, &word, size); |
| 427 | |
| 428 | bcmsdh->regfail = !(SDIOH_API_SUCCESS(status)); |
| 429 | |
| 430 | BCMSDH_INFO(("uint32data = 0x%x\n", word)); |
| 431 | |
| 432 | /* if ok, return appropriately masked word */ |
| 433 | if (SDIOH_API_SUCCESS(status)) { |
| 434 | switch (size) { |
| 435 | case sizeof(uint8): |
| 436 | return (word & 0xff); |
| 437 | case sizeof(uint16): |
| 438 | return (word & 0xffff); |
| 439 | case sizeof(uint32): |
| 440 | return word; |
| 441 | default: |
| 442 | bcmsdh->regfail = TRUE; |
| 443 | |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | /* otherwise, bad sdio access or invalid size */ |
| 448 | BCMSDH_ERROR(("%s: error reading addr 0x%04x size %d\n", __FUNCTION__, addr, size)); |
| 449 | return 0xFFFFFFFF; |
| 450 | } |
| 451 | |
| 452 | uint32 |
| 453 | bcmsdh_reg_write(void *sdh, uint32 addr, uint size, uint32 data) |
| 454 | { |
| 455 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 456 | SDIOH_API_RC status; |
| 457 | int err = 0; |
| 458 | |
| 459 | BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n", |
| 460 | __FUNCTION__, addr, size*8, data)); |
| 461 | |
| 462 | if (!bcmsdh) |
| 463 | bcmsdh = l_bcmsdh; |
| 464 | |
| 465 | ASSERT(bcmsdh->init_success); |
| 466 | |
| 467 | if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE))) |
| 468 | return err; |
| 469 | |
| 470 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 471 | if (size == 4) |
| 472 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 473 | status = sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, SDIOH_WRITE, SDIO_FUNC_1, |
| 474 | addr, &data, size); |
| 475 | bcmsdh->regfail = !(SDIOH_API_SUCCESS(status)); |
| 476 | |
| 477 | if (SDIOH_API_SUCCESS(status)) |
| 478 | return 0; |
| 479 | |
| 480 | BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n", |
| 481 | __FUNCTION__, data, addr, size)); |
| 482 | return 0xFFFFFFFF; |
| 483 | } |
| 484 | |
| 485 | bool |
| 486 | bcmsdh_regfail(void *sdh) |
| 487 | { |
| 488 | return ((bcmsdh_info_t *)sdh)->regfail; |
| 489 | } |
| 490 | |
| 491 | int |
| 492 | bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags, |
| 493 | uint8 *buf, uint nbytes, void *pkt, |
| 494 | bcmsdh_cmplt_fn_t complete_fn, void *handle) |
| 495 | { |
| 496 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 497 | SDIOH_API_RC status; |
| 498 | uint incr_fix; |
| 499 | uint width; |
| 500 | int err = 0; |
| 501 | |
| 502 | ASSERT(bcmsdh); |
| 503 | ASSERT(bcmsdh->init_success); |
| 504 | |
| 505 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", |
| 506 | __FUNCTION__, fn, addr, nbytes)); |
| 507 | |
| 508 | /* Async not implemented yet */ |
| 509 | ASSERT(!(flags & SDIO_REQ_ASYNC)); |
| 510 | if (flags & SDIO_REQ_ASYNC) |
| 511 | return BCME_UNSUPPORTED; |
| 512 | |
| 513 | if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE))) |
| 514 | return err; |
| 515 | |
| 516 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 517 | |
| 518 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
| 519 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
| 520 | if (width == 4) |
| 521 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 522 | |
| 523 | status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix, |
| 524 | SDIOH_READ, fn, addr, width, nbytes, buf, pkt); |
| 525 | |
| 526 | return (SDIOH_API_SUCCESS(status) ? 0 : BCME_SDIO_ERROR); |
| 527 | } |
| 528 | |
| 529 | int |
| 530 | bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags, |
| 531 | uint8 *buf, uint nbytes, void *pkt, |
| 532 | bcmsdh_cmplt_fn_t complete_fn, void *handle) |
| 533 | { |
| 534 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 535 | SDIOH_API_RC status; |
| 536 | uint incr_fix; |
| 537 | uint width; |
| 538 | int err = 0; |
| 539 | |
| 540 | ASSERT(bcmsdh); |
| 541 | ASSERT(bcmsdh->init_success); |
| 542 | |
| 543 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", |
| 544 | __FUNCTION__, fn, addr, nbytes)); |
| 545 | |
| 546 | /* Async not implemented yet */ |
| 547 | ASSERT(!(flags & SDIO_REQ_ASYNC)); |
| 548 | if (flags & SDIO_REQ_ASYNC) |
| 549 | return BCME_UNSUPPORTED; |
| 550 | |
| 551 | if ((err = bcmsdhsdio_set_sbaddr_window(bcmsdh, addr, FALSE))) |
| 552 | return err; |
| 553 | |
| 554 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 555 | |
| 556 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
| 557 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
| 558 | if (width == 4) |
| 559 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 560 | |
| 561 | status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, incr_fix, |
| 562 | SDIOH_WRITE, fn, addr, width, nbytes, buf, pkt); |
| 563 | |
| 564 | return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR); |
| 565 | } |
| 566 | |
| 567 | int |
| 568 | bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes) |
| 569 | { |
| 570 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 571 | SDIOH_API_RC status; |
| 572 | |
| 573 | ASSERT(bcmsdh); |
| 574 | ASSERT(bcmsdh->init_success); |
| 575 | ASSERT((addr & SBSDIO_SBWINDOW_MASK) == 0); |
| 576 | |
| 577 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 578 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 579 | |
| 580 | status = sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, SDIOH_DATA_INC, |
| 581 | (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1, |
| 582 | addr, 4, nbytes, buf, NULL); |
| 583 | |
| 584 | return (SDIOH_API_SUCCESS(status) ? 0 : BCME_ERROR); |
| 585 | } |
| 586 | |
| 587 | int |
| 588 | bcmsdh_abort(void *sdh, uint fn) |
| 589 | { |
| 590 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 591 | |
| 592 | return sdioh_abort(bcmsdh->sdioh, fn); |
| 593 | } |
| 594 | |
| 595 | int |
| 596 | bcmsdh_start(void *sdh, int stage) |
| 597 | { |
| 598 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 599 | |
| 600 | return sdioh_start(bcmsdh->sdioh, stage); |
| 601 | } |
| 602 | |
| 603 | int |
| 604 | bcmsdh_stop(void *sdh) |
| 605 | { |
| 606 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 607 | |
| 608 | return sdioh_stop(bcmsdh->sdioh); |
| 609 | } |
| 610 | |
| 611 | int |
| 612 | bcmsdh_waitlockfree(void *sdh) |
| 613 | { |
| 614 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 615 | if (!bcmsdh) |
| 616 | bcmsdh = l_bcmsdh; |
| 617 | |
| 618 | return sdioh_waitlockfree(bcmsdh->sdioh); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | int |
| 623 | bcmsdh_query_device(void *sdh) |
| 624 | { |
| 625 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 626 | bcmsdh->vendevid = (VENDOR_BROADCOM << 16) | 0; |
| 627 | return (bcmsdh->vendevid); |
| 628 | } |
| 629 | |
| 630 | uint |
| 631 | bcmsdh_query_iofnum(void *sdh) |
| 632 | { |
| 633 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 634 | |
| 635 | if (!bcmsdh) |
| 636 | bcmsdh = l_bcmsdh; |
| 637 | |
| 638 | return (sdioh_query_iofnum(bcmsdh->sdioh)); |
| 639 | } |
| 640 | |
| 641 | int |
| 642 | bcmsdh_reset(bcmsdh_info_t *sdh) |
| 643 | { |
| 644 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 645 | |
| 646 | return sdioh_sdio_reset(bcmsdh->sdioh); |
| 647 | } |
| 648 | |
| 649 | void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh) |
| 650 | { |
| 651 | ASSERT(sdh); |
| 652 | return sdh->sdioh; |
| 653 | } |
| 654 | |
| 655 | /* Function to pass device-status bits to DHD. */ |
| 656 | uint32 |
| 657 | bcmsdh_get_dstatus(void *sdh) |
| 658 | { |
| 659 | return 0; |
| 660 | } |
| 661 | uint32 |
| 662 | bcmsdh_cur_sbwad(void *sdh) |
| 663 | { |
| 664 | bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)sdh; |
| 665 | |
| 666 | if (!bcmsdh) |
| 667 | bcmsdh = l_bcmsdh; |
| 668 | |
| 669 | return (bcmsdh->sbwad); |
| 670 | } |
| 671 | |
| 672 | void |
| 673 | bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev) |
| 674 | { |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | |
| 679 | int |
| 680 | bcmsdh_sleep(void *sdh, bool enab) |
| 681 | { |
| 682 | #ifdef SDIOH_SLEEP_ENABLED |
| 683 | bcmsdh_info_t *p = (bcmsdh_info_t *)sdh; |
| 684 | sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh); |
| 685 | |
| 686 | return sdioh_sleep(sd, enab); |
| 687 | #else |
| 688 | return BCME_UNSUPPORTED; |
| 689 | #endif |
| 690 | } |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame^] | 691 | |
| 692 | int |
| 693 | bcmsdh_gpio_init(void *sdh) |
| 694 | { |
| 695 | bcmsdh_info_t *p = (bcmsdh_info_t *)sdh; |
| 696 | sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh); |
| 697 | |
| 698 | return sdioh_gpio_init(sd); |
| 699 | } |
| 700 | |
| 701 | bool |
| 702 | bcmsdh_gpioin(void *sdh, uint32 gpio) |
| 703 | { |
| 704 | bcmsdh_info_t *p = (bcmsdh_info_t *)sdh; |
| 705 | sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh); |
| 706 | |
| 707 | return sdioh_gpioin(sd, gpio); |
| 708 | } |
| 709 | |
| 710 | int |
| 711 | bcmsdh_gpioouten(void *sdh, uint32 gpio) |
| 712 | { |
| 713 | bcmsdh_info_t *p = (bcmsdh_info_t *)sdh; |
| 714 | sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh); |
| 715 | |
| 716 | return sdioh_gpioouten(sd, gpio); |
| 717 | } |
| 718 | |
| 719 | int |
| 720 | bcmsdh_gpioout(void *sdh, uint32 gpio, bool enab) |
| 721 | { |
| 722 | bcmsdh_info_t *p = (bcmsdh_info_t *)sdh; |
| 723 | sdioh_info_t *sd = (sdioh_info_t *)(p->sdioh); |
| 724 | |
| 725 | return sdioh_gpioout(sd, gpio, enab); |
| 726 | } |