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