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 | */ |
Greg Kroah-Hartman | a1c16ed | 2010-10-21 11:17:44 -0700 | [diff] [blame] | 16 | #include <linux/types.h> |
Brett Rudley | c6ac24e | 2010-10-26 11:55:23 -0700 | [diff] [blame] | 17 | #include <linux/netdevice.h> |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 18 | #include <linux/mmc/sdio.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 19 | #include <linux/mmc/core.h> |
| 20 | #include <linux/mmc/sdio_func.h> |
| 21 | #include <linux/mmc/sdio_ids.h> |
Sukesh Srikakula | e6e8f89 | 2011-05-13 11:59:39 +0200 | [diff] [blame] | 22 | #include <linux/suspend.h> |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 23 | #include <linux/errno.h> |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 24 | |
Roland Vossen | c4daa84 | 2011-06-09 16:44:50 +0200 | [diff] [blame] | 25 | #include <defs.h> |
| 26 | #include <brcm_hw_ids.h> |
| 27 | #include <brcmu_utils.h> |
| 28 | #include <brcmu_wifi.h> |
| 29 | #include "sdio_host.h" |
| 30 | #include "bcmsdbus.h" /* bcmsdh to/from specific controller APIs */ |
| 31 | #include "sdiovar.h" /* ioctl/iovars */ |
| 32 | #include "dngl_stats.h" |
| 33 | #include "dhd.h" |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 34 | #include "bcmsdh_sdmmc.h" |
| 35 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 36 | static void brcmf_sdioh_irqhandler(struct sdio_func *func); |
| 37 | static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func); |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 38 | static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 39 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 40 | uint sd_f2_blocksize = 512; /* Default blocksize */ |
| 41 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 42 | uint sd_msglevel = 0x01; |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 43 | BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_byte_wait); |
| 44 | BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_word_wait); |
| 45 | BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_packet_wait); |
| 46 | BRCMF_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 47 | |
| 48 | #define DMA_ALIGN_MASK 0x03 |
| 49 | |
Roland Vossen | b9a7429 | 2011-06-29 16:47:57 -0700 | [diff] [blame] | 50 | static int |
| 51 | brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr, |
| 52 | int regsize, u32 *data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 53 | |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 54 | static int brcmf_sdioh_enablefuncs(struct sdioh_info *sd) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 55 | { |
| 56 | int err_ret; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 57 | u32 fbraddr; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 58 | u8 func; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 59 | |
| 60 | sd_trace(("%s\n", __func__)); |
| 61 | |
| 62 | /* Get the Card's common CIS address */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 63 | sd->com_cis_ptr = brcmf_sdioh_get_cisaddr(sd, SDIO_CCCR_CIS); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 64 | sd->func_cis_ptr[0] = sd->com_cis_ptr; |
| 65 | sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__, |
| 66 | sd->com_cis_ptr)); |
| 67 | |
| 68 | /* Get the Card's function CIS (for each function) */ |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 69 | for (fbraddr = SDIO_FBR_BASE(1), func = 1; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 70 | func <= sd->num_funcs; func++, fbraddr += SDIOD_FBR_SIZE) { |
| 71 | sd->func_cis_ptr[func] = |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 72 | brcmf_sdioh_get_cisaddr(sd, SDIO_FBR_CIS + fbraddr); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 73 | sd_info(("%s: Function %d CIS Ptr = 0x%x\n", __func__, func, |
| 74 | sd->func_cis_ptr[func])); |
| 75 | } |
| 76 | |
| 77 | sd->func_cis_ptr[0] = sd->com_cis_ptr; |
| 78 | sd_info(("%s: Card's Common CIS Ptr = 0x%x\n", __func__, |
| 79 | sd->com_cis_ptr)); |
| 80 | |
| 81 | /* Enable Function 1 */ |
| 82 | sdio_claim_host(gInstance->func[1]); |
| 83 | err_ret = sdio_enable_func(gInstance->func[1]); |
| 84 | sdio_release_host(gInstance->func[1]); |
| 85 | if (err_ret) { |
| 86 | sd_err(("bcmsdh_sdmmc: Failed to enable F1 Err: 0x%08x", |
| 87 | err_ret)); |
| 88 | } |
| 89 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 90 | return false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Public entry points & extern's |
| 95 | */ |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 96 | struct sdioh_info *brcmf_sdioh_attach(void *bar0, uint irq) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 97 | { |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 98 | struct sdioh_info *sd; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 99 | int err_ret; |
| 100 | |
| 101 | sd_trace(("%s\n", __func__)); |
| 102 | |
| 103 | if (gInstance == NULL) { |
| 104 | sd_err(("%s: SDIO Device not present\n", __func__)); |
| 105 | return NULL; |
| 106 | } |
| 107 | |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 108 | sd = kzalloc(sizeof(struct sdioh_info), GFP_ATOMIC); |
Jason Cooper | a1b04b0 | 2010-09-30 15:15:37 -0400 | [diff] [blame] | 109 | if (sd == NULL) { |
mike.rapoport@gmail.com | 97e17d0 | 2010-10-13 00:09:09 +0200 | [diff] [blame] | 110 | sd_err(("sdioh_attach: out of memory\n")); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 111 | return NULL; |
| 112 | } |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 113 | if (brcmf_sdioh_osinit(sd) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 114 | sd_err(("%s:sdioh_sdmmc_osinit() failed\n", __func__)); |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 115 | kfree(sd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 116 | return NULL; |
| 117 | } |
| 118 | |
| 119 | sd->num_funcs = 2; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 120 | sd->use_client_ints = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 121 | sd->client_block_size[0] = 64; |
| 122 | |
| 123 | gInstance->sd = sd; |
| 124 | |
| 125 | /* Claim host controller */ |
| 126 | sdio_claim_host(gInstance->func[1]); |
| 127 | |
| 128 | sd->client_block_size[1] = 64; |
| 129 | err_ret = sdio_set_block_size(gInstance->func[1], 64); |
| 130 | if (err_ret) |
| 131 | sd_err(("bcmsdh_sdmmc: Failed to set F1 blocksize\n")); |
| 132 | |
| 133 | /* Release host controller F1 */ |
| 134 | sdio_release_host(gInstance->func[1]); |
| 135 | |
| 136 | if (gInstance->func[2]) { |
| 137 | /* Claim host controller F2 */ |
| 138 | sdio_claim_host(gInstance->func[2]); |
| 139 | |
| 140 | sd->client_block_size[2] = sd_f2_blocksize; |
| 141 | err_ret = |
| 142 | sdio_set_block_size(gInstance->func[2], sd_f2_blocksize); |
| 143 | if (err_ret) |
| 144 | sd_err(("bcmsdh_sdmmc: Failed to set F2 blocksize " |
| 145 | "to %d\n", sd_f2_blocksize)); |
| 146 | |
| 147 | /* Release host controller F2 */ |
| 148 | sdio_release_host(gInstance->func[2]); |
| 149 | } |
| 150 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 151 | brcmf_sdioh_enablefuncs(sd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 152 | |
| 153 | sd_trace(("%s: Done\n", __func__)); |
| 154 | return sd; |
| 155 | } |
| 156 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 157 | extern int brcmf_sdioh_detach(struct sdioh_info *sd) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 158 | { |
| 159 | sd_trace(("%s\n", __func__)); |
| 160 | |
| 161 | if (sd) { |
| 162 | |
| 163 | /* Disable Function 2 */ |
| 164 | sdio_claim_host(gInstance->func[2]); |
| 165 | sdio_disable_func(gInstance->func[2]); |
| 166 | sdio_release_host(gInstance->func[2]); |
| 167 | |
| 168 | /* Disable Function 1 */ |
| 169 | sdio_claim_host(gInstance->func[1]); |
| 170 | sdio_disable_func(gInstance->func[1]); |
| 171 | sdio_release_host(gInstance->func[1]); |
| 172 | |
| 173 | /* deregister irq */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 174 | brcmf_sdioh_osfree(sd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 175 | |
mike.rapoport@gmail.com | 182acb3 | 2010-10-13 00:09:12 +0200 | [diff] [blame] | 176 | kfree(sd); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 177 | } |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 178 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Peter Huewe | b3b97f5 | 2011-03-26 02:17:52 +0100 | [diff] [blame] | 181 | /* Configure callback to client when we receive client interrupt */ |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 182 | extern int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 183 | brcmf_sdioh_interrupt_register(struct sdioh_info *sd, sdioh_cb_fn_t fn, |
| 184 | void *argh) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 185 | { |
| 186 | sd_trace(("%s: Entering\n", __func__)); |
| 187 | if (fn == NULL) { |
| 188 | sd_err(("%s: interrupt handler is NULL, not registering\n", |
| 189 | __func__)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 190 | return -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 191 | } |
Arend van Spriel | 67a646f | 2011-06-29 16:47:38 -0700 | [diff] [blame] | 192 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 193 | sd->intr_handler = fn; |
| 194 | sd->intr_handler_arg = argh; |
Greg Kroah-Hartman | 0f0881b | 2010-10-12 12:15:18 -0700 | [diff] [blame] | 195 | sd->intr_handler_valid = true; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 196 | |
| 197 | /* register and unmask irq */ |
| 198 | if (gInstance->func[2]) { |
| 199 | sdio_claim_host(gInstance->func[2]); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 200 | sdio_claim_irq(gInstance->func[2], brcmf_sdioh_irqhandler_f2); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 201 | sdio_release_host(gInstance->func[2]); |
| 202 | } |
| 203 | |
| 204 | if (gInstance->func[1]) { |
| 205 | sdio_claim_host(gInstance->func[1]); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 206 | sdio_claim_irq(gInstance->func[1], brcmf_sdioh_irqhandler); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 207 | sdio_release_host(gInstance->func[1]); |
| 208 | } |
Arend van Spriel | 67a646f | 2011-06-29 16:47:38 -0700 | [diff] [blame] | 209 | |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 210 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 213 | extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *sd) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 214 | { |
| 215 | sd_trace(("%s: Entering\n", __func__)); |
| 216 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 217 | if (gInstance->func[1]) { |
| 218 | /* register and unmask irq */ |
| 219 | sdio_claim_host(gInstance->func[1]); |
| 220 | sdio_release_irq(gInstance->func[1]); |
| 221 | sdio_release_host(gInstance->func[1]); |
| 222 | } |
| 223 | |
| 224 | if (gInstance->func[2]) { |
| 225 | /* Claim host controller F2 */ |
| 226 | sdio_claim_host(gInstance->func[2]); |
| 227 | sdio_release_irq(gInstance->func[2]); |
| 228 | /* Release host controller F2 */ |
| 229 | sdio_release_host(gInstance->func[2]); |
| 230 | } |
| 231 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 232 | sd->intr_handler_valid = false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 233 | sd->intr_handler = NULL; |
| 234 | sd->intr_handler_arg = NULL; |
Arend van Spriel | 67a646f | 2011-06-29 16:47:38 -0700 | [diff] [blame] | 235 | |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 236 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 239 | extern int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 240 | brcmf_sdioh_interrupt_query(struct sdioh_info *sd, bool *onoff) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 241 | { |
| 242 | sd_trace(("%s: Entering\n", __func__)); |
| 243 | *onoff = sd->client_intr_enabled; |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 244 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Arend van Spriel | 762c2a3 | 2011-06-29 16:47:35 -0700 | [diff] [blame] | 247 | #if defined(BCMDBG) |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 248 | extern bool brcmf_sdioh_interrupt_pending(struct sdioh_info *sd) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 249 | { |
| 250 | return 0; |
| 251 | } |
| 252 | #endif |
| 253 | |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 254 | uint brcmf_sdioh_query_iofnum(struct sdioh_info *sd) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 255 | { |
| 256 | return sd->num_funcs; |
| 257 | } |
| 258 | |
| 259 | /* IOVar table */ |
| 260 | enum { |
| 261 | IOV_MSGLEVEL = 1, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 262 | IOV_BLOCKSIZE, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 263 | IOV_USEINTS, |
| 264 | IOV_NUMINTS, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 265 | IOV_DEVREG, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 266 | IOV_HCIREGS, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 267 | IOV_RXCHAIN |
| 268 | }; |
| 269 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 270 | const struct brcmu_iovar sdioh_iovars[] = { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 271 | {"sd_msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0}, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 272 | {"sd_blocksize", IOV_BLOCKSIZE, 0, IOVT_UINT32, 0},/* ((fn << 16) | |
| 273 | size) */ |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 274 | {"sd_ints", IOV_USEINTS, 0, IOVT_BOOL, 0}, |
| 275 | {"sd_numints", IOV_NUMINTS, 0, IOVT_UINT32, 0}, |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 276 | {"sd_devreg", IOV_DEVREG, 0, IOVT_BUFFER, sizeof(struct brcmf_sdreg)} |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 277 | , |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 278 | {"sd_rxchain", IOV_RXCHAIN, 0, IOVT_BOOL, 0} |
| 279 | , |
| 280 | {NULL, 0, 0, 0, 0} |
| 281 | }; |
| 282 | |
| 283 | int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 284 | brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 285 | void *params, int plen, void *arg, int len, bool set) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 286 | { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 287 | const struct brcmu_iovar *vi = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 288 | int bcmerror = 0; |
| 289 | int val_size; |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 290 | s32 int_val = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 291 | bool bool_val; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 292 | u32 actionid; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 293 | |
| 294 | ASSERT(name); |
| 295 | ASSERT(len >= 0); |
| 296 | |
| 297 | /* Get must have return space; Set does not take qualifiers */ |
| 298 | ASSERT(set || (arg && len)); |
| 299 | ASSERT(!set || (!params && !plen)); |
| 300 | |
| 301 | sd_trace(("%s: Enter (%s %s)\n", __func__, (set ? "set" : "get"), |
| 302 | name)); |
| 303 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 304 | vi = brcmu_iovar_lookup(sdioh_iovars, name); |
Jason Cooper | a1b04b0 | 2010-09-30 15:15:37 -0400 | [diff] [blame] | 305 | if (vi == NULL) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 306 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 307 | goto exit; |
| 308 | } |
| 309 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 310 | bcmerror = brcmu_iovar_lencheck(vi, arg, len, set); |
Jason Cooper | a1b04b0 | 2010-09-30 15:15:37 -0400 | [diff] [blame] | 311 | if (bcmerror != 0) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 312 | goto exit; |
| 313 | |
| 314 | /* Set up params so get and set can share the convenience variables */ |
| 315 | if (params == NULL) { |
| 316 | params = arg; |
| 317 | plen = len; |
| 318 | } |
| 319 | |
| 320 | if (vi->type == IOVT_VOID) |
| 321 | val_size = 0; |
| 322 | else if (vi->type == IOVT_BUFFER) |
| 323 | val_size = len; |
| 324 | else |
| 325 | val_size = sizeof(int); |
| 326 | |
| 327 | if (plen >= (int)sizeof(int_val)) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 328 | memcpy(&int_val, params, sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 329 | |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 330 | bool_val = (int_val != 0) ? true : false; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 331 | |
| 332 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); |
| 333 | switch (actionid) { |
| 334 | case IOV_GVAL(IOV_MSGLEVEL): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 335 | int_val = (s32) sd_msglevel; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 336 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 337 | break; |
| 338 | |
| 339 | case IOV_SVAL(IOV_MSGLEVEL): |
| 340 | sd_msglevel = int_val; |
| 341 | break; |
| 342 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 343 | case IOV_GVAL(IOV_BLOCKSIZE): |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 344 | if ((u32) int_val > si->num_funcs) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 345 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 346 | break; |
| 347 | } |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 348 | int_val = (s32) si->client_block_size[int_val]; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 349 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 350 | break; |
| 351 | |
| 352 | case IOV_SVAL(IOV_BLOCKSIZE): |
| 353 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 354 | uint func = ((u32) int_val >> 16); |
Greg Kroah-Hartman | 7d4df48 | 2010-10-07 17:04:47 -0700 | [diff] [blame] | 355 | uint blksize = (u16) int_val; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 356 | uint maxsize; |
| 357 | |
| 358 | if (func > si->num_funcs) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 359 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 360 | break; |
| 361 | } |
| 362 | |
| 363 | switch (func) { |
| 364 | case 0: |
| 365 | maxsize = 32; |
| 366 | break; |
| 367 | case 1: |
| 368 | maxsize = BLOCK_SIZE_4318; |
| 369 | break; |
| 370 | case 2: |
| 371 | maxsize = BLOCK_SIZE_4328; |
| 372 | break; |
| 373 | default: |
| 374 | maxsize = 0; |
| 375 | } |
| 376 | if (blksize > maxsize) { |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 377 | bcmerror = -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 378 | break; |
| 379 | } |
| 380 | if (!blksize) |
| 381 | blksize = maxsize; |
| 382 | |
| 383 | /* Now set it */ |
| 384 | si->client_block_size[func] = blksize; |
| 385 | |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | case IOV_GVAL(IOV_RXCHAIN): |
Greg Kroah-Hartman | 0965ae8 | 2010-10-12 12:50:15 -0700 | [diff] [blame] | 390 | int_val = false; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 391 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 392 | break; |
| 393 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 394 | case IOV_GVAL(IOV_USEINTS): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 395 | int_val = (s32) si->use_client_ints; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 396 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 397 | break; |
| 398 | |
| 399 | case IOV_SVAL(IOV_USEINTS): |
| 400 | si->use_client_ints = (bool) int_val; |
| 401 | if (si->use_client_ints) |
| 402 | si->intmask |= CLIENT_INTR; |
| 403 | else |
| 404 | si->intmask &= ~CLIENT_INTR; |
| 405 | |
| 406 | break; |
| 407 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 408 | case IOV_GVAL(IOV_NUMINTS): |
Greg Kroah-Hartman | 3e26416 | 2010-10-08 11:11:13 -0700 | [diff] [blame] | 409 | int_val = (s32) si->intrcount; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 410 | memcpy(arg, &int_val, val_size); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 411 | break; |
| 412 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 413 | case IOV_GVAL(IOV_DEVREG): |
| 414 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 415 | struct brcmf_sdreg *sd_ptr = |
| 416 | (struct brcmf_sdreg *) params; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 417 | u8 data = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 418 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 419 | if (brcmf_sdioh_cfg_read |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 420 | (si, sd_ptr->func, sd_ptr->offset, &data)) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 421 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 422 | break; |
| 423 | } |
| 424 | |
| 425 | int_val = (int)data; |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 426 | memcpy(arg, &int_val, sizeof(int_val)); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 427 | break; |
| 428 | } |
| 429 | |
| 430 | case IOV_SVAL(IOV_DEVREG): |
| 431 | { |
Roland Vossen | 5185125 | 2011-06-29 16:47:24 -0700 | [diff] [blame] | 432 | struct brcmf_sdreg *sd_ptr = |
| 433 | (struct brcmf_sdreg *) params; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 434 | u8 data = (u8) sd_ptr->value; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 435 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 436 | if (brcmf_sdioh_cfg_write |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 437 | (si, sd_ptr->func, sd_ptr->offset, &data)) { |
Roland Vossen | b74ac12 | 2011-05-03 11:35:20 +0200 | [diff] [blame] | 438 | bcmerror = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 439 | break; |
| 440 | } |
| 441 | break; |
| 442 | } |
| 443 | |
| 444 | default: |
Roland Vossen | e10d82d | 2011-05-03 11:35:19 +0200 | [diff] [blame] | 445 | bcmerror = -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 446 | break; |
| 447 | } |
| 448 | exit: |
| 449 | |
| 450 | return bcmerror; |
| 451 | } |
| 452 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 453 | extern int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 454 | brcmf_sdioh_cfg_read(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 455 | { |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 456 | int status; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 457 | /* No lock needed since brcmf_sdioh_request_byte does locking */ |
| 458 | status = brcmf_sdioh_request_byte(sd, SDIOH_READ, fnc_num, addr, data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 459 | return status; |
| 460 | } |
| 461 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 462 | extern int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 463 | brcmf_sdioh_cfg_write(struct sdioh_info *sd, uint fnc_num, u32 addr, u8 *data) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 464 | { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 465 | /* No lock needed since brcmf_sdioh_request_byte does locking */ |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 466 | int status; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 467 | status = brcmf_sdioh_request_byte(sd, SDIOH_WRITE, fnc_num, addr, data); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 468 | return status; |
| 469 | } |
| 470 | |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 471 | static int brcmf_sdioh_get_cisaddr(struct sdioh_info *sd, u32 regaddr) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 472 | { |
| 473 | /* read 24 bits and return valid 17 bit addr */ |
| 474 | int i; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 475 | u32 scratch, regdata; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 476 | u8 *ptr = (u8 *)&scratch; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 477 | for (i = 0; i < 3; i++) { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 478 | if ((brcmf_sdioh_card_regread(sd, 0, regaddr, 1, ®data)) != |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 479 | SUCCESS) |
| 480 | sd_err(("%s: Can't read!\n", __func__)); |
| 481 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 482 | *ptr++ = (u8) regdata; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 483 | regaddr++; |
| 484 | } |
| 485 | |
| 486 | /* Only the lower 17-bits are valid */ |
Stanislav Fomichev | 628f10b | 2011-02-20 21:43:32 +0300 | [diff] [blame] | 487 | scratch = le32_to_cpu(scratch); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 488 | scratch &= 0x0001FFFF; |
| 489 | return scratch; |
| 490 | } |
| 491 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 492 | extern int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 493 | brcmf_sdioh_cis_read(struct sdioh_info *sd, uint func, u8 *cisd, u32 length) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 494 | { |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 495 | u32 count; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 496 | int offset; |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 497 | u32 foo; |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 498 | u8 *cis = cisd; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 499 | |
| 500 | sd_trace(("%s: Func = %d\n", __func__, func)); |
| 501 | |
| 502 | if (!sd->func_cis_ptr[func]) { |
Brett Rudley | 9249ede | 2010-11-30 20:09:49 -0800 | [diff] [blame] | 503 | memset(cis, 0, length); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 504 | sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 505 | return -ENOTSUPP; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | sd_err(("%s: func_cis_ptr[%d]=0x%04x\n", __func__, func, |
| 509 | sd->func_cis_ptr[func])); |
| 510 | |
| 511 | for (count = 0; count < length; count++) { |
| 512 | offset = sd->func_cis_ptr[func] + count; |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 513 | if (brcmf_sdioh_card_regread(sd, 0, offset, 1, &foo) < 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 514 | sd_err(("%s: regread failed: Can't read CIS\n", |
| 515 | __func__)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 516 | return -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 519 | *cis = (u8) (foo & 0xff); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 520 | cis++; |
| 521 | } |
| 522 | |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 523 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 526 | extern int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 527 | brcmf_sdioh_request_byte(struct sdioh_info *sd, uint rw, uint func, |
| 528 | uint regaddr, u8 *byte) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 529 | { |
| 530 | int err_ret; |
| 531 | |
| 532 | sd_info(("%s: rw=%d, func=%d, addr=0x%05x\n", __func__, rw, func, |
| 533 | regaddr)); |
| 534 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 535 | BRCMF_PM_RESUME_WAIT(sdioh_request_byte_wait); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 536 | BRCMF_PM_RESUME_RETURN_ERROR(-EIO); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 537 | if (rw) { /* CMD52 Write */ |
| 538 | if (func == 0) { |
| 539 | /* Can only directly write to some F0 registers. |
| 540 | * Handle F2 enable |
| 541 | * as a special case. |
| 542 | */ |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 543 | if (regaddr == SDIO_CCCR_IOEx) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 544 | if (gInstance->func[2]) { |
| 545 | sdio_claim_host(gInstance->func[2]); |
| 546 | if (*byte & SDIO_FUNC_ENABLE_2) { |
| 547 | /* Enable Function 2 */ |
| 548 | err_ret = |
| 549 | sdio_enable_func |
| 550 | (gInstance->func[2]); |
| 551 | if (err_ret) |
| 552 | sd_err(("bcmsdh_sdmmc: enable F2 failed:%d", |
| 553 | err_ret)); |
| 554 | } else { |
| 555 | /* Disable Function 2 */ |
| 556 | err_ret = |
| 557 | sdio_disable_func |
| 558 | (gInstance->func[2]); |
| 559 | if (err_ret) |
| 560 | sd_err(("bcmsdh_sdmmc: Disab F2 failed:%d", |
| 561 | err_ret)); |
| 562 | } |
| 563 | sdio_release_host(gInstance->func[2]); |
| 564 | } |
| 565 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 566 | /* to allow abort command through F1 */ |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 567 | else if (regaddr == SDIO_CCCR_ABORT) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 568 | sdio_claim_host(gInstance->func[func]); |
| 569 | /* |
| 570 | * this sdio_f0_writeb() can be replaced |
| 571 | * with another api |
| 572 | * depending upon MMC driver change. |
| 573 | * As of this time, this is temporaray one |
| 574 | */ |
| 575 | sdio_writeb(gInstance->func[func], *byte, |
| 576 | regaddr, &err_ret); |
| 577 | sdio_release_host(gInstance->func[func]); |
| 578 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 579 | else if (regaddr < 0xF0) { |
| 580 | sd_err(("bcmsdh_sdmmc: F0 Wr:0x%02x: write " |
| 581 | "disallowed\n", regaddr)); |
| 582 | } else { |
| 583 | /* Claim host controller, perform F0 write, |
| 584 | and release */ |
| 585 | sdio_claim_host(gInstance->func[func]); |
| 586 | sdio_f0_writeb(gInstance->func[func], *byte, |
| 587 | regaddr, &err_ret); |
| 588 | sdio_release_host(gInstance->func[func]); |
| 589 | } |
| 590 | } else { |
| 591 | /* Claim host controller, perform Fn write, |
| 592 | and release */ |
| 593 | sdio_claim_host(gInstance->func[func]); |
| 594 | sdio_writeb(gInstance->func[func], *byte, regaddr, |
| 595 | &err_ret); |
| 596 | sdio_release_host(gInstance->func[func]); |
| 597 | } |
| 598 | } else { /* CMD52 Read */ |
| 599 | /* Claim host controller, perform Fn read, and release */ |
| 600 | sdio_claim_host(gInstance->func[func]); |
| 601 | |
| 602 | if (func == 0) { |
| 603 | *byte = |
| 604 | sdio_f0_readb(gInstance->func[func], regaddr, |
| 605 | &err_ret); |
| 606 | } else { |
| 607 | *byte = |
| 608 | sdio_readb(gInstance->func[func], regaddr, |
| 609 | &err_ret); |
| 610 | } |
| 611 | |
| 612 | sdio_release_host(gInstance->func[func]); |
| 613 | } |
| 614 | |
| 615 | if (err_ret) |
| 616 | sd_err(("bcmsdh_sdmmc: Failed to %s byte F%d:@0x%05x=%02x, " |
| 617 | "Err: %d\n", rw ? "Write" : "Read", func, regaddr, |
| 618 | *byte, err_ret)); |
| 619 | |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 620 | return err_ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 623 | extern int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 624 | brcmf_sdioh_request_word(struct sdioh_info *sd, uint cmd_type, uint rw, |
| 625 | uint func, uint addr, u32 *word, uint nbytes) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 626 | { |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 627 | int err_ret = -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 628 | |
| 629 | if (func == 0) { |
| 630 | sd_err(("%s: Only CMD52 allowed to F0.\n", __func__)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 631 | return -EINVAL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | sd_info(("%s: cmd_type=%d, rw=%d, func=%d, addr=0x%05x, nbytes=%d\n", |
| 635 | __func__, cmd_type, rw, func, addr, nbytes)); |
| 636 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 637 | BRCMF_PM_RESUME_WAIT(sdioh_request_word_wait); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 638 | BRCMF_PM_RESUME_RETURN_ERROR(-EIO); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 639 | /* Claim host controller */ |
| 640 | sdio_claim_host(gInstance->func[func]); |
| 641 | |
| 642 | if (rw) { /* CMD52 Write */ |
| 643 | if (nbytes == 4) { |
| 644 | sdio_writel(gInstance->func[func], *word, addr, |
| 645 | &err_ret); |
| 646 | } else if (nbytes == 2) { |
| 647 | sdio_writew(gInstance->func[func], (*word & 0xFFFF), |
| 648 | addr, &err_ret); |
| 649 | } else { |
| 650 | sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes)); |
| 651 | } |
| 652 | } else { /* CMD52 Read */ |
| 653 | if (nbytes == 4) { |
| 654 | *word = |
| 655 | sdio_readl(gInstance->func[func], addr, &err_ret); |
| 656 | } else if (nbytes == 2) { |
| 657 | *word = |
| 658 | sdio_readw(gInstance->func[func], addr, |
| 659 | &err_ret) & 0xFFFF; |
| 660 | } else { |
| 661 | sd_err(("%s: Invalid nbytes: %d\n", __func__, nbytes)); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | /* Release host controller */ |
| 666 | sdio_release_host(gInstance->func[func]); |
| 667 | |
| 668 | if (err_ret) { |
| 669 | sd_err(("bcmsdh_sdmmc: Failed to %s word, Err: 0x%08x", |
| 670 | rw ? "Write" : "Read", err_ret)); |
| 671 | } |
| 672 | |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 673 | return err_ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 676 | static int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 677 | brcmf_sdioh_request_packet(struct sdioh_info *sd, uint fix_inc, uint write, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 678 | uint func, uint addr, struct sk_buff *pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 679 | { |
| 680 | bool fifo = (fix_inc == SDIOH_DATA_FIX); |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 681 | u32 SGCount = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 682 | int err_ret = 0; |
| 683 | |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 684 | struct sk_buff *pnext; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 685 | |
| 686 | sd_trace(("%s: Enter\n", __func__)); |
| 687 | |
| 688 | ASSERT(pkt); |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 689 | BRCMF_PM_RESUME_WAIT(sdioh_request_packet_wait); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 690 | BRCMF_PM_RESUME_RETURN_ERROR(-EIO); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 691 | |
| 692 | /* Claim host controller */ |
| 693 | sdio_claim_host(gInstance->func[func]); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 694 | for (pnext = pkt; pnext; pnext = pnext->next) { |
| 695 | uint pkt_len = pnext->len; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 696 | pkt_len += 3; |
| 697 | pkt_len &= 0xFFFFFFFC; |
| 698 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 699 | /* Make sure the packet is aligned properly. |
| 700 | * If it isn't, then this |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 701 | * is the fault of brcmf_sdioh_request_buffer() which |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 702 | * is supposed to give |
| 703 | * us something we can work with. |
| 704 | */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 705 | ASSERT(((u32) (pkt->data) & DMA_ALIGN_MASK) == 0); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 706 | |
| 707 | if ((write) && (!fifo)) { |
| 708 | err_ret = sdio_memcpy_toio(gInstance->func[func], addr, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 709 | ((u8 *) (pnext->data)), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 710 | pkt_len); |
| 711 | } else if (write) { |
| 712 | err_ret = sdio_memcpy_toio(gInstance->func[func], addr, |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 713 | ((u8 *) (pnext->data)), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 714 | pkt_len); |
| 715 | } else if (fifo) { |
| 716 | err_ret = sdio_readsb(gInstance->func[func], |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 717 | ((u8 *) (pnext->data)), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 718 | addr, pkt_len); |
| 719 | } else { |
| 720 | err_ret = sdio_memcpy_fromio(gInstance->func[func], |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 721 | ((u8 *) (pnext->data)), |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 722 | addr, pkt_len); |
| 723 | } |
| 724 | |
| 725 | if (err_ret) { |
| 726 | sd_err(("%s: %s FAILED %p[%d], addr=0x%05x, pkt_len=%d," |
Jason Cooper | e9887c9 | 2010-10-06 10:08:02 -0400 | [diff] [blame] | 727 | "ERR=0x%08x\n", __func__, |
| 728 | (write) ? "TX" : "RX", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 729 | pnext, SGCount, addr, pkt_len, err_ret)); |
| 730 | } else { |
| 731 | sd_trace(("%s: %s xfr'd %p[%d], addr=0x%05x, len=%d\n", |
| 732 | __func__, |
| 733 | (write) ? "TX" : "RX", |
| 734 | pnext, SGCount, addr, pkt_len)); |
| 735 | } |
| 736 | |
| 737 | if (!fifo) |
| 738 | addr += pkt_len; |
| 739 | SGCount++; |
| 740 | |
| 741 | } |
| 742 | |
| 743 | /* Release host controller */ |
| 744 | sdio_release_host(gInstance->func[func]); |
| 745 | |
| 746 | sd_trace(("%s: Exit\n", __func__)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 747 | return err_ret; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* |
| 751 | * This function takes a buffer or packet, and fixes everything up |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 752 | * so that in the end, a DMA-able packet is created. |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 753 | * |
| 754 | * A buffer does not have an associated packet pointer, |
| 755 | * and may or may not be aligned. |
| 756 | * A packet may consist of a single packet, or a packet chain. |
Grant Grundler | 4b455e0 | 2011-05-04 09:59:47 -0700 | [diff] [blame] | 757 | * If it is a packet chain, then all the packets in the chain |
| 758 | * must be properly aligned. |
| 759 | * |
| 760 | * If the packet data is not aligned, then there may only be |
| 761 | * one packet, and in this case, it is copied to a new |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 762 | * aligned packet. |
| 763 | * |
| 764 | */ |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 765 | extern int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 766 | brcmf_sdioh_request_buffer(struct sdioh_info *sd, uint pio_dma, uint fix_inc, |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 767 | uint write, uint func, uint addr, uint reg_width, |
| 768 | uint buflen_u, u8 *buffer, struct sk_buff *pkt) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 769 | { |
Roland Vossen | 3c79382 | 2011-06-29 16:47:23 -0700 | [diff] [blame] | 770 | int Status; |
Arend van Spriel | c26b137 | 2010-11-23 14:06:23 +0100 | [diff] [blame] | 771 | struct sk_buff *mypkt = NULL; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 772 | |
| 773 | sd_trace(("%s: Enter\n", __func__)); |
| 774 | |
Arend van Spriel | 40695d1 | 2011-06-29 16:47:51 -0700 | [diff] [blame] | 775 | BRCMF_PM_RESUME_WAIT(sdioh_request_buffer_wait); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 776 | BRCMF_PM_RESUME_RETURN_ERROR(-EIO); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 777 | /* Case 1: we don't have a packet. */ |
| 778 | if (pkt == NULL) { |
| 779 | sd_data(("%s: Creating new %s Packet, len=%d\n", |
| 780 | __func__, write ? "TX" : "RX", buflen_u)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 781 | mypkt = brcmu_pkt_buf_get_skb(buflen_u); |
Jason Cooper | a1b04b0 | 2010-09-30 15:15:37 -0400 | [diff] [blame] | 782 | if (!mypkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 783 | sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n", |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 784 | __func__, buflen_u)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 785 | return -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | /* For a write, copy the buffer data into the packet. */ |
| 789 | if (write) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 790 | memcpy(mypkt->data, buffer, buflen_u); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 791 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 792 | Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func, |
| 793 | addr, mypkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 794 | |
| 795 | /* For a read, copy the packet data back to the buffer. */ |
| 796 | if (!write) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 797 | memcpy(buffer, mypkt->data, buflen_u); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 798 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 799 | brcmu_pkt_buf_free_skb(mypkt); |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 800 | } else if (((u32) (pkt->data) & DMA_ALIGN_MASK) != 0) { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 801 | /* Case 2: We have a packet, but it is unaligned. */ |
| 802 | |
| 803 | /* In this case, we cannot have a chain. */ |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 804 | ASSERT(pkt->next == NULL); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 805 | |
| 806 | sd_data(("%s: Creating aligned %s Packet, len=%d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 807 | __func__, write ? "TX" : "RX", pkt->len)); |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 808 | mypkt = brcmu_pkt_buf_get_skb(pkt->len); |
Jason Cooper | a1b04b0 | 2010-09-30 15:15:37 -0400 | [diff] [blame] | 809 | if (!mypkt) { |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 810 | sd_err(("%s: brcmu_pkt_buf_get_skb failed: len %d\n", |
Arend van Spriel | 54991ad | 2010-11-23 14:06:24 +0100 | [diff] [blame] | 811 | __func__, pkt->len)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 812 | return -EIO; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /* For a write, copy the buffer data into the packet. */ |
| 816 | if (write) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 817 | memcpy(mypkt->data, pkt->data, pkt->len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 818 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 819 | Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func, |
| 820 | addr, mypkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 821 | |
| 822 | /* For a read, copy the packet data back to the buffer. */ |
| 823 | if (!write) |
Stanislav Fomichev | 0216069 | 2011-02-15 01:05:10 +0300 | [diff] [blame] | 824 | memcpy(pkt->data, mypkt->data, mypkt->len); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 825 | |
Roland Vossen | 67ad48b | 2011-06-01 13:45:51 +0200 | [diff] [blame] | 826 | brcmu_pkt_buf_free_skb(mypkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 827 | } else { /* case 3: We have a packet and |
| 828 | it is aligned. */ |
| 829 | sd_data(("%s: Aligned %s Packet, direct DMA\n", |
| 830 | __func__, write ? "Tx" : "Rx")); |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 831 | Status = brcmf_sdioh_request_packet(sd, fix_inc, write, func, |
| 832 | addr, pkt); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | return Status; |
| 836 | } |
| 837 | |
| 838 | /* this function performs "abort" for both of host & device */ |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 839 | extern int brcmf_sdioh_abort(struct sdioh_info *sd, uint func) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 840 | { |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 841 | char t_func = (char)func; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 842 | sd_trace(("%s: Enter\n", __func__)); |
| 843 | |
Franky Lin | 0df4604 | 2011-06-01 13:45:40 +0200 | [diff] [blame] | 844 | /* issue abort cmd52 command through F0 */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 845 | brcmf_sdioh_request_byte(sd, SDIOH_WRITE, SDIO_FUNC_0, SDIO_CCCR_ABORT, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 846 | &t_func); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 847 | |
| 848 | sd_trace(("%s: Exit\n", __func__)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 849 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /* Reset and re-initialize the device */ |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 853 | int brcmf_sdioh_reset(struct sdioh_info *si) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 854 | { |
| 855 | sd_trace(("%s: Enter\n", __func__)); |
| 856 | sd_trace(("%s: Exit\n", __func__)); |
Roland Vossen | 67f72be | 2011-06-29 16:47:56 -0700 | [diff] [blame^] | 857 | return 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /* Disable device interrupt */ |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 861 | void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 862 | { |
| 863 | sd_trace(("%s: %d\n", __func__, sd->use_client_ints)); |
| 864 | sd->intmask &= ~CLIENT_INTR; |
| 865 | } |
| 866 | |
| 867 | /* Enable device interrupt */ |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 868 | void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 869 | { |
| 870 | sd_trace(("%s: %d\n", __func__, sd->use_client_ints)); |
| 871 | sd->intmask |= CLIENT_INTR; |
| 872 | } |
| 873 | |
| 874 | /* Read client card reg */ |
| 875 | int |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 876 | brcmf_sdioh_card_regread(struct sdioh_info *sd, int func, u32 regaddr, |
Greg Kroah-Hartman | 66cbd3a | 2010-10-08 11:05:47 -0700 | [diff] [blame] | 877 | int regsize, u32 *data) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 878 | { |
| 879 | |
| 880 | if ((func == 0) || (regsize == 1)) { |
Greg Kroah-Hartman | 3fd79f7 | 2010-10-05 10:11:12 -0700 | [diff] [blame] | 881 | u8 temp = 0; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 882 | |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 883 | brcmf_sdioh_request_byte(sd, SDIOH_READ, func, regaddr, &temp); |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 884 | *data = temp; |
| 885 | *data &= 0xff; |
| 886 | sd_data(("%s: byte read data=0x%02x\n", __func__, *data)); |
| 887 | } else { |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 888 | brcmf_sdioh_request_word(sd, 0, SDIOH_READ, func, regaddr, data, |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 889 | regsize); |
| 890 | if (regsize == 2) |
| 891 | *data &= 0xffff; |
| 892 | |
| 893 | sd_data(("%s: word read data=0x%08x\n", __func__, *data)); |
| 894 | } |
| 895 | |
| 896 | return SUCCESS; |
| 897 | } |
| 898 | |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 899 | /* bcmsdh_sdmmc interrupt handler */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 900 | static void brcmf_sdioh_irqhandler(struct sdio_func *func) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 901 | { |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 902 | struct sdioh_info *sd; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 903 | |
| 904 | sd_trace(("bcmsdh_sdmmc: ***IRQHandler\n")); |
| 905 | sd = gInstance->sd; |
| 906 | |
| 907 | ASSERT(sd != NULL); |
| 908 | sdio_release_host(gInstance->func[0]); |
| 909 | |
| 910 | if (sd->use_client_ints) { |
| 911 | sd->intrcount++; |
| 912 | ASSERT(sd->intr_handler); |
| 913 | ASSERT(sd->intr_handler_arg); |
| 914 | (sd->intr_handler) (sd->intr_handler_arg); |
| 915 | } else { |
| 916 | sd_err(("bcmsdh_sdmmc: ***IRQHandler\n")); |
| 917 | |
| 918 | sd_err(("%s: Not ready for intr: enabled %d, handler %p\n", |
| 919 | __func__, sd->client_intr_enabled, sd->intr_handler)); |
| 920 | } |
| 921 | |
| 922 | sdio_claim_host(gInstance->func[0]); |
| 923 | } |
| 924 | |
| 925 | /* bcmsdh_sdmmc interrupt handler for F2 (dummy handler) */ |
Roland Vossen | 54ca296 | 2011-06-29 16:46:59 -0700 | [diff] [blame] | 926 | static void brcmf_sdioh_irqhandler_f2(struct sdio_func *func) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 927 | { |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 928 | struct sdioh_info *sd; |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 929 | |
| 930 | sd_trace(("bcmsdh_sdmmc: ***IRQHandlerF2\n")); |
| 931 | |
| 932 | sd = gInstance->sd; |
| 933 | |
| 934 | ASSERT(sd != NULL); |
| 935 | } |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 936 | |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 937 | int brcmf_sdioh_start(struct sdioh_info *si, int stage) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 938 | { |
| 939 | return 0; |
| 940 | } |
| 941 | |
Roland Vossen | 294f243 | 2011-06-29 16:47:20 -0700 | [diff] [blame] | 942 | int brcmf_sdioh_stop(struct sdioh_info *si) |
Henry Ptasinski | cf2b448 | 2010-09-20 22:33:12 -0700 | [diff] [blame] | 943 | { |
| 944 | return 0; |
| 945 | } |