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