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