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> |
Franky Lin | 7c6100e | 2011-06-01 13:45:36 +0200 | [diff] [blame] | 21 | #include <linux/sched.h> |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 22 | |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 23 | #include <defs.h> |
| 24 | #include <brcm_hw_ids.h> |
Roland Vossen | f97e956 | 2011-06-01 13:45:52 +0200 | [diff] [blame] | 25 | #include <brcmu_utils.h> |
| 26 | #include <brcmu_wifi.h> |
Roland Vossen | cc3cea5 | 2011-06-01 13:45:59 +0200 | [diff] [blame] | 27 | #include <soc.h> |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 28 | #include "bcmsdbus.h" /* common SDIO/controller interface */ |
| 29 | #include "sbsdio.h" /* BRCM sdio device core */ |
Roland Vossen | 13f401c | 2011-05-03 11:35:52 +0200 | [diff] [blame] | 30 | #include "dngl_stats.h" |
| 31 | #include "dhd.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 32 | |
| 33 | #define SDIOH_API_ACCESS_RETRY_LIMIT 2 |
| 34 | const uint bcmsdh_msglevel = BCMSDH_ERROR_VAL; |
| 35 | |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 36 | struct brcmf_sdio { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 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 */ |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 45 | struct brcmf_sdio *l_bcmsdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 46 | |
| 47 | #if defined(OOB_INTR_ONLY) && defined(HW_OOB) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 48 | extern int brcmf_sdioh_enable_hw_oob_intr(void *sdioh, bool enable); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 49 | |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 50 | void brcmf_sdcard_enable_hw_oob_intr(struct brcmf_sdio *sdh, bool enable) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 51 | { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 52 | brcmf_sdioh_enable_hw_oob_intr(sdh->sdioh, enable); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 53 | } |
| 54 | #endif |
| 55 | |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 56 | struct brcmf_sdio *brcmf_sdcard_attach(void *cfghdl, void **regsva, uint irq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 57 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 58 | struct brcmf_sdio *bcmsdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 59 | |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 60 | bcmsdh = kzalloc(sizeof(struct brcmf_sdio), 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 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 69 | bcmsdh->sdioh = brcmf_sdioh_attach(cfghdl, irq); |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 70 | if (!bcmsdh->sdioh) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 71 | brcmf_sdcard_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 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 84 | int brcmf_sdcard_detach(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 85 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 86 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 87 | |
| 88 | if (bcmsdh != NULL) { |
| 89 | if (bcmsdh->sdioh) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 90 | brcmf_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 |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 101 | brcmf_sdcard_iovar_op(void *sdh, const char *name, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 102 | void *params, int plen, void *arg, int len, bool set) |
| 103 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 104 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 105 | return brcmf_sdioh_iovar_op(bcmsdh->sdioh, name, params, plen, arg, |
| 106 | len, set); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 109 | bool brcmf_sdcard_intr_query(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 110 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 111 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 112 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 113 | bool on; |
| 114 | |
| 115 | ASSERT(bcmsdh); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 116 | status = brcmf_sdioh_interrupt_query(bcmsdh->sdioh, &on); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 117 | if (SDIOH_API_SUCCESS(status)) |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 118 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 119 | else |
| 120 | return on; |
| 121 | } |
| 122 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 123 | int brcmf_sdcard_intr_enable(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 124 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 125 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 126 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 127 | ASSERT(bcmsdh); |
| 128 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 129 | status = brcmf_sdioh_interrupt_set(bcmsdh->sdioh, true); |
Roland Vossen | 1bc93ce | 2011-05-03 11:35:21 +0200 | [diff] [blame] | 130 | return SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 133 | int brcmf_sdcard_intr_disable(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 134 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 135 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 136 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 137 | ASSERT(bcmsdh); |
| 138 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 139 | status = brcmf_sdioh_interrupt_set(bcmsdh->sdioh, false); |
Roland Vossen | 1bc93ce | 2011-05-03 11:35:21 +0200 | [diff] [blame] | 140 | return SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 143 | int brcmf_sdcard_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 144 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 145 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 146 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 147 | ASSERT(bcmsdh); |
| 148 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 149 | status = brcmf_sdioh_interrupt_register(bcmsdh->sdioh, fn, argh); |
Roland Vossen | 1bc93ce | 2011-05-03 11:35:21 +0200 | [diff] [blame] | 150 | return SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 153 | int brcmf_sdcard_intr_dereg(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 154 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 155 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 156 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 157 | ASSERT(bcmsdh); |
| 158 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 159 | status = brcmf_sdioh_interrupt_deregister(bcmsdh->sdioh); |
Roland Vossen | 1bc93ce | 2011-05-03 11:35:21 +0200 | [diff] [blame] | 160 | return SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | #if defined(DHD_DEBUG) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 164 | bool brcmf_sdcard_intr_pending(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 165 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 166 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 167 | |
| 168 | ASSERT(sdh); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 169 | return brcmf_sdioh_interrupt_pending(bcmsdh->sdioh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 170 | } |
| 171 | #endif |
| 172 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 173 | int brcmf_sdcard_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 174 | { |
| 175 | ASSERT(sdh); |
| 176 | |
| 177 | /* don't support yet */ |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 178 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 181 | u8 brcmf_sdcard_cfg_read(void *sdh, uint fnc_num, u32 addr, int *err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 182 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 183 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 184 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 185 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 186 | s32 retry = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 187 | #endif |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 188 | u8 data = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 189 | |
| 190 | if (!bcmsdh) |
| 191 | bcmsdh = l_bcmsdh; |
| 192 | |
| 193 | ASSERT(bcmsdh->init_success); |
| 194 | |
| 195 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 196 | do { |
| 197 | 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] | 198 | udelay(1000); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 199 | #endif |
| 200 | status = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 201 | brcmf_sdioh_cfg_read(bcmsdh->sdioh, fnc_num, addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 202 | (u8 *) &data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 203 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 204 | } while (!SDIOH_API_SUCCESS(status) |
| 205 | && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
| 206 | #endif |
| 207 | if (err) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 208 | *err = (SDIOH_API_SUCCESS(status) ? 0 : -EIO); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 209 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 210 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 211 | __func__, fnc_num, addr, data)); |
| 212 | |
| 213 | return data; |
| 214 | } |
| 215 | |
| 216 | void |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 217 | brcmf_sdcard_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] | 218 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 219 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 220 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 221 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 222 | s32 retry = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 223 | #endif |
| 224 | |
| 225 | if (!bcmsdh) |
| 226 | bcmsdh = l_bcmsdh; |
| 227 | |
| 228 | ASSERT(bcmsdh->init_success); |
| 229 | |
| 230 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 231 | do { |
| 232 | 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] | 233 | udelay(1000); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 234 | #endif |
| 235 | status = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 236 | brcmf_sdioh_cfg_write(bcmsdh->sdioh, fnc_num, addr, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 237 | (u8 *) &data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 238 | #ifdef SDIOH_API_ACCESS_RETRY_LIMIT |
| 239 | } while (!SDIOH_API_SUCCESS(status) |
| 240 | && (retry++ < SDIOH_API_ACCESS_RETRY_LIMIT)); |
| 241 | #endif |
| 242 | if (err) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 243 | *err = SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 244 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 245 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, u8data = 0x%x\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 246 | __func__, fnc_num, addr, data)); |
| 247 | } |
| 248 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 249 | u32 brcmf_sdcard_cfg_read_word(void *sdh, uint fnc_num, u32 addr, int *err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 250 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 251 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 252 | int status; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 253 | u32 data = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 254 | |
| 255 | if (!bcmsdh) |
| 256 | bcmsdh = l_bcmsdh; |
| 257 | |
| 258 | ASSERT(bcmsdh->init_success); |
| 259 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 260 | status = brcmf_sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
| 261 | SDIOH_READ, fnc_num, addr, &data, 4); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 262 | |
| 263 | if (err) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 264 | *err = (SDIOH_API_SUCCESS(status) ? 0 : -EIO); |
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 |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 273 | brcmf_sdcard_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 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 276 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 277 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 278 | |
| 279 | if (!bcmsdh) |
| 280 | bcmsdh = l_bcmsdh; |
| 281 | |
| 282 | ASSERT(bcmsdh->init_success); |
| 283 | |
| 284 | status = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 285 | brcmf_sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 286 | SDIOH_WRITE, fnc_num, addr, &data, 4); |
| 287 | |
| 288 | if (err) |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 289 | *err = (SDIOH_API_SUCCESS(status) ? 0 : -EIO); |
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 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 295 | int brcmf_sdcard_cis_read(void *sdh, uint func, u8 * cis, uint length) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 296 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 297 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 298 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 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 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 312 | status = brcmf_sdioh_cis_read(bcmsdh->sdioh, func, cis, length); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 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 | 1bc93ce | 2011-05-03 11:35:21 +0200 | [diff] [blame] | 332 | return SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 335 | static int brcmf_sdcard_set_sbaddr_window(void *sdh, u32 address) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 336 | { |
| 337 | int err = 0; |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 338 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 339 | brcmf_sdcard_cfg_write(bcmsdh, SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 340 | (address >> 8) & SBSDIO_SBADDRLOW_MASK, &err); |
| 341 | if (!err) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 342 | brcmf_sdcard_cfg_write(bcmsdh, SDIO_FUNC_1, |
| 343 | SBSDIO_FUNC1_SBADDRMID, |
| 344 | (address >> 16) & SBSDIO_SBADDRMID_MASK, |
| 345 | &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 346 | if (!err) |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 347 | brcmf_sdcard_cfg_write(bcmsdh, SDIO_FUNC_1, |
| 348 | SBSDIO_FUNC1_SBADDRHIGH, |
| 349 | (address >> 24) & SBSDIO_SBADDRHIGH_MASK, |
| 350 | &err); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 351 | |
| 352 | return err; |
| 353 | } |
| 354 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 355 | u32 brcmf_sdcard_reg_read(void *sdh, u32 addr, uint size) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 356 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 357 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 358 | int status; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 359 | u32 word = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 360 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 361 | |
| 362 | BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, ", __func__, addr)); |
| 363 | |
| 364 | if (!bcmsdh) |
| 365 | bcmsdh = l_bcmsdh; |
| 366 | |
| 367 | ASSERT(bcmsdh->init_success); |
| 368 | |
| 369 | if (bar0 != bcmsdh->sbwad) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 370 | if (brcmf_sdcard_set_sbaddr_window(bcmsdh, bar0)) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 371 | return 0xFFFFFFFF; |
| 372 | |
| 373 | bcmsdh->sbwad = bar0; |
| 374 | } |
| 375 | |
| 376 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 377 | if (size == 4) |
| 378 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 379 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 380 | status = brcmf_sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 381 | SDIOH_READ, SDIO_FUNC_1, addr, &word, size); |
| 382 | |
| 383 | bcmsdh->regfail = !(SDIOH_API_SUCCESS(status)); |
| 384 | |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 385 | BCMSDH_INFO(("u32data = 0x%x\n", word)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 386 | |
| 387 | /* if ok, return appropriately masked word */ |
| 388 | if (SDIOH_API_SUCCESS(status)) { |
| 389 | switch (size) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 390 | case sizeof(u8): |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 391 | return word & 0xff; |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 392 | case sizeof(u16): |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 393 | return word & 0xffff; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 394 | case sizeof(u32): |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 395 | return word; |
| 396 | default: |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 397 | bcmsdh->regfail = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 398 | |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | /* otherwise, bad sdio access or invalid size */ |
| 403 | BCMSDH_ERROR(("%s: error reading addr 0x%04x size %d\n", __func__, |
| 404 | addr, size)); |
| 405 | return 0xFFFFFFFF; |
| 406 | } |
| 407 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 408 | u32 brcmf_sdcard_reg_write(void *sdh, u32 addr, uint size, u32 data) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 409 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 410 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 411 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 412 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 413 | int err = 0; |
| 414 | |
| 415 | BCMSDH_INFO(("%s:fun = 1, addr = 0x%x, uint%ddata = 0x%x\n", |
| 416 | __func__, addr, size * 8, data)); |
| 417 | |
| 418 | if (!bcmsdh) |
| 419 | bcmsdh = l_bcmsdh; |
| 420 | |
| 421 | ASSERT(bcmsdh->init_success); |
| 422 | |
| 423 | if (bar0 != bcmsdh->sbwad) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 424 | err = brcmf_sdcard_set_sbaddr_window(bcmsdh, bar0); |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 425 | if (err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 426 | return err; |
| 427 | |
| 428 | bcmsdh->sbwad = bar0; |
| 429 | } |
| 430 | |
| 431 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 432 | if (size == 4) |
| 433 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 434 | status = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 435 | brcmf_sdioh_request_word(bcmsdh->sdioh, SDIOH_CMD_TYPE_NORMAL, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 436 | SDIOH_WRITE, SDIO_FUNC_1, addr, &data, size); |
| 437 | bcmsdh->regfail = !(SDIOH_API_SUCCESS(status)); |
| 438 | |
| 439 | if (SDIOH_API_SUCCESS(status)) |
| 440 | return 0; |
| 441 | |
| 442 | BCMSDH_ERROR(("%s: error writing 0x%08x to addr 0x%04x size %d\n", |
| 443 | __func__, data, addr, size)); |
| 444 | return 0xFFFFFFFF; |
| 445 | } |
| 446 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 447 | bool brcmf_sdcard_regfail(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 448 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 449 | return ((struct brcmf_sdio *) sdh)->regfail; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | int |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 453 | brcmf_sdcard_recv_buf(struct brcmf_sdio *bcmsdh, u32 addr, uint fn, uint flags, |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 454 | u8 *buf, uint nbytes, struct sk_buff *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 455 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 456 | { |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 457 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 458 | uint incr_fix; |
| 459 | uint width; |
| 460 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 461 | int err = 0; |
| 462 | |
| 463 | ASSERT(bcmsdh); |
| 464 | ASSERT(bcmsdh->init_success); |
| 465 | |
| 466 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", |
| 467 | __func__, fn, addr, nbytes)); |
| 468 | |
| 469 | /* Async not implemented yet */ |
| 470 | ASSERT(!(flags & SDIO_REQ_ASYNC)); |
| 471 | if (flags & SDIO_REQ_ASYNC) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 472 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 473 | |
| 474 | if (bar0 != bcmsdh->sbwad) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 475 | err = brcmf_sdcard_set_sbaddr_window(bcmsdh, bar0); |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 476 | if (err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 477 | return err; |
| 478 | |
| 479 | bcmsdh->sbwad = bar0; |
| 480 | } |
| 481 | |
| 482 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 483 | |
| 484 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
| 485 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
| 486 | if (width == 4) |
| 487 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 488 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 489 | status = brcmf_sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, |
| 490 | incr_fix, SDIOH_READ, fn, addr, width, nbytes, buf, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 491 | |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 492 | return SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | int |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 496 | brcmf_sdcard_send_buf(void *sdh, u32 addr, uint fn, uint flags, |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 497 | u8 *buf, uint nbytes, void *pkt, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 498 | bcmsdh_cmplt_fn_t complete, void *handle) |
| 499 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 500 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 501 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 502 | uint incr_fix; |
| 503 | uint width; |
| 504 | uint bar0 = addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 505 | int err = 0; |
| 506 | |
| 507 | ASSERT(bcmsdh); |
| 508 | ASSERT(bcmsdh->init_success); |
| 509 | |
| 510 | BCMSDH_INFO(("%s:fun = %d, addr = 0x%x, size = %d\n", |
| 511 | __func__, fn, addr, nbytes)); |
| 512 | |
| 513 | /* Async not implemented yet */ |
| 514 | ASSERT(!(flags & SDIO_REQ_ASYNC)); |
| 515 | if (flags & SDIO_REQ_ASYNC) |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 516 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 517 | |
| 518 | if (bar0 != bcmsdh->sbwad) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 519 | err = brcmf_sdcard_set_sbaddr_window(bcmsdh, bar0); |
Jason Cooper | c74c95c | 2010-09-30 15:15:35 -0400 | [diff] [blame] | 520 | if (err) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 521 | return err; |
| 522 | |
| 523 | bcmsdh->sbwad = bar0; |
| 524 | } |
| 525 | |
| 526 | addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 527 | |
| 528 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
| 529 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
| 530 | if (width == 4) |
| 531 | addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 532 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 533 | status = brcmf_sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, |
| 534 | incr_fix, SDIOH_WRITE, fn, addr, width, nbytes, buf, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 535 | |
Roland Vossen | 1bc93ce | 2011-05-03 11:35:21 +0200 | [diff] [blame] | 536 | return SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 539 | int brcmf_sdcard_rwdata(void *sdh, uint rw, u32 addr, u8 *buf, uint nbytes) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 540 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 541 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame^] | 542 | int status; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 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 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 551 | status = brcmf_sdioh_request_buffer(bcmsdh->sdioh, SDIOH_DATA_PIO, |
| 552 | SDIOH_DATA_INC, (rw ? SDIOH_WRITE : SDIOH_READ), SDIO_FUNC_1, |
| 553 | addr, 4, nbytes, buf, NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 554 | |
Roland Vossen | 1bc93ce | 2011-05-03 11:35:21 +0200 | [diff] [blame] | 555 | return SDIOH_API_SUCCESS(status) ? 0 : -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 558 | int brcmf_sdcard_abort(void *sdh, uint fn) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 559 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 560 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 561 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 562 | return brcmf_sdioh_abort(bcmsdh->sdioh, fn); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 565 | int brcmf_sdcard_start(void *sdh, int stage) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 566 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 567 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 568 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 569 | return brcmf_sdioh_start(bcmsdh->sdioh, stage); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 572 | int brcmf_sdcard_stop(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 573 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 574 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 575 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 576 | return brcmf_sdioh_stop(bcmsdh->sdioh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 579 | int brcmf_sdcard_query_device(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 580 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 581 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Stanislav Fomichev | be1c09f | 2011-03-28 01:31:36 +0400 | [diff] [blame] | 582 | bcmsdh->vendevid = (PCI_VENDOR_ID_BROADCOM << 16) | 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 583 | return bcmsdh->vendevid; |
| 584 | } |
| 585 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 586 | uint brcmf_sdcard_query_iofnum(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 587 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 588 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 589 | |
| 590 | if (!bcmsdh) |
| 591 | bcmsdh = l_bcmsdh; |
| 592 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 593 | return brcmf_sdioh_query_iofnum(bcmsdh->sdioh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 596 | int brcmf_sdcard_reset(struct brcmf_sdio *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 597 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 598 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 599 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 600 | return brcmf_sdioh_reset(bcmsdh->sdioh); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 603 | void *brcmf_sdcard_get_sdioh(struct brcmf_sdio *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 604 | { |
| 605 | ASSERT(sdh); |
| 606 | return sdh->sdioh; |
| 607 | } |
| 608 | |
| 609 | /* Function to pass device-status bits to DHD. */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 610 | u32 brcmf_sdcard_get_dstatus(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 611 | { |
| 612 | return 0; |
| 613 | } |
| 614 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 615 | u32 brcmf_sdcard_cur_sbwad(void *sdh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 616 | { |
Roland Vossen | 677226a | 2011-06-29 16:47:21 -0700 | [diff] [blame] | 617 | struct brcmf_sdio *bcmsdh = (struct brcmf_sdio *) sdh; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 618 | |
| 619 | if (!bcmsdh) |
| 620 | bcmsdh = l_bcmsdh; |
| 621 | |
| 622 | return bcmsdh->sbwad; |
| 623 | } |
| 624 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 625 | void brcmf_sdcard_chipinfo(void *sdh, u32 chip, u32 chiprev) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 626 | { |
| 627 | return; |
| 628 | } |