Lines Matching refs:bdev

147 	struct btmtksdio_dev *bdev = hci_get_drvdata(hdev);  in mtk_hci_wmt_sync()  local
172 set_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
176 clear_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
189 err = wait_on_bit_timeout(&bdev->tx_state, BTMTKSDIO_TX_WAIT_VND_EVT, in mtk_hci_wmt_sync()
193 clear_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
199 clear_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state); in mtk_hci_wmt_sync()
205 wmt_evt = (struct btmtk_hci_wmt_evt *)bdev->evt_skb->data; in mtk_hci_wmt_sync()
248 kfree_skb(bdev->evt_skb); in mtk_hci_wmt_sync()
249 bdev->evt_skb = NULL; in mtk_hci_wmt_sync()
256 static int btmtksdio_tx_packet(struct btmtksdio_dev *bdev, in btmtksdio_tx_packet() argument
278 clear_bit(BTMTKSDIO_HW_TX_READY, &bdev->tx_state); in btmtksdio_tx_packet()
279 err = sdio_writesb(bdev->func, MTK_REG_CTDR, skb->data, in btmtksdio_tx_packet()
284 bdev->hdev->stat.byte_tx += skb->len; in btmtksdio_tx_packet()
296 static u32 btmtksdio_drv_own_query(struct btmtksdio_dev *bdev) in btmtksdio_drv_own_query() argument
298 return sdio_readl(bdev->func, MTK_REG_CHLPCR, NULL); in btmtksdio_drv_own_query()
301 static u32 btmtksdio_drv_own_query_79xx(struct btmtksdio_dev *bdev) in btmtksdio_drv_own_query_79xx() argument
303 return sdio_readl(bdev->func, MTK_REG_PD2HRM0R, NULL); in btmtksdio_drv_own_query_79xx()
306 static u32 btmtksdio_chcr_query(struct btmtksdio_dev *bdev) in btmtksdio_chcr_query() argument
308 return sdio_readl(bdev->func, MTK_REG_CHCR, NULL); in btmtksdio_chcr_query()
311 static int btmtksdio_fw_pmctrl(struct btmtksdio_dev *bdev) in btmtksdio_fw_pmctrl() argument
316 sdio_claim_host(bdev->func); in btmtksdio_fw_pmctrl()
318 if (bdev->data->lp_mbox_supported && in btmtksdio_fw_pmctrl()
319 test_bit(BTMTKSDIO_PATCH_ENABLED, &bdev->tx_state)) { in btmtksdio_fw_pmctrl()
320 sdio_writel(bdev->func, CSICR_CLR_MBOX_ACK, MTK_REG_CSICR, in btmtksdio_fw_pmctrl()
322 err = readx_poll_timeout(btmtksdio_drv_own_query_79xx, bdev, in btmtksdio_fw_pmctrl()
326 bt_dev_err(bdev->hdev, "mailbox ACK not cleared"); in btmtksdio_fw_pmctrl()
332 sdio_writel(bdev->func, C_FW_OWN_REQ_SET, MTK_REG_CHLPCR, &err); in btmtksdio_fw_pmctrl()
336 err = readx_poll_timeout(btmtksdio_drv_own_query, bdev, status, in btmtksdio_fw_pmctrl()
340 sdio_release_host(bdev->func); in btmtksdio_fw_pmctrl()
343 bt_dev_err(bdev->hdev, "Cannot return ownership to device"); in btmtksdio_fw_pmctrl()
348 static int btmtksdio_drv_pmctrl(struct btmtksdio_dev *bdev) in btmtksdio_drv_pmctrl() argument
353 sdio_claim_host(bdev->func); in btmtksdio_drv_pmctrl()
356 sdio_writel(bdev->func, C_FW_OWN_REQ_CLR, MTK_REG_CHLPCR, &err); in btmtksdio_drv_pmctrl()
360 err = readx_poll_timeout(btmtksdio_drv_own_query, bdev, status, in btmtksdio_drv_pmctrl()
363 if (!err && bdev->data->lp_mbox_supported && in btmtksdio_drv_pmctrl()
364 test_bit(BTMTKSDIO_PATCH_ENABLED, &bdev->tx_state)) in btmtksdio_drv_pmctrl()
365 err = readx_poll_timeout(btmtksdio_drv_own_query_79xx, bdev, in btmtksdio_drv_pmctrl()
370 sdio_release_host(bdev->func); in btmtksdio_drv_pmctrl()
373 bt_dev_err(bdev->hdev, "Cannot get ownership from device"); in btmtksdio_drv_pmctrl()
380 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_recv_event() local
388 if (test_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state)) { in btmtksdio_recv_event()
389 bdev->evt_skb = skb_clone(skb, GFP_KERNEL); in btmtksdio_recv_event()
390 if (!bdev->evt_skb) { in btmtksdio_recv_event()
402 &bdev->tx_state)) { in btmtksdio_recv_event()
405 wake_up_bit(&bdev->tx_state, BTMTKSDIO_TX_WAIT_VND_EVT); in btmtksdio_recv_event()
412 kfree_skb(bdev->evt_skb); in btmtksdio_recv_event()
413 bdev->evt_skb = NULL; in btmtksdio_recv_event()
421 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_recv_acl() local
429 pm_runtime_forbid(bdev->dev); in btmtksdio_recv_acl()
446 static int btmtksdio_rx_packet(struct btmtksdio_dev *bdev, u16 rx_size) in btmtksdio_rx_packet() argument
465 err = sdio_readsb(bdev->func, skb->data, MTK_REG_CRDR, rx_size); in btmtksdio_rx_packet()
477 bt_dev_err(bdev->hdev, "Rx size in sdio header is mismatched "); in btmtksdio_rx_packet()
496 bt_dev_err(bdev->hdev, "Invalid bt type 0x%02x", in btmtksdio_rx_packet()
503 bt_dev_err(bdev->hdev, "The size of bt header is mismatched"); in btmtksdio_rx_packet()
523 bt_dev_err(bdev->hdev, "The size of bt payload is mismatched"); in btmtksdio_rx_packet()
531 (&pkts[i])->recv(bdev->hdev, skb); in btmtksdio_rx_packet()
533 bdev->hdev->stat.byte_rx += rx_size; in btmtksdio_rx_packet()
545 struct btmtksdio_dev *bdev = container_of(work, struct btmtksdio_dev, in btmtksdio_txrx_work() local
552 pm_runtime_get_sync(bdev->dev); in btmtksdio_txrx_work()
554 sdio_claim_host(bdev->func); in btmtksdio_txrx_work()
557 sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, 0); in btmtksdio_txrx_work()
562 int_status = sdio_readl(bdev->func, MTK_REG_CHISR, NULL); in btmtksdio_txrx_work()
573 sdio_writel(bdev->func, int_status, MTK_REG_CHISR, NULL); in btmtksdio_txrx_work()
577 bdev->data->chipid == 0x7921) { in btmtksdio_txrx_work()
578 sdio_writel(bdev->func, PH2DSM0R_DRIVER_OWN, in btmtksdio_txrx_work()
583 bt_dev_dbg(bdev->hdev, "Get fw own back"); in btmtksdio_txrx_work()
586 set_bit(BTMTKSDIO_HW_TX_READY, &bdev->tx_state); in btmtksdio_txrx_work()
589 bt_dev_warn(bdev->hdev, "Tx fifo overflow"); in btmtksdio_txrx_work()
591 if (test_bit(BTMTKSDIO_HW_TX_READY, &bdev->tx_state)) { in btmtksdio_txrx_work()
592 skb = skb_dequeue(&bdev->txq); in btmtksdio_txrx_work()
594 err = btmtksdio_tx_packet(bdev, skb); in btmtksdio_txrx_work()
596 bdev->hdev->stat.err_tx++; in btmtksdio_txrx_work()
597 skb_queue_head(&bdev->txq, skb); in btmtksdio_txrx_work()
603 rx_size = sdio_readl(bdev->func, MTK_REG_CRPLR, NULL); in btmtksdio_txrx_work()
605 if (btmtksdio_rx_packet(bdev, rx_size) < 0) in btmtksdio_txrx_work()
606 bdev->hdev->stat.err_rx++; in btmtksdio_txrx_work()
611 sdio_writel(bdev->func, C_INT_EN_SET, MTK_REG_CHLPCR, 0); in btmtksdio_txrx_work()
613 sdio_release_host(bdev->func); in btmtksdio_txrx_work()
615 pm_runtime_mark_last_busy(bdev->dev); in btmtksdio_txrx_work()
616 pm_runtime_put_autosuspend(bdev->dev); in btmtksdio_txrx_work()
621 struct btmtksdio_dev *bdev = sdio_get_drvdata(func); in btmtksdio_interrupt() local
624 sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, 0); in btmtksdio_interrupt()
626 schedule_work(&bdev->txrx_work); in btmtksdio_interrupt()
631 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_open() local
635 sdio_claim_host(bdev->func); in btmtksdio_open()
637 err = sdio_enable_func(bdev->func); in btmtksdio_open()
641 set_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state); in btmtksdio_open()
643 err = btmtksdio_drv_pmctrl(bdev); in btmtksdio_open()
648 sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, &err); in btmtksdio_open()
652 sdio_writel(bdev->func, 0, MTK_REG_CHIER, &err); in btmtksdio_open()
656 err = sdio_claim_irq(bdev->func, btmtksdio_interrupt); in btmtksdio_open()
660 err = sdio_set_block_size(bdev->func, MTK_SDIO_BLOCK_SIZE); in btmtksdio_open()
667 val = sdio_readl(bdev->func, MTK_REG_CSDIOCSR, &err); in btmtksdio_open()
672 sdio_writel(bdev->func, val, MTK_REG_CSDIOCSR, &err); in btmtksdio_open()
677 val = sdio_readl(bdev->func, MTK_REG_CHCR, &err); in btmtksdio_open()
682 sdio_writel(bdev->func, val, MTK_REG_CHCR, &err); in btmtksdio_open()
687 sdio_writel(bdev->func, RX_DONE_INT | TX_EMPTY | TX_FIFO_OVERFLOW, in btmtksdio_open()
693 sdio_writel(bdev->func, C_INT_EN_SET, MTK_REG_CHLPCR, &err); in btmtksdio_open()
697 sdio_release_host(bdev->func); in btmtksdio_open()
702 sdio_release_irq(bdev->func); in btmtksdio_open()
705 sdio_disable_func(bdev->func); in btmtksdio_open()
708 sdio_release_host(bdev->func); in btmtksdio_open()
715 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_close() local
717 sdio_claim_host(bdev->func); in btmtksdio_close()
720 sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, NULL); in btmtksdio_close()
722 sdio_release_irq(bdev->func); in btmtksdio_close()
724 cancel_work_sync(&bdev->txrx_work); in btmtksdio_close()
726 btmtksdio_fw_pmctrl(bdev); in btmtksdio_close()
728 clear_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state); in btmtksdio_close()
729 sdio_disable_func(bdev->func); in btmtksdio_close()
731 sdio_release_host(bdev->func); in btmtksdio_close()
738 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_flush() local
740 skb_queue_purge(&bdev->txq); in btmtksdio_flush()
742 cancel_work_sync(&bdev->txrx_work); in btmtksdio_flush()
771 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in mt76xx_setup() local
832 set_bit(BTMTKSDIO_PATCH_ENABLED, &bdev->tx_state); in mt76xx_setup()
856 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in mt79xx_setup() local
867 err = btmtksdio_fw_pmctrl(bdev); in mt79xx_setup()
871 err = btmtksdio_drv_pmctrl(bdev); in mt79xx_setup()
890 set_bit(BTMTKSDIO_PATCH_ENABLED, &bdev->tx_state); in mt79xx_setup()
1070 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_setup() local
1078 set_bit(BTMTKSDIO_HW_TX_READY, &bdev->tx_state); in btmtksdio_setup()
1080 switch (bdev->data->chipid) { in btmtksdio_setup()
1082 if (test_bit(BTMTKSDIO_HW_RESET_ACTIVE, &bdev->tx_state)) { in btmtksdio_setup()
1094 btmtksdio_fw_pmctrl(bdev); in btmtksdio_setup()
1096 btmtksdio_drv_pmctrl(bdev); in btmtksdio_setup()
1098 clear_bit(BTMTKSDIO_HW_RESET_ACTIVE, &bdev->tx_state); in btmtksdio_setup()
1131 if (bdev->reset) { in btmtksdio_setup()
1135 devm_gpiod_put(bdev->dev, bdev->reset); in btmtksdio_setup()
1136 bdev->reset = NULL; in btmtksdio_setup()
1146 err = mt76xx_setup(hdev, bdev->data->fwname); in btmtksdio_setup()
1158 pm_runtime_set_autosuspend_delay(bdev->dev, in btmtksdio_setup()
1160 pm_runtime_use_autosuspend(bdev->dev); in btmtksdio_setup()
1162 err = pm_runtime_set_active(bdev->dev); in btmtksdio_setup()
1169 pm_runtime_forbid(bdev->dev); in btmtksdio_setup()
1170 pm_runtime_enable(bdev->dev); in btmtksdio_setup()
1173 pm_runtime_allow(bdev->dev); in btmtksdio_setup()
1182 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_shutdown() local
1190 pm_runtime_get_sync(bdev->dev); in btmtksdio_shutdown()
1193 if (test_bit(BTMTKSDIO_HW_RESET_ACTIVE, &bdev->tx_state)) in btmtksdio_shutdown()
1210 pm_runtime_put_noidle(bdev->dev); in btmtksdio_shutdown()
1211 pm_runtime_disable(bdev->dev); in btmtksdio_shutdown()
1218 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_send_frame() local
1237 skb_queue_tail(&bdev->txq, skb); in btmtksdio_send_frame()
1239 schedule_work(&bdev->txrx_work); in btmtksdio_send_frame()
1246 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_cmd_timeout() local
1250 if (!bdev->reset || bdev->data->chipid != 0x7921) in btmtksdio_cmd_timeout()
1253 pm_runtime_get_sync(bdev->dev); in btmtksdio_cmd_timeout()
1255 if (test_and_set_bit(BTMTKSDIO_HW_RESET_ACTIVE, &bdev->tx_state)) in btmtksdio_cmd_timeout()
1258 sdio_claim_host(bdev->func); in btmtksdio_cmd_timeout()
1260 sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, NULL); in btmtksdio_cmd_timeout()
1261 skb_queue_purge(&bdev->txq); in btmtksdio_cmd_timeout()
1262 cancel_work_sync(&bdev->txrx_work); in btmtksdio_cmd_timeout()
1264 gpiod_set_value_cansleep(bdev->reset, 1); in btmtksdio_cmd_timeout()
1266 gpiod_set_value_cansleep(bdev->reset, 0); in btmtksdio_cmd_timeout()
1268 err = readx_poll_timeout(btmtksdio_chcr_query, bdev, status, in btmtksdio_cmd_timeout()
1275 clear_bit(BTMTKSDIO_PATCH_ENABLED, &bdev->tx_state); in btmtksdio_cmd_timeout()
1277 sdio_release_host(bdev->func); in btmtksdio_cmd_timeout()
1279 pm_runtime_put_noidle(bdev->dev); in btmtksdio_cmd_timeout()
1280 pm_runtime_disable(bdev->dev); in btmtksdio_cmd_timeout()
1287 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_sdio_inband_wakeup() local
1289 return device_may_wakeup(bdev->dev); in btmtksdio_sdio_inband_wakeup()
1294 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev); in btmtksdio_sdio_wakeup() local
1295 bool may_wakeup = device_may_wakeup(bdev->dev); in btmtksdio_sdio_wakeup()
1304 if (may_wakeup && bdev->data->chipid == 0x7921) { in btmtksdio_sdio_wakeup()
1321 struct btmtksdio_dev *bdev; in btmtksdio_probe() local
1325 bdev = devm_kzalloc(&func->dev, sizeof(*bdev), GFP_KERNEL); in btmtksdio_probe()
1326 if (!bdev) in btmtksdio_probe()
1329 bdev->data = (void *)id->driver_data; in btmtksdio_probe()
1330 if (!bdev->data) in btmtksdio_probe()
1333 bdev->dev = &func->dev; in btmtksdio_probe()
1334 bdev->func = func; in btmtksdio_probe()
1336 INIT_WORK(&bdev->txrx_work, btmtksdio_txrx_work); in btmtksdio_probe()
1337 skb_queue_head_init(&bdev->txq); in btmtksdio_probe()
1346 bdev->hdev = hdev; in btmtksdio_probe()
1349 hci_set_drvdata(hdev, bdev); in btmtksdio_probe()
1374 sdio_set_drvdata(func, bdev); in btmtksdio_probe()
1388 if (pm_runtime_enabled(bdev->dev)) in btmtksdio_probe()
1389 pm_runtime_disable(bdev->dev); in btmtksdio_probe()
1400 pm_runtime_put_noidle(bdev->dev); in btmtksdio_probe()
1402 err = device_init_wakeup(bdev->dev, true); in btmtksdio_probe()
1406 bdev->dev->of_node = of_find_compatible_node(NULL, NULL, in btmtksdio_probe()
1408 bdev->reset = devm_gpiod_get_optional(bdev->dev, "reset", in btmtksdio_probe()
1410 if (IS_ERR(bdev->reset)) in btmtksdio_probe()
1411 err = PTR_ERR(bdev->reset); in btmtksdio_probe()
1418 struct btmtksdio_dev *bdev = sdio_get_drvdata(func); in btmtksdio_remove() local
1421 if (!bdev) in btmtksdio_remove()
1425 pm_runtime_get_noresume(bdev->dev); in btmtksdio_remove()
1427 hdev = bdev->hdev; in btmtksdio_remove()
1438 struct btmtksdio_dev *bdev; in btmtksdio_runtime_suspend() local
1441 bdev = sdio_get_drvdata(func); in btmtksdio_runtime_suspend()
1442 if (!bdev) in btmtksdio_runtime_suspend()
1445 if (!test_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state)) in btmtksdio_runtime_suspend()
1450 err = btmtksdio_fw_pmctrl(bdev); in btmtksdio_runtime_suspend()
1452 bt_dev_dbg(bdev->hdev, "status (%d) return ownership to device", err); in btmtksdio_runtime_suspend()
1460 struct btmtksdio_dev *bdev; in btmtksdio_runtime_resume() local
1463 bdev = sdio_get_drvdata(func); in btmtksdio_runtime_resume()
1464 if (!bdev) in btmtksdio_runtime_resume()
1467 if (!test_bit(BTMTKSDIO_FUNC_ENABLED, &bdev->tx_state)) in btmtksdio_runtime_resume()
1470 err = btmtksdio_drv_pmctrl(bdev); in btmtksdio_runtime_resume()
1472 bt_dev_dbg(bdev->hdev, "status (%d) get ownership from device", err); in btmtksdio_runtime_resume()