2 * Marvell BT-over-SDIO driver: SDIO interface related functions.
4 * Copyright (C) 2009, Marvell International Ltd.
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.
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.
21 #include <linux/firmware.h>
22 #include <linux/slab.h>
23 #include <linux/suspend.h>
25 #include <linux/mmc/sdio_ids.h>
26 #include <linux/mmc/sdio_func.h>
27 #include <linux/module.h>
28 #include <linux/devcoredump.h>
30 #include <net/bluetooth/bluetooth.h>
31 #include <net/bluetooth/hci_core.h>
33 #include "btmrvl_drv.h"
34 #include "btmrvl_sdio.h"
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},
56 static const struct of_device_id btmrvl_sdio_of_match_table
[] = {
57 { .compatible
= "marvell,sd8897-bt" },
58 { .compatible
= "marvell,sd8997-bt" },
62 static irqreturn_t
btmrvl_wake_irq_bt(int irq
, void *priv
)
64 struct btmrvl_sdio_card
*card
= priv
;
65 struct device
*dev
= &card
->func
->dev
;
66 struct btmrvl_plt_wake_cfg
*cfg
= card
->plt_wake_cfg
;
68 dev_info(dev
, "wake by bt\n");
69 cfg
->wake_by_bt
= true;
70 disable_irq_nosync(irq
);
72 pm_wakeup_event(dev
, 0);
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.
83 static int btmrvl_sdio_probe_of(struct device
*dev
,
84 struct btmrvl_sdio_card
*card
)
86 struct btmrvl_plt_wake_cfg
*cfg
;
90 !of_match_node(btmrvl_sdio_of_match_table
, dev
->of_node
)) {
91 dev_info(dev
, "sdio device tree data not available\n");
95 card
->plt_of_node
= dev
->of_node
;
97 card
->plt_wake_cfg
= devm_kzalloc(dev
, sizeof(*card
->plt_wake_cfg
),
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);
103 dev_err(dev
, "fail to parse irq_bt from device tree\n");
106 ret
= devm_request_irq(dev
, cfg
->irq_bt
,
111 "Failed to request irq_bt %d (%d)\n",
115 /* Configure wakeup (enabled by default) */
116 device_init_wakeup(dev
, true);
117 disable_irq(cfg
->irq_bt
);
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
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.
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.
138 static u8 user_rmmod
;
141 static const struct btmrvl_sdio_card_reg btmrvl_reg_8688
= {
143 .host_int_mask
= 0x04,
144 .host_intstatus
= 0x05,
146 .sq_read_base_addr_a0
= 0x10,
147 .sq_read_base_addr_a1
= 0x11,
148 .card_fw_status0
= 0x40,
149 .card_fw_status1
= 0x41,
151 .card_rx_unit
= 0x43,
155 .int_read_to_clear
= false,
157 static const struct btmrvl_sdio_card_reg btmrvl_reg_87xx
= {
159 .host_int_mask
= 0x02,
160 .host_intstatus
= 0x03,
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,
168 .card_rx_unit
= 0x63,
172 .int_read_to_clear
= false,
175 static const struct btmrvl_sdio_card_reg btmrvl_reg_8887
= {
177 .host_int_mask
= 0x08,
178 .host_intstatus
= 0x0C,
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,
186 .card_rx_unit
= 0x8B,
190 .int_read_to_clear
= true,
191 .host_int_rsr
= 0x04,
192 .card_misc_cfg
= 0xD8,
195 static const struct btmrvl_sdio_card_reg btmrvl_reg_8897
= {
197 .host_int_mask
= 0x02,
198 .host_intstatus
= 0x03,
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,
206 .card_rx_unit
= 0xc3,
210 .int_read_to_clear
= true,
211 .host_int_rsr
= 0x01,
212 .card_misc_cfg
= 0xcc,
213 .fw_dump_ctrl
= 0xe2,
214 .fw_dump_start
= 0xe3,
218 static const struct btmrvl_sdio_card_reg btmrvl_reg_89xx
= {
220 .host_int_mask
= 0x08,
221 .host_intstatus
= 0x0c,
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,
229 .card_rx_unit
= 0xeb,
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,
241 static const struct btmrvl_sdio_device btmrvl_sdio_sd8688
= {
242 .helper
= "mrvl/sd8688_helper.bin",
243 .firmware
= "mrvl/sd8688.bin",
244 .reg
= &btmrvl_reg_8688
,
245 .support_pscan_win_report
= false,
246 .sd_blksz_fw_dl
= 64,
247 .supports_fw_dump
= false,
250 static const struct btmrvl_sdio_device btmrvl_sdio_sd8787
= {
252 .firmware
= "mrvl/sd8787_uapsta.bin",
253 .reg
= &btmrvl_reg_87xx
,
254 .support_pscan_win_report
= false,
255 .sd_blksz_fw_dl
= 256,
256 .supports_fw_dump
= false,
259 static const struct btmrvl_sdio_device btmrvl_sdio_sd8797
= {
261 .firmware
= "mrvl/sd8797_uapsta.bin",
262 .reg
= &btmrvl_reg_87xx
,
263 .support_pscan_win_report
= false,
264 .sd_blksz_fw_dl
= 256,
265 .supports_fw_dump
= false,
268 static const struct btmrvl_sdio_device btmrvl_sdio_sd8887
= {
270 .firmware
= "mrvl/sd8887_uapsta.bin",
271 .reg
= &btmrvl_reg_8887
,
272 .support_pscan_win_report
= true,
273 .sd_blksz_fw_dl
= 256,
274 .supports_fw_dump
= false,
277 static const struct btmrvl_sdio_device btmrvl_sdio_sd8897
= {
279 .firmware
= "mrvl/sd8897_uapsta.bin",
280 .reg
= &btmrvl_reg_8897
,
281 .support_pscan_win_report
= true,
282 .sd_blksz_fw_dl
= 256,
283 .supports_fw_dump
= true,
286 static const struct btmrvl_sdio_device btmrvl_sdio_sd8977
= {
288 .firmware
= "mrvl/sdsd8977_combo_v2.bin",
289 .reg
= &btmrvl_reg_89xx
,
290 .support_pscan_win_report
= true,
291 .sd_blksz_fw_dl
= 256,
292 .supports_fw_dump
= true,
295 static const struct btmrvl_sdio_device btmrvl_sdio_sd8987
= {
297 .firmware
= "mrvl/sd8987_uapsta.bin",
298 .reg
= &btmrvl_reg_89xx
,
299 .support_pscan_win_report
= true,
300 .sd_blksz_fw_dl
= 256,
301 .supports_fw_dump
= true,
304 static const struct btmrvl_sdio_device btmrvl_sdio_sd8997
= {
306 .firmware
= "mrvl/sdsd8997_combo_v4.bin",
307 .reg
= &btmrvl_reg_89xx
,
308 .support_pscan_win_report
= true,
309 .sd_blksz_fw_dl
= 256,
310 .supports_fw_dump
= true,
313 static const struct sdio_device_id btmrvl_sdio_ids
[] = {
314 /* Marvell SD8688 Bluetooth device */
315 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8688_BT
),
316 .driver_data
= (unsigned long)&btmrvl_sdio_sd8688
},
317 /* Marvell SD8787 Bluetooth device */
318 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8787_BT
),
319 .driver_data
= (unsigned long)&btmrvl_sdio_sd8787
},
320 /* Marvell SD8787 Bluetooth AMP device */
321 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8787_BT_AMP
),
322 .driver_data
= (unsigned long)&btmrvl_sdio_sd8787
},
323 /* Marvell SD8797 Bluetooth device */
324 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8797_BT
),
325 .driver_data
= (unsigned long)&btmrvl_sdio_sd8797
},
326 /* Marvell SD8887 Bluetooth device */
327 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8887_BT
),
328 .driver_data
= (unsigned long)&btmrvl_sdio_sd8887
},
329 /* Marvell SD8897 Bluetooth device */
330 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8897_BT
),
331 .driver_data
= (unsigned long)&btmrvl_sdio_sd8897
},
332 /* Marvell SD8977 Bluetooth device */
333 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8977_BT
),
334 .driver_data
= (unsigned long)&btmrvl_sdio_sd8977
},
335 /* Marvell SD8987 Bluetooth device */
336 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8987_BT
),
337 .driver_data
= (unsigned long)&btmrvl_sdio_sd8987
},
338 /* Marvell SD8997 Bluetooth device */
339 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, SDIO_DEVICE_ID_MARVELL_8997_BT
),
340 .driver_data
= (unsigned long)&btmrvl_sdio_sd8997
},
342 { } /* Terminating entry */
345 MODULE_DEVICE_TABLE(sdio
, btmrvl_sdio_ids
);
347 static int btmrvl_sdio_get_rx_unit(struct btmrvl_sdio_card
*card
)
352 reg
= sdio_readb(card
->func
, card
->reg
->card_rx_unit
, &ret
);
359 static int btmrvl_sdio_read_fw_status(struct btmrvl_sdio_card
*card
, u16
*dat
)
366 fws0
= sdio_readb(card
->func
, card
->reg
->card_fw_status0
, &ret
);
370 fws1
= sdio_readb(card
->func
, card
->reg
->card_fw_status1
, &ret
);
374 *dat
= (((u16
) fws1
) << 8) | fws0
;
379 static int btmrvl_sdio_read_rx_len(struct btmrvl_sdio_card
*card
, u16
*dat
)
384 reg
= sdio_readb(card
->func
, card
->reg
->card_rx_len
, &ret
);
386 *dat
= (u16
) reg
<< card
->rx_unit
;
391 static int btmrvl_sdio_enable_host_int_mask(struct btmrvl_sdio_card
*card
,
396 sdio_writeb(card
->func
, mask
, card
->reg
->host_int_mask
, &ret
);
398 BT_ERR("Unable to enable the host interrupt!");
405 static int btmrvl_sdio_disable_host_int_mask(struct btmrvl_sdio_card
*card
,
411 host_int_mask
= sdio_readb(card
->func
, card
->reg
->host_int_mask
, &ret
);
415 host_int_mask
&= ~mask
;
417 sdio_writeb(card
->func
, host_int_mask
, card
->reg
->host_int_mask
, &ret
);
419 BT_ERR("Unable to disable the host interrupt!");
426 static int btmrvl_sdio_poll_card_status(struct btmrvl_sdio_card
*card
, u8 bits
)
432 for (tries
= 0; tries
< MAX_POLL_TRIES
* 1000; tries
++) {
433 status
= sdio_readb(card
->func
, card
->reg
->card_status
, &ret
);
436 if ((status
& bits
) == bits
)
445 BT_ERR("FAILED! ret=%d", ret
);
450 static int btmrvl_sdio_verify_fw_download(struct btmrvl_sdio_card
*card
,
456 /* Wait for firmware to become ready */
457 for (tries
= 0; tries
< pollnum
; tries
++) {
458 sdio_claim_host(card
->func
);
459 ret
= btmrvl_sdio_read_fw_status(card
, &firmwarestat
);
460 sdio_release_host(card
->func
);
464 if (firmwarestat
== FIRMWARE_READY
)
473 static int btmrvl_sdio_download_helper(struct btmrvl_sdio_card
*card
)
475 const struct firmware
*fw_helper
= NULL
;
476 const u8
*helper
= NULL
;
478 void *tmphlprbuf
= NULL
;
479 int tmphlprbufsz
, hlprblknow
, helperlen
;
483 ret
= request_firmware(&fw_helper
, card
->helper
,
485 if ((ret
< 0) || !fw_helper
) {
486 BT_ERR("request_firmware(helper) failed, error code = %d",
492 helper
= fw_helper
->data
;
493 helperlen
= fw_helper
->size
;
495 BT_DBG("Downloading helper image (%d bytes), block size %d bytes",
496 helperlen
, SDIO_BLOCK_SIZE
);
498 tmphlprbufsz
= ALIGN_SZ(BTM_UPLD_SIZE
, BTSDIO_DMA_ALIGN
);
500 tmphlprbuf
= kzalloc(tmphlprbufsz
, GFP_KERNEL
);
502 BT_ERR("Unable to allocate buffer for helper."
503 " Terminating download");
508 helperbuf
= (u8
*) ALIGN_ADDR(tmphlprbuf
, BTSDIO_DMA_ALIGN
);
510 /* Perform helper data transfer */
511 tx_len
= (FIRMWARE_TRANSFER_NBLOCK
* SDIO_BLOCK_SIZE
)
516 ret
= btmrvl_sdio_poll_card_status(card
,
517 CARD_IO_READY
| DN_LD_CARD_RDY
);
519 BT_ERR("Helper download poll status timeout @ %d",
524 /* Check if there is more data? */
525 if (hlprblknow
>= helperlen
)
528 if (helperlen
- hlprblknow
< tx_len
)
529 tx_len
= helperlen
- hlprblknow
;
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);
537 memcpy(&helperbuf
[SDIO_HEADER_LEN
], &helper
[hlprblknow
],
540 /* Now send the data */
541 ret
= sdio_writesb(card
->func
, card
->ioport
, helperbuf
,
542 FIRMWARE_TRANSFER_NBLOCK
* SDIO_BLOCK_SIZE
);
544 BT_ERR("IO error during helper download @ %d",
549 hlprblknow
+= tx_len
;
552 BT_DBG("Transferring helper image EOF block");
554 memset(helperbuf
, 0x0, SDIO_BLOCK_SIZE
);
556 ret
= sdio_writesb(card
->func
, card
->ioport
, helperbuf
,
559 BT_ERR("IO error in writing helper image EOF block");
567 release_firmware(fw_helper
);
571 static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card
*card
)
573 const struct firmware
*fw_firmware
= NULL
;
574 const u8
*firmware
= NULL
;
575 int firmwarelen
, tmpfwbufsz
, ret
;
576 unsigned int tries
, offset
;
578 void *tmpfwbuf
= NULL
;
580 u16 len
, blksz_dl
= card
->sd_blksz_fw_dl
;
581 int txlen
= 0, tx_blocks
= 0, count
= 0;
583 ret
= request_firmware(&fw_firmware
, card
->firmware
,
585 if ((ret
< 0) || !fw_firmware
) {
586 BT_ERR("request_firmware(firmware) failed, error code = %d",
592 firmware
= fw_firmware
->data
;
593 firmwarelen
= fw_firmware
->size
;
595 BT_DBG("Downloading FW image (%d bytes)", firmwarelen
);
597 tmpfwbufsz
= ALIGN_SZ(BTM_UPLD_SIZE
, BTSDIO_DMA_ALIGN
);
598 tmpfwbuf
= kzalloc(tmpfwbufsz
, GFP_KERNEL
);
600 BT_ERR("Unable to allocate buffer for firmware."
601 " Terminating download");
606 /* Ensure aligned firmware buffer */
607 fwbuf
= (u8
*) ALIGN_ADDR(tmpfwbuf
, BTSDIO_DMA_ALIGN
);
609 /* Perform firmware data transfer */
612 ret
= btmrvl_sdio_poll_card_status(card
,
613 CARD_IO_READY
| DN_LD_CARD_RDY
);
615 BT_ERR("FW download with helper poll status"
616 " timeout @ %d", offset
);
620 /* Check if there is more data ? */
621 if (offset
>= firmwarelen
)
624 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
625 base0
= sdio_readb(card
->func
,
626 card
->reg
->sq_read_base_addr_a0
, &ret
);
628 BT_ERR("BASE0 register read failed:"
629 " base0 = 0x%04X(%d)."
630 " Terminating download",
635 base1
= sdio_readb(card
->func
,
636 card
->reg
->sq_read_base_addr_a1
, &ret
);
638 BT_ERR("BASE1 register read failed:"
639 " base1 = 0x%04X(%d)."
640 " Terminating download",
646 len
= (((u16
) base1
) << 8) | base0
;
655 else if (len
> BTM_UPLD_SIZE
) {
656 BT_ERR("FW download failure @%d, invalid length %d",
666 if (count
> MAX_WRITE_IOMEM_RETRY
) {
667 BT_ERR("FW download failure @%d, "
668 "over max retry count", offset
);
672 BT_ERR("FW CRC error indicated by the helper: "
673 "len = 0x%04X, txlen = %d", len
, txlen
);
675 /* Set txlen to 0 so as to resend from same offset */
681 if (firmwarelen
- offset
< txlen
)
682 txlen
= firmwarelen
- offset
;
684 tx_blocks
= DIV_ROUND_UP(txlen
, blksz_dl
);
686 memcpy(fwbuf
, &firmware
[offset
], txlen
);
689 ret
= sdio_writesb(card
->func
, card
->ioport
, fwbuf
,
690 tx_blocks
* blksz_dl
);
693 BT_ERR("FW download, writesb(%d) failed @%d",
695 sdio_writeb(card
->func
, HOST_CMD53_FIN
,
696 card
->reg
->cfg
, &ret
);
698 BT_ERR("writeb failed (CFG)");
704 BT_INFO("FW download over, size %d bytes", offset
);
710 release_firmware(fw_firmware
);
714 static int btmrvl_sdio_card_to_host(struct btmrvl_private
*priv
)
717 int ret
, num_blocks
, blksz
;
718 struct sk_buff
*skb
= NULL
;
721 struct hci_dev
*hdev
= priv
->btmrvl_dev
.hcidev
;
722 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
724 if (!card
|| !card
->func
) {
725 BT_ERR("card or function is NULL!");
730 /* Read the length of data to be transferred */
731 ret
= btmrvl_sdio_read_rx_len(card
, &buf_len
);
733 BT_ERR("read rx_len failed");
738 blksz
= SDIO_BLOCK_SIZE
;
739 num_blocks
= DIV_ROUND_UP(buf_len
, blksz
);
741 if (buf_len
<= SDIO_HEADER_LEN
742 || (num_blocks
* blksz
) > ALLOC_BUF_SIZE
) {
743 BT_ERR("invalid packet length: %d", buf_len
);
748 /* Allocate buffer */
749 skb
= bt_skb_alloc(num_blocks
* blksz
+ BTSDIO_DMA_ALIGN
, GFP_KERNEL
);
751 BT_ERR("No free skb");
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));
765 ret
= sdio_readsb(card
->func
, payload
, card
->ioport
,
768 BT_ERR("readsb failed: %d", ret
);
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)
777 buf_len
= payload
[0];
778 buf_len
|= payload
[1] << 8;
779 buf_len
|= payload
[2] << 16;
781 if (buf_len
> blksz
* num_blocks
) {
782 BT_ERR("Skip incorrect packet: hdrlen %d buffer %d",
783 buf_len
, blksz
* num_blocks
);
791 case HCI_ACLDATA_PKT
:
792 case HCI_SCODATA_PKT
:
794 hci_skb_pkt_type(skb
) = type
;
795 skb_put(skb
, buf_len
);
796 skb_pull(skb
, SDIO_HEADER_LEN
);
798 if (type
== HCI_EVENT_PKT
) {
799 if (btmrvl_check_evtpkt(priv
, skb
))
800 hci_recv_frame(hdev
, skb
);
802 hci_recv_frame(hdev
, skb
);
805 hdev
->stat
.byte_rx
+= buf_len
;
808 case MRVL_VENDOR_PKT
:
809 hci_skb_pkt_type(skb
) = HCI_VENDOR_PKT
;
810 skb_put(skb
, buf_len
);
811 skb_pull(skb
, SDIO_HEADER_LEN
);
813 if (btmrvl_process_event(priv
, skb
))
814 hci_recv_frame(hdev
, skb
);
816 hdev
->stat
.byte_rx
+= buf_len
;
820 BT_ERR("Unknown packet type:%d", type
);
821 BT_ERR("hex: %*ph", blksz
* num_blocks
, payload
);
837 static int btmrvl_sdio_process_int_status(struct btmrvl_private
*priv
)
841 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
843 spin_lock_irqsave(&priv
->driver_lock
, flags
);
846 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
848 sdio_claim_host(card
->func
);
849 if (ireg
& DN_LD_HOST_INT_STATUS
) {
850 if (priv
->btmrvl_dev
.tx_dnld_rdy
)
851 BT_DBG("tx_done already received: "
852 " int_status=0x%x", ireg
);
854 priv
->btmrvl_dev
.tx_dnld_rdy
= true;
857 if (ireg
& UP_LD_HOST_INT_STATUS
)
858 btmrvl_sdio_card_to_host(priv
);
860 sdio_release_host(card
->func
);
865 static int btmrvl_sdio_read_to_clear(struct btmrvl_sdio_card
*card
, u8
*ireg
)
867 struct btmrvl_adapter
*adapter
= card
->priv
->adapter
;
870 ret
= sdio_readsb(card
->func
, adapter
->hw_regs
, 0, SDIO_BLOCK_SIZE
);
872 BT_ERR("sdio_readsb: read int hw_regs failed: %d", ret
);
876 *ireg
= adapter
->hw_regs
[card
->reg
->host_intstatus
];
877 BT_DBG("hw_regs[%#x]=%#x", card
->reg
->host_intstatus
, *ireg
);
882 static int btmrvl_sdio_write_to_clear(struct btmrvl_sdio_card
*card
, u8
*ireg
)
886 *ireg
= sdio_readb(card
->func
, card
->reg
->host_intstatus
, &ret
);
888 BT_ERR("sdio_readb: read int status failed: %d", ret
);
894 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
895 * Clear the interrupt status register and re-enable the
898 BT_DBG("int_status = 0x%x", *ireg
);
900 sdio_writeb(card
->func
, ~(*ireg
) & (DN_LD_HOST_INT_STATUS
|
901 UP_LD_HOST_INT_STATUS
),
902 card
->reg
->host_intstatus
, &ret
);
904 BT_ERR("sdio_writeb: clear int status failed: %d", ret
);
912 static void btmrvl_sdio_interrupt(struct sdio_func
*func
)
914 struct btmrvl_private
*priv
;
915 struct btmrvl_sdio_card
*card
;
920 card
= sdio_get_drvdata(func
);
921 if (!card
|| !card
->priv
) {
922 BT_ERR("sbi_interrupt(%p) card or priv is NULL, card=%p",
929 if (priv
->surprise_removed
)
932 if (card
->reg
->int_read_to_clear
)
933 ret
= btmrvl_sdio_read_to_clear(card
, &ireg
);
935 ret
= btmrvl_sdio_write_to_clear(card
, &ireg
);
940 spin_lock_irqsave(&priv
->driver_lock
, flags
);
942 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
944 btmrvl_interrupt(priv
);
947 static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card
*card
)
949 struct sdio_func
*func
;
953 if (!card
|| !card
->func
) {
954 BT_ERR("Error: card or function is NULL!");
961 sdio_claim_host(func
);
963 ret
= sdio_enable_func(func
);
965 BT_ERR("sdio_enable_func() failed: ret=%d", ret
);
970 ret
= sdio_claim_irq(func
, btmrvl_sdio_interrupt
);
972 BT_ERR("sdio_claim_irq failed: ret=%d", ret
);
977 ret
= sdio_set_block_size(card
->func
, SDIO_BLOCK_SIZE
);
979 BT_ERR("cannot set SDIO block size");
984 reg
= sdio_readb(func
, card
->reg
->io_port_0
, &ret
);
992 reg
= sdio_readb(func
, card
->reg
->io_port_1
, &ret
);
998 card
->ioport
|= (reg
<< 8);
1000 reg
= sdio_readb(func
, card
->reg
->io_port_2
, &ret
);
1006 card
->ioport
|= (reg
<< 16);
1008 BT_DBG("SDIO FUNC%d IO port: 0x%x", func
->num
, card
->ioport
);
1010 if (card
->reg
->int_read_to_clear
) {
1011 reg
= sdio_readb(func
, card
->reg
->host_int_rsr
, &ret
);
1016 sdio_writeb(func
, reg
| 0x3f, card
->reg
->host_int_rsr
, &ret
);
1022 reg
= sdio_readb(func
, card
->reg
->card_misc_cfg
, &ret
);
1027 sdio_writeb(func
, reg
| 0x10, card
->reg
->card_misc_cfg
, &ret
);
1034 sdio_set_drvdata(func
, card
);
1036 sdio_release_host(func
);
1041 sdio_release_irq(func
);
1044 sdio_disable_func(func
);
1047 sdio_release_host(func
);
1053 static int btmrvl_sdio_unregister_dev(struct btmrvl_sdio_card
*card
)
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
);
1066 static int btmrvl_sdio_enable_host_int(struct btmrvl_sdio_card
*card
)
1070 if (!card
|| !card
->func
)
1073 sdio_claim_host(card
->func
);
1075 ret
= btmrvl_sdio_enable_host_int_mask(card
, HIM_ENABLE
);
1077 btmrvl_sdio_get_rx_unit(card
);
1079 sdio_release_host(card
->func
);
1084 static int btmrvl_sdio_disable_host_int(struct btmrvl_sdio_card
*card
)
1088 if (!card
|| !card
->func
)
1091 sdio_claim_host(card
->func
);
1093 ret
= btmrvl_sdio_disable_host_int_mask(card
, HIM_DISABLE
);
1095 sdio_release_host(card
->func
);
1100 static int btmrvl_sdio_host_to_card(struct btmrvl_private
*priv
,
1101 u8
*payload
, u16 nb
)
1103 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
1108 void *tmpbuf
= NULL
;
1111 if (!card
|| !card
->func
) {
1112 BT_ERR("card or function is NULL!");
1116 blksz
= DIV_ROUND_UP(nb
, SDIO_BLOCK_SIZE
) * SDIO_BLOCK_SIZE
;
1119 if ((unsigned long) payload
& (BTSDIO_DMA_ALIGN
- 1) ||
1121 tmpbufsz
= ALIGN_SZ(blksz
, BTSDIO_DMA_ALIGN
) +
1123 tmpbuf
= kzalloc(tmpbufsz
, GFP_KERNEL
);
1126 buf
= (u8
*) ALIGN_ADDR(tmpbuf
, BTSDIO_DMA_ALIGN
);
1127 memcpy(buf
, payload
, nb
);
1130 sdio_claim_host(card
->func
);
1133 /* Transfer data to card */
1134 ret
= sdio_writesb(card
->func
, card
->ioport
, buf
,
1138 BT_ERR("i=%d writesb failed: %d", i
, ret
);
1139 BT_ERR("hex: %*ph", nb
, payload
);
1141 if (i
> MAX_WRITE_IOMEM_RETRY
)
1146 priv
->btmrvl_dev
.tx_dnld_rdy
= false;
1149 sdio_release_host(card
->func
);
1155 static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card
*card
)
1159 int pollnum
= MAX_POLL_TRIES
;
1161 if (!card
|| !card
->func
) {
1162 BT_ERR("card or function is NULL!");
1166 if (!btmrvl_sdio_verify_fw_download(card
, 1)) {
1167 BT_DBG("Firmware already downloaded!");
1171 sdio_claim_host(card
->func
);
1173 /* Check if other function driver is downloading the firmware */
1174 fws0
= sdio_readb(card
->func
, card
->reg
->card_fw_status0
, &ret
);
1176 BT_ERR("Failed to read FW downloading status!");
1181 BT_DBG("BT not the winner (%#x). Skip FW downloading", fws0
);
1183 /* Give other function more time to download the firmware */
1187 ret
= btmrvl_sdio_download_helper(card
);
1189 BT_ERR("Failed to download helper!");
1195 if (btmrvl_sdio_download_fw_w_helper(card
)) {
1196 BT_ERR("Failed to download firmware!");
1203 * winner or not, with this test the FW synchronizes when the
1204 * module can continue its initialization
1206 if (btmrvl_sdio_verify_fw_download(card
, pollnum
)) {
1207 BT_ERR("FW failed to be active in time!");
1212 sdio_release_host(card
->func
);
1217 sdio_release_host(card
->func
);
1221 static int btmrvl_sdio_wakeup_fw(struct btmrvl_private
*priv
)
1223 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
1226 if (!card
|| !card
->func
) {
1227 BT_ERR("card or function is NULL!");
1231 sdio_claim_host(card
->func
);
1233 sdio_writeb(card
->func
, HOST_POWER_UP
, card
->reg
->cfg
, &ret
);
1235 sdio_release_host(card
->func
);
1237 BT_DBG("wake up firmware");
1242 static void btmrvl_sdio_dump_regs(struct btmrvl_private
*priv
)
1244 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
1246 unsigned int reg
, reg_start
, reg_end
;
1247 char buf
[256], *ptr
;
1248 u8 loop
, func
, data
;
1251 btmrvl_sdio_wakeup_fw(priv
);
1252 sdio_claim_host(card
->func
);
1254 for (loop
= 0; loop
< MAX_LOOP
; loop
++) {
1255 memset(buf
, 0, sizeof(buf
));
1259 /* Read the registers of SDIO function0 */
1269 ptr
+= sprintf(ptr
, "SDIO Func%d (%#x-%#x): ",
1270 func
, reg_start
, reg_end
);
1271 for (reg
= reg_start
; reg
<= reg_end
; reg
++) {
1273 data
= sdio_f0_readb(card
->func
, reg
, &ret
);
1275 data
= sdio_readb(card
->func
, reg
, &ret
);
1278 ptr
+= sprintf(ptr
, "%02x ", data
);
1280 ptr
+= sprintf(ptr
, "ERR");
1288 sdio_release_host(card
->func
);
1291 /* This function read/write firmware */
1293 rdwr_status
btmrvl_sdio_rdwr_firmware(struct btmrvl_private
*priv
,
1296 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
1300 sdio_writeb(card
->func
, FW_DUMP_HOST_READY
, card
->reg
->fw_dump_ctrl
,
1304 BT_ERR("SDIO write err");
1305 return RDWR_STATUS_FAILURE
;
1308 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
1309 ctrl_data
= sdio_readb(card
->func
, card
->reg
->fw_dump_ctrl
,
1313 BT_ERR("SDIO read err");
1314 return RDWR_STATUS_FAILURE
;
1317 if (ctrl_data
== FW_DUMP_DONE
)
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
);
1326 BT_ERR("SDIO write err");
1327 return RDWR_STATUS_FAILURE
;
1330 usleep_range(100, 200);
1333 if (ctrl_data
== FW_DUMP_HOST_READY
) {
1334 BT_ERR("Fail to pull ctrl_data");
1335 return RDWR_STATUS_FAILURE
;
1338 return RDWR_STATUS_SUCCESS
;
1341 /* This function dump sdio register and memory data */
1342 static void btmrvl_sdio_coredump(struct device
*dev
)
1344 struct sdio_func
*func
= dev_to_sdio_func(dev
);
1345 struct btmrvl_sdio_card
*card
;
1346 struct btmrvl_private
*priv
;
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
;
1351 u8 dump_num
= 0, idx
, i
, read_reg
, doneflag
= 0;
1352 u32 memory_size
, fw_dump_len
= 0;
1354 card
= sdio_get_drvdata(func
);
1357 /* dump sdio register first */
1358 btmrvl_sdio_dump_regs(priv
);
1360 if (!card
->supports_fw_dump
) {
1361 BT_ERR("Firmware dump not supported for this card!");
1365 for (idx
= 0; idx
< ARRAY_SIZE(mem_type_mapping_tbl
); idx
++) {
1366 struct memory_type_mapping
*entry
= &mem_type_mapping_tbl
[idx
];
1368 if (entry
->mem_ptr
) {
1369 vfree(entry
->mem_ptr
);
1370 entry
->mem_ptr
= NULL
;
1372 entry
->mem_size
= 0;
1375 btmrvl_sdio_wakeup_fw(priv
);
1376 sdio_claim_host(card
->func
);
1378 BT_INFO("== btmrvl firmware dump start ==");
1380 stat
= btmrvl_sdio_rdwr_firmware(priv
, doneflag
);
1381 if (stat
== RDWR_STATUS_FAILURE
)
1384 reg
= card
->reg
->fw_dump_start
;
1385 /* Read the number of the memories which will dump */
1386 dump_num
= sdio_readb(card
->func
, reg
, &ret
);
1389 BT_ERR("SDIO read memory length err");
1393 /* Read the length of every memory which will dump */
1394 for (idx
= 0; idx
< dump_num
; idx
++) {
1395 struct memory_type_mapping
*entry
= &mem_type_mapping_tbl
[idx
];
1397 stat
= btmrvl_sdio_rdwr_firmware(priv
, doneflag
);
1398 if (stat
== RDWR_STATUS_FAILURE
)
1402 reg
= card
->reg
->fw_dump_start
;
1403 for (i
= 0; i
< 4; i
++) {
1404 read_reg
= sdio_readb(card
->func
, reg
, &ret
);
1406 BT_ERR("SDIO read err");
1409 memory_size
|= (read_reg
<< i
*8);
1413 if (memory_size
== 0) {
1414 BT_INFO("Firmware dump finished!");
1415 sdio_writeb(card
->func
, FW_DUMP_READ_DONE
,
1416 card
->reg
->fw_dump_ctrl
, &ret
);
1418 BT_ERR("SDIO Write MEMDUMP_FINISH ERR");
1424 BT_INFO("%s_SIZE=0x%x", entry
->mem_name
, memory_size
);
1425 entry
->mem_ptr
= vzalloc(memory_size
+ 1);
1426 entry
->mem_size
= memory_size
;
1427 if (!entry
->mem_ptr
) {
1428 BT_ERR("Vzalloc %s failed", entry
->mem_name
);
1432 fw_dump_len
+= (strlen("========Start dump ") +
1433 strlen(entry
->mem_name
) +
1434 strlen("========\n") +
1436 strlen("\n========End dump========\n"));
1438 dbg_ptr
= entry
->mem_ptr
;
1439 end_ptr
= dbg_ptr
+ memory_size
;
1441 doneflag
= entry
->done_flag
;
1442 BT_INFO("Start %s output, please wait...",
1446 stat
= btmrvl_sdio_rdwr_firmware(priv
, doneflag
);
1447 if (stat
== RDWR_STATUS_FAILURE
)
1450 reg_start
= card
->reg
->fw_dump_start
;
1451 reg_end
= card
->reg
->fw_dump_end
;
1452 for (reg
= reg_start
; reg
<= reg_end
; reg
++) {
1453 *dbg_ptr
= sdio_readb(card
->func
, reg
, &ret
);
1455 BT_ERR("SDIO read err");
1458 if (dbg_ptr
< end_ptr
)
1461 BT_ERR("Allocated buffer not enough");
1464 if (stat
!= RDWR_STATUS_DONE
) {
1467 BT_INFO("%s done: size=0x%tx",
1469 dbg_ptr
- entry
->mem_ptr
);
1475 BT_INFO("== btmrvl firmware dump end ==");
1478 sdio_release_host(card
->func
);
1480 if (fw_dump_len
== 0)
1483 fw_dump_data
= vzalloc(fw_dump_len
+1);
1484 if (!fw_dump_data
) {
1485 BT_ERR("Vzalloc fw_dump_data fail!");
1488 fw_dump_ptr
= fw_dump_data
;
1490 /* Dump all the memory data into single file, a userspace script will
1491 * be used to split all the memory data to multiple files
1493 BT_INFO("== btmrvl firmware dump to /sys/class/devcoredump start");
1494 for (idx
= 0; idx
< dump_num
; idx
++) {
1495 struct memory_type_mapping
*entry
= &mem_type_mapping_tbl
[idx
];
1497 if (entry
->mem_ptr
) {
1498 strcpy(fw_dump_ptr
, "========Start dump ");
1499 fw_dump_ptr
+= strlen("========Start dump ");
1501 strcpy(fw_dump_ptr
, entry
->mem_name
);
1502 fw_dump_ptr
+= strlen(entry
->mem_name
);
1504 strcpy(fw_dump_ptr
, "========\n");
1505 fw_dump_ptr
+= strlen("========\n");
1507 memcpy(fw_dump_ptr
, entry
->mem_ptr
, entry
->mem_size
);
1508 fw_dump_ptr
+= entry
->mem_size
;
1510 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1511 fw_dump_ptr
+= strlen("\n========End dump========\n");
1513 vfree(mem_type_mapping_tbl
[idx
].mem_ptr
);
1514 mem_type_mapping_tbl
[idx
].mem_ptr
= NULL
;
1518 /* fw_dump_data will be free in device coredump release function
1521 dev_coredumpv(&card
->func
->dev
, fw_dump_data
, fw_dump_len
, GFP_KERNEL
);
1522 BT_INFO("== btmrvl firmware dump to /sys/class/devcoredump end");
1525 static int btmrvl_sdio_probe(struct sdio_func
*func
,
1526 const struct sdio_device_id
*id
)
1529 struct btmrvl_private
*priv
= NULL
;
1530 struct btmrvl_sdio_card
*card
= NULL
;
1532 BT_INFO("vendor=0x%x, device=0x%x, class=%d, fn=%d",
1533 id
->vendor
, id
->device
, id
->class, func
->num
);
1535 card
= devm_kzalloc(&func
->dev
, sizeof(*card
), GFP_KERNEL
);
1541 if (id
->driver_data
) {
1542 struct btmrvl_sdio_device
*data
= (void *) id
->driver_data
;
1543 card
->helper
= data
->helper
;
1544 card
->firmware
= data
->firmware
;
1545 card
->reg
= data
->reg
;
1546 card
->sd_blksz_fw_dl
= data
->sd_blksz_fw_dl
;
1547 card
->support_pscan_win_report
= data
->support_pscan_win_report
;
1548 card
->supports_fw_dump
= data
->supports_fw_dump
;
1551 if (btmrvl_sdio_register_dev(card
) < 0) {
1552 BT_ERR("Failed to register BT device!");
1556 /* Disable the interrupts on the card */
1557 btmrvl_sdio_disable_host_int(card
);
1559 if (btmrvl_sdio_download_fw(card
)) {
1560 BT_ERR("Downloading firmware failed!");
1565 btmrvl_sdio_enable_host_int(card
);
1567 /* Device tree node parsing and platform specific configuration*/
1568 btmrvl_sdio_probe_of(&func
->dev
, card
);
1570 priv
= btmrvl_add_card(card
);
1572 BT_ERR("Initializing card failed!");
1574 goto disable_host_int
;
1579 /* Initialize the interface specific function pointers */
1580 priv
->hw_host_to_card
= btmrvl_sdio_host_to_card
;
1581 priv
->hw_wakeup_firmware
= btmrvl_sdio_wakeup_fw
;
1582 priv
->hw_process_int_status
= btmrvl_sdio_process_int_status
;
1584 if (btmrvl_register_hdev(priv
)) {
1585 BT_ERR("Register hdev failed!");
1587 goto disable_host_int
;
1593 btmrvl_sdio_disable_host_int(card
);
1595 btmrvl_sdio_unregister_dev(card
);
1599 static void btmrvl_sdio_remove(struct sdio_func
*func
)
1601 struct btmrvl_sdio_card
*card
;
1604 card
= sdio_get_drvdata(func
);
1606 /* Send SHUTDOWN command & disable interrupt
1607 * if user removes the module.
1610 btmrvl_send_module_cfg_cmd(card
->priv
,
1611 MODULE_SHUTDOWN_REQ
);
1612 btmrvl_sdio_disable_host_int(card
);
1615 BT_DBG("unregister dev");
1616 card
->priv
->surprise_removed
= true;
1617 btmrvl_sdio_unregister_dev(card
);
1618 btmrvl_remove_card(card
->priv
);
1623 static int btmrvl_sdio_suspend(struct device
*dev
)
1625 struct sdio_func
*func
= dev_to_sdio_func(dev
);
1626 struct btmrvl_sdio_card
*card
;
1627 struct btmrvl_private
*priv
;
1628 mmc_pm_flag_t pm_flags
;
1629 struct hci_dev
*hcidev
;
1632 pm_flags
= sdio_get_host_pm_caps(func
);
1633 BT_DBG("%s: suspend: PM flags = 0x%x", sdio_func_id(func
),
1635 if (!(pm_flags
& MMC_PM_KEEP_POWER
)) {
1636 BT_ERR("%s: cannot remain alive while suspended",
1637 sdio_func_id(func
));
1640 card
= sdio_get_drvdata(func
);
1641 if (!card
|| !card
->priv
) {
1642 BT_ERR("card or priv structure is not valid");
1646 BT_ERR("sdio_func is not specified");
1650 /* Enable platform specific wakeup interrupt */
1651 if (card
->plt_wake_cfg
&& card
->plt_wake_cfg
->irq_bt
>= 0 &&
1652 device_may_wakeup(dev
)) {
1653 card
->plt_wake_cfg
->wake_by_bt
= false;
1654 enable_irq(card
->plt_wake_cfg
->irq_bt
);
1655 enable_irq_wake(card
->plt_wake_cfg
->irq_bt
);
1659 priv
->adapter
->is_suspending
= true;
1660 hcidev
= priv
->btmrvl_dev
.hcidev
;
1661 BT_DBG("%s: SDIO suspend", hcidev
->name
);
1662 hci_suspend_dev(hcidev
);
1664 if (priv
->adapter
->hs_state
!= HS_ACTIVATED
) {
1665 if (btmrvl_enable_hs(priv
)) {
1666 BT_ERR("HS not activated, suspend failed!");
1667 /* Disable platform specific wakeup interrupt */
1668 if (card
->plt_wake_cfg
&&
1669 card
->plt_wake_cfg
->irq_bt
>= 0 &&
1670 device_may_wakeup(dev
)) {
1671 disable_irq_wake(card
->plt_wake_cfg
->irq_bt
);
1672 disable_irq(card
->plt_wake_cfg
->irq_bt
);
1675 priv
->adapter
->is_suspending
= false;
1680 priv
->adapter
->is_suspending
= false;
1681 priv
->adapter
->is_suspended
= true;
1683 /* We will keep the power when hs enabled successfully */
1684 if (priv
->adapter
->hs_state
== HS_ACTIVATED
) {
1685 BT_DBG("suspend with MMC_PM_KEEP_POWER");
1686 return sdio_set_host_pm_flags(func
, MMC_PM_KEEP_POWER
);
1689 BT_DBG("suspend without MMC_PM_KEEP_POWER");
1693 static int btmrvl_sdio_resume(struct device
*dev
)
1695 struct sdio_func
*func
= dev_to_sdio_func(dev
);
1696 struct btmrvl_sdio_card
*card
;
1697 struct btmrvl_private
*priv
;
1698 mmc_pm_flag_t pm_flags
;
1699 struct hci_dev
*hcidev
;
1702 pm_flags
= sdio_get_host_pm_caps(func
);
1703 BT_DBG("%s: resume: PM flags = 0x%x", sdio_func_id(func
),
1705 card
= sdio_get_drvdata(func
);
1706 if (!card
|| !card
->priv
) {
1707 BT_ERR("card or priv structure is not valid");
1711 BT_ERR("sdio_func is not specified");
1716 if (!priv
->adapter
->is_suspended
) {
1717 BT_DBG("device already resumed");
1721 priv
->hw_wakeup_firmware(priv
);
1722 priv
->adapter
->hs_state
= HS_DEACTIVATED
;
1723 hcidev
= priv
->btmrvl_dev
.hcidev
;
1724 BT_DBG("%s: HS DEACTIVATED in resume!", hcidev
->name
);
1725 priv
->adapter
->is_suspended
= false;
1726 BT_DBG("%s: SDIO resume", hcidev
->name
);
1727 hci_resume_dev(hcidev
);
1729 /* Disable platform specific wakeup interrupt */
1730 if (card
->plt_wake_cfg
&& card
->plt_wake_cfg
->irq_bt
>= 0 &&
1731 device_may_wakeup(dev
)) {
1732 disable_irq_wake(card
->plt_wake_cfg
->irq_bt
);
1733 disable_irq(card
->plt_wake_cfg
->irq_bt
);
1734 if (card
->plt_wake_cfg
->wake_by_bt
)
1735 /* Undo our disable, since interrupt handler already
1738 enable_irq(card
->plt_wake_cfg
->irq_bt
);
1744 static const struct dev_pm_ops btmrvl_sdio_pm_ops
= {
1745 .suspend
= btmrvl_sdio_suspend
,
1746 .resume
= btmrvl_sdio_resume
,
1749 static struct sdio_driver bt_mrvl_sdio
= {
1750 .name
= "btmrvl_sdio",
1751 .id_table
= btmrvl_sdio_ids
,
1752 .probe
= btmrvl_sdio_probe
,
1753 .remove
= btmrvl_sdio_remove
,
1755 .owner
= THIS_MODULE
,
1756 .coredump
= btmrvl_sdio_coredump
,
1757 .pm
= &btmrvl_sdio_pm_ops
,
1761 static int __init
btmrvl_sdio_init_module(void)
1763 if (sdio_register_driver(&bt_mrvl_sdio
) != 0) {
1764 BT_ERR("SDIO Driver Registration Failed");
1768 /* Clear the flag in case user removes the card. */
1774 static void __exit
btmrvl_sdio_exit_module(void)
1776 /* Set the flag as user is removing this module. */
1779 sdio_unregister_driver(&bt_mrvl_sdio
);
1782 module_init(btmrvl_sdio_init_module
);
1783 module_exit(btmrvl_sdio_exit_module
);
1785 MODULE_AUTHOR("Marvell International Ltd.");
1786 MODULE_DESCRIPTION("Marvell BT-over-SDIO driver ver " VERSION
);
1787 MODULE_VERSION(VERSION
);
1788 MODULE_LICENSE("GPL v2");
1789 MODULE_FIRMWARE("mrvl/sd8688_helper.bin");
1790 MODULE_FIRMWARE("mrvl/sd8688.bin");
1791 MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin");
1792 MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin");
1793 MODULE_FIRMWARE("mrvl/sd8887_uapsta.bin");
1794 MODULE_FIRMWARE("mrvl/sd8897_uapsta.bin");
1795 MODULE_FIRMWARE("mrvl/sdsd8977_combo_v2.bin");
1796 MODULE_FIRMWARE("mrvl/sd8987_uapsta.bin");
1797 MODULE_FIRMWARE("mrvl/sdsd8997_combo_v4.bin");