Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [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 | /* ****************** SDIO CARD Interface Functions **************************/ |
| 17 | |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/netdevice.h> |
Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 20 | #include <linux/export.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 21 | #include <linux/pci.h> |
| 22 | #include <linux/pci_ids.h> |
| 23 | #include <linux/sched.h> |
| 24 | #include <linux/completion.h> |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 25 | #include <linux/scatterlist.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 26 | #include <linux/mmc/sdio.h> |
| 27 | #include <linux/mmc/sdio_func.h> |
| 28 | #include <linux/mmc/card.h> |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 29 | #include <linux/mmc/host.h> |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 30 | #include <linux/platform_data/brcmfmac-sdio.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 31 | |
| 32 | #include <defs.h> |
| 33 | #include <brcm_hw_ids.h> |
| 34 | #include <brcmu_utils.h> |
| 35 | #include <brcmu_wifi.h> |
| 36 | #include <soc.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 37 | #include "dhd_bus.h" |
| 38 | #include "dhd_dbg.h" |
| 39 | #include "sdio_host.h" |
| 40 | |
| 41 | #define SDIOH_API_ACCESS_RETRY_LIMIT 2 |
| 42 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 43 | |
| 44 | static irqreturn_t brcmf_sdio_oob_irqhandler(int irq, void *dev_id) |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 45 | { |
Hante Meuleman | 5b3c183 | 2012-11-14 18:46:20 -0800 | [diff] [blame] | 46 | struct brcmf_bus *bus_if = dev_get_drvdata(dev_id); |
| 47 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 48 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 49 | brcmf_dbg(INTR, "OOB intr triggered\n"); |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 50 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 51 | /* out-of-band interrupt is level-triggered which won't |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 52 | * be cleared until dpc |
| 53 | */ |
| 54 | if (sdiodev->irq_en) { |
| 55 | disable_irq_nosync(irq); |
| 56 | sdiodev->irq_en = false; |
| 57 | } |
| 58 | |
| 59 | brcmf_sdbrcm_isr(sdiodev->bus); |
| 60 | |
| 61 | return IRQ_HANDLED; |
| 62 | } |
| 63 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 64 | static void brcmf_sdio_ib_irqhandler(struct sdio_func *func) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 65 | { |
Hante Meuleman | 5b3c183 | 2012-11-14 18:46:20 -0800 | [diff] [blame] | 66 | struct brcmf_bus *bus_if = dev_get_drvdata(&func->dev); |
| 67 | struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 68 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 69 | brcmf_dbg(INTR, "IB intr triggered\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 70 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 71 | brcmf_sdbrcm_isr(sdiodev->bus); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Franky Lin | fbf5910 | 2011-12-16 18:36:53 -0800 | [diff] [blame] | 74 | /* dummy handler for SDIO function 2 interrupt */ |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 75 | static void brcmf_sdio_dummy_irqhandler(struct sdio_func *func) |
Franky Lin | fbf5910 | 2011-12-16 18:36:53 -0800 | [diff] [blame] | 76 | { |
| 77 | } |
| 78 | |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 79 | int brcmf_sdio_intr_register(struct brcmf_sdio_dev *sdiodev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 80 | { |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 81 | int ret = 0; |
| 82 | u8 data; |
| 83 | unsigned long flags; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 84 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 85 | if ((sdiodev->pdata) && (sdiodev->pdata->oob_irq_supported)) { |
| 86 | brcmf_dbg(SDIO, "Enter, register OOB IRQ %d\n", |
| 87 | sdiodev->pdata->oob_irq_nr); |
| 88 | ret = request_irq(sdiodev->pdata->oob_irq_nr, |
| 89 | brcmf_sdio_oob_irqhandler, |
| 90 | sdiodev->pdata->oob_irq_flags, |
| 91 | "brcmf_oob_intr", |
| 92 | &sdiodev->func[1]->dev); |
| 93 | if (ret != 0) { |
| 94 | brcmf_err("request_irq failed %d\n", ret); |
| 95 | return ret; |
| 96 | } |
| 97 | sdiodev->oob_irq_requested = true; |
| 98 | spin_lock_init(&sdiodev->irq_en_lock); |
| 99 | spin_lock_irqsave(&sdiodev->irq_en_lock, flags); |
| 100 | sdiodev->irq_en = true; |
| 101 | spin_unlock_irqrestore(&sdiodev->irq_en_lock, flags); |
| 102 | |
| 103 | ret = enable_irq_wake(sdiodev->pdata->oob_irq_nr); |
| 104 | if (ret != 0) { |
| 105 | brcmf_err("enable_irq_wake failed %d\n", ret); |
| 106 | return ret; |
| 107 | } |
| 108 | sdiodev->irq_wake = true; |
| 109 | |
| 110 | sdio_claim_host(sdiodev->func[1]); |
| 111 | |
| 112 | /* must configure SDIO_CCCR_IENx to enable irq */ |
| 113 | data = brcmf_sdio_regrb(sdiodev, SDIO_CCCR_IENx, &ret); |
| 114 | data |= 1 << SDIO_FUNC_1 | 1 << SDIO_FUNC_2 | 1; |
| 115 | brcmf_sdio_regwb(sdiodev, SDIO_CCCR_IENx, data, &ret); |
| 116 | |
| 117 | /* redirect, configure and enable io for interrupt signal */ |
| 118 | data = SDIO_SEPINT_MASK | SDIO_SEPINT_OE; |
| 119 | if (sdiodev->pdata->oob_irq_flags & IRQF_TRIGGER_HIGH) |
| 120 | data |= SDIO_SEPINT_ACT_HI; |
| 121 | brcmf_sdio_regwb(sdiodev, SDIO_CCCR_BRCM_SEPINT, data, &ret); |
| 122 | |
| 123 | sdio_release_host(sdiodev->func[1]); |
| 124 | } else { |
| 125 | brcmf_dbg(SDIO, "Entering\n"); |
| 126 | sdio_claim_host(sdiodev->func[1]); |
| 127 | sdio_claim_irq(sdiodev->func[1], brcmf_sdio_ib_irqhandler); |
| 128 | sdio_claim_irq(sdiodev->func[2], brcmf_sdio_dummy_irqhandler); |
| 129 | sdio_release_host(sdiodev->func[1]); |
| 130 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
Franky Lin | ba89bf1 | 2012-04-27 18:56:59 -0700 | [diff] [blame] | 135 | int brcmf_sdio_intr_unregister(struct brcmf_sdio_dev *sdiodev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 136 | { |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 137 | brcmf_dbg(SDIO, "Entering\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 138 | |
Hante Meuleman | 668761a | 2013-04-12 10:55:55 +0200 | [diff] [blame] | 139 | if ((sdiodev->pdata) && (sdiodev->pdata->oob_irq_supported)) { |
| 140 | sdio_claim_host(sdiodev->func[1]); |
| 141 | brcmf_sdio_regwb(sdiodev, SDIO_CCCR_BRCM_SEPINT, 0, NULL); |
| 142 | brcmf_sdio_regwb(sdiodev, SDIO_CCCR_IENx, 0, NULL); |
| 143 | sdio_release_host(sdiodev->func[1]); |
| 144 | |
| 145 | if (sdiodev->oob_irq_requested) { |
| 146 | sdiodev->oob_irq_requested = false; |
| 147 | if (sdiodev->irq_wake) { |
| 148 | disable_irq_wake(sdiodev->pdata->oob_irq_nr); |
| 149 | sdiodev->irq_wake = false; |
| 150 | } |
| 151 | free_irq(sdiodev->pdata->oob_irq_nr, |
| 152 | &sdiodev->func[1]->dev); |
| 153 | sdiodev->irq_en = false; |
| 154 | } |
| 155 | } else { |
| 156 | sdio_claim_host(sdiodev->func[1]); |
| 157 | sdio_release_irq(sdiodev->func[2]); |
| 158 | sdio_release_irq(sdiodev->func[1]); |
| 159 | sdio_release_host(sdiodev->func[1]); |
| 160 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Franky Lin | 356bae6 | 2013-06-26 14:20:17 +0200 | [diff] [blame^] | 165 | static int |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 166 | brcmf_sdcard_set_sbaddr_window(struct brcmf_sdio_dev *sdiodev, u32 address) |
| 167 | { |
Franky Lin | 7d9cfc2 | 2012-05-04 18:27:30 -0700 | [diff] [blame] | 168 | int err = 0, i; |
| 169 | u8 addr[3]; |
| 170 | s32 retry; |
| 171 | |
| 172 | addr[0] = (address >> 8) & SBSDIO_SBADDRLOW_MASK; |
| 173 | addr[1] = (address >> 16) & SBSDIO_SBADDRMID_MASK; |
| 174 | addr[2] = (address >> 24) & SBSDIO_SBADDRHIGH_MASK; |
| 175 | |
| 176 | for (i = 0; i < 3; i++) { |
| 177 | retry = 0; |
| 178 | do { |
| 179 | if (retry) |
| 180 | usleep_range(1000, 2000); |
| 181 | err = brcmf_sdioh_request_byte(sdiodev, SDIOH_WRITE, |
| 182 | SDIO_FUNC_1, SBSDIO_FUNC1_SBADDRLOW + i, |
| 183 | &addr[i]); |
| 184 | } while (err != 0 && retry++ < SDIOH_API_ACCESS_RETRY_LIMIT); |
| 185 | |
| 186 | if (err) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 187 | brcmf_err("failed at addr:0x%0x\n", |
Franky Lin | 7d9cfc2 | 2012-05-04 18:27:30 -0700 | [diff] [blame] | 188 | SBSDIO_FUNC1_SBADDRLOW + i); |
| 189 | break; |
| 190 | } |
| 191 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 192 | |
| 193 | return err; |
| 194 | } |
| 195 | |
Franky Lin | 356bae6 | 2013-06-26 14:20:17 +0200 | [diff] [blame^] | 196 | static int |
| 197 | brcmf_sdio_addrprep(struct brcmf_sdio_dev *sdiodev, uint width, u32 *addr) |
| 198 | { |
| 199 | uint bar0 = *addr & ~SBSDIO_SB_OFT_ADDR_MASK; |
| 200 | int err = 0; |
| 201 | |
| 202 | if (bar0 != sdiodev->sbwad) { |
| 203 | err = brcmf_sdcard_set_sbaddr_window(sdiodev, bar0); |
| 204 | if (err) |
| 205 | return err; |
| 206 | |
| 207 | sdiodev->sbwad = bar0; |
| 208 | } |
| 209 | |
| 210 | *addr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 211 | |
| 212 | if (width == 4) |
| 213 | *addr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
Franky Lin | 4531603 | 2012-09-13 21:12:03 +0200 | [diff] [blame] | 218 | int |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 219 | brcmf_sdio_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr, |
| 220 | void *data, bool write) |
| 221 | { |
| 222 | u8 func_num, reg_size; |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 223 | s32 retry = 0; |
| 224 | int ret; |
| 225 | |
| 226 | /* |
| 227 | * figure out how to read the register based on address range |
Franky Lin | d8b3fc5 | 2012-05-04 18:27:38 -0700 | [diff] [blame] | 228 | * 0x00 ~ 0x7FF: function 0 CCCR and FBR |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 229 | * 0x10000 ~ 0x1FFFF: function 1 miscellaneous registers |
| 230 | * The rest: function 1 silicon backplane core registers |
| 231 | */ |
Franky Lin | d8b3fc5 | 2012-05-04 18:27:38 -0700 | [diff] [blame] | 232 | if ((addr & ~REG_F0_REG_MASK) == 0) { |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 233 | func_num = SDIO_FUNC_0; |
| 234 | reg_size = 1; |
| 235 | } else if ((addr & ~REG_F1_MISC_MASK) == 0) { |
| 236 | func_num = SDIO_FUNC_1; |
| 237 | reg_size = 1; |
| 238 | } else { |
| 239 | func_num = SDIO_FUNC_1; |
| 240 | reg_size = 4; |
| 241 | |
Franky Lin | 356bae6 | 2013-06-26 14:20:17 +0200 | [diff] [blame^] | 242 | brcmf_sdio_addrprep(sdiodev, reg_size, &addr); |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | do { |
| 246 | if (!write) |
| 247 | memset(data, 0, reg_size); |
| 248 | if (retry) /* wait for 1 ms till bus get settled down */ |
| 249 | usleep_range(1000, 2000); |
| 250 | if (reg_size == 1) |
| 251 | ret = brcmf_sdioh_request_byte(sdiodev, write, |
| 252 | func_num, addr, data); |
| 253 | else |
| 254 | ret = brcmf_sdioh_request_word(sdiodev, write, |
| 255 | func_num, addr, data, 4); |
| 256 | } while (ret != 0 && retry++ < SDIOH_API_ACCESS_RETRY_LIMIT); |
| 257 | |
Franky Lin | 5c15c23 | 2012-05-04 18:27:37 -0700 | [diff] [blame] | 258 | if (ret != 0) |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 259 | brcmf_err("failed with %d\n", ret); |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 260 | |
| 261 | return ret; |
| 262 | } |
| 263 | |
| 264 | u8 brcmf_sdio_regrb(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret) |
| 265 | { |
| 266 | u8 data; |
| 267 | int retval; |
| 268 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 269 | brcmf_dbg(SDIO, "addr:0x%08x\n", addr); |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 270 | retval = brcmf_sdio_regrw_helper(sdiodev, addr, &data, false); |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 271 | brcmf_dbg(SDIO, "data:0x%02x\n", data); |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 272 | |
| 273 | if (ret) |
| 274 | *ret = retval; |
| 275 | |
| 276 | return data; |
| 277 | } |
| 278 | |
| 279 | u32 brcmf_sdio_regrl(struct brcmf_sdio_dev *sdiodev, u32 addr, int *ret) |
| 280 | { |
| 281 | u32 data; |
| 282 | int retval; |
| 283 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 284 | brcmf_dbg(SDIO, "addr:0x%08x\n", addr); |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 285 | retval = brcmf_sdio_regrw_helper(sdiodev, addr, &data, false); |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 286 | brcmf_dbg(SDIO, "data:0x%08x\n", data); |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 287 | |
| 288 | if (ret) |
| 289 | *ret = retval; |
| 290 | |
| 291 | return data; |
| 292 | } |
| 293 | |
| 294 | void brcmf_sdio_regwb(struct brcmf_sdio_dev *sdiodev, u32 addr, |
| 295 | u8 data, int *ret) |
| 296 | { |
| 297 | int retval; |
| 298 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 299 | brcmf_dbg(SDIO, "addr:0x%08x, data:0x%02x\n", addr, data); |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 300 | retval = brcmf_sdio_regrw_helper(sdiodev, addr, &data, true); |
| 301 | |
| 302 | if (ret) |
| 303 | *ret = retval; |
| 304 | } |
| 305 | |
| 306 | void brcmf_sdio_regwl(struct brcmf_sdio_dev *sdiodev, u32 addr, |
| 307 | u32 data, int *ret) |
| 308 | { |
| 309 | int retval; |
| 310 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 311 | brcmf_dbg(SDIO, "addr:0x%08x, data:0x%08x\n", addr, data); |
Franky Lin | e9b8d91 | 2012-05-04 18:27:31 -0700 | [diff] [blame] | 312 | retval = brcmf_sdio_regrw_helper(sdiodev, addr, &data, true); |
| 313 | |
| 314 | if (ret) |
| 315 | *ret = retval; |
| 316 | } |
| 317 | |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 318 | /** |
| 319 | * brcmf_sdio_buffrw - SDIO interface function for block data access |
| 320 | * @sdiodev: brcmfmac sdio device |
| 321 | * @fn: SDIO function number |
| 322 | * @write: direction flag |
| 323 | * @addr: dongle memory address as source/destination |
| 324 | * @pkt: skb pointer |
| 325 | * |
| 326 | * This function takes the respbonsibility as the interface function to MMC |
| 327 | * stack for block data access. It assumes that the skb passed down by the |
| 328 | * caller has already been padded and aligned. |
| 329 | */ |
| 330 | static int brcmf_sdio_buffrw(struct brcmf_sdio_dev *sdiodev, uint fn, |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 331 | bool write, u32 addr, struct sk_buff_head *pktlist) |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 332 | { |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 333 | unsigned int req_sz, func_blk_sz, sg_cnt, sg_data_sz, pkt_offset; |
| 334 | unsigned int max_blks, max_req_sz; |
| 335 | unsigned short max_seg_sz, seg_sz; |
| 336 | unsigned char *pkt_data; |
| 337 | struct sk_buff *pkt_next = NULL; |
| 338 | struct mmc_request mmc_req; |
| 339 | struct mmc_command mmc_cmd; |
| 340 | struct mmc_data mmc_dat; |
| 341 | struct sg_table st; |
| 342 | struct scatterlist *sgl; |
| 343 | struct mmc_host *host; |
| 344 | int ret = 0; |
| 345 | |
| 346 | if (!pktlist->qlen) |
| 347 | return -EINVAL; |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 348 | |
| 349 | brcmf_pm_resume_wait(sdiodev, &sdiodev->request_buffer_wait); |
| 350 | if (brcmf_pm_resume_error(sdiodev)) |
| 351 | return -EIO; |
| 352 | |
| 353 | /* Single skb use the standard mmc interface */ |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 354 | if (pktlist->qlen == 1) { |
| 355 | pkt_next = pktlist->next; |
| 356 | req_sz = pkt_next->len + 3; |
| 357 | req_sz &= (uint)~3; |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 358 | |
| 359 | if (write) |
| 360 | return sdio_memcpy_toio(sdiodev->func[fn], addr, |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 361 | ((u8 *)(pkt_next->data)), |
| 362 | req_sz); |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 363 | else if (fn == 1) |
| 364 | return sdio_memcpy_fromio(sdiodev->func[fn], |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 365 | ((u8 *)(pkt_next->data)), |
| 366 | addr, req_sz); |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 367 | else |
| 368 | /* function 2 read is FIFO operation */ |
| 369 | return sdio_readsb(sdiodev->func[fn], |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 370 | ((u8 *)(pkt_next->data)), addr, |
| 371 | req_sz); |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 372 | } |
| 373 | |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 374 | host = sdiodev->func[fn]->card->host; |
| 375 | func_blk_sz = sdiodev->func[fn]->cur_blksize; |
| 376 | /* Blocks per command is limited by host count, host transfer |
| 377 | * size and the maximum for IO_RW_EXTENDED of 511 blocks. |
| 378 | */ |
| 379 | max_blks = min_t(unsigned int, host->max_blk_count, 511u); |
| 380 | max_req_sz = min_t(unsigned int, host->max_req_size, |
| 381 | max_blks * func_blk_sz); |
| 382 | max_seg_sz = min_t(unsigned short, host->max_segs, SG_MAX_SINGLE_ALLOC); |
| 383 | max_seg_sz = min_t(unsigned short, max_seg_sz, pktlist->qlen); |
| 384 | seg_sz = pktlist->qlen; |
| 385 | pkt_offset = 0; |
| 386 | pkt_next = pktlist->next; |
| 387 | |
| 388 | if (sg_alloc_table(&st, max_seg_sz, GFP_KERNEL)) |
| 389 | return -ENOMEM; |
| 390 | |
| 391 | while (seg_sz) { |
| 392 | req_sz = 0; |
| 393 | sg_cnt = 0; |
| 394 | memset(&mmc_req, 0, sizeof(struct mmc_request)); |
| 395 | memset(&mmc_cmd, 0, sizeof(struct mmc_command)); |
| 396 | memset(&mmc_dat, 0, sizeof(struct mmc_data)); |
| 397 | sgl = st.sgl; |
| 398 | /* prep sg table */ |
| 399 | while (pkt_next != (struct sk_buff *)pktlist) { |
| 400 | pkt_data = pkt_next->data + pkt_offset; |
| 401 | sg_data_sz = pkt_next->len - pkt_offset; |
| 402 | if (sg_data_sz > host->max_seg_size) |
| 403 | sg_data_sz = host->max_seg_size; |
| 404 | if (sg_data_sz > max_req_sz - req_sz) |
| 405 | sg_data_sz = max_req_sz - req_sz; |
| 406 | |
| 407 | sg_set_buf(sgl, pkt_data, sg_data_sz); |
| 408 | |
| 409 | sg_cnt++; |
| 410 | sgl = sg_next(sgl); |
| 411 | req_sz += sg_data_sz; |
| 412 | pkt_offset += sg_data_sz; |
| 413 | if (pkt_offset == pkt_next->len) { |
| 414 | pkt_offset = 0; |
| 415 | pkt_next = pkt_next->next; |
| 416 | } |
| 417 | |
| 418 | if (req_sz >= max_req_sz || sg_cnt >= max_seg_sz) |
| 419 | break; |
| 420 | } |
| 421 | seg_sz -= sg_cnt; |
| 422 | |
| 423 | if (req_sz % func_blk_sz != 0) { |
| 424 | brcmf_err("sg request length %u is not %u aligned\n", |
| 425 | req_sz, func_blk_sz); |
| 426 | sg_free_table(&st); |
| 427 | return -ENOTBLK; |
| 428 | } |
| 429 | mmc_dat.sg = st.sgl; |
| 430 | mmc_dat.sg_len = sg_cnt; |
| 431 | mmc_dat.blksz = func_blk_sz; |
| 432 | mmc_dat.blocks = req_sz / func_blk_sz; |
| 433 | mmc_dat.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; |
| 434 | mmc_cmd.opcode = SD_IO_RW_EXTENDED; |
| 435 | mmc_cmd.arg = write ? 1<<31 : 0; /* write flag */ |
| 436 | mmc_cmd.arg |= (fn & 0x7) << 28; /* SDIO func num */ |
| 437 | mmc_cmd.arg |= 1<<27; /* block mode */ |
| 438 | /* incrementing addr for function 1 */ |
| 439 | mmc_cmd.arg |= (fn == 1) ? 1<<26 : 0; |
| 440 | mmc_cmd.arg |= (addr & 0x1FFFF) << 9; /* address */ |
| 441 | mmc_cmd.arg |= mmc_dat.blocks & 0x1FF; /* block count */ |
| 442 | mmc_cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC; |
| 443 | mmc_req.cmd = &mmc_cmd; |
| 444 | mmc_req.data = &mmc_dat; |
| 445 | if (fn == 1) |
| 446 | addr += req_sz; |
| 447 | |
| 448 | mmc_set_data_timeout(&mmc_dat, sdiodev->func[fn]->card); |
| 449 | mmc_wait_for_req(host, &mmc_req); |
| 450 | |
| 451 | ret = mmc_cmd.error ? mmc_cmd.error : mmc_dat.error; |
| 452 | if (ret != 0) { |
| 453 | brcmf_err("CMD53 sg block %s failed %d\n", |
| 454 | write ? "write" : "read", ret); |
| 455 | ret = -EIO; |
| 456 | break; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | sg_free_table(&st); |
| 461 | |
| 462 | return ret; |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 465 | int |
| 466 | brcmf_sdcard_recv_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, |
| 467 | uint flags, u8 *buf, uint nbytes) |
| 468 | { |
| 469 | struct sk_buff *mypkt; |
| 470 | int err; |
| 471 | |
| 472 | mypkt = brcmu_pkt_buf_get_skb(nbytes); |
| 473 | if (!mypkt) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 474 | brcmf_err("brcmu_pkt_buf_get_skb failed: len %d\n", |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 475 | nbytes); |
| 476 | return -EIO; |
| 477 | } |
| 478 | |
| 479 | err = brcmf_sdcard_recv_pkt(sdiodev, addr, fn, flags, mypkt); |
| 480 | if (!err) |
| 481 | memcpy(buf, mypkt->data, nbytes); |
| 482 | |
| 483 | brcmu_pkt_buf_free_skb(mypkt); |
| 484 | return err; |
| 485 | } |
| 486 | |
| 487 | int |
| 488 | brcmf_sdcard_recv_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, |
| 489 | uint flags, struct sk_buff *pkt) |
| 490 | { |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 491 | uint width; |
| 492 | int err = 0; |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 493 | struct sk_buff_head pkt_list; |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 494 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 495 | brcmf_dbg(SDIO, "fun = %d, addr = 0x%x, size = %d\n", |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 496 | fn, addr, pkt->len); |
| 497 | |
| 498 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
Franky Lin | 356bae6 | 2013-06-26 14:20:17 +0200 | [diff] [blame^] | 499 | err = brcmf_sdio_addrprep(sdiodev, width, &addr); |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 500 | if (err) |
Franky Lin | 7057fd0 | 2012-09-13 21:12:02 +0200 | [diff] [blame] | 501 | goto done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 502 | |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 503 | skb_queue_head_init(&pkt_list); |
| 504 | skb_queue_tail(&pkt_list, pkt); |
| 505 | err = brcmf_sdio_buffrw(sdiodev, fn, false, addr, &pkt_list); |
| 506 | skb_dequeue_tail(&pkt_list); |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 507 | |
Franky Lin | 7057fd0 | 2012-09-13 21:12:02 +0200 | [diff] [blame] | 508 | done: |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 509 | return err; |
| 510 | } |
| 511 | |
| 512 | int brcmf_sdcard_recv_chain(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, |
| 513 | uint flags, struct sk_buff_head *pktq) |
| 514 | { |
| 515 | uint incr_fix; |
| 516 | uint width; |
| 517 | int err = 0; |
| 518 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 519 | brcmf_dbg(SDIO, "fun = %d, addr = 0x%x, size = %d\n", |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 520 | fn, addr, pktq->qlen); |
| 521 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 522 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
Franky Lin | 356bae6 | 2013-06-26 14:20:17 +0200 | [diff] [blame^] | 523 | err = brcmf_sdio_addrprep(sdiodev, width, &addr); |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 524 | if (err) |
Franky Lin | 7057fd0 | 2012-09-13 21:12:02 +0200 | [diff] [blame] | 525 | goto done; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 526 | |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 527 | incr_fix = (flags & SDIO_REQ_FIXED) ? SDIOH_DATA_FIX : SDIOH_DATA_INC; |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 528 | err = brcmf_sdio_buffrw(sdiodev, fn, false, addr, pktq); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 529 | |
Franky Lin | 7057fd0 | 2012-09-13 21:12:02 +0200 | [diff] [blame] | 530 | done: |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 531 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | int |
| 535 | brcmf_sdcard_send_buf(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 536 | uint flags, u8 *buf, uint nbytes) |
| 537 | { |
| 538 | struct sk_buff *mypkt; |
| 539 | int err; |
| 540 | |
| 541 | mypkt = brcmu_pkt_buf_get_skb(nbytes); |
| 542 | if (!mypkt) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 543 | brcmf_err("brcmu_pkt_buf_get_skb failed: len %d\n", |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 544 | nbytes); |
| 545 | return -EIO; |
| 546 | } |
| 547 | |
| 548 | memcpy(mypkt->data, buf, nbytes); |
| 549 | err = brcmf_sdcard_send_pkt(sdiodev, addr, fn, flags, mypkt); |
| 550 | |
| 551 | brcmu_pkt_buf_free_skb(mypkt); |
| 552 | return err; |
| 553 | |
| 554 | } |
| 555 | |
| 556 | int |
| 557 | brcmf_sdcard_send_pkt(struct brcmf_sdio_dev *sdiodev, u32 addr, uint fn, |
| 558 | uint flags, struct sk_buff *pkt) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 559 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 560 | uint width; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 561 | int err = 0; |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 562 | struct sk_buff_head pkt_list; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 563 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 564 | brcmf_dbg(SDIO, "fun = %d, addr = 0x%x, size = %d\n", |
Arend van Spriel | 5adfeb6 | 2011-11-22 17:21:38 -0800 | [diff] [blame] | 565 | fn, addr, pkt->len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 566 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 567 | width = (flags & SDIO_REQ_4BYTE) ? 4 : 2; |
Franky Lin | 356bae6 | 2013-06-26 14:20:17 +0200 | [diff] [blame^] | 568 | brcmf_sdio_addrprep(sdiodev, width, &addr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 569 | |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 570 | skb_queue_head_init(&pkt_list); |
| 571 | skb_queue_tail(&pkt_list, pkt); |
| 572 | err = brcmf_sdio_buffrw(sdiodev, fn, true, addr, &pkt_list); |
| 573 | skb_dequeue_tail(&pkt_list); |
Franky Lin | 7057fd0 | 2012-09-13 21:12:02 +0200 | [diff] [blame] | 574 | |
Franky Lin | 7057fd0 | 2012-09-13 21:12:02 +0200 | [diff] [blame] | 575 | return err; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 576 | } |
| 577 | |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 578 | int |
| 579 | brcmf_sdio_ramrw(struct brcmf_sdio_dev *sdiodev, bool write, u32 address, |
| 580 | u8 *data, uint size) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 581 | { |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 582 | int bcmerror = 0; |
| 583 | struct sk_buff *pkt; |
| 584 | u32 sdaddr; |
| 585 | uint dsize; |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 586 | struct sk_buff_head pkt_list; |
Arend van Spriel | 4c6e869 | 2011-11-22 17:21:40 -0800 | [diff] [blame] | 587 | |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 588 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
| 589 | pkt = dev_alloc_skb(dsize); |
| 590 | if (!pkt) { |
| 591 | brcmf_err("dev_alloc_skb failed: len %d\n", dsize); |
Arend van Spriel | 4c6e869 | 2011-11-22 17:21:40 -0800 | [diff] [blame] | 592 | return -EIO; |
| 593 | } |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 594 | pkt->priority = 0; |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 595 | skb_queue_head_init(&pkt_list); |
Arend van Spriel | 4c6e869 | 2011-11-22 17:21:40 -0800 | [diff] [blame] | 596 | |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 597 | /* Determine initial transfer parameters */ |
| 598 | sdaddr = address & SBSDIO_SB_OFT_ADDR_MASK; |
| 599 | if ((sdaddr + size) & SBSDIO_SBWINDOW_MASK) |
| 600 | dsize = (SBSDIO_SB_OFT_ADDR_LIMIT - sdaddr); |
| 601 | else |
| 602 | dsize = size; |
Arend van Spriel | 4c6e869 | 2011-11-22 17:21:40 -0800 | [diff] [blame] | 603 | |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 604 | sdio_claim_host(sdiodev->func[1]); |
Arend van Spriel | 4c6e869 | 2011-11-22 17:21:40 -0800 | [diff] [blame] | 605 | |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 606 | /* Do the transfer(s) */ |
| 607 | while (size) { |
| 608 | /* Set the backplane window to include the start address */ |
| 609 | bcmerror = brcmf_sdcard_set_sbaddr_window(sdiodev, address); |
| 610 | if (bcmerror) |
| 611 | break; |
Arend van Spriel | 4c6e869 | 2011-11-22 17:21:40 -0800 | [diff] [blame] | 612 | |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 613 | brcmf_dbg(SDIO, "%s %d bytes at offset 0x%08x in window 0x%08x\n", |
| 614 | write ? "write" : "read", dsize, |
| 615 | sdaddr, address & SBSDIO_SBWINDOW_MASK); |
| 616 | |
| 617 | sdaddr &= SBSDIO_SB_OFT_ADDR_MASK; |
| 618 | sdaddr |= SBSDIO_SB_ACCESS_2_4B_FLAG; |
| 619 | |
| 620 | skb_put(pkt, dsize); |
| 621 | if (write) |
| 622 | memcpy(pkt->data, data, dsize); |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 623 | skb_queue_tail(&pkt_list, pkt); |
Franky Lin | 78b3f1c | 2013-06-18 13:29:28 +0200 | [diff] [blame] | 624 | bcmerror = brcmf_sdio_buffrw(sdiodev, SDIO_FUNC_1, write, |
Franky Lin | 354b75b | 2013-06-18 13:29:29 +0200 | [diff] [blame] | 625 | sdaddr, &pkt_list); |
| 626 | skb_dequeue_tail(&pkt_list); |
Franky Lin | ba540b0 | 2013-04-11 13:28:47 +0200 | [diff] [blame] | 627 | if (bcmerror) { |
| 628 | brcmf_err("membytes transfer failed\n"); |
| 629 | break; |
| 630 | } |
| 631 | if (!write) |
| 632 | memcpy(data, pkt->data, dsize); |
| 633 | skb_trim(pkt, dsize); |
| 634 | |
| 635 | /* Adjust for next transfer (if any) */ |
| 636 | size -= dsize; |
| 637 | if (size) { |
| 638 | data += dsize; |
| 639 | address += dsize; |
| 640 | sdaddr = 0; |
| 641 | dsize = min_t(uint, SBSDIO_SB_OFT_ADDR_LIMIT, size); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | dev_kfree_skb(pkt); |
| 646 | |
| 647 | /* Return the window to backplane enumeration space for core access */ |
| 648 | if (brcmf_sdcard_set_sbaddr_window(sdiodev, sdiodev->sbwad)) |
| 649 | brcmf_err("FAILED to set window back to 0x%x\n", |
| 650 | sdiodev->sbwad); |
| 651 | |
| 652 | sdio_release_host(sdiodev->func[1]); |
| 653 | |
| 654 | return bcmerror; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | int brcmf_sdcard_abort(struct brcmf_sdio_dev *sdiodev, uint fn) |
| 658 | { |
| 659 | char t_func = (char)fn; |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 660 | brcmf_dbg(SDIO, "Enter\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 661 | |
| 662 | /* issue abort cmd52 command through F0 */ |
| 663 | brcmf_sdioh_request_byte(sdiodev, SDIOH_WRITE, SDIO_FUNC_0, |
| 664 | SDIO_CCCR_ABORT, &t_func); |
| 665 | |
Arend van Spriel | c320337 | 2013-04-03 12:40:44 +0200 | [diff] [blame] | 666 | brcmf_dbg(SDIO, "Exit\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | int brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev) |
| 671 | { |
| 672 | u32 regs = 0; |
| 673 | int ret = 0; |
| 674 | |
| 675 | ret = brcmf_sdioh_attach(sdiodev); |
| 676 | if (ret) |
| 677 | goto out; |
| 678 | |
| 679 | regs = SI_ENUM_BASE; |
| 680 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 681 | /* try to attach to the target device */ |
Franky Lin | 4175b88 | 2011-11-22 17:21:49 -0800 | [diff] [blame] | 682 | sdiodev->bus = brcmf_sdbrcm_probe(regs, sdiodev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 683 | if (!sdiodev->bus) { |
Arend van Spriel | 5e8149f | 2012-12-07 10:49:57 +0100 | [diff] [blame] | 684 | brcmf_err("device attach failed\n"); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 685 | ret = -ENODEV; |
| 686 | goto out; |
| 687 | } |
| 688 | |
| 689 | out: |
| 690 | if (ret) |
| 691 | brcmf_sdio_remove(sdiodev); |
| 692 | |
| 693 | return ret; |
| 694 | } |
| 695 | EXPORT_SYMBOL(brcmf_sdio_probe); |
| 696 | |
| 697 | int brcmf_sdio_remove(struct brcmf_sdio_dev *sdiodev) |
| 698 | { |
Hante Meuleman | 2def5c1 | 2012-11-14 18:46:19 -0800 | [diff] [blame] | 699 | sdiodev->bus_if->state = BRCMF_BUS_DOWN; |
| 700 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 701 | if (sdiodev->bus) { |
| 702 | brcmf_sdbrcm_disconnect(sdiodev->bus); |
| 703 | sdiodev->bus = NULL; |
| 704 | } |
| 705 | |
| 706 | brcmf_sdioh_detach(sdiodev); |
| 707 | |
| 708 | sdiodev->sbwad = 0; |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | EXPORT_SYMBOL(brcmf_sdio_remove); |
| 713 | |
| 714 | void brcmf_sdio_wdtmr_enable(struct brcmf_sdio_dev *sdiodev, bool enable) |
| 715 | { |
| 716 | if (enable) |
| 717 | brcmf_sdbrcm_wd_timer(sdiodev->bus, BRCMF_WD_POLL_MS); |
| 718 | else |
| 719 | brcmf_sdbrcm_wd_timer(sdiodev->bus, 0); |
| 720 | } |