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/slab.h>
23 #include <linux/mmc/sdio_ids.h>
24 #include <linux/mmc/sdio_func.h>
25 #include <linux/module.h>
27 #include <net/bluetooth/bluetooth.h>
28 #include <net/bluetooth/hci_core.h>
30 #include "btmrvl_drv.h"
31 #include "btmrvl_sdio.h"
35 /* The btmrvl_sdio_remove() callback function is called
36 * when user removes this module from kernel space or ejects
37 * the card from the slot. The driver handles these 2 cases
39 * If the user is removing the module, a MODULE_SHUTDOWN_REQ
40 * command is sent to firmware and interrupt will be disabled.
41 * If the card is removed, there is no need to send command
42 * or disable interrupt.
44 * The variable 'user_rmmod' is used to distinguish these two
45 * scenarios. This flag is initialized as FALSE in case the card
46 * is removed, and will be set to TRUE for module removal when
47 * module_exit function is called.
52 static const struct btmrvl_sdio_card_reg btmrvl_reg_8688 = {
54 .host_int_mask = 0x04,
55 .host_intstatus = 0x05,
57 .sq_read_base_addr_a0 = 0x10,
58 .sq_read_base_addr_a1 = 0x11,
59 .card_fw_status0 = 0x40,
60 .card_fw_status1 = 0x41,
67 static const struct btmrvl_sdio_card_reg btmrvl_reg_87xx = {
69 .host_int_mask = 0x02,
70 .host_intstatus = 0x03,
72 .sq_read_base_addr_a0 = 0x40,
73 .sq_read_base_addr_a1 = 0x41,
74 .card_revision = 0x5c,
75 .card_fw_status0 = 0x60,
76 .card_fw_status1 = 0x61,
84 static const struct btmrvl_sdio_card_reg btmrvl_reg_88xx = {
86 .host_int_mask = 0x02,
87 .host_intstatus = 0x03,
89 .sq_read_base_addr_a0 = 0x60,
90 .sq_read_base_addr_a1 = 0x61,
91 .card_revision = 0xbc,
92 .card_fw_status0 = 0xc0,
93 .card_fw_status1 = 0xc1,
101 static const struct btmrvl_sdio_device btmrvl_sdio_sd8688 = {
102 .helper = "mrvl/sd8688_helper.bin",
103 .firmware = "mrvl/sd8688.bin",
105 .reg = &btmrvl_reg_8688,
106 .sd_blksz_fw_dl = 64,
109 static const struct btmrvl_sdio_device btmrvl_sdio_sd8787 = {
111 .firmware = "mrvl/sd8787_uapsta.bin",
113 .reg = &btmrvl_reg_87xx,
114 .sd_blksz_fw_dl = 256,
117 static const struct btmrvl_sdio_device btmrvl_sdio_sd8797 = {
119 .firmware = "mrvl/sd8797_uapsta.bin",
120 .cal_data = "mrvl/sd8797_caldata.conf",
121 .reg = &btmrvl_reg_87xx,
122 .sd_blksz_fw_dl = 256,
125 static const struct btmrvl_sdio_device btmrvl_sdio_sd8897 = {
127 .firmware = "mrvl/sd8897_uapsta.bin",
129 .reg = &btmrvl_reg_88xx,
130 .sd_blksz_fw_dl = 256,
133 static const struct sdio_device_id btmrvl_sdio_ids[] = {
134 /* Marvell SD8688 Bluetooth device */
135 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x9105),
136 .driver_data = (unsigned long) &btmrvl_sdio_sd8688 },
137 /* Marvell SD8787 Bluetooth device */
138 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x911A),
139 .driver_data = (unsigned long) &btmrvl_sdio_sd8787 },
140 /* Marvell SD8787 Bluetooth AMP device */
141 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x911B),
142 .driver_data = (unsigned long) &btmrvl_sdio_sd8787 },
143 /* Marvell SD8797 Bluetooth device */
144 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x912A),
145 .driver_data = (unsigned long) &btmrvl_sdio_sd8797 },
146 /* Marvell SD8897 Bluetooth device */
147 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x912E),
148 .driver_data = (unsigned long) &btmrvl_sdio_sd8897 },
150 { } /* Terminating entry */
153 MODULE_DEVICE_TABLE(sdio, btmrvl_sdio_ids);
155 static int btmrvl_sdio_get_rx_unit(struct btmrvl_sdio_card *card)
160 reg = sdio_readb(card->func, card->reg->card_rx_unit, &ret);
167 static int btmrvl_sdio_read_fw_status(struct btmrvl_sdio_card *card, u16 *dat)
174 fws0 = sdio_readb(card->func, card->reg->card_fw_status0, &ret);
178 fws1 = sdio_readb(card->func, card->reg->card_fw_status1, &ret);
182 *dat = (((u16) fws1) << 8) | fws0;
187 static int btmrvl_sdio_read_rx_len(struct btmrvl_sdio_card *card, u16 *dat)
192 reg = sdio_readb(card->func, card->reg->card_rx_len, &ret);
194 *dat = (u16) reg << card->rx_unit;
199 static int btmrvl_sdio_enable_host_int_mask(struct btmrvl_sdio_card *card,
204 sdio_writeb(card->func, mask, card->reg->host_int_mask, &ret);
206 BT_ERR("Unable to enable the host interrupt!");
213 static int btmrvl_sdio_disable_host_int_mask(struct btmrvl_sdio_card *card,
219 host_int_mask = sdio_readb(card->func, card->reg->host_int_mask, &ret);
223 host_int_mask &= ~mask;
225 sdio_writeb(card->func, host_int_mask, card->reg->host_int_mask, &ret);
227 BT_ERR("Unable to disable the host interrupt!");
234 static int btmrvl_sdio_poll_card_status(struct btmrvl_sdio_card *card, u8 bits)
240 for (tries = 0; tries < MAX_POLL_TRIES * 1000; tries++) {
241 status = sdio_readb(card->func, card->reg->card_status, &ret);
244 if ((status & bits) == bits)
253 BT_ERR("FAILED! ret=%d", ret);
258 static int btmrvl_sdio_verify_fw_download(struct btmrvl_sdio_card *card,
264 /* Wait for firmware to become ready */
265 for (tries = 0; tries < pollnum; tries++) {
266 sdio_claim_host(card->func);
267 ret = btmrvl_sdio_read_fw_status(card, &firmwarestat);
268 sdio_release_host(card->func);
272 if (firmwarestat == FIRMWARE_READY)
281 static int btmrvl_sdio_download_helper(struct btmrvl_sdio_card *card)
283 const struct firmware *fw_helper = NULL;
284 const u8 *helper = NULL;
286 void *tmphlprbuf = NULL;
287 int tmphlprbufsz, hlprblknow, helperlen;
291 ret = request_firmware(&fw_helper, card->helper,
293 if ((ret < 0) || !fw_helper) {
294 BT_ERR("request_firmware(helper) failed, error code = %d",
300 helper = fw_helper->data;
301 helperlen = fw_helper->size;
303 BT_DBG("Downloading helper image (%d bytes), block size %d bytes",
304 helperlen, SDIO_BLOCK_SIZE);
306 tmphlprbufsz = ALIGN_SZ(BTM_UPLD_SIZE, BTSDIO_DMA_ALIGN);
308 tmphlprbuf = kzalloc(tmphlprbufsz, GFP_KERNEL);
310 BT_ERR("Unable to allocate buffer for helper."
311 " Terminating download");
316 helperbuf = (u8 *) ALIGN_ADDR(tmphlprbuf, BTSDIO_DMA_ALIGN);
318 /* Perform helper data transfer */
319 tx_len = (FIRMWARE_TRANSFER_NBLOCK * SDIO_BLOCK_SIZE)
324 ret = btmrvl_sdio_poll_card_status(card,
325 CARD_IO_READY | DN_LD_CARD_RDY);
327 BT_ERR("Helper download poll status timeout @ %d",
332 /* Check if there is more data? */
333 if (hlprblknow >= helperlen)
336 if (helperlen - hlprblknow < tx_len)
337 tx_len = helperlen - hlprblknow;
340 helperbuf[0] = ((tx_len & 0x000000ff) >> 0);
341 helperbuf[1] = ((tx_len & 0x0000ff00) >> 8);
342 helperbuf[2] = ((tx_len & 0x00ff0000) >> 16);
343 helperbuf[3] = ((tx_len & 0xff000000) >> 24);
345 memcpy(&helperbuf[SDIO_HEADER_LEN], &helper[hlprblknow],
348 /* Now send the data */
349 ret = sdio_writesb(card->func, card->ioport, helperbuf,
350 FIRMWARE_TRANSFER_NBLOCK * SDIO_BLOCK_SIZE);
352 BT_ERR("IO error during helper download @ %d",
357 hlprblknow += tx_len;
360 BT_DBG("Transferring helper image EOF block");
362 memset(helperbuf, 0x0, SDIO_BLOCK_SIZE);
364 ret = sdio_writesb(card->func, card->ioport, helperbuf,
367 BT_ERR("IO error in writing helper image EOF block");
375 release_firmware(fw_helper);
379 static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
381 const struct firmware *fw_firmware = NULL;
382 const u8 *firmware = NULL;
383 int firmwarelen, tmpfwbufsz, ret;
384 unsigned int tries, offset;
386 void *tmpfwbuf = NULL;
388 u16 len, blksz_dl = card->sd_blksz_fw_dl;
389 int txlen = 0, tx_blocks = 0, count = 0;
391 ret = request_firmware(&fw_firmware, card->firmware,
393 if ((ret < 0) || !fw_firmware) {
394 BT_ERR("request_firmware(firmware) failed, error code = %d",
400 firmware = fw_firmware->data;
401 firmwarelen = fw_firmware->size;
403 BT_DBG("Downloading FW image (%d bytes)", firmwarelen);
405 tmpfwbufsz = ALIGN_SZ(BTM_UPLD_SIZE, BTSDIO_DMA_ALIGN);
406 tmpfwbuf = kzalloc(tmpfwbufsz, GFP_KERNEL);
408 BT_ERR("Unable to allocate buffer for firmware."
409 " Terminating download");
414 /* Ensure aligned firmware buffer */
415 fwbuf = (u8 *) ALIGN_ADDR(tmpfwbuf, BTSDIO_DMA_ALIGN);
417 /* Perform firmware data transfer */
420 ret = btmrvl_sdio_poll_card_status(card,
421 CARD_IO_READY | DN_LD_CARD_RDY);
423 BT_ERR("FW download with helper poll status"
424 " timeout @ %d", offset);
428 /* Check if there is more data ? */
429 if (offset >= firmwarelen)
432 for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
433 base0 = sdio_readb(card->func,
434 card->reg->sq_read_base_addr_a0, &ret);
436 BT_ERR("BASE0 register read failed:"
437 " base0 = 0x%04X(%d)."
438 " Terminating download",
443 base1 = sdio_readb(card->func,
444 card->reg->sq_read_base_addr_a1, &ret);
446 BT_ERR("BASE1 register read failed:"
447 " base1 = 0x%04X(%d)."
448 " Terminating download",
454 len = (((u16) base1) << 8) | base0;
463 else if (len > BTM_UPLD_SIZE) {
464 BT_ERR("FW download failure @%d, invalid length %d",
474 if (count > MAX_WRITE_IOMEM_RETRY) {
475 BT_ERR("FW download failure @%d, "
476 "over max retry count", offset);
480 BT_ERR("FW CRC error indicated by the helper: "
481 "len = 0x%04X, txlen = %d", len, txlen);
483 /* Set txlen to 0 so as to resend from same offset */
489 if (firmwarelen - offset < txlen)
490 txlen = firmwarelen - offset;
492 tx_blocks = DIV_ROUND_UP(txlen, blksz_dl);
494 memcpy(fwbuf, &firmware[offset], txlen);
497 ret = sdio_writesb(card->func, card->ioport, fwbuf,
498 tx_blocks * blksz_dl);
501 BT_ERR("FW download, writesb(%d) failed @%d",
503 sdio_writeb(card->func, HOST_CMD53_FIN,
504 card->reg->cfg, &ret);
506 BT_ERR("writeb failed (CFG)");
512 BT_DBG("FW download over, size %d bytes", offset);
518 release_firmware(fw_firmware);
522 static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
525 int ret, num_blocks, blksz;
526 struct sk_buff *skb = NULL;
529 struct hci_dev *hdev = priv->btmrvl_dev.hcidev;
530 struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
532 if (!card || !card->func) {
533 BT_ERR("card or function is NULL!");
538 /* Read the length of data to be transferred */
539 ret = btmrvl_sdio_read_rx_len(card, &buf_len);
541 BT_ERR("read rx_len failed");
546 blksz = SDIO_BLOCK_SIZE;
547 num_blocks = DIV_ROUND_UP(buf_len, blksz);
549 if (buf_len <= SDIO_HEADER_LEN
550 || (num_blocks * blksz) > ALLOC_BUF_SIZE) {
551 BT_ERR("invalid packet length: %d", buf_len);
556 /* Allocate buffer */
557 skb = bt_skb_alloc(num_blocks * blksz + BTSDIO_DMA_ALIGN, GFP_ATOMIC);
559 BT_ERR("No free skb");
564 if ((unsigned long) skb->data & (BTSDIO_DMA_ALIGN - 1)) {
565 skb_put(skb, (unsigned long) skb->data &
566 (BTSDIO_DMA_ALIGN - 1));
567 skb_pull(skb, (unsigned long) skb->data &
568 (BTSDIO_DMA_ALIGN - 1));
573 ret = sdio_readsb(card->func, payload, card->ioport,
576 BT_ERR("readsb failed: %d", ret);
581 /* This is SDIO specific header length: byte[2][1][0], type: byte[3]
582 * (HCI_COMMAND = 1, ACL_DATA = 2, SCO_DATA = 3, 0xFE = Vendor)
585 buf_len = payload[0];
586 buf_len |= payload[1] << 8;
587 buf_len |= payload[2] << 16;
589 if (buf_len > blksz * num_blocks) {
590 BT_ERR("Skip incorrect packet: hdrlen %d buffer %d",
591 buf_len, blksz * num_blocks);
599 case HCI_ACLDATA_PKT:
600 case HCI_SCODATA_PKT:
602 bt_cb(skb)->pkt_type = type;
603 skb_put(skb, buf_len);
604 skb_pull(skb, SDIO_HEADER_LEN);
606 if (type == HCI_EVENT_PKT) {
607 if (btmrvl_check_evtpkt(priv, skb))
608 hci_recv_frame(hdev, skb);
610 hci_recv_frame(hdev, skb);
613 hdev->stat.byte_rx += buf_len;
616 case MRVL_VENDOR_PKT:
617 bt_cb(skb)->pkt_type = HCI_VENDOR_PKT;
618 skb_put(skb, buf_len);
619 skb_pull(skb, SDIO_HEADER_LEN);
621 if (btmrvl_process_event(priv, skb))
622 hci_recv_frame(hdev, skb);
624 hdev->stat.byte_rx += buf_len;
628 BT_ERR("Unknown packet type:%d", type);
629 BT_ERR("hex: %*ph", blksz * num_blocks, payload);
645 static int btmrvl_sdio_process_int_status(struct btmrvl_private *priv)
649 struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
651 spin_lock_irqsave(&priv->driver_lock, flags);
654 spin_unlock_irqrestore(&priv->driver_lock, flags);
656 sdio_claim_host(card->func);
657 if (ireg & DN_LD_HOST_INT_STATUS) {
658 if (priv->btmrvl_dev.tx_dnld_rdy)
659 BT_DBG("tx_done already received: "
660 " int_status=0x%x", ireg);
662 priv->btmrvl_dev.tx_dnld_rdy = true;
665 if (ireg & UP_LD_HOST_INT_STATUS)
666 btmrvl_sdio_card_to_host(priv);
668 sdio_release_host(card->func);
673 static void btmrvl_sdio_interrupt(struct sdio_func *func)
675 struct btmrvl_private *priv;
676 struct btmrvl_sdio_card *card;
681 card = sdio_get_drvdata(func);
682 if (!card || !card->priv) {
683 BT_ERR("sbi_interrupt(%p) card or priv is "
684 "NULL, card=%p\n", func, card);
690 ireg = sdio_readb(card->func, card->reg->host_intstatus, &ret);
692 BT_ERR("sdio_readb: read int status register failed");
698 * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
699 * Clear the interrupt status register and re-enable the
702 BT_DBG("ireg = 0x%x", ireg);
704 sdio_writeb(card->func, ~(ireg) & (DN_LD_HOST_INT_STATUS |
705 UP_LD_HOST_INT_STATUS),
706 card->reg->host_intstatus, &ret);
708 BT_ERR("sdio_writeb: clear int status register failed");
713 spin_lock_irqsave(&priv->driver_lock, flags);
715 spin_unlock_irqrestore(&priv->driver_lock, flags);
717 btmrvl_interrupt(priv);
720 static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
722 struct sdio_func *func;
726 if (!card || !card->func) {
727 BT_ERR("Error: card or function is NULL!");
734 sdio_claim_host(func);
736 ret = sdio_enable_func(func);
738 BT_ERR("sdio_enable_func() failed: ret=%d", ret);
743 ret = sdio_claim_irq(func, btmrvl_sdio_interrupt);
745 BT_ERR("sdio_claim_irq failed: ret=%d", ret);
750 ret = sdio_set_block_size(card->func, SDIO_BLOCK_SIZE);
752 BT_ERR("cannot set SDIO block size");
757 reg = sdio_readb(func, card->reg->io_port_0, &ret);
765 reg = sdio_readb(func, card->reg->io_port_1, &ret);
771 card->ioport |= (reg << 8);
773 reg = sdio_readb(func, card->reg->io_port_2, &ret);
779 card->ioport |= (reg << 16);
781 BT_DBG("SDIO FUNC%d IO port: 0x%x", func->num, card->ioport);
783 sdio_set_drvdata(func, card);
785 sdio_release_host(func);
790 sdio_release_irq(func);
793 sdio_disable_func(func);
796 sdio_release_host(func);
802 static int btmrvl_sdio_unregister_dev(struct btmrvl_sdio_card *card)
804 if (card && card->func) {
805 sdio_claim_host(card->func);
806 sdio_release_irq(card->func);
807 sdio_disable_func(card->func);
808 sdio_release_host(card->func);
809 sdio_set_drvdata(card->func, NULL);
815 static int btmrvl_sdio_enable_host_int(struct btmrvl_sdio_card *card)
819 if (!card || !card->func)
822 sdio_claim_host(card->func);
824 ret = btmrvl_sdio_enable_host_int_mask(card, HIM_ENABLE);
826 btmrvl_sdio_get_rx_unit(card);
828 sdio_release_host(card->func);
833 static int btmrvl_sdio_disable_host_int(struct btmrvl_sdio_card *card)
837 if (!card || !card->func)
840 sdio_claim_host(card->func);
842 ret = btmrvl_sdio_disable_host_int_mask(card, HIM_DISABLE);
844 sdio_release_host(card->func);
849 static int btmrvl_sdio_host_to_card(struct btmrvl_private *priv,
852 struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
861 if (!card || !card->func) {
862 BT_ERR("card or function is NULL!");
867 if ((unsigned long) payload & (BTSDIO_DMA_ALIGN - 1)) {
868 tmpbufsz = ALIGN_SZ(nb, BTSDIO_DMA_ALIGN);
869 tmpbuf = kzalloc(tmpbufsz, GFP_KERNEL);
872 buf = (u8 *) ALIGN_ADDR(tmpbuf, BTSDIO_DMA_ALIGN);
873 memcpy(buf, payload, nb);
876 blksz = SDIO_BLOCK_SIZE;
877 buf_block_len = DIV_ROUND_UP(nb, blksz);
879 sdio_claim_host(card->func);
882 /* Transfer data to card */
883 ret = sdio_writesb(card->func, card->ioport, buf,
884 buf_block_len * blksz);
887 BT_ERR("i=%d writesb failed: %d", i, ret);
888 BT_ERR("hex: %*ph", nb, payload);
890 if (i > MAX_WRITE_IOMEM_RETRY)
895 priv->btmrvl_dev.tx_dnld_rdy = false;
898 sdio_release_host(card->func);
904 static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card *card)
908 int pollnum = MAX_POLL_TRIES;
910 if (!card || !card->func) {
911 BT_ERR("card or function is NULL!");
915 if (!btmrvl_sdio_verify_fw_download(card, 1)) {
916 BT_DBG("Firmware already downloaded!");
920 sdio_claim_host(card->func);
922 /* Check if other function driver is downloading the firmware */
923 fws0 = sdio_readb(card->func, card->reg->card_fw_status0, &ret);
925 BT_ERR("Failed to read FW downloading status!");
930 BT_DBG("BT not the winner (%#x). Skip FW downloading", fws0);
932 /* Give other function more time to download the firmware */
936 ret = btmrvl_sdio_download_helper(card);
938 BT_ERR("Failed to download helper!");
944 if (btmrvl_sdio_download_fw_w_helper(card)) {
945 BT_ERR("Failed to download firmware!");
951 sdio_release_host(card->func);
954 * winner or not, with this test the FW synchronizes when the
955 * module can continue its initialization
957 if (btmrvl_sdio_verify_fw_download(card, pollnum)) {
958 BT_ERR("FW failed to be active in time!");
965 sdio_release_host(card->func);
969 static int btmrvl_sdio_wakeup_fw(struct btmrvl_private *priv)
971 struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
974 if (!card || !card->func) {
975 BT_ERR("card or function is NULL!");
979 sdio_claim_host(card->func);
981 sdio_writeb(card->func, HOST_POWER_UP, card->reg->cfg, &ret);
983 sdio_release_host(card->func);
985 BT_DBG("wake up firmware");
990 static int btmrvl_sdio_probe(struct sdio_func *func,
991 const struct sdio_device_id *id)
994 struct btmrvl_private *priv = NULL;
995 struct btmrvl_sdio_card *card = NULL;
997 BT_INFO("vendor=0x%x, device=0x%x, class=%d, fn=%d",
998 id->vendor, id->device, id->class, func->num);
1000 card = devm_kzalloc(&func->dev, sizeof(*card), GFP_KERNEL);
1006 if (id->driver_data) {
1007 struct btmrvl_sdio_device *data = (void *) id->driver_data;
1008 card->helper = data->helper;
1009 card->firmware = data->firmware;
1010 card->cal_data = data->cal_data;
1011 card->reg = data->reg;
1012 card->sd_blksz_fw_dl = data->sd_blksz_fw_dl;
1015 if (btmrvl_sdio_register_dev(card) < 0) {
1016 BT_ERR("Failed to register BT device!");
1020 /* Disable the interrupts on the card */
1021 btmrvl_sdio_disable_host_int(card);
1023 if (btmrvl_sdio_download_fw(card)) {
1024 BT_ERR("Downloading firmware failed!");
1029 btmrvl_sdio_enable_host_int(card);
1031 priv = btmrvl_add_card(card);
1033 BT_ERR("Initializing card failed!");
1035 goto disable_host_int;
1039 priv->btmrvl_dev.dev = &card->func->dev;
1040 priv->btmrvl_dev.cal_data = card->cal_data;
1042 /* Initialize the interface specific function pointers */
1043 priv->hw_host_to_card = btmrvl_sdio_host_to_card;
1044 priv->hw_wakeup_firmware = btmrvl_sdio_wakeup_fw;
1045 priv->hw_process_int_status = btmrvl_sdio_process_int_status;
1047 if (btmrvl_register_hdev(priv)) {
1048 BT_ERR("Register hdev failed!");
1050 goto disable_host_int;
1056 btmrvl_sdio_disable_host_int(card);
1058 btmrvl_sdio_unregister_dev(card);
1062 static void btmrvl_sdio_remove(struct sdio_func *func)
1064 struct btmrvl_sdio_card *card;
1067 card = sdio_get_drvdata(func);
1069 /* Send SHUTDOWN command & disable interrupt
1070 * if user removes the module.
1073 btmrvl_send_module_cfg_cmd(card->priv,
1074 MODULE_SHUTDOWN_REQ);
1075 btmrvl_sdio_disable_host_int(card);
1077 BT_DBG("unregester dev");
1078 btmrvl_sdio_unregister_dev(card);
1079 btmrvl_remove_card(card->priv);
1084 static int btmrvl_sdio_suspend(struct device *dev)
1086 struct sdio_func *func = dev_to_sdio_func(dev);
1087 struct btmrvl_sdio_card *card;
1088 struct btmrvl_private *priv;
1089 mmc_pm_flag_t pm_flags;
1090 struct hci_dev *hcidev;
1093 pm_flags = sdio_get_host_pm_caps(func);
1094 BT_DBG("%s: suspend: PM flags = 0x%x", sdio_func_id(func),
1096 if (!(pm_flags & MMC_PM_KEEP_POWER)) {
1097 BT_ERR("%s: cannot remain alive while suspended",
1098 sdio_func_id(func));
1101 card = sdio_get_drvdata(func);
1102 if (!card || !card->priv) {
1103 BT_ERR("card or priv structure is not valid");
1107 BT_ERR("sdio_func is not specified");
1113 if (priv->adapter->hs_state != HS_ACTIVATED) {
1114 if (btmrvl_enable_hs(priv)) {
1115 BT_ERR("HS not actived, suspend failed!");
1119 hcidev = priv->btmrvl_dev.hcidev;
1120 BT_DBG("%s: SDIO suspend", hcidev->name);
1121 hci_suspend_dev(hcidev);
1122 skb_queue_purge(&priv->adapter->tx_queue);
1124 priv->adapter->is_suspended = true;
1126 /* We will keep the power when hs enabled successfully */
1127 if (priv->adapter->hs_state == HS_ACTIVATED) {
1128 BT_DBG("suspend with MMC_PM_KEEP_POWER");
1129 return sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
1131 BT_DBG("suspend without MMC_PM_KEEP_POWER");
1136 static int btmrvl_sdio_resume(struct device *dev)
1138 struct sdio_func *func = dev_to_sdio_func(dev);
1139 struct btmrvl_sdio_card *card;
1140 struct btmrvl_private *priv;
1141 mmc_pm_flag_t pm_flags;
1142 struct hci_dev *hcidev;
1145 pm_flags = sdio_get_host_pm_caps(func);
1146 BT_DBG("%s: resume: PM flags = 0x%x", sdio_func_id(func),
1148 card = sdio_get_drvdata(func);
1149 if (!card || !card->priv) {
1150 BT_ERR("card or priv structure is not valid");
1154 BT_ERR("sdio_func is not specified");
1159 if (!priv->adapter->is_suspended) {
1160 BT_DBG("device already resumed");
1164 priv->adapter->is_suspended = false;
1165 hcidev = priv->btmrvl_dev.hcidev;
1166 BT_DBG("%s: SDIO resume", hcidev->name);
1167 hci_resume_dev(hcidev);
1168 priv->hw_wakeup_firmware(priv);
1169 priv->adapter->hs_state = HS_DEACTIVATED;
1170 BT_DBG("%s: HS DEACTIVATED in resume!", hcidev->name);
1175 static const struct dev_pm_ops btmrvl_sdio_pm_ops = {
1176 .suspend = btmrvl_sdio_suspend,
1177 .resume = btmrvl_sdio_resume,
1180 static struct sdio_driver bt_mrvl_sdio = {
1181 .name = "btmrvl_sdio",
1182 .id_table = btmrvl_sdio_ids,
1183 .probe = btmrvl_sdio_probe,
1184 .remove = btmrvl_sdio_remove,
1186 .owner = THIS_MODULE,
1187 .pm = &btmrvl_sdio_pm_ops,
1191 static int __init btmrvl_sdio_init_module(void)
1193 if (sdio_register_driver(&bt_mrvl_sdio) != 0) {
1194 BT_ERR("SDIO Driver Registration Failed");
1198 /* Clear the flag in case user removes the card. */
1204 static void __exit btmrvl_sdio_exit_module(void)
1206 /* Set the flag as user is removing this module. */
1209 sdio_unregister_driver(&bt_mrvl_sdio);
1212 module_init(btmrvl_sdio_init_module);
1213 module_exit(btmrvl_sdio_exit_module);
1215 MODULE_AUTHOR("Marvell International Ltd.");
1216 MODULE_DESCRIPTION("Marvell BT-over-SDIO driver ver " VERSION);
1217 MODULE_VERSION(VERSION);
1218 MODULE_LICENSE("GPL v2");
1219 MODULE_FIRMWARE("mrvl/sd8688_helper.bin");
1220 MODULE_FIRMWARE("mrvl/sd8688.bin");
1221 MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin");
1222 MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin");
1223 MODULE_FIRMWARE("mrvl/sd8797_caldata.conf");
1224 MODULE_FIRMWARE("mrvl/sd8897_uapsta.bin");