Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Marvell BT-over-SDIO driver: SDIO interface related functions. |
| 3 | * |
| 4 | * Copyright (C) 2009, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * |
| 15 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 17 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 18 | * this warranty disclaimer. |
| 19 | **/ |
| 20 | |
| 21 | #include <linux/firmware.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include <linux/mmc/sdio_ids.h> |
| 25 | #include <linux/mmc/sdio_func.h> |
Paul Gortmaker | a59b968 | 2011-08-29 16:44:23 -0400 | [diff] [blame] | 26 | #include <linux/module.h> |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include <net/bluetooth/bluetooth.h> |
| 29 | #include <net/bluetooth/hci_core.h> |
| 30 | |
| 31 | #include "btmrvl_drv.h" |
| 32 | #include "btmrvl_sdio.h" |
| 33 | |
| 34 | #define VERSION "1.0" |
| 35 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 36 | /* The btmrvl_sdio_remove() callback function is called |
| 37 | * when user removes this module from kernel space or ejects |
| 38 | * the card from the slot. The driver handles these 2 cases |
| 39 | * differently. |
| 40 | * If the user is removing the module, a MODULE_SHUTDOWN_REQ |
| 41 | * command is sent to firmware and interrupt will be disabled. |
| 42 | * If the card is removed, there is no need to send command |
| 43 | * or disable interrupt. |
| 44 | * |
| 45 | * The variable 'user_rmmod' is used to distinguish these two |
| 46 | * scenarios. This flag is initialized as FALSE in case the card |
| 47 | * is removed, and will be set to TRUE for module removal when |
| 48 | * module_exit function is called. |
| 49 | */ |
| 50 | static u8 user_rmmod; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 51 | static u8 sdio_ireg; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 52 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 53 | static const struct btmrvl_sdio_card_reg btmrvl_reg_8688 = { |
| 54 | .cfg = 0x03, |
| 55 | .host_int_mask = 0x04, |
| 56 | .host_intstatus = 0x05, |
| 57 | .card_status = 0x20, |
| 58 | .sq_read_base_addr_a0 = 0x10, |
| 59 | .sq_read_base_addr_a1 = 0x11, |
| 60 | .card_fw_status0 = 0x40, |
| 61 | .card_fw_status1 = 0x41, |
| 62 | .card_rx_len = 0x42, |
| 63 | .card_rx_unit = 0x43, |
| 64 | .io_port_0 = 0x00, |
| 65 | .io_port_1 = 0x01, |
| 66 | .io_port_2 = 0x02, |
| 67 | }; |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 68 | static const struct btmrvl_sdio_card_reg btmrvl_reg_87xx = { |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 69 | .cfg = 0x00, |
| 70 | .host_int_mask = 0x02, |
| 71 | .host_intstatus = 0x03, |
| 72 | .card_status = 0x30, |
| 73 | .sq_read_base_addr_a0 = 0x40, |
| 74 | .sq_read_base_addr_a1 = 0x41, |
| 75 | .card_revision = 0x5c, |
| 76 | .card_fw_status0 = 0x60, |
| 77 | .card_fw_status1 = 0x61, |
| 78 | .card_rx_len = 0x62, |
| 79 | .card_rx_unit = 0x63, |
| 80 | .io_port_0 = 0x78, |
| 81 | .io_port_1 = 0x79, |
| 82 | .io_port_2 = 0x7a, |
| 83 | }; |
| 84 | |
Paul Bolle | c675786 | 2011-10-05 14:56:46 +0200 | [diff] [blame] | 85 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8688 = { |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 86 | .helper = "sd8688_helper.bin", |
| 87 | .firmware = "sd8688.bin", |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 88 | .reg = &btmrvl_reg_8688, |
| 89 | .sd_blksz_fw_dl = 64, |
| 90 | }; |
| 91 | |
| 92 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8787 = { |
| 93 | .helper = NULL, |
| 94 | .firmware = "mrvl/sd8787_uapsta.bin", |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 95 | .reg = &btmrvl_reg_87xx, |
| 96 | .sd_blksz_fw_dl = 256, |
| 97 | }; |
| 98 | |
| 99 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8797 = { |
| 100 | .helper = NULL, |
| 101 | .firmware = "mrvl/sd8797_uapsta.bin", |
| 102 | .reg = &btmrvl_reg_87xx, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 103 | .sd_blksz_fw_dl = 256, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 104 | }; |
| 105 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 106 | static const struct sdio_device_id btmrvl_sdio_ids[] = { |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 107 | /* Marvell SD8688 Bluetooth device */ |
| 108 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x9105), |
Paul Bolle | c675786 | 2011-10-05 14:56:46 +0200 | [diff] [blame] | 109 | .driver_data = (unsigned long) &btmrvl_sdio_sd8688 }, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 110 | /* Marvell SD8787 Bluetooth device */ |
| 111 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x911A), |
| 112 | .driver_data = (unsigned long) &btmrvl_sdio_sd8787 }, |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 113 | /* Marvell SD8797 Bluetooth device */ |
| 114 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x912A), |
| 115 | .driver_data = (unsigned long) &btmrvl_sdio_sd8797 }, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 116 | |
| 117 | { } /* Terminating entry */ |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | MODULE_DEVICE_TABLE(sdio, btmrvl_sdio_ids); |
| 121 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 122 | static int btmrvl_sdio_get_rx_unit(struct btmrvl_sdio_card *card) |
| 123 | { |
| 124 | u8 reg; |
| 125 | int ret; |
| 126 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 127 | reg = sdio_readb(card->func, card->reg->card_rx_unit, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 128 | if (!ret) |
| 129 | card->rx_unit = reg; |
| 130 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | static int btmrvl_sdio_read_fw_status(struct btmrvl_sdio_card *card, u16 *dat) |
| 135 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 136 | u8 fws0, fws1; |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 137 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 138 | |
| 139 | *dat = 0; |
| 140 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 141 | fws0 = sdio_readb(card->func, card->reg->card_fw_status0, &ret); |
Kulikov Vasiliy | 278be27 | 2010-07-05 12:01:22 +0400 | [diff] [blame] | 142 | if (ret) |
| 143 | return -EIO; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 144 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 145 | fws1 = sdio_readb(card->func, card->reg->card_fw_status1, &ret); |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 146 | if (ret) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 147 | return -EIO; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 148 | |
| 149 | *dat = (((u16) fws1) << 8) | fws0; |
| 150 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static int btmrvl_sdio_read_rx_len(struct btmrvl_sdio_card *card, u16 *dat) |
| 155 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 156 | u8 reg; |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 157 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 158 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 159 | reg = sdio_readb(card->func, card->reg->card_rx_len, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 160 | if (!ret) |
| 161 | *dat = (u16) reg << card->rx_unit; |
| 162 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | static int btmrvl_sdio_enable_host_int_mask(struct btmrvl_sdio_card *card, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 167 | u8 mask) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 168 | { |
| 169 | int ret; |
| 170 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 171 | sdio_writeb(card->func, mask, card->reg->host_int_mask, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 172 | if (ret) { |
| 173 | BT_ERR("Unable to enable the host interrupt!"); |
| 174 | ret = -EIO; |
| 175 | } |
| 176 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 177 | return ret; |
| 178 | } |
| 179 | |
| 180 | static int btmrvl_sdio_disable_host_int_mask(struct btmrvl_sdio_card *card, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 181 | u8 mask) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 182 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 183 | u8 host_int_mask; |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 184 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 185 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 186 | host_int_mask = sdio_readb(card->func, card->reg->host_int_mask, &ret); |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 187 | if (ret) |
| 188 | return -EIO; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 189 | |
| 190 | host_int_mask &= ~mask; |
| 191 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 192 | sdio_writeb(card->func, host_int_mask, card->reg->host_int_mask, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 193 | if (ret < 0) { |
| 194 | BT_ERR("Unable to disable the host interrupt!"); |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 195 | return -EIO; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 198 | return 0; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static int btmrvl_sdio_poll_card_status(struct btmrvl_sdio_card *card, u8 bits) |
| 202 | { |
| 203 | unsigned int tries; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 204 | u8 status; |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 205 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 206 | |
| 207 | for (tries = 0; tries < MAX_POLL_TRIES * 1000; tries++) { |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 208 | status = sdio_readb(card->func, card->reg->card_status, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 209 | if (ret) |
| 210 | goto failed; |
| 211 | if ((status & bits) == bits) |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 212 | return ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 213 | |
| 214 | udelay(1); |
| 215 | } |
| 216 | |
| 217 | ret = -ETIMEDOUT; |
| 218 | |
| 219 | failed: |
| 220 | BT_ERR("FAILED! ret=%d", ret); |
| 221 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | static int btmrvl_sdio_verify_fw_download(struct btmrvl_sdio_card *card, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 226 | int pollnum) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 227 | { |
| 228 | int ret = -ETIMEDOUT; |
| 229 | u16 firmwarestat; |
| 230 | unsigned int tries; |
| 231 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 232 | /* Wait for firmware to become ready */ |
| 233 | for (tries = 0; tries < pollnum; tries++) { |
| 234 | if (btmrvl_sdio_read_fw_status(card, &firmwarestat) < 0) |
| 235 | continue; |
| 236 | |
| 237 | if (firmwarestat == FIRMWARE_READY) { |
| 238 | ret = 0; |
| 239 | break; |
| 240 | } else { |
| 241 | msleep(10); |
| 242 | } |
| 243 | } |
| 244 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 245 | return ret; |
| 246 | } |
| 247 | |
| 248 | static int btmrvl_sdio_download_helper(struct btmrvl_sdio_card *card) |
| 249 | { |
| 250 | const struct firmware *fw_helper = NULL; |
| 251 | const u8 *helper = NULL; |
| 252 | int ret; |
| 253 | void *tmphlprbuf = NULL; |
| 254 | int tmphlprbufsz, hlprblknow, helperlen; |
| 255 | u8 *helperbuf; |
| 256 | u32 tx_len; |
| 257 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 258 | ret = request_firmware(&fw_helper, card->helper, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 259 | &card->func->dev); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 260 | if ((ret < 0) || !fw_helper) { |
| 261 | BT_ERR("request_firmware(helper) failed, error code = %d", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 262 | ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 263 | ret = -ENOENT; |
| 264 | goto done; |
| 265 | } |
| 266 | |
| 267 | helper = fw_helper->data; |
| 268 | helperlen = fw_helper->size; |
| 269 | |
| 270 | BT_DBG("Downloading helper image (%d bytes), block size %d bytes", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 271 | helperlen, SDIO_BLOCK_SIZE); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 272 | |
| 273 | tmphlprbufsz = ALIGN_SZ(BTM_UPLD_SIZE, BTSDIO_DMA_ALIGN); |
| 274 | |
Julia Lawall | f8df39f | 2010-05-13 22:02:03 +0200 | [diff] [blame] | 275 | tmphlprbuf = kzalloc(tmphlprbufsz, GFP_KERNEL); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 276 | if (!tmphlprbuf) { |
| 277 | BT_ERR("Unable to allocate buffer for helper." |
| 278 | " Terminating download"); |
| 279 | ret = -ENOMEM; |
| 280 | goto done; |
| 281 | } |
| 282 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 283 | helperbuf = (u8 *) ALIGN_ADDR(tmphlprbuf, BTSDIO_DMA_ALIGN); |
| 284 | |
| 285 | /* Perform helper data transfer */ |
| 286 | tx_len = (FIRMWARE_TRANSFER_NBLOCK * SDIO_BLOCK_SIZE) |
| 287 | - SDIO_HEADER_LEN; |
| 288 | hlprblknow = 0; |
| 289 | |
| 290 | do { |
| 291 | ret = btmrvl_sdio_poll_card_status(card, |
| 292 | CARD_IO_READY | DN_LD_CARD_RDY); |
| 293 | if (ret < 0) { |
| 294 | BT_ERR("Helper download poll status timeout @ %d", |
| 295 | hlprblknow); |
| 296 | goto done; |
| 297 | } |
| 298 | |
| 299 | /* Check if there is more data? */ |
| 300 | if (hlprblknow >= helperlen) |
| 301 | break; |
| 302 | |
| 303 | if (helperlen - hlprblknow < tx_len) |
| 304 | tx_len = helperlen - hlprblknow; |
| 305 | |
| 306 | /* Little-endian */ |
| 307 | helperbuf[0] = ((tx_len & 0x000000ff) >> 0); |
| 308 | helperbuf[1] = ((tx_len & 0x0000ff00) >> 8); |
| 309 | helperbuf[2] = ((tx_len & 0x00ff0000) >> 16); |
| 310 | helperbuf[3] = ((tx_len & 0xff000000) >> 24); |
| 311 | |
| 312 | memcpy(&helperbuf[SDIO_HEADER_LEN], &helper[hlprblknow], |
| 313 | tx_len); |
| 314 | |
| 315 | /* Now send the data */ |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 316 | ret = sdio_writesb(card->func, card->ioport, helperbuf, |
| 317 | FIRMWARE_TRANSFER_NBLOCK * SDIO_BLOCK_SIZE); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 318 | if (ret < 0) { |
| 319 | BT_ERR("IO error during helper download @ %d", |
| 320 | hlprblknow); |
| 321 | goto done; |
| 322 | } |
| 323 | |
| 324 | hlprblknow += tx_len; |
| 325 | } while (true); |
| 326 | |
| 327 | BT_DBG("Transferring helper image EOF block"); |
| 328 | |
| 329 | memset(helperbuf, 0x0, SDIO_BLOCK_SIZE); |
| 330 | |
| 331 | ret = sdio_writesb(card->func, card->ioport, helperbuf, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 332 | SDIO_BLOCK_SIZE); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 333 | if (ret < 0) { |
| 334 | BT_ERR("IO error in writing helper image EOF block"); |
| 335 | goto done; |
| 336 | } |
| 337 | |
| 338 | ret = 0; |
| 339 | |
| 340 | done: |
| 341 | kfree(tmphlprbuf); |
Jesper Juhl | 59f34fb | 2012-04-09 22:49:49 +0200 | [diff] [blame] | 342 | release_firmware(fw_helper); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 343 | return ret; |
| 344 | } |
| 345 | |
| 346 | static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card) |
| 347 | { |
| 348 | const struct firmware *fw_firmware = NULL; |
| 349 | const u8 *firmware = NULL; |
| 350 | int firmwarelen, tmpfwbufsz, ret; |
| 351 | unsigned int tries, offset; |
| 352 | u8 base0, base1; |
| 353 | void *tmpfwbuf = NULL; |
| 354 | u8 *fwbuf; |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 355 | u16 len, blksz_dl = card->sd_blksz_fw_dl; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 356 | int txlen = 0, tx_blocks = 0, count = 0; |
| 357 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 358 | ret = request_firmware(&fw_firmware, card->firmware, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 359 | &card->func->dev); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 360 | if ((ret < 0) || !fw_firmware) { |
| 361 | BT_ERR("request_firmware(firmware) failed, error code = %d", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 362 | ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 363 | ret = -ENOENT; |
| 364 | goto done; |
| 365 | } |
| 366 | |
| 367 | firmware = fw_firmware->data; |
| 368 | firmwarelen = fw_firmware->size; |
| 369 | |
| 370 | BT_DBG("Downloading FW image (%d bytes)", firmwarelen); |
| 371 | |
| 372 | tmpfwbufsz = ALIGN_SZ(BTM_UPLD_SIZE, BTSDIO_DMA_ALIGN); |
Julia Lawall | f8df39f | 2010-05-13 22:02:03 +0200 | [diff] [blame] | 373 | tmpfwbuf = kzalloc(tmpfwbufsz, GFP_KERNEL); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 374 | if (!tmpfwbuf) { |
| 375 | BT_ERR("Unable to allocate buffer for firmware." |
| 376 | " Terminating download"); |
| 377 | ret = -ENOMEM; |
| 378 | goto done; |
| 379 | } |
| 380 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 381 | /* Ensure aligned firmware buffer */ |
| 382 | fwbuf = (u8 *) ALIGN_ADDR(tmpfwbuf, BTSDIO_DMA_ALIGN); |
| 383 | |
| 384 | /* Perform firmware data transfer */ |
| 385 | offset = 0; |
| 386 | do { |
| 387 | ret = btmrvl_sdio_poll_card_status(card, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 388 | CARD_IO_READY | DN_LD_CARD_RDY); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 389 | if (ret < 0) { |
| 390 | BT_ERR("FW download with helper poll status" |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 391 | " timeout @ %d", offset); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 392 | goto done; |
| 393 | } |
| 394 | |
| 395 | /* Check if there is more data ? */ |
| 396 | if (offset >= firmwarelen) |
| 397 | break; |
| 398 | |
| 399 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { |
| 400 | base0 = sdio_readb(card->func, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 401 | card->reg->sq_read_base_addr_a0, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 402 | if (ret) { |
| 403 | BT_ERR("BASE0 register read failed:" |
| 404 | " base0 = 0x%04X(%d)." |
| 405 | " Terminating download", |
| 406 | base0, base0); |
| 407 | ret = -EIO; |
| 408 | goto done; |
| 409 | } |
| 410 | base1 = sdio_readb(card->func, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 411 | card->reg->sq_read_base_addr_a1, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 412 | if (ret) { |
| 413 | BT_ERR("BASE1 register read failed:" |
| 414 | " base1 = 0x%04X(%d)." |
| 415 | " Terminating download", |
| 416 | base1, base1); |
| 417 | ret = -EIO; |
| 418 | goto done; |
| 419 | } |
| 420 | |
| 421 | len = (((u16) base1) << 8) | base0; |
| 422 | if (len) |
| 423 | break; |
| 424 | |
| 425 | udelay(10); |
| 426 | } |
| 427 | |
| 428 | if (!len) |
| 429 | break; |
| 430 | else if (len > BTM_UPLD_SIZE) { |
| 431 | BT_ERR("FW download failure @%d, invalid length %d", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 432 | offset, len); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 433 | ret = -EINVAL; |
| 434 | goto done; |
| 435 | } |
| 436 | |
| 437 | txlen = len; |
| 438 | |
| 439 | if (len & BIT(0)) { |
| 440 | count++; |
| 441 | if (count > MAX_WRITE_IOMEM_RETRY) { |
| 442 | BT_ERR("FW download failure @%d, " |
| 443 | "over max retry count", offset); |
| 444 | ret = -EIO; |
| 445 | goto done; |
| 446 | } |
| 447 | BT_ERR("FW CRC error indicated by the helper: " |
| 448 | "len = 0x%04X, txlen = %d", len, txlen); |
| 449 | len &= ~BIT(0); |
| 450 | /* Set txlen to 0 so as to resend from same offset */ |
| 451 | txlen = 0; |
| 452 | } else { |
| 453 | count = 0; |
| 454 | |
| 455 | /* Last block ? */ |
| 456 | if (firmwarelen - offset < txlen) |
| 457 | txlen = firmwarelen - offset; |
| 458 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 459 | tx_blocks = (txlen + blksz_dl - 1) / blksz_dl; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 460 | |
| 461 | memcpy(fwbuf, &firmware[offset], txlen); |
| 462 | } |
| 463 | |
| 464 | ret = sdio_writesb(card->func, card->ioport, fwbuf, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 465 | tx_blocks * blksz_dl); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 466 | |
| 467 | if (ret < 0) { |
| 468 | BT_ERR("FW download, writesb(%d) failed @%d", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 469 | count, offset); |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 470 | sdio_writeb(card->func, HOST_CMD53_FIN, |
| 471 | card->reg->cfg, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 472 | if (ret) |
| 473 | BT_ERR("writeb failed (CFG)"); |
| 474 | } |
| 475 | |
| 476 | offset += txlen; |
| 477 | } while (true); |
| 478 | |
| 479 | BT_DBG("FW download over, size %d bytes", offset); |
| 480 | |
| 481 | ret = 0; |
| 482 | |
| 483 | done: |
| 484 | kfree(tmpfwbuf); |
Jesper Juhl | 59f34fb | 2012-04-09 22:49:49 +0200 | [diff] [blame] | 485 | release_firmware(fw_firmware); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 486 | return ret; |
| 487 | } |
| 488 | |
| 489 | static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv) |
| 490 | { |
| 491 | u16 buf_len = 0; |
| 492 | int ret, buf_block_len, blksz; |
| 493 | struct sk_buff *skb = NULL; |
| 494 | u32 type; |
| 495 | u8 *payload = NULL; |
| 496 | struct hci_dev *hdev = priv->btmrvl_dev.hcidev; |
| 497 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 498 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 499 | if (!card || !card->func) { |
| 500 | BT_ERR("card or function is NULL!"); |
| 501 | ret = -EINVAL; |
| 502 | goto exit; |
| 503 | } |
| 504 | |
| 505 | /* Read the length of data to be transferred */ |
| 506 | ret = btmrvl_sdio_read_rx_len(card, &buf_len); |
| 507 | if (ret < 0) { |
| 508 | BT_ERR("read rx_len failed"); |
| 509 | ret = -EIO; |
| 510 | goto exit; |
| 511 | } |
| 512 | |
| 513 | blksz = SDIO_BLOCK_SIZE; |
| 514 | buf_block_len = (buf_len + blksz - 1) / blksz; |
| 515 | |
| 516 | if (buf_len <= SDIO_HEADER_LEN |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 517 | || (buf_block_len * blksz) > ALLOC_BUF_SIZE) { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 518 | BT_ERR("invalid packet length: %d", buf_len); |
| 519 | ret = -EINVAL; |
| 520 | goto exit; |
| 521 | } |
| 522 | |
| 523 | /* Allocate buffer */ |
| 524 | skb = bt_skb_alloc(buf_block_len * blksz + BTSDIO_DMA_ALIGN, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 525 | GFP_ATOMIC); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 526 | if (skb == NULL) { |
| 527 | BT_ERR("No free skb"); |
| 528 | goto exit; |
| 529 | } |
| 530 | |
Bing Zhao | 3318b23 | 2009-07-08 11:44:14 -0700 | [diff] [blame] | 531 | if ((unsigned long) skb->data & (BTSDIO_DMA_ALIGN - 1)) { |
| 532 | skb_put(skb, (unsigned long) skb->data & |
| 533 | (BTSDIO_DMA_ALIGN - 1)); |
| 534 | skb_pull(skb, (unsigned long) skb->data & |
| 535 | (BTSDIO_DMA_ALIGN - 1)); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Bing Zhao | 3318b23 | 2009-07-08 11:44:14 -0700 | [diff] [blame] | 538 | payload = skb->data; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 539 | |
| 540 | ret = sdio_readsb(card->func, payload, card->ioport, |
| 541 | buf_block_len * blksz); |
| 542 | if (ret < 0) { |
| 543 | BT_ERR("readsb failed: %d", ret); |
| 544 | ret = -EIO; |
| 545 | goto exit; |
| 546 | } |
| 547 | |
| 548 | /* This is SDIO specific header length: byte[2][1][0], type: byte[3] |
| 549 | * (HCI_COMMAND = 1, ACL_DATA = 2, SCO_DATA = 3, 0xFE = Vendor) |
| 550 | */ |
| 551 | |
| 552 | buf_len = payload[0]; |
| 553 | buf_len |= (u16) payload[1] << 8; |
| 554 | type = payload[3]; |
| 555 | |
| 556 | switch (type) { |
| 557 | case HCI_ACLDATA_PKT: |
| 558 | case HCI_SCODATA_PKT: |
| 559 | case HCI_EVENT_PKT: |
| 560 | bt_cb(skb)->pkt_type = type; |
| 561 | skb->dev = (void *)hdev; |
| 562 | skb_put(skb, buf_len); |
| 563 | skb_pull(skb, SDIO_HEADER_LEN); |
| 564 | |
| 565 | if (type == HCI_EVENT_PKT) |
| 566 | btmrvl_check_evtpkt(priv, skb); |
| 567 | |
| 568 | hci_recv_frame(skb); |
| 569 | hdev->stat.byte_rx += buf_len; |
| 570 | break; |
| 571 | |
| 572 | case MRVL_VENDOR_PKT: |
| 573 | bt_cb(skb)->pkt_type = HCI_VENDOR_PKT; |
| 574 | skb->dev = (void *)hdev; |
| 575 | skb_put(skb, buf_len); |
| 576 | skb_pull(skb, SDIO_HEADER_LEN); |
| 577 | |
| 578 | if (btmrvl_process_event(priv, skb)) |
| 579 | hci_recv_frame(skb); |
| 580 | |
| 581 | hdev->stat.byte_rx += buf_len; |
| 582 | break; |
| 583 | |
| 584 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 585 | BT_ERR("Unknown packet type:%d", type); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 586 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, payload, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 587 | blksz * buf_block_len); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 588 | |
| 589 | kfree_skb(skb); |
| 590 | skb = NULL; |
| 591 | break; |
| 592 | } |
| 593 | |
| 594 | exit: |
| 595 | if (ret) { |
| 596 | hdev->stat.err_rx++; |
| 597 | if (skb) |
| 598 | kfree_skb(skb); |
| 599 | } |
| 600 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 601 | return ret; |
| 602 | } |
| 603 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 604 | static int btmrvl_sdio_process_int_status(struct btmrvl_private *priv) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 605 | { |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 606 | ulong flags; |
| 607 | u8 ireg; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 608 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 609 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 610 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 611 | ireg = sdio_ireg; |
| 612 | sdio_ireg = 0; |
| 613 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 614 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 615 | sdio_claim_host(card->func); |
| 616 | if (ireg & DN_LD_HOST_INT_STATUS) { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 617 | if (priv->btmrvl_dev.tx_dnld_rdy) |
| 618 | BT_DBG("tx_done already received: " |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 619 | " int_status=0x%x", ireg); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 620 | else |
| 621 | priv->btmrvl_dev.tx_dnld_rdy = true; |
| 622 | } |
| 623 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 624 | if (ireg & UP_LD_HOST_INT_STATUS) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 625 | btmrvl_sdio_card_to_host(priv); |
| 626 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 627 | sdio_release_host(card->func); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 628 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 629 | return 0; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | static void btmrvl_sdio_interrupt(struct sdio_func *func) |
| 633 | { |
| 634 | struct btmrvl_private *priv; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 635 | struct btmrvl_sdio_card *card; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 636 | ulong flags; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 637 | u8 ireg = 0; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 638 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 639 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 640 | card = sdio_get_drvdata(func); |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 641 | if (!card || !card->priv) { |
| 642 | BT_ERR("sbi_interrupt(%p) card or priv is " |
| 643 | "NULL, card=%p\n", func, card); |
| 644 | return; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 645 | } |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 646 | |
| 647 | priv = card->priv; |
| 648 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 649 | ireg = sdio_readb(card->func, card->reg->host_intstatus, &ret); |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 650 | if (ret) { |
| 651 | BT_ERR("sdio_readb: read int status register failed"); |
| 652 | return; |
| 653 | } |
| 654 | |
| 655 | if (ireg != 0) { |
| 656 | /* |
| 657 | * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS |
| 658 | * Clear the interrupt status register and re-enable the |
| 659 | * interrupt. |
| 660 | */ |
| 661 | BT_DBG("ireg = 0x%x", ireg); |
| 662 | |
| 663 | sdio_writeb(card->func, ~(ireg) & (DN_LD_HOST_INT_STATUS | |
| 664 | UP_LD_HOST_INT_STATUS), |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 665 | card->reg->host_intstatus, &ret); |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 666 | if (ret) { |
| 667 | BT_ERR("sdio_writeb: clear int status register failed"); |
| 668 | return; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 673 | sdio_ireg |= ireg; |
| 674 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 675 | |
| 676 | btmrvl_interrupt(priv); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card) |
| 680 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 681 | struct sdio_func *func; |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 682 | u8 reg; |
| 683 | int ret = 0; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 684 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 685 | if (!card || !card->func) { |
| 686 | BT_ERR("Error: card or function is NULL!"); |
| 687 | ret = -EINVAL; |
| 688 | goto failed; |
| 689 | } |
| 690 | |
| 691 | func = card->func; |
| 692 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 693 | sdio_claim_host(func); |
| 694 | |
| 695 | ret = sdio_enable_func(func); |
| 696 | if (ret) { |
| 697 | BT_ERR("sdio_enable_func() failed: ret=%d", ret); |
| 698 | ret = -EIO; |
| 699 | goto release_host; |
| 700 | } |
| 701 | |
| 702 | ret = sdio_claim_irq(func, btmrvl_sdio_interrupt); |
| 703 | if (ret) { |
| 704 | BT_ERR("sdio_claim_irq failed: ret=%d", ret); |
| 705 | ret = -EIO; |
| 706 | goto disable_func; |
| 707 | } |
| 708 | |
| 709 | ret = sdio_set_block_size(card->func, SDIO_BLOCK_SIZE); |
| 710 | if (ret) { |
| 711 | BT_ERR("cannot set SDIO block size"); |
| 712 | ret = -EIO; |
| 713 | goto release_irq; |
| 714 | } |
| 715 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 716 | reg = sdio_readb(func, card->reg->io_port_0, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 717 | if (ret < 0) { |
| 718 | ret = -EIO; |
| 719 | goto release_irq; |
| 720 | } |
| 721 | |
| 722 | card->ioport = reg; |
| 723 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 724 | reg = sdio_readb(func, card->reg->io_port_1, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 725 | if (ret < 0) { |
| 726 | ret = -EIO; |
| 727 | goto release_irq; |
| 728 | } |
| 729 | |
| 730 | card->ioport |= (reg << 8); |
| 731 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 732 | reg = sdio_readb(func, card->reg->io_port_2, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 733 | if (ret < 0) { |
| 734 | ret = -EIO; |
| 735 | goto release_irq; |
| 736 | } |
| 737 | |
| 738 | card->ioport |= (reg << 16); |
| 739 | |
| 740 | BT_DBG("SDIO FUNC%d IO port: 0x%x", func->num, card->ioport); |
| 741 | |
| 742 | sdio_set_drvdata(func, card); |
| 743 | |
| 744 | sdio_release_host(func); |
| 745 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 746 | return 0; |
| 747 | |
| 748 | release_irq: |
| 749 | sdio_release_irq(func); |
| 750 | |
| 751 | disable_func: |
| 752 | sdio_disable_func(func); |
| 753 | |
| 754 | release_host: |
| 755 | sdio_release_host(func); |
| 756 | |
| 757 | failed: |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 758 | return ret; |
| 759 | } |
| 760 | |
| 761 | static int btmrvl_sdio_unregister_dev(struct btmrvl_sdio_card *card) |
| 762 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 763 | if (card && card->func) { |
| 764 | sdio_claim_host(card->func); |
| 765 | sdio_release_irq(card->func); |
| 766 | sdio_disable_func(card->func); |
| 767 | sdio_release_host(card->func); |
| 768 | sdio_set_drvdata(card->func, NULL); |
| 769 | } |
| 770 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | static int btmrvl_sdio_enable_host_int(struct btmrvl_sdio_card *card) |
| 775 | { |
| 776 | int ret; |
| 777 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 778 | if (!card || !card->func) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 779 | return -EINVAL; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 780 | |
| 781 | sdio_claim_host(card->func); |
| 782 | |
| 783 | ret = btmrvl_sdio_enable_host_int_mask(card, HIM_ENABLE); |
| 784 | |
| 785 | btmrvl_sdio_get_rx_unit(card); |
| 786 | |
| 787 | sdio_release_host(card->func); |
| 788 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 789 | return ret; |
| 790 | } |
| 791 | |
| 792 | static int btmrvl_sdio_disable_host_int(struct btmrvl_sdio_card *card) |
| 793 | { |
| 794 | int ret; |
| 795 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 796 | if (!card || !card->func) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 797 | return -EINVAL; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 798 | |
| 799 | sdio_claim_host(card->func); |
| 800 | |
| 801 | ret = btmrvl_sdio_disable_host_int_mask(card, HIM_DISABLE); |
| 802 | |
| 803 | sdio_release_host(card->func); |
| 804 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 805 | return ret; |
| 806 | } |
| 807 | |
| 808 | static int btmrvl_sdio_host_to_card(struct btmrvl_private *priv, |
| 809 | u8 *payload, u16 nb) |
| 810 | { |
| 811 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 812 | int ret = 0; |
| 813 | int buf_block_len; |
| 814 | int blksz; |
| 815 | int i = 0; |
| 816 | u8 *buf = NULL; |
| 817 | void *tmpbuf = NULL; |
| 818 | int tmpbufsz; |
| 819 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 820 | if (!card || !card->func) { |
| 821 | BT_ERR("card or function is NULL!"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 822 | return -EINVAL; |
| 823 | } |
| 824 | |
| 825 | buf = payload; |
Bing Zhao | 3318b23 | 2009-07-08 11:44:14 -0700 | [diff] [blame] | 826 | if ((unsigned long) payload & (BTSDIO_DMA_ALIGN - 1)) { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 827 | tmpbufsz = ALIGN_SZ(nb, BTSDIO_DMA_ALIGN); |
Julia Lawall | 5959809 | 2009-08-06 22:05:18 +0200 | [diff] [blame] | 828 | tmpbuf = kzalloc(tmpbufsz, GFP_KERNEL); |
| 829 | if (!tmpbuf) |
| 830 | return -ENOMEM; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 831 | buf = (u8 *) ALIGN_ADDR(tmpbuf, BTSDIO_DMA_ALIGN); |
| 832 | memcpy(buf, payload, nb); |
| 833 | } |
| 834 | |
| 835 | blksz = SDIO_BLOCK_SIZE; |
| 836 | buf_block_len = (nb + blksz - 1) / blksz; |
| 837 | |
| 838 | sdio_claim_host(card->func); |
| 839 | |
| 840 | do { |
| 841 | /* Transfer data to card */ |
| 842 | ret = sdio_writesb(card->func, card->ioport, buf, |
| 843 | buf_block_len * blksz); |
| 844 | if (ret < 0) { |
| 845 | i++; |
| 846 | BT_ERR("i=%d writesb failed: %d", i, ret); |
| 847 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, |
| 848 | payload, nb); |
| 849 | ret = -EIO; |
| 850 | if (i > MAX_WRITE_IOMEM_RETRY) |
| 851 | goto exit; |
| 852 | } |
| 853 | } while (ret); |
| 854 | |
| 855 | priv->btmrvl_dev.tx_dnld_rdy = false; |
| 856 | |
| 857 | exit: |
| 858 | sdio_release_host(card->func); |
Yoichi Yuasa | 88d1a0c | 2010-02-04 09:55:51 +0900 | [diff] [blame] | 859 | kfree(tmpbuf); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 860 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 861 | return ret; |
| 862 | } |
| 863 | |
| 864 | static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card *card) |
| 865 | { |
| 866 | int ret = 0; |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 867 | u8 fws0; |
| 868 | int pollnum = MAX_POLL_TRIES; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 869 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 870 | if (!card || !card->func) { |
| 871 | BT_ERR("card or function is NULL!"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 872 | return -EINVAL; |
| 873 | } |
| 874 | sdio_claim_host(card->func); |
| 875 | |
| 876 | if (!btmrvl_sdio_verify_fw_download(card, 1)) { |
| 877 | BT_DBG("Firmware already downloaded!"); |
| 878 | goto done; |
| 879 | } |
| 880 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 881 | /* Check if other function driver is downloading the firmware */ |
| 882 | fws0 = sdio_readb(card->func, card->reg->card_fw_status0, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 883 | if (ret) { |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 884 | BT_ERR("Failed to read FW downloading status!"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 885 | ret = -EIO; |
| 886 | goto done; |
| 887 | } |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 888 | if (fws0) { |
| 889 | BT_DBG("BT not the winner (%#x). Skip FW downloading", fws0); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 890 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 891 | /* Give other function more time to download the firmware */ |
| 892 | pollnum *= 10; |
| 893 | } else { |
| 894 | if (card->helper) { |
| 895 | ret = btmrvl_sdio_download_helper(card); |
| 896 | if (ret) { |
| 897 | BT_ERR("Failed to download helper!"); |
| 898 | ret = -EIO; |
| 899 | goto done; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | if (btmrvl_sdio_download_fw_w_helper(card)) { |
| 904 | BT_ERR("Failed to download firmware!"); |
| 905 | ret = -EIO; |
| 906 | goto done; |
| 907 | } |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 910 | if (btmrvl_sdio_verify_fw_download(card, pollnum)) { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 911 | BT_ERR("FW failed to be active in time!"); |
| 912 | ret = -ETIMEDOUT; |
| 913 | goto done; |
| 914 | } |
| 915 | |
| 916 | done: |
| 917 | sdio_release_host(card->func); |
| 918 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 919 | return ret; |
| 920 | } |
| 921 | |
| 922 | static int btmrvl_sdio_wakeup_fw(struct btmrvl_private *priv) |
| 923 | { |
| 924 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 925 | int ret = 0; |
| 926 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 927 | if (!card || !card->func) { |
| 928 | BT_ERR("card or function is NULL!"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 929 | return -EINVAL; |
| 930 | } |
| 931 | |
| 932 | sdio_claim_host(card->func); |
| 933 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 934 | sdio_writeb(card->func, HOST_POWER_UP, card->reg->cfg, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 935 | |
| 936 | sdio_release_host(card->func); |
| 937 | |
| 938 | BT_DBG("wake up firmware"); |
| 939 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 940 | return ret; |
| 941 | } |
| 942 | |
| 943 | static int btmrvl_sdio_probe(struct sdio_func *func, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 944 | const struct sdio_device_id *id) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 945 | { |
| 946 | int ret = 0; |
| 947 | struct btmrvl_private *priv = NULL; |
| 948 | struct btmrvl_sdio_card *card = NULL; |
| 949 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 950 | BT_INFO("vendor=0x%x, device=0x%x, class=%d, fn=%d", |
| 951 | id->vendor, id->device, id->class, func->num); |
| 952 | |
| 953 | card = kzalloc(sizeof(*card), GFP_KERNEL); |
| 954 | if (!card) { |
| 955 | ret = -ENOMEM; |
| 956 | goto done; |
| 957 | } |
| 958 | |
| 959 | card->func = func; |
| 960 | |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 961 | if (id->driver_data) { |
| 962 | struct btmrvl_sdio_device *data = (void *) id->driver_data; |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 963 | card->helper = data->helper; |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 964 | card->firmware = data->firmware; |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 965 | card->reg = data->reg; |
| 966 | card->sd_blksz_fw_dl = data->sd_blksz_fw_dl; |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 967 | } |
| 968 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 969 | if (btmrvl_sdio_register_dev(card) < 0) { |
| 970 | BT_ERR("Failed to register BT device!"); |
| 971 | ret = -ENODEV; |
| 972 | goto free_card; |
| 973 | } |
| 974 | |
| 975 | /* Disable the interrupts on the card */ |
| 976 | btmrvl_sdio_disable_host_int(card); |
| 977 | |
| 978 | if (btmrvl_sdio_download_fw(card)) { |
| 979 | BT_ERR("Downloading firmware failed!"); |
| 980 | ret = -ENODEV; |
| 981 | goto unreg_dev; |
| 982 | } |
| 983 | |
| 984 | msleep(100); |
| 985 | |
| 986 | btmrvl_sdio_enable_host_int(card); |
| 987 | |
| 988 | priv = btmrvl_add_card(card); |
| 989 | if (!priv) { |
| 990 | BT_ERR("Initializing card failed!"); |
| 991 | ret = -ENODEV; |
| 992 | goto disable_host_int; |
| 993 | } |
| 994 | |
| 995 | card->priv = priv; |
| 996 | |
| 997 | /* Initialize the interface specific function pointers */ |
| 998 | priv->hw_host_to_card = btmrvl_sdio_host_to_card; |
| 999 | priv->hw_wakeup_firmware = btmrvl_sdio_wakeup_fw; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 1000 | priv->hw_process_int_status = btmrvl_sdio_process_int_status; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1001 | |
Bing Zhao | 6406160 | 2010-03-03 14:37:36 -0800 | [diff] [blame] | 1002 | if (btmrvl_register_hdev(priv)) { |
| 1003 | BT_ERR("Register hdev failed!"); |
| 1004 | ret = -ENODEV; |
| 1005 | goto disable_host_int; |
| 1006 | } |
| 1007 | |
Amitkumar Karwar | 32fd639 | 2009-09-30 11:18:30 -0700 | [diff] [blame] | 1008 | priv->btmrvl_dev.psmode = 1; |
| 1009 | btmrvl_enable_ps(priv); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1010 | |
Amitkumar Karwar | 2a8ff61 | 2012-04-24 16:31:40 -0700 | [diff] [blame] | 1011 | priv->btmrvl_dev.gpio_gap = 0xffff; |
| 1012 | btmrvl_send_hscfg_cmd(priv); |
| 1013 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1014 | return 0; |
| 1015 | |
| 1016 | disable_host_int: |
| 1017 | btmrvl_sdio_disable_host_int(card); |
| 1018 | unreg_dev: |
| 1019 | btmrvl_sdio_unregister_dev(card); |
| 1020 | free_card: |
| 1021 | kfree(card); |
| 1022 | done: |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1023 | return ret; |
| 1024 | } |
| 1025 | |
| 1026 | static void btmrvl_sdio_remove(struct sdio_func *func) |
| 1027 | { |
| 1028 | struct btmrvl_sdio_card *card; |
| 1029 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1030 | if (func) { |
| 1031 | card = sdio_get_drvdata(func); |
| 1032 | if (card) { |
| 1033 | /* Send SHUTDOWN command & disable interrupt |
| 1034 | * if user removes the module. |
| 1035 | */ |
| 1036 | if (user_rmmod) { |
| 1037 | btmrvl_send_module_cfg_cmd(card->priv, |
| 1038 | MODULE_SHUTDOWN_REQ); |
| 1039 | btmrvl_sdio_disable_host_int(card); |
| 1040 | } |
| 1041 | BT_DBG("unregester dev"); |
| 1042 | btmrvl_sdio_unregister_dev(card); |
| 1043 | btmrvl_remove_card(card->priv); |
| 1044 | kfree(card); |
| 1045 | } |
| 1046 | } |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1049 | static int btmrvl_sdio_suspend(struct device *dev) |
| 1050 | { |
| 1051 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 1052 | struct btmrvl_sdio_card *card; |
| 1053 | struct btmrvl_private *priv; |
| 1054 | mmc_pm_flag_t pm_flags; |
| 1055 | struct hci_dev *hcidev; |
| 1056 | |
| 1057 | if (func) { |
| 1058 | pm_flags = sdio_get_host_pm_caps(func); |
| 1059 | BT_DBG("%s: suspend: PM flags = 0x%x", sdio_func_id(func), |
| 1060 | pm_flags); |
| 1061 | if (!(pm_flags & MMC_PM_KEEP_POWER)) { |
| 1062 | BT_ERR("%s: cannot remain alive while suspended", |
| 1063 | sdio_func_id(func)); |
| 1064 | return -ENOSYS; |
| 1065 | } |
| 1066 | card = sdio_get_drvdata(func); |
| 1067 | if (!card || !card->priv) { |
| 1068 | BT_ERR("card or priv structure is not valid"); |
| 1069 | return 0; |
| 1070 | } |
| 1071 | } else { |
| 1072 | BT_ERR("sdio_func is not specified"); |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | priv = card->priv; |
| 1077 | |
| 1078 | if (priv->adapter->hs_state != HS_ACTIVATED) { |
| 1079 | if (btmrvl_enable_hs(priv)) { |
| 1080 | BT_ERR("HS not actived, suspend failed!"); |
| 1081 | return -EBUSY; |
| 1082 | } |
| 1083 | } |
| 1084 | hcidev = priv->btmrvl_dev.hcidev; |
| 1085 | BT_DBG("%s: SDIO suspend", hcidev->name); |
| 1086 | hci_suspend_dev(hcidev); |
| 1087 | skb_queue_purge(&priv->adapter->tx_queue); |
| 1088 | |
| 1089 | priv->adapter->is_suspended = true; |
| 1090 | |
| 1091 | /* We will keep the power when hs enabled successfully */ |
| 1092 | if (priv->adapter->hs_state == HS_ACTIVATED) { |
| 1093 | BT_DBG("suspend with MMC_PM_KEEP_POWER"); |
| 1094 | return sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); |
| 1095 | } else { |
| 1096 | BT_DBG("suspend without MMC_PM_KEEP_POWER"); |
| 1097 | return 0; |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | static int btmrvl_sdio_resume(struct device *dev) |
| 1102 | { |
| 1103 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 1104 | struct btmrvl_sdio_card *card; |
| 1105 | struct btmrvl_private *priv; |
| 1106 | mmc_pm_flag_t pm_flags; |
| 1107 | struct hci_dev *hcidev; |
| 1108 | |
| 1109 | if (func) { |
| 1110 | pm_flags = sdio_get_host_pm_caps(func); |
| 1111 | BT_DBG("%s: resume: PM flags = 0x%x", sdio_func_id(func), |
| 1112 | pm_flags); |
| 1113 | card = sdio_get_drvdata(func); |
| 1114 | if (!card || !card->priv) { |
| 1115 | BT_ERR("card or priv structure is not valid"); |
| 1116 | return 0; |
| 1117 | } |
| 1118 | } else { |
| 1119 | BT_ERR("sdio_func is not specified"); |
| 1120 | return 0; |
| 1121 | } |
| 1122 | priv = card->priv; |
| 1123 | |
| 1124 | if (!priv->adapter->is_suspended) { |
| 1125 | BT_DBG("device already resumed"); |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | priv->adapter->is_suspended = false; |
| 1130 | hcidev = priv->btmrvl_dev.hcidev; |
| 1131 | BT_DBG("%s: SDIO resume", hcidev->name); |
| 1132 | hci_resume_dev(hcidev); |
| 1133 | priv->hw_wakeup_firmware(priv); |
| 1134 | priv->adapter->hs_state = HS_DEACTIVATED; |
| 1135 | BT_DBG("%s: HS DEACTIVATED in resume!", hcidev->name); |
| 1136 | |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | static const struct dev_pm_ops btmrvl_sdio_pm_ops = { |
| 1141 | .suspend = btmrvl_sdio_suspend, |
| 1142 | .resume = btmrvl_sdio_resume, |
| 1143 | }; |
| 1144 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1145 | static struct sdio_driver bt_mrvl_sdio = { |
| 1146 | .name = "btmrvl_sdio", |
| 1147 | .id_table = btmrvl_sdio_ids, |
| 1148 | .probe = btmrvl_sdio_probe, |
| 1149 | .remove = btmrvl_sdio_remove, |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1150 | .drv = { |
| 1151 | .owner = THIS_MODULE, |
| 1152 | .pm = &btmrvl_sdio_pm_ops, |
| 1153 | } |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1154 | }; |
| 1155 | |
Peter Huewe | 8e5b230 | 2009-12-22 09:34:20 +0100 | [diff] [blame] | 1156 | static int __init btmrvl_sdio_init_module(void) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1157 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1158 | if (sdio_register_driver(&bt_mrvl_sdio) != 0) { |
| 1159 | BT_ERR("SDIO Driver Registration Failed"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1160 | return -ENODEV; |
| 1161 | } |
| 1162 | |
| 1163 | /* Clear the flag in case user removes the card. */ |
| 1164 | user_rmmod = 0; |
| 1165 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1166 | return 0; |
| 1167 | } |
| 1168 | |
Peter Huewe | 8e5b230 | 2009-12-22 09:34:20 +0100 | [diff] [blame] | 1169 | static void __exit btmrvl_sdio_exit_module(void) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1170 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1171 | /* Set the flag as user is removing this module. */ |
| 1172 | user_rmmod = 1; |
| 1173 | |
| 1174 | sdio_unregister_driver(&bt_mrvl_sdio); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | module_init(btmrvl_sdio_init_module); |
| 1178 | module_exit(btmrvl_sdio_exit_module); |
| 1179 | |
| 1180 | MODULE_AUTHOR("Marvell International Ltd."); |
Marcel Holtmann | 9666fb3 | 2009-06-09 21:45:04 +0200 | [diff] [blame] | 1181 | MODULE_DESCRIPTION("Marvell BT-over-SDIO driver ver " VERSION); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1182 | MODULE_VERSION(VERSION); |
| 1183 | MODULE_LICENSE("GPL v2"); |
Ben Hutchings | 2861453 | 2009-11-07 21:41:18 +0000 | [diff] [blame] | 1184 | MODULE_FIRMWARE("sd8688_helper.bin"); |
| 1185 | MODULE_FIRMWARE("sd8688.bin"); |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1186 | MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin"); |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 1187 | MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin"); |