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 | |
Bing Zhao | 433a938 | 2013-11-01 15:28:24 -0700 | [diff] [blame] | 21 | #include <linux/firmware.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Jeffy Chen | 17e41ea | 2017-02-24 14:24:30 +0800 | [diff] [blame] | 23 | #include <linux/suspend.h> |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include <linux/mmc/sdio_ids.h> |
| 26 | #include <linux/mmc/sdio_func.h> |
Paul Gortmaker | a59b968 | 2011-08-29 16:44:23 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 28 | #include <linux/devcoredump.h> |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <net/bluetooth/bluetooth.h> |
| 31 | #include <net/bluetooth/hci_core.h> |
| 32 | |
| 33 | #include "btmrvl_drv.h" |
| 34 | #include "btmrvl_sdio.h" |
| 35 | |
| 36 | #define VERSION "1.0" |
| 37 | |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 38 | static struct memory_type_mapping mem_type_mapping_tbl[] = { |
| 39 | {"ITCM", NULL, 0, 0xF0}, |
| 40 | {"DTCM", NULL, 0, 0xF1}, |
| 41 | {"SQRAM", NULL, 0, 0xF2}, |
| 42 | {"APU", NULL, 0, 0xF3}, |
| 43 | {"CIU", NULL, 0, 0xF4}, |
| 44 | {"ICU", NULL, 0, 0xF5}, |
| 45 | {"MAC", NULL, 0, 0xF6}, |
| 46 | {"EXT7", NULL, 0, 0xF7}, |
| 47 | {"EXT8", NULL, 0, 0xF8}, |
| 48 | {"EXT9", NULL, 0, 0xF9}, |
| 49 | {"EXT10", NULL, 0, 0xFA}, |
| 50 | {"EXT11", NULL, 0, 0xFB}, |
| 51 | {"EXT12", NULL, 0, 0xFC}, |
| 52 | {"EXT13", NULL, 0, 0xFD}, |
| 53 | {"EXTLAST", NULL, 0, 0xFE}, |
| 54 | }; |
| 55 | |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 56 | static const struct of_device_id btmrvl_sdio_of_match_table[] = { |
| 57 | { .compatible = "marvell,sd8897-bt" }, |
| 58 | { .compatible = "marvell,sd8997-bt" }, |
| 59 | { } |
| 60 | }; |
| 61 | |
| 62 | static irqreturn_t btmrvl_wake_irq_bt(int irq, void *priv) |
| 63 | { |
Jeffy Chen | 17e41ea | 2017-02-24 14:24:30 +0800 | [diff] [blame] | 64 | struct btmrvl_sdio_card *card = priv; |
Stefan Agner | 10004f8 | 2019-01-11 21:56:56 +0100 | [diff] [blame] | 65 | struct device *dev = &card->func->dev; |
Jeffy Chen | 17e41ea | 2017-02-24 14:24:30 +0800 | [diff] [blame] | 66 | struct btmrvl_plt_wake_cfg *cfg = card->plt_wake_cfg; |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 67 | |
Stefan Agner | 10004f8 | 2019-01-11 21:56:56 +0100 | [diff] [blame] | 68 | dev_info(dev, "wake by bt\n"); |
Xinming Hu | c8ba804 | 2017-03-31 14:32:32 +0800 | [diff] [blame] | 69 | cfg->wake_by_bt = true; |
| 70 | disable_irq_nosync(irq); |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 71 | |
Stefan Agner | 10004f8 | 2019-01-11 21:56:56 +0100 | [diff] [blame] | 72 | pm_wakeup_event(dev, 0); |
Jeffy Chen | 17e41ea | 2017-02-24 14:24:30 +0800 | [diff] [blame] | 73 | pm_system_wakeup(); |
| 74 | |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 75 | return IRQ_HANDLED; |
| 76 | } |
| 77 | |
| 78 | /* This function parses device tree node using mmc subnode devicetree API. |
| 79 | * The device node is saved in card->plt_of_node. |
| 80 | * If the device tree node exists and includes interrupts attributes, this |
| 81 | * function will request platform specific wakeup interrupt. |
| 82 | */ |
| 83 | static int btmrvl_sdio_probe_of(struct device *dev, |
| 84 | struct btmrvl_sdio_card *card) |
| 85 | { |
| 86 | struct btmrvl_plt_wake_cfg *cfg; |
| 87 | int ret; |
| 88 | |
| 89 | if (!dev->of_node || |
| 90 | !of_match_node(btmrvl_sdio_of_match_table, dev->of_node)) { |
Stefan Agner | 37c589e | 2019-01-11 21:56:57 +0100 | [diff] [blame] | 91 | dev_info(dev, "sdio device tree data not available\n"); |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 92 | return -1; |
| 93 | } |
| 94 | |
| 95 | card->plt_of_node = dev->of_node; |
| 96 | |
| 97 | card->plt_wake_cfg = devm_kzalloc(dev, sizeof(*card->plt_wake_cfg), |
| 98 | GFP_KERNEL); |
| 99 | cfg = card->plt_wake_cfg; |
| 100 | if (cfg && card->plt_of_node) { |
| 101 | cfg->irq_bt = irq_of_parse_and_map(card->plt_of_node, 0); |
| 102 | if (!cfg->irq_bt) { |
Arvind Yadav | 24a3a32 | 2017-09-25 13:07:39 +0530 | [diff] [blame] | 103 | dev_err(dev, "fail to parse irq_bt from device tree\n"); |
Jeffy Chen | fd1a88d | 2017-01-23 12:18:52 +0800 | [diff] [blame] | 104 | cfg->irq_bt = -1; |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 105 | } else { |
| 106 | ret = devm_request_irq(dev, cfg->irq_bt, |
| 107 | btmrvl_wake_irq_bt, |
Jeffy Chen | 17e41ea | 2017-02-24 14:24:30 +0800 | [diff] [blame] | 108 | 0, "bt_wake", card); |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 109 | if (ret) { |
| 110 | dev_err(dev, |
| 111 | "Failed to request irq_bt %d (%d)\n", |
| 112 | cfg->irq_bt, ret); |
| 113 | } |
Abhishek Pandit-Subedi | e660b35 | 2020-06-10 18:53:55 -0700 | [diff] [blame] | 114 | |
| 115 | /* Configure wakeup (enabled by default) */ |
| 116 | device_init_wakeup(dev, true); |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 117 | disable_irq(cfg->irq_bt); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 124 | /* The btmrvl_sdio_remove() callback function is called |
| 125 | * when user removes this module from kernel space or ejects |
| 126 | * the card from the slot. The driver handles these 2 cases |
| 127 | * differently. |
| 128 | * If the user is removing the module, a MODULE_SHUTDOWN_REQ |
| 129 | * command is sent to firmware and interrupt will be disabled. |
| 130 | * If the card is removed, there is no need to send command |
| 131 | * or disable interrupt. |
| 132 | * |
| 133 | * The variable 'user_rmmod' is used to distinguish these two |
| 134 | * scenarios. This flag is initialized as FALSE in case the card |
| 135 | * is removed, and will be set to TRUE for module removal when |
| 136 | * module_exit function is called. |
| 137 | */ |
| 138 | static u8 user_rmmod; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 139 | static u8 sdio_ireg; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 140 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 141 | static const struct btmrvl_sdio_card_reg btmrvl_reg_8688 = { |
| 142 | .cfg = 0x03, |
| 143 | .host_int_mask = 0x04, |
| 144 | .host_intstatus = 0x05, |
| 145 | .card_status = 0x20, |
| 146 | .sq_read_base_addr_a0 = 0x10, |
| 147 | .sq_read_base_addr_a1 = 0x11, |
| 148 | .card_fw_status0 = 0x40, |
| 149 | .card_fw_status1 = 0x41, |
| 150 | .card_rx_len = 0x42, |
| 151 | .card_rx_unit = 0x43, |
| 152 | .io_port_0 = 0x00, |
| 153 | .io_port_1 = 0x01, |
| 154 | .io_port_2 = 0x02, |
Bing Zhao | 0d36740 | 2014-03-28 14:54:39 -0700 | [diff] [blame] | 155 | .int_read_to_clear = false, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 156 | }; |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 157 | static const struct btmrvl_sdio_card_reg btmrvl_reg_87xx = { |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 158 | .cfg = 0x00, |
| 159 | .host_int_mask = 0x02, |
| 160 | .host_intstatus = 0x03, |
| 161 | .card_status = 0x30, |
| 162 | .sq_read_base_addr_a0 = 0x40, |
| 163 | .sq_read_base_addr_a1 = 0x41, |
| 164 | .card_revision = 0x5c, |
| 165 | .card_fw_status0 = 0x60, |
| 166 | .card_fw_status1 = 0x61, |
| 167 | .card_rx_len = 0x62, |
| 168 | .card_rx_unit = 0x63, |
| 169 | .io_port_0 = 0x78, |
| 170 | .io_port_1 = 0x79, |
| 171 | .io_port_2 = 0x7a, |
Bing Zhao | 0d36740 | 2014-03-28 14:54:39 -0700 | [diff] [blame] | 172 | .int_read_to_clear = false, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
Xinming Hu | 3907d55 | 2014-09-30 06:45:33 -0400 | [diff] [blame] | 175 | static const struct btmrvl_sdio_card_reg btmrvl_reg_8887 = { |
| 176 | .cfg = 0x00, |
| 177 | .host_int_mask = 0x08, |
| 178 | .host_intstatus = 0x0C, |
| 179 | .card_status = 0x5C, |
| 180 | .sq_read_base_addr_a0 = 0x6C, |
| 181 | .sq_read_base_addr_a1 = 0x6D, |
| 182 | .card_revision = 0xC8, |
| 183 | .card_fw_status0 = 0x88, |
| 184 | .card_fw_status1 = 0x89, |
| 185 | .card_rx_len = 0x8A, |
| 186 | .card_rx_unit = 0x8B, |
| 187 | .io_port_0 = 0xE4, |
| 188 | .io_port_1 = 0xE5, |
| 189 | .io_port_2 = 0xE6, |
| 190 | .int_read_to_clear = true, |
| 191 | .host_int_rsr = 0x04, |
| 192 | .card_misc_cfg = 0xD8, |
| 193 | }; |
| 194 | |
Amitkumar Karwar | 1e3e492 | 2014-09-30 06:45:32 -0400 | [diff] [blame] | 195 | static const struct btmrvl_sdio_card_reg btmrvl_reg_8897 = { |
Bing Zhao | 22f2efe | 2013-05-13 18:15:32 -0700 | [diff] [blame] | 196 | .cfg = 0x00, |
| 197 | .host_int_mask = 0x02, |
| 198 | .host_intstatus = 0x03, |
| 199 | .card_status = 0x50, |
| 200 | .sq_read_base_addr_a0 = 0x60, |
| 201 | .sq_read_base_addr_a1 = 0x61, |
| 202 | .card_revision = 0xbc, |
| 203 | .card_fw_status0 = 0xc0, |
| 204 | .card_fw_status1 = 0xc1, |
| 205 | .card_rx_len = 0xc2, |
| 206 | .card_rx_unit = 0xc3, |
| 207 | .io_port_0 = 0xd8, |
| 208 | .io_port_1 = 0xd9, |
| 209 | .io_port_2 = 0xda, |
Bing Zhao | 0d36740 | 2014-03-28 14:54:39 -0700 | [diff] [blame] | 210 | .int_read_to_clear = true, |
| 211 | .host_int_rsr = 0x01, |
| 212 | .card_misc_cfg = 0xcc, |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 213 | .fw_dump_ctrl = 0xe2, |
| 214 | .fw_dump_start = 0xe3, |
| 215 | .fw_dump_end = 0xea, |
Bing Zhao | 22f2efe | 2013-05-13 18:15:32 -0700 | [diff] [blame] | 216 | }; |
| 217 | |
Tamás Szűcs | 7cfc21e | 2020-08-02 16:56:42 +0200 | [diff] [blame] | 218 | static const struct btmrvl_sdio_card_reg btmrvl_reg_89xx = { |
Tamás Szűcs | 73623340 | 2019-04-14 20:38:14 +0200 | [diff] [blame] | 219 | .cfg = 0x00, |
| 220 | .host_int_mask = 0x08, |
| 221 | .host_intstatus = 0x0c, |
| 222 | .card_status = 0x5c, |
| 223 | .sq_read_base_addr_a0 = 0xf8, |
| 224 | .sq_read_base_addr_a1 = 0xf9, |
| 225 | .card_revision = 0xc8, |
| 226 | .card_fw_status0 = 0xe8, |
| 227 | .card_fw_status1 = 0xe9, |
| 228 | .card_rx_len = 0xea, |
| 229 | .card_rx_unit = 0xeb, |
| 230 | .io_port_0 = 0xe4, |
| 231 | .io_port_1 = 0xe5, |
| 232 | .io_port_2 = 0xe6, |
| 233 | .int_read_to_clear = true, |
| 234 | .host_int_rsr = 0x04, |
| 235 | .card_misc_cfg = 0xd8, |
| 236 | .fw_dump_ctrl = 0xf0, |
| 237 | .fw_dump_start = 0xf1, |
| 238 | .fw_dump_end = 0xf8, |
| 239 | }; |
| 240 | |
Paul Bolle | c675786 | 2011-10-05 14:56:46 +0200 | [diff] [blame] | 241 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8688 = { |
Lubomir Rintel | 77189df | 2013-03-13 12:04:30 +0100 | [diff] [blame] | 242 | .helper = "mrvl/sd8688_helper.bin", |
| 243 | .firmware = "mrvl/sd8688.bin", |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 244 | .reg = &btmrvl_reg_8688, |
Bing Zhao | 4df82b5 | 2014-03-31 14:41:44 -0700 | [diff] [blame] | 245 | .support_pscan_win_report = false, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 246 | .sd_blksz_fw_dl = 64, |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 247 | .supports_fw_dump = false, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8787 = { |
| 251 | .helper = NULL, |
| 252 | .firmware = "mrvl/sd8787_uapsta.bin", |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 253 | .reg = &btmrvl_reg_87xx, |
Bing Zhao | 4df82b5 | 2014-03-31 14:41:44 -0700 | [diff] [blame] | 254 | .support_pscan_win_report = false, |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 255 | .sd_blksz_fw_dl = 256, |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 256 | .supports_fw_dump = false, |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8797 = { |
| 260 | .helper = NULL, |
| 261 | .firmware = "mrvl/sd8797_uapsta.bin", |
| 262 | .reg = &btmrvl_reg_87xx, |
Bing Zhao | 4df82b5 | 2014-03-31 14:41:44 -0700 | [diff] [blame] | 263 | .support_pscan_win_report = false, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 264 | .sd_blksz_fw_dl = 256, |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 265 | .supports_fw_dump = false, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 266 | }; |
| 267 | |
Xinming Hu | 3907d55 | 2014-09-30 06:45:33 -0400 | [diff] [blame] | 268 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8887 = { |
| 269 | .helper = NULL, |
| 270 | .firmware = "mrvl/sd8887_uapsta.bin", |
| 271 | .reg = &btmrvl_reg_8887, |
| 272 | .support_pscan_win_report = true, |
| 273 | .sd_blksz_fw_dl = 256, |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 274 | .supports_fw_dump = false, |
Xinming Hu | 3907d55 | 2014-09-30 06:45:33 -0400 | [diff] [blame] | 275 | }; |
| 276 | |
Bing Zhao | 22f2efe | 2013-05-13 18:15:32 -0700 | [diff] [blame] | 277 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8897 = { |
| 278 | .helper = NULL, |
| 279 | .firmware = "mrvl/sd8897_uapsta.bin", |
Amitkumar Karwar | 1e3e492 | 2014-09-30 06:45:32 -0400 | [diff] [blame] | 280 | .reg = &btmrvl_reg_8897, |
Bing Zhao | 4df82b5 | 2014-03-31 14:41:44 -0700 | [diff] [blame] | 281 | .support_pscan_win_report = true, |
Bing Zhao | 22f2efe | 2013-05-13 18:15:32 -0700 | [diff] [blame] | 282 | .sd_blksz_fw_dl = 256, |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 283 | .supports_fw_dump = true, |
Bing Zhao | 22f2efe | 2013-05-13 18:15:32 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
Hemantkumar Suthar | 8c57983 | 2019-01-09 15:03:57 +0000 | [diff] [blame] | 286 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8977 = { |
| 287 | .helper = NULL, |
Pali Rohár | dbec3af | 2020-06-03 10:22:28 +0200 | [diff] [blame] | 288 | .firmware = "mrvl/sdsd8977_combo_v2.bin", |
Tamás Szűcs | 7cfc21e | 2020-08-02 16:56:42 +0200 | [diff] [blame] | 289 | .reg = &btmrvl_reg_89xx, |
Hemantkumar Suthar | 8c57983 | 2019-01-09 15:03:57 +0000 | [diff] [blame] | 290 | .support_pscan_win_report = true, |
| 291 | .sd_blksz_fw_dl = 256, |
| 292 | .supports_fw_dump = true, |
| 293 | }; |
| 294 | |
Tamás Szűcs | 73623340 | 2019-04-14 20:38:14 +0200 | [diff] [blame] | 295 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8987 = { |
| 296 | .helper = NULL, |
| 297 | .firmware = "mrvl/sd8987_uapsta.bin", |
Tamás Szűcs | 7cfc21e | 2020-08-02 16:56:42 +0200 | [diff] [blame] | 298 | .reg = &btmrvl_reg_89xx, |
Tamás Szűcs | 73623340 | 2019-04-14 20:38:14 +0200 | [diff] [blame] | 299 | .support_pscan_win_report = true, |
| 300 | .sd_blksz_fw_dl = 256, |
| 301 | .supports_fw_dump = true, |
| 302 | }; |
| 303 | |
Amitkumar Karwar | f0ef674 | 2015-09-21 03:06:42 -0700 | [diff] [blame] | 304 | static const struct btmrvl_sdio_device btmrvl_sdio_sd8997 = { |
| 305 | .helper = NULL, |
Pali Rohár | 00eb0cb | 2020-06-03 10:22:29 +0200 | [diff] [blame] | 306 | .firmware = "mrvl/sdsd8997_combo_v4.bin", |
Tamás Szűcs | 7cfc21e | 2020-08-02 16:56:42 +0200 | [diff] [blame] | 307 | .reg = &btmrvl_reg_89xx, |
Amitkumar Karwar | f0ef674 | 2015-09-21 03:06:42 -0700 | [diff] [blame] | 308 | .support_pscan_win_report = true, |
| 309 | .sd_blksz_fw_dl = 256, |
| 310 | .supports_fw_dump = true, |
| 311 | }; |
| 312 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 313 | static const struct sdio_device_id btmrvl_sdio_ids[] = { |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 314 | /* Marvell SD8688 Bluetooth device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 315 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8688_BT), |
Amitkumar Karwar | 53d6cfa | 2015-09-21 03:06:41 -0700 | [diff] [blame] | 316 | .driver_data = (unsigned long)&btmrvl_sdio_sd8688 }, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 317 | /* Marvell SD8787 Bluetooth device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 318 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787_BT), |
Amitkumar Karwar | 53d6cfa | 2015-09-21 03:06:41 -0700 | [diff] [blame] | 319 | .driver_data = (unsigned long)&btmrvl_sdio_sd8787 }, |
Bing Zhao | 37ed561 | 2012-05-23 18:50:04 -0700 | [diff] [blame] | 320 | /* Marvell SD8787 Bluetooth AMP device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 321 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787_BT_AMP), |
Amitkumar Karwar | 53d6cfa | 2015-09-21 03:06:41 -0700 | [diff] [blame] | 322 | .driver_data = (unsigned long)&btmrvl_sdio_sd8787 }, |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 323 | /* Marvell SD8797 Bluetooth device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 324 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_BT), |
Amitkumar Karwar | 53d6cfa | 2015-09-21 03:06:41 -0700 | [diff] [blame] | 325 | .driver_data = (unsigned long)&btmrvl_sdio_sd8797 }, |
Xinming Hu | 3907d55 | 2014-09-30 06:45:33 -0400 | [diff] [blame] | 326 | /* Marvell SD8887 Bluetooth device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 327 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8887_BT), |
Xinming Hu | 3907d55 | 2014-09-30 06:45:33 -0400 | [diff] [blame] | 328 | .driver_data = (unsigned long)&btmrvl_sdio_sd8887 }, |
Bing Zhao | 22f2efe | 2013-05-13 18:15:32 -0700 | [diff] [blame] | 329 | /* Marvell SD8897 Bluetooth device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 330 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8897_BT), |
Amitkumar Karwar | 53d6cfa | 2015-09-21 03:06:41 -0700 | [diff] [blame] | 331 | .driver_data = (unsigned long)&btmrvl_sdio_sd8897 }, |
Hemantkumar Suthar | 8c57983 | 2019-01-09 15:03:57 +0000 | [diff] [blame] | 332 | /* Marvell SD8977 Bluetooth device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 333 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8977_BT), |
Hemantkumar Suthar | 8c57983 | 2019-01-09 15:03:57 +0000 | [diff] [blame] | 334 | .driver_data = (unsigned long)&btmrvl_sdio_sd8977 }, |
Tamás Szűcs | 73623340 | 2019-04-14 20:38:14 +0200 | [diff] [blame] | 335 | /* Marvell SD8987 Bluetooth device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 336 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8987_BT), |
Tamás Szűcs | 73623340 | 2019-04-14 20:38:14 +0200 | [diff] [blame] | 337 | .driver_data = (unsigned long)&btmrvl_sdio_sd8987 }, |
Amitkumar Karwar | f0ef674 | 2015-09-21 03:06:42 -0700 | [diff] [blame] | 338 | /* Marvell SD8997 Bluetooth device */ |
Pali Rohár | 649c7d7 | 2020-05-22 16:44:05 +0200 | [diff] [blame] | 339 | { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8997_BT), |
Amitkumar Karwar | f0ef674 | 2015-09-21 03:06:42 -0700 | [diff] [blame] | 340 | .driver_data = (unsigned long)&btmrvl_sdio_sd8997 }, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 341 | |
| 342 | { } /* Terminating entry */ |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | MODULE_DEVICE_TABLE(sdio, btmrvl_sdio_ids); |
| 346 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 347 | static int btmrvl_sdio_get_rx_unit(struct btmrvl_sdio_card *card) |
| 348 | { |
| 349 | u8 reg; |
| 350 | int ret; |
| 351 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 352 | reg = sdio_readb(card->func, card->reg->card_rx_unit, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 353 | if (!ret) |
| 354 | card->rx_unit = reg; |
| 355 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | static int btmrvl_sdio_read_fw_status(struct btmrvl_sdio_card *card, u16 *dat) |
| 360 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 361 | u8 fws0, fws1; |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 362 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 363 | |
| 364 | *dat = 0; |
| 365 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 366 | fws0 = sdio_readb(card->func, card->reg->card_fw_status0, &ret); |
Kulikov Vasiliy | 278be27 | 2010-07-05 12:01:22 +0400 | [diff] [blame] | 367 | if (ret) |
| 368 | return -EIO; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 369 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 370 | fws1 = sdio_readb(card->func, card->reg->card_fw_status1, &ret); |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 371 | if (ret) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 372 | return -EIO; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 373 | |
| 374 | *dat = (((u16) fws1) << 8) | fws0; |
| 375 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static int btmrvl_sdio_read_rx_len(struct btmrvl_sdio_card *card, u16 *dat) |
| 380 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 381 | u8 reg; |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 382 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 383 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 384 | reg = sdio_readb(card->func, card->reg->card_rx_len, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 385 | if (!ret) |
| 386 | *dat = (u16) reg << card->rx_unit; |
| 387 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 388 | return ret; |
| 389 | } |
| 390 | |
| 391 | 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] | 392 | u8 mask) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 393 | { |
| 394 | int ret; |
| 395 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 396 | sdio_writeb(card->func, mask, card->reg->host_int_mask, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 397 | if (ret) { |
| 398 | BT_ERR("Unable to enable the host interrupt!"); |
| 399 | ret = -EIO; |
| 400 | } |
| 401 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | 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] | 406 | u8 mask) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 407 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 408 | u8 host_int_mask; |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 409 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 410 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 411 | 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] | 412 | if (ret) |
| 413 | return -EIO; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 414 | |
| 415 | host_int_mask &= ~mask; |
| 416 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 417 | 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] | 418 | if (ret < 0) { |
| 419 | BT_ERR("Unable to disable the host interrupt!"); |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 420 | return -EIO; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 423 | return 0; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | static int btmrvl_sdio_poll_card_status(struct btmrvl_sdio_card *card, u8 bits) |
| 427 | { |
| 428 | unsigned int tries; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 429 | u8 status; |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 430 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 431 | |
| 432 | for (tries = 0; tries < MAX_POLL_TRIES * 1000; tries++) { |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 433 | status = sdio_readb(card->func, card->reg->card_status, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 434 | if (ret) |
| 435 | goto failed; |
| 436 | if ((status & bits) == bits) |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 437 | return ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 438 | |
| 439 | udelay(1); |
| 440 | } |
| 441 | |
| 442 | ret = -ETIMEDOUT; |
| 443 | |
| 444 | failed: |
| 445 | BT_ERR("FAILED! ret=%d", ret); |
| 446 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | static int btmrvl_sdio_verify_fw_download(struct btmrvl_sdio_card *card, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 451 | int pollnum) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 452 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 453 | u16 firmwarestat; |
Andreas Fenkart | 69676b1 | 2013-04-22 11:10:23 +0200 | [diff] [blame] | 454 | int tries, ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 455 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 456 | /* Wait for firmware to become ready */ |
| 457 | for (tries = 0; tries < pollnum; tries++) { |
Andreas Fenkart | c1c999e | 2013-04-22 11:10:22 +0200 | [diff] [blame] | 458 | sdio_claim_host(card->func); |
| 459 | ret = btmrvl_sdio_read_fw_status(card, &firmwarestat); |
| 460 | sdio_release_host(card->func); |
| 461 | if (ret < 0) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 462 | continue; |
| 463 | |
Andreas Fenkart | 69676b1 | 2013-04-22 11:10:23 +0200 | [diff] [blame] | 464 | if (firmwarestat == FIRMWARE_READY) |
| 465 | return 0; |
| 466 | |
Wei-Ning Huang | 9a01242 | 2016-03-08 11:40:06 +0800 | [diff] [blame] | 467 | msleep(100); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Andreas Fenkart | 69676b1 | 2013-04-22 11:10:23 +0200 | [diff] [blame] | 470 | return -ETIMEDOUT; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static int btmrvl_sdio_download_helper(struct btmrvl_sdio_card *card) |
| 474 | { |
| 475 | const struct firmware *fw_helper = NULL; |
| 476 | const u8 *helper = NULL; |
| 477 | int ret; |
| 478 | void *tmphlprbuf = NULL; |
| 479 | int tmphlprbufsz, hlprblknow, helperlen; |
| 480 | u8 *helperbuf; |
| 481 | u32 tx_len; |
| 482 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 483 | ret = request_firmware(&fw_helper, card->helper, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 484 | &card->func->dev); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 485 | if ((ret < 0) || !fw_helper) { |
| 486 | BT_ERR("request_firmware(helper) failed, error code = %d", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 487 | ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 488 | ret = -ENOENT; |
| 489 | goto done; |
| 490 | } |
| 491 | |
| 492 | helper = fw_helper->data; |
| 493 | helperlen = fw_helper->size; |
| 494 | |
| 495 | BT_DBG("Downloading helper image (%d bytes), block size %d bytes", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 496 | helperlen, SDIO_BLOCK_SIZE); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 497 | |
| 498 | tmphlprbufsz = ALIGN_SZ(BTM_UPLD_SIZE, BTSDIO_DMA_ALIGN); |
| 499 | |
Julia Lawall | f8df39f | 2010-05-13 22:02:03 +0200 | [diff] [blame] | 500 | tmphlprbuf = kzalloc(tmphlprbufsz, GFP_KERNEL); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 501 | if (!tmphlprbuf) { |
| 502 | BT_ERR("Unable to allocate buffer for helper." |
| 503 | " Terminating download"); |
| 504 | ret = -ENOMEM; |
| 505 | goto done; |
| 506 | } |
| 507 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 508 | helperbuf = (u8 *) ALIGN_ADDR(tmphlprbuf, BTSDIO_DMA_ALIGN); |
| 509 | |
| 510 | /* Perform helper data transfer */ |
| 511 | tx_len = (FIRMWARE_TRANSFER_NBLOCK * SDIO_BLOCK_SIZE) |
| 512 | - SDIO_HEADER_LEN; |
| 513 | hlprblknow = 0; |
| 514 | |
| 515 | do { |
| 516 | ret = btmrvl_sdio_poll_card_status(card, |
| 517 | CARD_IO_READY | DN_LD_CARD_RDY); |
| 518 | if (ret < 0) { |
| 519 | BT_ERR("Helper download poll status timeout @ %d", |
| 520 | hlprblknow); |
| 521 | goto done; |
| 522 | } |
| 523 | |
| 524 | /* Check if there is more data? */ |
| 525 | if (hlprblknow >= helperlen) |
| 526 | break; |
| 527 | |
| 528 | if (helperlen - hlprblknow < tx_len) |
| 529 | tx_len = helperlen - hlprblknow; |
| 530 | |
| 531 | /* Little-endian */ |
| 532 | helperbuf[0] = ((tx_len & 0x000000ff) >> 0); |
| 533 | helperbuf[1] = ((tx_len & 0x0000ff00) >> 8); |
| 534 | helperbuf[2] = ((tx_len & 0x00ff0000) >> 16); |
| 535 | helperbuf[3] = ((tx_len & 0xff000000) >> 24); |
| 536 | |
| 537 | memcpy(&helperbuf[SDIO_HEADER_LEN], &helper[hlprblknow], |
| 538 | tx_len); |
| 539 | |
| 540 | /* Now send the data */ |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 541 | ret = sdio_writesb(card->func, card->ioport, helperbuf, |
| 542 | FIRMWARE_TRANSFER_NBLOCK * SDIO_BLOCK_SIZE); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 543 | if (ret < 0) { |
| 544 | BT_ERR("IO error during helper download @ %d", |
| 545 | hlprblknow); |
| 546 | goto done; |
| 547 | } |
| 548 | |
| 549 | hlprblknow += tx_len; |
| 550 | } while (true); |
| 551 | |
| 552 | BT_DBG("Transferring helper image EOF block"); |
| 553 | |
| 554 | memset(helperbuf, 0x0, SDIO_BLOCK_SIZE); |
| 555 | |
| 556 | ret = sdio_writesb(card->func, card->ioport, helperbuf, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 557 | SDIO_BLOCK_SIZE); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 558 | if (ret < 0) { |
| 559 | BT_ERR("IO error in writing helper image EOF block"); |
| 560 | goto done; |
| 561 | } |
| 562 | |
| 563 | ret = 0; |
| 564 | |
| 565 | done: |
| 566 | kfree(tmphlprbuf); |
Jesper Juhl | 59f34fb | 2012-04-09 22:49:49 +0200 | [diff] [blame] | 567 | release_firmware(fw_helper); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 568 | return ret; |
| 569 | } |
| 570 | |
| 571 | static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card) |
| 572 | { |
| 573 | const struct firmware *fw_firmware = NULL; |
| 574 | const u8 *firmware = NULL; |
| 575 | int firmwarelen, tmpfwbufsz, ret; |
| 576 | unsigned int tries, offset; |
| 577 | u8 base0, base1; |
| 578 | void *tmpfwbuf = NULL; |
| 579 | u8 *fwbuf; |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 580 | u16 len, blksz_dl = card->sd_blksz_fw_dl; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 581 | int txlen = 0, tx_blocks = 0, count = 0; |
| 582 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 583 | ret = request_firmware(&fw_firmware, card->firmware, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 584 | &card->func->dev); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 585 | if ((ret < 0) || !fw_firmware) { |
| 586 | BT_ERR("request_firmware(firmware) failed, error code = %d", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 587 | ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 588 | ret = -ENOENT; |
| 589 | goto done; |
| 590 | } |
| 591 | |
| 592 | firmware = fw_firmware->data; |
| 593 | firmwarelen = fw_firmware->size; |
| 594 | |
| 595 | BT_DBG("Downloading FW image (%d bytes)", firmwarelen); |
| 596 | |
| 597 | tmpfwbufsz = ALIGN_SZ(BTM_UPLD_SIZE, BTSDIO_DMA_ALIGN); |
Julia Lawall | f8df39f | 2010-05-13 22:02:03 +0200 | [diff] [blame] | 598 | tmpfwbuf = kzalloc(tmpfwbufsz, GFP_KERNEL); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 599 | if (!tmpfwbuf) { |
| 600 | BT_ERR("Unable to allocate buffer for firmware." |
| 601 | " Terminating download"); |
| 602 | ret = -ENOMEM; |
| 603 | goto done; |
| 604 | } |
| 605 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 606 | /* Ensure aligned firmware buffer */ |
| 607 | fwbuf = (u8 *) ALIGN_ADDR(tmpfwbuf, BTSDIO_DMA_ALIGN); |
| 608 | |
| 609 | /* Perform firmware data transfer */ |
| 610 | offset = 0; |
| 611 | do { |
| 612 | ret = btmrvl_sdio_poll_card_status(card, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 613 | CARD_IO_READY | DN_LD_CARD_RDY); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 614 | if (ret < 0) { |
| 615 | BT_ERR("FW download with helper poll status" |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 616 | " timeout @ %d", offset); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 617 | goto done; |
| 618 | } |
| 619 | |
| 620 | /* Check if there is more data ? */ |
| 621 | if (offset >= firmwarelen) |
| 622 | break; |
| 623 | |
| 624 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { |
| 625 | base0 = sdio_readb(card->func, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 626 | card->reg->sq_read_base_addr_a0, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 627 | if (ret) { |
| 628 | BT_ERR("BASE0 register read failed:" |
| 629 | " base0 = 0x%04X(%d)." |
| 630 | " Terminating download", |
| 631 | base0, base0); |
| 632 | ret = -EIO; |
| 633 | goto done; |
| 634 | } |
| 635 | base1 = sdio_readb(card->func, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 636 | card->reg->sq_read_base_addr_a1, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 637 | if (ret) { |
| 638 | BT_ERR("BASE1 register read failed:" |
| 639 | " base1 = 0x%04X(%d)." |
| 640 | " Terminating download", |
| 641 | base1, base1); |
| 642 | ret = -EIO; |
| 643 | goto done; |
| 644 | } |
| 645 | |
| 646 | len = (((u16) base1) << 8) | base0; |
| 647 | if (len) |
| 648 | break; |
| 649 | |
| 650 | udelay(10); |
| 651 | } |
| 652 | |
| 653 | if (!len) |
| 654 | break; |
| 655 | else if (len > BTM_UPLD_SIZE) { |
| 656 | BT_ERR("FW download failure @%d, invalid length %d", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 657 | offset, len); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 658 | ret = -EINVAL; |
| 659 | goto done; |
| 660 | } |
| 661 | |
| 662 | txlen = len; |
| 663 | |
| 664 | if (len & BIT(0)) { |
| 665 | count++; |
| 666 | if (count > MAX_WRITE_IOMEM_RETRY) { |
| 667 | BT_ERR("FW download failure @%d, " |
| 668 | "over max retry count", offset); |
| 669 | ret = -EIO; |
| 670 | goto done; |
| 671 | } |
| 672 | BT_ERR("FW CRC error indicated by the helper: " |
| 673 | "len = 0x%04X, txlen = %d", len, txlen); |
| 674 | len &= ~BIT(0); |
| 675 | /* Set txlen to 0 so as to resend from same offset */ |
| 676 | txlen = 0; |
| 677 | } else { |
| 678 | count = 0; |
| 679 | |
| 680 | /* Last block ? */ |
| 681 | if (firmwarelen - offset < txlen) |
| 682 | txlen = firmwarelen - offset; |
| 683 | |
Andy Shevchenko | ba34dd3 | 2013-08-02 14:10:12 +0300 | [diff] [blame] | 684 | tx_blocks = DIV_ROUND_UP(txlen, blksz_dl); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 685 | |
| 686 | memcpy(fwbuf, &firmware[offset], txlen); |
| 687 | } |
| 688 | |
| 689 | ret = sdio_writesb(card->func, card->ioport, fwbuf, |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 690 | tx_blocks * blksz_dl); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 691 | |
| 692 | if (ret < 0) { |
| 693 | BT_ERR("FW download, writesb(%d) failed @%d", |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 694 | count, offset); |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 695 | sdio_writeb(card->func, HOST_CMD53_FIN, |
| 696 | card->reg->cfg, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 697 | if (ret) |
| 698 | BT_ERR("writeb failed (CFG)"); |
| 699 | } |
| 700 | |
| 701 | offset += txlen; |
| 702 | } while (true); |
| 703 | |
Amitkumar Karwar | 1c6098e | 2015-01-01 00:13:42 -0800 | [diff] [blame] | 704 | BT_INFO("FW download over, size %d bytes", offset); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 705 | |
| 706 | ret = 0; |
| 707 | |
| 708 | done: |
| 709 | kfree(tmpfwbuf); |
Jesper Juhl | 59f34fb | 2012-04-09 22:49:49 +0200 | [diff] [blame] | 710 | release_firmware(fw_firmware); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 711 | return ret; |
| 712 | } |
| 713 | |
| 714 | static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv) |
| 715 | { |
| 716 | u16 buf_len = 0; |
Andrei Emeltchenko | 4263280 | 2012-09-28 14:36:08 +0300 | [diff] [blame] | 717 | int ret, num_blocks, blksz; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 718 | struct sk_buff *skb = NULL; |
| 719 | u32 type; |
Markus Elfring | 9376e4a | 2018-03-12 11:15:59 +0100 | [diff] [blame] | 720 | u8 *payload; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 721 | struct hci_dev *hdev = priv->btmrvl_dev.hcidev; |
| 722 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 723 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 724 | if (!card || !card->func) { |
| 725 | BT_ERR("card or function is NULL!"); |
| 726 | ret = -EINVAL; |
| 727 | goto exit; |
| 728 | } |
| 729 | |
| 730 | /* Read the length of data to be transferred */ |
| 731 | ret = btmrvl_sdio_read_rx_len(card, &buf_len); |
| 732 | if (ret < 0) { |
| 733 | BT_ERR("read rx_len failed"); |
| 734 | ret = -EIO; |
| 735 | goto exit; |
| 736 | } |
| 737 | |
| 738 | blksz = SDIO_BLOCK_SIZE; |
Andrei Emeltchenko | e678bad | 2012-09-28 14:36:09 +0300 | [diff] [blame] | 739 | num_blocks = DIV_ROUND_UP(buf_len, blksz); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 740 | |
| 741 | if (buf_len <= SDIO_HEADER_LEN |
Andrei Emeltchenko | 4263280 | 2012-09-28 14:36:08 +0300 | [diff] [blame] | 742 | || (num_blocks * blksz) > ALLOC_BUF_SIZE) { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 743 | BT_ERR("invalid packet length: %d", buf_len); |
| 744 | ret = -EINVAL; |
| 745 | goto exit; |
| 746 | } |
| 747 | |
| 748 | /* Allocate buffer */ |
Jia-Ju Bai | 436018e | 2018-07-23 11:30:03 +0800 | [diff] [blame] | 749 | skb = bt_skb_alloc(num_blocks * blksz + BTSDIO_DMA_ALIGN, GFP_KERNEL); |
Prasanna Karthik | 1f438c6 | 2015-09-25 09:03:14 +0000 | [diff] [blame] | 750 | if (!skb) { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 751 | BT_ERR("No free skb"); |
Wei Yongjun | 6ea81c4 | 2013-06-05 10:16:55 +0800 | [diff] [blame] | 752 | ret = -ENOMEM; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 753 | goto exit; |
| 754 | } |
| 755 | |
Bing Zhao | 3318b23 | 2009-07-08 11:44:14 -0700 | [diff] [blame] | 756 | if ((unsigned long) skb->data & (BTSDIO_DMA_ALIGN - 1)) { |
| 757 | skb_put(skb, (unsigned long) skb->data & |
| 758 | (BTSDIO_DMA_ALIGN - 1)); |
| 759 | skb_pull(skb, (unsigned long) skb->data & |
| 760 | (BTSDIO_DMA_ALIGN - 1)); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Bing Zhao | 3318b23 | 2009-07-08 11:44:14 -0700 | [diff] [blame] | 763 | payload = skb->data; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 764 | |
| 765 | ret = sdio_readsb(card->func, payload, card->ioport, |
Andrei Emeltchenko | 4263280 | 2012-09-28 14:36:08 +0300 | [diff] [blame] | 766 | num_blocks * blksz); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 767 | if (ret < 0) { |
| 768 | BT_ERR("readsb failed: %d", ret); |
| 769 | ret = -EIO; |
| 770 | goto exit; |
| 771 | } |
| 772 | |
| 773 | /* This is SDIO specific header length: byte[2][1][0], type: byte[3] |
| 774 | * (HCI_COMMAND = 1, ACL_DATA = 2, SCO_DATA = 3, 0xFE = Vendor) |
| 775 | */ |
| 776 | |
| 777 | buf_len = payload[0]; |
Andrei Emeltchenko | 9cb23dd | 2012-09-28 14:36:10 +0300 | [diff] [blame] | 778 | buf_len |= payload[1] << 8; |
| 779 | buf_len |= payload[2] << 16; |
| 780 | |
| 781 | if (buf_len > blksz * num_blocks) { |
| 782 | BT_ERR("Skip incorrect packet: hdrlen %d buffer %d", |
| 783 | buf_len, blksz * num_blocks); |
| 784 | ret = -EIO; |
| 785 | goto exit; |
| 786 | } |
| 787 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 788 | type = payload[3]; |
| 789 | |
| 790 | switch (type) { |
| 791 | case HCI_ACLDATA_PKT: |
| 792 | case HCI_SCODATA_PKT: |
| 793 | case HCI_EVENT_PKT: |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 794 | hci_skb_pkt_type(skb) = type; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 795 | skb_put(skb, buf_len); |
| 796 | skb_pull(skb, SDIO_HEADER_LEN); |
| 797 | |
Andrei Emeltchenko | ea1e76a | 2012-06-13 13:35:44 +0300 | [diff] [blame] | 798 | if (type == HCI_EVENT_PKT) { |
| 799 | if (btmrvl_check_evtpkt(priv, skb)) |
Marcel Holtmann | e1a2617 | 2013-10-10 16:52:43 -0700 | [diff] [blame] | 800 | hci_recv_frame(hdev, skb); |
Andrei Emeltchenko | 2c2453f | 2012-07-09 13:57:18 +0300 | [diff] [blame] | 801 | } else { |
Marcel Holtmann | e1a2617 | 2013-10-10 16:52:43 -0700 | [diff] [blame] | 802 | hci_recv_frame(hdev, skb); |
Andrei Emeltchenko | 2c2453f | 2012-07-09 13:57:18 +0300 | [diff] [blame] | 803 | } |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 804 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 805 | hdev->stat.byte_rx += buf_len; |
| 806 | break; |
| 807 | |
| 808 | case MRVL_VENDOR_PKT: |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 809 | hci_skb_pkt_type(skb) = HCI_VENDOR_PKT; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 810 | skb_put(skb, buf_len); |
| 811 | skb_pull(skb, SDIO_HEADER_LEN); |
| 812 | |
| 813 | if (btmrvl_process_event(priv, skb)) |
Marcel Holtmann | e1a2617 | 2013-10-10 16:52:43 -0700 | [diff] [blame] | 814 | hci_recv_frame(hdev, skb); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 815 | |
| 816 | hdev->stat.byte_rx += buf_len; |
| 817 | break; |
| 818 | |
| 819 | default: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 820 | BT_ERR("Unknown packet type:%d", type); |
Andrei Emeltchenko | 78c1b8e | 2012-10-10 17:41:33 +0300 | [diff] [blame] | 821 | BT_ERR("hex: %*ph", blksz * num_blocks, payload); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 822 | |
| 823 | kfree_skb(skb); |
| 824 | skb = NULL; |
| 825 | break; |
| 826 | } |
| 827 | |
| 828 | exit: |
| 829 | if (ret) { |
| 830 | hdev->stat.err_rx++; |
Wei Yongjun | 7923296 | 2012-08-28 21:12:48 +0800 | [diff] [blame] | 831 | kfree_skb(skb); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 834 | return ret; |
| 835 | } |
| 836 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 837 | static int btmrvl_sdio_process_int_status(struct btmrvl_private *priv) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 838 | { |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 839 | ulong flags; |
| 840 | u8 ireg; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 841 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 842 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 843 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 844 | ireg = sdio_ireg; |
| 845 | sdio_ireg = 0; |
| 846 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 847 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 848 | sdio_claim_host(card->func); |
| 849 | if (ireg & DN_LD_HOST_INT_STATUS) { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 850 | if (priv->btmrvl_dev.tx_dnld_rdy) |
| 851 | BT_DBG("tx_done already received: " |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 852 | " int_status=0x%x", ireg); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 853 | else |
| 854 | priv->btmrvl_dev.tx_dnld_rdy = true; |
| 855 | } |
| 856 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 857 | if (ireg & UP_LD_HOST_INT_STATUS) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 858 | btmrvl_sdio_card_to_host(priv); |
| 859 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 860 | sdio_release_host(card->func); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 861 | |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 862 | return 0; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Bing Zhao | 0d36740 | 2014-03-28 14:54:39 -0700 | [diff] [blame] | 865 | static int btmrvl_sdio_read_to_clear(struct btmrvl_sdio_card *card, u8 *ireg) |
| 866 | { |
| 867 | struct btmrvl_adapter *adapter = card->priv->adapter; |
| 868 | int ret; |
| 869 | |
| 870 | ret = sdio_readsb(card->func, adapter->hw_regs, 0, SDIO_BLOCK_SIZE); |
| 871 | if (ret) { |
| 872 | BT_ERR("sdio_readsb: read int hw_regs failed: %d", ret); |
| 873 | return ret; |
| 874 | } |
| 875 | |
| 876 | *ireg = adapter->hw_regs[card->reg->host_intstatus]; |
| 877 | BT_DBG("hw_regs[%#x]=%#x", card->reg->host_intstatus, *ireg); |
| 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
Bing Zhao | 8af4840 | 2014-03-27 21:30:42 -0700 | [diff] [blame] | 882 | static int btmrvl_sdio_write_to_clear(struct btmrvl_sdio_card *card, u8 *ireg) |
| 883 | { |
| 884 | int ret; |
| 885 | |
| 886 | *ireg = sdio_readb(card->func, card->reg->host_intstatus, &ret); |
| 887 | if (ret) { |
| 888 | BT_ERR("sdio_readb: read int status failed: %d", ret); |
| 889 | return ret; |
| 890 | } |
| 891 | |
| 892 | if (*ireg) { |
| 893 | /* |
| 894 | * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS |
| 895 | * Clear the interrupt status register and re-enable the |
| 896 | * interrupt. |
| 897 | */ |
| 898 | BT_DBG("int_status = 0x%x", *ireg); |
| 899 | |
| 900 | sdio_writeb(card->func, ~(*ireg) & (DN_LD_HOST_INT_STATUS | |
| 901 | UP_LD_HOST_INT_STATUS), |
| 902 | card->reg->host_intstatus, &ret); |
| 903 | if (ret) { |
| 904 | BT_ERR("sdio_writeb: clear int status failed: %d", ret); |
| 905 | return ret; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | return 0; |
| 910 | } |
| 911 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 912 | static void btmrvl_sdio_interrupt(struct sdio_func *func) |
| 913 | { |
| 914 | struct btmrvl_private *priv; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 915 | struct btmrvl_sdio_card *card; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 916 | ulong flags; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 917 | u8 ireg = 0; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 918 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 919 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 920 | card = sdio_get_drvdata(func); |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 921 | if (!card || !card->priv) { |
Amitkumar Karwar | 7365d47 | 2014-11-24 02:40:52 -0800 | [diff] [blame] | 922 | BT_ERR("sbi_interrupt(%p) card or priv is NULL, card=%p", |
| 923 | func, card); |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 924 | return; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 925 | } |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 926 | |
| 927 | priv = card->priv; |
| 928 | |
Amitkumar Karwar | 7b4b874 | 2015-01-01 00:13:41 -0800 | [diff] [blame] | 929 | if (priv->surprise_removed) |
| 930 | return; |
| 931 | |
Bing Zhao | 0d36740 | 2014-03-28 14:54:39 -0700 | [diff] [blame] | 932 | if (card->reg->int_read_to_clear) |
| 933 | ret = btmrvl_sdio_read_to_clear(card, &ireg); |
| 934 | else |
| 935 | ret = btmrvl_sdio_write_to_clear(card, &ireg); |
| 936 | |
Bing Zhao | 8af4840 | 2014-03-27 21:30:42 -0700 | [diff] [blame] | 937 | if (ret) |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 938 | return; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 939 | |
| 940 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 941 | sdio_ireg |= ireg; |
| 942 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 943 | |
| 944 | btmrvl_interrupt(priv); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card) |
| 948 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 949 | struct sdio_func *func; |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 950 | u8 reg; |
Markus Elfring | a5c2f4c | 2018-03-12 10:20:04 +0100 | [diff] [blame] | 951 | int ret; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 952 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 953 | if (!card || !card->func) { |
| 954 | BT_ERR("Error: card or function is NULL!"); |
| 955 | ret = -EINVAL; |
| 956 | goto failed; |
| 957 | } |
| 958 | |
| 959 | func = card->func; |
| 960 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 961 | sdio_claim_host(func); |
| 962 | |
| 963 | ret = sdio_enable_func(func); |
| 964 | if (ret) { |
| 965 | BT_ERR("sdio_enable_func() failed: ret=%d", ret); |
| 966 | ret = -EIO; |
| 967 | goto release_host; |
| 968 | } |
| 969 | |
| 970 | ret = sdio_claim_irq(func, btmrvl_sdio_interrupt); |
| 971 | if (ret) { |
| 972 | BT_ERR("sdio_claim_irq failed: ret=%d", ret); |
| 973 | ret = -EIO; |
| 974 | goto disable_func; |
| 975 | } |
| 976 | |
| 977 | ret = sdio_set_block_size(card->func, SDIO_BLOCK_SIZE); |
| 978 | if (ret) { |
| 979 | BT_ERR("cannot set SDIO block size"); |
| 980 | ret = -EIO; |
| 981 | goto release_irq; |
| 982 | } |
| 983 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 984 | reg = sdio_readb(func, card->reg->io_port_0, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 985 | if (ret < 0) { |
| 986 | ret = -EIO; |
| 987 | goto release_irq; |
| 988 | } |
| 989 | |
| 990 | card->ioport = reg; |
| 991 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 992 | reg = sdio_readb(func, card->reg->io_port_1, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 993 | if (ret < 0) { |
| 994 | ret = -EIO; |
| 995 | goto release_irq; |
| 996 | } |
| 997 | |
| 998 | card->ioport |= (reg << 8); |
| 999 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1000 | reg = sdio_readb(func, card->reg->io_port_2, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1001 | if (ret < 0) { |
| 1002 | ret = -EIO; |
| 1003 | goto release_irq; |
| 1004 | } |
| 1005 | |
| 1006 | card->ioport |= (reg << 16); |
| 1007 | |
| 1008 | BT_DBG("SDIO FUNC%d IO port: 0x%x", func->num, card->ioport); |
| 1009 | |
Bing Zhao | 0d36740 | 2014-03-28 14:54:39 -0700 | [diff] [blame] | 1010 | if (card->reg->int_read_to_clear) { |
| 1011 | reg = sdio_readb(func, card->reg->host_int_rsr, &ret); |
| 1012 | if (ret < 0) { |
| 1013 | ret = -EIO; |
| 1014 | goto release_irq; |
| 1015 | } |
| 1016 | sdio_writeb(func, reg | 0x3f, card->reg->host_int_rsr, &ret); |
| 1017 | if (ret < 0) { |
| 1018 | ret = -EIO; |
| 1019 | goto release_irq; |
| 1020 | } |
| 1021 | |
| 1022 | reg = sdio_readb(func, card->reg->card_misc_cfg, &ret); |
| 1023 | if (ret < 0) { |
| 1024 | ret = -EIO; |
| 1025 | goto release_irq; |
| 1026 | } |
| 1027 | sdio_writeb(func, reg | 0x10, card->reg->card_misc_cfg, &ret); |
| 1028 | if (ret < 0) { |
| 1029 | ret = -EIO; |
| 1030 | goto release_irq; |
| 1031 | } |
| 1032 | } |
| 1033 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1034 | sdio_set_drvdata(func, card); |
| 1035 | |
| 1036 | sdio_release_host(func); |
| 1037 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1038 | return 0; |
| 1039 | |
| 1040 | release_irq: |
| 1041 | sdio_release_irq(func); |
| 1042 | |
| 1043 | disable_func: |
| 1044 | sdio_disable_func(func); |
| 1045 | |
| 1046 | release_host: |
| 1047 | sdio_release_host(func); |
| 1048 | |
| 1049 | failed: |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1050 | return ret; |
| 1051 | } |
| 1052 | |
| 1053 | static int btmrvl_sdio_unregister_dev(struct btmrvl_sdio_card *card) |
| 1054 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1055 | if (card && card->func) { |
| 1056 | sdio_claim_host(card->func); |
| 1057 | sdio_release_irq(card->func); |
| 1058 | sdio_disable_func(card->func); |
| 1059 | sdio_release_host(card->func); |
| 1060 | sdio_set_drvdata(card->func, NULL); |
| 1061 | } |
| 1062 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1063 | return 0; |
| 1064 | } |
| 1065 | |
| 1066 | static int btmrvl_sdio_enable_host_int(struct btmrvl_sdio_card *card) |
| 1067 | { |
| 1068 | int ret; |
| 1069 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 1070 | if (!card || !card->func) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1071 | return -EINVAL; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1072 | |
| 1073 | sdio_claim_host(card->func); |
| 1074 | |
| 1075 | ret = btmrvl_sdio_enable_host_int_mask(card, HIM_ENABLE); |
| 1076 | |
| 1077 | btmrvl_sdio_get_rx_unit(card); |
| 1078 | |
| 1079 | sdio_release_host(card->func); |
| 1080 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1081 | return ret; |
| 1082 | } |
| 1083 | |
| 1084 | static int btmrvl_sdio_disable_host_int(struct btmrvl_sdio_card *card) |
| 1085 | { |
| 1086 | int ret; |
| 1087 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 1088 | if (!card || !card->func) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1089 | return -EINVAL; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1090 | |
| 1091 | sdio_claim_host(card->func); |
| 1092 | |
| 1093 | ret = btmrvl_sdio_disable_host_int_mask(card, HIM_DISABLE); |
| 1094 | |
| 1095 | sdio_release_host(card->func); |
| 1096 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1097 | return ret; |
| 1098 | } |
| 1099 | |
| 1100 | static int btmrvl_sdio_host_to_card(struct btmrvl_private *priv, |
| 1101 | u8 *payload, u16 nb) |
| 1102 | { |
| 1103 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 1104 | int ret = 0; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1105 | int blksz; |
| 1106 | int i = 0; |
| 1107 | u8 *buf = NULL; |
| 1108 | void *tmpbuf = NULL; |
| 1109 | int tmpbufsz; |
| 1110 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1111 | if (!card || !card->func) { |
| 1112 | BT_ERR("card or function is NULL!"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1113 | return -EINVAL; |
| 1114 | } |
| 1115 | |
Ricky Liang | d2f3024 | 2016-06-28 15:06:57 +0800 | [diff] [blame] | 1116 | blksz = DIV_ROUND_UP(nb, SDIO_BLOCK_SIZE) * SDIO_BLOCK_SIZE; |
| 1117 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1118 | buf = payload; |
Ricky Liang | d2f3024 | 2016-06-28 15:06:57 +0800 | [diff] [blame] | 1119 | if ((unsigned long) payload & (BTSDIO_DMA_ALIGN - 1) || |
| 1120 | nb < blksz) { |
| 1121 | tmpbufsz = ALIGN_SZ(blksz, BTSDIO_DMA_ALIGN) + |
| 1122 | BTSDIO_DMA_ALIGN; |
Julia Lawall | 5959809 | 2009-08-06 22:05:18 +0200 | [diff] [blame] | 1123 | tmpbuf = kzalloc(tmpbufsz, GFP_KERNEL); |
| 1124 | if (!tmpbuf) |
| 1125 | return -ENOMEM; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1126 | buf = (u8 *) ALIGN_ADDR(tmpbuf, BTSDIO_DMA_ALIGN); |
| 1127 | memcpy(buf, payload, nb); |
| 1128 | } |
| 1129 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1130 | sdio_claim_host(card->func); |
| 1131 | |
| 1132 | do { |
| 1133 | /* Transfer data to card */ |
| 1134 | ret = sdio_writesb(card->func, card->ioport, buf, |
Ricky Liang | d2f3024 | 2016-06-28 15:06:57 +0800 | [diff] [blame] | 1135 | blksz); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1136 | if (ret < 0) { |
| 1137 | i++; |
| 1138 | BT_ERR("i=%d writesb failed: %d", i, ret); |
Andrei Emeltchenko | 78c1b8e | 2012-10-10 17:41:33 +0300 | [diff] [blame] | 1139 | BT_ERR("hex: %*ph", nb, payload); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1140 | ret = -EIO; |
| 1141 | if (i > MAX_WRITE_IOMEM_RETRY) |
| 1142 | goto exit; |
| 1143 | } |
| 1144 | } while (ret); |
| 1145 | |
| 1146 | priv->btmrvl_dev.tx_dnld_rdy = false; |
| 1147 | |
| 1148 | exit: |
| 1149 | sdio_release_host(card->func); |
Yoichi Yuasa | 88d1a0c | 2010-02-04 09:55:51 +0900 | [diff] [blame] | 1150 | kfree(tmpbuf); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1151 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1152 | return ret; |
| 1153 | } |
| 1154 | |
| 1155 | static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card *card) |
| 1156 | { |
Gustavo Padovan | faff7f7 | 2013-04-18 19:35:33 -0300 | [diff] [blame] | 1157 | int ret; |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1158 | u8 fws0; |
| 1159 | int pollnum = MAX_POLL_TRIES; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1160 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1161 | if (!card || !card->func) { |
| 1162 | BT_ERR("card or function is NULL!"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1163 | return -EINVAL; |
| 1164 | } |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1165 | |
| 1166 | if (!btmrvl_sdio_verify_fw_download(card, 1)) { |
| 1167 | BT_DBG("Firmware already downloaded!"); |
Andreas Fenkart | c1c999e | 2013-04-22 11:10:22 +0200 | [diff] [blame] | 1168 | return 0; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Andreas Fenkart | c1c999e | 2013-04-22 11:10:22 +0200 | [diff] [blame] | 1171 | sdio_claim_host(card->func); |
| 1172 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1173 | /* Check if other function driver is downloading the firmware */ |
| 1174 | fws0 = sdio_readb(card->func, card->reg->card_fw_status0, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1175 | if (ret) { |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1176 | BT_ERR("Failed to read FW downloading status!"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1177 | ret = -EIO; |
| 1178 | goto done; |
| 1179 | } |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1180 | if (fws0) { |
| 1181 | BT_DBG("BT not the winner (%#x). Skip FW downloading", fws0); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1182 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1183 | /* Give other function more time to download the firmware */ |
| 1184 | pollnum *= 10; |
| 1185 | } else { |
| 1186 | if (card->helper) { |
| 1187 | ret = btmrvl_sdio_download_helper(card); |
| 1188 | if (ret) { |
| 1189 | BT_ERR("Failed to download helper!"); |
| 1190 | ret = -EIO; |
| 1191 | goto done; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | if (btmrvl_sdio_download_fw_w_helper(card)) { |
| 1196 | BT_ERR("Failed to download firmware!"); |
| 1197 | ret = -EIO; |
| 1198 | goto done; |
| 1199 | } |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Andreas Fenkart | 69676b1 | 2013-04-22 11:10:23 +0200 | [diff] [blame] | 1202 | /* |
| 1203 | * winner or not, with this test the FW synchronizes when the |
| 1204 | * module can continue its initialization |
| 1205 | */ |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1206 | if (btmrvl_sdio_verify_fw_download(card, pollnum)) { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1207 | BT_ERR("FW failed to be active in time!"); |
Chin-Ran Lo | 86f7ac7 | 2015-12-29 04:26:33 -0800 | [diff] [blame] | 1208 | ret = -ETIMEDOUT; |
| 1209 | goto done; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Aniket Nagarnaik | 4863e4c | 2015-08-06 03:43:09 -0700 | [diff] [blame] | 1212 | sdio_release_host(card->func); |
| 1213 | |
Andreas Fenkart | c1c999e | 2013-04-22 11:10:22 +0200 | [diff] [blame] | 1214 | return 0; |
| 1215 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1216 | done: |
| 1217 | sdio_release_host(card->func); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1218 | return ret; |
| 1219 | } |
| 1220 | |
| 1221 | static int btmrvl_sdio_wakeup_fw(struct btmrvl_private *priv) |
| 1222 | { |
| 1223 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 1224 | int ret = 0; |
| 1225 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1226 | if (!card || !card->func) { |
| 1227 | BT_ERR("card or function is NULL!"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1228 | return -EINVAL; |
| 1229 | } |
| 1230 | |
| 1231 | sdio_claim_host(card->func); |
| 1232 | |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1233 | sdio_writeb(card->func, HOST_POWER_UP, card->reg->cfg, &ret); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1234 | |
| 1235 | sdio_release_host(card->func); |
| 1236 | |
| 1237 | BT_DBG("wake up firmware"); |
| 1238 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1239 | return ret; |
| 1240 | } |
| 1241 | |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1242 | static void btmrvl_sdio_dump_regs(struct btmrvl_private *priv) |
| 1243 | { |
| 1244 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 1245 | int ret = 0; |
| 1246 | unsigned int reg, reg_start, reg_end; |
| 1247 | char buf[256], *ptr; |
| 1248 | u8 loop, func, data; |
| 1249 | int MAX_LOOP = 2; |
| 1250 | |
| 1251 | btmrvl_sdio_wakeup_fw(priv); |
| 1252 | sdio_claim_host(card->func); |
| 1253 | |
| 1254 | for (loop = 0; loop < MAX_LOOP; loop++) { |
| 1255 | memset(buf, 0, sizeof(buf)); |
| 1256 | ptr = buf; |
| 1257 | |
| 1258 | if (loop == 0) { |
| 1259 | /* Read the registers of SDIO function0 */ |
| 1260 | func = loop; |
| 1261 | reg_start = 0; |
| 1262 | reg_end = 9; |
| 1263 | } else { |
| 1264 | func = 2; |
| 1265 | reg_start = 0; |
| 1266 | reg_end = 0x09; |
| 1267 | } |
| 1268 | |
| 1269 | ptr += sprintf(ptr, "SDIO Func%d (%#x-%#x): ", |
| 1270 | func, reg_start, reg_end); |
| 1271 | for (reg = reg_start; reg <= reg_end; reg++) { |
| 1272 | if (func == 0) |
| 1273 | data = sdio_f0_readb(card->func, reg, &ret); |
| 1274 | else |
| 1275 | data = sdio_readb(card->func, reg, &ret); |
| 1276 | |
| 1277 | if (!ret) { |
| 1278 | ptr += sprintf(ptr, "%02x ", data); |
| 1279 | } else { |
| 1280 | ptr += sprintf(ptr, "ERR"); |
| 1281 | break; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | BT_INFO("%s", buf); |
| 1286 | } |
| 1287 | |
| 1288 | sdio_release_host(card->func); |
| 1289 | } |
| 1290 | |
| 1291 | /* This function read/write firmware */ |
| 1292 | static enum |
| 1293 | rdwr_status btmrvl_sdio_rdwr_firmware(struct btmrvl_private *priv, |
| 1294 | u8 doneflag) |
| 1295 | { |
| 1296 | struct btmrvl_sdio_card *card = priv->btmrvl_dev.card; |
| 1297 | int ret, tries; |
| 1298 | u8 ctrl_data = 0; |
| 1299 | |
| 1300 | sdio_writeb(card->func, FW_DUMP_HOST_READY, card->reg->fw_dump_ctrl, |
| 1301 | &ret); |
| 1302 | |
| 1303 | if (ret) { |
| 1304 | BT_ERR("SDIO write err"); |
| 1305 | return RDWR_STATUS_FAILURE; |
| 1306 | } |
| 1307 | |
| 1308 | for (tries = 0; tries < MAX_POLL_TRIES; tries++) { |
| 1309 | ctrl_data = sdio_readb(card->func, card->reg->fw_dump_ctrl, |
| 1310 | &ret); |
| 1311 | |
| 1312 | if (ret) { |
| 1313 | BT_ERR("SDIO read err"); |
| 1314 | return RDWR_STATUS_FAILURE; |
| 1315 | } |
| 1316 | |
| 1317 | if (ctrl_data == FW_DUMP_DONE) |
| 1318 | break; |
| 1319 | if (doneflag && ctrl_data == doneflag) |
| 1320 | return RDWR_STATUS_DONE; |
| 1321 | if (ctrl_data != FW_DUMP_HOST_READY) { |
| 1322 | BT_INFO("The ctrl reg was changed, re-try again!"); |
| 1323 | sdio_writeb(card->func, FW_DUMP_HOST_READY, |
| 1324 | card->reg->fw_dump_ctrl, &ret); |
| 1325 | if (ret) { |
| 1326 | BT_ERR("SDIO write err"); |
| 1327 | return RDWR_STATUS_FAILURE; |
| 1328 | } |
| 1329 | } |
| 1330 | usleep_range(100, 200); |
| 1331 | } |
| 1332 | |
| 1333 | if (ctrl_data == FW_DUMP_HOST_READY) { |
| 1334 | BT_ERR("Fail to pull ctrl_data"); |
| 1335 | return RDWR_STATUS_FAILURE; |
| 1336 | } |
| 1337 | |
| 1338 | return RDWR_STATUS_SUCCESS; |
| 1339 | } |
| 1340 | |
| 1341 | /* This function dump sdio register and memory data */ |
Arend van Spriel | 4565049 | 2018-05-18 00:15:12 +0200 | [diff] [blame] | 1342 | static void btmrvl_sdio_coredump(struct device *dev) |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1343 | { |
Arend van Spriel | 4565049 | 2018-05-18 00:15:12 +0200 | [diff] [blame] | 1344 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 1345 | struct btmrvl_sdio_card *card; |
| 1346 | struct btmrvl_private *priv; |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1347 | int ret = 0; |
| 1348 | unsigned int reg, reg_start, reg_end; |
| 1349 | enum rdwr_status stat; |
| 1350 | u8 *dbg_ptr, *end_ptr, *fw_dump_data, *fw_dump_ptr; |
Xinming Hu | a1e85f04 | 2015-04-21 06:59:56 -0700 | [diff] [blame] | 1351 | u8 dump_num = 0, idx, i, read_reg, doneflag = 0; |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1352 | u32 memory_size, fw_dump_len = 0; |
Len Baker | 785077f | 2021-07-24 14:21:52 +0200 | [diff] [blame] | 1353 | int size = 0; |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1354 | |
Arend van Spriel | 4565049 | 2018-05-18 00:15:12 +0200 | [diff] [blame] | 1355 | card = sdio_get_drvdata(func); |
| 1356 | priv = card->priv; |
| 1357 | |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1358 | /* dump sdio register first */ |
| 1359 | btmrvl_sdio_dump_regs(priv); |
| 1360 | |
| 1361 | if (!card->supports_fw_dump) { |
| 1362 | BT_ERR("Firmware dump not supported for this card!"); |
| 1363 | return; |
| 1364 | } |
| 1365 | |
| 1366 | for (idx = 0; idx < ARRAY_SIZE(mem_type_mapping_tbl); idx++) { |
| 1367 | struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx]; |
| 1368 | |
| 1369 | if (entry->mem_ptr) { |
| 1370 | vfree(entry->mem_ptr); |
| 1371 | entry->mem_ptr = NULL; |
| 1372 | } |
| 1373 | entry->mem_size = 0; |
| 1374 | } |
| 1375 | |
| 1376 | btmrvl_sdio_wakeup_fw(priv); |
| 1377 | sdio_claim_host(card->func); |
| 1378 | |
| 1379 | BT_INFO("== btmrvl firmware dump start =="); |
| 1380 | |
| 1381 | stat = btmrvl_sdio_rdwr_firmware(priv, doneflag); |
| 1382 | if (stat == RDWR_STATUS_FAILURE) |
| 1383 | goto done; |
| 1384 | |
| 1385 | reg = card->reg->fw_dump_start; |
| 1386 | /* Read the number of the memories which will dump */ |
| 1387 | dump_num = sdio_readb(card->func, reg, &ret); |
| 1388 | |
| 1389 | if (ret) { |
| 1390 | BT_ERR("SDIO read memory length err"); |
| 1391 | goto done; |
| 1392 | } |
| 1393 | |
| 1394 | /* Read the length of every memory which will dump */ |
| 1395 | for (idx = 0; idx < dump_num; idx++) { |
| 1396 | struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx]; |
| 1397 | |
| 1398 | stat = btmrvl_sdio_rdwr_firmware(priv, doneflag); |
| 1399 | if (stat == RDWR_STATUS_FAILURE) |
| 1400 | goto done; |
| 1401 | |
| 1402 | memory_size = 0; |
| 1403 | reg = card->reg->fw_dump_start; |
| 1404 | for (i = 0; i < 4; i++) { |
| 1405 | read_reg = sdio_readb(card->func, reg, &ret); |
| 1406 | if (ret) { |
| 1407 | BT_ERR("SDIO read err"); |
| 1408 | goto done; |
| 1409 | } |
| 1410 | memory_size |= (read_reg << i*8); |
| 1411 | reg++; |
| 1412 | } |
| 1413 | |
| 1414 | if (memory_size == 0) { |
| 1415 | BT_INFO("Firmware dump finished!"); |
Nachiket Kukade | 475b9ea | 2015-09-18 06:40:40 -0700 | [diff] [blame] | 1416 | sdio_writeb(card->func, FW_DUMP_READ_DONE, |
| 1417 | card->reg->fw_dump_ctrl, &ret); |
| 1418 | if (ret) { |
| 1419 | BT_ERR("SDIO Write MEMDUMP_FINISH ERR"); |
| 1420 | goto done; |
| 1421 | } |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1422 | break; |
| 1423 | } |
| 1424 | |
| 1425 | BT_INFO("%s_SIZE=0x%x", entry->mem_name, memory_size); |
| 1426 | entry->mem_ptr = vzalloc(memory_size + 1); |
| 1427 | entry->mem_size = memory_size; |
| 1428 | if (!entry->mem_ptr) { |
| 1429 | BT_ERR("Vzalloc %s failed", entry->mem_name); |
| 1430 | goto done; |
| 1431 | } |
| 1432 | |
| 1433 | fw_dump_len += (strlen("========Start dump ") + |
| 1434 | strlen(entry->mem_name) + |
| 1435 | strlen("========\n") + |
| 1436 | (memory_size + 1) + |
| 1437 | strlen("\n========End dump========\n")); |
| 1438 | |
| 1439 | dbg_ptr = entry->mem_ptr; |
| 1440 | end_ptr = dbg_ptr + memory_size; |
| 1441 | |
| 1442 | doneflag = entry->done_flag; |
| 1443 | BT_INFO("Start %s output, please wait...", |
| 1444 | entry->mem_name); |
| 1445 | |
| 1446 | do { |
| 1447 | stat = btmrvl_sdio_rdwr_firmware(priv, doneflag); |
| 1448 | if (stat == RDWR_STATUS_FAILURE) |
| 1449 | goto done; |
| 1450 | |
| 1451 | reg_start = card->reg->fw_dump_start; |
| 1452 | reg_end = card->reg->fw_dump_end; |
| 1453 | for (reg = reg_start; reg <= reg_end; reg++) { |
| 1454 | *dbg_ptr = sdio_readb(card->func, reg, &ret); |
| 1455 | if (ret) { |
| 1456 | BT_ERR("SDIO read err"); |
| 1457 | goto done; |
| 1458 | } |
| 1459 | if (dbg_ptr < end_ptr) |
| 1460 | dbg_ptr++; |
| 1461 | else |
| 1462 | BT_ERR("Allocated buffer not enough"); |
| 1463 | } |
| 1464 | |
Colin Ian King | dd912f4 | 2021-06-16 14:07:57 +0100 | [diff] [blame] | 1465 | if (stat == RDWR_STATUS_DONE) { |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1466 | BT_INFO("%s done: size=0x%tx", |
| 1467 | entry->mem_name, |
| 1468 | dbg_ptr - entry->mem_ptr); |
| 1469 | break; |
| 1470 | } |
| 1471 | } while (1); |
| 1472 | } |
| 1473 | |
| 1474 | BT_INFO("== btmrvl firmware dump end =="); |
| 1475 | |
| 1476 | done: |
| 1477 | sdio_release_host(card->func); |
| 1478 | |
| 1479 | if (fw_dump_len == 0) |
| 1480 | return; |
| 1481 | |
Len Baker | 785077f | 2021-07-24 14:21:52 +0200 | [diff] [blame] | 1482 | fw_dump_data = vzalloc(fw_dump_len + 1); |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1483 | if (!fw_dump_data) { |
| 1484 | BT_ERR("Vzalloc fw_dump_data fail!"); |
| 1485 | return; |
| 1486 | } |
| 1487 | fw_dump_ptr = fw_dump_data; |
| 1488 | |
| 1489 | /* Dump all the memory data into single file, a userspace script will |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 1490 | * be used to split all the memory data to multiple files |
| 1491 | */ |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1492 | BT_INFO("== btmrvl firmware dump to /sys/class/devcoredump start"); |
| 1493 | for (idx = 0; idx < dump_num; idx++) { |
| 1494 | struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx]; |
| 1495 | |
| 1496 | if (entry->mem_ptr) { |
Len Baker | 785077f | 2021-07-24 14:21:52 +0200 | [diff] [blame] | 1497 | size += scnprintf(fw_dump_ptr + size, |
| 1498 | fw_dump_len + 1 - size, |
| 1499 | "========Start dump %s========\n", |
| 1500 | entry->mem_name); |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1501 | |
Len Baker | 785077f | 2021-07-24 14:21:52 +0200 | [diff] [blame] | 1502 | memcpy(fw_dump_ptr + size, entry->mem_ptr, |
| 1503 | entry->mem_size); |
| 1504 | size += entry->mem_size; |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1505 | |
Len Baker | 785077f | 2021-07-24 14:21:52 +0200 | [diff] [blame] | 1506 | size += scnprintf(fw_dump_ptr + size, |
| 1507 | fw_dump_len + 1 - size, |
| 1508 | "\n========End dump========\n"); |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1509 | |
| 1510 | vfree(mem_type_mapping_tbl[idx].mem_ptr); |
| 1511 | mem_type_mapping_tbl[idx].mem_ptr = NULL; |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | /* fw_dump_data will be free in device coredump release function |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 1516 | * after 5 min |
| 1517 | */ |
Shengzhen Li | d490263 | 2015-08-19 03:12:19 -0700 | [diff] [blame] | 1518 | dev_coredumpv(&card->func->dev, fw_dump_data, fw_dump_len, GFP_KERNEL); |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1519 | BT_INFO("== btmrvl firmware dump to /sys/class/devcoredump end"); |
| 1520 | } |
| 1521 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1522 | static int btmrvl_sdio_probe(struct sdio_func *func, |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 1523 | const struct sdio_device_id *id) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1524 | { |
| 1525 | int ret = 0; |
| 1526 | struct btmrvl_private *priv = NULL; |
| 1527 | struct btmrvl_sdio_card *card = NULL; |
| 1528 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1529 | BT_INFO("vendor=0x%x, device=0x%x, class=%d, fn=%d", |
| 1530 | id->vendor, id->device, id->class, func->num); |
| 1531 | |
Sachin Kamat | eb17ea3 | 2012-07-27 12:38:36 +0530 | [diff] [blame] | 1532 | card = devm_kzalloc(&func->dev, sizeof(*card), GFP_KERNEL); |
| 1533 | if (!card) |
| 1534 | return -ENOMEM; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1535 | |
| 1536 | card->func = func; |
| 1537 | |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 1538 | if (id->driver_data) { |
| 1539 | struct btmrvl_sdio_device *data = (void *) id->driver_data; |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1540 | card->helper = data->helper; |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 1541 | card->firmware = data->firmware; |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1542 | card->reg = data->reg; |
| 1543 | card->sd_blksz_fw_dl = data->sd_blksz_fw_dl; |
Bing Zhao | 4df82b5 | 2014-03-31 14:41:44 -0700 | [diff] [blame] | 1544 | card->support_pscan_win_report = data->support_pscan_win_report; |
Xinming Hu | dc75961 | 2014-11-24 02:40:53 -0800 | [diff] [blame] | 1545 | card->supports_fw_dump = data->supports_fw_dump; |
Marcel Holtmann | dcf47f3 | 2009-06-09 16:21:58 +0200 | [diff] [blame] | 1546 | } |
| 1547 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1548 | if (btmrvl_sdio_register_dev(card) < 0) { |
| 1549 | BT_ERR("Failed to register BT device!"); |
Sachin Kamat | eb17ea3 | 2012-07-27 12:38:36 +0530 | [diff] [blame] | 1550 | return -ENODEV; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | /* Disable the interrupts on the card */ |
| 1554 | btmrvl_sdio_disable_host_int(card); |
| 1555 | |
| 1556 | if (btmrvl_sdio_download_fw(card)) { |
| 1557 | BT_ERR("Downloading firmware failed!"); |
| 1558 | ret = -ENODEV; |
| 1559 | goto unreg_dev; |
| 1560 | } |
| 1561 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1562 | btmrvl_sdio_enable_host_int(card); |
| 1563 | |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 1564 | /* Device tree node parsing and platform specific configuration*/ |
| 1565 | btmrvl_sdio_probe_of(&func->dev, card); |
| 1566 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1567 | priv = btmrvl_add_card(card); |
| 1568 | if (!priv) { |
| 1569 | BT_ERR("Initializing card failed!"); |
| 1570 | ret = -ENODEV; |
| 1571 | goto disable_host_int; |
| 1572 | } |
| 1573 | |
| 1574 | card->priv = priv; |
| 1575 | |
| 1576 | /* Initialize the interface specific function pointers */ |
| 1577 | priv->hw_host_to_card = btmrvl_sdio_host_to_card; |
| 1578 | priv->hw_wakeup_firmware = btmrvl_sdio_wakeup_fw; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 1579 | priv->hw_process_int_status = btmrvl_sdio_process_int_status; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1580 | |
Bing Zhao | 6406160 | 2010-03-03 14:37:36 -0800 | [diff] [blame] | 1581 | if (btmrvl_register_hdev(priv)) { |
| 1582 | BT_ERR("Register hdev failed!"); |
| 1583 | ret = -ENODEV; |
| 1584 | goto disable_host_int; |
| 1585 | } |
| 1586 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1587 | return 0; |
| 1588 | |
| 1589 | disable_host_int: |
| 1590 | btmrvl_sdio_disable_host_int(card); |
| 1591 | unreg_dev: |
| 1592 | btmrvl_sdio_unregister_dev(card); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1593 | return ret; |
| 1594 | } |
| 1595 | |
| 1596 | static void btmrvl_sdio_remove(struct sdio_func *func) |
| 1597 | { |
| 1598 | struct btmrvl_sdio_card *card; |
| 1599 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1600 | if (func) { |
| 1601 | card = sdio_get_drvdata(func); |
| 1602 | if (card) { |
| 1603 | /* Send SHUTDOWN command & disable interrupt |
| 1604 | * if user removes the module. |
| 1605 | */ |
| 1606 | if (user_rmmod) { |
| 1607 | btmrvl_send_module_cfg_cmd(card->priv, |
| 1608 | MODULE_SHUTDOWN_REQ); |
| 1609 | btmrvl_sdio_disable_host_int(card); |
| 1610 | } |
Abhishek Pandit-Subedi | e660b35 | 2020-06-10 18:53:55 -0700 | [diff] [blame] | 1611 | |
Colin Ian King | 9232259 | 2017-03-21 12:20:28 +0000 | [diff] [blame] | 1612 | BT_DBG("unregister dev"); |
Amitkumar Karwar | 7b4b874 | 2015-01-01 00:13:41 -0800 | [diff] [blame] | 1613 | card->priv->surprise_removed = true; |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1614 | btmrvl_sdio_unregister_dev(card); |
| 1615 | btmrvl_remove_card(card->priv); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1616 | } |
| 1617 | } |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1620 | static int btmrvl_sdio_suspend(struct device *dev) |
| 1621 | { |
| 1622 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 1623 | struct btmrvl_sdio_card *card; |
| 1624 | struct btmrvl_private *priv; |
| 1625 | mmc_pm_flag_t pm_flags; |
| 1626 | struct hci_dev *hcidev; |
| 1627 | |
| 1628 | if (func) { |
| 1629 | pm_flags = sdio_get_host_pm_caps(func); |
| 1630 | BT_DBG("%s: suspend: PM flags = 0x%x", sdio_func_id(func), |
| 1631 | pm_flags); |
| 1632 | if (!(pm_flags & MMC_PM_KEEP_POWER)) { |
| 1633 | BT_ERR("%s: cannot remain alive while suspended", |
| 1634 | sdio_func_id(func)); |
| 1635 | return -ENOSYS; |
| 1636 | } |
| 1637 | card = sdio_get_drvdata(func); |
| 1638 | if (!card || !card->priv) { |
| 1639 | BT_ERR("card or priv structure is not valid"); |
| 1640 | return 0; |
| 1641 | } |
| 1642 | } else { |
| 1643 | BT_ERR("sdio_func is not specified"); |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 1647 | /* Enable platform specific wakeup interrupt */ |
Abhishek Pandit-Subedi | e660b35 | 2020-06-10 18:53:55 -0700 | [diff] [blame] | 1648 | if (card->plt_wake_cfg && card->plt_wake_cfg->irq_bt >= 0 && |
| 1649 | device_may_wakeup(dev)) { |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 1650 | card->plt_wake_cfg->wake_by_bt = false; |
| 1651 | enable_irq(card->plt_wake_cfg->irq_bt); |
| 1652 | enable_irq_wake(card->plt_wake_cfg->irq_bt); |
| 1653 | } |
| 1654 | |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1655 | priv = card->priv; |
Chin-Ran Lo | 8cf60cf | 2016-01-06 06:34:38 -0800 | [diff] [blame] | 1656 | priv->adapter->is_suspending = true; |
Chin-Ran Lo | 5bf8a74 | 2014-07-14 21:05:37 -0700 | [diff] [blame] | 1657 | hcidev = priv->btmrvl_dev.hcidev; |
| 1658 | BT_DBG("%s: SDIO suspend", hcidev->name); |
| 1659 | hci_suspend_dev(hcidev); |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1660 | |
| 1661 | if (priv->adapter->hs_state != HS_ACTIVATED) { |
| 1662 | if (btmrvl_enable_hs(priv)) { |
Colin Ian King | 8f91566 | 2017-02-18 22:52:55 +0000 | [diff] [blame] | 1663 | BT_ERR("HS not activated, suspend failed!"); |
Xinming Hu | 6eb7bd6 | 2017-03-31 14:32:31 +0800 | [diff] [blame] | 1664 | /* Disable platform specific wakeup interrupt */ |
| 1665 | if (card->plt_wake_cfg && |
Abhishek Pandit-Subedi | e660b35 | 2020-06-10 18:53:55 -0700 | [diff] [blame] | 1666 | card->plt_wake_cfg->irq_bt >= 0 && |
| 1667 | device_may_wakeup(dev)) { |
Xinming Hu | 6eb7bd6 | 2017-03-31 14:32:31 +0800 | [diff] [blame] | 1668 | disable_irq_wake(card->plt_wake_cfg->irq_bt); |
| 1669 | disable_irq(card->plt_wake_cfg->irq_bt); |
| 1670 | } |
| 1671 | |
Amitkumar Karwar | e7acf43 | 2016-07-15 16:20:52 +0530 | [diff] [blame] | 1672 | priv->adapter->is_suspending = false; |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1673 | return -EBUSY; |
| 1674 | } |
| 1675 | } |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1676 | |
Chin-Ran Lo | 8cf60cf | 2016-01-06 06:34:38 -0800 | [diff] [blame] | 1677 | priv->adapter->is_suspending = false; |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1678 | priv->adapter->is_suspended = true; |
| 1679 | |
| 1680 | /* We will keep the power when hs enabled successfully */ |
| 1681 | if (priv->adapter->hs_state == HS_ACTIVATED) { |
| 1682 | BT_DBG("suspend with MMC_PM_KEEP_POWER"); |
| 1683 | return sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1684 | } |
prasanna karthik | f1554b7 | 2017-03-28 19:44:00 +0000 | [diff] [blame] | 1685 | |
| 1686 | BT_DBG("suspend without MMC_PM_KEEP_POWER"); |
| 1687 | return 0; |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | static int btmrvl_sdio_resume(struct device *dev) |
| 1691 | { |
| 1692 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 1693 | struct btmrvl_sdio_card *card; |
| 1694 | struct btmrvl_private *priv; |
| 1695 | mmc_pm_flag_t pm_flags; |
| 1696 | struct hci_dev *hcidev; |
| 1697 | |
| 1698 | if (func) { |
| 1699 | pm_flags = sdio_get_host_pm_caps(func); |
| 1700 | BT_DBG("%s: resume: PM flags = 0x%x", sdio_func_id(func), |
| 1701 | pm_flags); |
| 1702 | card = sdio_get_drvdata(func); |
| 1703 | if (!card || !card->priv) { |
| 1704 | BT_ERR("card or priv structure is not valid"); |
| 1705 | return 0; |
| 1706 | } |
| 1707 | } else { |
| 1708 | BT_ERR("sdio_func is not specified"); |
| 1709 | return 0; |
| 1710 | } |
| 1711 | priv = card->priv; |
| 1712 | |
| 1713 | if (!priv->adapter->is_suspended) { |
| 1714 | BT_DBG("device already resumed"); |
| 1715 | return 0; |
| 1716 | } |
| 1717 | |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1718 | priv->hw_wakeup_firmware(priv); |
| 1719 | priv->adapter->hs_state = HS_DEACTIVATED; |
Chin-Ran Lo | 5bf8a74 | 2014-07-14 21:05:37 -0700 | [diff] [blame] | 1720 | hcidev = priv->btmrvl_dev.hcidev; |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1721 | BT_DBG("%s: HS DEACTIVATED in resume!", hcidev->name); |
Chin-Ran Lo | 5bf8a74 | 2014-07-14 21:05:37 -0700 | [diff] [blame] | 1722 | priv->adapter->is_suspended = false; |
| 1723 | BT_DBG("%s: SDIO resume", hcidev->name); |
| 1724 | hci_resume_dev(hcidev); |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1725 | |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 1726 | /* Disable platform specific wakeup interrupt */ |
Abhishek Pandit-Subedi | e660b35 | 2020-06-10 18:53:55 -0700 | [diff] [blame] | 1727 | if (card->plt_wake_cfg && card->plt_wake_cfg->irq_bt >= 0 && |
| 1728 | device_may_wakeup(dev)) { |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 1729 | disable_irq_wake(card->plt_wake_cfg->irq_bt); |
Jeffy Chen | 9af02d8 | 2017-01-23 12:18:51 +0800 | [diff] [blame] | 1730 | disable_irq(card->plt_wake_cfg->irq_bt); |
| 1731 | if (card->plt_wake_cfg->wake_by_bt) |
| 1732 | /* Undo our disable, since interrupt handler already |
| 1733 | * did this. |
| 1734 | */ |
| 1735 | enable_irq(card->plt_wake_cfg->irq_bt); |
Xinming Hu | bb7f4f0 | 2016-04-26 06:57:27 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1738 | return 0; |
| 1739 | } |
| 1740 | |
| 1741 | static const struct dev_pm_ops btmrvl_sdio_pm_ops = { |
| 1742 | .suspend = btmrvl_sdio_suspend, |
| 1743 | .resume = btmrvl_sdio_resume, |
| 1744 | }; |
| 1745 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1746 | static struct sdio_driver bt_mrvl_sdio = { |
| 1747 | .name = "btmrvl_sdio", |
| 1748 | .id_table = btmrvl_sdio_ids, |
| 1749 | .probe = btmrvl_sdio_probe, |
| 1750 | .remove = btmrvl_sdio_remove, |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1751 | .drv = { |
| 1752 | .owner = THIS_MODULE, |
Arend van Spriel | 4565049 | 2018-05-18 00:15:12 +0200 | [diff] [blame] | 1753 | .coredump = btmrvl_sdio_coredump, |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 1754 | .pm = &btmrvl_sdio_pm_ops, |
| 1755 | } |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1756 | }; |
| 1757 | |
Peter Huewe | 8e5b230 | 2009-12-22 09:34:20 +0100 | [diff] [blame] | 1758 | static int __init btmrvl_sdio_init_module(void) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1759 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1760 | if (sdio_register_driver(&bt_mrvl_sdio) != 0) { |
| 1761 | BT_ERR("SDIO Driver Registration Failed"); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1762 | return -ENODEV; |
| 1763 | } |
| 1764 | |
| 1765 | /* Clear the flag in case user removes the card. */ |
| 1766 | user_rmmod = 0; |
| 1767 | |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1768 | return 0; |
| 1769 | } |
| 1770 | |
Peter Huewe | 8e5b230 | 2009-12-22 09:34:20 +0100 | [diff] [blame] | 1771 | static void __exit btmrvl_sdio_exit_module(void) |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1772 | { |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1773 | /* Set the flag as user is removing this module. */ |
| 1774 | user_rmmod = 1; |
| 1775 | |
| 1776 | sdio_unregister_driver(&bt_mrvl_sdio); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | module_init(btmrvl_sdio_init_module); |
| 1780 | module_exit(btmrvl_sdio_exit_module); |
| 1781 | |
| 1782 | MODULE_AUTHOR("Marvell International Ltd."); |
Marcel Holtmann | 9666fb3 | 2009-06-09 21:45:04 +0200 | [diff] [blame] | 1783 | MODULE_DESCRIPTION("Marvell BT-over-SDIO driver ver " VERSION); |
Bing Zhao | 789221e | 2009-06-02 14:29:36 -0700 | [diff] [blame] | 1784 | MODULE_VERSION(VERSION); |
| 1785 | MODULE_LICENSE("GPL v2"); |
Lubomir Rintel | 77189df | 2013-03-13 12:04:30 +0100 | [diff] [blame] | 1786 | MODULE_FIRMWARE("mrvl/sd8688_helper.bin"); |
| 1787 | MODULE_FIRMWARE("mrvl/sd8688.bin"); |
Kevin Gan | 9f72c1d | 2011-04-08 18:19:33 -0700 | [diff] [blame] | 1788 | MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin"); |
Bing Zhao | 2ac654f | 2011-11-16 20:40:42 -0800 | [diff] [blame] | 1789 | MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin"); |
Xinming Hu | 3907d55 | 2014-09-30 06:45:33 -0400 | [diff] [blame] | 1790 | MODULE_FIRMWARE("mrvl/sd8887_uapsta.bin"); |
Bing Zhao | 22f2efe | 2013-05-13 18:15:32 -0700 | [diff] [blame] | 1791 | MODULE_FIRMWARE("mrvl/sd8897_uapsta.bin"); |
Pali Rohár | dbec3af | 2020-06-03 10:22:28 +0200 | [diff] [blame] | 1792 | MODULE_FIRMWARE("mrvl/sdsd8977_combo_v2.bin"); |
Tamás Szűcs | 73623340 | 2019-04-14 20:38:14 +0200 | [diff] [blame] | 1793 | MODULE_FIRMWARE("mrvl/sd8987_uapsta.bin"); |
Pali Rohár | 00eb0cb | 2020-06-03 10:22:29 +0200 | [diff] [blame] | 1794 | MODULE_FIRMWARE("mrvl/sdsd8997_combo_v4.bin"); |