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>
24 #include <linux/mmc/sdio_ids.h>
25 #include <linux/mmc/sdio_func.h>
26 #include <linux/module.h>
28 #include <net/bluetooth/bluetooth.h>
29 #include <net/bluetooth/hci_core.h>
31 #include "btmrvl_drv.h"
32 #include "btmrvl_sdio.h"
36 /* The btmrvl_sdio_remove() callback function is called
37 * when user removes this module from kernel space or ejects
38 * the card from the slot. The driver handles these 2 cases
40 * If the user is removing the module, a MODULE_SHUTDOWN_REQ
41 * command is sent to firmware and interrupt will be disabled.
42 * If the card is removed, there is no need to send command
43 * or disable interrupt.
45 * The variable 'user_rmmod' is used to distinguish these two
46 * scenarios. This flag is initialized as FALSE in case the card
47 * is removed, and will be set to TRUE for module removal when
48 * module_exit function is called.
53 static const struct btmrvl_sdio_card_reg btmrvl_reg_8688
= {
55 .host_int_mask
= 0x04,
56 .host_intstatus
= 0x05,
58 .sq_read_base_addr_a0
= 0x10,
59 .sq_read_base_addr_a1
= 0x11,
60 .card_fw_status0
= 0x40,
61 .card_fw_status1
= 0x41,
68 static const struct btmrvl_sdio_card_reg btmrvl_reg_87xx
= {
70 .host_int_mask
= 0x02,
71 .host_intstatus
= 0x03,
73 .sq_read_base_addr_a0
= 0x40,
74 .sq_read_base_addr_a1
= 0x41,
75 .card_revision
= 0x5c,
76 .card_fw_status0
= 0x60,
77 .card_fw_status1
= 0x61,
85 static const struct btmrvl_sdio_device btmrvl_sdio_sd8688
= {
86 .helper
= "sd8688_helper.bin",
87 .firmware
= "sd8688.bin",
88 .reg
= &btmrvl_reg_8688
,
92 static const struct btmrvl_sdio_device btmrvl_sdio_sd8787
= {
94 .firmware
= "mrvl/sd8787_uapsta.bin",
95 .reg
= &btmrvl_reg_87xx
,
96 .sd_blksz_fw_dl
= 256,
99 static const struct btmrvl_sdio_device btmrvl_sdio_sd8797
= {
101 .firmware
= "mrvl/sd8797_uapsta.bin",
102 .reg
= &btmrvl_reg_87xx
,
103 .sd_blksz_fw_dl
= 256,
106 static const struct sdio_device_id btmrvl_sdio_ids
[] = {
107 /* Marvell SD8688 Bluetooth device */
108 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, 0x9105),
109 .driver_data
= (unsigned long) &btmrvl_sdio_sd8688
},
110 /* Marvell SD8787 Bluetooth device */
111 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, 0x911A),
112 .driver_data
= (unsigned long) &btmrvl_sdio_sd8787
},
113 /* Marvell SD8787 Bluetooth AMP device */
114 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, 0x911B),
115 .driver_data
= (unsigned long) &btmrvl_sdio_sd8787
},
116 /* Marvell SD8797 Bluetooth device */
117 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL
, 0x912A),
118 .driver_data
= (unsigned long) &btmrvl_sdio_sd8797
},
120 { } /* Terminating entry */
123 MODULE_DEVICE_TABLE(sdio
, btmrvl_sdio_ids
);
125 static int btmrvl_sdio_get_rx_unit(struct btmrvl_sdio_card
*card
)
130 reg
= sdio_readb(card
->func
, card
->reg
->card_rx_unit
, &ret
);
137 static int btmrvl_sdio_read_fw_status(struct btmrvl_sdio_card
*card
, u16
*dat
)
144 fws0
= sdio_readb(card
->func
, card
->reg
->card_fw_status0
, &ret
);
148 fws1
= sdio_readb(card
->func
, card
->reg
->card_fw_status1
, &ret
);
152 *dat
= (((u16
) fws1
) << 8) | fws0
;
157 static int btmrvl_sdio_read_rx_len(struct btmrvl_sdio_card
*card
, u16
*dat
)
162 reg
= sdio_readb(card
->func
, card
->reg
->card_rx_len
, &ret
);
164 *dat
= (u16
) reg
<< card
->rx_unit
;
169 static int btmrvl_sdio_enable_host_int_mask(struct btmrvl_sdio_card
*card
,
174 sdio_writeb(card
->func
, mask
, card
->reg
->host_int_mask
, &ret
);
176 BT_ERR("Unable to enable the host interrupt!");
183 static int btmrvl_sdio_disable_host_int_mask(struct btmrvl_sdio_card
*card
,
189 host_int_mask
= sdio_readb(card
->func
, card
->reg
->host_int_mask
, &ret
);
193 host_int_mask
&= ~mask
;
195 sdio_writeb(card
->func
, host_int_mask
, card
->reg
->host_int_mask
, &ret
);
197 BT_ERR("Unable to disable the host interrupt!");
204 static int btmrvl_sdio_poll_card_status(struct btmrvl_sdio_card
*card
, u8 bits
)
210 for (tries
= 0; tries
< MAX_POLL_TRIES
* 1000; tries
++) {
211 status
= sdio_readb(card
->func
, card
->reg
->card_status
, &ret
);
214 if ((status
& bits
) == bits
)
223 BT_ERR("FAILED! ret=%d", ret
);
228 static int btmrvl_sdio_verify_fw_download(struct btmrvl_sdio_card
*card
,
231 int ret
= -ETIMEDOUT
;
235 /* Wait for firmware to become ready */
236 for (tries
= 0; tries
< pollnum
; tries
++) {
237 if (btmrvl_sdio_read_fw_status(card
, &firmwarestat
) < 0)
240 if (firmwarestat
== FIRMWARE_READY
) {
251 static int btmrvl_sdio_download_helper(struct btmrvl_sdio_card
*card
)
253 const struct firmware
*fw_helper
= NULL
;
254 const u8
*helper
= NULL
;
256 void *tmphlprbuf
= NULL
;
257 int tmphlprbufsz
, hlprblknow
, helperlen
;
261 ret
= request_firmware(&fw_helper
, card
->helper
,
263 if ((ret
< 0) || !fw_helper
) {
264 BT_ERR("request_firmware(helper) failed, error code = %d",
270 helper
= fw_helper
->data
;
271 helperlen
= fw_helper
->size
;
273 BT_DBG("Downloading helper image (%d bytes), block size %d bytes",
274 helperlen
, SDIO_BLOCK_SIZE
);
276 tmphlprbufsz
= ALIGN_SZ(BTM_UPLD_SIZE
, BTSDIO_DMA_ALIGN
);
278 tmphlprbuf
= kzalloc(tmphlprbufsz
, GFP_KERNEL
);
280 BT_ERR("Unable to allocate buffer for helper."
281 " Terminating download");
286 helperbuf
= (u8
*) ALIGN_ADDR(tmphlprbuf
, BTSDIO_DMA_ALIGN
);
288 /* Perform helper data transfer */
289 tx_len
= (FIRMWARE_TRANSFER_NBLOCK
* SDIO_BLOCK_SIZE
)
294 ret
= btmrvl_sdio_poll_card_status(card
,
295 CARD_IO_READY
| DN_LD_CARD_RDY
);
297 BT_ERR("Helper download poll status timeout @ %d",
302 /* Check if there is more data? */
303 if (hlprblknow
>= helperlen
)
306 if (helperlen
- hlprblknow
< tx_len
)
307 tx_len
= helperlen
- hlprblknow
;
310 helperbuf
[0] = ((tx_len
& 0x000000ff) >> 0);
311 helperbuf
[1] = ((tx_len
& 0x0000ff00) >> 8);
312 helperbuf
[2] = ((tx_len
& 0x00ff0000) >> 16);
313 helperbuf
[3] = ((tx_len
& 0xff000000) >> 24);
315 memcpy(&helperbuf
[SDIO_HEADER_LEN
], &helper
[hlprblknow
],
318 /* Now send the data */
319 ret
= sdio_writesb(card
->func
, card
->ioport
, helperbuf
,
320 FIRMWARE_TRANSFER_NBLOCK
* SDIO_BLOCK_SIZE
);
322 BT_ERR("IO error during helper download @ %d",
327 hlprblknow
+= tx_len
;
330 BT_DBG("Transferring helper image EOF block");
332 memset(helperbuf
, 0x0, SDIO_BLOCK_SIZE
);
334 ret
= sdio_writesb(card
->func
, card
->ioport
, helperbuf
,
337 BT_ERR("IO error in writing helper image EOF block");
345 release_firmware(fw_helper
);
349 static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card
*card
)
351 const struct firmware
*fw_firmware
= NULL
;
352 const u8
*firmware
= NULL
;
353 int firmwarelen
, tmpfwbufsz
, ret
;
354 unsigned int tries
, offset
;
356 void *tmpfwbuf
= NULL
;
358 u16 len
, blksz_dl
= card
->sd_blksz_fw_dl
;
359 int txlen
= 0, tx_blocks
= 0, count
= 0;
361 ret
= request_firmware(&fw_firmware
, card
->firmware
,
363 if ((ret
< 0) || !fw_firmware
) {
364 BT_ERR("request_firmware(firmware) failed, error code = %d",
370 firmware
= fw_firmware
->data
;
371 firmwarelen
= fw_firmware
->size
;
373 BT_DBG("Downloading FW image (%d bytes)", firmwarelen
);
375 tmpfwbufsz
= ALIGN_SZ(BTM_UPLD_SIZE
, BTSDIO_DMA_ALIGN
);
376 tmpfwbuf
= kzalloc(tmpfwbufsz
, GFP_KERNEL
);
378 BT_ERR("Unable to allocate buffer for firmware."
379 " Terminating download");
384 /* Ensure aligned firmware buffer */
385 fwbuf
= (u8
*) ALIGN_ADDR(tmpfwbuf
, BTSDIO_DMA_ALIGN
);
387 /* Perform firmware data transfer */
390 ret
= btmrvl_sdio_poll_card_status(card
,
391 CARD_IO_READY
| DN_LD_CARD_RDY
);
393 BT_ERR("FW download with helper poll status"
394 " timeout @ %d", offset
);
398 /* Check if there is more data ? */
399 if (offset
>= firmwarelen
)
402 for (tries
= 0; tries
< MAX_POLL_TRIES
; tries
++) {
403 base0
= sdio_readb(card
->func
,
404 card
->reg
->sq_read_base_addr_a0
, &ret
);
406 BT_ERR("BASE0 register read failed:"
407 " base0 = 0x%04X(%d)."
408 " Terminating download",
413 base1
= sdio_readb(card
->func
,
414 card
->reg
->sq_read_base_addr_a1
, &ret
);
416 BT_ERR("BASE1 register read failed:"
417 " base1 = 0x%04X(%d)."
418 " Terminating download",
424 len
= (((u16
) base1
) << 8) | base0
;
433 else if (len
> BTM_UPLD_SIZE
) {
434 BT_ERR("FW download failure @%d, invalid length %d",
444 if (count
> MAX_WRITE_IOMEM_RETRY
) {
445 BT_ERR("FW download failure @%d, "
446 "over max retry count", offset
);
450 BT_ERR("FW CRC error indicated by the helper: "
451 "len = 0x%04X, txlen = %d", len
, txlen
);
453 /* Set txlen to 0 so as to resend from same offset */
459 if (firmwarelen
- offset
< txlen
)
460 txlen
= firmwarelen
- offset
;
462 tx_blocks
= (txlen
+ blksz_dl
- 1) / blksz_dl
;
464 memcpy(fwbuf
, &firmware
[offset
], txlen
);
467 ret
= sdio_writesb(card
->func
, card
->ioport
, fwbuf
,
468 tx_blocks
* blksz_dl
);
471 BT_ERR("FW download, writesb(%d) failed @%d",
473 sdio_writeb(card
->func
, HOST_CMD53_FIN
,
474 card
->reg
->cfg
, &ret
);
476 BT_ERR("writeb failed (CFG)");
482 BT_DBG("FW download over, size %d bytes", offset
);
488 release_firmware(fw_firmware
);
492 static int btmrvl_sdio_card_to_host(struct btmrvl_private
*priv
)
495 int ret
, buf_block_len
, blksz
;
496 struct sk_buff
*skb
= NULL
;
499 struct hci_dev
*hdev
= priv
->btmrvl_dev
.hcidev
;
500 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
502 if (!card
|| !card
->func
) {
503 BT_ERR("card or function is NULL!");
508 /* Read the length of data to be transferred */
509 ret
= btmrvl_sdio_read_rx_len(card
, &buf_len
);
511 BT_ERR("read rx_len failed");
516 blksz
= SDIO_BLOCK_SIZE
;
517 buf_block_len
= (buf_len
+ blksz
- 1) / blksz
;
519 if (buf_len
<= SDIO_HEADER_LEN
520 || (buf_block_len
* blksz
) > ALLOC_BUF_SIZE
) {
521 BT_ERR("invalid packet length: %d", buf_len
);
526 /* Allocate buffer */
527 skb
= bt_skb_alloc(buf_block_len
* blksz
+ BTSDIO_DMA_ALIGN
,
530 BT_ERR("No free skb");
534 if ((unsigned long) skb
->data
& (BTSDIO_DMA_ALIGN
- 1)) {
535 skb_put(skb
, (unsigned long) skb
->data
&
536 (BTSDIO_DMA_ALIGN
- 1));
537 skb_pull(skb
, (unsigned long) skb
->data
&
538 (BTSDIO_DMA_ALIGN
- 1));
543 ret
= sdio_readsb(card
->func
, payload
, card
->ioport
,
544 buf_block_len
* blksz
);
546 BT_ERR("readsb failed: %d", ret
);
551 /* This is SDIO specific header length: byte[2][1][0], type: byte[3]
552 * (HCI_COMMAND = 1, ACL_DATA = 2, SCO_DATA = 3, 0xFE = Vendor)
555 buf_len
= payload
[0];
556 buf_len
|= (u16
) payload
[1] << 8;
560 case HCI_ACLDATA_PKT
:
561 case HCI_SCODATA_PKT
:
563 bt_cb(skb
)->pkt_type
= type
;
564 skb
->dev
= (void *)hdev
;
565 skb_put(skb
, buf_len
);
566 skb_pull(skb
, SDIO_HEADER_LEN
);
568 if (type
== HCI_EVENT_PKT
) {
569 if (btmrvl_check_evtpkt(priv
, skb
))
575 hdev
->stat
.byte_rx
+= buf_len
;
578 case MRVL_VENDOR_PKT
:
579 bt_cb(skb
)->pkt_type
= HCI_VENDOR_PKT
;
580 skb
->dev
= (void *)hdev
;
581 skb_put(skb
, buf_len
);
582 skb_pull(skb
, SDIO_HEADER_LEN
);
584 if (btmrvl_process_event(priv
, skb
))
587 hdev
->stat
.byte_rx
+= buf_len
;
591 BT_ERR("Unknown packet type:%d", type
);
592 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
, payload
,
593 blksz
* buf_block_len
);
609 static int btmrvl_sdio_process_int_status(struct btmrvl_private
*priv
)
613 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
615 spin_lock_irqsave(&priv
->driver_lock
, flags
);
618 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
620 sdio_claim_host(card
->func
);
621 if (ireg
& DN_LD_HOST_INT_STATUS
) {
622 if (priv
->btmrvl_dev
.tx_dnld_rdy
)
623 BT_DBG("tx_done already received: "
624 " int_status=0x%x", ireg
);
626 priv
->btmrvl_dev
.tx_dnld_rdy
= true;
629 if (ireg
& UP_LD_HOST_INT_STATUS
)
630 btmrvl_sdio_card_to_host(priv
);
632 sdio_release_host(card
->func
);
637 static void btmrvl_sdio_interrupt(struct sdio_func
*func
)
639 struct btmrvl_private
*priv
;
640 struct btmrvl_sdio_card
*card
;
645 card
= sdio_get_drvdata(func
);
646 if (!card
|| !card
->priv
) {
647 BT_ERR("sbi_interrupt(%p) card or priv is "
648 "NULL, card=%p\n", func
, card
);
654 ireg
= sdio_readb(card
->func
, card
->reg
->host_intstatus
, &ret
);
656 BT_ERR("sdio_readb: read int status register failed");
662 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
663 * Clear the interrupt status register and re-enable the
666 BT_DBG("ireg = 0x%x", ireg
);
668 sdio_writeb(card
->func
, ~(ireg
) & (DN_LD_HOST_INT_STATUS
|
669 UP_LD_HOST_INT_STATUS
),
670 card
->reg
->host_intstatus
, &ret
);
672 BT_ERR("sdio_writeb: clear int status register failed");
677 spin_lock_irqsave(&priv
->driver_lock
, flags
);
679 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
681 btmrvl_interrupt(priv
);
684 static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card
*card
)
686 struct sdio_func
*func
;
690 if (!card
|| !card
->func
) {
691 BT_ERR("Error: card or function is NULL!");
698 sdio_claim_host(func
);
700 ret
= sdio_enable_func(func
);
702 BT_ERR("sdio_enable_func() failed: ret=%d", ret
);
707 ret
= sdio_claim_irq(func
, btmrvl_sdio_interrupt
);
709 BT_ERR("sdio_claim_irq failed: ret=%d", ret
);
714 ret
= sdio_set_block_size(card
->func
, SDIO_BLOCK_SIZE
);
716 BT_ERR("cannot set SDIO block size");
721 reg
= sdio_readb(func
, card
->reg
->io_port_0
, &ret
);
729 reg
= sdio_readb(func
, card
->reg
->io_port_1
, &ret
);
735 card
->ioport
|= (reg
<< 8);
737 reg
= sdio_readb(func
, card
->reg
->io_port_2
, &ret
);
743 card
->ioport
|= (reg
<< 16);
745 BT_DBG("SDIO FUNC%d IO port: 0x%x", func
->num
, card
->ioport
);
747 sdio_set_drvdata(func
, card
);
749 sdio_release_host(func
);
754 sdio_release_irq(func
);
757 sdio_disable_func(func
);
760 sdio_release_host(func
);
766 static int btmrvl_sdio_unregister_dev(struct btmrvl_sdio_card
*card
)
768 if (card
&& card
->func
) {
769 sdio_claim_host(card
->func
);
770 sdio_release_irq(card
->func
);
771 sdio_disable_func(card
->func
);
772 sdio_release_host(card
->func
);
773 sdio_set_drvdata(card
->func
, NULL
);
779 static int btmrvl_sdio_enable_host_int(struct btmrvl_sdio_card
*card
)
783 if (!card
|| !card
->func
)
786 sdio_claim_host(card
->func
);
788 ret
= btmrvl_sdio_enable_host_int_mask(card
, HIM_ENABLE
);
790 btmrvl_sdio_get_rx_unit(card
);
792 sdio_release_host(card
->func
);
797 static int btmrvl_sdio_disable_host_int(struct btmrvl_sdio_card
*card
)
801 if (!card
|| !card
->func
)
804 sdio_claim_host(card
->func
);
806 ret
= btmrvl_sdio_disable_host_int_mask(card
, HIM_DISABLE
);
808 sdio_release_host(card
->func
);
813 static int btmrvl_sdio_host_to_card(struct btmrvl_private
*priv
,
816 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
825 if (!card
|| !card
->func
) {
826 BT_ERR("card or function is NULL!");
831 if ((unsigned long) payload
& (BTSDIO_DMA_ALIGN
- 1)) {
832 tmpbufsz
= ALIGN_SZ(nb
, BTSDIO_DMA_ALIGN
);
833 tmpbuf
= kzalloc(tmpbufsz
, GFP_KERNEL
);
836 buf
= (u8
*) ALIGN_ADDR(tmpbuf
, BTSDIO_DMA_ALIGN
);
837 memcpy(buf
, payload
, nb
);
840 blksz
= SDIO_BLOCK_SIZE
;
841 buf_block_len
= (nb
+ blksz
- 1) / blksz
;
843 sdio_claim_host(card
->func
);
846 /* Transfer data to card */
847 ret
= sdio_writesb(card
->func
, card
->ioport
, buf
,
848 buf_block_len
* blksz
);
851 BT_ERR("i=%d writesb failed: %d", i
, ret
);
852 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
,
855 if (i
> MAX_WRITE_IOMEM_RETRY
)
860 priv
->btmrvl_dev
.tx_dnld_rdy
= false;
863 sdio_release_host(card
->func
);
869 static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card
*card
)
873 int pollnum
= MAX_POLL_TRIES
;
875 if (!card
|| !card
->func
) {
876 BT_ERR("card or function is NULL!");
879 sdio_claim_host(card
->func
);
881 if (!btmrvl_sdio_verify_fw_download(card
, 1)) {
882 BT_DBG("Firmware already downloaded!");
886 /* Check if other function driver is downloading the firmware */
887 fws0
= sdio_readb(card
->func
, card
->reg
->card_fw_status0
, &ret
);
889 BT_ERR("Failed to read FW downloading status!");
894 BT_DBG("BT not the winner (%#x). Skip FW downloading", fws0
);
896 /* Give other function more time to download the firmware */
900 ret
= btmrvl_sdio_download_helper(card
);
902 BT_ERR("Failed to download helper!");
908 if (btmrvl_sdio_download_fw_w_helper(card
)) {
909 BT_ERR("Failed to download firmware!");
915 if (btmrvl_sdio_verify_fw_download(card
, pollnum
)) {
916 BT_ERR("FW failed to be active in time!");
922 sdio_release_host(card
->func
);
927 static int btmrvl_sdio_wakeup_fw(struct btmrvl_private
*priv
)
929 struct btmrvl_sdio_card
*card
= priv
->btmrvl_dev
.card
;
932 if (!card
|| !card
->func
) {
933 BT_ERR("card or function is NULL!");
937 sdio_claim_host(card
->func
);
939 sdio_writeb(card
->func
, HOST_POWER_UP
, card
->reg
->cfg
, &ret
);
941 sdio_release_host(card
->func
);
943 BT_DBG("wake up firmware");
948 static int btmrvl_sdio_probe(struct sdio_func
*func
,
949 const struct sdio_device_id
*id
)
952 struct btmrvl_private
*priv
= NULL
;
953 struct btmrvl_sdio_card
*card
= NULL
;
955 BT_INFO("vendor=0x%x, device=0x%x, class=%d, fn=%d",
956 id
->vendor
, id
->device
, id
->class, func
->num
);
958 card
= devm_kzalloc(&func
->dev
, sizeof(*card
), GFP_KERNEL
);
964 if (id
->driver_data
) {
965 struct btmrvl_sdio_device
*data
= (void *) id
->driver_data
;
966 card
->helper
= data
->helper
;
967 card
->firmware
= data
->firmware
;
968 card
->reg
= data
->reg
;
969 card
->sd_blksz_fw_dl
= data
->sd_blksz_fw_dl
;
972 if (btmrvl_sdio_register_dev(card
) < 0) {
973 BT_ERR("Failed to register BT device!");
977 /* Disable the interrupts on the card */
978 btmrvl_sdio_disable_host_int(card
);
980 if (btmrvl_sdio_download_fw(card
)) {
981 BT_ERR("Downloading firmware failed!");
988 btmrvl_sdio_enable_host_int(card
);
990 priv
= btmrvl_add_card(card
);
992 BT_ERR("Initializing card failed!");
994 goto disable_host_int
;
999 /* Initialize the interface specific function pointers */
1000 priv
->hw_host_to_card
= btmrvl_sdio_host_to_card
;
1001 priv
->hw_wakeup_firmware
= btmrvl_sdio_wakeup_fw
;
1002 priv
->hw_process_int_status
= btmrvl_sdio_process_int_status
;
1004 if (btmrvl_register_hdev(priv
)) {
1005 BT_ERR("Register hdev failed!");
1007 goto disable_host_int
;
1010 priv
->btmrvl_dev
.psmode
= 1;
1011 btmrvl_enable_ps(priv
);
1013 priv
->btmrvl_dev
.gpio_gap
= 0xffff;
1014 btmrvl_send_hscfg_cmd(priv
);
1019 btmrvl_sdio_disable_host_int(card
);
1021 btmrvl_sdio_unregister_dev(card
);
1025 static void btmrvl_sdio_remove(struct sdio_func
*func
)
1027 struct btmrvl_sdio_card
*card
;
1030 card
= sdio_get_drvdata(func
);
1032 /* Send SHUTDOWN command & disable interrupt
1033 * if user removes the module.
1036 btmrvl_send_module_cfg_cmd(card
->priv
,
1037 MODULE_SHUTDOWN_REQ
);
1038 btmrvl_sdio_disable_host_int(card
);
1040 BT_DBG("unregester dev");
1041 btmrvl_sdio_unregister_dev(card
);
1042 btmrvl_remove_card(card
->priv
);
1047 static int btmrvl_sdio_suspend(struct device
*dev
)
1049 struct sdio_func
*func
= dev_to_sdio_func(dev
);
1050 struct btmrvl_sdio_card
*card
;
1051 struct btmrvl_private
*priv
;
1052 mmc_pm_flag_t pm_flags
;
1053 struct hci_dev
*hcidev
;
1056 pm_flags
= sdio_get_host_pm_caps(func
);
1057 BT_DBG("%s: suspend: PM flags = 0x%x", sdio_func_id(func
),
1059 if (!(pm_flags
& MMC_PM_KEEP_POWER
)) {
1060 BT_ERR("%s: cannot remain alive while suspended",
1061 sdio_func_id(func
));
1064 card
= sdio_get_drvdata(func
);
1065 if (!card
|| !card
->priv
) {
1066 BT_ERR("card or priv structure is not valid");
1070 BT_ERR("sdio_func is not specified");
1076 if (priv
->adapter
->hs_state
!= HS_ACTIVATED
) {
1077 if (btmrvl_enable_hs(priv
)) {
1078 BT_ERR("HS not actived, suspend failed!");
1082 hcidev
= priv
->btmrvl_dev
.hcidev
;
1083 BT_DBG("%s: SDIO suspend", hcidev
->name
);
1084 hci_suspend_dev(hcidev
);
1085 skb_queue_purge(&priv
->adapter
->tx_queue
);
1087 priv
->adapter
->is_suspended
= true;
1089 /* We will keep the power when hs enabled successfully */
1090 if (priv
->adapter
->hs_state
== HS_ACTIVATED
) {
1091 BT_DBG("suspend with MMC_PM_KEEP_POWER");
1092 return sdio_set_host_pm_flags(func
, MMC_PM_KEEP_POWER
);
1094 BT_DBG("suspend without MMC_PM_KEEP_POWER");
1099 static int btmrvl_sdio_resume(struct device
*dev
)
1101 struct sdio_func
*func
= dev_to_sdio_func(dev
);
1102 struct btmrvl_sdio_card
*card
;
1103 struct btmrvl_private
*priv
;
1104 mmc_pm_flag_t pm_flags
;
1105 struct hci_dev
*hcidev
;
1108 pm_flags
= sdio_get_host_pm_caps(func
);
1109 BT_DBG("%s: resume: PM flags = 0x%x", sdio_func_id(func
),
1111 card
= sdio_get_drvdata(func
);
1112 if (!card
|| !card
->priv
) {
1113 BT_ERR("card or priv structure is not valid");
1117 BT_ERR("sdio_func is not specified");
1122 if (!priv
->adapter
->is_suspended
) {
1123 BT_DBG("device already resumed");
1127 priv
->adapter
->is_suspended
= false;
1128 hcidev
= priv
->btmrvl_dev
.hcidev
;
1129 BT_DBG("%s: SDIO resume", hcidev
->name
);
1130 hci_resume_dev(hcidev
);
1131 priv
->hw_wakeup_firmware(priv
);
1132 priv
->adapter
->hs_state
= HS_DEACTIVATED
;
1133 BT_DBG("%s: HS DEACTIVATED in resume!", hcidev
->name
);
1138 static const struct dev_pm_ops btmrvl_sdio_pm_ops
= {
1139 .suspend
= btmrvl_sdio_suspend
,
1140 .resume
= btmrvl_sdio_resume
,
1143 static struct sdio_driver bt_mrvl_sdio
= {
1144 .name
= "btmrvl_sdio",
1145 .id_table
= btmrvl_sdio_ids
,
1146 .probe
= btmrvl_sdio_probe
,
1147 .remove
= btmrvl_sdio_remove
,
1149 .owner
= THIS_MODULE
,
1150 .pm
= &btmrvl_sdio_pm_ops
,
1154 static int __init
btmrvl_sdio_init_module(void)
1156 if (sdio_register_driver(&bt_mrvl_sdio
) != 0) {
1157 BT_ERR("SDIO Driver Registration Failed");
1161 /* Clear the flag in case user removes the card. */
1167 static void __exit
btmrvl_sdio_exit_module(void)
1169 /* Set the flag as user is removing this module. */
1172 sdio_unregister_driver(&bt_mrvl_sdio
);
1175 module_init(btmrvl_sdio_init_module
);
1176 module_exit(btmrvl_sdio_exit_module
);
1178 MODULE_AUTHOR("Marvell International Ltd.");
1179 MODULE_DESCRIPTION("Marvell BT-over-SDIO driver ver " VERSION
);
1180 MODULE_VERSION(VERSION
);
1181 MODULE_LICENSE("GPL v2");
1182 MODULE_FIRMWARE("sd8688_helper.bin");
1183 MODULE_FIRMWARE("sd8688.bin");
1184 MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin");
1185 MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin");