blob: 9d273cdde5639aa39de4d8589814ed4c60a66b18 [file] [log] [blame]
Thomas Gleixner45051532019-05-29 16:57:47 -07001// SPDX-License-Identifier: GPL-2.0-only
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07002/*
3 * Bluetooth Software UART Qualcomm protocol
4 *
5 * HCI_IBS (HCI In-Band Sleep) is Qualcomm's power management
6 * protocol extension to H4.
7 *
8 * Copyright (C) 2007 Texas Instruments, Inc.
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05309 * Copyright (c) 2010, 2012, 2018 The Linux Foundation. All rights reserved.
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070010 *
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.
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070016 */
17
18#include <linux/kernel.h>
Thierry Escande05ba5332018-03-29 21:15:24 +020019#include <linux/clk.h>
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070020#include <linux/debugfs.h>
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +053021#include <linux/delay.h>
22#include <linux/device.h>
Thierry Escande05ba5332018-03-29 21:15:24 +020023#include <linux/gpio/consumer.h>
24#include <linux/mod_devicetable.h>
25#include <linux/module.h>
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +053026#include <linux/of_device.h>
27#include <linux/platform_device.h>
28#include <linux/regulator/consumer.h>
Thierry Escande05ba5332018-03-29 21:15:24 +020029#include <linux/serdev.h>
Balakrishna Godavarthic614ca32018-10-16 19:51:35 +053030#include <asm/unaligned.h>
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070031
32#include <net/bluetooth/bluetooth.h>
33#include <net/bluetooth/hci_core.h>
34
35#include "hci_uart.h"
36#include "btqca.h"
37
38/* HCI_IBS protocol messages */
39#define HCI_IBS_SLEEP_IND 0xFE
40#define HCI_IBS_WAKE_IND 0xFD
41#define HCI_IBS_WAKE_ACK 0xFC
Marcel Holtmannf81b0012015-08-30 23:05:32 +020042#define HCI_MAX_IBS_SIZE 10
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070043
Marcel Holtmannf81b0012015-08-30 23:05:32 +020044#define IBS_WAKE_RETRANS_TIMEOUT_MS 100
45#define IBS_TX_IDLE_TIMEOUT_MS 2000
Matthias Kaehlcke94d66712019-02-27 15:52:23 -080046#define CMD_TRANS_TIMEOUT_MS 100
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070047
Thierry Escande05ba5332018-03-29 21:15:24 +020048/* susclk rate */
49#define SUSCLK_RATE_32KHZ 32768
50
Balakrishna Godavarthic614ca32018-10-16 19:51:35 +053051/* Controller debug log header */
52#define QCA_DEBUG_HANDLE 0x2EDC
53
Matthias Kaehlcke62a91992019-04-29 16:21:30 -070054enum qca_flags {
55 QCA_IBS_ENABLED,
56};
57
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070058/* HCI_IBS transmit side sleep protocol states */
59enum tx_ibs_states {
60 HCI_IBS_TX_ASLEEP,
61 HCI_IBS_TX_WAKING,
62 HCI_IBS_TX_AWAKE,
63};
64
65/* HCI_IBS receive side sleep protocol states */
66enum rx_states {
67 HCI_IBS_RX_ASLEEP,
68 HCI_IBS_RX_AWAKE,
69};
70
71/* HCI_IBS transmit and receive side clock state vote */
72enum hci_ibs_clock_state_vote {
73 HCI_IBS_VOTE_STATS_UPDATE,
74 HCI_IBS_TX_VOTE_CLOCK_ON,
75 HCI_IBS_TX_VOTE_CLOCK_OFF,
76 HCI_IBS_RX_VOTE_CLOCK_ON,
77 HCI_IBS_RX_VOTE_CLOCK_OFF,
78};
79
80struct qca_data {
81 struct hci_uart *hu;
82 struct sk_buff *rx_skb;
83 struct sk_buff_head txq;
84 struct sk_buff_head tx_wait_q; /* HCI_IBS wait queue */
85 spinlock_t hci_ibs_lock; /* HCI_IBS state lock */
86 u8 tx_ibs_state; /* HCI_IBS transmit side power state*/
87 u8 rx_ibs_state; /* HCI_IBS receive side power state */
Viresh Kumar621a5f72015-09-26 15:04:07 -070088 bool tx_vote; /* Clock must be on for TX */
89 bool rx_vote; /* Clock must be on for RX */
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070090 struct timer_list tx_idle_timer;
91 u32 tx_idle_delay;
92 struct timer_list wake_retrans_timer;
93 u32 wake_retrans;
94 struct workqueue_struct *workqueue;
95 struct work_struct ws_awake_rx;
96 struct work_struct ws_awake_device;
97 struct work_struct ws_rx_vote_off;
98 struct work_struct ws_tx_vote_off;
99 unsigned long flags;
100
101 /* For debugging purpose */
102 u64 ibs_sent_wacks;
103 u64 ibs_sent_slps;
104 u64 ibs_sent_wakes;
105 u64 ibs_recv_wacks;
106 u64 ibs_recv_slps;
107 u64 ibs_recv_wakes;
108 u64 vote_last_jif;
109 u32 vote_on_ms;
110 u32 vote_off_ms;
111 u64 tx_votes_on;
112 u64 rx_votes_on;
113 u64 tx_votes_off;
114 u64 rx_votes_off;
115 u64 votes_on;
116 u64 votes_off;
117};
118
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +0530119enum qca_speed_type {
120 QCA_INIT_SPEED = 1,
121 QCA_OPER_SPEED
122};
123
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530124/*
125 * Voltage regulator information required for configuring the
126 * QCA Bluetooth chipset
127 */
128struct qca_vreg {
129 const char *name;
130 unsigned int min_uV;
131 unsigned int max_uV;
132 unsigned int load_uA;
133};
134
135struct qca_vreg_data {
136 enum qca_btsoc_type soc_type;
137 struct qca_vreg *vregs;
138 size_t num_vregs;
139};
140
141/*
142 * Platform data for the QCA Bluetooth power driver.
143 */
144struct qca_power {
145 struct device *dev;
146 const struct qca_vreg_data *vreg_data;
147 struct regulator_bulk_data *vreg_bulk;
148 bool vregs_on;
149};
150
Thierry Escande05ba5332018-03-29 21:15:24 +0200151struct qca_serdev {
152 struct hci_uart serdev_hu;
153 struct gpio_desc *bt_en;
154 struct clk *susclk;
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530155 enum qca_btsoc_type btsoc_type;
156 struct qca_power *bt_power;
157 u32 init_speed;
158 u32 oper_speed;
Thierry Escande05ba5332018-03-29 21:15:24 +0200159};
160
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530161static int qca_power_setup(struct hci_uart *hu, bool on);
Balakrishna Godavarthic2d78272018-08-22 17:50:05 +0530162static void qca_power_shutdown(struct hci_uart *hu);
Balakrishna Godavarthi3e4be652018-09-24 20:14:45 +0530163static int qca_power_off(struct hci_dev *hdev);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530164
Matthias Kaehlcke4fdd5a42019-03-11 11:38:31 -0700165static enum qca_btsoc_type qca_soc_type(struct hci_uart *hu)
166{
167 enum qca_btsoc_type soc_type;
168
169 if (hu->serdev) {
170 struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev);
171
172 soc_type = qsd->btsoc_type;
173 } else {
174 soc_type = QCA_ROME;
175 }
176
177 return soc_type;
178}
179
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700180static void __serial_clock_on(struct tty_struct *tty)
181{
182 /* TODO: Some chipset requires to enable UART clock on client
183 * side to save power consumption or manual work is required.
184 * Please put your code to control UART clock here if needed
185 */
186}
187
188static void __serial_clock_off(struct tty_struct *tty)
189{
190 /* TODO: Some chipset requires to disable UART clock on client
191 * side to save power consumption or manual work is required.
192 * Please put your code to control UART clock off here if needed
193 */
194}
195
196/* serial_clock_vote needs to be called with the ibs lock held */
197static void serial_clock_vote(unsigned long vote, struct hci_uart *hu)
198{
199 struct qca_data *qca = hu->priv;
200 unsigned int diff;
201
202 bool old_vote = (qca->tx_vote | qca->rx_vote);
203 bool new_vote;
204
205 switch (vote) {
206 case HCI_IBS_VOTE_STATS_UPDATE:
207 diff = jiffies_to_msecs(jiffies - qca->vote_last_jif);
208
209 if (old_vote)
210 qca->vote_off_ms += diff;
211 else
212 qca->vote_on_ms += diff;
213 return;
214
215 case HCI_IBS_TX_VOTE_CLOCK_ON:
216 qca->tx_vote = true;
217 qca->tx_votes_on++;
218 new_vote = true;
219 break;
220
221 case HCI_IBS_RX_VOTE_CLOCK_ON:
222 qca->rx_vote = true;
223 qca->rx_votes_on++;
224 new_vote = true;
225 break;
226
227 case HCI_IBS_TX_VOTE_CLOCK_OFF:
228 qca->tx_vote = false;
229 qca->tx_votes_off++;
230 new_vote = qca->rx_vote | qca->tx_vote;
231 break;
232
233 case HCI_IBS_RX_VOTE_CLOCK_OFF:
234 qca->rx_vote = false;
235 qca->rx_votes_off++;
236 new_vote = qca->rx_vote | qca->tx_vote;
237 break;
238
239 default:
240 BT_ERR("Voting irregularity");
241 return;
242 }
243
244 if (new_vote != old_vote) {
245 if (new_vote)
246 __serial_clock_on(hu->tty);
247 else
248 __serial_clock_off(hu->tty);
249
Prasanna Karthikce26d812015-09-15 12:19:45 +0000250 BT_DBG("Vote serial clock %s(%s)", new_vote ? "true" : "false",
251 vote ? "true" : "false");
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700252
253 diff = jiffies_to_msecs(jiffies - qca->vote_last_jif);
254
255 if (new_vote) {
256 qca->votes_on++;
257 qca->vote_off_ms += diff;
258 } else {
259 qca->votes_off++;
260 qca->vote_on_ms += diff;
261 }
262 qca->vote_last_jif = jiffies;
263 }
264}
265
266/* Builds and sends an HCI_IBS command packet.
267 * These are very simple packets with only 1 cmd byte.
268 */
269static int send_hci_ibs_cmd(u8 cmd, struct hci_uart *hu)
270{
271 int err = 0;
272 struct sk_buff *skb = NULL;
273 struct qca_data *qca = hu->priv;
274
275 BT_DBG("hu %p send hci ibs cmd 0x%x", hu, cmd);
276
277 skb = bt_skb_alloc(1, GFP_ATOMIC);
278 if (!skb) {
279 BT_ERR("Failed to allocate memory for HCI_IBS packet");
280 return -ENOMEM;
281 }
282
283 /* Assign HCI_IBS type */
Johannes Berg634fef62017-06-16 14:29:24 +0200284 skb_put_u8(skb, cmd);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700285
286 skb_queue_tail(&qca->txq, skb);
287
288 return err;
289}
290
291static void qca_wq_awake_device(struct work_struct *work)
292{
293 struct qca_data *qca = container_of(work, struct qca_data,
294 ws_awake_device);
295 struct hci_uart *hu = qca->hu;
296 unsigned long retrans_delay;
297
298 BT_DBG("hu %p wq awake device", hu);
299
300 /* Vote for serial clock */
301 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_ON, hu);
302
303 spin_lock(&qca->hci_ibs_lock);
304
305 /* Send wake indication to device */
306 if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND, hu) < 0)
307 BT_ERR("Failed to send WAKE to device");
308
309 qca->ibs_sent_wakes++;
310
311 /* Start retransmit timer */
312 retrans_delay = msecs_to_jiffies(qca->wake_retrans);
313 mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay);
314
315 spin_unlock(&qca->hci_ibs_lock);
316
317 /* Actually send the packets */
318 hci_uart_tx_wakeup(hu);
319}
320
321static void qca_wq_awake_rx(struct work_struct *work)
322{
323 struct qca_data *qca = container_of(work, struct qca_data,
324 ws_awake_rx);
325 struct hci_uart *hu = qca->hu;
326
327 BT_DBG("hu %p wq awake rx", hu);
328
329 serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_ON, hu);
330
331 spin_lock(&qca->hci_ibs_lock);
332 qca->rx_ibs_state = HCI_IBS_RX_AWAKE;
333
334 /* Always acknowledge device wake up,
335 * sending IBS message doesn't count as TX ON.
336 */
337 if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK, hu) < 0)
338 BT_ERR("Failed to acknowledge device wake up");
339
340 qca->ibs_sent_wacks++;
341
342 spin_unlock(&qca->hci_ibs_lock);
343
344 /* Actually send the packets */
345 hci_uart_tx_wakeup(hu);
346}
347
348static void qca_wq_serial_rx_clock_vote_off(struct work_struct *work)
349{
350 struct qca_data *qca = container_of(work, struct qca_data,
351 ws_rx_vote_off);
352 struct hci_uart *hu = qca->hu;
353
354 BT_DBG("hu %p rx clock vote off", hu);
355
356 serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_OFF, hu);
357}
358
359static void qca_wq_serial_tx_clock_vote_off(struct work_struct *work)
360{
361 struct qca_data *qca = container_of(work, struct qca_data,
362 ws_tx_vote_off);
363 struct hci_uart *hu = qca->hu;
364
365 BT_DBG("hu %p tx clock vote off", hu);
366
367 /* Run HCI tx handling unlocked */
368 hci_uart_tx_wakeup(hu);
369
370 /* Now that message queued to tty driver, vote for tty clocks off.
371 * It is up to the tty driver to pend the clocks off until tx done.
372 */
373 serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF, hu);
374}
375
Kees Cook04356052017-10-04 17:54:29 -0700376static void hci_ibs_tx_idle_timeout(struct timer_list *t)
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700377{
Kees Cook04356052017-10-04 17:54:29 -0700378 struct qca_data *qca = from_timer(qca, t, tx_idle_timer);
379 struct hci_uart *hu = qca->hu;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700380 unsigned long flags;
381
382 BT_DBG("hu %p idle timeout in %d state", hu, qca->tx_ibs_state);
383
384 spin_lock_irqsave_nested(&qca->hci_ibs_lock,
385 flags, SINGLE_DEPTH_NESTING);
386
387 switch (qca->tx_ibs_state) {
388 case HCI_IBS_TX_AWAKE:
389 /* TX_IDLE, go to SLEEP */
390 if (send_hci_ibs_cmd(HCI_IBS_SLEEP_IND, hu) < 0) {
391 BT_ERR("Failed to send SLEEP to device");
392 break;
393 }
394 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
395 qca->ibs_sent_slps++;
396 queue_work(qca->workqueue, &qca->ws_tx_vote_off);
397 break;
398
399 case HCI_IBS_TX_ASLEEP:
400 case HCI_IBS_TX_WAKING:
401 /* Fall through */
402
403 default:
Colin Ian Kinge059a462017-02-17 19:58:10 +0000404 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700405 break;
406 }
407
408 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
409}
410
Kees Cook04356052017-10-04 17:54:29 -0700411static void hci_ibs_wake_retrans_timeout(struct timer_list *t)
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700412{
Kees Cook04356052017-10-04 17:54:29 -0700413 struct qca_data *qca = from_timer(qca, t, wake_retrans_timer);
414 struct hci_uart *hu = qca->hu;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700415 unsigned long flags, retrans_delay;
Prasanna Karthika9137182015-09-28 08:03:24 +0000416 bool retransmit = false;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700417
418 BT_DBG("hu %p wake retransmit timeout in %d state",
419 hu, qca->tx_ibs_state);
420
421 spin_lock_irqsave_nested(&qca->hci_ibs_lock,
422 flags, SINGLE_DEPTH_NESTING);
423
424 switch (qca->tx_ibs_state) {
425 case HCI_IBS_TX_WAKING:
426 /* No WAKE_ACK, retransmit WAKE */
Prasanna Karthika9137182015-09-28 08:03:24 +0000427 retransmit = true;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700428 if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND, hu) < 0) {
429 BT_ERR("Failed to acknowledge device wake up");
430 break;
431 }
432 qca->ibs_sent_wakes++;
433 retrans_delay = msecs_to_jiffies(qca->wake_retrans);
434 mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay);
435 break;
436
437 case HCI_IBS_TX_ASLEEP:
438 case HCI_IBS_TX_AWAKE:
439 /* Fall through */
440
441 default:
Colin Ian Kinge059a462017-02-17 19:58:10 +0000442 BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700443 break;
444 }
445
446 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
447
448 if (retransmit)
449 hci_uart_tx_wakeup(hu);
450}
451
452/* Initialize protocol */
453static int qca_open(struct hci_uart *hu)
454{
Thierry Escande05ba5332018-03-29 21:15:24 +0200455 struct qca_serdev *qcadev;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700456 struct qca_data *qca;
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530457 int ret;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700458
459 BT_DBG("hu %p qca_open", hu);
460
Jia-Ju Bai25a13e382018-07-23 11:56:51 +0800461 qca = kzalloc(sizeof(struct qca_data), GFP_KERNEL);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700462 if (!qca)
463 return -ENOMEM;
464
465 skb_queue_head_init(&qca->txq);
466 skb_queue_head_init(&qca->tx_wait_q);
467 spin_lock_init(&qca->hci_ibs_lock);
Bhaktipriya Shridharfac9a602016-08-30 22:42:53 +0530468 qca->workqueue = alloc_ordered_workqueue("qca_wq", 0);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700469 if (!qca->workqueue) {
470 BT_ERR("QCA Workqueue not initialized properly");
471 kfree(qca);
472 return -ENOMEM;
473 }
474
475 INIT_WORK(&qca->ws_awake_rx, qca_wq_awake_rx);
476 INIT_WORK(&qca->ws_awake_device, qca_wq_awake_device);
477 INIT_WORK(&qca->ws_rx_vote_off, qca_wq_serial_rx_clock_vote_off);
478 INIT_WORK(&qca->ws_tx_vote_off, qca_wq_serial_tx_clock_vote_off);
479
480 qca->hu = hu;
481
482 /* Assume we start with both sides asleep -- extra wakes OK */
483 qca->tx_ibs_state = HCI_IBS_TX_ASLEEP;
484 qca->rx_ibs_state = HCI_IBS_RX_ASLEEP;
485
486 /* clocks actually on, but we start votes off */
487 qca->tx_vote = false;
488 qca->rx_vote = false;
489 qca->flags = 0;
490
491 qca->ibs_sent_wacks = 0;
492 qca->ibs_sent_slps = 0;
493 qca->ibs_sent_wakes = 0;
494 qca->ibs_recv_wacks = 0;
495 qca->ibs_recv_slps = 0;
496 qca->ibs_recv_wakes = 0;
497 qca->vote_last_jif = jiffies;
498 qca->vote_on_ms = 0;
499 qca->vote_off_ms = 0;
500 qca->votes_on = 0;
501 qca->votes_off = 0;
502 qca->tx_votes_on = 0;
503 qca->tx_votes_off = 0;
504 qca->rx_votes_on = 0;
505 qca->rx_votes_off = 0;
506
507 hu->priv = qca;
508
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530509 if (hu->serdev) {
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530510
511 qcadev = serdev_device_get_drvdata(hu->serdev);
Harish Bandi523760b2019-04-26 19:26:01 +0530512 if (!qca_is_wcn399x(qcadev->btsoc_type)) {
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530513 gpiod_set_value_cansleep(qcadev->bt_en, 1);
Balakrishna Godavarthi7f09d5a2019-04-01 15:19:08 +0530514 /* Controller needs time to bootup. */
515 msleep(150);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530516 } else {
517 hu->init_speed = qcadev->init_speed;
518 hu->oper_speed = qcadev->oper_speed;
519 ret = qca_power_setup(hu, true);
520 if (ret) {
521 destroy_workqueue(qca->workqueue);
522 kfree_skb(qca->rx_skb);
523 hu->priv = NULL;
524 kfree(qca);
525 return ret;
526 }
527 }
528 }
529
Kees Cook04356052017-10-04 17:54:29 -0700530 timer_setup(&qca->wake_retrans_timer, hci_ibs_wake_retrans_timeout, 0);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700531 qca->wake_retrans = IBS_WAKE_RETRANS_TIMEOUT_MS;
532
Kees Cook04356052017-10-04 17:54:29 -0700533 timer_setup(&qca->tx_idle_timer, hci_ibs_tx_idle_timeout, 0);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700534 qca->tx_idle_delay = IBS_TX_IDLE_TIMEOUT_MS;
535
536 BT_DBG("HCI_UART_QCA open, tx_idle_delay=%u, wake_retrans=%u",
537 qca->tx_idle_delay, qca->wake_retrans);
538
539 return 0;
540}
541
542static void qca_debugfs_init(struct hci_dev *hdev)
543{
544 struct hci_uart *hu = hci_get_drvdata(hdev);
545 struct qca_data *qca = hu->priv;
546 struct dentry *ibs_dir;
547 umode_t mode;
548
549 if (!hdev->debugfs)
550 return;
551
552 ibs_dir = debugfs_create_dir("ibs", hdev->debugfs);
553
554 /* read only */
555 mode = S_IRUGO;
556 debugfs_create_u8("tx_ibs_state", mode, ibs_dir, &qca->tx_ibs_state);
557 debugfs_create_u8("rx_ibs_state", mode, ibs_dir, &qca->rx_ibs_state);
558 debugfs_create_u64("ibs_sent_sleeps", mode, ibs_dir,
559 &qca->ibs_sent_slps);
560 debugfs_create_u64("ibs_sent_wakes", mode, ibs_dir,
561 &qca->ibs_sent_wakes);
562 debugfs_create_u64("ibs_sent_wake_acks", mode, ibs_dir,
563 &qca->ibs_sent_wacks);
564 debugfs_create_u64("ibs_recv_sleeps", mode, ibs_dir,
565 &qca->ibs_recv_slps);
566 debugfs_create_u64("ibs_recv_wakes", mode, ibs_dir,
567 &qca->ibs_recv_wakes);
568 debugfs_create_u64("ibs_recv_wake_acks", mode, ibs_dir,
569 &qca->ibs_recv_wacks);
Ben YoungTae Kim10be6c02015-08-13 22:09:42 -0700570 debugfs_create_bool("tx_vote", mode, ibs_dir, &qca->tx_vote);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700571 debugfs_create_u64("tx_votes_on", mode, ibs_dir, &qca->tx_votes_on);
572 debugfs_create_u64("tx_votes_off", mode, ibs_dir, &qca->tx_votes_off);
Ben YoungTae Kim10be6c02015-08-13 22:09:42 -0700573 debugfs_create_bool("rx_vote", mode, ibs_dir, &qca->rx_vote);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700574 debugfs_create_u64("rx_votes_on", mode, ibs_dir, &qca->rx_votes_on);
575 debugfs_create_u64("rx_votes_off", mode, ibs_dir, &qca->rx_votes_off);
576 debugfs_create_u64("votes_on", mode, ibs_dir, &qca->votes_on);
577 debugfs_create_u64("votes_off", mode, ibs_dir, &qca->votes_off);
578 debugfs_create_u32("vote_on_ms", mode, ibs_dir, &qca->vote_on_ms);
579 debugfs_create_u32("vote_off_ms", mode, ibs_dir, &qca->vote_off_ms);
580
581 /* read/write */
582 mode = S_IRUGO | S_IWUSR;
583 debugfs_create_u32("wake_retrans", mode, ibs_dir, &qca->wake_retrans);
584 debugfs_create_u32("tx_idle_delay", mode, ibs_dir,
585 &qca->tx_idle_delay);
586}
587
588/* Flush protocol data */
589static int qca_flush(struct hci_uart *hu)
590{
591 struct qca_data *qca = hu->priv;
592
593 BT_DBG("hu %p qca flush", hu);
594
595 skb_queue_purge(&qca->tx_wait_q);
596 skb_queue_purge(&qca->txq);
597
598 return 0;
599}
600
601/* Close protocol */
602static int qca_close(struct hci_uart *hu)
603{
Thierry Escande05ba5332018-03-29 21:15:24 +0200604 struct qca_serdev *qcadev;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700605 struct qca_data *qca = hu->priv;
606
607 BT_DBG("hu %p qca close", hu);
608
609 serial_clock_vote(HCI_IBS_VOTE_STATS_UPDATE, hu);
610
611 skb_queue_purge(&qca->tx_wait_q);
612 skb_queue_purge(&qca->txq);
613 del_timer(&qca->tx_idle_timer);
614 del_timer(&qca->wake_retrans_timer);
615 destroy_workqueue(qca->workqueue);
616 qca->hu = NULL;
617
Thierry Escande05ba5332018-03-29 21:15:24 +0200618 if (hu->serdev) {
Thierry Escande05ba5332018-03-29 21:15:24 +0200619 qcadev = serdev_device_get_drvdata(hu->serdev);
Harish Bandi523760b2019-04-26 19:26:01 +0530620 if (qca_is_wcn399x(qcadev->btsoc_type))
Balakrishna Godavarthic2d78272018-08-22 17:50:05 +0530621 qca_power_shutdown(hu);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +0530622 else
623 gpiod_set_value_cansleep(qcadev->bt_en, 0);
624
Thierry Escande05ba5332018-03-29 21:15:24 +0200625 }
626
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700627 kfree_skb(qca->rx_skb);
628
629 hu->priv = NULL;
630
631 kfree(qca);
632
633 return 0;
634}
635
636/* Called upon a wake-up-indication from the device.
637 */
638static void device_want_to_wakeup(struct hci_uart *hu)
639{
640 unsigned long flags;
641 struct qca_data *qca = hu->priv;
642
643 BT_DBG("hu %p want to wake up", hu);
644
645 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
646
647 qca->ibs_recv_wakes++;
648
649 switch (qca->rx_ibs_state) {
650 case HCI_IBS_RX_ASLEEP:
651 /* Make sure clock is on - we may have turned clock off since
652 * receiving the wake up indicator awake rx clock.
653 */
654 queue_work(qca->workqueue, &qca->ws_awake_rx);
655 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
656 return;
657
658 case HCI_IBS_RX_AWAKE:
659 /* Always acknowledge device wake up,
660 * sending IBS message doesn't count as TX ON.
661 */
662 if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK, hu) < 0) {
663 BT_ERR("Failed to acknowledge device wake up");
664 break;
665 }
666 qca->ibs_sent_wacks++;
667 break;
668
669 default:
670 /* Any other state is illegal */
671 BT_ERR("Received HCI_IBS_WAKE_IND in rx state %d",
672 qca->rx_ibs_state);
673 break;
674 }
675
676 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
677
678 /* Actually send the packets */
679 hci_uart_tx_wakeup(hu);
680}
681
682/* Called upon a sleep-indication from the device.
683 */
684static void device_want_to_sleep(struct hci_uart *hu)
685{
686 unsigned long flags;
687 struct qca_data *qca = hu->priv;
688
689 BT_DBG("hu %p want to sleep", hu);
690
691 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
692
693 qca->ibs_recv_slps++;
694
695 switch (qca->rx_ibs_state) {
696 case HCI_IBS_RX_AWAKE:
697 /* Update state */
698 qca->rx_ibs_state = HCI_IBS_RX_ASLEEP;
699 /* Vote off rx clock under workqueue */
700 queue_work(qca->workqueue, &qca->ws_rx_vote_off);
701 break;
702
703 case HCI_IBS_RX_ASLEEP:
704 /* Fall through */
705
706 default:
707 /* Any other state is illegal */
708 BT_ERR("Received HCI_IBS_SLEEP_IND in rx state %d",
709 qca->rx_ibs_state);
710 break;
711 }
712
713 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
714}
715
716/* Called upon wake-up-acknowledgement from the device
717 */
718static void device_woke_up(struct hci_uart *hu)
719{
720 unsigned long flags, idle_delay;
721 struct qca_data *qca = hu->priv;
722 struct sk_buff *skb = NULL;
723
724 BT_DBG("hu %p woke up", hu);
725
726 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
727
728 qca->ibs_recv_wacks++;
729
730 switch (qca->tx_ibs_state) {
731 case HCI_IBS_TX_AWAKE:
732 /* Expect one if we send 2 WAKEs */
733 BT_DBG("Received HCI_IBS_WAKE_ACK in tx state %d",
734 qca->tx_ibs_state);
735 break;
736
737 case HCI_IBS_TX_WAKING:
738 /* Send pending packets */
739 while ((skb = skb_dequeue(&qca->tx_wait_q)))
740 skb_queue_tail(&qca->txq, skb);
741
742 /* Switch timers and change state to HCI_IBS_TX_AWAKE */
743 del_timer(&qca->wake_retrans_timer);
744 idle_delay = msecs_to_jiffies(qca->tx_idle_delay);
745 mod_timer(&qca->tx_idle_timer, jiffies + idle_delay);
746 qca->tx_ibs_state = HCI_IBS_TX_AWAKE;
747 break;
748
749 case HCI_IBS_TX_ASLEEP:
750 /* Fall through */
751
752 default:
753 BT_ERR("Received HCI_IBS_WAKE_ACK in tx state %d",
754 qca->tx_ibs_state);
755 break;
756 }
757
758 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
759
760 /* Actually send the packets */
761 hci_uart_tx_wakeup(hu);
762}
763
764/* Enqueue frame for transmittion (padding, crc, etc) may be called from
765 * two simultaneous tasklets.
766 */
767static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)
768{
769 unsigned long flags = 0, idle_delay;
770 struct qca_data *qca = hu->priv;
771
772 BT_DBG("hu %p qca enq skb %p tx_ibs_state %d", hu, skb,
773 qca->tx_ibs_state);
774
775 /* Prepend skb with frame type */
Marcel Holtmann618e8bc2015-11-05 07:33:56 +0100776 memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700777
Balakrishna Godavarthi035a9602019-02-04 20:36:43 +0530778 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
779
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700780 /* Don't go to sleep in middle of patch download or
781 * Out-Of-Band(GPIOs control) sleep is selected.
782 */
Matthias Kaehlcke62a91992019-04-29 16:21:30 -0700783 if (!test_bit(QCA_IBS_ENABLED, &qca->flags)) {
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700784 skb_queue_tail(&qca->txq, skb);
Balakrishna Godavarthi035a9602019-02-04 20:36:43 +0530785 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700786 return 0;
787 }
788
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700789 /* Act according to current state */
790 switch (qca->tx_ibs_state) {
791 case HCI_IBS_TX_AWAKE:
792 BT_DBG("Device awake, sending normally");
793 skb_queue_tail(&qca->txq, skb);
794 idle_delay = msecs_to_jiffies(qca->tx_idle_delay);
795 mod_timer(&qca->tx_idle_timer, jiffies + idle_delay);
796 break;
797
798 case HCI_IBS_TX_ASLEEP:
799 BT_DBG("Device asleep, waking up and queueing packet");
800 /* Save packet for later */
801 skb_queue_tail(&qca->tx_wait_q, skb);
802
803 qca->tx_ibs_state = HCI_IBS_TX_WAKING;
804 /* Schedule a work queue to wake up device */
805 queue_work(qca->workqueue, &qca->ws_awake_device);
806 break;
807
808 case HCI_IBS_TX_WAKING:
809 BT_DBG("Device waking up, queueing packet");
810 /* Transient state; just keep packet for later */
811 skb_queue_tail(&qca->tx_wait_q, skb);
812 break;
813
814 default:
815 BT_ERR("Illegal tx state: %d (losing packet)",
816 qca->tx_ibs_state);
817 kfree_skb(skb);
818 break;
819 }
820
821 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
822
823 return 0;
824}
825
826static int qca_ibs_sleep_ind(struct hci_dev *hdev, struct sk_buff *skb)
827{
828 struct hci_uart *hu = hci_get_drvdata(hdev);
829
830 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_SLEEP_IND);
831
832 device_want_to_sleep(hu);
833
834 kfree_skb(skb);
835 return 0;
836}
837
838static int qca_ibs_wake_ind(struct hci_dev *hdev, struct sk_buff *skb)
839{
840 struct hci_uart *hu = hci_get_drvdata(hdev);
841
842 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_WAKE_IND);
843
844 device_want_to_wakeup(hu);
845
846 kfree_skb(skb);
847 return 0;
848}
849
850static int qca_ibs_wake_ack(struct hci_dev *hdev, struct sk_buff *skb)
851{
852 struct hci_uart *hu = hci_get_drvdata(hdev);
853
854 BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_WAKE_ACK);
855
856 device_woke_up(hu);
857
858 kfree_skb(skb);
859 return 0;
860}
861
Balakrishna Godavarthic614ca32018-10-16 19:51:35 +0530862static int qca_recv_acl_data(struct hci_dev *hdev, struct sk_buff *skb)
863{
864 /* We receive debug logs from chip as an ACL packets.
865 * Instead of sending the data to ACL to decode the
866 * received data, we are pushing them to the above layers
867 * as a diagnostic packet.
868 */
869 if (get_unaligned_le16(skb->data) == QCA_DEBUG_HANDLE)
870 return hci_recv_diag(hdev, skb);
871
872 return hci_recv_frame(hdev, skb);
873}
874
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700875#define QCA_IBS_SLEEP_IND_EVENT \
876 .type = HCI_IBS_SLEEP_IND, \
877 .hlen = 0, \
878 .loff = 0, \
879 .lsize = 0, \
880 .maxlen = HCI_MAX_IBS_SIZE
881
882#define QCA_IBS_WAKE_IND_EVENT \
883 .type = HCI_IBS_WAKE_IND, \
884 .hlen = 0, \
885 .loff = 0, \
886 .lsize = 0, \
887 .maxlen = HCI_MAX_IBS_SIZE
888
889#define QCA_IBS_WAKE_ACK_EVENT \
890 .type = HCI_IBS_WAKE_ACK, \
891 .hlen = 0, \
892 .loff = 0, \
893 .lsize = 0, \
894 .maxlen = HCI_MAX_IBS_SIZE
895
896static const struct h4_recv_pkt qca_recv_pkts[] = {
Balakrishna Godavarthic614ca32018-10-16 19:51:35 +0530897 { H4_RECV_ACL, .recv = qca_recv_acl_data },
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700898 { H4_RECV_SCO, .recv = hci_recv_frame },
899 { H4_RECV_EVENT, .recv = hci_recv_frame },
900 { QCA_IBS_WAKE_IND_EVENT, .recv = qca_ibs_wake_ind },
901 { QCA_IBS_WAKE_ACK_EVENT, .recv = qca_ibs_wake_ack },
902 { QCA_IBS_SLEEP_IND_EVENT, .recv = qca_ibs_sleep_ind },
903};
904
905static int qca_recv(struct hci_uart *hu, const void *data, int count)
906{
907 struct qca_data *qca = hu->priv;
908
909 if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
910 return -EUNATCH;
911
912 qca->rx_skb = h4_recv_buf(hu->hdev, qca->rx_skb, data, count,
913 qca_recv_pkts, ARRAY_SIZE(qca_recv_pkts));
914 if (IS_ERR(qca->rx_skb)) {
915 int err = PTR_ERR(qca->rx_skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100916 bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700917 qca->rx_skb = NULL;
918 return err;
919 }
920
921 return count;
922}
923
924static struct sk_buff *qca_dequeue(struct hci_uart *hu)
925{
926 struct qca_data *qca = hu->priv;
927
928 return skb_dequeue(&qca->txq);
929}
930
931static uint8_t qca_get_baudrate_value(int speed)
932{
Prasanna Karthikce26d812015-09-15 12:19:45 +0000933 switch (speed) {
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700934 case 9600:
935 return QCA_BAUDRATE_9600;
936 case 19200:
937 return QCA_BAUDRATE_19200;
938 case 38400:
939 return QCA_BAUDRATE_38400;
940 case 57600:
941 return QCA_BAUDRATE_57600;
942 case 115200:
943 return QCA_BAUDRATE_115200;
944 case 230400:
945 return QCA_BAUDRATE_230400;
946 case 460800:
947 return QCA_BAUDRATE_460800;
948 case 500000:
949 return QCA_BAUDRATE_500000;
950 case 921600:
951 return QCA_BAUDRATE_921600;
952 case 1000000:
953 return QCA_BAUDRATE_1000000;
954 case 2000000:
955 return QCA_BAUDRATE_2000000;
956 case 3000000:
957 return QCA_BAUDRATE_3000000;
Balakrishna Godavarthibe93a492018-08-03 17:46:30 +0530958 case 3200000:
959 return QCA_BAUDRATE_3200000;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700960 case 3500000:
961 return QCA_BAUDRATE_3500000;
962 default:
963 return QCA_BAUDRATE_115200;
964 }
965}
966
967static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
968{
969 struct hci_uart *hu = hci_get_drvdata(hdev);
970 struct qca_data *qca = hu->priv;
971 struct sk_buff *skb;
972 u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
973
Balakrishna Godavarthibe93a492018-08-03 17:46:30 +0530974 if (baudrate > QCA_BAUDRATE_3200000)
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700975 return -EINVAL;
976
977 cmd[4] = baudrate;
978
Jia-Ju Bai25a13e382018-07-23 11:56:51 +0800979 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700980 if (!skb) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100981 bt_dev_err(hdev, "Failed to allocate baudrate packet");
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700982 return -ENOMEM;
983 }
984
985 /* Assign commands to change baudrate and packet type. */
Johannes Berg59ae1d12017-06-16 14:29:20 +0200986 skb_put_data(skb, cmd, sizeof(cmd));
Marcel Holtmann618e8bc2015-11-05 07:33:56 +0100987 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700988
989 skb_queue_tail(&qca->txq, skb);
990 hci_uart_tx_wakeup(hu);
991
Matthias Kaehlcke94d66712019-02-27 15:52:23 -0800992 /* Wait for the baudrate change request to be sent */
993
994 while (!skb_queue_empty(&qca->txq))
995 usleep_range(100, 200);
996
Matthias Kaehlckeecf2b762019-04-23 11:16:52 -0700997 if (hu->serdev)
998 serdev_device_wait_until_sent(hu->serdev,
Matthias Kaehlcke94d66712019-02-27 15:52:23 -0800999 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS));
1000
1001 /* Give the controller time to process the request */
Harish Bandi523760b2019-04-26 19:26:01 +05301002 if (qca_is_wcn399x(qca_soc_type(hu)))
Matthias Kaehlcke94d66712019-02-27 15:52:23 -08001003 msleep(10);
1004 else
1005 msleep(300);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001006
1007 return 0;
1008}
1009
Thierry Escande05ba5332018-03-29 21:15:24 +02001010static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
1011{
1012 if (hu->serdev)
1013 serdev_device_set_baudrate(hu->serdev, speed);
1014 else
1015 hci_uart_set_baudrate(hu, speed);
1016}
1017
Matthias Kaehlcke9836b802019-02-26 11:46:45 -08001018static int qca_send_power_pulse(struct hci_uart *hu, bool on)
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301019{
Balakrishna Godavarthif9558272019-02-04 20:36:41 +05301020 int ret;
Matthias Kaehlcke94d66712019-02-27 15:52:23 -08001021 int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
Matthias Kaehlcke9836b802019-02-26 11:46:45 -08001022 u8 cmd = on ? QCA_WCN3990_POWERON_PULSE : QCA_WCN3990_POWEROFF_PULSE;
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301023
1024 /* These power pulses are single byte command which are sent
1025 * at required baudrate to wcn3990. On wcn3990, we have an external
1026 * circuit at Tx pin which decodes the pulse sent at specific baudrate.
1027 * For example, wcn3990 supports RF COEX antenna for both Wi-Fi/BT
1028 * and also we use the same power inputs to turn on and off for
1029 * Wi-Fi/BT. Powering up the power sources will not enable BT, until
1030 * we send a power on pulse at 115200 bps. This algorithm will help to
1031 * save power. Disabling hardware flow control is mandatory while
1032 * sending power pulses to SoC.
1033 */
Balakrishna Godavarthif9558272019-02-04 20:36:41 +05301034 bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301035
Balakrishna Godavarthif9558272019-02-04 20:36:41 +05301036 serdev_device_write_flush(hu->serdev);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301037 hci_uart_set_flow_control(hu, true);
Balakrishna Godavarthif9558272019-02-04 20:36:41 +05301038 ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd));
1039 if (ret < 0) {
1040 bt_dev_err(hu->hdev, "failed to send power pulse %02x", cmd);
1041 return ret;
1042 }
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301043
Balakrishna Godavarthif9558272019-02-04 20:36:41 +05301044 serdev_device_wait_until_sent(hu->serdev, timeout);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301045 hci_uart_set_flow_control(hu, false);
1046
Matthias Kaehlcke0ebcddd2019-02-26 11:46:47 -08001047 /* Give to controller time to boot/shutdown */
Matthias Kaehlckead571d72019-02-26 11:46:46 -08001048 if (on)
1049 msleep(100);
Matthias Kaehlcke0ebcddd2019-02-26 11:46:47 -08001050 else
1051 msleep(10);
Matthias Kaehlckead571d72019-02-26 11:46:46 -08001052
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301053 return 0;
1054}
1055
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301056static unsigned int qca_get_speed(struct hci_uart *hu,
1057 enum qca_speed_type speed_type)
1058{
1059 unsigned int speed = 0;
1060
1061 if (speed_type == QCA_INIT_SPEED) {
1062 if (hu->init_speed)
1063 speed = hu->init_speed;
1064 else if (hu->proto->init_speed)
1065 speed = hu->proto->init_speed;
1066 } else {
1067 if (hu->oper_speed)
1068 speed = hu->oper_speed;
1069 else if (hu->proto->oper_speed)
1070 speed = hu->proto->oper_speed;
1071 }
1072
1073 return speed;
1074}
1075
1076static int qca_check_speeds(struct hci_uart *hu)
1077{
Harish Bandi523760b2019-04-26 19:26:01 +05301078 if (qca_is_wcn399x(qca_soc_type(hu))) {
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301079 if (!qca_get_speed(hu, QCA_INIT_SPEED) &&
1080 !qca_get_speed(hu, QCA_OPER_SPEED))
1081 return -EINVAL;
1082 } else {
1083 if (!qca_get_speed(hu, QCA_INIT_SPEED) ||
1084 !qca_get_speed(hu, QCA_OPER_SPEED))
1085 return -EINVAL;
1086 }
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301087
1088 return 0;
1089}
1090
1091static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
1092{
1093 unsigned int speed, qca_baudrate;
Balakrishna Godavarthi78e8fa22019-02-04 20:36:42 +05301094 int ret = 0;
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301095
1096 if (speed_type == QCA_INIT_SPEED) {
1097 speed = qca_get_speed(hu, QCA_INIT_SPEED);
1098 if (speed)
1099 host_set_baudrate(hu, speed);
1100 } else {
Matthias Kaehlcke4fdd5a42019-03-11 11:38:31 -07001101 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1102
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301103 speed = qca_get_speed(hu, QCA_OPER_SPEED);
1104 if (!speed)
1105 return 0;
1106
Balakrishna Godavarthi78e8fa22019-02-04 20:36:42 +05301107 /* Disable flow control for wcn3990 to deassert RTS while
1108 * changing the baudrate of chip and host.
1109 */
Harish Bandi523760b2019-04-26 19:26:01 +05301110 if (qca_is_wcn399x(soc_type))
Balakrishna Godavarthi78e8fa22019-02-04 20:36:42 +05301111 hci_uart_set_flow_control(hu, true);
1112
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301113 qca_baudrate = qca_get_baudrate_value(speed);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301114 bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed);
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301115 ret = qca_set_baudrate(hu->hdev, qca_baudrate);
1116 if (ret)
Balakrishna Godavarthi78e8fa22019-02-04 20:36:42 +05301117 goto error;
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301118
1119 host_set_baudrate(hu, speed);
Balakrishna Godavarthi78e8fa22019-02-04 20:36:42 +05301120
1121error:
Harish Bandi523760b2019-04-26 19:26:01 +05301122 if (qca_is_wcn399x(soc_type))
Balakrishna Godavarthi78e8fa22019-02-04 20:36:42 +05301123 hci_uart_set_flow_control(hu, false);
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301124 }
1125
Balakrishna Godavarthi78e8fa22019-02-04 20:36:42 +05301126 return ret;
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301127}
1128
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301129static int qca_wcn3990_init(struct hci_uart *hu)
1130{
Balakrishna Godavarthi3e4be652018-09-24 20:14:45 +05301131 struct qca_serdev *qcadev;
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301132 int ret;
1133
Balakrishna Godavarthi3e4be652018-09-24 20:14:45 +05301134 /* Check for vregs status, may be hci down has turned
1135 * off the voltage regulator.
1136 */
1137 qcadev = serdev_device_get_drvdata(hu->serdev);
1138 if (!qcadev->bt_power->vregs_on) {
1139 serdev_device_close(hu->serdev);
1140 ret = qca_power_setup(hu, true);
1141 if (ret)
1142 return ret;
1143
1144 ret = serdev_device_open(hu->serdev);
1145 if (ret) {
1146 bt_dev_err(hu->hdev, "failed to open port");
1147 return ret;
1148 }
1149 }
1150
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301151 /* Forcefully enable wcn3990 to enter in to boot mode. */
1152 host_set_baudrate(hu, 2400);
Matthias Kaehlcke9836b802019-02-26 11:46:45 -08001153 ret = qca_send_power_pulse(hu, false);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301154 if (ret)
1155 return ret;
1156
1157 qca_set_speed(hu, QCA_INIT_SPEED);
Matthias Kaehlcke9836b802019-02-26 11:46:45 -08001158 ret = qca_send_power_pulse(hu, true);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301159 if (ret)
1160 return ret;
1161
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301162 /* Now the device is in ready state to communicate with host.
1163 * To sync host with device we need to reopen port.
1164 * Without this, we will have RTS and CTS synchronization
1165 * issues.
1166 */
1167 serdev_device_close(hu->serdev);
1168 ret = serdev_device_open(hu->serdev);
1169 if (ret) {
1170 bt_dev_err(hu->hdev, "failed to open port");
1171 return ret;
1172 }
1173
1174 hci_uart_set_flow_control(hu, false);
1175
1176 return 0;
1177}
1178
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001179static int qca_setup(struct hci_uart *hu)
1180{
1181 struct hci_dev *hdev = hu->hdev;
1182 struct qca_data *qca = hu->priv;
1183 unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200;
Matthias Kaehlcke4fdd5a42019-03-11 11:38:31 -07001184 enum qca_btsoc_type soc_type = qca_soc_type(hu);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001185 int ret;
Balakrishna Godavarthiaadebac2018-08-03 17:46:28 +05301186 int soc_ver = 0;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001187
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301188 ret = qca_check_speeds(hu);
1189 if (ret)
1190 return ret;
1191
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001192 /* Patch downloading has to be done without IBS mode */
Matthias Kaehlcke62a91992019-04-29 16:21:30 -07001193 clear_bit(QCA_IBS_ENABLED, &qca->flags);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001194
Harish Bandi523760b2019-04-26 19:26:01 +05301195 if (qca_is_wcn399x(soc_type)) {
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301196 bt_dev_info(hdev, "setting up wcn3990");
Balakrishna Godavarthi3e4be652018-09-24 20:14:45 +05301197
1198 /* Enable NON_PERSISTENT_SETUP QUIRK to ensure to execute
1199 * setup for every hci up.
1200 */
1201 set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
Matthias Kaehlcke5971752d2019-02-19 12:05:59 -08001202 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
Balakrishna Godavarthi3e4be652018-09-24 20:14:45 +05301203 hu->hdev->shutdown = qca_power_off;
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301204 ret = qca_wcn3990_init(hu);
1205 if (ret)
1206 return ret;
1207
1208 ret = qca_read_soc_version(hdev, &soc_ver);
1209 if (ret)
1210 return ret;
1211 } else {
1212 bt_dev_info(hdev, "ROME setup");
1213 qca_set_speed(hu, QCA_INIT_SPEED);
1214 }
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001215
1216 /* Setup user speed if needed */
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301217 speed = qca_get_speed(hu, QCA_OPER_SPEED);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001218 if (speed) {
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301219 ret = qca_set_speed(hu, QCA_OPER_SPEED);
1220 if (ret)
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001221 return ret;
Balakrishna Godavarthi83d9c5e2018-08-03 17:46:29 +05301222
1223 qca_baudrate = qca_get_baudrate_value(speed);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001224 }
1225
Harish Bandi523760b2019-04-26 19:26:01 +05301226 if (!qca_is_wcn399x(soc_type)) {
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301227 /* Get QCA version information */
1228 ret = qca_read_soc_version(hdev, &soc_ver);
1229 if (ret)
1230 return ret;
1231 }
Balakrishna Godavarthiaadebac2018-08-03 17:46:28 +05301232
1233 bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001234 /* Setup patch / NVM configurations */
Matthias Kaehlcke4fdd5a42019-03-11 11:38:31 -07001235 ret = qca_uart_setup(hdev, qca_baudrate, soc_type, soc_ver);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001236 if (!ret) {
Matthias Kaehlcke62a91992019-04-29 16:21:30 -07001237 set_bit(QCA_IBS_ENABLED, &qca->flags);
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001238 qca_debugfs_init(hdev);
Loic Poulainba8f3592017-11-06 12:16:56 +01001239 } else if (ret == -ENOENT) {
1240 /* No patch/nvm-config found, run with original fw/config */
1241 ret = 0;
Amit Pundir7dc5fe02018-04-16 12:10:24 +05301242 } else if (ret == -EAGAIN) {
1243 /*
1244 * Userspace firmware loader will return -EAGAIN in case no
1245 * patch/nvm-config is found, so run with original fw/config.
1246 */
1247 ret = 0;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001248 }
1249
1250 /* Setup bdaddr */
Harish Bandi523760b2019-04-26 19:26:01 +05301251 if (qca_is_wcn399x(soc_type))
Balakrishna Godavarthi5c0a10012019-01-16 18:01:15 +05301252 hu->hdev->set_bdaddr = qca_set_bdaddr;
1253 else
1254 hu->hdev->set_bdaddr = qca_set_bdaddr_rome;
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001255
1256 return ret;
1257}
1258
1259static struct hci_uart_proto qca_proto = {
1260 .id = HCI_UART_QCA,
1261 .name = "QCA",
Marcel Holtmannaee61f72015-10-20 21:30:45 +02001262 .manufacturer = 29,
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001263 .init_speed = 115200,
1264 .oper_speed = 3000000,
1265 .open = qca_open,
1266 .close = qca_close,
1267 .flush = qca_flush,
1268 .setup = qca_setup,
1269 .recv = qca_recv,
1270 .enqueue = qca_enqueue,
1271 .dequeue = qca_dequeue,
1272};
1273
Harish Bandi523760b2019-04-26 19:26:01 +05301274static const struct qca_vreg_data qca_soc_data_wcn3990 = {
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301275 .soc_type = QCA_WCN3990,
1276 .vregs = (struct qca_vreg []) {
1277 { "vddio", 1800000, 1900000, 15000 },
1278 { "vddxo", 1800000, 1900000, 80000 },
1279 { "vddrf", 1300000, 1350000, 300000 },
1280 { "vddch0", 3300000, 3400000, 450000 },
1281 },
1282 .num_vregs = 4,
1283};
1284
Harish Bandi523760b2019-04-26 19:26:01 +05301285static const struct qca_vreg_data qca_soc_data_wcn3998 = {
1286 .soc_type = QCA_WCN3998,
1287 .vregs = (struct qca_vreg []) {
1288 { "vddio", 1800000, 1900000, 10000 },
1289 { "vddxo", 1800000, 1900000, 80000 },
1290 { "vddrf", 1300000, 1352000, 300000 },
1291 { "vddch0", 3300000, 3300000, 450000 },
1292 },
1293 .num_vregs = 4,
1294};
1295
Balakrishna Godavarthic2d78272018-08-22 17:50:05 +05301296static void qca_power_shutdown(struct hci_uart *hu)
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301297{
Balakrishna Godavarthi035a9602019-02-04 20:36:43 +05301298 struct qca_data *qca = hu->priv;
1299 unsigned long flags;
1300
1301 /* From this point we go into power off state. But serial port is
1302 * still open, stop queueing the IBS data and flush all the buffered
1303 * data in skb's.
1304 */
1305 spin_lock_irqsave(&qca->hci_ibs_lock, flags);
Matthias Kaehlcke62a91992019-04-29 16:21:30 -07001306 clear_bit(QCA_IBS_ENABLED, &qca->flags);
Balakrishna Godavarthi035a9602019-02-04 20:36:43 +05301307 qca_flush(hu);
1308 spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
1309
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301310 host_set_baudrate(hu, 2400);
Matthias Kaehlcke9836b802019-02-26 11:46:45 -08001311 qca_send_power_pulse(hu, false);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301312 qca_power_setup(hu, false);
1313}
1314
Balakrishna Godavarthi3e4be652018-09-24 20:14:45 +05301315static int qca_power_off(struct hci_dev *hdev)
1316{
1317 struct hci_uart *hu = hci_get_drvdata(hdev);
1318
1319 qca_power_shutdown(hu);
1320 return 0;
1321}
1322
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301323static int qca_enable_regulator(struct qca_vreg vregs,
1324 struct regulator *regulator)
1325{
1326 int ret;
1327
1328 ret = regulator_set_voltage(regulator, vregs.min_uV,
1329 vregs.max_uV);
1330 if (ret)
1331 return ret;
1332
1333 if (vregs.load_uA)
1334 ret = regulator_set_load(regulator,
1335 vregs.load_uA);
1336
1337 if (ret)
1338 return ret;
1339
1340 return regulator_enable(regulator);
1341
1342}
1343
1344static void qca_disable_regulator(struct qca_vreg vregs,
1345 struct regulator *regulator)
1346{
1347 regulator_disable(regulator);
1348 regulator_set_voltage(regulator, 0, vregs.max_uV);
1349 if (vregs.load_uA)
1350 regulator_set_load(regulator, 0);
1351
1352}
1353
1354static int qca_power_setup(struct hci_uart *hu, bool on)
1355{
1356 struct qca_vreg *vregs;
1357 struct regulator_bulk_data *vreg_bulk;
1358 struct qca_serdev *qcadev;
1359 int i, num_vregs, ret = 0;
1360
1361 qcadev = serdev_device_get_drvdata(hu->serdev);
1362 if (!qcadev || !qcadev->bt_power || !qcadev->bt_power->vreg_data ||
1363 !qcadev->bt_power->vreg_bulk)
1364 return -EINVAL;
1365
1366 vregs = qcadev->bt_power->vreg_data->vregs;
1367 vreg_bulk = qcadev->bt_power->vreg_bulk;
1368 num_vregs = qcadev->bt_power->vreg_data->num_vregs;
1369 BT_DBG("on: %d", on);
1370 if (on && !qcadev->bt_power->vregs_on) {
1371 for (i = 0; i < num_vregs; i++) {
1372 ret = qca_enable_regulator(vregs[i],
1373 vreg_bulk[i].consumer);
1374 if (ret)
1375 break;
1376 }
1377
1378 if (ret) {
1379 BT_ERR("failed to enable regulator:%s", vregs[i].name);
1380 /* turn off regulators which are enabled */
1381 for (i = i - 1; i >= 0; i--)
1382 qca_disable_regulator(vregs[i],
1383 vreg_bulk[i].consumer);
1384 } else {
1385 qcadev->bt_power->vregs_on = true;
1386 }
1387 } else if (!on && qcadev->bt_power->vregs_on) {
1388 /* turn off regulator in reverse order */
1389 i = qcadev->bt_power->vreg_data->num_vregs - 1;
1390 for ( ; i >= 0; i--)
1391 qca_disable_regulator(vregs[i], vreg_bulk[i].consumer);
1392
1393 qcadev->bt_power->vregs_on = false;
1394 }
1395
1396 return ret;
1397}
1398
1399static int qca_init_regulators(struct qca_power *qca,
1400 const struct qca_vreg *vregs, size_t num_vregs)
1401{
1402 int i;
1403
Kees Cook329e0982018-10-05 16:21:46 -07001404 qca->vreg_bulk = devm_kcalloc(qca->dev, num_vregs,
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301405 sizeof(struct regulator_bulk_data),
1406 GFP_KERNEL);
1407 if (!qca->vreg_bulk)
1408 return -ENOMEM;
1409
1410 for (i = 0; i < num_vregs; i++)
1411 qca->vreg_bulk[i].supply = vregs[i].name;
1412
1413 return devm_regulator_bulk_get(qca->dev, num_vregs, qca->vreg_bulk);
1414}
1415
Thierry Escande05ba5332018-03-29 21:15:24 +02001416static int qca_serdev_probe(struct serdev_device *serdev)
1417{
1418 struct qca_serdev *qcadev;
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301419 const struct qca_vreg_data *data;
Thierry Escande05ba5332018-03-29 21:15:24 +02001420 int err;
1421
1422 qcadev = devm_kzalloc(&serdev->dev, sizeof(*qcadev), GFP_KERNEL);
1423 if (!qcadev)
1424 return -ENOMEM;
1425
1426 qcadev->serdev_hu.serdev = serdev;
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301427 data = of_device_get_match_data(&serdev->dev);
Thierry Escande05ba5332018-03-29 21:15:24 +02001428 serdev_device_set_drvdata(serdev, qcadev);
Harish Bandi523760b2019-04-26 19:26:01 +05301429 if (data && qca_is_wcn399x(data->soc_type)) {
1430 qcadev->btsoc_type = data->soc_type;
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301431 qcadev->bt_power = devm_kzalloc(&serdev->dev,
1432 sizeof(struct qca_power),
1433 GFP_KERNEL);
1434 if (!qcadev->bt_power)
1435 return -ENOMEM;
Thierry Escande05ba5332018-03-29 21:15:24 +02001436
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301437 qcadev->bt_power->dev = &serdev->dev;
1438 qcadev->bt_power->vreg_data = data;
1439 err = qca_init_regulators(qcadev->bt_power, data->vregs,
1440 data->num_vregs);
1441 if (err) {
1442 BT_ERR("Failed to init regulators:%d", err);
1443 goto out;
1444 }
1445
1446 qcadev->bt_power->vregs_on = false;
1447
1448 device_property_read_u32(&serdev->dev, "max-speed",
1449 &qcadev->oper_speed);
1450 if (!qcadev->oper_speed)
1451 BT_DBG("UART will pick default operating speed");
1452
1453 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
1454 if (err) {
1455 BT_ERR("wcn3990 serdev registration failed");
1456 goto out;
1457 }
1458 } else {
1459 qcadev->btsoc_type = QCA_ROME;
1460 qcadev->bt_en = devm_gpiod_get(&serdev->dev, "enable",
1461 GPIOD_OUT_LOW);
1462 if (IS_ERR(qcadev->bt_en)) {
1463 dev_err(&serdev->dev, "failed to acquire enable gpio\n");
1464 return PTR_ERR(qcadev->bt_en);
1465 }
1466
1467 qcadev->susclk = devm_clk_get(&serdev->dev, NULL);
1468 if (IS_ERR(qcadev->susclk)) {
1469 dev_err(&serdev->dev, "failed to acquire clk\n");
1470 return PTR_ERR(qcadev->susclk);
1471 }
1472
1473 err = clk_set_rate(qcadev->susclk, SUSCLK_RATE_32KHZ);
1474 if (err)
1475 return err;
1476
1477 err = clk_prepare_enable(qcadev->susclk);
1478 if (err)
1479 return err;
1480
1481 err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto);
1482 if (err)
1483 clk_disable_unprepare(qcadev->susclk);
Thierry Escande05ba5332018-03-29 21:15:24 +02001484 }
1485
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301486out: return err;
Thierry Escande05ba5332018-03-29 21:15:24 +02001487
Thierry Escande05ba5332018-03-29 21:15:24 +02001488}
1489
1490static void qca_serdev_remove(struct serdev_device *serdev)
1491{
1492 struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
1493
Harish Bandi523760b2019-04-26 19:26:01 +05301494 if (qca_is_wcn399x(qcadev->btsoc_type))
Balakrishna Godavarthic2d78272018-08-22 17:50:05 +05301495 qca_power_shutdown(&qcadev->serdev_hu);
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301496 else
1497 clk_disable_unprepare(qcadev->susclk);
Thierry Escande05ba5332018-03-29 21:15:24 +02001498
Balakrishna Godavarthifa9ad872018-08-03 17:46:32 +05301499 hci_uart_unregister_device(&qcadev->serdev_hu);
Thierry Escande05ba5332018-03-29 21:15:24 +02001500}
1501
1502static const struct of_device_id qca_bluetooth_of_match[] = {
1503 { .compatible = "qcom,qca6174-bt" },
Harish Bandi523760b2019-04-26 19:26:01 +05301504 { .compatible = "qcom,wcn3990-bt", .data = &qca_soc_data_wcn3990},
1505 { .compatible = "qcom,wcn3998-bt", .data = &qca_soc_data_wcn3998},
Thierry Escande05ba5332018-03-29 21:15:24 +02001506 { /* sentinel */ }
1507};
1508MODULE_DEVICE_TABLE(of, qca_bluetooth_of_match);
1509
1510static struct serdev_device_driver qca_serdev_driver = {
1511 .probe = qca_serdev_probe,
1512 .remove = qca_serdev_remove,
1513 .driver = {
1514 .name = "hci_uart_qca",
1515 .of_match_table = qca_bluetooth_of_match,
1516 },
1517};
1518
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001519int __init qca_init(void)
1520{
Thierry Escande05ba5332018-03-29 21:15:24 +02001521 serdev_device_driver_register(&qca_serdev_driver);
1522
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001523 return hci_uart_register_proto(&qca_proto);
1524}
1525
1526int __exit qca_deinit(void)
1527{
Thierry Escande05ba5332018-03-29 21:15:24 +02001528 serdev_device_driver_unregister(&qca_serdev_driver);
1529
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -07001530 return hci_uart_unregister_proto(&qca_proto);
1531}