dm writecache: add cond_resched to loop in persistent_memory_claim()
[linux/fpc-iii.git] / drivers / bluetooth / hci_qca.c
blob0b1036e5e963c5f7d44b6f0b56989720cba272dd
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
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.
11 * Acknowledgements:
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/platform_device.h>
30 #include <linux/regulator/consumer.h>
31 #include <linux/serdev.h>
32 #include <linux/mutex.h>
33 #include <asm/unaligned.h>
35 #include <net/bluetooth/bluetooth.h>
36 #include <net/bluetooth/hci_core.h>
38 #include "hci_uart.h"
39 #include "btqca.h"
41 /* HCI_IBS protocol messages */
42 #define HCI_IBS_SLEEP_IND 0xFE
43 #define HCI_IBS_WAKE_IND 0xFD
44 #define HCI_IBS_WAKE_ACK 0xFC
45 #define HCI_MAX_IBS_SIZE 10
47 #define IBS_WAKE_RETRANS_TIMEOUT_MS 100
48 #define IBS_BTSOC_TX_IDLE_TIMEOUT_MS 40
49 #define IBS_HOST_TX_IDLE_TIMEOUT_MS 2000
50 #define CMD_TRANS_TIMEOUT_MS 100
51 #define MEMDUMP_TIMEOUT_MS 8000
53 /* susclk rate */
54 #define SUSCLK_RATE_32KHZ 32768
56 /* Controller debug log header */
57 #define QCA_DEBUG_HANDLE 0x2EDC
59 /* max retry count when init fails */
60 #define MAX_INIT_RETRIES 3
62 /* Controller dump header */
63 #define QCA_SSR_DUMP_HANDLE 0x0108
64 #define QCA_DUMP_PACKET_SIZE 255
65 #define QCA_LAST_SEQUENCE_NUM 0xFFFF
66 #define QCA_CRASHBYTE_PACKET_LEN 1096
67 #define QCA_MEMDUMP_BYTE 0xFB
69 enum qca_flags {
70 QCA_IBS_ENABLED,
71 QCA_DROP_VENDOR_EVENT,
72 QCA_SUSPENDING,
73 QCA_MEMDUMP_COLLECTION,
74 QCA_HW_ERROR_EVENT
78 /* HCI_IBS transmit side sleep protocol states */
79 enum tx_ibs_states {
80 HCI_IBS_TX_ASLEEP,
81 HCI_IBS_TX_WAKING,
82 HCI_IBS_TX_AWAKE,
85 /* HCI_IBS receive side sleep protocol states */
86 enum rx_states {
87 HCI_IBS_RX_ASLEEP,
88 HCI_IBS_RX_AWAKE,
91 /* HCI_IBS transmit and receive side clock state vote */
92 enum hci_ibs_clock_state_vote {
93 HCI_IBS_VOTE_STATS_UPDATE,
94 HCI_IBS_TX_VOTE_CLOCK_ON,
95 HCI_IBS_TX_VOTE_CLOCK_OFF,
96 HCI_IBS_RX_VOTE_CLOCK_ON,
97 HCI_IBS_RX_VOTE_CLOCK_OFF,
100 /* Controller memory dump states */
101 enum qca_memdump_states {
102 QCA_MEMDUMP_IDLE,
103 QCA_MEMDUMP_COLLECTING,
104 QCA_MEMDUMP_COLLECTED,
105 QCA_MEMDUMP_TIMEOUT,
108 struct qca_memdump_data {
109 char *memdump_buf_head;
110 char *memdump_buf_tail;
111 u32 current_seq_no;
112 u32 received_dump;
115 struct qca_memdump_event_hdr {
116 __u8 evt;
117 __u8 plen;
118 __u16 opcode;
119 __u16 seq_no;
120 __u8 reserved;
121 } __packed;
124 struct qca_dump_size {
125 u32 dump_size;
126 } __packed;
128 struct qca_data {
129 struct hci_uart *hu;
130 struct sk_buff *rx_skb;
131 struct sk_buff_head txq;
132 struct sk_buff_head tx_wait_q; /* HCI_IBS wait queue */
133 struct sk_buff_head rx_memdump_q; /* Memdump wait queue */
134 spinlock_t hci_ibs_lock; /* HCI_IBS state lock */
135 u8 tx_ibs_state; /* HCI_IBS transmit side power state*/
136 u8 rx_ibs_state; /* HCI_IBS receive side power state */
137 bool tx_vote; /* Clock must be on for TX */
138 bool rx_vote; /* Clock must be on for RX */
139 struct timer_list tx_idle_timer;
140 u32 tx_idle_delay;
141 struct timer_list wake_retrans_timer;
142 u32 wake_retrans;
143 struct workqueue_struct *workqueue;
144 struct work_struct ws_awake_rx;
145 struct work_struct ws_awake_device;
146 struct work_struct ws_rx_vote_off;
147 struct work_struct ws_tx_vote_off;
148 struct work_struct ctrl_memdump_evt;
149 struct delayed_work ctrl_memdump_timeout;
150 struct qca_memdump_data *qca_memdump;
151 unsigned long flags;
152 struct completion drop_ev_comp;
153 wait_queue_head_t suspend_wait_q;
154 enum qca_memdump_states memdump_state;
155 struct mutex hci_memdump_lock;
157 /* For debugging purpose */
158 u64 ibs_sent_wacks;
159 u64 ibs_sent_slps;
160 u64 ibs_sent_wakes;
161 u64 ibs_recv_wacks;
162 u64 ibs_recv_slps;
163 u64 ibs_recv_wakes;
164 u64 vote_last_jif;
165 u32 vote_on_ms;
166 u32 vote_off_ms;
167 u64 tx_votes_on;
168 u64 rx_votes_on;
169 u64 tx_votes_off;
170 u64 rx_votes_off;
171 u64 votes_on;
172 u64 votes_off;
175 enum qca_speed_type {
176 QCA_INIT_SPEED = 1,
177 QCA_OPER_SPEED
181 * Voltage regulator information required for configuring the
182 * QCA Bluetooth chipset
184 struct qca_vreg {
185 const char *name;
186 unsigned int load_uA;
189 struct qca_vreg_data {
190 enum qca_btsoc_type soc_type;
191 struct qca_vreg *vregs;
192 size_t num_vregs;
196 * Platform data for the QCA Bluetooth power driver.
198 struct qca_power {
199 struct device *dev;
200 struct regulator_bulk_data *vreg_bulk;
201 int num_vregs;
202 bool vregs_on;
205 struct qca_serdev {
206 struct hci_uart serdev_hu;
207 struct gpio_desc *bt_en;
208 struct clk *susclk;
209 enum qca_btsoc_type btsoc_type;
210 struct qca_power *bt_power;
211 u32 init_speed;
212 u32 oper_speed;
213 const char *firmware_name;
216 static int qca_regulator_enable(struct qca_serdev *qcadev);
217 static void qca_regulator_disable(struct qca_serdev *qcadev);
218 static void qca_power_shutdown(struct hci_uart *hu);
219 static int qca_power_off(struct hci_dev *hdev);
220 static void qca_controller_memdump(struct work_struct *work);
222 static enum qca_btsoc_type qca_soc_type(struct hci_uart *hu)
224 enum qca_btsoc_type soc_type;
226 if (hu->serdev) {
227 struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev);
229 soc_type = qsd->btsoc_type;
230 } else {
231 soc_type = QCA_ROME;
234 return soc_type;
237 static const char *qca_get_firmware_name(struct hci_uart *hu)
239 if (hu->serdev) {
240 struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev);
242 return qsd->firmware_name;
243 } else {
244 return NULL;
248 static void __serial_clock_on(struct tty_struct *tty)
250 /* TODO: Some chipset requires to enable UART clock on client
251 * side to save power consumption or manual work is required.
252 * Please put your code to control UART clock here if needed
256 static void __serial_clock_off(struct tty_struct *tty)
258 /* TODO: Some chipset requires to disable UART clock on client
259 * side to save power consumption or manual work is required.
260 * Please put your code to control UART clock off here if needed
264 /* serial_clock_vote needs to be called with the ibs lock held */
265 static void serial_clock_vote(unsigned long vote, struct hci_uart *hu)
267 struct qca_data *qca = hu->priv;
268 unsigned int diff;
270 bool old_vote = (qca->tx_vote | qca->rx_vote);
271 bool new_vote;
273 switch (vote) {
274 case HCI_IBS_VOTE_STATS_UPDATE:
275 diff = jiffies_to_msecs(jiffies - qca->vote_last_jif);
277 if (old_vote)
278 qca->vote_off_ms += diff;
279 else
280 qca->vote_on_ms += diff;
281 return;
283 case HCI_IBS_TX_VOTE_CLOCK_ON:
284 qca->tx_vote = true;
285 qca->tx_votes_on++;
286 new_vote = true;
287 break;
289 case HCI_IBS_RX_VOTE_CLOCK_ON:
290 qca->rx_vote = true;
291 qca->rx_votes_on++;
292 new_vote = true;
293 break;
295 case HCI_IBS_TX_VOTE_CLOCK_OFF:
296 qca->tx_vote = false;
297 qca->tx_votes_off++;
298 new_vote = qca->rx_vote | qca->tx_vote;
299 break;
301 case HCI_IBS_RX_VOTE_CLOCK_OFF:
302 qca->rx_vote = false;
303 qca->rx_votes_off++;
304 new_vote = qca->rx_vote | qca->tx_vote;
305 break;
307 default:
308 BT_ERR("Voting irregularity");
309 return;
312 if (new_vote != old_vote) {
313 if (new_vote)
314 __serial_clock_on(hu->tty);
315 else
316 __serial_clock_off(hu->tty);
318 BT_DBG("Vote serial clock %s(%s)", new_vote ? "true" : "false",
319 vote ? "true" : "false");
321 diff = jiffies_to_msecs(jiffies - qca->vote_last_jif);
323 if (new_vote) {
324 qca->votes_on++;
325 qca->vote_off_ms += diff;
326 } else {
327 qca->votes_off++;
328 qca->vote_on_ms += diff;
330 qca->vote_last_jif = jiffies;
334 /* Builds and sends an HCI_IBS command packet.
335 * These are very simple packets with only 1 cmd byte.
337 static int send_hci_ibs_cmd(u8 cmd, struct hci_uart *hu)
339 int err = 0;
340 struct sk_buff *skb = NULL;
341 struct qca_data *qca = hu->priv;
343 BT_DBG("hu %p send hci ibs cmd 0x%x", hu, cmd);
345 skb = bt_skb_alloc(1, GFP_ATOMIC);
346 if (!skb) {
347 BT_ERR("Failed to allocate memory for HCI_IBS packet");
348 return -ENOMEM;
351 /* Assign HCI_IBS type */
352 skb_put_u8(skb, cmd);
354 skb_queue_tail(&qca->txq, skb);
356 return err;
359 static void qca_wq_awake_device(struct work_struct *work)
361 struct qca_data *qca = container_of(work, struct qca_data,
362 ws_awake_device);
363 struct hci_uart *hu = qca->hu;
364 unsigned long retrans_delay;
365 unsigned long flags;
367 BT_DBG("hu %p wq awake device", hu);
369 /* Vote for serial clock */
370 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_ON, hu);
372 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
374 /* Send wake indication to device */
375 if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND, hu) < 0)
376 BT_ERR("Failed to send WAKE to device");
378 qca->ibs_sent_wakes++;
380 /* Start retransmit timer */
381 retrans_delay = msecs_to_jiffies(qca->wake_retrans);
382 mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay);
384 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
386 /* Actually send the packets */
387 hci_uart_tx_wakeup(hu);
390 static void qca_wq_awake_rx(struct work_struct *work)
392 struct qca_data *qca = container_of(work, struct qca_data,
393 ws_awake_rx);
394 struct hci_uart *hu = qca->hu;
395 unsigned long flags;
397 BT_DBG("hu %p wq awake rx", hu);
399 serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_ON, hu);
401 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
402 qca->rx_ibs_state = HCI_IBS_RX_AWAKE;
404 /* Always acknowledge device wake up,
405 * sending IBS message doesn't count as TX ON.
407 if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK, hu) < 0)
408 BT_ERR("Failed to acknowledge device wake up");
410 qca->ibs_sent_wacks++;
412 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
414 /* Actually send the packets */
415 hci_uart_tx_wakeup(hu);
418 static void qca_wq_serial_rx_clock_vote_off(struct work_struct *work)
420 struct qca_data *qca = container_of(work, struct qca_data,
421 ws_rx_vote_off);
422 struct hci_uart *hu = qca->hu;
424 BT_DBG("hu %p rx clock vote off", hu);
426 serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_OFF, hu);
429 static void qca_wq_serial_tx_clock_vote_off(struct work_struct *work)
431 struct qca_data *qca = container_of(work, struct qca_data,
432 ws_tx_vote_off);
433 struct hci_uart *hu = qca->hu;
435 BT_DBG("hu %p tx clock vote off", hu);
437 /* Run HCI tx handling unlocked */
438 hci_uart_tx_wakeup(hu);
440 /* Now that message queued to tty driver, vote for tty clocks off.
441 * It is up to the tty driver to pend the clocks off until tx done.
443 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF, hu);
446 static void hci_ibs_tx_idle_timeout(struct timer_list *t)
448 struct qca_data *qca = from_timer(qca, t, tx_idle_timer);
449 struct hci_uart *hu = qca->hu;
450 unsigned long flags;
452 BT_DBG("hu %p idle timeout in %d state", hu, qca->tx_ibs_state);
454 spin_lock_irqsave_nested(&qca->hci_ibs_lock,
455 flags, SINGLE_DEPTH_NESTING);
457 switch (qca->tx_ibs_state) {
458 case HCI_IBS_TX_AWAKE:
459 /* TX_IDLE, go to SLEEP */
460 if (send_hci_ibs_cmd(HCI_IBS_SLEEP_IND, hu) < 0) {
461 BT_ERR("Failed to send SLEEP to device");
462 break;
464 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
465 qca->ibs_sent_slps++;
466 queue_work(qca->workqueue, &qca->ws_tx_vote_off);
467 break;
469 case HCI_IBS_TX_ASLEEP:
470 case HCI_IBS_TX_WAKING:
471 /* Fall through */
473 default:
474 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state);
475 break;
478 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
481 static void hci_ibs_wake_retrans_timeout(struct timer_list *t)
483 struct qca_data *qca = from_timer(qca, t, wake_retrans_timer);
484 struct hci_uart *hu = qca->hu;
485 unsigned long flags, retrans_delay;
486 bool retransmit = false;
488 BT_DBG("hu %p wake retransmit timeout in %d state",
489 hu, qca->tx_ibs_state);
491 spin_lock_irqsave_nested(&qca->hci_ibs_lock,
492 flags, SINGLE_DEPTH_NESTING);
494 /* Don't retransmit the HCI_IBS_WAKE_IND when suspending. */
495 if (test_bit(QCA_SUSPENDING, &qca->flags)) {
496 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
497 return;
500 switch (qca->tx_ibs_state) {
501 case HCI_IBS_TX_WAKING:
502 /* No WAKE_ACK, retransmit WAKE */
503 retransmit = true;
504 if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND, hu) < 0) {
505 BT_ERR("Failed to acknowledge device wake up");
506 break;
508 qca->ibs_sent_wakes++;
509 retrans_delay = msecs_to_jiffies(qca->wake_retrans);
510 mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay);
511 break;
513 case HCI_IBS_TX_ASLEEP:
514 case HCI_IBS_TX_AWAKE:
515 /* Fall through */
517 default:
518 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state);
519 break;
522 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
524 if (retransmit)
525 hci_uart_tx_wakeup(hu);
529 static void qca_controller_memdump_timeout(struct work_struct *work)
531 struct qca_data *qca = container_of(work, struct qca_data,
532 ctrl_memdump_timeout.work);
533 struct hci_uart *hu = qca->hu;
535 mutex_lock(&qca->hci_memdump_lock);
536 if (test_bit(QCA_MEMDUMP_COLLECTION, &qca->flags)) {
537 qca->memdump_state = QCA_MEMDUMP_TIMEOUT;
538 if (!test_bit(QCA_HW_ERROR_EVENT, &qca->flags)) {
539 /* Inject hw error event to reset the device
540 * and driver.
542 hci_reset_dev(hu->hdev);
546 mutex_unlock(&qca->hci_memdump_lock);
550 /* Initialize protocol */
551 static int qca_open(struct hci_uart *hu)
553 struct qca_serdev *qcadev;
554 struct qca_data *qca;
556 BT_DBG("hu %p qca_open", hu);
558 if (!hci_uart_has_flow_control(hu))
559 return -EOPNOTSUPP;
561 qca = kzalloc(sizeof(struct qca_data), GFP_KERNEL);
562 if (!qca)
563 return -ENOMEM;
565 skb_queue_head_init(&qca->txq);
566 skb_queue_head_init(&qca->tx_wait_q);
567 skb_queue_head_init(&qca->rx_memdump_q);
568 spin_lock_init(&qca->hci_ibs_lock);
569 mutex_init(&qca->hci_memdump_lock);
570 qca->workqueue = alloc_ordered_workqueue("qca_wq", 0);
571 if (!qca->workqueue) {
572 BT_ERR("QCA Workqueue not initialized properly");
573 kfree(qca);
574 return -ENOMEM;
577 INIT_WORK(&qca->ws_awake_rx, qca_wq_awake_rx);
578 INIT_WORK(&qca->ws_awake_device, qca_wq_awake_device);
579 INIT_WORK(&qca->ws_rx_vote_off, qca_wq_serial_rx_clock_vote_off);
580 INIT_WORK(&qca->ws_tx_vote_off, qca_wq_serial_tx_clock_vote_off);
581 INIT_WORK(&qca->ctrl_memdump_evt, qca_controller_memdump);
582 INIT_DELAYED_WORK(&qca->ctrl_memdump_timeout,
583 qca_controller_memdump_timeout);
584 init_waitqueue_head(&qca->suspend_wait_q);
586 qca->hu = hu;
587 init_completion(&qca->drop_ev_comp);
589 /* Assume we start with both sides asleep -- extra wakes OK */
590 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
591 qca->rx_ibs_state = HCI_IBS_RX_ASLEEP;
593 qca->vote_last_jif = jiffies;
595 hu->priv = qca;
597 if (hu->serdev) {
598 qcadev = serdev_device_get_drvdata(hu->serdev);
599 if (qca_is_wcn399x(qcadev->btsoc_type)) {
600 hu->init_speed = qcadev->init_speed;
601 hu->oper_speed = qcadev->oper_speed;
605 timer_setup(&qca->wake_retrans_timer, hci_ibs_wake_retrans_timeout, 0);
606 qca->wake_retrans = IBS_WAKE_RETRANS_TIMEOUT_MS;
608 timer_setup(&qca->tx_idle_timer, hci_ibs_tx_idle_timeout, 0);
609 qca->tx_idle_delay = IBS_HOST_TX_IDLE_TIMEOUT_MS;
611 BT_DBG("HCI_UART_QCA open, tx_idle_delay=%u, wake_retrans=%u",
612 qca->tx_idle_delay, qca->wake_retrans);
614 return 0;
617 static void qca_debugfs_init(struct hci_dev *hdev)
619 struct hci_uart *hu = hci_get_drvdata(hdev);
620 struct qca_data *qca = hu->priv;
621 struct dentry *ibs_dir;
622 umode_t mode;
624 if (!hdev->debugfs)
625 return;
627 ibs_dir = debugfs_create_dir("ibs", hdev->debugfs);
629 /* read only */
630 mode = S_IRUGO;
631 debugfs_create_u8("tx_ibs_state", mode, ibs_dir, &qca->tx_ibs_state);
632 debugfs_create_u8("rx_ibs_state", mode, ibs_dir, &qca->rx_ibs_state);
633 debugfs_create_u64("ibs_sent_sleeps", mode, ibs_dir,
634 &qca->ibs_sent_slps);
635 debugfs_create_u64("ibs_sent_wakes", mode, ibs_dir,
636 &qca->ibs_sent_wakes);
637 debugfs_create_u64("ibs_sent_wake_acks", mode, ibs_dir,
638 &qca->ibs_sent_wacks);
639 debugfs_create_u64("ibs_recv_sleeps", mode, ibs_dir,
640 &qca->ibs_recv_slps);
641 debugfs_create_u64("ibs_recv_wakes", mode, ibs_dir,
642 &qca->ibs_recv_wakes);
643 debugfs_create_u64("ibs_recv_wake_acks", mode, ibs_dir,
644 &qca->ibs_recv_wacks);
645 debugfs_create_bool("tx_vote", mode, ibs_dir, &qca->tx_vote);
646 debugfs_create_u64("tx_votes_on", mode, ibs_dir, &qca->tx_votes_on);
647 debugfs_create_u64("tx_votes_off", mode, ibs_dir, &qca->tx_votes_off);
648 debugfs_create_bool("rx_vote", mode, ibs_dir, &qca->rx_vote);
649 debugfs_create_u64("rx_votes_on", mode, ibs_dir, &qca->rx_votes_on);
650 debugfs_create_u64("rx_votes_off", mode, ibs_dir, &qca->rx_votes_off);
651 debugfs_create_u64("votes_on", mode, ibs_dir, &qca->votes_on);
652 debugfs_create_u64("votes_off", mode, ibs_dir, &qca->votes_off);
653 debugfs_create_u32("vote_on_ms", mode, ibs_dir, &qca->vote_on_ms);
654 debugfs_create_u32("vote_off_ms", mode, ibs_dir, &qca->vote_off_ms);
656 /* read/write */
657 mode = S_IRUGO | S_IWUSR;
658 debugfs_create_u32("wake_retrans", mode, ibs_dir, &qca->wake_retrans);
659 debugfs_create_u32("tx_idle_delay", mode, ibs_dir,
660 &qca->tx_idle_delay);
663 /* Flush protocol data */
664 static int qca_flush(struct hci_uart *hu)
666 struct qca_data *qca = hu->priv;
668 BT_DBG("hu %p qca flush", hu);
670 skb_queue_purge(&qca->tx_wait_q);
671 skb_queue_purge(&qca->txq);
673 return 0;
676 /* Close protocol */
677 static int qca_close(struct hci_uart *hu)
679 struct qca_data *qca = hu->priv;
681 BT_DBG("hu %p qca close", hu);
683 serial_clock_vote(HCI_IBS_VOTE_STATS_UPDATE, hu);
685 skb_queue_purge(&qca->tx_wait_q);
686 skb_queue_purge(&qca->txq);
687 skb_queue_purge(&qca->rx_memdump_q);
688 del_timer(&qca->tx_idle_timer);
689 del_timer(&qca->wake_retrans_timer);
690 destroy_workqueue(qca->workqueue);
691 qca->hu = NULL;
693 qca_power_shutdown(hu);
695 kfree_skb(qca->rx_skb);
697 hu->priv = NULL;
699 kfree(qca);
701 return 0;
704 /* Called upon a wake-up-indication from the device.
706 static void device_want_to_wakeup(struct hci_uart *hu)
708 unsigned long flags;
709 struct qca_data *qca = hu->priv;
711 BT_DBG("hu %p want to wake up", hu);
713 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
715 qca->ibs_recv_wakes++;
717 /* Don't wake the rx up when suspending. */
718 if (test_bit(QCA_SUSPENDING, &qca->flags)) {
719 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
720 return;
723 switch (qca->rx_ibs_state) {
724 case HCI_IBS_RX_ASLEEP:
725 /* Make sure clock is on - we may have turned clock off since
726 * receiving the wake up indicator awake rx clock.
728 queue_work(qca->workqueue, &qca->ws_awake_rx);
729 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
730 return;
732 case HCI_IBS_RX_AWAKE:
733 /* Always acknowledge device wake up,
734 * sending IBS message doesn't count as TX ON.
736 if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK, hu) < 0) {
737 BT_ERR("Failed to acknowledge device wake up");
738 break;
740 qca->ibs_sent_wacks++;
741 break;
743 default:
744 /* Any other state is illegal */
745 BT_ERR("Received HCI_IBS_WAKE_IND in rx state %d",
746 qca->rx_ibs_state);
747 break;
750 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
752 /* Actually send the packets */
753 hci_uart_tx_wakeup(hu);
756 /* Called upon a sleep-indication from the device.
758 static void device_want_to_sleep(struct hci_uart *hu)
760 unsigned long flags;
761 struct qca_data *qca = hu->priv;
763 BT_DBG("hu %p want to sleep in %d state", hu, qca->rx_ibs_state);
765 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
767 qca->ibs_recv_slps++;
769 switch (qca->rx_ibs_state) {
770 case HCI_IBS_RX_AWAKE:
771 /* Update state */
772 qca->rx_ibs_state = HCI_IBS_RX_ASLEEP;
773 /* Vote off rx clock under workqueue */
774 queue_work(qca->workqueue, &qca->ws_rx_vote_off);
775 break;
777 case HCI_IBS_RX_ASLEEP:
778 break;
780 default:
781 /* Any other state is illegal */
782 BT_ERR("Received HCI_IBS_SLEEP_IND in rx state %d",
783 qca->rx_ibs_state);
784 break;
787 wake_up_interruptible(&qca->suspend_wait_q);
789 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
792 /* Called upon wake-up-acknowledgement from the device
794 static void device_woke_up(struct hci_uart *hu)
796 unsigned long flags, idle_delay;
797 struct qca_data *qca = hu->priv;
798 struct sk_buff *skb = NULL;
800 BT_DBG("hu %p woke up", hu);
802 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
804 qca->ibs_recv_wacks++;
806 /* Don't react to the wake-up-acknowledgment when suspending. */
807 if (test_bit(QCA_SUSPENDING, &qca->flags)) {
808 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
809 return;
812 switch (qca->tx_ibs_state) {
813 case HCI_IBS_TX_AWAKE:
814 /* Expect one if we send 2 WAKEs */
815 BT_DBG("Received HCI_IBS_WAKE_ACK in tx state %d",
816 qca->tx_ibs_state);
817 break;
819 case HCI_IBS_TX_WAKING:
820 /* Send pending packets */
821 while ((skb = skb_dequeue(&qca->tx_wait_q)))
822 skb_queue_tail(&qca->txq, skb);
824 /* Switch timers and change state to HCI_IBS_TX_AWAKE */
825 del_timer(&qca->wake_retrans_timer);
826 idle_delay = msecs_to_jiffies(qca->tx_idle_delay);
827 mod_timer(&qca->tx_idle_timer, jiffies + idle_delay);
828 qca->tx_ibs_state = HCI_IBS_TX_AWAKE;
829 break;
831 case HCI_IBS_TX_ASLEEP:
832 /* Fall through */
834 default:
835 BT_ERR("Received HCI_IBS_WAKE_ACK in tx state %d",
836 qca->tx_ibs_state);
837 break;
840 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
842 /* Actually send the packets */
843 hci_uart_tx_wakeup(hu);
846 /* Enqueue frame for transmittion (padding, crc, etc) may be called from
847 * two simultaneous tasklets.
849 static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)
851 unsigned long flags = 0, idle_delay;
852 struct qca_data *qca = hu->priv;
854 BT_DBG("hu %p qca enq skb %p tx_ibs_state %d", hu, skb,
855 qca->tx_ibs_state);
857 /* Prepend skb with frame type */
858 memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
860 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
862 /* Don't go to sleep in middle of patch download or
863 * Out-Of-Band(GPIOs control) sleep is selected.
864 * Don't wake the device up when suspending.
866 if (!test_bit(QCA_IBS_ENABLED, &qca->flags) ||
867 test_bit(QCA_SUSPENDING, &qca->flags)) {
868 skb_queue_tail(&qca->txq, skb);
869 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
870 return 0;
873 /* Act according to current state */
874 switch (qca->tx_ibs_state) {
875 case HCI_IBS_TX_AWAKE:
876 BT_DBG("Device awake, sending normally");
877 skb_queue_tail(&qca->txq, skb);
878 idle_delay = msecs_to_jiffies(qca->tx_idle_delay);
879 mod_timer(&qca->tx_idle_timer, jiffies + idle_delay);
880 break;
882 case HCI_IBS_TX_ASLEEP:
883 BT_DBG("Device asleep, waking up and queueing packet");
884 /* Save packet for later */
885 skb_queue_tail(&qca->tx_wait_q, skb);
887 qca->tx_ibs_state = HCI_IBS_TX_WAKING;
888 /* Schedule a work queue to wake up device */
889 queue_work(qca->workqueue, &qca->ws_awake_device);
890 break;
892 case HCI_IBS_TX_WAKING:
893 BT_DBG("Device waking up, queueing packet");
894 /* Transient state; just keep packet for later */
895 skb_queue_tail(&qca->tx_wait_q, skb);
896 break;
898 default:
899 BT_ERR("Illegal tx state: %d (losing packet)",
900 qca->tx_ibs_state);
901 kfree_skb(skb);
902 break;
905 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
907 return 0;
910 static int qca_ibs_sleep_ind(struct hci_dev *hdev, struct sk_buff *skb)
912 struct hci_uart *hu = hci_get_drvdata(hdev);
914 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_SLEEP_IND);
916 device_want_to_sleep(hu);
918 kfree_skb(skb);
919 return 0;
922 static int qca_ibs_wake_ind(struct hci_dev *hdev, struct sk_buff *skb)
924 struct hci_uart *hu = hci_get_drvdata(hdev);
926 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_WAKE_IND);
928 device_want_to_wakeup(hu);
930 kfree_skb(skb);
931 return 0;
934 static int qca_ibs_wake_ack(struct hci_dev *hdev, struct sk_buff *skb)
936 struct hci_uart *hu = hci_get_drvdata(hdev);
938 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_WAKE_ACK);
940 device_woke_up(hu);
942 kfree_skb(skb);
943 return 0;
946 static int qca_recv_acl_data(struct hci_dev *hdev, struct sk_buff *skb)
948 /* We receive debug logs from chip as an ACL packets.
949 * Instead of sending the data to ACL to decode the
950 * received data, we are pushing them to the above layers
951 * as a diagnostic packet.
953 if (get_unaligned_le16(skb->data) == QCA_DEBUG_HANDLE)
954 return hci_recv_diag(hdev, skb);
956 return hci_recv_frame(hdev, skb);
959 static void qca_controller_memdump(struct work_struct *work)
961 struct qca_data *qca = container_of(work, struct qca_data,
962 ctrl_memdump_evt);
963 struct hci_uart *hu = qca->hu;
964 struct sk_buff *skb;
965 struct qca_memdump_event_hdr *cmd_hdr;
966 struct qca_memdump_data *qca_memdump = qca->qca_memdump;
967 struct qca_dump_size *dump;
968 char *memdump_buf;
969 char nullBuff[QCA_DUMP_PACKET_SIZE] = { 0 };
970 u16 seq_no;
971 u32 dump_size;
973 while ((skb = skb_dequeue(&qca->rx_memdump_q))) {
975 mutex_lock(&qca->hci_memdump_lock);
976 /* Skip processing the received packets if timeout detected. */
977 if (qca->memdump_state == QCA_MEMDUMP_TIMEOUT) {
978 mutex_unlock(&qca->hci_memdump_lock);
979 return;
982 if (!qca_memdump) {
983 qca_memdump = kzalloc(sizeof(struct qca_memdump_data),
984 GFP_ATOMIC);
985 if (!qca_memdump) {
986 mutex_unlock(&qca->hci_memdump_lock);
987 return;
990 qca->qca_memdump = qca_memdump;
993 qca->memdump_state = QCA_MEMDUMP_COLLECTING;
994 cmd_hdr = (void *) skb->data;
995 seq_no = __le16_to_cpu(cmd_hdr->seq_no);
996 skb_pull(skb, sizeof(struct qca_memdump_event_hdr));
998 if (!seq_no) {
1000 /* This is the first frame of memdump packet from
1001 * the controller, Disable IBS to recevie dump
1002 * with out any interruption, ideally time required for
1003 * the controller to send the dump is 8 seconds. let us
1004 * start timer to handle this asynchronous activity.
1006 clear_bit(QCA_IBS_ENABLED, &qca->flags);
1007 set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1008 dump = (void *) skb->data;
1009 dump_size = __le32_to_cpu(dump->dump_size);
1010 if (!(dump_size)) {
1011 bt_dev_err(hu->hdev, "Rx invalid memdump size");
1012 kfree_skb(skb);
1013 mutex_unlock(&qca->hci_memdump_lock);
1014 return;
1017 bt_dev_info(hu->hdev, "QCA collecting dump of size:%u",
1018 dump_size);
1019 queue_delayed_work(qca->workqueue,
1020 &qca->ctrl_memdump_timeout,
1021 msecs_to_jiffies(MEMDUMP_TIMEOUT_MS));
1023 skb_pull(skb, sizeof(dump_size));
1024 memdump_buf = vmalloc(dump_size);
1025 qca_memdump->memdump_buf_head = memdump_buf;
1026 qca_memdump->memdump_buf_tail = memdump_buf;
1029 memdump_buf = qca_memdump->memdump_buf_tail;
1031 /* If sequence no 0 is missed then there is no point in
1032 * accepting the other sequences.
1034 if (!memdump_buf) {
1035 bt_dev_err(hu->hdev, "QCA: Discarding other packets");
1036 kfree(qca_memdump);
1037 kfree_skb(skb);
1038 qca->qca_memdump = NULL;
1039 mutex_unlock(&qca->hci_memdump_lock);
1040 return;
1043 /* There could be chance of missing some packets from
1044 * the controller. In such cases let us store the dummy
1045 * packets in the buffer.
1047 while ((seq_no > qca_memdump->current_seq_no + 1) &&
1048 seq_no != QCA_LAST_SEQUENCE_NUM) {
1049 bt_dev_err(hu->hdev, "QCA controller missed packet:%d",
1050 qca_memdump->current_seq_no);
1051 memcpy(memdump_buf, nullBuff, QCA_DUMP_PACKET_SIZE);
1052 memdump_buf = memdump_buf + QCA_DUMP_PACKET_SIZE;
1053 qca_memdump->received_dump += QCA_DUMP_PACKET_SIZE;
1054 qca_memdump->current_seq_no++;
1057 memcpy(memdump_buf, (unsigned char *) skb->data, skb->len);
1058 memdump_buf = memdump_buf + skb->len;
1059 qca_memdump->memdump_buf_tail = memdump_buf;
1060 qca_memdump->current_seq_no = seq_no + 1;
1061 qca_memdump->received_dump += skb->len;
1062 qca->qca_memdump = qca_memdump;
1063 kfree_skb(skb);
1064 if (seq_no == QCA_LAST_SEQUENCE_NUM) {
1065 bt_dev_info(hu->hdev, "QCA writing crash dump of size %d bytes",
1066 qca_memdump->received_dump);
1067 memdump_buf = qca_memdump->memdump_buf_head;
1068 dev_coredumpv(&hu->serdev->dev, memdump_buf,
1069 qca_memdump->received_dump, GFP_KERNEL);
1070 cancel_delayed_work(&qca->ctrl_memdump_timeout);
1071 kfree(qca->qca_memdump);
1072 qca->qca_memdump = NULL;
1073 qca->memdump_state = QCA_MEMDUMP_COLLECTED;
1074 clear_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1077 mutex_unlock(&qca->hci_memdump_lock);
1082 static int qca_controller_memdump_event(struct hci_dev *hdev,
1083 struct sk_buff *skb)
1085 struct hci_uart *hu = hci_get_drvdata(hdev);
1086 struct qca_data *qca = hu->priv;
1088 skb_queue_tail(&qca->rx_memdump_q, skb);
1089 queue_work(qca->workqueue, &qca->ctrl_memdump_evt);
1091 return 0;
1094 static int qca_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
1096 struct hci_uart *hu = hci_get_drvdata(hdev);
1097 struct qca_data *qca = hu->priv;
1099 if (test_bit(QCA_DROP_VENDOR_EVENT, &qca->flags)) {
1100 struct hci_event_hdr *hdr = (void *)skb->data;
1102 /* For the WCN3990 the vendor command for a baudrate change
1103 * isn't sent as synchronous HCI command, because the
1104 * controller sends the corresponding vendor event with the
1105 * new baudrate. The event is received and properly decoded
1106 * after changing the baudrate of the host port. It needs to
1107 * be dropped, otherwise it can be misinterpreted as
1108 * response to a later firmware download command (also a
1109 * vendor command).
1112 if (hdr->evt == HCI_EV_VENDOR)
1113 complete(&qca->drop_ev_comp);
1115 kfree_skb(skb);
1117 return 0;
1119 /* We receive chip memory dump as an event packet, With a dedicated
1120 * handler followed by a hardware error event. When this event is
1121 * received we store dump into a file before closing hci. This
1122 * dump will help in triaging the issues.
1124 if ((skb->data[0] == HCI_VENDOR_PKT) &&
1125 (get_unaligned_be16(skb->data + 2) == QCA_SSR_DUMP_HANDLE))
1126 return qca_controller_memdump_event(hdev, skb);
1128 return hci_recv_frame(hdev, skb);
1131 #define QCA_IBS_SLEEP_IND_EVENT \
1132 .type = HCI_IBS_SLEEP_IND, \
1133 .hlen = 0, \
1134 .loff = 0, \
1135 .lsize = 0, \
1136 .maxlen = HCI_MAX_IBS_SIZE
1138 #define QCA_IBS_WAKE_IND_EVENT \
1139 .type = HCI_IBS_WAKE_IND, \
1140 .hlen = 0, \
1141 .loff = 0, \
1142 .lsize = 0, \
1143 .maxlen = HCI_MAX_IBS_SIZE
1145 #define QCA_IBS_WAKE_ACK_EVENT \
1146 .type = HCI_IBS_WAKE_ACK, \
1147 .hlen = 0, \
1148 .loff = 0, \
1149 .lsize = 0, \
1150 .maxlen = HCI_MAX_IBS_SIZE
1152 static const struct h4_recv_pkt qca_recv_pkts[] = {
1153 { H4_RECV_ACL, .recv = qca_recv_acl_data },
1154 { H4_RECV_SCO, .recv = hci_recv_frame },
1155 { H4_RECV_EVENT, .recv = qca_recv_event },
1156 { QCA_IBS_WAKE_IND_EVENT, .recv = qca_ibs_wake_ind },
1157 { QCA_IBS_WAKE_ACK_EVENT, .recv = qca_ibs_wake_ack },
1158 { QCA_IBS_SLEEP_IND_EVENT, .recv = qca_ibs_sleep_ind },
1161 static int qca_recv(struct hci_uart *hu, const void *data, int count)
1163 struct qca_data *qca = hu->priv;
1165 if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
1166 return -EUNATCH;
1168 qca->rx_skb = h4_recv_buf(hu->hdev, qca->rx_skb, data, count,
1169 qca_recv_pkts, ARRAY_SIZE(qca_recv_pkts));
1170 if (IS_ERR(qca->rx_skb)) {
1171 int err = PTR_ERR(qca->rx_skb);
1172 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
1173 qca->rx_skb = NULL;
1174 return err;
1177 return count;
1180 static struct sk_buff *qca_dequeue(struct hci_uart *hu)
1182 struct qca_data *qca = hu->priv;
1184 return skb_dequeue(&qca->txq);
1187 static uint8_t qca_get_baudrate_value(int speed)
1189 switch (speed) {
1190 case 9600:
1191 return QCA_BAUDRATE_9600;
1192 case 19200:
1193 return QCA_BAUDRATE_19200;
1194 case 38400:
1195 return QCA_BAUDRATE_38400;
1196 case 57600:
1197 return QCA_BAUDRATE_57600;
1198 case 115200:
1199 return QCA_BAUDRATE_115200;
1200 case 230400:
1201 return QCA_BAUDRATE_230400;
1202 case 460800:
1203 return QCA_BAUDRATE_460800;
1204 case 500000:
1205 return QCA_BAUDRATE_500000;
1206 case 921600:
1207 return QCA_BAUDRATE_921600;
1208 case 1000000:
1209 return QCA_BAUDRATE_1000000;
1210 case 2000000:
1211 return QCA_BAUDRATE_2000000;
1212 case 3000000:
1213 return QCA_BAUDRATE_3000000;
1214 case 3200000:
1215 return QCA_BAUDRATE_3200000;
1216 case 3500000:
1217 return QCA_BAUDRATE_3500000;
1218 default:
1219 return QCA_BAUDRATE_115200;
1223 static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
1225 struct hci_uart *hu = hci_get_drvdata(hdev);
1226 struct qca_data *qca = hu->priv;
1227 struct sk_buff *skb;
1228 u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
1230 if (baudrate > QCA_BAUDRATE_3200000)
1231 return -EINVAL;
1233 cmd[4] = baudrate;
1235 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
1236 if (!skb) {
1237 bt_dev_err(hdev, "Failed to allocate baudrate packet");
1238 return -ENOMEM;
1241 /* Assign commands to change baudrate and packet type. */
1242 skb_put_data(skb, cmd, sizeof(cmd));
1243 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
1245 skb_queue_tail(&qca->txq, skb);
1246 hci_uart_tx_wakeup(hu);
1248 /* Wait for the baudrate change request to be sent */
1250 while (!skb_queue_empty(&qca->txq))
1251 usleep_range(100, 200);
1253 if (hu->serdev)
1254 serdev_device_wait_until_sent(hu->serdev,
1255 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS));
1257 /* Give the controller time to process the request */
1258 if (qca_is_wcn399x(qca_soc_type(hu)))
1259 msleep(10);
1260 else
1261 msleep(300);
1263 return 0;
1266 static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
1268 if (hu->serdev)
1269 serdev_device_set_baudrate(hu->serdev, speed);
1270 else
1271 hci_uart_set_baudrate(hu, speed);
1274 static int qca_send_power_pulse(struct hci_uart *hu, bool on)
1276 int ret;
1277 int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
1278 u8 cmd = on ? QCA_WCN3990_POWERON_PULSE : QCA_WCN3990_POWEROFF_PULSE;
1280 /* These power pulses are single byte command which are sent
1281 * at required baudrate to wcn3990. On wcn3990, we have an external
1282 * circuit at Tx pin which decodes the pulse sent at specific baudrate.
1283 * For example, wcn3990 supports RF COEX antenna for both Wi-Fi/BT
1284 * and also we use the same power inputs to turn on and off for
1285 * Wi-Fi/BT. Powering up the power sources will not enable BT, until
1286 * we send a power on pulse at 115200 bps. This algorithm will help to
1287 * save power. Disabling hardware flow control is mandatory while
1288 * sending power pulses to SoC.
1290 bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd);
1292 serdev_device_write_flush(hu->serdev);
1293 hci_uart_set_flow_control(hu, true);
1294 ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
1295 if (ret < 0) {
1296 bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
1297 return ret;
1300 serdev_device_wait_until_sent(hu->serdev, timeout);
1301 hci_uart_set_flow_control(hu, false);
1303 /* Give to controller time to boot/shutdown */
1304 if (on)
1305 msleep(100);
1306 else
1307 msleep(10);
1309 return 0;
1312 static unsigned int qca_get_speed(struct hci_uart *hu,
1313 enum qca_speed_type speed_type)
1315 unsigned int speed = 0;
1317 if (speed_type == QCA_INIT_SPEED) {
1318 if (hu->init_speed)
1319 speed = hu->init_speed;
1320 else if (hu->proto->init_speed)
1321 speed = hu->proto->init_speed;
1322 } else {
1323 if (hu->oper_speed)
1324 speed = hu->oper_speed;
1325 else if (hu->proto->oper_speed)
1326 speed = hu->proto->oper_speed;
1329 return speed;
1332 static int qca_check_speeds(struct hci_uart *hu)
1334 if (qca_is_wcn399x(qca_soc_type(hu))) {
1335 if (!qca_get_speed(hu, QCA_INIT_SPEED) &&
1336 !qca_get_speed(hu, QCA_OPER_SPEED))
1337 return -EINVAL;
1338 } else {
1339 if (!qca_get_speed(hu, QCA_INIT_SPEED) ||
1340 !qca_get_speed(hu, QCA_OPER_SPEED))
1341 return -EINVAL;
1344 return 0;
1347 static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
1349 unsigned int speed, qca_baudrate;
1350 struct qca_data *qca = hu->priv;
1351 int ret = 0;
1353 if (speed_type == QCA_INIT_SPEED) {
1354 speed = qca_get_speed(hu, QCA_INIT_SPEED);
1355 if (speed)
1356 host_set_baudrate(hu, speed);
1357 } else {
1358 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1360 speed = qca_get_speed(hu, QCA_OPER_SPEED);
1361 if (!speed)
1362 return 0;
1364 /* Disable flow control for wcn3990 to deassert RTS while
1365 * changing the baudrate of chip and host.
1367 if (qca_is_wcn399x(soc_type))
1368 hci_uart_set_flow_control(hu, true);
1370 if (soc_type == QCA_WCN3990) {
1371 reinit_completion(&qca->drop_ev_comp);
1372 set_bit(QCA_DROP_VENDOR_EVENT, &qca->flags);
1375 qca_baudrate = qca_get_baudrate_value(speed);
1376 bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed);
1377 ret = qca_set_baudrate(hu->hdev, qca_baudrate);
1378 if (ret)
1379 goto error;
1381 host_set_baudrate(hu, speed);
1383 error:
1384 if (qca_is_wcn399x(soc_type))
1385 hci_uart_set_flow_control(hu, false);
1387 if (soc_type == QCA_WCN3990) {
1388 /* Wait for the controller to send the vendor event
1389 * for the baudrate change command.
1391 if (!wait_for_completion_timeout(&qca->drop_ev_comp,
1392 msecs_to_jiffies(100))) {
1393 bt_dev_err(hu->hdev,
1394 "Failed to change controller baudrate\n");
1395 ret = -ETIMEDOUT;
1398 clear_bit(QCA_DROP_VENDOR_EVENT, &qca->flags);
1402 return ret;
1405 static int qca_send_crashbuffer(struct hci_uart *hu)
1407 struct qca_data *qca = hu->priv;
1408 struct sk_buff *skb;
1410 skb = bt_skb_alloc(QCA_CRASHBYTE_PACKET_LEN, GFP_KERNEL);
1411 if (!skb) {
1412 bt_dev_err(hu->hdev, "Failed to allocate memory for skb packet");
1413 return -ENOMEM;
1416 /* We forcefully crash the controller, by sending 0xfb byte for
1417 * 1024 times. We also might have chance of losing data, To be
1418 * on safer side we send 1096 bytes to the SoC.
1420 memset(skb_put(skb, QCA_CRASHBYTE_PACKET_LEN), QCA_MEMDUMP_BYTE,
1421 QCA_CRASHBYTE_PACKET_LEN);
1422 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
1423 bt_dev_info(hu->hdev, "crash the soc to collect controller dump");
1424 skb_queue_tail(&qca->txq, skb);
1425 hci_uart_tx_wakeup(hu);
1427 return 0;
1430 static void qca_wait_for_dump_collection(struct hci_dev *hdev)
1432 struct hci_uart *hu = hci_get_drvdata(hdev);
1433 struct qca_data *qca = hu->priv;
1435 wait_on_bit_timeout(&qca->flags, QCA_MEMDUMP_COLLECTION,
1436 TASK_UNINTERRUPTIBLE, MEMDUMP_TIMEOUT_MS);
1438 clear_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1441 static void qca_hw_error(struct hci_dev *hdev, u8 code)
1443 struct hci_uart *hu = hci_get_drvdata(hdev);
1444 struct qca_data *qca = hu->priv;
1445 struct qca_memdump_data *qca_memdump = qca->qca_memdump;
1446 char *memdump_buf = NULL;
1448 set_bit(QCA_HW_ERROR_EVENT, &qca->flags);
1449 bt_dev_info(hdev, "mem_dump_status: %d", qca->memdump_state);
1451 if (qca->memdump_state == QCA_MEMDUMP_IDLE) {
1452 /* If hardware error event received for other than QCA
1453 * soc memory dump event, then we need to crash the SOC
1454 * and wait here for 8 seconds to get the dump packets.
1455 * This will block main thread to be on hold until we
1456 * collect dump.
1458 set_bit(QCA_MEMDUMP_COLLECTION, &qca->flags);
1459 qca_send_crashbuffer(hu);
1460 qca_wait_for_dump_collection(hdev);
1461 } else if (qca->memdump_state == QCA_MEMDUMP_COLLECTING) {
1462 /* Let us wait here until memory dump collected or
1463 * memory dump timer expired.
1465 bt_dev_info(hdev, "waiting for dump to complete");
1466 qca_wait_for_dump_collection(hdev);
1469 if (qca->memdump_state != QCA_MEMDUMP_COLLECTED) {
1470 bt_dev_err(hu->hdev, "clearing allocated memory due to memdump timeout");
1471 mutex_lock(&qca->hci_memdump_lock);
1472 if (qca_memdump)
1473 memdump_buf = qca_memdump->memdump_buf_head;
1474 vfree(memdump_buf);
1475 kfree(qca_memdump);
1476 qca->qca_memdump = NULL;
1477 qca->memdump_state = QCA_MEMDUMP_TIMEOUT;
1478 cancel_delayed_work(&qca->ctrl_memdump_timeout);
1479 skb_queue_purge(&qca->rx_memdump_q);
1480 mutex_unlock(&qca->hci_memdump_lock);
1481 cancel_work_sync(&qca->ctrl_memdump_evt);
1484 clear_bit(QCA_HW_ERROR_EVENT, &qca->flags);
1487 static void qca_cmd_timeout(struct hci_dev *hdev)
1489 struct hci_uart *hu = hci_get_drvdata(hdev);
1490 struct qca_data *qca = hu->priv;
1492 if (qca->memdump_state == QCA_MEMDUMP_IDLE)
1493 qca_send_crashbuffer(hu);
1494 else
1495 bt_dev_info(hdev, "Dump collection is in process");
1498 static int qca_wcn3990_init(struct hci_uart *hu)
1500 struct qca_serdev *qcadev;
1501 int ret;
1503 /* Check for vregs status, may be hci down has turned
1504 * off the voltage regulator.
1506 qcadev = serdev_device_get_drvdata(hu->serdev);
1507 if (!qcadev->bt_power->vregs_on) {
1508 serdev_device_close(hu->serdev);
1509 ret = qca_regulator_enable(qcadev);
1510 if (ret)
1511 return ret;
1513 ret = serdev_device_open(hu->serdev);
1514 if (ret) {
1515 bt_dev_err(hu->hdev, "failed to open port");
1516 return ret;
1520 /* Forcefully enable wcn3990 to enter in to boot mode. */
1521 host_set_baudrate(hu, 2400);
1522 ret = qca_send_power_pulse(hu, false);
1523 if (ret)
1524 return ret;
1526 qca_set_speed(hu, QCA_INIT_SPEED);
1527 ret = qca_send_power_pulse(hu, true);
1528 if (ret)
1529 return ret;
1531 /* Now the device is in ready state to communicate with host.
1532 * To sync host with device we need to reopen port.
1533 * Without this, we will have RTS and CTS synchronization
1534 * issues.
1536 serdev_device_close(hu->serdev);
1537 ret = serdev_device_open(hu->serdev);
1538 if (ret) {
1539 bt_dev_err(hu->hdev, "failed to open port");
1540 return ret;
1543 hci_uart_set_flow_control(hu, false);
1545 return 0;
1548 static int qca_power_on(struct hci_dev *hdev)
1550 struct hci_uart *hu = hci_get_drvdata(hdev);
1551 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1552 struct qca_serdev *qcadev;
1553 int ret = 0;
1555 /* Non-serdev device usually is powered by external power
1556 * and don't need additional action in driver for power on
1558 if (!hu->serdev)
1559 return 0;
1561 if (qca_is_wcn399x(soc_type)) {
1562 ret = qca_wcn3990_init(hu);
1563 } else {
1564 qcadev = serdev_device_get_drvdata(hu->serdev);
1565 if (qcadev->bt_en) {
1566 gpiod_set_value_cansleep(qcadev->bt_en, 1);
1567 /* Controller needs time to bootup. */
1568 msleep(150);
1572 return ret;
1575 static int qca_setup(struct hci_uart *hu)
1577 struct hci_dev *hdev = hu->hdev;
1578 struct qca_data *qca = hu->priv;
1579 unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200;
1580 unsigned int retries = 0;
1581 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1582 const char *firmware_name = qca_get_firmware_name(hu);
1583 int ret;
1584 int soc_ver = 0;
1586 ret = qca_check_speeds(hu);
1587 if (ret)
1588 return ret;
1590 /* Patch downloading has to be done without IBS mode */
1591 clear_bit(QCA_IBS_ENABLED, &qca->flags);
1593 /* Enable controller to do both LE scan and BR/EDR inquiry
1594 * simultaneously.
1596 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
1598 bt_dev_info(hdev, "setting up %s",
1599 qca_is_wcn399x(soc_type) ? "wcn399x" : "ROME");
1601 retry:
1602 ret = qca_power_on(hdev);
1603 if (ret)
1604 return ret;
1606 if (qca_is_wcn399x(soc_type)) {
1607 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
1609 ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
1610 if (ret)
1611 return ret;
1612 } else {
1613 qca_set_speed(hu, QCA_INIT_SPEED);
1616 /* Setup user speed if needed */
1617 speed = qca_get_speed(hu, QCA_OPER_SPEED);
1618 if (speed) {
1619 ret = qca_set_speed(hu, QCA_OPER_SPEED);
1620 if (ret)
1621 return ret;
1623 qca_baudrate = qca_get_baudrate_value(speed);
1626 if (!qca_is_wcn399x(soc_type)) {
1627 /* Get QCA version information */
1628 ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
1629 if (ret)
1630 return ret;
1633 bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
1634 /* Setup patch / NVM configurations */
1635 ret = qca_uart_setup(hdev, qca_baudrate, soc_type, soc_ver,
1636 firmware_name);
1637 if (!ret) {
1638 set_bit(QCA_IBS_ENABLED, &qca->flags);
1639 qca_debugfs_init(hdev);
1640 hu->hdev->hw_error = qca_hw_error;
1641 hu->hdev->cmd_timeout = qca_cmd_timeout;
1642 } else if (ret == -ENOENT) {
1643 /* No patch/nvm-config found, run with original fw/config */
1644 ret = 0;
1645 } else if (ret == -EAGAIN) {
1647 * Userspace firmware loader will return -EAGAIN in case no
1648 * patch/nvm-config is found, so run with original fw/config.
1650 ret = 0;
1651 } else {
1652 if (retries < MAX_INIT_RETRIES) {
1653 qca_power_shutdown(hu);
1654 if (hu->serdev) {
1655 serdev_device_close(hu->serdev);
1656 ret = serdev_device_open(hu->serdev);
1657 if (ret) {
1658 bt_dev_err(hdev, "failed to open port");
1659 return ret;
1662 retries++;
1663 goto retry;
1667 /* Setup bdaddr */
1668 if (qca_is_wcn399x(soc_type))
1669 hu->hdev->set_bdaddr = qca_set_bdaddr;
1670 else
1671 hu->hdev->set_bdaddr = qca_set_bdaddr_rome;
1673 return ret;
1676 static const struct hci_uart_proto qca_proto = {
1677 .id = HCI_UART_QCA,
1678 .name = "QCA",
1679 .manufacturer = 29,
1680 .init_speed = 115200,
1681 .oper_speed = 3000000,
1682 .open = qca_open,
1683 .close = qca_close,
1684 .flush = qca_flush,
1685 .setup = qca_setup,
1686 .recv = qca_recv,
1687 .enqueue = qca_enqueue,
1688 .dequeue = qca_dequeue,
1691 static const struct qca_vreg_data qca_soc_data_wcn3990 = {
1692 .soc_type = QCA_WCN3990,
1693 .vregs = (struct qca_vreg []) {
1694 { "vddio", 15000 },
1695 { "vddxo", 80000 },
1696 { "vddrf", 300000 },
1697 { "vddch0", 450000 },
1699 .num_vregs = 4,
1702 static const struct qca_vreg_data qca_soc_data_wcn3991 = {
1703 .soc_type = QCA_WCN3991,
1704 .vregs = (struct qca_vreg []) {
1705 { "vddio", 15000 },
1706 { "vddxo", 80000 },
1707 { "vddrf", 300000 },
1708 { "vddch0", 450000 },
1710 .num_vregs = 4,
1713 static const struct qca_vreg_data qca_soc_data_wcn3998 = {
1714 .soc_type = QCA_WCN3998,
1715 .vregs = (struct qca_vreg []) {
1716 { "vddio", 10000 },
1717 { "vddxo", 80000 },
1718 { "vddrf", 300000 },
1719 { "vddch0", 450000 },
1721 .num_vregs = 4,
1724 static void qca_power_shutdown(struct hci_uart *hu)
1726 struct qca_serdev *qcadev;
1727 struct qca_data *qca = hu->priv;
1728 unsigned long flags;
1729 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1731 qcadev = serdev_device_get_drvdata(hu->serdev);
1733 /* From this point we go into power off state. But serial port is
1734 * still open, stop queueing the IBS data and flush all the buffered
1735 * data in skb's.
1737 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
1738 clear_bit(QCA_IBS_ENABLED, &qca->flags);
1739 qca_flush(hu);
1740 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
1742 hu->hdev->hw_error = NULL;
1743 hu->hdev->cmd_timeout = NULL;
1745 /* Non-serdev device usually is powered by external power
1746 * and don't need additional action in driver for power down
1748 if (!hu->serdev)
1749 return;
1751 if (qca_is_wcn399x(soc_type)) {
1752 host_set_baudrate(hu, 2400);
1753 qca_send_power_pulse(hu, false);
1754 qca_regulator_disable(qcadev);
1755 } else if (qcadev->bt_en) {
1756 gpiod_set_value_cansleep(qcadev->bt_en, 0);
1760 static int qca_power_off(struct hci_dev *hdev)
1762 struct hci_uart *hu = hci_get_drvdata(hdev);
1763 struct qca_data *qca = hu->priv;
1764 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1766 /* Stop sending shutdown command if soc crashes. */
1767 if (qca_is_wcn399x(soc_type)
1768 && qca->memdump_state == QCA_MEMDUMP_IDLE) {
1769 qca_send_pre_shutdown_cmd(hdev);
1770 usleep_range(8000, 10000);
1773 qca->memdump_state = QCA_MEMDUMP_IDLE;
1774 qca_power_shutdown(hu);
1775 return 0;
1778 static int qca_regulator_enable(struct qca_serdev *qcadev)
1780 struct qca_power *power = qcadev->bt_power;
1781 int ret;
1783 /* Already enabled */
1784 if (power->vregs_on)
1785 return 0;
1787 BT_DBG("enabling %d regulators)", power->num_vregs);
1789 ret = regulator_bulk_enable(power->num_vregs, power->vreg_bulk);
1790 if (ret)
1791 return ret;
1793 power->vregs_on = true;
1795 ret = clk_prepare_enable(qcadev->susclk);
1796 if (ret)
1797 qca_regulator_disable(qcadev);
1799 return ret;
1802 static void qca_regulator_disable(struct qca_serdev *qcadev)
1804 struct qca_power *power;
1806 if (!qcadev)
1807 return;
1809 power = qcadev->bt_power;
1811 /* Already disabled? */
1812 if (!power->vregs_on)
1813 return;
1815 regulator_bulk_disable(power->num_vregs, power->vreg_bulk);
1816 power->vregs_on = false;
1818 clk_disable_unprepare(qcadev->susclk);
1821 static int qca_init_regulators(struct qca_power *qca,
1822 const struct qca_vreg *vregs, size_t num_vregs)
1824 struct regulator_bulk_data *bulk;
1825 int ret;
1826 int i;
1828 bulk = devm_kcalloc(qca->dev, num_vregs, sizeof(*bulk), GFP_KERNEL);
1829 if (!bulk)
1830 return -ENOMEM;
1832 for (i = 0; i < num_vregs; i++)
1833 bulk[i].supply = vregs[i].name;
1835 ret = devm_regulator_bulk_get(qca->dev, num_vregs, bulk);
1836 if (ret < 0)
1837 return ret;
1839 for (i = 0; i < num_vregs; i++) {
1840 ret = regulator_set_load(bulk[i].consumer, vregs[i].load_uA);
1841 if (ret)
1842 return ret;
1845 qca->vreg_bulk = bulk;
1846 qca->num_vregs = num_vregs;
1848 return 0;
1851 static int qca_serdev_probe(struct serdev_device *serdev)
1853 struct qca_serdev *qcadev;
1854 struct hci_dev *hdev;
1855 const struct qca_vreg_data *data;
1856 int err;
1857 bool power_ctrl_enabled = true;
1859 qcadev = devm_kzalloc(&serdev->dev, sizeof(*qcadev), GFP_KERNEL);
1860 if (!qcadev)
1861 return -ENOMEM;
1863 qcadev->serdev_hu.serdev = serdev;
1864 data = device_get_match_data(&serdev->dev);
1865 serdev_device_set_drvdata(serdev, qcadev);
1866 device_property_read_string(&serdev->dev, "firmware-name",
1867 &qcadev->firmware_name);
1868 if (data && qca_is_wcn399x(data->soc_type)) {
1869 qcadev->btsoc_type = data->soc_type;
1870 qcadev->bt_power = devm_kzalloc(&serdev->dev,
1871 sizeof(struct qca_power),
1872 GFP_KERNEL);
1873 if (!qcadev->bt_power)
1874 return -ENOMEM;
1876 qcadev->bt_power->dev = &serdev->dev;
1877 err = qca_init_regulators(qcadev->bt_power, data->vregs,
1878 data->num_vregs);
1879 if (err) {
1880 BT_ERR("Failed to init regulators:%d", err);
1881 return err;
1884 qcadev->bt_power->vregs_on = false;
1886 qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
1887 if (IS_ERR(qcadev->susclk)) {
1888 dev_err(&serdev->dev, "failed to acquire clk\n");
1889 return PTR_ERR(qcadev->susclk);
1892 device_property_read_u32(&serdev->dev, "max-speed",
1893 &qcadev->oper_speed);
1894 if (!qcadev->oper_speed)
1895 BT_DBG("UART will pick default operating speed");
1897 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
1898 if (err) {
1899 BT_ERR("wcn3990 serdev registration failed");
1900 return err;
1902 } else {
1903 qcadev->btsoc_type = QCA_ROME;
1904 qcadev->bt_en = devm_gpiod_get_optional(&serdev->dev, "enable",
1905 GPIOD_OUT_LOW);
1906 if (!qcadev->bt_en) {
1907 dev_warn(&serdev->dev, "failed to acquire enable gpio\n");
1908 power_ctrl_enabled = false;
1911 qcadev->susclk = devm_clk_get_optional(&serdev->dev, NULL);
1912 if (!qcadev->susclk) {
1913 dev_warn(&serdev->dev, "failed to acquire clk\n");
1914 } else {
1915 err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ);
1916 if (err)
1917 return err;
1919 err = clk_prepare_enable(qcadev->susclk);
1920 if (err)
1921 return err;
1924 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
1925 if (err) {
1926 BT_ERR("Rome serdev registration failed");
1927 if (qcadev->susclk)
1928 clk_disable_unprepare(qcadev->susclk);
1929 return err;
1933 if (power_ctrl_enabled) {
1934 hdev = qcadev->serdev_hu.hdev;
1935 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
1936 hdev->shutdown = qca_power_off;
1939 return 0;
1942 static void qca_serdev_remove(struct serdev_device *serdev)
1944 struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
1946 if (qca_is_wcn399x(qcadev->btsoc_type))
1947 qca_power_shutdown(&qcadev->serdev_hu);
1948 else if (qcadev->susclk)
1949 clk_disable_unprepare(qcadev->susclk);
1951 hci_uart_unregister_device(&qcadev->serdev_hu);
1954 static int __maybe_unused qca_suspend(struct device *dev)
1956 struct serdev_device *serdev = to_serdev_device(dev);
1957 struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
1958 struct hci_uart *hu = &qcadev->serdev_hu;
1959 struct qca_data *qca = hu->priv;
1960 unsigned long flags;
1961 int ret = 0;
1962 u8 cmd;
1964 set_bit(QCA_SUSPENDING, &qca->flags);
1966 /* Device is downloading patch or doesn't support in-band sleep. */
1967 if (!test_bit(QCA_IBS_ENABLED, &qca->flags))
1968 return 0;
1970 cancel_work_sync(&qca->ws_awake_device);
1971 cancel_work_sync(&qca->ws_awake_rx);
1973 spin_lock_irqsave_nested(&qca->hci_ibs_lock,
1974 flags, SINGLE_DEPTH_NESTING);
1976 switch (qca->tx_ibs_state) {
1977 case HCI_IBS_TX_WAKING:
1978 del_timer(&qca->wake_retrans_timer);
1979 /* Fall through */
1980 case HCI_IBS_TX_AWAKE:
1981 del_timer(&qca->tx_idle_timer);
1983 serdev_device_write_flush(hu->serdev);
1984 cmd = HCI_IBS_SLEEP_IND;
1985 ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
1987 if (ret < 0) {
1988 BT_ERR("Failed to send SLEEP to device");
1989 break;
1992 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
1993 qca->ibs_sent_slps++;
1995 qca_wq_serial_tx_clock_vote_off(&qca->ws_tx_vote_off);
1996 break;
1998 case HCI_IBS_TX_ASLEEP:
1999 break;
2001 default:
2002 BT_ERR("Spurious tx state %d", qca->tx_ibs_state);
2003 ret = -EINVAL;
2004 break;
2007 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
2009 if (ret < 0)
2010 goto error;
2012 serdev_device_wait_until_sent(hu->serdev,
2013 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS));
2015 /* Wait for HCI_IBS_SLEEP_IND sent by device to indicate its Tx is going
2016 * to sleep, so that the packet does not wake the system later.
2019 ret = wait_event_interruptible_timeout(qca->suspend_wait_q,
2020 qca->rx_ibs_state == HCI_IBS_RX_ASLEEP,
2021 msecs_to_jiffies(IBS_BTSOC_TX_IDLE_TIMEOUT_MS));
2023 if (ret > 0)
2024 return 0;
2026 if (ret == 0)
2027 ret = -ETIMEDOUT;
2029 error:
2030 clear_bit(QCA_SUSPENDING, &qca->flags);
2032 return ret;
2035 static int __maybe_unused qca_resume(struct device *dev)
2037 struct serdev_device *serdev = to_serdev_device(dev);
2038 struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
2039 struct hci_uart *hu = &qcadev->serdev_hu;
2040 struct qca_data *qca = hu->priv;
2042 clear_bit(QCA_SUSPENDING, &qca->flags);
2044 return 0;
2047 static SIMPLE_DEV_PM_OPS(qca_pm_ops, qca_suspend, qca_resume);
2049 static const struct of_device_id qca_bluetooth_of_match[] = {
2050 { .compatible = "qcom,qca6174-bt" },
2051 { .compatible = "qcom,wcn3990-bt", .data = &qca_soc_data_wcn3990},
2052 { .compatible = "qcom,wcn3991-bt", .data = &qca_soc_data_wcn3991},
2053 { .compatible = "qcom,wcn3998-bt", .data = &qca_soc_data_wcn3998},
2054 { /* sentinel */ }
2056 MODULE_DEVICE_TABLE(of, qca_bluetooth_of_match);
2058 static struct serdev_device_driver qca_serdev_driver = {
2059 .probe = qca_serdev_probe,
2060 .remove = qca_serdev_remove,
2061 .driver = {
2062 .name = "hci_uart_qca",
2063 .of_match_table = qca_bluetooth_of_match,
2064 .pm = &qca_pm_ops,
2068 int __init qca_init(void)
2070 serdev_device_driver_register(&qca_serdev_driver);
2072 return hci_uart_register_proto(&qca_proto);
2075 int __exit qca_deinit(void)
2077 serdev_device_driver_unregister(&qca_serdev_driver);
2079 return hci_uart_unregister_proto(&qca_proto);