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 (MEMDUMP_TIMEOUT_MS + 1000)
54 #define FW_DOWNLOAD_TIMEOUT_MS 3000
57 #define SUSCLK_RATE_32KHZ 32768
59 /* Controller debug log header */
60 #define QCA_DEBUG_HANDLE 0x2EDC
62 /* max retry count when init fails */
63 #define MAX_INIT_RETRIES 3
65 /* Controller dump header */
66 #define QCA_SSR_DUMP_HANDLE 0x0108
67 #define QCA_DUMP_PACKET_SIZE 255
68 #define QCA_LAST_SEQUENCE_NUM 0xFFFF
69 #define QCA_CRASHBYTE_PACKET_LEN 1096
70 #define QCA_MEMDUMP_BYTE 0xFB
74 QCA_DROP_VENDOR_EVENT
,
76 QCA_MEMDUMP_COLLECTION
,
82 enum qca_capabilities
{
83 QCA_CAP_WIDEBAND_SPEECH
= BIT(0),
84 QCA_CAP_VALID_LE_STATES
= BIT(1),
87 /* HCI_IBS transmit side sleep protocol states */
94 /* HCI_IBS receive side sleep protocol states */
100 /* HCI_IBS transmit and receive side clock state vote */
101 enum hci_ibs_clock_state_vote
{
102 HCI_IBS_VOTE_STATS_UPDATE
,
103 HCI_IBS_TX_VOTE_CLOCK_ON
,
104 HCI_IBS_TX_VOTE_CLOCK_OFF
,
105 HCI_IBS_RX_VOTE_CLOCK_ON
,
106 HCI_IBS_RX_VOTE_CLOCK_OFF
,
109 /* Controller memory dump states */
110 enum qca_memdump_states
{
112 QCA_MEMDUMP_COLLECTING
,
113 QCA_MEMDUMP_COLLECTED
,
117 struct qca_memdump_data
{
118 char *memdump_buf_head
;
119 char *memdump_buf_tail
;
125 struct qca_memdump_event_hdr
{
134 struct qca_dump_size
{
140 struct sk_buff
*rx_skb
;
141 struct sk_buff_head txq
;
142 struct sk_buff_head tx_wait_q
; /* HCI_IBS wait queue */
143 struct sk_buff_head rx_memdump_q
; /* Memdump wait queue */
144 spinlock_t hci_ibs_lock
; /* HCI_IBS state lock */
145 u8 tx_ibs_state
; /* HCI_IBS transmit side power state*/
146 u8 rx_ibs_state
; /* HCI_IBS receive side power state */
147 bool tx_vote
; /* Clock must be on for TX */
148 bool rx_vote
; /* Clock must be on for RX */
149 struct timer_list tx_idle_timer
;
151 struct timer_list wake_retrans_timer
;
153 struct workqueue_struct
*workqueue
;
154 struct work_struct ws_awake_rx
;
155 struct work_struct ws_awake_device
;
156 struct work_struct ws_rx_vote_off
;
157 struct work_struct ws_tx_vote_off
;
158 struct work_struct ctrl_memdump_evt
;
159 struct delayed_work ctrl_memdump_timeout
;
160 struct qca_memdump_data
*qca_memdump
;
162 struct completion drop_ev_comp
;
163 wait_queue_head_t suspend_wait_q
;
164 enum qca_memdump_states memdump_state
;
165 struct mutex hci_memdump_lock
;
167 /* For debugging purpose */
185 enum qca_speed_type
{
191 * Voltage regulator information required for configuring the
192 * QCA Bluetooth chipset
196 unsigned int load_uA
;
199 struct qca_device_data
{
200 enum qca_btsoc_type soc_type
;
201 struct qca_vreg
*vregs
;
203 uint32_t capabilities
;
207 * Platform data for the QCA Bluetooth power driver.
211 struct regulator_bulk_data
*vreg_bulk
;
217 struct hci_uart serdev_hu
;
218 struct gpio_desc
*bt_en
;
220 enum qca_btsoc_type btsoc_type
;
221 struct qca_power
*bt_power
;
224 const char *firmware_name
;
227 static int qca_regulator_enable(struct qca_serdev
*qcadev
);
228 static void qca_regulator_disable(struct qca_serdev
*qcadev
);
229 static void qca_power_shutdown(struct hci_uart
*hu
);
230 static int qca_power_off(struct hci_dev
*hdev
);
231 static void qca_controller_memdump(struct work_struct
*work
);
233 static enum qca_btsoc_type
qca_soc_type(struct hci_uart
*hu
)
235 enum qca_btsoc_type soc_type
;
238 struct qca_serdev
*qsd
= serdev_device_get_drvdata(hu
->serdev
);
240 soc_type
= qsd
->btsoc_type
;
248 static const char *qca_get_firmware_name(struct hci_uart
*hu
)
251 struct qca_serdev
*qsd
= serdev_device_get_drvdata(hu
->serdev
);
253 return qsd
->firmware_name
;
259 static void __serial_clock_on(struct tty_struct
*tty
)
261 /* TODO: Some chipset requires to enable UART clock on client
262 * side to save power consumption or manual work is required.
263 * Please put your code to control UART clock here if needed
267 static void __serial_clock_off(struct tty_struct
*tty
)
269 /* TODO: Some chipset requires to disable UART clock on client
270 * side to save power consumption or manual work is required.
271 * Please put your code to control UART clock off here if needed
275 /* serial_clock_vote needs to be called with the ibs lock held */
276 static void serial_clock_vote(unsigned long vote
, struct hci_uart
*hu
)
278 struct qca_data
*qca
= hu
->priv
;
281 bool old_vote
= (qca
->tx_vote
| qca
->rx_vote
);
285 case HCI_IBS_VOTE_STATS_UPDATE
:
286 diff
= jiffies_to_msecs(jiffies
- qca
->vote_last_jif
);
289 qca
->vote_off_ms
+= diff
;
291 qca
->vote_on_ms
+= diff
;
294 case HCI_IBS_TX_VOTE_CLOCK_ON
:
299 case HCI_IBS_RX_VOTE_CLOCK_ON
:
304 case HCI_IBS_TX_VOTE_CLOCK_OFF
:
305 qca
->tx_vote
= false;
309 case HCI_IBS_RX_VOTE_CLOCK_OFF
:
310 qca
->rx_vote
= false;
315 BT_ERR("Voting irregularity");
319 new_vote
= qca
->rx_vote
| qca
->tx_vote
;
321 if (new_vote
!= old_vote
) {
323 __serial_clock_on(hu
->tty
);
325 __serial_clock_off(hu
->tty
);
327 BT_DBG("Vote serial clock %s(%s)", new_vote
? "true" : "false",
328 vote
? "true" : "false");
330 diff
= jiffies_to_msecs(jiffies
- qca
->vote_last_jif
);
334 qca
->vote_off_ms
+= diff
;
337 qca
->vote_on_ms
+= diff
;
339 qca
->vote_last_jif
= jiffies
;
343 /* Builds and sends an HCI_IBS command packet.
344 * These are very simple packets with only 1 cmd byte.
346 static int send_hci_ibs_cmd(u8 cmd
, struct hci_uart
*hu
)
349 struct sk_buff
*skb
= NULL
;
350 struct qca_data
*qca
= hu
->priv
;
352 BT_DBG("hu %p send hci ibs cmd 0x%x", hu
, cmd
);
354 skb
= bt_skb_alloc(1, GFP_ATOMIC
);
356 BT_ERR("Failed to allocate memory for HCI_IBS packet");
360 /* Assign HCI_IBS type */
361 skb_put_u8(skb
, cmd
);
363 skb_queue_tail(&qca
->txq
, skb
);
368 static void qca_wq_awake_device(struct work_struct
*work
)
370 struct qca_data
*qca
= container_of(work
, struct qca_data
,
372 struct hci_uart
*hu
= qca
->hu
;
373 unsigned long retrans_delay
;
376 BT_DBG("hu %p wq awake device", hu
);
378 /* Vote for serial clock */
379 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_ON
, hu
);
381 spin_lock_irqsave(&qca
->hci_ibs_lock
, flags
);
383 /* Send wake indication to device */
384 if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND
, hu
) < 0)
385 BT_ERR("Failed to send WAKE to device");
387 qca
->ibs_sent_wakes
++;
389 /* Start retransmit timer */
390 retrans_delay
= msecs_to_jiffies(qca
->wake_retrans
);
391 mod_timer(&qca
->wake_retrans_timer
, jiffies
+ retrans_delay
);
393 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
395 /* Actually send the packets */
396 hci_uart_tx_wakeup(hu
);
399 static void qca_wq_awake_rx(struct work_struct
*work
)
401 struct qca_data
*qca
= container_of(work
, struct qca_data
,
403 struct hci_uart
*hu
= qca
->hu
;
406 BT_DBG("hu %p wq awake rx", hu
);
408 serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_ON
, hu
);
410 spin_lock_irqsave(&qca
->hci_ibs_lock
, flags
);
411 qca
->rx_ibs_state
= HCI_IBS_RX_AWAKE
;
413 /* Always acknowledge device wake up,
414 * sending IBS message doesn't count as TX ON.
416 if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK
, hu
) < 0)
417 BT_ERR("Failed to acknowledge device wake up");
419 qca
->ibs_sent_wacks
++;
421 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
423 /* Actually send the packets */
424 hci_uart_tx_wakeup(hu
);
427 static void qca_wq_serial_rx_clock_vote_off(struct work_struct
*work
)
429 struct qca_data
*qca
= container_of(work
, struct qca_data
,
431 struct hci_uart
*hu
= qca
->hu
;
433 BT_DBG("hu %p rx clock vote off", hu
);
435 serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_OFF
, hu
);
438 static void qca_wq_serial_tx_clock_vote_off(struct work_struct
*work
)
440 struct qca_data
*qca
= container_of(work
, struct qca_data
,
442 struct hci_uart
*hu
= qca
->hu
;
444 BT_DBG("hu %p tx clock vote off", hu
);
446 /* Run HCI tx handling unlocked */
447 hci_uart_tx_wakeup(hu
);
449 /* Now that message queued to tty driver, vote for tty clocks off.
450 * It is up to the tty driver to pend the clocks off until tx done.
452 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF
, hu
);
455 static void hci_ibs_tx_idle_timeout(struct timer_list
*t
)
457 struct qca_data
*qca
= from_timer(qca
, t
, tx_idle_timer
);
458 struct hci_uart
*hu
= qca
->hu
;
461 BT_DBG("hu %p idle timeout in %d state", hu
, qca
->tx_ibs_state
);
463 spin_lock_irqsave_nested(&qca
->hci_ibs_lock
,
464 flags
, SINGLE_DEPTH_NESTING
);
466 switch (qca
->tx_ibs_state
) {
467 case HCI_IBS_TX_AWAKE
:
468 /* TX_IDLE, go to SLEEP */
469 if (send_hci_ibs_cmd(HCI_IBS_SLEEP_IND
, hu
) < 0) {
470 BT_ERR("Failed to send SLEEP to device");
473 qca
->tx_ibs_state
= HCI_IBS_TX_ASLEEP
;
474 qca
->ibs_sent_slps
++;
475 queue_work(qca
->workqueue
, &qca
->ws_tx_vote_off
);
478 case HCI_IBS_TX_ASLEEP
:
479 case HCI_IBS_TX_WAKING
:
481 BT_ERR("Spurious timeout tx state %d", qca
->tx_ibs_state
);
485 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
488 static void hci_ibs_wake_retrans_timeout(struct timer_list
*t
)
490 struct qca_data
*qca
= from_timer(qca
, t
, wake_retrans_timer
);
491 struct hci_uart
*hu
= qca
->hu
;
492 unsigned long flags
, retrans_delay
;
493 bool retransmit
= false;
495 BT_DBG("hu %p wake retransmit timeout in %d state",
496 hu
, qca
->tx_ibs_state
);
498 spin_lock_irqsave_nested(&qca
->hci_ibs_lock
,
499 flags
, SINGLE_DEPTH_NESTING
);
501 /* Don't retransmit the HCI_IBS_WAKE_IND when suspending. */
502 if (test_bit(QCA_SUSPENDING
, &qca
->flags
)) {
503 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
507 switch (qca
->tx_ibs_state
) {
508 case HCI_IBS_TX_WAKING
:
509 /* No WAKE_ACK, retransmit WAKE */
511 if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND
, hu
) < 0) {
512 BT_ERR("Failed to acknowledge device wake up");
515 qca
->ibs_sent_wakes
++;
516 retrans_delay
= msecs_to_jiffies(qca
->wake_retrans
);
517 mod_timer(&qca
->wake_retrans_timer
, jiffies
+ retrans_delay
);
520 case HCI_IBS_TX_ASLEEP
:
521 case HCI_IBS_TX_AWAKE
:
523 BT_ERR("Spurious timeout tx state %d", qca
->tx_ibs_state
);
527 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
530 hci_uart_tx_wakeup(hu
);
534 static void qca_controller_memdump_timeout(struct work_struct
*work
)
536 struct qca_data
*qca
= container_of(work
, struct qca_data
,
537 ctrl_memdump_timeout
.work
);
538 struct hci_uart
*hu
= qca
->hu
;
540 mutex_lock(&qca
->hci_memdump_lock
);
541 if (test_bit(QCA_MEMDUMP_COLLECTION
, &qca
->flags
)) {
542 qca
->memdump_state
= QCA_MEMDUMP_TIMEOUT
;
543 if (!test_bit(QCA_HW_ERROR_EVENT
, &qca
->flags
)) {
544 /* Inject hw error event to reset the device
547 hci_reset_dev(hu
->hdev
);
551 mutex_unlock(&qca
->hci_memdump_lock
);
555 /* Initialize protocol */
556 static int qca_open(struct hci_uart
*hu
)
558 struct qca_serdev
*qcadev
;
559 struct qca_data
*qca
;
561 BT_DBG("hu %p qca_open", hu
);
563 if (!hci_uart_has_flow_control(hu
))
566 qca
= kzalloc(sizeof(struct qca_data
), GFP_KERNEL
);
570 skb_queue_head_init(&qca
->txq
);
571 skb_queue_head_init(&qca
->tx_wait_q
);
572 skb_queue_head_init(&qca
->rx_memdump_q
);
573 spin_lock_init(&qca
->hci_ibs_lock
);
574 mutex_init(&qca
->hci_memdump_lock
);
575 qca
->workqueue
= alloc_ordered_workqueue("qca_wq", 0);
576 if (!qca
->workqueue
) {
577 BT_ERR("QCA Workqueue not initialized properly");
582 INIT_WORK(&qca
->ws_awake_rx
, qca_wq_awake_rx
);
583 INIT_WORK(&qca
->ws_awake_device
, qca_wq_awake_device
);
584 INIT_WORK(&qca
->ws_rx_vote_off
, qca_wq_serial_rx_clock_vote_off
);
585 INIT_WORK(&qca
->ws_tx_vote_off
, qca_wq_serial_tx_clock_vote_off
);
586 INIT_WORK(&qca
->ctrl_memdump_evt
, qca_controller_memdump
);
587 INIT_DELAYED_WORK(&qca
->ctrl_memdump_timeout
,
588 qca_controller_memdump_timeout
);
589 init_waitqueue_head(&qca
->suspend_wait_q
);
592 init_completion(&qca
->drop_ev_comp
);
594 /* Assume we start with both sides asleep -- extra wakes OK */
595 qca
->tx_ibs_state
= HCI_IBS_TX_ASLEEP
;
596 qca
->rx_ibs_state
= HCI_IBS_RX_ASLEEP
;
598 qca
->vote_last_jif
= jiffies
;
603 qcadev
= serdev_device_get_drvdata(hu
->serdev
);
605 if (qca_is_wcn399x(qcadev
->btsoc_type
))
606 hu
->init_speed
= qcadev
->init_speed
;
608 if (qcadev
->oper_speed
)
609 hu
->oper_speed
= qcadev
->oper_speed
;
612 timer_setup(&qca
->wake_retrans_timer
, hci_ibs_wake_retrans_timeout
, 0);
613 qca
->wake_retrans
= IBS_WAKE_RETRANS_TIMEOUT_MS
;
615 timer_setup(&qca
->tx_idle_timer
, hci_ibs_tx_idle_timeout
, 0);
616 qca
->tx_idle_delay
= IBS_HOST_TX_IDLE_TIMEOUT_MS
;
618 BT_DBG("HCI_UART_QCA open, tx_idle_delay=%u, wake_retrans=%u",
619 qca
->tx_idle_delay
, qca
->wake_retrans
);
624 static void qca_debugfs_init(struct hci_dev
*hdev
)
626 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
627 struct qca_data
*qca
= hu
->priv
;
628 struct dentry
*ibs_dir
;
634 ibs_dir
= debugfs_create_dir("ibs", hdev
->debugfs
);
638 debugfs_create_u8("tx_ibs_state", mode
, ibs_dir
, &qca
->tx_ibs_state
);
639 debugfs_create_u8("rx_ibs_state", mode
, ibs_dir
, &qca
->rx_ibs_state
);
640 debugfs_create_u64("ibs_sent_sleeps", mode
, ibs_dir
,
641 &qca
->ibs_sent_slps
);
642 debugfs_create_u64("ibs_sent_wakes", mode
, ibs_dir
,
643 &qca
->ibs_sent_wakes
);
644 debugfs_create_u64("ibs_sent_wake_acks", mode
, ibs_dir
,
645 &qca
->ibs_sent_wacks
);
646 debugfs_create_u64("ibs_recv_sleeps", mode
, ibs_dir
,
647 &qca
->ibs_recv_slps
);
648 debugfs_create_u64("ibs_recv_wakes", mode
, ibs_dir
,
649 &qca
->ibs_recv_wakes
);
650 debugfs_create_u64("ibs_recv_wake_acks", mode
, ibs_dir
,
651 &qca
->ibs_recv_wacks
);
652 debugfs_create_bool("tx_vote", mode
, ibs_dir
, &qca
->tx_vote
);
653 debugfs_create_u64("tx_votes_on", mode
, ibs_dir
, &qca
->tx_votes_on
);
654 debugfs_create_u64("tx_votes_off", mode
, ibs_dir
, &qca
->tx_votes_off
);
655 debugfs_create_bool("rx_vote", mode
, ibs_dir
, &qca
->rx_vote
);
656 debugfs_create_u64("rx_votes_on", mode
, ibs_dir
, &qca
->rx_votes_on
);
657 debugfs_create_u64("rx_votes_off", mode
, ibs_dir
, &qca
->rx_votes_off
);
658 debugfs_create_u64("votes_on", mode
, ibs_dir
, &qca
->votes_on
);
659 debugfs_create_u64("votes_off", mode
, ibs_dir
, &qca
->votes_off
);
660 debugfs_create_u32("vote_on_ms", mode
, ibs_dir
, &qca
->vote_on_ms
);
661 debugfs_create_u32("vote_off_ms", mode
, ibs_dir
, &qca
->vote_off_ms
);
665 debugfs_create_u32("wake_retrans", mode
, ibs_dir
, &qca
->wake_retrans
);
666 debugfs_create_u32("tx_idle_delay", mode
, ibs_dir
,
667 &qca
->tx_idle_delay
);
670 /* Flush protocol data */
671 static int qca_flush(struct hci_uart
*hu
)
673 struct qca_data
*qca
= hu
->priv
;
675 BT_DBG("hu %p qca flush", hu
);
677 skb_queue_purge(&qca
->tx_wait_q
);
678 skb_queue_purge(&qca
->txq
);
684 static int qca_close(struct hci_uart
*hu
)
686 struct qca_data
*qca
= hu
->priv
;
688 BT_DBG("hu %p qca close", hu
);
690 serial_clock_vote(HCI_IBS_VOTE_STATS_UPDATE
, hu
);
692 skb_queue_purge(&qca
->tx_wait_q
);
693 skb_queue_purge(&qca
->txq
);
694 skb_queue_purge(&qca
->rx_memdump_q
);
695 del_timer(&qca
->tx_idle_timer
);
696 del_timer(&qca
->wake_retrans_timer
);
697 destroy_workqueue(qca
->workqueue
);
700 kfree_skb(qca
->rx_skb
);
709 /* Called upon a wake-up-indication from the device.
711 static void device_want_to_wakeup(struct hci_uart
*hu
)
714 struct qca_data
*qca
= hu
->priv
;
716 BT_DBG("hu %p want to wake up", hu
);
718 spin_lock_irqsave(&qca
->hci_ibs_lock
, flags
);
720 qca
->ibs_recv_wakes
++;
722 /* Don't wake the rx up when suspending. */
723 if (test_bit(QCA_SUSPENDING
, &qca
->flags
)) {
724 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
728 switch (qca
->rx_ibs_state
) {
729 case HCI_IBS_RX_ASLEEP
:
730 /* Make sure clock is on - we may have turned clock off since
731 * receiving the wake up indicator awake rx clock.
733 queue_work(qca
->workqueue
, &qca
->ws_awake_rx
);
734 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
737 case HCI_IBS_RX_AWAKE
:
738 /* Always acknowledge device wake up,
739 * sending IBS message doesn't count as TX ON.
741 if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK
, hu
) < 0) {
742 BT_ERR("Failed to acknowledge device wake up");
745 qca
->ibs_sent_wacks
++;
749 /* Any other state is illegal */
750 BT_ERR("Received HCI_IBS_WAKE_IND in rx state %d",
755 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
757 /* Actually send the packets */
758 hci_uart_tx_wakeup(hu
);
761 /* Called upon a sleep-indication from the device.
763 static void device_want_to_sleep(struct hci_uart
*hu
)
766 struct qca_data
*qca
= hu
->priv
;
768 BT_DBG("hu %p want to sleep in %d state", hu
, qca
->rx_ibs_state
);
770 spin_lock_irqsave(&qca
->hci_ibs_lock
, flags
);
772 qca
->ibs_recv_slps
++;
774 switch (qca
->rx_ibs_state
) {
775 case HCI_IBS_RX_AWAKE
:
777 qca
->rx_ibs_state
= HCI_IBS_RX_ASLEEP
;
778 /* Vote off rx clock under workqueue */
779 queue_work(qca
->workqueue
, &qca
->ws_rx_vote_off
);
782 case HCI_IBS_RX_ASLEEP
:
786 /* Any other state is illegal */
787 BT_ERR("Received HCI_IBS_SLEEP_IND in rx state %d",
792 wake_up_interruptible(&qca
->suspend_wait_q
);
794 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
797 /* Called upon wake-up-acknowledgement from the device
799 static void device_woke_up(struct hci_uart
*hu
)
801 unsigned long flags
, idle_delay
;
802 struct qca_data
*qca
= hu
->priv
;
803 struct sk_buff
*skb
= NULL
;
805 BT_DBG("hu %p woke up", hu
);
807 spin_lock_irqsave(&qca
->hci_ibs_lock
, flags
);
809 qca
->ibs_recv_wacks
++;
811 /* Don't react to the wake-up-acknowledgment when suspending. */
812 if (test_bit(QCA_SUSPENDING
, &qca
->flags
)) {
813 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
817 switch (qca
->tx_ibs_state
) {
818 case HCI_IBS_TX_AWAKE
:
819 /* Expect one if we send 2 WAKEs */
820 BT_DBG("Received HCI_IBS_WAKE_ACK in tx state %d",
824 case HCI_IBS_TX_WAKING
:
825 /* Send pending packets */
826 while ((skb
= skb_dequeue(&qca
->tx_wait_q
)))
827 skb_queue_tail(&qca
->txq
, skb
);
829 /* Switch timers and change state to HCI_IBS_TX_AWAKE */
830 del_timer(&qca
->wake_retrans_timer
);
831 idle_delay
= msecs_to_jiffies(qca
->tx_idle_delay
);
832 mod_timer(&qca
->tx_idle_timer
, jiffies
+ idle_delay
);
833 qca
->tx_ibs_state
= HCI_IBS_TX_AWAKE
;
836 case HCI_IBS_TX_ASLEEP
:
838 BT_ERR("Received HCI_IBS_WAKE_ACK in tx state %d",
843 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
845 /* Actually send the packets */
846 hci_uart_tx_wakeup(hu
);
849 /* Enqueue frame for transmittion (padding, crc, etc) may be called from
850 * two simultaneous tasklets.
852 static int qca_enqueue(struct hci_uart
*hu
, struct sk_buff
*skb
)
854 unsigned long flags
= 0, idle_delay
;
855 struct qca_data
*qca
= hu
->priv
;
857 BT_DBG("hu %p qca enq skb %p tx_ibs_state %d", hu
, skb
,
860 if (test_bit(QCA_SSR_TRIGGERED
, &qca
->flags
)) {
861 /* As SSR is in progress, ignore the packets */
862 bt_dev_dbg(hu
->hdev
, "SSR is in progress");
867 /* Prepend skb with frame type */
868 memcpy(skb_push(skb
, 1), &hci_skb_pkt_type(skb
), 1);
870 spin_lock_irqsave(&qca
->hci_ibs_lock
, flags
);
872 /* Don't go to sleep in middle of patch download or
873 * Out-Of-Band(GPIOs control) sleep is selected.
874 * Don't wake the device up when suspending.
876 if (test_bit(QCA_IBS_DISABLED
, &qca
->flags
) ||
877 test_bit(QCA_SUSPENDING
, &qca
->flags
)) {
878 skb_queue_tail(&qca
->txq
, skb
);
879 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
883 /* Act according to current state */
884 switch (qca
->tx_ibs_state
) {
885 case HCI_IBS_TX_AWAKE
:
886 BT_DBG("Device awake, sending normally");
887 skb_queue_tail(&qca
->txq
, skb
);
888 idle_delay
= msecs_to_jiffies(qca
->tx_idle_delay
);
889 mod_timer(&qca
->tx_idle_timer
, jiffies
+ idle_delay
);
892 case HCI_IBS_TX_ASLEEP
:
893 BT_DBG("Device asleep, waking up and queueing packet");
894 /* Save packet for later */
895 skb_queue_tail(&qca
->tx_wait_q
, skb
);
897 qca
->tx_ibs_state
= HCI_IBS_TX_WAKING
;
898 /* Schedule a work queue to wake up device */
899 queue_work(qca
->workqueue
, &qca
->ws_awake_device
);
902 case HCI_IBS_TX_WAKING
:
903 BT_DBG("Device waking up, queueing packet");
904 /* Transient state; just keep packet for later */
905 skb_queue_tail(&qca
->tx_wait_q
, skb
);
909 BT_ERR("Illegal tx state: %d (losing packet)",
915 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
920 static int qca_ibs_sleep_ind(struct hci_dev
*hdev
, struct sk_buff
*skb
)
922 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
924 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu
, HCI_IBS_SLEEP_IND
);
926 device_want_to_sleep(hu
);
932 static int qca_ibs_wake_ind(struct hci_dev
*hdev
, struct sk_buff
*skb
)
934 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
936 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu
, HCI_IBS_WAKE_IND
);
938 device_want_to_wakeup(hu
);
944 static int qca_ibs_wake_ack(struct hci_dev
*hdev
, struct sk_buff
*skb
)
946 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
948 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu
, HCI_IBS_WAKE_ACK
);
956 static int qca_recv_acl_data(struct hci_dev
*hdev
, struct sk_buff
*skb
)
958 /* We receive debug logs from chip as an ACL packets.
959 * Instead of sending the data to ACL to decode the
960 * received data, we are pushing them to the above layers
961 * as a diagnostic packet.
963 if (get_unaligned_le16(skb
->data
) == QCA_DEBUG_HANDLE
)
964 return hci_recv_diag(hdev
, skb
);
966 return hci_recv_frame(hdev
, skb
);
969 static void qca_controller_memdump(struct work_struct
*work
)
971 struct qca_data
*qca
= container_of(work
, struct qca_data
,
973 struct hci_uart
*hu
= qca
->hu
;
975 struct qca_memdump_event_hdr
*cmd_hdr
;
976 struct qca_memdump_data
*qca_memdump
= qca
->qca_memdump
;
977 struct qca_dump_size
*dump
;
979 char nullBuff
[QCA_DUMP_PACKET_SIZE
] = { 0 };
983 enum qca_btsoc_type soc_type
= qca_soc_type(hu
);
985 while ((skb
= skb_dequeue(&qca
->rx_memdump_q
))) {
987 mutex_lock(&qca
->hci_memdump_lock
);
988 /* Skip processing the received packets if timeout detected
989 * or memdump collection completed.
991 if (qca
->memdump_state
== QCA_MEMDUMP_TIMEOUT
||
992 qca
->memdump_state
== QCA_MEMDUMP_COLLECTED
) {
993 mutex_unlock(&qca
->hci_memdump_lock
);
998 qca_memdump
= kzalloc(sizeof(struct qca_memdump_data
),
1001 mutex_unlock(&qca
->hci_memdump_lock
);
1005 qca
->qca_memdump
= qca_memdump
;
1008 qca
->memdump_state
= QCA_MEMDUMP_COLLECTING
;
1009 cmd_hdr
= (void *) skb
->data
;
1010 seq_no
= __le16_to_cpu(cmd_hdr
->seq_no
);
1011 skb_pull(skb
, sizeof(struct qca_memdump_event_hdr
));
1015 /* This is the first frame of memdump packet from
1016 * the controller, Disable IBS to recevie dump
1017 * with out any interruption, ideally time required for
1018 * the controller to send the dump is 8 seconds. let us
1019 * start timer to handle this asynchronous activity.
1021 set_bit(QCA_IBS_DISABLED
, &qca
->flags
);
1022 set_bit(QCA_MEMDUMP_COLLECTION
, &qca
->flags
);
1023 dump
= (void *) skb
->data
;
1024 dump_size
= __le32_to_cpu(dump
->dump_size
);
1026 bt_dev_err(hu
->hdev
, "Rx invalid memdump size");
1028 mutex_unlock(&qca
->hci_memdump_lock
);
1032 bt_dev_info(hu
->hdev
, "QCA collecting dump of size:%u",
1034 queue_delayed_work(qca
->workqueue
,
1035 &qca
->ctrl_memdump_timeout
,
1036 msecs_to_jiffies(MEMDUMP_TIMEOUT_MS
)
1039 skb_pull(skb
, sizeof(dump_size
));
1040 memdump_buf
= vmalloc(dump_size
);
1041 qca_memdump
->ram_dump_size
= dump_size
;
1042 qca_memdump
->memdump_buf_head
= memdump_buf
;
1043 qca_memdump
->memdump_buf_tail
= memdump_buf
;
1046 memdump_buf
= qca_memdump
->memdump_buf_tail
;
1048 /* If sequence no 0 is missed then there is no point in
1049 * accepting the other sequences.
1052 bt_dev_err(hu
->hdev
, "QCA: Discarding other packets");
1055 qca
->qca_memdump
= NULL
;
1056 mutex_unlock(&qca
->hci_memdump_lock
);
1060 /* There could be chance of missing some packets from
1061 * the controller. In such cases let us store the dummy
1062 * packets in the buffer.
1064 /* For QCA6390, controller does not lost packets but
1065 * sequence number field of packat sometimes has error
1066 * bits, so skip this checking for missing packet.
1068 while ((seq_no
> qca_memdump
->current_seq_no
+ 1) &&
1069 (soc_type
!= QCA_QCA6390
) &&
1070 seq_no
!= QCA_LAST_SEQUENCE_NUM
) {
1071 bt_dev_err(hu
->hdev
, "QCA controller missed packet:%d",
1072 qca_memdump
->current_seq_no
);
1073 rx_size
= qca_memdump
->received_dump
;
1074 rx_size
+= QCA_DUMP_PACKET_SIZE
;
1075 if (rx_size
> qca_memdump
->ram_dump_size
) {
1076 bt_dev_err(hu
->hdev
,
1077 "QCA memdump received %d, no space for missed packet",
1078 qca_memdump
->received_dump
);
1081 memcpy(memdump_buf
, nullBuff
, QCA_DUMP_PACKET_SIZE
);
1082 memdump_buf
= memdump_buf
+ QCA_DUMP_PACKET_SIZE
;
1083 qca_memdump
->received_dump
+= QCA_DUMP_PACKET_SIZE
;
1084 qca_memdump
->current_seq_no
++;
1087 rx_size
= qca_memdump
->received_dump
+ skb
->len
;
1088 if (rx_size
<= qca_memdump
->ram_dump_size
) {
1089 if ((seq_no
!= QCA_LAST_SEQUENCE_NUM
) &&
1090 (seq_no
!= qca_memdump
->current_seq_no
))
1091 bt_dev_err(hu
->hdev
,
1092 "QCA memdump unexpected packet %d",
1094 bt_dev_dbg(hu
->hdev
,
1095 "QCA memdump packet %d with length %d",
1097 memcpy(memdump_buf
, (unsigned char *)skb
->data
,
1099 memdump_buf
= memdump_buf
+ skb
->len
;
1100 qca_memdump
->memdump_buf_tail
= memdump_buf
;
1101 qca_memdump
->current_seq_no
= seq_no
+ 1;
1102 qca_memdump
->received_dump
+= skb
->len
;
1104 bt_dev_err(hu
->hdev
,
1105 "QCA memdump received %d, no space for packet %d",
1106 qca_memdump
->received_dump
, seq_no
);
1108 qca
->qca_memdump
= qca_memdump
;
1110 if (seq_no
== QCA_LAST_SEQUENCE_NUM
) {
1111 bt_dev_info(hu
->hdev
,
1112 "QCA memdump Done, received %d, total %d",
1113 qca_memdump
->received_dump
,
1114 qca_memdump
->ram_dump_size
);
1115 memdump_buf
= qca_memdump
->memdump_buf_head
;
1116 dev_coredumpv(&hu
->serdev
->dev
, memdump_buf
,
1117 qca_memdump
->received_dump
, GFP_KERNEL
);
1118 cancel_delayed_work(&qca
->ctrl_memdump_timeout
);
1119 kfree(qca
->qca_memdump
);
1120 qca
->qca_memdump
= NULL
;
1121 qca
->memdump_state
= QCA_MEMDUMP_COLLECTED
;
1122 clear_bit(QCA_MEMDUMP_COLLECTION
, &qca
->flags
);
1125 mutex_unlock(&qca
->hci_memdump_lock
);
1130 static int qca_controller_memdump_event(struct hci_dev
*hdev
,
1131 struct sk_buff
*skb
)
1133 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
1134 struct qca_data
*qca
= hu
->priv
;
1136 set_bit(QCA_SSR_TRIGGERED
, &qca
->flags
);
1137 skb_queue_tail(&qca
->rx_memdump_q
, skb
);
1138 queue_work(qca
->workqueue
, &qca
->ctrl_memdump_evt
);
1143 static int qca_recv_event(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1145 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
1146 struct qca_data
*qca
= hu
->priv
;
1148 if (test_bit(QCA_DROP_VENDOR_EVENT
, &qca
->flags
)) {
1149 struct hci_event_hdr
*hdr
= (void *)skb
->data
;
1151 /* For the WCN3990 the vendor command for a baudrate change
1152 * isn't sent as synchronous HCI command, because the
1153 * controller sends the corresponding vendor event with the
1154 * new baudrate. The event is received and properly decoded
1155 * after changing the baudrate of the host port. It needs to
1156 * be dropped, otherwise it can be misinterpreted as
1157 * response to a later firmware download command (also a
1161 if (hdr
->evt
== HCI_EV_VENDOR
)
1162 complete(&qca
->drop_ev_comp
);
1168 /* We receive chip memory dump as an event packet, With a dedicated
1169 * handler followed by a hardware error event. When this event is
1170 * received we store dump into a file before closing hci. This
1171 * dump will help in triaging the issues.
1173 if ((skb
->data
[0] == HCI_VENDOR_PKT
) &&
1174 (get_unaligned_be16(skb
->data
+ 2) == QCA_SSR_DUMP_HANDLE
))
1175 return qca_controller_memdump_event(hdev
, skb
);
1177 return hci_recv_frame(hdev
, skb
);
1180 #define QCA_IBS_SLEEP_IND_EVENT \
1181 .type = HCI_IBS_SLEEP_IND, \
1185 .maxlen = HCI_MAX_IBS_SIZE
1187 #define QCA_IBS_WAKE_IND_EVENT \
1188 .type = HCI_IBS_WAKE_IND, \
1192 .maxlen = HCI_MAX_IBS_SIZE
1194 #define QCA_IBS_WAKE_ACK_EVENT \
1195 .type = HCI_IBS_WAKE_ACK, \
1199 .maxlen = HCI_MAX_IBS_SIZE
1201 static const struct h4_recv_pkt qca_recv_pkts
[] = {
1202 { H4_RECV_ACL
, .recv
= qca_recv_acl_data
},
1203 { H4_RECV_SCO
, .recv
= hci_recv_frame
},
1204 { H4_RECV_EVENT
, .recv
= qca_recv_event
},
1205 { QCA_IBS_WAKE_IND_EVENT
, .recv
= qca_ibs_wake_ind
},
1206 { QCA_IBS_WAKE_ACK_EVENT
, .recv
= qca_ibs_wake_ack
},
1207 { QCA_IBS_SLEEP_IND_EVENT
, .recv
= qca_ibs_sleep_ind
},
1210 static int qca_recv(struct hci_uart
*hu
, const void *data
, int count
)
1212 struct qca_data
*qca
= hu
->priv
;
1214 if (!test_bit(HCI_UART_REGISTERED
, &hu
->flags
))
1217 qca
->rx_skb
= h4_recv_buf(hu
->hdev
, qca
->rx_skb
, data
, count
,
1218 qca_recv_pkts
, ARRAY_SIZE(qca_recv_pkts
));
1219 if (IS_ERR(qca
->rx_skb
)) {
1220 int err
= PTR_ERR(qca
->rx_skb
);
1221 bt_dev_err(hu
->hdev
, "Frame reassembly failed (%d)", err
);
1229 static struct sk_buff
*qca_dequeue(struct hci_uart
*hu
)
1231 struct qca_data
*qca
= hu
->priv
;
1233 return skb_dequeue(&qca
->txq
);
1236 static uint8_t qca_get_baudrate_value(int speed
)
1240 return QCA_BAUDRATE_9600
;
1242 return QCA_BAUDRATE_19200
;
1244 return QCA_BAUDRATE_38400
;
1246 return QCA_BAUDRATE_57600
;
1248 return QCA_BAUDRATE_115200
;
1250 return QCA_BAUDRATE_230400
;
1252 return QCA_BAUDRATE_460800
;
1254 return QCA_BAUDRATE_500000
;
1256 return QCA_BAUDRATE_921600
;
1258 return QCA_BAUDRATE_1000000
;
1260 return QCA_BAUDRATE_2000000
;
1262 return QCA_BAUDRATE_3000000
;
1264 return QCA_BAUDRATE_3200000
;
1266 return QCA_BAUDRATE_3500000
;
1268 return QCA_BAUDRATE_115200
;
1272 static int qca_set_baudrate(struct hci_dev
*hdev
, uint8_t baudrate
)
1274 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
1275 struct qca_data
*qca
= hu
->priv
;
1276 struct sk_buff
*skb
;
1277 u8 cmd
[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
1279 if (baudrate
> QCA_BAUDRATE_3200000
)
1284 skb
= bt_skb_alloc(sizeof(cmd
), GFP_KERNEL
);
1286 bt_dev_err(hdev
, "Failed to allocate baudrate packet");
1290 /* Assign commands to change baudrate and packet type. */
1291 skb_put_data(skb
, cmd
, sizeof(cmd
));
1292 hci_skb_pkt_type(skb
) = HCI_COMMAND_PKT
;
1294 skb_queue_tail(&qca
->txq
, skb
);
1295 hci_uart_tx_wakeup(hu
);
1297 /* Wait for the baudrate change request to be sent */
1299 while (!skb_queue_empty(&qca
->txq
))
1300 usleep_range(100, 200);
1303 serdev_device_wait_until_sent(hu
->serdev
,
1304 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS
));
1306 /* Give the controller time to process the request */
1307 if (qca_is_wcn399x(qca_soc_type(hu
)))
1308 usleep_range(1000, 10000);
1315 static inline void host_set_baudrate(struct hci_uart
*hu
, unsigned int speed
)
1318 serdev_device_set_baudrate(hu
->serdev
, speed
);
1320 hci_uart_set_baudrate(hu
, speed
);
1323 static int qca_send_power_pulse(struct hci_uart
*hu
, bool on
)
1326 int timeout
= msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS
);
1327 u8 cmd
= on
? QCA_WCN3990_POWERON_PULSE
: QCA_WCN3990_POWEROFF_PULSE
;
1329 /* These power pulses are single byte command which are sent
1330 * at required baudrate to wcn3990. On wcn3990, we have an external
1331 * circuit at Tx pin which decodes the pulse sent at specific baudrate.
1332 * For example, wcn3990 supports RF COEX antenna for both Wi-Fi/BT
1333 * and also we use the same power inputs to turn on and off for
1334 * Wi-Fi/BT. Powering up the power sources will not enable BT, until
1335 * we send a power on pulse at 115200 bps. This algorithm will help to
1336 * save power. Disabling hardware flow control is mandatory while
1337 * sending power pulses to SoC.
1339 bt_dev_dbg(hu
->hdev
, "sending power pulse %02x to controller", cmd
);
1341 serdev_device_write_flush(hu
->serdev
);
1342 hci_uart_set_flow_control(hu
, true);
1343 ret
= serdev_device_write_buf(hu
->serdev
, &cmd
, sizeof(cmd
));
1345 bt_dev_err(hu
->hdev
, "failed to send power pulse %02x", cmd
);
1349 serdev_device_wait_until_sent(hu
->serdev
, timeout
);
1350 hci_uart_set_flow_control(hu
, false);
1352 /* Give to controller time to boot/shutdown */
1356 usleep_range(1000, 10000);
1361 static unsigned int qca_get_speed(struct hci_uart
*hu
,
1362 enum qca_speed_type speed_type
)
1364 unsigned int speed
= 0;
1366 if (speed_type
== QCA_INIT_SPEED
) {
1368 speed
= hu
->init_speed
;
1369 else if (hu
->proto
->init_speed
)
1370 speed
= hu
->proto
->init_speed
;
1373 speed
= hu
->oper_speed
;
1374 else if (hu
->proto
->oper_speed
)
1375 speed
= hu
->proto
->oper_speed
;
1381 static int qca_check_speeds(struct hci_uart
*hu
)
1383 if (qca_is_wcn399x(qca_soc_type(hu
))) {
1384 if (!qca_get_speed(hu
, QCA_INIT_SPEED
) &&
1385 !qca_get_speed(hu
, QCA_OPER_SPEED
))
1388 if (!qca_get_speed(hu
, QCA_INIT_SPEED
) ||
1389 !qca_get_speed(hu
, QCA_OPER_SPEED
))
1396 static int qca_set_speed(struct hci_uart
*hu
, enum qca_speed_type speed_type
)
1398 unsigned int speed
, qca_baudrate
;
1399 struct qca_data
*qca
= hu
->priv
;
1402 if (speed_type
== QCA_INIT_SPEED
) {
1403 speed
= qca_get_speed(hu
, QCA_INIT_SPEED
);
1405 host_set_baudrate(hu
, speed
);
1407 enum qca_btsoc_type soc_type
= qca_soc_type(hu
);
1409 speed
= qca_get_speed(hu
, QCA_OPER_SPEED
);
1413 /* Disable flow control for wcn3990 to deassert RTS while
1414 * changing the baudrate of chip and host.
1416 if (qca_is_wcn399x(soc_type
))
1417 hci_uart_set_flow_control(hu
, true);
1419 if (soc_type
== QCA_WCN3990
) {
1420 reinit_completion(&qca
->drop_ev_comp
);
1421 set_bit(QCA_DROP_VENDOR_EVENT
, &qca
->flags
);
1424 qca_baudrate
= qca_get_baudrate_value(speed
);
1425 bt_dev_dbg(hu
->hdev
, "Set UART speed to %d", speed
);
1426 ret
= qca_set_baudrate(hu
->hdev
, qca_baudrate
);
1430 host_set_baudrate(hu
, speed
);
1433 if (qca_is_wcn399x(soc_type
))
1434 hci_uart_set_flow_control(hu
, false);
1436 if (soc_type
== QCA_WCN3990
) {
1437 /* Wait for the controller to send the vendor event
1438 * for the baudrate change command.
1440 if (!wait_for_completion_timeout(&qca
->drop_ev_comp
,
1441 msecs_to_jiffies(100))) {
1442 bt_dev_err(hu
->hdev
,
1443 "Failed to change controller baudrate\n");
1447 clear_bit(QCA_DROP_VENDOR_EVENT
, &qca
->flags
);
1454 static int qca_send_crashbuffer(struct hci_uart
*hu
)
1456 struct qca_data
*qca
= hu
->priv
;
1457 struct sk_buff
*skb
;
1459 skb
= bt_skb_alloc(QCA_CRASHBYTE_PACKET_LEN
, GFP_KERNEL
);
1461 bt_dev_err(hu
->hdev
, "Failed to allocate memory for skb packet");
1465 /* We forcefully crash the controller, by sending 0xfb byte for
1466 * 1024 times. We also might have chance of losing data, To be
1467 * on safer side we send 1096 bytes to the SoC.
1469 memset(skb_put(skb
, QCA_CRASHBYTE_PACKET_LEN
), QCA_MEMDUMP_BYTE
,
1470 QCA_CRASHBYTE_PACKET_LEN
);
1471 hci_skb_pkt_type(skb
) = HCI_COMMAND_PKT
;
1472 bt_dev_info(hu
->hdev
, "crash the soc to collect controller dump");
1473 skb_queue_tail(&qca
->txq
, skb
);
1474 hci_uart_tx_wakeup(hu
);
1479 static void qca_wait_for_dump_collection(struct hci_dev
*hdev
)
1481 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
1482 struct qca_data
*qca
= hu
->priv
;
1484 wait_on_bit_timeout(&qca
->flags
, QCA_MEMDUMP_COLLECTION
,
1485 TASK_UNINTERRUPTIBLE
, MEMDUMP_TIMEOUT_MS
);
1487 clear_bit(QCA_MEMDUMP_COLLECTION
, &qca
->flags
);
1490 static void qca_hw_error(struct hci_dev
*hdev
, u8 code
)
1492 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
1493 struct qca_data
*qca
= hu
->priv
;
1495 set_bit(QCA_SSR_TRIGGERED
, &qca
->flags
);
1496 set_bit(QCA_HW_ERROR_EVENT
, &qca
->flags
);
1497 bt_dev_info(hdev
, "mem_dump_status: %d", qca
->memdump_state
);
1499 if (qca
->memdump_state
== QCA_MEMDUMP_IDLE
) {
1500 /* If hardware error event received for other than QCA
1501 * soc memory dump event, then we need to crash the SOC
1502 * and wait here for 8 seconds to get the dump packets.
1503 * This will block main thread to be on hold until we
1506 set_bit(QCA_MEMDUMP_COLLECTION
, &qca
->flags
);
1507 qca_send_crashbuffer(hu
);
1508 qca_wait_for_dump_collection(hdev
);
1509 } else if (qca
->memdump_state
== QCA_MEMDUMP_COLLECTING
) {
1510 /* Let us wait here until memory dump collected or
1511 * memory dump timer expired.
1513 bt_dev_info(hdev
, "waiting for dump to complete");
1514 qca_wait_for_dump_collection(hdev
);
1517 mutex_lock(&qca
->hci_memdump_lock
);
1518 if (qca
->memdump_state
!= QCA_MEMDUMP_COLLECTED
) {
1519 bt_dev_err(hu
->hdev
, "clearing allocated memory due to memdump timeout");
1520 if (qca
->qca_memdump
) {
1521 vfree(qca
->qca_memdump
->memdump_buf_head
);
1522 kfree(qca
->qca_memdump
);
1523 qca
->qca_memdump
= NULL
;
1525 qca
->memdump_state
= QCA_MEMDUMP_TIMEOUT
;
1526 cancel_delayed_work(&qca
->ctrl_memdump_timeout
);
1528 mutex_unlock(&qca
->hci_memdump_lock
);
1530 if (qca
->memdump_state
== QCA_MEMDUMP_TIMEOUT
||
1531 qca
->memdump_state
== QCA_MEMDUMP_COLLECTED
) {
1532 cancel_work_sync(&qca
->ctrl_memdump_evt
);
1533 skb_queue_purge(&qca
->rx_memdump_q
);
1536 clear_bit(QCA_HW_ERROR_EVENT
, &qca
->flags
);
1539 static void qca_cmd_timeout(struct hci_dev
*hdev
)
1541 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
1542 struct qca_data
*qca
= hu
->priv
;
1544 set_bit(QCA_SSR_TRIGGERED
, &qca
->flags
);
1545 if (qca
->memdump_state
== QCA_MEMDUMP_IDLE
) {
1546 set_bit(QCA_MEMDUMP_COLLECTION
, &qca
->flags
);
1547 qca_send_crashbuffer(hu
);
1548 qca_wait_for_dump_collection(hdev
);
1549 } else if (qca
->memdump_state
== QCA_MEMDUMP_COLLECTING
) {
1550 /* Let us wait here until memory dump collected or
1551 * memory dump timer expired.
1553 bt_dev_info(hdev
, "waiting for dump to complete");
1554 qca_wait_for_dump_collection(hdev
);
1557 mutex_lock(&qca
->hci_memdump_lock
);
1558 if (qca
->memdump_state
!= QCA_MEMDUMP_COLLECTED
) {
1559 qca
->memdump_state
= QCA_MEMDUMP_TIMEOUT
;
1560 if (!test_bit(QCA_HW_ERROR_EVENT
, &qca
->flags
)) {
1561 /* Inject hw error event to reset the device
1564 hci_reset_dev(hu
->hdev
);
1567 mutex_unlock(&qca
->hci_memdump_lock
);
1570 static int qca_wcn3990_init(struct hci_uart
*hu
)
1572 struct qca_serdev
*qcadev
;
1575 /* Check for vregs status, may be hci down has turned
1576 * off the voltage regulator.
1578 qcadev
= serdev_device_get_drvdata(hu
->serdev
);
1579 if (!qcadev
->bt_power
->vregs_on
) {
1580 serdev_device_close(hu
->serdev
);
1581 ret
= qca_regulator_enable(qcadev
);
1585 ret
= serdev_device_open(hu
->serdev
);
1587 bt_dev_err(hu
->hdev
, "failed to open port");
1592 /* Forcefully enable wcn3990 to enter in to boot mode. */
1593 host_set_baudrate(hu
, 2400);
1594 ret
= qca_send_power_pulse(hu
, false);
1598 qca_set_speed(hu
, QCA_INIT_SPEED
);
1599 ret
= qca_send_power_pulse(hu
, true);
1603 /* Now the device is in ready state to communicate with host.
1604 * To sync host with device we need to reopen port.
1605 * Without this, we will have RTS and CTS synchronization
1608 serdev_device_close(hu
->serdev
);
1609 ret
= serdev_device_open(hu
->serdev
);
1611 bt_dev_err(hu
->hdev
, "failed to open port");
1615 hci_uart_set_flow_control(hu
, false);
1620 static int qca_power_on(struct hci_dev
*hdev
)
1622 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
1623 enum qca_btsoc_type soc_type
= qca_soc_type(hu
);
1624 struct qca_serdev
*qcadev
;
1625 struct qca_data
*qca
= hu
->priv
;
1628 /* Non-serdev device usually is powered by external power
1629 * and don't need additional action in driver for power on
1634 if (qca_is_wcn399x(soc_type
)) {
1635 ret
= qca_wcn3990_init(hu
);
1637 qcadev
= serdev_device_get_drvdata(hu
->serdev
);
1638 if (qcadev
->bt_en
) {
1639 gpiod_set_value_cansleep(qcadev
->bt_en
, 1);
1640 /* Controller needs time to bootup. */
1645 clear_bit(QCA_BT_OFF
, &qca
->flags
);
1649 static int qca_setup(struct hci_uart
*hu
)
1651 struct hci_dev
*hdev
= hu
->hdev
;
1652 struct qca_data
*qca
= hu
->priv
;
1653 unsigned int speed
, qca_baudrate
= QCA_BAUDRATE_115200
;
1654 unsigned int retries
= 0;
1655 enum qca_btsoc_type soc_type
= qca_soc_type(hu
);
1656 const char *firmware_name
= qca_get_firmware_name(hu
);
1658 struct qca_btsoc_version ver
;
1660 ret
= qca_check_speeds(hu
);
1664 /* Patch downloading has to be done without IBS mode */
1665 set_bit(QCA_IBS_DISABLED
, &qca
->flags
);
1667 /* Enable controller to do both LE scan and BR/EDR inquiry
1670 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
1672 bt_dev_info(hdev
, "setting up %s",
1673 qca_is_wcn399x(soc_type
) ? "wcn399x" : "ROME/QCA6390");
1675 qca
->memdump_state
= QCA_MEMDUMP_IDLE
;
1678 ret
= qca_power_on(hdev
);
1682 clear_bit(QCA_SSR_TRIGGERED
, &qca
->flags
);
1684 if (qca_is_wcn399x(soc_type
)) {
1685 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY
, &hdev
->quirks
);
1687 ret
= qca_read_soc_version(hdev
, &ver
, soc_type
);
1691 qca_set_speed(hu
, QCA_INIT_SPEED
);
1694 /* Setup user speed if needed */
1695 speed
= qca_get_speed(hu
, QCA_OPER_SPEED
);
1697 ret
= qca_set_speed(hu
, QCA_OPER_SPEED
);
1701 qca_baudrate
= qca_get_baudrate_value(speed
);
1704 if (!qca_is_wcn399x(soc_type
)) {
1705 /* Get QCA version information */
1706 ret
= qca_read_soc_version(hdev
, &ver
, soc_type
);
1711 /* Setup patch / NVM configurations */
1712 ret
= qca_uart_setup(hdev
, qca_baudrate
, soc_type
, ver
,
1715 clear_bit(QCA_IBS_DISABLED
, &qca
->flags
);
1716 qca_debugfs_init(hdev
);
1717 hu
->hdev
->hw_error
= qca_hw_error
;
1718 hu
->hdev
->cmd_timeout
= qca_cmd_timeout
;
1719 } else if (ret
== -ENOENT
) {
1720 /* No patch/nvm-config found, run with original fw/config */
1722 } else if (ret
== -EAGAIN
) {
1724 * Userspace firmware loader will return -EAGAIN in case no
1725 * patch/nvm-config is found, so run with original fw/config.
1731 if (ret
&& retries
< MAX_INIT_RETRIES
) {
1732 bt_dev_warn(hdev
, "Retry BT power ON:%d", retries
);
1733 qca_power_shutdown(hu
);
1735 serdev_device_close(hu
->serdev
);
1736 ret
= serdev_device_open(hu
->serdev
);
1738 bt_dev_err(hdev
, "failed to open port");
1747 if (soc_type
== QCA_ROME
)
1748 hu
->hdev
->set_bdaddr
= qca_set_bdaddr_rome
;
1750 hu
->hdev
->set_bdaddr
= qca_set_bdaddr
;
1755 static const struct hci_uart_proto qca_proto
= {
1759 .init_speed
= 115200,
1760 .oper_speed
= 3000000,
1766 .enqueue
= qca_enqueue
,
1767 .dequeue
= qca_dequeue
,
1770 static const struct qca_device_data qca_soc_data_wcn3990
= {
1771 .soc_type
= QCA_WCN3990
,
1772 .vregs
= (struct qca_vreg
[]) {
1775 { "vddrf", 300000 },
1776 { "vddch0", 450000 },
1781 static const struct qca_device_data qca_soc_data_wcn3991
= {
1782 .soc_type
= QCA_WCN3991
,
1783 .vregs
= (struct qca_vreg
[]) {
1786 { "vddrf", 300000 },
1787 { "vddch0", 450000 },
1790 .capabilities
= QCA_CAP_WIDEBAND_SPEECH
| QCA_CAP_VALID_LE_STATES
,
1793 static const struct qca_device_data qca_soc_data_wcn3998
= {
1794 .soc_type
= QCA_WCN3998
,
1795 .vregs
= (struct qca_vreg
[]) {
1798 { "vddrf", 300000 },
1799 { "vddch0", 450000 },
1804 static const struct qca_device_data qca_soc_data_qca6390
= {
1805 .soc_type
= QCA_QCA6390
,
1809 static void qca_power_shutdown(struct hci_uart
*hu
)
1811 struct qca_serdev
*qcadev
;
1812 struct qca_data
*qca
= hu
->priv
;
1813 unsigned long flags
;
1814 enum qca_btsoc_type soc_type
= qca_soc_type(hu
);
1816 qcadev
= serdev_device_get_drvdata(hu
->serdev
);
1818 /* From this point we go into power off state. But serial port is
1819 * still open, stop queueing the IBS data and flush all the buffered
1822 spin_lock_irqsave(&qca
->hci_ibs_lock
, flags
);
1823 set_bit(QCA_IBS_DISABLED
, &qca
->flags
);
1825 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
1827 /* Non-serdev device usually is powered by external power
1828 * and don't need additional action in driver for power down
1833 if (qca_is_wcn399x(soc_type
)) {
1834 host_set_baudrate(hu
, 2400);
1835 qca_send_power_pulse(hu
, false);
1836 qca_regulator_disable(qcadev
);
1837 } else if (qcadev
->bt_en
) {
1838 gpiod_set_value_cansleep(qcadev
->bt_en
, 0);
1841 set_bit(QCA_BT_OFF
, &qca
->flags
);
1844 static int qca_power_off(struct hci_dev
*hdev
)
1846 struct hci_uart
*hu
= hci_get_drvdata(hdev
);
1847 struct qca_data
*qca
= hu
->priv
;
1848 enum qca_btsoc_type soc_type
= qca_soc_type(hu
);
1850 hu
->hdev
->hw_error
= NULL
;
1851 hu
->hdev
->cmd_timeout
= NULL
;
1853 /* Stop sending shutdown command if soc crashes. */
1854 if (soc_type
!= QCA_ROME
1855 && qca
->memdump_state
== QCA_MEMDUMP_IDLE
) {
1856 qca_send_pre_shutdown_cmd(hdev
);
1857 usleep_range(8000, 10000);
1860 qca_power_shutdown(hu
);
1864 static int qca_regulator_enable(struct qca_serdev
*qcadev
)
1866 struct qca_power
*power
= qcadev
->bt_power
;
1869 /* Already enabled */
1870 if (power
->vregs_on
)
1873 BT_DBG("enabling %d regulators)", power
->num_vregs
);
1875 ret
= regulator_bulk_enable(power
->num_vregs
, power
->vreg_bulk
);
1879 power
->vregs_on
= true;
1881 ret
= clk_prepare_enable(qcadev
->susclk
);
1883 qca_regulator_disable(qcadev
);
1888 static void qca_regulator_disable(struct qca_serdev
*qcadev
)
1890 struct qca_power
*power
;
1895 power
= qcadev
->bt_power
;
1897 /* Already disabled? */
1898 if (!power
->vregs_on
)
1901 regulator_bulk_disable(power
->num_vregs
, power
->vreg_bulk
);
1902 power
->vregs_on
= false;
1904 clk_disable_unprepare(qcadev
->susclk
);
1907 static int qca_init_regulators(struct qca_power
*qca
,
1908 const struct qca_vreg
*vregs
, size_t num_vregs
)
1910 struct regulator_bulk_data
*bulk
;
1914 bulk
= devm_kcalloc(qca
->dev
, num_vregs
, sizeof(*bulk
), GFP_KERNEL
);
1918 for (i
= 0; i
< num_vregs
; i
++)
1919 bulk
[i
].supply
= vregs
[i
].name
;
1921 ret
= devm_regulator_bulk_get(qca
->dev
, num_vregs
, bulk
);
1925 for (i
= 0; i
< num_vregs
; i
++) {
1926 ret
= regulator_set_load(bulk
[i
].consumer
, vregs
[i
].load_uA
);
1931 qca
->vreg_bulk
= bulk
;
1932 qca
->num_vregs
= num_vregs
;
1937 static int qca_serdev_probe(struct serdev_device
*serdev
)
1939 struct qca_serdev
*qcadev
;
1940 struct hci_dev
*hdev
;
1941 const struct qca_device_data
*data
;
1943 bool power_ctrl_enabled
= true;
1945 qcadev
= devm_kzalloc(&serdev
->dev
, sizeof(*qcadev
), GFP_KERNEL
);
1949 qcadev
->serdev_hu
.serdev
= serdev
;
1950 data
= device_get_match_data(&serdev
->dev
);
1951 serdev_device_set_drvdata(serdev
, qcadev
);
1952 device_property_read_string(&serdev
->dev
, "firmware-name",
1953 &qcadev
->firmware_name
);
1954 device_property_read_u32(&serdev
->dev
, "max-speed",
1955 &qcadev
->oper_speed
);
1956 if (!qcadev
->oper_speed
)
1957 BT_DBG("UART will pick default operating speed");
1959 if (data
&& qca_is_wcn399x(data
->soc_type
)) {
1960 qcadev
->btsoc_type
= data
->soc_type
;
1961 qcadev
->bt_power
= devm_kzalloc(&serdev
->dev
,
1962 sizeof(struct qca_power
),
1964 if (!qcadev
->bt_power
)
1967 qcadev
->bt_power
->dev
= &serdev
->dev
;
1968 err
= qca_init_regulators(qcadev
->bt_power
, data
->vregs
,
1971 BT_ERR("Failed to init regulators:%d", err
);
1975 qcadev
->bt_power
->vregs_on
= false;
1977 qcadev
->susclk
= devm_clk_get_optional(&serdev
->dev
, NULL
);
1978 if (IS_ERR(qcadev
->susclk
)) {
1979 dev_err(&serdev
->dev
, "failed to acquire clk\n");
1980 return PTR_ERR(qcadev
->susclk
);
1983 err
= hci_uart_register_device(&qcadev
->serdev_hu
, &qca_proto
);
1985 BT_ERR("wcn3990 serdev registration failed");
1990 qcadev
->btsoc_type
= data
->soc_type
;
1992 qcadev
->btsoc_type
= QCA_ROME
;
1994 qcadev
->bt_en
= devm_gpiod_get_optional(&serdev
->dev
, "enable",
1996 if (!qcadev
->bt_en
) {
1997 dev_warn(&serdev
->dev
, "failed to acquire enable gpio\n");
1998 power_ctrl_enabled
= false;
2001 qcadev
->susclk
= devm_clk_get_optional(&serdev
->dev
, NULL
);
2002 if (IS_ERR(qcadev
->susclk
)) {
2003 dev_warn(&serdev
->dev
, "failed to acquire clk\n");
2004 return PTR_ERR(qcadev
->susclk
);
2006 err
= clk_set_rate(qcadev
->susclk
, SUSCLK_RATE_32KHZ
);
2010 err
= clk_prepare_enable(qcadev
->susclk
);
2014 err
= hci_uart_register_device(&qcadev
->serdev_hu
, &qca_proto
);
2016 BT_ERR("Rome serdev registration failed");
2017 clk_disable_unprepare(qcadev
->susclk
);
2022 hdev
= qcadev
->serdev_hu
.hdev
;
2024 if (power_ctrl_enabled
) {
2025 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP
, &hdev
->quirks
);
2026 hdev
->shutdown
= qca_power_off
;
2030 /* Wideband speech support must be set per driver since it can't
2031 * be queried via hci. Same with the valid le states quirk.
2033 if (data
->capabilities
& QCA_CAP_WIDEBAND_SPEECH
)
2034 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED
,
2037 if (data
->capabilities
& QCA_CAP_VALID_LE_STATES
)
2038 set_bit(HCI_QUIRK_VALID_LE_STATES
, &hdev
->quirks
);
2044 static void qca_serdev_remove(struct serdev_device
*serdev
)
2046 struct qca_serdev
*qcadev
= serdev_device_get_drvdata(serdev
);
2047 struct qca_power
*power
= qcadev
->bt_power
;
2049 if (qca_is_wcn399x(qcadev
->btsoc_type
) && power
->vregs_on
)
2050 qca_power_shutdown(&qcadev
->serdev_hu
);
2051 else if (qcadev
->susclk
)
2052 clk_disable_unprepare(qcadev
->susclk
);
2054 hci_uart_unregister_device(&qcadev
->serdev_hu
);
2057 static void qca_serdev_shutdown(struct device
*dev
)
2060 int timeout
= msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS
);
2061 struct serdev_device
*serdev
= to_serdev_device(dev
);
2062 struct qca_serdev
*qcadev
= serdev_device_get_drvdata(serdev
);
2063 const u8 ibs_wake_cmd
[] = { 0xFD };
2064 const u8 edl_reset_soc_cmd
[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
2066 if (qcadev
->btsoc_type
== QCA_QCA6390
) {
2067 serdev_device_write_flush(serdev
);
2068 ret
= serdev_device_write_buf(serdev
, ibs_wake_cmd
,
2069 sizeof(ibs_wake_cmd
));
2071 BT_ERR("QCA send IBS_WAKE_IND error: %d", ret
);
2074 serdev_device_wait_until_sent(serdev
, timeout
);
2075 usleep_range(8000, 10000);
2077 serdev_device_write_flush(serdev
);
2078 ret
= serdev_device_write_buf(serdev
, edl_reset_soc_cmd
,
2079 sizeof(edl_reset_soc_cmd
));
2081 BT_ERR("QCA send EDL_RESET_REQ error: %d", ret
);
2084 serdev_device_wait_until_sent(serdev
, timeout
);
2085 usleep_range(8000, 10000);
2089 static int __maybe_unused
qca_suspend(struct device
*dev
)
2091 struct serdev_device
*serdev
= to_serdev_device(dev
);
2092 struct qca_serdev
*qcadev
= serdev_device_get_drvdata(serdev
);
2093 struct hci_uart
*hu
= &qcadev
->serdev_hu
;
2094 struct qca_data
*qca
= hu
->priv
;
2095 unsigned long flags
;
2096 bool tx_pending
= false;
2099 u32 wait_timeout
= 0;
2101 set_bit(QCA_SUSPENDING
, &qca
->flags
);
2103 if (test_bit(QCA_BT_OFF
, &qca
->flags
))
2106 if (test_bit(QCA_IBS_DISABLED
, &qca
->flags
)) {
2107 wait_timeout
= test_bit(QCA_SSR_TRIGGERED
, &qca
->flags
) ?
2108 IBS_DISABLE_SSR_TIMEOUT_MS
:
2109 FW_DOWNLOAD_TIMEOUT_MS
;
2111 /* QCA_IBS_DISABLED flag is set to true, During FW download
2112 * and during memory dump collection. It is reset to false,
2113 * After FW download complete and after memory dump collections.
2115 wait_on_bit_timeout(&qca
->flags
, QCA_IBS_DISABLED
,
2116 TASK_UNINTERRUPTIBLE
, msecs_to_jiffies(wait_timeout
));
2118 if (test_bit(QCA_IBS_DISABLED
, &qca
->flags
)) {
2119 bt_dev_err(hu
->hdev
, "SSR or FW download time out");
2125 /* After memory dump collection, Controller is powered off.*/
2126 if (test_bit(QCA_BT_OFF
, &qca
->flags
))
2129 cancel_work_sync(&qca
->ws_awake_device
);
2130 cancel_work_sync(&qca
->ws_awake_rx
);
2132 spin_lock_irqsave_nested(&qca
->hci_ibs_lock
,
2133 flags
, SINGLE_DEPTH_NESTING
);
2135 switch (qca
->tx_ibs_state
) {
2136 case HCI_IBS_TX_WAKING
:
2137 del_timer(&qca
->wake_retrans_timer
);
2139 case HCI_IBS_TX_AWAKE
:
2140 del_timer(&qca
->tx_idle_timer
);
2142 serdev_device_write_flush(hu
->serdev
);
2143 cmd
= HCI_IBS_SLEEP_IND
;
2144 ret
= serdev_device_write_buf(hu
->serdev
, &cmd
, sizeof(cmd
));
2147 BT_ERR("Failed to send SLEEP to device");
2151 qca
->tx_ibs_state
= HCI_IBS_TX_ASLEEP
;
2152 qca
->ibs_sent_slps
++;
2156 case HCI_IBS_TX_ASLEEP
:
2160 BT_ERR("Spurious tx state %d", qca
->tx_ibs_state
);
2165 spin_unlock_irqrestore(&qca
->hci_ibs_lock
, flags
);
2171 serdev_device_wait_until_sent(hu
->serdev
,
2172 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS
));
2173 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF
, hu
);
2176 /* Wait for HCI_IBS_SLEEP_IND sent by device to indicate its Tx is going
2177 * to sleep, so that the packet does not wake the system later.
2179 ret
= wait_event_interruptible_timeout(qca
->suspend_wait_q
,
2180 qca
->rx_ibs_state
== HCI_IBS_RX_ASLEEP
,
2181 msecs_to_jiffies(IBS_BTSOC_TX_IDLE_TIMEOUT_MS
));
2190 clear_bit(QCA_SUSPENDING
, &qca
->flags
);
2195 static int __maybe_unused
qca_resume(struct device
*dev
)
2197 struct serdev_device
*serdev
= to_serdev_device(dev
);
2198 struct qca_serdev
*qcadev
= serdev_device_get_drvdata(serdev
);
2199 struct hci_uart
*hu
= &qcadev
->serdev_hu
;
2200 struct qca_data
*qca
= hu
->priv
;
2202 clear_bit(QCA_SUSPENDING
, &qca
->flags
);
2207 static SIMPLE_DEV_PM_OPS(qca_pm_ops
, qca_suspend
, qca_resume
);
2210 static const struct of_device_id qca_bluetooth_of_match
[] = {
2211 { .compatible
= "qcom,qca6174-bt" },
2212 { .compatible
= "qcom,qca6390-bt", .data
= &qca_soc_data_qca6390
},
2213 { .compatible
= "qcom,qca9377-bt" },
2214 { .compatible
= "qcom,wcn3990-bt", .data
= &qca_soc_data_wcn3990
},
2215 { .compatible
= "qcom,wcn3991-bt", .data
= &qca_soc_data_wcn3991
},
2216 { .compatible
= "qcom,wcn3998-bt", .data
= &qca_soc_data_wcn3998
},
2219 MODULE_DEVICE_TABLE(of
, qca_bluetooth_of_match
);
2223 static const struct acpi_device_id qca_bluetooth_acpi_match
[] = {
2224 { "QCOM6390", (kernel_ulong_t
)&qca_soc_data_qca6390
},
2225 { "DLA16390", (kernel_ulong_t
)&qca_soc_data_qca6390
},
2226 { "DLB16390", (kernel_ulong_t
)&qca_soc_data_qca6390
},
2227 { "DLB26390", (kernel_ulong_t
)&qca_soc_data_qca6390
},
2230 MODULE_DEVICE_TABLE(acpi
, qca_bluetooth_acpi_match
);
2234 static struct serdev_device_driver qca_serdev_driver
= {
2235 .probe
= qca_serdev_probe
,
2236 .remove
= qca_serdev_remove
,
2238 .name
= "hci_uart_qca",
2239 .of_match_table
= of_match_ptr(qca_bluetooth_of_match
),
2240 .acpi_match_table
= ACPI_PTR(qca_bluetooth_acpi_match
),
2241 .shutdown
= qca_serdev_shutdown
,
2246 int __init
qca_init(void)
2248 serdev_device_driver_register(&qca_serdev_driver
);
2250 return hci_uart_register_proto(&qca_proto
);
2253 int __exit
qca_deinit(void)
2255 serdev_device_driver_unregister(&qca_serdev_driver
);
2257 return hci_uart_unregister_proto(&qca_proto
);