22 #include <linux/slab.h>
26 #include <linux/module.h>
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,
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,
86 .helper =
"sd8688_helper.bin",
87 .firmware =
"sd8688.bin",
88 .reg = &btmrvl_reg_8688,
94 .firmware =
"mrvl/sd8787_uapsta.bin",
95 .reg = &btmrvl_reg_87xx,
96 .sd_blksz_fw_dl = 256,
101 .firmware =
"mrvl/sd8797_uapsta.bin",
102 .reg = &btmrvl_reg_87xx,
103 .sd_blksz_fw_dl = 256,
109 .driver_data = (
unsigned long) &btmrvl_sdio_sd8688 },
112 .driver_data = (
unsigned long) &btmrvl_sdio_sd8787 },
115 .driver_data = (
unsigned long) &btmrvl_sdio_sd8787 },
118 .driver_data = (
unsigned long) &btmrvl_sdio_sd8797 },
152 *dat = (((
u16) fws1) << 8) | fws0;
176 BT_ERR(
"Unable to enable the host interrupt!");
193 host_int_mask &= ~mask;
197 BT_ERR(
"Unable to disable the host interrupt!");
214 if ((status & bits) == bits)
223 BT_ERR(
"FAILED! ret=%d", ret);
236 for (tries = 0; tries < pollnum; tries++) {
237 if (btmrvl_sdio_read_fw_status(card, &firmwarestat) < 0)
256 void *tmphlprbuf =
NULL;
257 int tmphlprbufsz, hlprblknow, helperlen;
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",
278 tmphlprbuf = kzalloc(tmphlprbufsz,
GFP_KERNEL);
280 BT_ERR(
"Unable to allocate buffer for helper."
281 " Terminating download");
294 ret = btmrvl_sdio_poll_card_status(card,
297 BT_ERR(
"Helper download poll status timeout @ %d",
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);
322 BT_ERR(
"IO error during helper download @ %d",
327 hlprblknow += tx_len;
330 BT_DBG(
"Transferring helper image EOF block");
337 BT_ERR(
"IO error in writing helper image EOF block");
353 int firmwarelen, tmpfwbufsz,
ret;
354 unsigned int tries,
offset;
356 void *tmpfwbuf =
NULL;
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);
378 BT_ERR(
"Unable to allocate buffer for firmware."
379 " Terminating download");
390 ret = btmrvl_sdio_poll_card_status(card,
393 BT_ERR(
"FW download with helper poll status"
394 " timeout @ %d", offset);
399 if (offset >= firmwarelen)
404 card->
reg->sq_read_base_addr_a0, &ret);
406 BT_ERR(
"BASE0 register read failed:"
407 " base0 = 0x%04X(%d)."
408 " Terminating download",
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;
434 BT_ERR(
"FW download failure @%d, invalid length %d",
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);
459 if (firmwarelen - offset < txlen)
460 txlen = firmwarelen -
offset;
462 tx_blocks = (txlen + blksz_dl - 1) / blksz_dl;
464 memcpy(fwbuf, &firmware[offset], txlen);
468 tx_blocks * blksz_dl);
471 BT_ERR(
"FW download, writesb(%d) failed @%d",
474 card->
reg->cfg, &ret);
476 BT_ERR(
"writeb failed (CFG)");
482 BT_DBG(
"FW download over, size %d bytes", offset);
502 if (!card || !card->
func) {
503 BT_ERR(
"card or function is NULL!");
509 ret = btmrvl_sdio_read_rx_len(card, &buf_len);
511 BT_ERR(
"read rx_len failed");
517 buf_block_len = (buf_len + blksz - 1) / blksz;
521 BT_ERR(
"invalid packet length: %d", buf_len);
544 buf_block_len * blksz);
546 BT_ERR(
"readsb failed: %d", ret);
555 buf_len = payload[0];
556 buf_len |= (
u16) payload[1] << 8;
564 skb->
dev = (
void *)hdev;
575 hdev->
stat.byte_rx += buf_len;
580 skb->
dev = (
void *)hdev;
587 hdev->
stat.byte_rx += buf_len;
591 BT_ERR(
"Unknown packet type:%d", type);
593 blksz * buf_block_len);
609 static int btmrvl_sdio_process_int_status(
struct btmrvl_private *priv)
623 BT_DBG(
"tx_done already received: "
624 " int_status=0x%x", ireg);
630 btmrvl_sdio_card_to_host(priv);
646 if (!card || !card->
priv) {
647 BT_ERR(
"sbi_interrupt(%p) card or priv is "
648 "NULL, card=%p\n", func, card);
656 BT_ERR(
"sdio_readb: read int status register failed");
666 BT_DBG(
"ireg = 0x%x", ireg);
670 card->
reg->host_intstatus, &ret);
672 BT_ERR(
"sdio_writeb: clear int status register failed");
690 if (!card || !card->
func) {
691 BT_ERR(
"Error: card or function is NULL!");
702 BT_ERR(
"sdio_enable_func() failed: ret=%d", ret);
709 BT_ERR(
"sdio_claim_irq failed: ret=%d", ret);
716 BT_ERR(
"cannot set SDIO block size");
735 card->
ioport |= (reg << 8);
743 card->
ioport |= (reg << 16);
768 if (card && card->
func) {
783 if (!card || !card->
func)
788 ret = btmrvl_sdio_enable_host_int_mask(card,
HIM_ENABLE);
790 btmrvl_sdio_get_rx_unit(card);
801 if (!card || !card->
func)
806 ret = btmrvl_sdio_disable_host_int_mask(card,
HIM_DISABLE);
825 if (!card || !card->
func) {
826 BT_ERR(
"card or function is NULL!");
841 buf_block_len = (nb + blksz - 1) / blksz;
848 buf_block_len * blksz);
851 BT_ERR(
"i=%d writesb failed: %d", i, ret);
875 if (!card || !card->
func) {
876 BT_ERR(
"card or function is NULL!");
881 if (!btmrvl_sdio_verify_fw_download(card, 1)) {
882 BT_DBG(
"Firmware already downloaded!");
889 BT_ERR(
"Failed to read FW downloading status!");
894 BT_DBG(
"BT not the winner (%#x). Skip FW downloading", fws0);
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!");
932 if (!card || !card->
func) {
933 BT_ERR(
"card or function is NULL!");
943 BT_DBG(
"wake up firmware");
948 static int btmrvl_sdio_probe(
struct sdio_func *func,
955 BT_INFO(
"vendor=0x%x, device=0x%x, class=%d, fn=%d",
964 if (id->driver_data) {
972 if (btmrvl_sdio_register_dev(card) < 0) {
973 BT_ERR(
"Failed to register BT device!");
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);
992 BT_ERR(
"Initializing card failed!");
994 goto disable_host_int;
1005 BT_ERR(
"Register hdev failed!");
1007 goto disable_host_int;
1019 btmrvl_sdio_disable_host_int(card);
1021 btmrvl_sdio_unregister_dev(card);
1025 static void btmrvl_sdio_remove(
struct sdio_func *func)
1038 btmrvl_sdio_disable_host_int(card);
1040 BT_DBG(
"unregester dev");
1041 btmrvl_sdio_unregister_dev(card);
1047 static int btmrvl_sdio_suspend(
struct device *
dev)
1060 BT_ERR(
"%s: cannot remain alive while suspended",
1065 if (!card || !card->
priv) {
1066 BT_ERR(
"card or priv structure is not valid");
1070 BT_ERR(
"sdio_func is not specified");
1078 BT_ERR(
"HS not actived, suspend failed!");
1087 priv->
adapter->is_suspended =
true;
1091 BT_DBG(
"suspend with MMC_PM_KEEP_POWER");
1094 BT_DBG(
"suspend without MMC_PM_KEEP_POWER");
1099 static int btmrvl_sdio_resume(
struct device *dev)
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;
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,
1144 .name =
"btmrvl_sdio",
1145 .id_table = btmrvl_sdio_ids,
1146 .probe = btmrvl_sdio_probe,
1147 .remove = btmrvl_sdio_remove,
1150 .pm = &btmrvl_sdio_pm_ops,
1154 static int __init btmrvl_sdio_init_module(
void)
1157 BT_ERR(
"SDIO Driver Registration Failed");
1167 static void __exit btmrvl_sdio_exit_module(
void)