Lines Matching +full:qca6174 +full:- +full:bt
1 // SPDX-License-Identifier: GPL-2.0-only
5 * HCI_IBS (HCI In-Band Sleep) is Qualcomm's power management
13 * Written by Ohad Ben-Cohen <ohad@bencohen.org>
240 if (hu->serdev) { in qca_soc_type()
241 struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev); in qca_soc_type()
243 soc_type = qsd->btsoc_type; in qca_soc_type()
253 if (hu->serdev) { in qca_get_firmware_name()
254 struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev); in qca_get_firmware_name()
256 return qsd->firmware_name; in qca_get_firmware_name()
281 struct qca_data *qca = hu->priv; in serial_clock_vote()
284 bool old_vote = (qca->tx_vote | qca->rx_vote); in serial_clock_vote()
289 diff = jiffies_to_msecs(jiffies - qca->vote_last_jif); in serial_clock_vote()
292 qca->vote_off_ms += diff; in serial_clock_vote()
294 qca->vote_on_ms += diff; in serial_clock_vote()
298 qca->tx_vote = true; in serial_clock_vote()
299 qca->tx_votes_on++; in serial_clock_vote()
303 qca->rx_vote = true; in serial_clock_vote()
304 qca->rx_votes_on++; in serial_clock_vote()
308 qca->tx_vote = false; in serial_clock_vote()
309 qca->tx_votes_off++; in serial_clock_vote()
313 qca->rx_vote = false; in serial_clock_vote()
314 qca->rx_votes_off++; in serial_clock_vote()
322 new_vote = qca->rx_vote | qca->tx_vote; in serial_clock_vote()
326 __serial_clock_on(hu->tty); in serial_clock_vote()
328 __serial_clock_off(hu->tty); in serial_clock_vote()
333 diff = jiffies_to_msecs(jiffies - qca->vote_last_jif); in serial_clock_vote()
336 qca->votes_on++; in serial_clock_vote()
337 qca->vote_off_ms += diff; in serial_clock_vote()
339 qca->votes_off++; in serial_clock_vote()
340 qca->vote_on_ms += diff; in serial_clock_vote()
342 qca->vote_last_jif = jiffies; in serial_clock_vote()
353 struct qca_data *qca = hu->priv; in send_hci_ibs_cmd()
360 return -ENOMEM; in send_hci_ibs_cmd()
366 skb_queue_tail(&qca->txq, skb); in send_hci_ibs_cmd()
375 struct hci_uart *hu = qca->hu; in qca_wq_awake_device()
384 spin_lock_irqsave(&qca->hci_ibs_lock, flags); in qca_wq_awake_device()
390 qca->ibs_sent_wakes++; in qca_wq_awake_device()
393 retrans_delay = msecs_to_jiffies(qca->wake_retrans); in qca_wq_awake_device()
394 mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay); in qca_wq_awake_device()
396 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in qca_wq_awake_device()
406 struct hci_uart *hu = qca->hu; in qca_wq_awake_rx()
413 spin_lock_irqsave(&qca->hci_ibs_lock, flags); in qca_wq_awake_rx()
414 qca->rx_ibs_state = HCI_IBS_RX_AWAKE; in qca_wq_awake_rx()
422 qca->ibs_sent_wacks++; in qca_wq_awake_rx()
424 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in qca_wq_awake_rx()
434 struct hci_uart *hu = qca->hu; in qca_wq_serial_rx_clock_vote_off()
445 struct hci_uart *hu = qca->hu; in qca_wq_serial_tx_clock_vote_off()
461 struct hci_uart *hu = qca->hu; in hci_ibs_tx_idle_timeout()
464 BT_DBG("hu %p idle timeout in %d state", hu, qca->tx_ibs_state); in hci_ibs_tx_idle_timeout()
466 spin_lock_irqsave_nested(&qca->hci_ibs_lock, in hci_ibs_tx_idle_timeout()
469 switch (qca->tx_ibs_state) { in hci_ibs_tx_idle_timeout()
476 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP; in hci_ibs_tx_idle_timeout()
477 qca->ibs_sent_slps++; in hci_ibs_tx_idle_timeout()
478 queue_work(qca->workqueue, &qca->ws_tx_vote_off); in hci_ibs_tx_idle_timeout()
484 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state); in hci_ibs_tx_idle_timeout()
488 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in hci_ibs_tx_idle_timeout()
494 struct hci_uart *hu = qca->hu; in hci_ibs_wake_retrans_timeout()
499 hu, qca->tx_ibs_state); in hci_ibs_wake_retrans_timeout()
501 spin_lock_irqsave_nested(&qca->hci_ibs_lock, in hci_ibs_wake_retrans_timeout()
505 if (test_bit(QCA_SUSPENDING, &qca->flags)) { in hci_ibs_wake_retrans_timeout()
506 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in hci_ibs_wake_retrans_timeout()
510 switch (qca->tx_ibs_state) { in hci_ibs_wake_retrans_timeout()
518 qca->ibs_sent_wakes++; in hci_ibs_wake_retrans_timeout()
519 retrans_delay = msecs_to_jiffies(qca->wake_retrans); in hci_ibs_wake_retrans_timeout()
520 mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay); in hci_ibs_wake_retrans_timeout()
526 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state); in hci_ibs_wake_retrans_timeout()
530 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in hci_ibs_wake_retrans_timeout()
541 struct hci_uart *hu = qca->hu; in qca_controller_memdump_timeout()
543 mutex_lock(&qca->hci_memdump_lock); in qca_controller_memdump_timeout()
544 if (test_bit(QCA_MEMDUMP_COLLECTION, &qca->flags)) { in qca_controller_memdump_timeout()
545 qca->memdump_state = QCA_MEMDUMP_TIMEOUT; in qca_controller_memdump_timeout()
546 if (!test_bit(QCA_HW_ERROR_EVENT, &qca->flags)) { in qca_controller_memdump_timeout()
550 hci_reset_dev(hu->hdev); in qca_controller_memdump_timeout()
554 mutex_unlock(&qca->hci_memdump_lock); in qca_controller_memdump_timeout()
567 return -EOPNOTSUPP; in qca_open()
571 return -ENOMEM; in qca_open()
573 skb_queue_head_init(&qca->txq); in qca_open()
574 skb_queue_head_init(&qca->tx_wait_q); in qca_open()
575 skb_queue_head_init(&qca->rx_memdump_q); in qca_open()
576 spin_lock_init(&qca->hci_ibs_lock); in qca_open()
577 mutex_init(&qca->hci_memdump_lock); in qca_open()
578 qca->workqueue = alloc_ordered_workqueue("qca_wq", 0); in qca_open()
579 if (!qca->workqueue) { in qca_open()
582 return -ENOMEM; in qca_open()
585 INIT_WORK(&qca->ws_awake_rx, qca_wq_awake_rx); in qca_open()
586 INIT_WORK(&qca->ws_awake_device, qca_wq_awake_device); in qca_open()
587 INIT_WORK(&qca->ws_rx_vote_off, qca_wq_serial_rx_clock_vote_off); in qca_open()
588 INIT_WORK(&qca->ws_tx_vote_off, qca_wq_serial_tx_clock_vote_off); in qca_open()
589 INIT_WORK(&qca->ctrl_memdump_evt, qca_controller_memdump); in qca_open()
590 INIT_DELAYED_WORK(&qca->ctrl_memdump_timeout, in qca_open()
592 init_waitqueue_head(&qca->suspend_wait_q); in qca_open()
594 qca->hu = hu; in qca_open()
595 init_completion(&qca->drop_ev_comp); in qca_open()
597 /* Assume we start with both sides asleep -- extra wakes OK */ in qca_open()
598 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP; in qca_open()
599 qca->rx_ibs_state = HCI_IBS_RX_ASLEEP; in qca_open()
601 qca->vote_last_jif = jiffies; in qca_open()
603 hu->priv = qca; in qca_open()
605 if (hu->serdev) { in qca_open()
606 qcadev = serdev_device_get_drvdata(hu->serdev); in qca_open()
608 if (qca_is_wcn399x(qcadev->btsoc_type) || in qca_open()
609 qca_is_wcn6750(qcadev->btsoc_type)) in qca_open()
610 hu->init_speed = qcadev->init_speed; in qca_open()
612 if (qcadev->oper_speed) in qca_open()
613 hu->oper_speed = qcadev->oper_speed; in qca_open()
616 timer_setup(&qca->wake_retrans_timer, hci_ibs_wake_retrans_timeout, 0); in qca_open()
617 qca->wake_retrans = IBS_WAKE_RETRANS_TIMEOUT_MS; in qca_open()
619 timer_setup(&qca->tx_idle_timer, hci_ibs_tx_idle_timeout, 0); in qca_open()
620 qca->tx_idle_delay = IBS_HOST_TX_IDLE_TIMEOUT_MS; in qca_open()
623 qca->tx_idle_delay, qca->wake_retrans); in qca_open()
631 struct qca_data *qca = hu->priv; in qca_debugfs_init()
635 if (!hdev->debugfs) in qca_debugfs_init()
638 ibs_dir = debugfs_create_dir("ibs", hdev->debugfs); in qca_debugfs_init()
642 debugfs_create_u8("tx_ibs_state", mode, ibs_dir, &qca->tx_ibs_state); in qca_debugfs_init()
643 debugfs_create_u8("rx_ibs_state", mode, ibs_dir, &qca->rx_ibs_state); in qca_debugfs_init()
645 &qca->ibs_sent_slps); in qca_debugfs_init()
647 &qca->ibs_sent_wakes); in qca_debugfs_init()
649 &qca->ibs_sent_wacks); in qca_debugfs_init()
651 &qca->ibs_recv_slps); in qca_debugfs_init()
653 &qca->ibs_recv_wakes); in qca_debugfs_init()
655 &qca->ibs_recv_wacks); in qca_debugfs_init()
656 debugfs_create_bool("tx_vote", mode, ibs_dir, &qca->tx_vote); in qca_debugfs_init()
657 debugfs_create_u64("tx_votes_on", mode, ibs_dir, &qca->tx_votes_on); in qca_debugfs_init()
658 debugfs_create_u64("tx_votes_off", mode, ibs_dir, &qca->tx_votes_off); in qca_debugfs_init()
659 debugfs_create_bool("rx_vote", mode, ibs_dir, &qca->rx_vote); in qca_debugfs_init()
660 debugfs_create_u64("rx_votes_on", mode, ibs_dir, &qca->rx_votes_on); in qca_debugfs_init()
661 debugfs_create_u64("rx_votes_off", mode, ibs_dir, &qca->rx_votes_off); in qca_debugfs_init()
662 debugfs_create_u64("votes_on", mode, ibs_dir, &qca->votes_on); in qca_debugfs_init()
663 debugfs_create_u64("votes_off", mode, ibs_dir, &qca->votes_off); in qca_debugfs_init()
664 debugfs_create_u32("vote_on_ms", mode, ibs_dir, &qca->vote_on_ms); in qca_debugfs_init()
665 debugfs_create_u32("vote_off_ms", mode, ibs_dir, &qca->vote_off_ms); in qca_debugfs_init()
669 debugfs_create_u32("wake_retrans", mode, ibs_dir, &qca->wake_retrans); in qca_debugfs_init()
671 &qca->tx_idle_delay); in qca_debugfs_init()
677 struct qca_data *qca = hu->priv; in qca_flush()
681 skb_queue_purge(&qca->tx_wait_q); in qca_flush()
682 skb_queue_purge(&qca->txq); in qca_flush()
690 struct qca_data *qca = hu->priv; in qca_close()
696 skb_queue_purge(&qca->tx_wait_q); in qca_close()
697 skb_queue_purge(&qca->txq); in qca_close()
698 skb_queue_purge(&qca->rx_memdump_q); in qca_close()
699 destroy_workqueue(qca->workqueue); in qca_close()
700 del_timer_sync(&qca->tx_idle_timer); in qca_close()
701 del_timer_sync(&qca->wake_retrans_timer); in qca_close()
702 qca->hu = NULL; in qca_close()
704 kfree_skb(qca->rx_skb); in qca_close()
706 hu->priv = NULL; in qca_close()
713 /* Called upon a wake-up-indication from the device.
718 struct qca_data *qca = hu->priv; in device_want_to_wakeup()
722 spin_lock_irqsave(&qca->hci_ibs_lock, flags); in device_want_to_wakeup()
724 qca->ibs_recv_wakes++; in device_want_to_wakeup()
727 if (test_bit(QCA_SUSPENDING, &qca->flags)) { in device_want_to_wakeup()
728 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in device_want_to_wakeup()
732 switch (qca->rx_ibs_state) { in device_want_to_wakeup()
734 /* Make sure clock is on - we may have turned clock off since in device_want_to_wakeup()
737 queue_work(qca->workqueue, &qca->ws_awake_rx); in device_want_to_wakeup()
738 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in device_want_to_wakeup()
749 qca->ibs_sent_wacks++; in device_want_to_wakeup()
755 qca->rx_ibs_state); in device_want_to_wakeup()
759 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in device_want_to_wakeup()
765 /* Called upon a sleep-indication from the device.
770 struct qca_data *qca = hu->priv; in device_want_to_sleep()
772 BT_DBG("hu %p want to sleep in %d state", hu, qca->rx_ibs_state); in device_want_to_sleep()
774 spin_lock_irqsave(&qca->hci_ibs_lock, flags); in device_want_to_sleep()
776 qca->ibs_recv_slps++; in device_want_to_sleep()
778 switch (qca->rx_ibs_state) { in device_want_to_sleep()
781 qca->rx_ibs_state = HCI_IBS_RX_ASLEEP; in device_want_to_sleep()
783 queue_work(qca->workqueue, &qca->ws_rx_vote_off); in device_want_to_sleep()
792 qca->rx_ibs_state); in device_want_to_sleep()
796 wake_up_interruptible(&qca->suspend_wait_q); in device_want_to_sleep()
798 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in device_want_to_sleep()
801 /* Called upon wake-up-acknowledgement from the device
806 struct qca_data *qca = hu->priv; in device_woke_up()
811 spin_lock_irqsave(&qca->hci_ibs_lock, flags); in device_woke_up()
813 qca->ibs_recv_wacks++; in device_woke_up()
815 /* Don't react to the wake-up-acknowledgment when suspending. */ in device_woke_up()
816 if (test_bit(QCA_SUSPENDING, &qca->flags)) { in device_woke_up()
817 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in device_woke_up()
821 switch (qca->tx_ibs_state) { in device_woke_up()
825 qca->tx_ibs_state); in device_woke_up()
830 while ((skb = skb_dequeue(&qca->tx_wait_q))) in device_woke_up()
831 skb_queue_tail(&qca->txq, skb); in device_woke_up()
834 del_timer(&qca->wake_retrans_timer); in device_woke_up()
835 idle_delay = msecs_to_jiffies(qca->tx_idle_delay); in device_woke_up()
836 mod_timer(&qca->tx_idle_timer, jiffies + idle_delay); in device_woke_up()
837 qca->tx_ibs_state = HCI_IBS_TX_AWAKE; in device_woke_up()
843 qca->tx_ibs_state); in device_woke_up()
847 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in device_woke_up()
859 struct qca_data *qca = hu->priv; in qca_enqueue()
862 qca->tx_ibs_state); in qca_enqueue()
864 if (test_bit(QCA_SSR_TRIGGERED, &qca->flags)) { in qca_enqueue()
866 bt_dev_dbg(hu->hdev, "SSR is in progress"); in qca_enqueue()
874 spin_lock_irqsave(&qca->hci_ibs_lock, flags); in qca_enqueue()
877 * Out-Of-Band(GPIOs control) sleep is selected. in qca_enqueue()
880 if (test_bit(QCA_IBS_DISABLED, &qca->flags) || in qca_enqueue()
881 test_bit(QCA_SUSPENDING, &qca->flags)) { in qca_enqueue()
882 skb_queue_tail(&qca->txq, skb); in qca_enqueue()
883 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in qca_enqueue()
888 switch (qca->tx_ibs_state) { in qca_enqueue()
891 skb_queue_tail(&qca->txq, skb); in qca_enqueue()
892 idle_delay = msecs_to_jiffies(qca->tx_idle_delay); in qca_enqueue()
893 mod_timer(&qca->tx_idle_timer, jiffies + idle_delay); in qca_enqueue()
899 skb_queue_tail(&qca->tx_wait_q, skb); in qca_enqueue()
901 qca->tx_ibs_state = HCI_IBS_TX_WAKING; in qca_enqueue()
903 queue_work(qca->workqueue, &qca->ws_awake_device); in qca_enqueue()
909 skb_queue_tail(&qca->tx_wait_q, skb); in qca_enqueue()
914 qca->tx_ibs_state); in qca_enqueue()
919 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in qca_enqueue()
967 if (get_unaligned_le16(skb->data) == QCA_DEBUG_HANDLE) in qca_recv_acl_data()
977 struct hci_uart *hu = qca->hu; in qca_controller_memdump()
980 struct qca_memdump_data *qca_memdump = qca->qca_memdump; in qca_controller_memdump()
989 while ((skb = skb_dequeue(&qca->rx_memdump_q))) { in qca_controller_memdump()
991 mutex_lock(&qca->hci_memdump_lock); in qca_controller_memdump()
995 if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT || in qca_controller_memdump()
996 qca->memdump_state == QCA_MEMDUMP_COLLECTED) { in qca_controller_memdump()
997 mutex_unlock(&qca->hci_memdump_lock); in qca_controller_memdump()
1005 mutex_unlock(&qca->hci_memdump_lock); in qca_controller_memdump()
1009 qca->qca_memdump = qca_memdump; in qca_controller_memdump()
1012 qca->memdump_state = QCA_MEMDUMP_COLLECTING; in qca_controller_memdump()
1013 cmd_hdr = (void *) skb->data; in qca_controller_memdump()
1014 seq_no = __le16_to_cpu(cmd_hdr->seq_no); in qca_controller_memdump()
1025 set_bit(QCA_IBS_DISABLED, &qca->flags); in qca_controller_memdump()
1026 set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags); in qca_controller_memdump()
1027 dump = (void *) skb->data; in qca_controller_memdump()
1028 dump_size = __le32_to_cpu(dump->dump_size); in qca_controller_memdump()
1030 bt_dev_err(hu->hdev, "Rx invalid memdump size"); in qca_controller_memdump()
1033 qca->qca_memdump = NULL; in qca_controller_memdump()
1034 mutex_unlock(&qca->hci_memdump_lock); in qca_controller_memdump()
1038 bt_dev_info(hu->hdev, "QCA collecting dump of size:%u", in qca_controller_memdump()
1040 queue_delayed_work(qca->workqueue, in qca_controller_memdump()
1041 &qca->ctrl_memdump_timeout, in qca_controller_memdump()
1047 qca_memdump->ram_dump_size = dump_size; in qca_controller_memdump()
1048 qca_memdump->memdump_buf_head = memdump_buf; in qca_controller_memdump()
1049 qca_memdump->memdump_buf_tail = memdump_buf; in qca_controller_memdump()
1052 memdump_buf = qca_memdump->memdump_buf_tail; in qca_controller_memdump()
1058 bt_dev_err(hu->hdev, "QCA: Discarding other packets"); in qca_controller_memdump()
1061 qca->qca_memdump = NULL; in qca_controller_memdump()
1062 mutex_unlock(&qca->hci_memdump_lock); in qca_controller_memdump()
1074 while ((seq_no > qca_memdump->current_seq_no + 1) && in qca_controller_memdump()
1077 bt_dev_err(hu->hdev, "QCA controller missed packet:%d", in qca_controller_memdump()
1078 qca_memdump->current_seq_no); in qca_controller_memdump()
1079 rx_size = qca_memdump->received_dump; in qca_controller_memdump()
1081 if (rx_size > qca_memdump->ram_dump_size) { in qca_controller_memdump()
1082 bt_dev_err(hu->hdev, in qca_controller_memdump()
1084 qca_memdump->received_dump); in qca_controller_memdump()
1089 qca_memdump->received_dump += QCA_DUMP_PACKET_SIZE; in qca_controller_memdump()
1090 qca_memdump->current_seq_no++; in qca_controller_memdump()
1093 rx_size = qca_memdump->received_dump + skb->len; in qca_controller_memdump()
1094 if (rx_size <= qca_memdump->ram_dump_size) { in qca_controller_memdump()
1096 (seq_no != qca_memdump->current_seq_no)) in qca_controller_memdump()
1097 bt_dev_err(hu->hdev, in qca_controller_memdump()
1100 bt_dev_dbg(hu->hdev, in qca_controller_memdump()
1102 seq_no, skb->len); in qca_controller_memdump()
1103 memcpy(memdump_buf, (unsigned char *)skb->data, in qca_controller_memdump()
1104 skb->len); in qca_controller_memdump()
1105 memdump_buf = memdump_buf + skb->len; in qca_controller_memdump()
1106 qca_memdump->memdump_buf_tail = memdump_buf; in qca_controller_memdump()
1107 qca_memdump->current_seq_no = seq_no + 1; in qca_controller_memdump()
1108 qca_memdump->received_dump += skb->len; in qca_controller_memdump()
1110 bt_dev_err(hu->hdev, in qca_controller_memdump()
1112 qca_memdump->received_dump, seq_no); in qca_controller_memdump()
1114 qca->qca_memdump = qca_memdump; in qca_controller_memdump()
1117 bt_dev_info(hu->hdev, in qca_controller_memdump()
1119 qca_memdump->received_dump, in qca_controller_memdump()
1120 qca_memdump->ram_dump_size); in qca_controller_memdump()
1121 memdump_buf = qca_memdump->memdump_buf_head; in qca_controller_memdump()
1122 dev_coredumpv(&hu->serdev->dev, memdump_buf, in qca_controller_memdump()
1123 qca_memdump->received_dump, GFP_KERNEL); in qca_controller_memdump()
1124 cancel_delayed_work(&qca->ctrl_memdump_timeout); in qca_controller_memdump()
1125 kfree(qca->qca_memdump); in qca_controller_memdump()
1126 qca->qca_memdump = NULL; in qca_controller_memdump()
1127 qca->memdump_state = QCA_MEMDUMP_COLLECTED; in qca_controller_memdump()
1128 clear_bit(QCA_MEMDUMP_COLLECTION, &qca->flags); in qca_controller_memdump()
1131 mutex_unlock(&qca->hci_memdump_lock); in qca_controller_memdump()
1140 struct qca_data *qca = hu->priv; in qca_controller_memdump_event()
1142 set_bit(QCA_SSR_TRIGGERED, &qca->flags); in qca_controller_memdump_event()
1143 skb_queue_tail(&qca->rx_memdump_q, skb); in qca_controller_memdump_event()
1144 queue_work(qca->workqueue, &qca->ctrl_memdump_evt); in qca_controller_memdump_event()
1152 struct qca_data *qca = hu->priv; in qca_recv_event()
1154 if (test_bit(QCA_DROP_VENDOR_EVENT, &qca->flags)) { in qca_recv_event()
1155 struct hci_event_hdr *hdr = (void *)skb->data; in qca_recv_event()
1167 if (hdr->evt == HCI_EV_VENDOR) in qca_recv_event()
1168 complete(&qca->drop_ev_comp); in qca_recv_event()
1179 if ((skb->data[0] == HCI_VENDOR_PKT) && in qca_recv_event()
1180 (get_unaligned_be16(skb->data + 2) == QCA_SSR_DUMP_HANDLE)) in qca_recv_event()
1218 struct qca_data *qca = hu->priv; in qca_recv()
1220 if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) in qca_recv()
1221 return -EUNATCH; in qca_recv()
1223 qca->rx_skb = h4_recv_buf(hu->hdev, qca->rx_skb, data, count, in qca_recv()
1225 if (IS_ERR(qca->rx_skb)) { in qca_recv()
1226 int err = PTR_ERR(qca->rx_skb); in qca_recv()
1227 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err); in qca_recv()
1228 qca->rx_skb = NULL; in qca_recv()
1237 struct qca_data *qca = hu->priv; in qca_dequeue()
1239 return skb_dequeue(&qca->txq); in qca_dequeue()
1281 struct qca_data *qca = hu->priv; in qca_set_baudrate()
1286 return -EINVAL; in qca_set_baudrate()
1293 return -ENOMEM; in qca_set_baudrate()
1300 skb_queue_tail(&qca->txq, skb); in qca_set_baudrate()
1305 while (!skb_queue_empty(&qca->txq)) in qca_set_baudrate()
1308 if (hu->serdev) in qca_set_baudrate()
1309 serdev_device_wait_until_sent(hu->serdev, in qca_set_baudrate()
1324 if (hu->serdev) in host_set_baudrate()
1325 serdev_device_set_baudrate(hu->serdev, speed); in host_set_baudrate()
1339 * For example, wcn3990 supports RF COEX antenna for both Wi-Fi/BT in qca_send_power_pulse()
1341 * Wi-Fi/BT. Powering up the power sources will not enable BT, until in qca_send_power_pulse()
1346 bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd); in qca_send_power_pulse()
1348 serdev_device_write_flush(hu->serdev); in qca_send_power_pulse()
1350 ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd)); in qca_send_power_pulse()
1352 bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd); in qca_send_power_pulse()
1356 serdev_device_wait_until_sent(hu->serdev, timeout); in qca_send_power_pulse()
1374 if (hu->init_speed) in qca_get_speed()
1375 speed = hu->init_speed; in qca_get_speed()
1376 else if (hu->proto->init_speed) in qca_get_speed()
1377 speed = hu->proto->init_speed; in qca_get_speed()
1379 if (hu->oper_speed) in qca_get_speed()
1380 speed = hu->oper_speed; in qca_get_speed()
1381 else if (hu->proto->oper_speed) in qca_get_speed()
1382 speed = hu->proto->oper_speed; in qca_get_speed()
1394 return -EINVAL; in qca_check_speeds()
1398 return -EINVAL; in qca_check_speeds()
1407 struct qca_data *qca = hu->priv; in qca_set_speed()
1429 reinit_completion(&qca->drop_ev_comp); in qca_set_speed()
1430 set_bit(QCA_DROP_VENDOR_EVENT, &qca->flags); in qca_set_speed()
1434 bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed); in qca_set_speed()
1435 ret = qca_set_baudrate(hu->hdev, qca_baudrate); in qca_set_speed()
1450 if (!wait_for_completion_timeout(&qca->drop_ev_comp, in qca_set_speed()
1452 bt_dev_err(hu->hdev, in qca_set_speed()
1454 ret = -ETIMEDOUT; in qca_set_speed()
1457 clear_bit(QCA_DROP_VENDOR_EVENT, &qca->flags); in qca_set_speed()
1466 struct qca_data *qca = hu->priv; in qca_send_crashbuffer()
1471 bt_dev_err(hu->hdev, "Failed to allocate memory for skb packet"); in qca_send_crashbuffer()
1472 return -ENOMEM; in qca_send_crashbuffer()
1482 bt_dev_info(hu->hdev, "crash the soc to collect controller dump"); in qca_send_crashbuffer()
1483 skb_queue_tail(&qca->txq, skb); in qca_send_crashbuffer()
1492 struct qca_data *qca = hu->priv; in qca_wait_for_dump_collection()
1494 wait_on_bit_timeout(&qca->flags, QCA_MEMDUMP_COLLECTION, in qca_wait_for_dump_collection()
1497 clear_bit(QCA_MEMDUMP_COLLECTION, &qca->flags); in qca_wait_for_dump_collection()
1503 struct qca_data *qca = hu->priv; in qca_hw_error()
1505 set_bit(QCA_SSR_TRIGGERED, &qca->flags); in qca_hw_error()
1506 set_bit(QCA_HW_ERROR_EVENT, &qca->flags); in qca_hw_error()
1507 bt_dev_info(hdev, "mem_dump_status: %d", qca->memdump_state); in qca_hw_error()
1509 if (qca->memdump_state == QCA_MEMDUMP_IDLE) { in qca_hw_error()
1516 set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags); in qca_hw_error()
1519 } else if (qca->memdump_state == QCA_MEMDUMP_COLLECTING) { in qca_hw_error()
1527 mutex_lock(&qca->hci_memdump_lock); in qca_hw_error()
1528 if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) { in qca_hw_error()
1529 bt_dev_err(hu->hdev, "clearing allocated memory due to memdump timeout"); in qca_hw_error()
1530 if (qca->qca_memdump) { in qca_hw_error()
1531 vfree(qca->qca_memdump->memdump_buf_head); in qca_hw_error()
1532 kfree(qca->qca_memdump); in qca_hw_error()
1533 qca->qca_memdump = NULL; in qca_hw_error()
1535 qca->memdump_state = QCA_MEMDUMP_TIMEOUT; in qca_hw_error()
1536 cancel_delayed_work(&qca->ctrl_memdump_timeout); in qca_hw_error()
1538 mutex_unlock(&qca->hci_memdump_lock); in qca_hw_error()
1540 if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT || in qca_hw_error()
1541 qca->memdump_state == QCA_MEMDUMP_COLLECTED) { in qca_hw_error()
1542 cancel_work_sync(&qca->ctrl_memdump_evt); in qca_hw_error()
1543 skb_queue_purge(&qca->rx_memdump_q); in qca_hw_error()
1546 clear_bit(QCA_HW_ERROR_EVENT, &qca->flags); in qca_hw_error()
1552 struct qca_data *qca = hu->priv; in qca_cmd_timeout()
1554 set_bit(QCA_SSR_TRIGGERED, &qca->flags); in qca_cmd_timeout()
1555 if (qca->memdump_state == QCA_MEMDUMP_IDLE) { in qca_cmd_timeout()
1556 set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags); in qca_cmd_timeout()
1559 } else if (qca->memdump_state == QCA_MEMDUMP_COLLECTING) { in qca_cmd_timeout()
1567 mutex_lock(&qca->hci_memdump_lock); in qca_cmd_timeout()
1568 if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) { in qca_cmd_timeout()
1569 qca->memdump_state = QCA_MEMDUMP_TIMEOUT; in qca_cmd_timeout()
1570 if (!test_bit(QCA_HW_ERROR_EVENT, &qca->flags)) { in qca_cmd_timeout()
1574 hci_reset_dev(hu->hdev); in qca_cmd_timeout()
1577 mutex_unlock(&qca->hci_memdump_lock); in qca_cmd_timeout()
1585 /* UART driver handles the interrupt from BT SoC.So we need to use in qca_wakeup()
1588 wakeup = device_may_wakeup(hu->serdev->ctrl->dev.parent); in qca_wakeup()
1589 bt_dev_dbg(hu->hdev, "wakeup status : %d", wakeup); in qca_wakeup()
1604 qcadev = serdev_device_get_drvdata(hu->serdev); in qca_regulator_init()
1605 if (!qcadev->bt_power->vregs_on) { in qca_regulator_init()
1606 serdev_device_close(hu->serdev); in qca_regulator_init()
1611 ret = serdev_device_open(hu->serdev); in qca_regulator_init()
1613 bt_dev_err(hu->hdev, "failed to open port"); in qca_regulator_init()
1627 if (qcadev->bt_en) { in qca_regulator_init()
1628 gpiod_set_value_cansleep(qcadev->bt_en, 0); in qca_regulator_init()
1630 gpiod_set_value_cansleep(qcadev->bt_en, 1); in qca_regulator_init()
1632 if (qcadev->sw_ctrl) { in qca_regulator_init()
1633 sw_ctrl_state = gpiod_get_value_cansleep(qcadev->sw_ctrl); in qca_regulator_init()
1634 bt_dev_dbg(hu->hdev, "SW_CTRL is %d", sw_ctrl_state); in qca_regulator_init()
1651 serdev_device_close(hu->serdev); in qca_regulator_init()
1652 ret = serdev_device_open(hu->serdev); in qca_regulator_init()
1654 bt_dev_err(hu->hdev, "failed to open port"); in qca_regulator_init()
1668 struct qca_data *qca = hu->priv; in qca_power_on()
1671 /* Non-serdev device usually is powered by external power in qca_power_on()
1674 if (!hu->serdev) in qca_power_on()
1681 qcadev = serdev_device_get_drvdata(hu->serdev); in qca_power_on()
1682 if (qcadev->bt_en) { in qca_power_on()
1683 gpiod_set_value_cansleep(qcadev->bt_en, 1); in qca_power_on()
1689 clear_bit(QCA_BT_OFF, &qca->flags); in qca_power_on()
1695 struct hci_dev *hdev = hu->hdev; in qca_setup()
1696 struct qca_data *qca = hu->priv; in qca_setup()
1708 clear_bit(QCA_ROM_FW, &qca->flags); in qca_setup()
1710 set_bit(QCA_IBS_DISABLED, &qca->flags); in qca_setup()
1715 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); in qca_setup()
1721 qca->memdump_state = QCA_MEMDUMP_IDLE; in qca_setup()
1728 clear_bit(QCA_SSR_TRIGGERED, &qca->flags); in qca_setup()
1732 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); in qca_setup()
1764 clear_bit(QCA_IBS_DISABLED, &qca->flags); in qca_setup()
1766 hu->hdev->hw_error = qca_hw_error; in qca_setup()
1767 hu->hdev->cmd_timeout = qca_cmd_timeout; in qca_setup()
1768 hu->hdev->wakeup = qca_wakeup; in qca_setup()
1769 } else if (ret == -ENOENT) { in qca_setup()
1770 /* No patch/nvm-config found, run with original fw/config */ in qca_setup()
1771 set_bit(QCA_ROM_FW, &qca->flags); in qca_setup()
1773 } else if (ret == -EAGAIN) { in qca_setup()
1775 * Userspace firmware loader will return -EAGAIN in case no in qca_setup()
1776 * patch/nvm-config is found, so run with original fw/config. in qca_setup()
1778 set_bit(QCA_ROM_FW, &qca->flags); in qca_setup()
1784 bt_dev_warn(hdev, "Retry BT power ON:%d", retries); in qca_setup()
1786 if (hu->serdev) { in qca_setup()
1787 serdev_device_close(hu->serdev); in qca_setup()
1788 ret = serdev_device_open(hu->serdev); in qca_setup()
1800 hu->hdev->set_bdaddr = qca_set_bdaddr_rome; in qca_setup()
1802 hu->hdev->set_bdaddr = qca_set_bdaddr; in qca_setup()
1881 struct qca_data *qca = hu->priv; in qca_power_shutdown()
1890 spin_lock_irqsave(&qca->hci_ibs_lock, flags); in qca_power_shutdown()
1891 set_bit(QCA_IBS_DISABLED, &qca->flags); in qca_power_shutdown()
1893 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in qca_power_shutdown()
1895 /* Non-serdev device usually is powered by external power in qca_power_shutdown()
1898 if (!hu->serdev) in qca_power_shutdown()
1901 qcadev = serdev_device_get_drvdata(hu->serdev); in qca_power_shutdown()
1908 gpiod_set_value_cansleep(qcadev->bt_en, 0); in qca_power_shutdown()
1911 if (qcadev->sw_ctrl) { in qca_power_shutdown()
1912 sw_ctrl_state = gpiod_get_value_cansleep(qcadev->sw_ctrl); in qca_power_shutdown()
1913 bt_dev_dbg(hu->hdev, "SW_CTRL is %d", sw_ctrl_state); in qca_power_shutdown()
1915 } else if (qcadev->bt_en) { in qca_power_shutdown()
1916 gpiod_set_value_cansleep(qcadev->bt_en, 0); in qca_power_shutdown()
1919 set_bit(QCA_BT_OFF, &qca->flags); in qca_power_shutdown()
1925 struct qca_data *qca = hu->priv; in qca_power_off()
1928 hu->hdev->hw_error = NULL; in qca_power_off()
1929 hu->hdev->cmd_timeout = NULL; in qca_power_off()
1931 del_timer_sync(&qca->wake_retrans_timer); in qca_power_off()
1932 del_timer_sync(&qca->tx_idle_timer); in qca_power_off()
1936 && qca->memdump_state == QCA_MEMDUMP_IDLE) { in qca_power_off()
1947 struct qca_power *power = qcadev->bt_power; in qca_regulator_enable()
1951 if (power->vregs_on) in qca_regulator_enable()
1954 BT_DBG("enabling %d regulators)", power->num_vregs); in qca_regulator_enable()
1956 ret = regulator_bulk_enable(power->num_vregs, power->vreg_bulk); in qca_regulator_enable()
1960 power->vregs_on = true; in qca_regulator_enable()
1962 ret = clk_prepare_enable(qcadev->susclk); in qca_regulator_enable()
1976 power = qcadev->bt_power; in qca_regulator_disable()
1979 if (!power->vregs_on) in qca_regulator_disable()
1982 regulator_bulk_disable(power->num_vregs, power->vreg_bulk); in qca_regulator_disable()
1983 power->vregs_on = false; in qca_regulator_disable()
1985 clk_disable_unprepare(qcadev->susclk); in qca_regulator_disable()
1995 bulk = devm_kcalloc(qca->dev, num_vregs, sizeof(*bulk), GFP_KERNEL); in qca_init_regulators()
1997 return -ENOMEM; in qca_init_regulators()
2002 ret = devm_regulator_bulk_get(qca->dev, num_vregs, bulk); in qca_init_regulators()
2012 qca->vreg_bulk = bulk; in qca_init_regulators()
2013 qca->num_vregs = num_vregs; in qca_init_regulators()
2026 qcadev = devm_kzalloc(&serdev->dev, sizeof(*qcadev), GFP_KERNEL); in qca_serdev_probe()
2028 return -ENOMEM; in qca_serdev_probe()
2030 qcadev->serdev_hu.serdev = serdev; in qca_serdev_probe()
2031 data = device_get_match_data(&serdev->dev); in qca_serdev_probe()
2033 device_property_read_string(&serdev->dev, "firmware-name", in qca_serdev_probe()
2034 &qcadev->firmware_name); in qca_serdev_probe()
2035 device_property_read_u32(&serdev->dev, "max-speed", in qca_serdev_probe()
2036 &qcadev->oper_speed); in qca_serdev_probe()
2037 if (!qcadev->oper_speed) in qca_serdev_probe()
2041 (qca_is_wcn399x(data->soc_type) || in qca_serdev_probe()
2042 qca_is_wcn6750(data->soc_type))) { in qca_serdev_probe()
2043 qcadev->btsoc_type = data->soc_type; in qca_serdev_probe()
2044 qcadev->bt_power = devm_kzalloc(&serdev->dev, in qca_serdev_probe()
2047 if (!qcadev->bt_power) in qca_serdev_probe()
2048 return -ENOMEM; in qca_serdev_probe()
2050 qcadev->bt_power->dev = &serdev->dev; in qca_serdev_probe()
2051 err = qca_init_regulators(qcadev->bt_power, data->vregs, in qca_serdev_probe()
2052 data->num_vregs); in qca_serdev_probe()
2058 qcadev->bt_power->vregs_on = false; in qca_serdev_probe()
2060 qcadev->bt_en = devm_gpiod_get_optional(&serdev->dev, "enable", in qca_serdev_probe()
2062 if (IS_ERR_OR_NULL(qcadev->bt_en) && data->soc_type == QCA_WCN6750) { in qca_serdev_probe()
2063 dev_err(&serdev->dev, "failed to acquire BT_EN gpio\n"); in qca_serdev_probe()
2067 qcadev->sw_ctrl = devm_gpiod_get_optional(&serdev->dev, "swctrl", in qca_serdev_probe()
2069 if (IS_ERR_OR_NULL(qcadev->sw_ctrl) && data->soc_type == QCA_WCN6750) in qca_serdev_probe()
2070 dev_warn(&serdev->dev, "failed to acquire SW_CTRL gpio\n"); in qca_serdev_probe()
2072 qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL); in qca_serdev_probe()
2073 if (IS_ERR(qcadev->susclk)) { in qca_serdev_probe()
2074 dev_err(&serdev->dev, "failed to acquire clk\n"); in qca_serdev_probe()
2075 return PTR_ERR(qcadev->susclk); in qca_serdev_probe()
2078 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto); in qca_serdev_probe()
2085 qcadev->btsoc_type = data->soc_type; in qca_serdev_probe()
2087 qcadev->btsoc_type = QCA_ROME; in qca_serdev_probe()
2089 qcadev->bt_en = devm_gpiod_get_optional(&serdev->dev, "enable", in qca_serdev_probe()
2091 if (IS_ERR_OR_NULL(qcadev->bt_en)) { in qca_serdev_probe()
2092 dev_warn(&serdev->dev, "failed to acquire enable gpio\n"); in qca_serdev_probe()
2096 qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL); in qca_serdev_probe()
2097 if (IS_ERR(qcadev->susclk)) { in qca_serdev_probe()
2098 dev_warn(&serdev->dev, "failed to acquire clk\n"); in qca_serdev_probe()
2099 return PTR_ERR(qcadev->susclk); in qca_serdev_probe()
2101 err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ); in qca_serdev_probe()
2105 err = clk_prepare_enable(qcadev->susclk); in qca_serdev_probe()
2109 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto); in qca_serdev_probe()
2112 clk_disable_unprepare(qcadev->susclk); in qca_serdev_probe()
2117 hdev = qcadev->serdev_hu.hdev; in qca_serdev_probe()
2120 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); in qca_serdev_probe()
2121 hdev->shutdown = qca_power_off; in qca_serdev_probe()
2128 if (data->capabilities & QCA_CAP_WIDEBAND_SPEECH) in qca_serdev_probe()
2130 &hdev->quirks); in qca_serdev_probe()
2132 if (data->capabilities & QCA_CAP_VALID_LE_STATES) in qca_serdev_probe()
2133 set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks); in qca_serdev_probe()
2142 struct qca_power *power = qcadev->bt_power; in qca_serdev_remove()
2144 if ((qca_is_wcn399x(qcadev->btsoc_type) || in qca_serdev_remove()
2145 qca_is_wcn6750(qcadev->btsoc_type)) && in qca_serdev_remove()
2146 power->vregs_on) in qca_serdev_remove()
2147 qca_power_shutdown(&qcadev->serdev_hu); in qca_serdev_remove()
2148 else if (qcadev->susclk) in qca_serdev_remove()
2149 clk_disable_unprepare(qcadev->susclk); in qca_serdev_remove()
2151 hci_uart_unregister_device(&qcadev->serdev_hu); in qca_serdev_remove()
2163 if (qcadev->btsoc_type == QCA_QCA6390) { in qca_serdev_shutdown()
2190 struct hci_uart *hu = &qcadev->serdev_hu; in qca_suspend()
2191 struct qca_data *qca = hu->priv; in qca_suspend()
2198 set_bit(QCA_SUSPENDING, &qca->flags); in qca_suspend()
2200 /* if BT SoC is running with default firmware then it does not in qca_suspend()
2201 * support in-band sleep in qca_suspend()
2203 if (test_bit(QCA_ROM_FW, &qca->flags)) in qca_suspend()
2210 if (test_bit(QCA_BT_OFF, &qca->flags) && in qca_suspend()
2211 !test_bit(QCA_SSR_TRIGGERED, &qca->flags)) in qca_suspend()
2214 if (test_bit(QCA_IBS_DISABLED, &qca->flags) || in qca_suspend()
2215 test_bit(QCA_SSR_TRIGGERED, &qca->flags)) { in qca_suspend()
2216 wait_timeout = test_bit(QCA_SSR_TRIGGERED, &qca->flags) ? in qca_suspend()
2224 wait_on_bit_timeout(&qca->flags, QCA_IBS_DISABLED, in qca_suspend()
2227 if (test_bit(QCA_IBS_DISABLED, &qca->flags)) { in qca_suspend()
2228 bt_dev_err(hu->hdev, "SSR or FW download time out"); in qca_suspend()
2229 ret = -ETIMEDOUT; in qca_suspend()
2234 cancel_work_sync(&qca->ws_awake_device); in qca_suspend()
2235 cancel_work_sync(&qca->ws_awake_rx); in qca_suspend()
2237 spin_lock_irqsave_nested(&qca->hci_ibs_lock, in qca_suspend()
2240 switch (qca->tx_ibs_state) { in qca_suspend()
2242 del_timer(&qca->wake_retrans_timer); in qca_suspend()
2245 del_timer(&qca->tx_idle_timer); in qca_suspend()
2247 serdev_device_write_flush(hu->serdev); in qca_suspend()
2249 ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd)); in qca_suspend()
2256 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP; in qca_suspend()
2257 qca->ibs_sent_slps++; in qca_suspend()
2265 BT_ERR("Spurious tx state %d", qca->tx_ibs_state); in qca_suspend()
2266 ret = -EINVAL; in qca_suspend()
2270 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); in qca_suspend()
2276 serdev_device_wait_until_sent(hu->serdev, in qca_suspend()
2284 ret = wait_event_interruptible_timeout(qca->suspend_wait_q, in qca_suspend()
2285 qca->rx_ibs_state == HCI_IBS_RX_ASLEEP, in qca_suspend()
2288 ret = -ETIMEDOUT; in qca_suspend()
2295 clear_bit(QCA_SUSPENDING, &qca->flags); in qca_suspend()
2304 struct hci_uart *hu = &qcadev->serdev_hu; in qca_resume()
2305 struct qca_data *qca = hu->priv; in qca_resume()
2307 clear_bit(QCA_SUSPENDING, &qca->flags); in qca_resume()
2316 { .compatible = "qcom,qca6174-bt" },
2317 { .compatible = "qcom,qca6390-bt", .data = &qca_soc_data_qca6390},
2318 { .compatible = "qcom,qca9377-bt" },
2319 { .compatible = "qcom,wcn3990-bt", .data = &qca_soc_data_wcn3990},
2320 { .compatible = "qcom,wcn3991-bt", .data = &qca_soc_data_wcn3991},
2321 { .compatible = "qcom,wcn3998-bt", .data = &qca_soc_data_wcn3998},
2322 { .compatible = "qcom,wcn6750-bt", .data = &qca_soc_data_wcn6750},