1 // SPDX-License-Identifier: GPL-2.0-only
3 * Bluetooth Software UART Qualcomm protocol
5 * HCI_IBS (HCI In-Band Sleep) is Qualcomm's power management
6 * protocol extension to H4.
8 * Copyright (C) 2007 Texas Instruments, Inc.
9 * Copyright (c) 2010, 2012, 2018 The Linux Foundation. All rights reserved.
12 * This file is based on hci_ll.c, which was...
13 * Written by Ohad Ben-Cohen <ohad@bencohen.org>
14 * which was in turn based on hci_h4.c, which was written
15 * by Maxim Krasnyansky and Marcel Holtmann.
18 #include <linux/kernel.h>
19 #include <linux/clk.h>
20 #include <linux/completion.h>
21 #include <linux/debugfs.h>
22 #include <linux/delay.h>
23 #include <linux/devcoredump.h>
24 #include <linux/device.h>
25 #include <linux/gpio/consumer.h>
26 #include <linux/mod_devicetable.h>
27 #include <linux/module.h>
28 #include <linux/of_device.h>
29 #include <linux/acpi.h>
30 #include <linux/platform_device.h>
31 #include <linux/regulator/consumer.h>
32 #include <linux/serdev.h>
33 #include <linux/mutex.h>
34 #include <asm/unaligned.h>
36 #include <net/bluetooth/bluetooth.h>
37 #include <net/bluetooth/hci_core.h>
42 /* HCI_IBS protocol messages */
43 #define HCI_IBS_SLEEP_IND 0xFE
44 #define HCI_IBS_WAKE_IND 0xFD
45 #define HCI_IBS_WAKE_ACK 0xFC
46 #define HCI_MAX_IBS_SIZE 10
48 #define IBS_WAKE_RETRANS_TIMEOUT_MS 100
49 #define IBS_BTSOC_TX_IDLE_TIMEOUT_MS 200
50 #define IBS_HOST_TX_IDLE_TIMEOUT_MS 2000
51 #define CMD_TRANS_TIMEOUT_MS 100
52 #define MEMDUMP_TIMEOUT_MS 8000
53 #define IBS_DISABLE_SSR_TIMEOUT_MS \
54 (MEMDUMP_TIMEOUT_MS + FW_DOWNLOAD_TIMEOUT_MS)
55 #define FW_DOWNLOAD_TIMEOUT_MS 3000
58 #define SUSCLK_RATE_32KHZ 32768
60 /* Controller debug log header */
61 #define QCA_DEBUG_HANDLE 0x2EDC
63 /* max retry count when init fails */
64 #define MAX_INIT_RETRIES 3
66 /* Controller dump header */
67 #define QCA_SSR_DUMP_HANDLE 0x0108
68 #define QCA_DUMP_PACKET_SIZE 255
69 #define QCA_LAST_SEQUENCE_NUM 0xFFFF
70 #define QCA_CRASHBYTE_PACKET_LEN 1096
71 #define QCA_MEMDUMP_BYTE 0xFB
75 QCA_DROP_VENDOR_EVENT,
77 QCA_MEMDUMP_COLLECTION,
84 enum qca_capabilities {
85 QCA_CAP_WIDEBAND_SPEECH = BIT(0),
86 QCA_CAP_VALID_LE_STATES = BIT(1),
89 /* HCI_IBS transmit side sleep protocol states */
96 /* HCI_IBS receive side sleep protocol states */
102 /* HCI_IBS transmit and receive side clock state vote */
103 enum hci_ibs_clock_state_vote {
104 HCI_IBS_VOTE_STATS_UPDATE,
105 HCI_IBS_TX_VOTE_CLOCK_ON,
106 HCI_IBS_TX_VOTE_CLOCK_OFF,
107 HCI_IBS_RX_VOTE_CLOCK_ON,
108 HCI_IBS_RX_VOTE_CLOCK_OFF,
111 /* Controller memory dump states */
112 enum qca_memdump_states {
114 QCA_MEMDUMP_COLLECTING,
115 QCA_MEMDUMP_COLLECTED,
119 struct qca_memdump_data {
120 char *memdump_buf_head;
121 char *memdump_buf_tail;
127 struct qca_memdump_event_hdr {
136 struct qca_dump_size {
142 struct sk_buff *rx_skb;
143 struct sk_buff_head txq;
144 struct sk_buff_head tx_wait_q; /* HCI_IBS wait queue */
145 struct sk_buff_head rx_memdump_q; /* Memdump wait queue */
146 spinlock_t hci_ibs_lock; /* HCI_IBS state lock */
147 u8 tx_ibs_state; /* HCI_IBS transmit side power state*/
148 u8 rx_ibs_state; /* HCI_IBS receive side power state */
149 bool tx_vote; /* Clock must be on for TX */
150 bool rx_vote; /* Clock must be on for RX */
151 struct timer_list tx_idle_timer;
153 struct timer_list wake_retrans_timer;
155 struct workqueue_struct *workqueue;
156 struct work_struct ws_awake_rx;
157 struct work_struct ws_awake_device;
158 struct work_struct ws_rx_vote_off;
159 struct work_struct ws_tx_vote_off;
160 struct work_struct ctrl_memdump_evt;
161 struct delayed_work ctrl_memdump_timeout;
162 struct qca_memdump_data *qca_memdump;
164 struct completion drop_ev_comp;
165 wait_queue_head_t suspend_wait_q;
166 enum qca_memdump_states memdump_state;
167 struct mutex hci_memdump_lock;
169 /* For debugging purpose */
187 enum qca_speed_type {
193 * Voltage regulator information required for configuring the
194 * QCA Bluetooth chipset
198 unsigned int load_uA;
201 struct qca_device_data {
202 enum qca_btsoc_type soc_type;
203 struct qca_vreg *vregs;
205 uint32_t capabilities;
209 * Platform data for the QCA Bluetooth power driver.
213 struct regulator_bulk_data *vreg_bulk;
219 struct hci_uart serdev_hu;
220 struct gpio_desc *bt_en;
221 struct gpio_desc *sw_ctrl;
223 enum qca_btsoc_type btsoc_type;
224 struct qca_power *bt_power;
227 const char *firmware_name;
230 static int qca_regulator_enable(struct qca_serdev *qcadev);
231 static void qca_regulator_disable(struct qca_serdev *qcadev);
232 static void qca_power_shutdown(struct hci_uart *hu);
233 static int qca_power_off(struct hci_dev *hdev);
234 static void qca_controller_memdump(struct work_struct *work);
236 static enum qca_btsoc_type qca_soc_type(struct hci_uart *hu)
238 enum qca_btsoc_type soc_type;
241 struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev);
243 soc_type = qsd->btsoc_type;
251 static const char *qca_get_firmware_name(struct hci_uart *hu)
254 struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev);
256 return qsd->firmware_name;
262 static void __serial_clock_on(struct tty_struct *tty)
264 /* TODO: Some chipset requires to enable UART clock on client
265 * side to save power consumption or manual work is required.
266 * Please put your code to control UART clock here if needed
270 static void __serial_clock_off(struct tty_struct *tty)
272 /* TODO: Some chipset requires to disable UART clock on client
273 * side to save power consumption or manual work is required.
274 * Please put your code to control UART clock off here if needed
278 /* serial_clock_vote needs to be called with the ibs lock held */
279 static void serial_clock_vote(unsigned long vote, struct hci_uart *hu)
281 struct qca_data *qca = hu->priv;
284 bool old_vote = (qca->tx_vote | qca->rx_vote);
288 case HCI_IBS_VOTE_STATS_UPDATE:
289 diff = jiffies_to_msecs(jiffies - qca->vote_last_jif);
292 qca->vote_off_ms += diff;
294 qca->vote_on_ms += diff;
297 case HCI_IBS_TX_VOTE_CLOCK_ON:
302 case HCI_IBS_RX_VOTE_CLOCK_ON:
307 case HCI_IBS_TX_VOTE_CLOCK_OFF:
308 qca->tx_vote = false;
312 case HCI_IBS_RX_VOTE_CLOCK_OFF:
313 qca->rx_vote = false;
318 BT_ERR("Voting irregularity");
322 new_vote = qca->rx_vote | qca->tx_vote;
324 if (new_vote != old_vote) {
326 __serial_clock_on(hu->tty);
328 __serial_clock_off(hu->tty);
330 BT_DBG("Vote serial clock %s(%s)", new_vote ? "true" : "false",
331 vote ? "true" : "false");
333 diff = jiffies_to_msecs(jiffies - qca->vote_last_jif);
337 qca->vote_off_ms += diff;
340 qca->vote_on_ms += diff;
342 qca->vote_last_jif = jiffies;
346 /* Builds and sends an HCI_IBS command packet.
347 * These are very simple packets with only 1 cmd byte.
349 static int send_hci_ibs_cmd(u8 cmd, struct hci_uart *hu)
352 struct sk_buff *skb = NULL;
353 struct qca_data *qca = hu->priv;
355 BT_DBG("hu %p send hci ibs cmd 0x%x", hu, cmd);
357 skb = bt_skb_alloc(1, GFP_ATOMIC);
359 BT_ERR("Failed to allocate memory for HCI_IBS packet");
363 /* Assign HCI_IBS type */
364 skb_put_u8(skb, cmd);
366 skb_queue_tail(&qca->txq, skb);
371 static void qca_wq_awake_device(struct work_struct *work)
373 struct qca_data *qca = container_of(work, struct qca_data,
375 struct hci_uart *hu = qca->hu;
376 unsigned long retrans_delay;
379 BT_DBG("hu %p wq awake device", hu);
381 /* Vote for serial clock */
382 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_ON, hu);
384 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
386 /* Send wake indication to device */
387 if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND, hu) < 0)
388 BT_ERR("Failed to send WAKE to device");
390 qca->ibs_sent_wakes++;
392 /* Start retransmit timer */
393 retrans_delay = msecs_to_jiffies(qca->wake_retrans);
394 mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay);
396 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
398 /* Actually send the packets */
399 hci_uart_tx_wakeup(hu);
402 static void qca_wq_awake_rx(struct work_struct *work)
404 struct qca_data *qca = container_of(work, struct qca_data,
406 struct hci_uart *hu = qca->hu;
409 BT_DBG("hu %p wq awake rx", hu);
411 serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_ON, hu);
413 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
414 qca->rx_ibs_state = HCI_IBS_RX_AWAKE;
416 /* Always acknowledge device wake up,
417 * sending IBS message doesn't count as TX ON.
419 if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK, hu) < 0)
420 BT_ERR("Failed to acknowledge device wake up");
422 qca->ibs_sent_wacks++;
424 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
426 /* Actually send the packets */
427 hci_uart_tx_wakeup(hu);
430 static void qca_wq_serial_rx_clock_vote_off(struct work_struct *work)
432 struct qca_data *qca = container_of(work, struct qca_data,
434 struct hci_uart *hu = qca->hu;
436 BT_DBG("hu %p rx clock vote off", hu);
438 serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_OFF, hu);
441 static void qca_wq_serial_tx_clock_vote_off(struct work_struct *work)
443 struct qca_data *qca = container_of(work, struct qca_data,
445 struct hci_uart *hu = qca->hu;
447 BT_DBG("hu %p tx clock vote off", hu);
449 /* Run HCI tx handling unlocked */
450 hci_uart_tx_wakeup(hu);
452 /* Now that message queued to tty driver, vote for tty clocks off.
453 * It is up to the tty driver to pend the clocks off until tx done.
455 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF, hu);
458 static void hci_ibs_tx_idle_timeout(struct timer_list *t)
460 struct qca_data *qca = from_timer(qca, t, tx_idle_timer);
461 struct hci_uart *hu = qca->hu;
464 BT_DBG("hu %p idle timeout in %d state", hu, qca->tx_ibs_state);
466 spin_lock_irqsave_nested(&qca->hci_ibs_lock,
467 flags, SINGLE_DEPTH_NESTING);
469 switch (qca->tx_ibs_state) {
470 case HCI_IBS_TX_AWAKE:
471 /* TX_IDLE, go to SLEEP */
472 if (send_hci_ibs_cmd(HCI_IBS_SLEEP_IND, hu) < 0) {
473 BT_ERR("Failed to send SLEEP to device");
476 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
477 qca->ibs_sent_slps++;
478 queue_work(qca->workqueue, &qca->ws_tx_vote_off);
481 case HCI_IBS_TX_ASLEEP:
482 case HCI_IBS_TX_WAKING:
484 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state);
488 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
491 static void hci_ibs_wake_retrans_timeout(struct timer_list *t)
493 struct qca_data *qca = from_timer(qca, t, wake_retrans_timer);
494 struct hci_uart *hu = qca->hu;
495 unsigned long flags, retrans_delay;
496 bool retransmit = false;
498 BT_DBG("hu %p wake retransmit timeout in %d state",
499 hu, qca->tx_ibs_state);
501 spin_lock_irqsave_nested(&qca->hci_ibs_lock,
502 flags, SINGLE_DEPTH_NESTING);
504 /* Don't retransmit the HCI_IBS_WAKE_IND when suspending. */
505 if (test_bit(QCA_SUSPENDING, &qca->flags)) {
506 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
510 switch (qca->tx_ibs_state) {
511 case HCI_IBS_TX_WAKING:
512 /* No WAKE_ACK, retransmit WAKE */
514 if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND, hu) < 0) {
515 BT_ERR("Failed to acknowledge device wake up");
518 qca->ibs_sent_wakes++;
519 retrans_delay = msecs_to_jiffies(qca->wake_retrans);
520 mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay);
523 case HCI_IBS_TX_ASLEEP:
524 case HCI_IBS_TX_AWAKE:
526 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state);
530 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
533 hci_uart_tx_wakeup(hu);
537 static void qca_controller_memdump_timeout(struct work_struct *work)
539 struct qca_data *qca = container_of(work, struct qca_data,
540 ctrl_memdump_timeout.work);
541 struct hci_uart *hu = qca->hu;
543 mutex_lock(&qca->hci_memdump_lock);
544 if (test_bit(QCA_MEMDUMP_COLLECTION, &qca->flags)) {
545 qca->memdump_state = QCA_MEMDUMP_TIMEOUT;
546 if (!test_bit(QCA_HW_ERROR_EVENT, &qca->flags)) {
547 /* Inject hw error event to reset the device
550 hci_reset_dev(hu->hdev);
554 mutex_unlock(&qca->hci_memdump_lock);
558 /* Initialize protocol */
559 static int qca_open(struct hci_uart *hu)
561 struct qca_serdev *qcadev;
562 struct qca_data *qca;
564 BT_DBG("hu %p qca_open", hu);
566 if (!hci_uart_has_flow_control(hu))
569 qca = kzalloc(sizeof(struct qca_data), GFP_KERNEL);
573 skb_queue_head_init(&qca->txq);
574 skb_queue_head_init(&qca->tx_wait_q);
575 skb_queue_head_init(&qca->rx_memdump_q);
576 spin_lock_init(&qca->hci_ibs_lock);
577 mutex_init(&qca->hci_memdump_lock);
578 qca->workqueue = alloc_ordered_workqueue("qca_wq", 0);
579 if (!qca->workqueue) {
580 BT_ERR("QCA Workqueue not initialized properly");
585 INIT_WORK(&qca->ws_awake_rx, qca_wq_awake_rx);
586 INIT_WORK(&qca->ws_awake_device, qca_wq_awake_device);
587 INIT_WORK(&qca->ws_rx_vote_off, qca_wq_serial_rx_clock_vote_off);
588 INIT_WORK(&qca->ws_tx_vote_off, qca_wq_serial_tx_clock_vote_off);
589 INIT_WORK(&qca->ctrl_memdump_evt, qca_controller_memdump);
590 INIT_DELAYED_WORK(&qca->ctrl_memdump_timeout,
591 qca_controller_memdump_timeout);
592 init_waitqueue_head(&qca->suspend_wait_q);
595 init_completion(&qca->drop_ev_comp);
597 /* Assume we start with both sides asleep -- extra wakes OK */
598 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
599 qca->rx_ibs_state = HCI_IBS_RX_ASLEEP;
601 qca->vote_last_jif = jiffies;
606 qcadev = serdev_device_get_drvdata(hu->serdev);
608 if (qca_is_wcn399x(qcadev->btsoc_type) ||
609 qca_is_wcn6750(qcadev->btsoc_type))
610 hu->init_speed = qcadev->init_speed;
612 if (qcadev->oper_speed)
613 hu->oper_speed = qcadev->oper_speed;
616 timer_setup(&qca->wake_retrans_timer, hci_ibs_wake_retrans_timeout, 0);
617 qca->wake_retrans = IBS_WAKE_RETRANS_TIMEOUT_MS;
619 timer_setup(&qca->tx_idle_timer, hci_ibs_tx_idle_timeout, 0);
620 qca->tx_idle_delay = IBS_HOST_TX_IDLE_TIMEOUT_MS;
622 BT_DBG("HCI_UART_QCA open, tx_idle_delay=%u, wake_retrans=%u",
623 qca->tx_idle_delay, qca->wake_retrans);
628 static void qca_debugfs_init(struct hci_dev *hdev)
630 struct hci_uart *hu = hci_get_drvdata(hdev);
631 struct qca_data *qca = hu->priv;
632 struct dentry *ibs_dir;
638 ibs_dir = debugfs_create_dir("ibs", hdev->debugfs);
642 debugfs_create_u8("tx_ibs_state", mode, ibs_dir, &qca->tx_ibs_state);
643 debugfs_create_u8("rx_ibs_state", mode, ibs_dir, &qca->rx_ibs_state);
644 debugfs_create_u64("ibs_sent_sleeps", mode, ibs_dir,
645 &qca->ibs_sent_slps);
646 debugfs_create_u64("ibs_sent_wakes", mode, ibs_dir,
647 &qca->ibs_sent_wakes);
648 debugfs_create_u64("ibs_sent_wake_acks", mode, ibs_dir,
649 &qca->ibs_sent_wacks);
650 debugfs_create_u64("ibs_recv_sleeps", mode, ibs_dir,
651 &qca->ibs_recv_slps);
652 debugfs_create_u64("ibs_recv_wakes", mode, ibs_dir,
653 &qca->ibs_recv_wakes);
654 debugfs_create_u64("ibs_recv_wake_acks", mode, ibs_dir,
655 &qca->ibs_recv_wacks);
656 debugfs_create_bool("tx_vote", mode, ibs_dir, &qca->tx_vote);
657 debugfs_create_u64("tx_votes_on", mode, ibs_dir, &qca->tx_votes_on);
658 debugfs_create_u64("tx_votes_off", mode, ibs_dir, &qca->tx_votes_off);
659 debugfs_create_bool("rx_vote", mode, ibs_dir, &qca->rx_vote);
660 debugfs_create_u64("rx_votes_on", mode, ibs_dir, &qca->rx_votes_on);
661 debugfs_create_u64("rx_votes_off", mode, ibs_dir, &qca->rx_votes_off);
662 debugfs_create_u64("votes_on", mode, ibs_dir, &qca->votes_on);
663 debugfs_create_u64("votes_off", mode, ibs_dir, &qca->votes_off);
664 debugfs_create_u32("vote_on_ms", mode, ibs_dir, &qca->vote_on_ms);
665 debugfs_create_u32("vote_off_ms", mode, ibs_dir, &qca->vote_off_ms);
669 debugfs_create_u32("wake_retrans", mode, ibs_dir, &qca->wake_retrans);
670 debugfs_create_u32("tx_idle_delay", mode, ibs_dir,
671 &qca->tx_idle_delay);
674 /* Flush protocol data */
675 static int qca_flush(struct hci_uart *hu)
677 struct qca_data *qca = hu->priv;
679 BT_DBG("hu %p qca flush", hu);
681 skb_queue_purge(&qca->tx_wait_q);
682 skb_queue_purge(&qca->txq);
688 static int qca_close(struct hci_uart *hu)
690 struct qca_data *qca = hu->priv;
692 BT_DBG("hu %p qca close", hu);
694 serial_clock_vote(HCI_IBS_VOTE_STATS_UPDATE, hu);
696 skb_queue_purge(&qca->tx_wait_q);
697 skb_queue_purge(&qca->txq);
698 skb_queue_purge(&qca->rx_memdump_q);
699 del_timer(&qca->tx_idle_timer);
700 del_timer(&qca->wake_retrans_timer);
701 destroy_workqueue(qca->workqueue);
704 kfree_skb(qca->rx_skb);
713 /* Called upon a wake-up-indication from the device.
715 static void device_want_to_wakeup(struct hci_uart *hu)
718 struct qca_data *qca = hu->priv;
720 BT_DBG("hu %p want to wake up", hu);
722 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
724 qca->ibs_recv_wakes++;
726 /* Don't wake the rx up when suspending. */
727 if (test_bit(QCA_SUSPENDING, &qca->flags)) {
728 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
732 switch (qca->rx_ibs_state) {
733 case HCI_IBS_RX_ASLEEP:
734 /* Make sure clock is on - we may have turned clock off since
735 * receiving the wake up indicator awake rx clock.
737 queue_work(qca->workqueue, &qca->ws_awake_rx);
738 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
741 case HCI_IBS_RX_AWAKE:
742 /* Always acknowledge device wake up,
743 * sending IBS message doesn't count as TX ON.
745 if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK, hu) < 0) {
746 BT_ERR("Failed to acknowledge device wake up");
749 qca->ibs_sent_wacks++;
753 /* Any other state is illegal */
754 BT_ERR("Received HCI_IBS_WAKE_IND in rx state %d",
759 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
761 /* Actually send the packets */
762 hci_uart_tx_wakeup(hu);
765 /* Called upon a sleep-indication from the device.
767 static void device_want_to_sleep(struct hci_uart *hu)
770 struct qca_data *qca = hu->priv;
772 BT_DBG("hu %p want to sleep in %d state", hu, qca->rx_ibs_state);
774 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
776 qca->ibs_recv_slps++;
778 switch (qca->rx_ibs_state) {
779 case HCI_IBS_RX_AWAKE:
781 qca->rx_ibs_state = HCI_IBS_RX_ASLEEP;
782 /* Vote off rx clock under workqueue */
783 queue_work(qca->workqueue, &qca->ws_rx_vote_off);
786 case HCI_IBS_RX_ASLEEP:
790 /* Any other state is illegal */
791 BT_ERR("Received HCI_IBS_SLEEP_IND in rx state %d",
796 wake_up_interruptible(&qca->suspend_wait_q);
798 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
801 /* Called upon wake-up-acknowledgement from the device
803 static void device_woke_up(struct hci_uart *hu)
805 unsigned long flags, idle_delay;
806 struct qca_data *qca = hu->priv;
807 struct sk_buff *skb = NULL;
809 BT_DBG("hu %p woke up", hu);
811 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
813 qca->ibs_recv_wacks++;
815 /* Don't react to the wake-up-acknowledgment when suspending. */
816 if (test_bit(QCA_SUSPENDING, &qca->flags)) {
817 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
821 switch (qca->tx_ibs_state) {
822 case HCI_IBS_TX_AWAKE:
823 /* Expect one if we send 2 WAKEs */
824 BT_DBG("Received HCI_IBS_WAKE_ACK in tx state %d",
828 case HCI_IBS_TX_WAKING:
829 /* Send pending packets */
830 while ((skb = skb_dequeue(&qca->tx_wait_q)))
831 skb_queue_tail(&qca->txq, skb);
833 /* Switch timers and change state to HCI_IBS_TX_AWAKE */
834 del_timer(&qca->wake_retrans_timer);
835 idle_delay = msecs_to_jiffies(qca->tx_idle_delay);
836 mod_timer(&qca->tx_idle_timer, jiffies + idle_delay);
837 qca->tx_ibs_state = HCI_IBS_TX_AWAKE;
840 case HCI_IBS_TX_ASLEEP:
842 BT_ERR("Received HCI_IBS_WAKE_ACK in tx state %d",
847 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
849 /* Actually send the packets */
850 hci_uart_tx_wakeup(hu);
853 /* Enqueue frame for transmittion (padding, crc, etc) may be called from
854 * two simultaneous tasklets.
856 static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)
858 unsigned long flags = 0, idle_delay;
859 struct qca_data *qca = hu->priv;
861 BT_DBG("hu %p qca enq skb %p tx_ibs_state %d", hu, skb,
864 if (test_bit(QCA_SSR_TRIGGERED, &qca->flags)) {
865 /* As SSR is in progress, ignore the packets */
866 bt_dev_dbg(hu->hdev, "SSR is in progress");
871 /* Prepend skb with frame type */
872 memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
874 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
876 /* Don't go to sleep in middle of patch download or
877 * Out-Of-Band(GPIOs control) sleep is selected.
878 * Don't wake the device up when suspending.
880 if (test_bit(QCA_IBS_DISABLED, &qca->flags) ||
881 test_bit(QCA_SUSPENDING, &qca->flags)) {
882 skb_queue_tail(&qca->txq, skb);
883 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
887 /* Act according to current state */
888 switch (qca->tx_ibs_state) {
889 case HCI_IBS_TX_AWAKE:
890 BT_DBG("Device awake, sending normally");
891 skb_queue_tail(&qca->txq, skb);
892 idle_delay = msecs_to_jiffies(qca->tx_idle_delay);
893 mod_timer(&qca->tx_idle_timer, jiffies + idle_delay);
896 case HCI_IBS_TX_ASLEEP:
897 BT_DBG("Device asleep, waking up and queueing packet");
898 /* Save packet for later */
899 skb_queue_tail(&qca->tx_wait_q, skb);
901 qca->tx_ibs_state = HCI_IBS_TX_WAKING;
902 /* Schedule a work queue to wake up device */
903 queue_work(qca->workqueue, &qca->ws_awake_device);
906 case HCI_IBS_TX_WAKING:
907 BT_DBG("Device waking up, queueing packet");
908 /* Transient state; just keep packet for later */
909 skb_queue_tail(&qca->tx_wait_q, skb);
913 BT_ERR("Illegal tx state: %d (losing packet)",
919 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
924 static int qca_ibs_sleep_ind(struct hci_dev *hdev, struct sk_buff *skb)
926 struct hci_uart *hu = hci_get_drvdata(hdev);
928 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_SLEEP_IND);
930 device_want_to_sleep(hu);
936 static int qca_ibs_wake_ind(struct hci_dev *hdev, struct sk_buff *skb)
938 struct hci_uart *hu = hci_get_drvdata(hdev);
940 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_WAKE_IND);
942 device_want_to_wakeup(hu);
948 static int qca_ibs_wake_ack(struct hci_dev *hdev, struct sk_buff *skb)
950 struct hci_uart *hu = hci_get_drvdata(hdev);
952 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_WAKE_ACK);
960 static int qca_recv_acl_data(struct hci_dev *hdev, struct sk_buff *skb)
962 /* We receive debug logs from chip as an ACL packets.
963 * Instead of sending the data to ACL to decode the
964 * received data, we are pushing them to the above layers
965 * as a diagnostic packet.
967 if (get_unaligned_le16(skb->data) == QCA_DEBUG_HANDLE)
968 return hci_recv_diag(hdev, skb);
970 return hci_recv_frame(hdev, skb);
973 static void qca_controller_memdump(struct work_struct *work)
975 struct qca_data *qca = container_of(work, struct qca_data,
977 struct hci_uart *hu = qca->hu;
979 struct qca_memdump_event_hdr *cmd_hdr;
980 struct qca_memdump_data *qca_memdump = qca->qca_memdump;
981 struct qca_dump_size *dump;
983 char nullBuff[QCA_DUMP_PACKET_SIZE] = { 0 };
987 enum qca_btsoc_type soc_type = qca_soc_type(hu);
989 while ((skb = skb_dequeue(&qca->rx_memdump_q))) {
991 mutex_lock(&qca->hci_memdump_lock);
992 /* Skip processing the received packets if timeout detected
993 * or memdump collection completed.
995 if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT ||
996 qca->memdump_state == QCA_MEMDUMP_COLLECTED) {
997 mutex_unlock(&qca->hci_memdump_lock);
1002 qca_memdump = kzalloc(sizeof(struct qca_memdump_data),
1005 mutex_unlock(&qca->hci_memdump_lock);
1009 qca->qca_memdump = qca_memdump;
1012 qca->memdump_state = QCA_MEMDUMP_COLLECTING;
1013 cmd_hdr = (void *) skb->data;
1014 seq_no = __le16_to_cpu(cmd_hdr->seq_no);
1015 skb_pull(skb, sizeof(struct qca_memdump_event_hdr));
1019 /* This is the first frame of memdump packet from
1020 * the controller, Disable IBS to recevie dump
1021 * with out any interruption, ideally time required for
1022 * the controller to send the dump is 8 seconds. let us
1023 * start timer to handle this asynchronous activity.
1025 set_bit(QCA_IBS_DISABLED, &qca->flags);
1026 set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1027 dump = (void *) skb->data;
1028 dump_size = __le32_to_cpu(dump->dump_size);
1030 bt_dev_err(hu->hdev, "Rx invalid memdump size");
1033 qca->qca_memdump = NULL;
1034 mutex_unlock(&qca->hci_memdump_lock);
1038 bt_dev_info(hu->hdev, "QCA collecting dump of size:%u",
1040 queue_delayed_work(qca->workqueue,
1041 &qca->ctrl_memdump_timeout,
1042 msecs_to_jiffies(MEMDUMP_TIMEOUT_MS)
1045 skb_pull(skb, sizeof(dump_size));
1046 memdump_buf = vmalloc(dump_size);
1047 qca_memdump->ram_dump_size = dump_size;
1048 qca_memdump->memdump_buf_head = memdump_buf;
1049 qca_memdump->memdump_buf_tail = memdump_buf;
1052 memdump_buf = qca_memdump->memdump_buf_tail;
1054 /* If sequence no 0 is missed then there is no point in
1055 * accepting the other sequences.
1058 bt_dev_err(hu->hdev, "QCA: Discarding other packets");
1061 qca->qca_memdump = NULL;
1062 mutex_unlock(&qca->hci_memdump_lock);
1066 /* There could be chance of missing some packets from
1067 * the controller. In such cases let us store the dummy
1068 * packets in the buffer.
1070 /* For QCA6390, controller does not lost packets but
1071 * sequence number field of packet sometimes has error
1072 * bits, so skip this checking for missing packet.
1074 while ((seq_no > qca_memdump->current_seq_no + 1) &&
1075 (soc_type != QCA_QCA6390) &&
1076 seq_no != QCA_LAST_SEQUENCE_NUM) {
1077 bt_dev_err(hu->hdev, "QCA controller missed packet:%d",
1078 qca_memdump->current_seq_no);
1079 rx_size = qca_memdump->received_dump;
1080 rx_size += QCA_DUMP_PACKET_SIZE;
1081 if (rx_size > qca_memdump->ram_dump_size) {
1082 bt_dev_err(hu->hdev,
1083 "QCA memdump received %d, no space for missed packet",
1084 qca_memdump->received_dump);
1087 memcpy(memdump_buf, nullBuff, QCA_DUMP_PACKET_SIZE);
1088 memdump_buf = memdump_buf + QCA_DUMP_PACKET_SIZE;
1089 qca_memdump->received_dump += QCA_DUMP_PACKET_SIZE;
1090 qca_memdump->current_seq_no++;
1093 rx_size = qca_memdump->received_dump + skb->len;
1094 if (rx_size <= qca_memdump->ram_dump_size) {
1095 if ((seq_no != QCA_LAST_SEQUENCE_NUM) &&
1096 (seq_no != qca_memdump->current_seq_no))
1097 bt_dev_err(hu->hdev,
1098 "QCA memdump unexpected packet %d",
1100 bt_dev_dbg(hu->hdev,
1101 "QCA memdump packet %d with length %d",
1103 memcpy(memdump_buf, (unsigned char *)skb->data,
1105 memdump_buf = memdump_buf + skb->len;
1106 qca_memdump->memdump_buf_tail = memdump_buf;
1107 qca_memdump->current_seq_no = seq_no + 1;
1108 qca_memdump->received_dump += skb->len;
1110 bt_dev_err(hu->hdev,
1111 "QCA memdump received %d, no space for packet %d",
1112 qca_memdump->received_dump, seq_no);
1114 qca->qca_memdump = qca_memdump;
1116 if (seq_no == QCA_LAST_SEQUENCE_NUM) {
1117 bt_dev_info(hu->hdev,
1118 "QCA memdump Done, received %d, total %d",
1119 qca_memdump->received_dump,
1120 qca_memdump->ram_dump_size);
1121 memdump_buf = qca_memdump->memdump_buf_head;
1122 dev_coredumpv(&hu->serdev->dev, memdump_buf,
1123 qca_memdump->received_dump, GFP_KERNEL);
1124 cancel_delayed_work(&qca->ctrl_memdump_timeout);
1125 kfree(qca->qca_memdump);
1126 qca->qca_memdump = NULL;
1127 qca->memdump_state = QCA_MEMDUMP_COLLECTED;
1128 clear_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1131 mutex_unlock(&qca->hci_memdump_lock);
1136 static int qca_controller_memdump_event(struct hci_dev *hdev,
1137 struct sk_buff *skb)
1139 struct hci_uart *hu = hci_get_drvdata(hdev);
1140 struct qca_data *qca = hu->priv;
1142 set_bit(QCA_SSR_TRIGGERED, &qca->flags);
1143 skb_queue_tail(&qca->rx_memdump_q, skb);
1144 queue_work(qca->workqueue, &qca->ctrl_memdump_evt);
1149 static int qca_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
1151 struct hci_uart *hu = hci_get_drvdata(hdev);
1152 struct qca_data *qca = hu->priv;
1154 if (test_bit(QCA_DROP_VENDOR_EVENT, &qca->flags)) {
1155 struct hci_event_hdr *hdr = (void *)skb->data;
1157 /* For the WCN3990 the vendor command for a baudrate change
1158 * isn't sent as synchronous HCI command, because the
1159 * controller sends the corresponding vendor event with the
1160 * new baudrate. The event is received and properly decoded
1161 * after changing the baudrate of the host port. It needs to
1162 * be dropped, otherwise it can be misinterpreted as
1163 * response to a later firmware download command (also a
1167 if (hdr->evt == HCI_EV_VENDOR)
1168 complete(&qca->drop_ev_comp);
1174 /* We receive chip memory dump as an event packet, With a dedicated
1175 * handler followed by a hardware error event. When this event is
1176 * received we store dump into a file before closing hci. This
1177 * dump will help in triaging the issues.
1179 if ((skb->data[0] == HCI_VENDOR_PKT) &&
1180 (get_unaligned_be16(skb->data + 2) == QCA_SSR_DUMP_HANDLE))
1181 return qca_controller_memdump_event(hdev, skb);
1183 return hci_recv_frame(hdev, skb);
1186 #define QCA_IBS_SLEEP_IND_EVENT \
1187 .type = HCI_IBS_SLEEP_IND, \
1191 .maxlen = HCI_MAX_IBS_SIZE
1193 #define QCA_IBS_WAKE_IND_EVENT \
1194 .type = HCI_IBS_WAKE_IND, \
1198 .maxlen = HCI_MAX_IBS_SIZE
1200 #define QCA_IBS_WAKE_ACK_EVENT \
1201 .type = HCI_IBS_WAKE_ACK, \
1205 .maxlen = HCI_MAX_IBS_SIZE
1207 static const struct h4_recv_pkt qca_recv_pkts[] = {
1208 { H4_RECV_ACL, .recv = qca_recv_acl_data },
1209 { H4_RECV_SCO, .recv = hci_recv_frame },
1210 { H4_RECV_EVENT, .recv = qca_recv_event },
1211 { QCA_IBS_WAKE_IND_EVENT, .recv = qca_ibs_wake_ind },
1212 { QCA_IBS_WAKE_ACK_EVENT, .recv = qca_ibs_wake_ack },
1213 { QCA_IBS_SLEEP_IND_EVENT, .recv = qca_ibs_sleep_ind },
1216 static int qca_recv(struct hci_uart *hu, const void *data, int count)
1218 struct qca_data *qca = hu->priv;
1220 if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
1223 qca->rx_skb = h4_recv_buf(hu->hdev, qca->rx_skb, data, count,
1224 qca_recv_pkts, ARRAY_SIZE(qca_recv_pkts));
1225 if (IS_ERR(qca->rx_skb)) {
1226 int err = PTR_ERR(qca->rx_skb);
1227 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
1235 static struct sk_buff *qca_dequeue(struct hci_uart *hu)
1237 struct qca_data *qca = hu->priv;
1239 return skb_dequeue(&qca->txq);
1242 static uint8_t qca_get_baudrate_value(int speed)
1246 return QCA_BAUDRATE_9600;
1248 return QCA_BAUDRATE_19200;
1250 return QCA_BAUDRATE_38400;
1252 return QCA_BAUDRATE_57600;
1254 return QCA_BAUDRATE_115200;
1256 return QCA_BAUDRATE_230400;
1258 return QCA_BAUDRATE_460800;
1260 return QCA_BAUDRATE_500000;
1262 return QCA_BAUDRATE_921600;
1264 return QCA_BAUDRATE_1000000;
1266 return QCA_BAUDRATE_2000000;
1268 return QCA_BAUDRATE_3000000;
1270 return QCA_BAUDRATE_3200000;
1272 return QCA_BAUDRATE_3500000;
1274 return QCA_BAUDRATE_115200;
1278 static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
1280 struct hci_uart *hu = hci_get_drvdata(hdev);
1281 struct qca_data *qca = hu->priv;
1282 struct sk_buff *skb;
1283 u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
1285 if (baudrate > QCA_BAUDRATE_3200000)
1290 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
1292 bt_dev_err(hdev, "Failed to allocate baudrate packet");
1296 /* Assign commands to change baudrate and packet type. */
1297 skb_put_data(skb, cmd, sizeof(cmd));
1298 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
1300 skb_queue_tail(&qca->txq, skb);
1301 hci_uart_tx_wakeup(hu);
1303 /* Wait for the baudrate change request to be sent */
1305 while (!skb_queue_empty(&qca->txq))
1306 usleep_range(100, 200);
1309 serdev_device_wait_until_sent(hu->serdev,
1310 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS));
1312 /* Give the controller time to process the request */
1313 if (qca_is_wcn399x(qca_soc_type(hu)) ||
1314 qca_is_wcn6750(qca_soc_type(hu)))
1315 usleep_range(1000, 10000);
1322 static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
1325 serdev_device_set_baudrate(hu->serdev, speed);
1327 hci_uart_set_baudrate(hu, speed);
1330 static int qca_send_power_pulse(struct hci_uart *hu, bool on)
1333 int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
1334 u8 cmd = on ? QCA_WCN3990_POWERON_PULSE : QCA_WCN3990_POWEROFF_PULSE;
1336 /* These power pulses are single byte command which are sent
1337 * at required baudrate to wcn3990. On wcn3990, we have an external
1338 * circuit at Tx pin which decodes the pulse sent at specific baudrate.
1339 * For example, wcn3990 supports RF COEX antenna for both Wi-Fi/BT
1340 * and also we use the same power inputs to turn on and off for
1341 * Wi-Fi/BT. Powering up the power sources will not enable BT, until
1342 * we send a power on pulse at 115200 bps. This algorithm will help to
1343 * save power. Disabling hardware flow control is mandatory while
1344 * sending power pulses to SoC.
1346 bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd);
1348 serdev_device_write_flush(hu->serdev);
1349 hci_uart_set_flow_control(hu, true);
1350 ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
1352 bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
1356 serdev_device_wait_until_sent(hu->serdev, timeout);
1357 hci_uart_set_flow_control(hu, false);
1359 /* Give to controller time to boot/shutdown */
1363 usleep_range(1000, 10000);
1368 static unsigned int qca_get_speed(struct hci_uart *hu,
1369 enum qca_speed_type speed_type)
1371 unsigned int speed = 0;
1373 if (speed_type == QCA_INIT_SPEED) {
1375 speed = hu->init_speed;
1376 else if (hu->proto->init_speed)
1377 speed = hu->proto->init_speed;
1380 speed = hu->oper_speed;
1381 else if (hu->proto->oper_speed)
1382 speed = hu->proto->oper_speed;
1388 static int qca_check_speeds(struct hci_uart *hu)
1390 if (qca_is_wcn399x(qca_soc_type(hu)) ||
1391 qca_is_wcn6750(qca_soc_type(hu))) {
1392 if (!qca_get_speed(hu, QCA_INIT_SPEED) &&
1393 !qca_get_speed(hu, QCA_OPER_SPEED))
1396 if (!qca_get_speed(hu, QCA_INIT_SPEED) ||
1397 !qca_get_speed(hu, QCA_OPER_SPEED))
1404 static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
1406 unsigned int speed, qca_baudrate;
1407 struct qca_data *qca = hu->priv;
1410 if (speed_type == QCA_INIT_SPEED) {
1411 speed = qca_get_speed(hu, QCA_INIT_SPEED);
1413 host_set_baudrate(hu, speed);
1415 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1417 speed = qca_get_speed(hu, QCA_OPER_SPEED);
1421 /* Disable flow control for wcn3990 to deassert RTS while
1422 * changing the baudrate of chip and host.
1424 if (qca_is_wcn399x(soc_type) ||
1425 qca_is_wcn6750(soc_type))
1426 hci_uart_set_flow_control(hu, true);
1428 if (soc_type == QCA_WCN3990) {
1429 reinit_completion(&qca->drop_ev_comp);
1430 set_bit(QCA_DROP_VENDOR_EVENT, &qca->flags);
1433 qca_baudrate = qca_get_baudrate_value(speed);
1434 bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed);
1435 ret = qca_set_baudrate(hu->hdev, qca_baudrate);
1439 host_set_baudrate(hu, speed);
1442 if (qca_is_wcn399x(soc_type) ||
1443 qca_is_wcn6750(soc_type))
1444 hci_uart_set_flow_control(hu, false);
1446 if (soc_type == QCA_WCN3990) {
1447 /* Wait for the controller to send the vendor event
1448 * for the baudrate change command.
1450 if (!wait_for_completion_timeout(&qca->drop_ev_comp,
1451 msecs_to_jiffies(100))) {
1452 bt_dev_err(hu->hdev,
1453 "Failed to change controller baudrate\n");
1457 clear_bit(QCA_DROP_VENDOR_EVENT, &qca->flags);
1464 static int qca_send_crashbuffer(struct hci_uart *hu)
1466 struct qca_data *qca = hu->priv;
1467 struct sk_buff *skb;
1469 skb = bt_skb_alloc(QCA_CRASHBYTE_PACKET_LEN, GFP_KERNEL);
1471 bt_dev_err(hu->hdev, "Failed to allocate memory for skb packet");
1475 /* We forcefully crash the controller, by sending 0xfb byte for
1476 * 1024 times. We also might have chance of losing data, To be
1477 * on safer side we send 1096 bytes to the SoC.
1479 memset(skb_put(skb, QCA_CRASHBYTE_PACKET_LEN), QCA_MEMDUMP_BYTE,
1480 QCA_CRASHBYTE_PACKET_LEN);
1481 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
1482 bt_dev_info(hu->hdev, "crash the soc to collect controller dump");
1483 skb_queue_tail(&qca->txq, skb);
1484 hci_uart_tx_wakeup(hu);
1489 static void qca_wait_for_dump_collection(struct hci_dev *hdev)
1491 struct hci_uart *hu = hci_get_drvdata(hdev);
1492 struct qca_data *qca = hu->priv;
1494 wait_on_bit_timeout(&qca->flags, QCA_MEMDUMP_COLLECTION,
1495 TASK_UNINTERRUPTIBLE, MEMDUMP_TIMEOUT_MS);
1497 clear_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1500 static void qca_hw_error(struct hci_dev *hdev, u8 code)
1502 struct hci_uart *hu = hci_get_drvdata(hdev);
1503 struct qca_data *qca = hu->priv;
1505 set_bit(QCA_SSR_TRIGGERED, &qca->flags);
1506 set_bit(QCA_HW_ERROR_EVENT, &qca->flags);
1507 bt_dev_info(hdev, "mem_dump_status: %d", qca->memdump_state);
1509 if (qca->memdump_state == QCA_MEMDUMP_IDLE) {
1510 /* If hardware error event received for other than QCA
1511 * soc memory dump event, then we need to crash the SOC
1512 * and wait here for 8 seconds to get the dump packets.
1513 * This will block main thread to be on hold until we
1516 set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1517 qca_send_crashbuffer(hu);
1518 qca_wait_for_dump_collection(hdev);
1519 } else if (qca->memdump_state == QCA_MEMDUMP_COLLECTING) {
1520 /* Let us wait here until memory dump collected or
1521 * memory dump timer expired.
1523 bt_dev_info(hdev, "waiting for dump to complete");
1524 qca_wait_for_dump_collection(hdev);
1527 mutex_lock(&qca->hci_memdump_lock);
1528 if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) {
1529 bt_dev_err(hu->hdev, "clearing allocated memory due to memdump timeout");
1530 if (qca->qca_memdump) {
1531 vfree(qca->qca_memdump->memdump_buf_head);
1532 kfree(qca->qca_memdump);
1533 qca->qca_memdump = NULL;
1535 qca->memdump_state = QCA_MEMDUMP_TIMEOUT;
1536 cancel_delayed_work(&qca->ctrl_memdump_timeout);
1538 mutex_unlock(&qca->hci_memdump_lock);
1540 if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT ||
1541 qca->memdump_state == QCA_MEMDUMP_COLLECTED) {
1542 cancel_work_sync(&qca->ctrl_memdump_evt);
1543 skb_queue_purge(&qca->rx_memdump_q);
1546 clear_bit(QCA_HW_ERROR_EVENT, &qca->flags);
1549 static void qca_cmd_timeout(struct hci_dev *hdev)
1551 struct hci_uart *hu = hci_get_drvdata(hdev);
1552 struct qca_data *qca = hu->priv;
1554 set_bit(QCA_SSR_TRIGGERED, &qca->flags);
1555 if (qca->memdump_state == QCA_MEMDUMP_IDLE) {
1556 set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1557 qca_send_crashbuffer(hu);
1558 qca_wait_for_dump_collection(hdev);
1559 } else if (qca->memdump_state == QCA_MEMDUMP_COLLECTING) {
1560 /* Let us wait here until memory dump collected or
1561 * memory dump timer expired.
1563 bt_dev_info(hdev, "waiting for dump to complete");
1564 qca_wait_for_dump_collection(hdev);
1567 mutex_lock(&qca->hci_memdump_lock);
1568 if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) {
1569 qca->memdump_state = QCA_MEMDUMP_TIMEOUT;
1570 if (!test_bit(QCA_HW_ERROR_EVENT, &qca->flags)) {
1571 /* Inject hw error event to reset the device
1574 hci_reset_dev(hu->hdev);
1577 mutex_unlock(&qca->hci_memdump_lock);
1580 static bool qca_prevent_wake(struct hci_dev *hdev)
1582 struct hci_uart *hu = hci_get_drvdata(hdev);
1585 /* UART driver handles the interrupt from BT SoC.So we need to use
1586 * device handle of UART driver to get the status of device may wakeup.
1588 wakeup = device_may_wakeup(hu->serdev->ctrl->dev.parent);
1589 bt_dev_dbg(hu->hdev, "wakeup status : %d", wakeup);
1594 static int qca_regulator_init(struct hci_uart *hu)
1596 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1597 struct qca_serdev *qcadev;
1601 /* Check for vregs status, may be hci down has turned
1602 * off the voltage regulator.
1604 qcadev = serdev_device_get_drvdata(hu->serdev);
1605 if (!qcadev->bt_power->vregs_on) {
1606 serdev_device_close(hu->serdev);
1607 ret = qca_regulator_enable(qcadev);
1611 ret = serdev_device_open(hu->serdev);
1613 bt_dev_err(hu->hdev, "failed to open port");
1618 if (qca_is_wcn399x(soc_type)) {
1619 /* Forcefully enable wcn399x to enter in to boot mode. */
1620 host_set_baudrate(hu, 2400);
1621 ret = qca_send_power_pulse(hu, false);
1626 /* For wcn6750 need to enable gpio bt_en */
1627 if (qcadev->bt_en) {
1628 gpiod_set_value_cansleep(qcadev->bt_en, 0);
1630 gpiod_set_value_cansleep(qcadev->bt_en, 1);
1632 if (qcadev->sw_ctrl) {
1633 sw_ctrl_state = gpiod_get_value_cansleep(qcadev->sw_ctrl);
1634 bt_dev_dbg(hu->hdev, "SW_CTRL is %d", sw_ctrl_state);
1638 qca_set_speed(hu, QCA_INIT_SPEED);
1640 if (qca_is_wcn399x(soc_type)) {
1641 ret = qca_send_power_pulse(hu, true);
1646 /* Now the device is in ready state to communicate with host.
1647 * To sync host with device we need to reopen port.
1648 * Without this, we will have RTS and CTS synchronization
1651 serdev_device_close(hu->serdev);
1652 ret = serdev_device_open(hu->serdev);
1654 bt_dev_err(hu->hdev, "failed to open port");
1658 hci_uart_set_flow_control(hu, false);
1663 static int qca_power_on(struct hci_dev *hdev)
1665 struct hci_uart *hu = hci_get_drvdata(hdev);
1666 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1667 struct qca_serdev *qcadev;
1668 struct qca_data *qca = hu->priv;
1671 /* Non-serdev device usually is powered by external power
1672 * and don't need additional action in driver for power on
1677 if (qca_is_wcn399x(soc_type) ||
1678 qca_is_wcn6750(soc_type)) {
1679 ret = qca_regulator_init(hu);
1681 qcadev = serdev_device_get_drvdata(hu->serdev);
1682 if (qcadev->bt_en) {
1683 gpiod_set_value_cansleep(qcadev->bt_en, 1);
1684 /* Controller needs time to bootup. */
1689 clear_bit(QCA_BT_OFF, &qca->flags);
1693 static int qca_setup(struct hci_uart *hu)
1695 struct hci_dev *hdev = hu->hdev;
1696 struct qca_data *qca = hu->priv;
1697 unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200;
1698 unsigned int retries = 0;
1699 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1700 const char *firmware_name = qca_get_firmware_name(hu);
1702 struct qca_btsoc_version ver;
1704 ret = qca_check_speeds(hu);
1708 clear_bit(QCA_ROM_FW, &qca->flags);
1709 /* Patch downloading has to be done without IBS mode */
1710 set_bit(QCA_IBS_DISABLED, &qca->flags);
1712 /* Enable controller to do both LE scan and BR/EDR inquiry
1715 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
1717 bt_dev_info(hdev, "setting up %s",
1718 qca_is_wcn399x(soc_type) ? "wcn399x" :
1719 (soc_type == QCA_WCN6750) ? "wcn6750" : "ROME/QCA6390");
1721 qca->memdump_state = QCA_MEMDUMP_IDLE;
1724 ret = qca_power_on(hdev);
1728 clear_bit(QCA_SSR_TRIGGERED, &qca->flags);
1730 if (qca_is_wcn399x(soc_type) ||
1731 qca_is_wcn6750(soc_type)) {
1732 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
1734 ret = qca_read_soc_version(hdev, &ver, soc_type);
1738 qca_set_speed(hu, QCA_INIT_SPEED);
1741 /* Setup user speed if needed */
1742 speed = qca_get_speed(hu, QCA_OPER_SPEED);
1744 ret = qca_set_speed(hu, QCA_OPER_SPEED);
1748 qca_baudrate = qca_get_baudrate_value(speed);
1751 if (!(qca_is_wcn399x(soc_type) ||
1752 qca_is_wcn6750(soc_type))) {
1753 /* Get QCA version information */
1754 ret = qca_read_soc_version(hdev, &ver, soc_type);
1759 /* Setup patch / NVM configurations */
1760 ret = qca_uart_setup(hdev, qca_baudrate, soc_type, ver,
1763 clear_bit(QCA_IBS_DISABLED, &qca->flags);
1764 qca_debugfs_init(hdev);
1765 hu->hdev->hw_error = qca_hw_error;
1766 hu->hdev->cmd_timeout = qca_cmd_timeout;
1767 hu->hdev->prevent_wake = qca_prevent_wake;
1768 } else if (ret == -ENOENT) {
1769 /* No patch/nvm-config found, run with original fw/config */
1770 set_bit(QCA_ROM_FW, &qca->flags);
1772 } else if (ret == -EAGAIN) {
1774 * Userspace firmware loader will return -EAGAIN in case no
1775 * patch/nvm-config is found, so run with original fw/config.
1777 set_bit(QCA_ROM_FW, &qca->flags);
1782 if (ret && retries < MAX_INIT_RETRIES) {
1783 bt_dev_warn(hdev, "Retry BT power ON:%d", retries);
1784 qca_power_shutdown(hu);
1786 serdev_device_close(hu->serdev);
1787 ret = serdev_device_open(hu->serdev);
1789 bt_dev_err(hdev, "failed to open port");
1798 if (soc_type == QCA_ROME)
1799 hu->hdev->set_bdaddr = qca_set_bdaddr_rome;
1801 hu->hdev->set_bdaddr = qca_set_bdaddr;
1806 static const struct hci_uart_proto qca_proto = {
1810 .init_speed = 115200,
1811 .oper_speed = 3000000,
1817 .enqueue = qca_enqueue,
1818 .dequeue = qca_dequeue,
1821 static const struct qca_device_data qca_soc_data_wcn3990 = {
1822 .soc_type = QCA_WCN3990,
1823 .vregs = (struct qca_vreg []) {
1826 { "vddrf", 300000 },
1827 { "vddch0", 450000 },
1832 static const struct qca_device_data qca_soc_data_wcn3991 = {
1833 .soc_type = QCA_WCN3991,
1834 .vregs = (struct qca_vreg []) {
1837 { "vddrf", 300000 },
1838 { "vddch0", 450000 },
1841 .capabilities = QCA_CAP_WIDEBAND_SPEECH | QCA_CAP_VALID_LE_STATES,
1844 static const struct qca_device_data qca_soc_data_wcn3998 = {
1845 .soc_type = QCA_WCN3998,
1846 .vregs = (struct qca_vreg []) {
1849 { "vddrf", 300000 },
1850 { "vddch0", 450000 },
1855 static const struct qca_device_data qca_soc_data_qca6390 = {
1856 .soc_type = QCA_QCA6390,
1860 static const struct qca_device_data qca_soc_data_wcn6750 = {
1861 .soc_type = QCA_WCN6750,
1862 .vregs = (struct qca_vreg []) {
1864 { "vddaon", 26000 },
1865 { "vddbtcxmx", 126000 },
1866 { "vddrfacmn", 12500 },
1867 { "vddrfa0p8", 102000 },
1868 { "vddrfa1p7", 302000 },
1869 { "vddrfa1p2", 257000 },
1870 { "vddrfa2p2", 1700000 },
1874 .capabilities = QCA_CAP_WIDEBAND_SPEECH | QCA_CAP_VALID_LE_STATES,
1877 static void qca_power_shutdown(struct hci_uart *hu)
1879 struct qca_serdev *qcadev;
1880 struct qca_data *qca = hu->priv;
1881 unsigned long flags;
1882 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1885 /* From this point we go into power off state. But serial port is
1886 * still open, stop queueing the IBS data and flush all the buffered
1889 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
1890 set_bit(QCA_IBS_DISABLED, &qca->flags);
1892 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
1894 /* Non-serdev device usually is powered by external power
1895 * and don't need additional action in driver for power down
1900 qcadev = serdev_device_get_drvdata(hu->serdev);
1902 if (qca_is_wcn399x(soc_type)) {
1903 host_set_baudrate(hu, 2400);
1904 qca_send_power_pulse(hu, false);
1905 qca_regulator_disable(qcadev);
1906 } else if (soc_type == QCA_WCN6750) {
1907 gpiod_set_value_cansleep(qcadev->bt_en, 0);
1909 qca_regulator_disable(qcadev);
1910 if (qcadev->sw_ctrl) {
1911 sw_ctrl_state = gpiod_get_value_cansleep(qcadev->sw_ctrl);
1912 bt_dev_dbg(hu->hdev, "SW_CTRL is %d", sw_ctrl_state);
1914 } else if (qcadev->bt_en) {
1915 gpiod_set_value_cansleep(qcadev->bt_en, 0);
1918 set_bit(QCA_BT_OFF, &qca->flags);
1921 static int qca_power_off(struct hci_dev *hdev)
1923 struct hci_uart *hu = hci_get_drvdata(hdev);
1924 struct qca_data *qca = hu->priv;
1925 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1927 hu->hdev->hw_error = NULL;
1928 hu->hdev->cmd_timeout = NULL;
1930 del_timer_sync(&qca->wake_retrans_timer);
1931 del_timer_sync(&qca->tx_idle_timer);
1933 /* Stop sending shutdown command if soc crashes. */
1934 if (soc_type != QCA_ROME
1935 && qca->memdump_state == QCA_MEMDUMP_IDLE) {
1936 qca_send_pre_shutdown_cmd(hdev);
1937 usleep_range(8000, 10000);
1940 qca_power_shutdown(hu);
1944 static int qca_regulator_enable(struct qca_serdev *qcadev)
1946 struct qca_power *power = qcadev->bt_power;
1949 /* Already enabled */
1950 if (power->vregs_on)
1953 BT_DBG("enabling %d regulators)", power->num_vregs);
1955 ret = regulator_bulk_enable(power->num_vregs, power->vreg_bulk);
1959 power->vregs_on = true;
1961 ret = clk_prepare_enable(qcadev->susclk);
1963 qca_regulator_disable(qcadev);
1968 static void qca_regulator_disable(struct qca_serdev *qcadev)
1970 struct qca_power *power;
1975 power = qcadev->bt_power;
1977 /* Already disabled? */
1978 if (!power->vregs_on)
1981 regulator_bulk_disable(power->num_vregs, power->vreg_bulk);
1982 power->vregs_on = false;
1984 clk_disable_unprepare(qcadev->susclk);
1987 static int qca_init_regulators(struct qca_power *qca,
1988 const struct qca_vreg *vregs, size_t num_vregs)
1990 struct regulator_bulk_data *bulk;
1994 bulk = devm_kcalloc(qca->dev, num_vregs, sizeof(*bulk), GFP_KERNEL);
1998 for (i = 0; i < num_vregs; i++)
1999 bulk[i].supply = vregs[i].name;
2001 ret = devm_regulator_bulk_get(qca->dev, num_vregs, bulk);
2005 for (i = 0; i < num_vregs; i++) {
2006 ret = regulator_set_load(bulk[i].consumer, vregs[i].load_uA);
2011 qca->vreg_bulk = bulk;
2012 qca->num_vregs = num_vregs;
2017 static int qca_serdev_probe(struct serdev_device *serdev)
2019 struct qca_serdev *qcadev;
2020 struct hci_dev *hdev;
2021 const struct qca_device_data *data;
2023 bool power_ctrl_enabled = true;
2025 qcadev = devm_kzalloc(&serdev->dev, sizeof(*qcadev), GFP_KERNEL);
2029 qcadev->serdev_hu.serdev = serdev;
2030 data = device_get_match_data(&serdev->dev);
2031 serdev_device_set_drvdata(serdev, qcadev);
2032 device_property_read_string(&serdev->dev, "firmware-name",
2033 &qcadev->firmware_name);
2034 device_property_read_u32(&serdev->dev, "max-speed",
2035 &qcadev->oper_speed);
2036 if (!qcadev->oper_speed)
2037 BT_DBG("UART will pick default operating speed");
2040 (qca_is_wcn399x(data->soc_type) ||
2041 qca_is_wcn6750(data->soc_type))) {
2042 qcadev->btsoc_type = data->soc_type;
2043 qcadev->bt_power = devm_kzalloc(&serdev->dev,
2044 sizeof(struct qca_power),
2046 if (!qcadev->bt_power)
2049 qcadev->bt_power->dev = &serdev->dev;
2050 err = qca_init_regulators(qcadev->bt_power, data->vregs,
2053 BT_ERR("Failed to init regulators:%d", err);
2057 qcadev->bt_power->vregs_on = false;
2059 qcadev->bt_en = devm_gpiod_get_optional(&serdev->dev, "enable",
2061 if (IS_ERR_OR_NULL(qcadev->bt_en) && data->soc_type == QCA_WCN6750) {
2062 dev_err(&serdev->dev, "failed to acquire BT_EN gpio\n");
2063 power_ctrl_enabled = false;
2066 qcadev->sw_ctrl = devm_gpiod_get_optional(&serdev->dev, "swctrl",
2068 if (IS_ERR_OR_NULL(qcadev->sw_ctrl) && data->soc_type == QCA_WCN6750)
2069 dev_warn(&serdev->dev, "failed to acquire SW_CTRL gpio\n");
2071 qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
2072 if (IS_ERR(qcadev->susclk)) {
2073 dev_err(&serdev->dev, "failed to acquire clk\n");
2074 return PTR_ERR(qcadev->susclk);
2077 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
2079 BT_ERR("wcn3990 serdev registration failed");
2084 qcadev->btsoc_type = data->soc_type;
2086 qcadev->btsoc_type = QCA_ROME;
2088 qcadev->bt_en = devm_gpiod_get_optional(&serdev->dev, "enable",
2090 if (IS_ERR_OR_NULL(qcadev->bt_en)) {
2091 dev_warn(&serdev->dev, "failed to acquire enable gpio\n");
2092 power_ctrl_enabled = false;
2095 qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
2096 if (IS_ERR(qcadev->susclk)) {
2097 dev_warn(&serdev->dev, "failed to acquire clk\n");
2098 return PTR_ERR(qcadev->susclk);
2100 err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ);
2104 err = clk_prepare_enable(qcadev->susclk);
2108 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
2110 BT_ERR("Rome serdev registration failed");
2111 clk_disable_unprepare(qcadev->susclk);
2116 hdev = qcadev->serdev_hu.hdev;
2118 if (power_ctrl_enabled) {
2119 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
2120 hdev->shutdown = qca_power_off;
2124 /* Wideband speech support must be set per driver since it can't
2125 * be queried via hci. Same with the valid le states quirk.
2127 if (data->capabilities & QCA_CAP_WIDEBAND_SPEECH)
2128 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED,
2131 if (data->capabilities & QCA_CAP_VALID_LE_STATES)
2132 set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
2138 static void qca_serdev_remove(struct serdev_device *serdev)
2140 struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
2141 struct qca_power *power = qcadev->bt_power;
2143 if ((qca_is_wcn399x(qcadev->btsoc_type) ||
2144 qca_is_wcn6750(qcadev->btsoc_type)) &&
2146 qca_power_shutdown(&qcadev->serdev_hu);
2147 else if (qcadev->susclk)
2148 clk_disable_unprepare(qcadev->susclk);
2150 hci_uart_unregister_device(&qcadev->serdev_hu);
2153 static void qca_serdev_shutdown(struct device *dev)
2156 int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
2157 struct serdev_device *serdev = to_serdev_device(dev);
2158 struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
2159 const u8 ibs_wake_cmd[] = { 0xFD };
2160 const u8 edl_reset_soc_cmd[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
2162 if (qcadev->btsoc_type == QCA_QCA6390) {
2163 serdev_device_write_flush(serdev);
2164 ret = serdev_device_write_buf(serdev, ibs_wake_cmd,
2165 sizeof(ibs_wake_cmd));
2167 BT_ERR("QCA send IBS_WAKE_IND error: %d", ret);
2170 serdev_device_wait_until_sent(serdev, timeout);
2171 usleep_range(8000, 10000);
2173 serdev_device_write_flush(serdev);
2174 ret = serdev_device_write_buf(serdev, edl_reset_soc_cmd,
2175 sizeof(edl_reset_soc_cmd));
2177 BT_ERR("QCA send EDL_RESET_REQ error: %d", ret);
2180 serdev_device_wait_until_sent(serdev, timeout);
2181 usleep_range(8000, 10000);
2185 static int __maybe_unused qca_suspend(struct device *dev)
2187 struct serdev_device *serdev = to_serdev_device(dev);
2188 struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
2189 struct hci_uart *hu = &qcadev->serdev_hu;
2190 struct qca_data *qca = hu->priv;
2191 unsigned long flags;
2192 bool tx_pending = false;
2195 u32 wait_timeout = 0;
2197 set_bit(QCA_SUSPENDING, &qca->flags);
2199 /* if BT SoC is running with default firmware then it does not
2200 * support in-band sleep
2202 if (test_bit(QCA_ROM_FW, &qca->flags))
2205 /* During SSR after memory dump collection, controller will be
2206 * powered off and then powered on.If controller is powered off
2207 * during SSR then we should wait until SSR is completed.
2209 if (test_bit(QCA_BT_OFF, &qca->flags) &&
2210 !test_bit(QCA_SSR_TRIGGERED, &qca->flags))
2213 if (test_bit(QCA_IBS_DISABLED, &qca->flags) ||
2214 test_bit(QCA_SSR_TRIGGERED, &qca->flags)) {
2215 wait_timeout = test_bit(QCA_SSR_TRIGGERED, &qca->flags) ?
2216 IBS_DISABLE_SSR_TIMEOUT_MS :
2217 FW_DOWNLOAD_TIMEOUT_MS;
2219 /* QCA_IBS_DISABLED flag is set to true, During FW download
2220 * and during memory dump collection. It is reset to false,
2221 * After FW download complete.
2223 wait_on_bit_timeout(&qca->flags, QCA_IBS_DISABLED,
2224 TASK_UNINTERRUPTIBLE, msecs_to_jiffies(wait_timeout));
2226 if (test_bit(QCA_IBS_DISABLED, &qca->flags)) {
2227 bt_dev_err(hu->hdev, "SSR or FW download time out");
2233 cancel_work_sync(&qca->ws_awake_device);
2234 cancel_work_sync(&qca->ws_awake_rx);
2236 spin_lock_irqsave_nested(&qca->hci_ibs_lock,
2237 flags, SINGLE_DEPTH_NESTING);
2239 switch (qca->tx_ibs_state) {
2240 case HCI_IBS_TX_WAKING:
2241 del_timer(&qca->wake_retrans_timer);
2243 case HCI_IBS_TX_AWAKE:
2244 del_timer(&qca->tx_idle_timer);
2246 serdev_device_write_flush(hu->serdev);
2247 cmd = HCI_IBS_SLEEP_IND;
2248 ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
2251 BT_ERR("Failed to send SLEEP to device");
2255 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
2256 qca->ibs_sent_slps++;
2260 case HCI_IBS_TX_ASLEEP:
2264 BT_ERR("Spurious tx state %d", qca->tx_ibs_state);
2269 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
2275 serdev_device_wait_until_sent(hu->serdev,
2276 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS));
2277 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF, hu);
2280 /* Wait for HCI_IBS_SLEEP_IND sent by device to indicate its Tx is going
2281 * to sleep, so that the packet does not wake the system later.
2283 ret = wait_event_interruptible_timeout(qca->suspend_wait_q,
2284 qca->rx_ibs_state == HCI_IBS_RX_ASLEEP,
2285 msecs_to_jiffies(IBS_BTSOC_TX_IDLE_TIMEOUT_MS));
2294 clear_bit(QCA_SUSPENDING, &qca->flags);
2299 static int __maybe_unused qca_resume(struct device *dev)
2301 struct serdev_device *serdev = to_serdev_device(dev);
2302 struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
2303 struct hci_uart *hu = &qcadev->serdev_hu;
2304 struct qca_data *qca = hu->priv;
2306 clear_bit(QCA_SUSPENDING, &qca->flags);
2311 static SIMPLE_DEV_PM_OPS(qca_pm_ops, qca_suspend, qca_resume);
2314 static const struct of_device_id qca_bluetooth_of_match[] = {
2315 { .compatible = "qcom,qca6174-bt" },
2316 { .compatible = "qcom,qca6390-bt", .data = &qca_soc_data_qca6390},
2317 { .compatible = "qcom,qca9377-bt" },
2318 { .compatible = "qcom,wcn3990-bt", .data = &qca_soc_data_wcn3990},
2319 { .compatible = "qcom,wcn3991-bt", .data = &qca_soc_data_wcn3991},
2320 { .compatible = "qcom,wcn3998-bt", .data = &qca_soc_data_wcn3998},
2321 { .compatible = "qcom,wcn6750-bt", .data = &qca_soc_data_wcn6750},
2324 MODULE_DEVICE_TABLE(of, qca_bluetooth_of_match);
2328 static const struct acpi_device_id qca_bluetooth_acpi_match[] = {
2329 { "QCOM6390", (kernel_ulong_t)&qca_soc_data_qca6390 },
2330 { "DLA16390", (kernel_ulong_t)&qca_soc_data_qca6390 },
2331 { "DLB16390", (kernel_ulong_t)&qca_soc_data_qca6390 },
2332 { "DLB26390", (kernel_ulong_t)&qca_soc_data_qca6390 },
2335 MODULE_DEVICE_TABLE(acpi, qca_bluetooth_acpi_match);
2339 static struct serdev_device_driver qca_serdev_driver = {
2340 .probe = qca_serdev_probe,
2341 .remove = qca_serdev_remove,
2343 .name = "hci_uart_qca",
2344 .of_match_table = of_match_ptr(qca_bluetooth_of_match),
2345 .acpi_match_table = ACPI_PTR(qca_bluetooth_acpi_match),
2346 .shutdown = qca_serdev_shutdown,
2351 int __init qca_init(void)
2353 serdev_device_driver_register(&qca_serdev_driver);
2355 return hci_uart_register_proto(&qca_proto);
2358 int __exit qca_deinit(void)
2360 serdev_device_driver_unregister(&qca_serdev_driver);
2362 return hci_uart_unregister_proto(&qca_proto);