Thomas Gleixner | 4505153 | 2019-05-29 16:57:47 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 2 | /* |
| 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 Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 9 | * Copyright (c) 2010, 2012, 2018 The Linux Foundation. All rights reserved. |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 10 | * |
| 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 Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 19 | #include <linux/clk.h> |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 20 | #include <linux/completion.h> |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 21 | #include <linux/debugfs.h> |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 22 | #include <linux/delay.h> |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 23 | #include <linux/devcoredump.h> |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 24 | #include <linux/device.h> |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 25 | #include <linux/gpio/consumer.h> |
| 26 | #include <linux/mod_devicetable.h> |
| 27 | #include <linux/module.h> |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 28 | #include <linux/of_device.h> |
| 29 | #include <linux/platform_device.h> |
| 30 | #include <linux/regulator/consumer.h> |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 31 | #include <linux/serdev.h> |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Balakrishna Godavarthi | c614ca3 | 2018-10-16 19:51:35 +0530 | [diff] [blame] | 33 | #include <asm/unaligned.h> |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 34 | |
| 35 | #include <net/bluetooth/bluetooth.h> |
| 36 | #include <net/bluetooth/hci_core.h> |
| 37 | |
| 38 | #include "hci_uart.h" |
| 39 | #include "btqca.h" |
| 40 | |
| 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 |
Marcel Holtmann | f81b001 | 2015-08-30 23:05:32 +0200 | [diff] [blame] | 45 | #define HCI_MAX_IBS_SIZE 10 |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 46 | |
Marcel Holtmann | f81b001 | 2015-08-30 23:05:32 +0200 | [diff] [blame] | 47 | #define IBS_WAKE_RETRANS_TIMEOUT_MS 100 |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 48 | #define IBS_BTSOC_TX_IDLE_TIMEOUT_MS 40 |
| 49 | #define IBS_HOST_TX_IDLE_TIMEOUT_MS 2000 |
Matthias Kaehlcke | 94d6671 | 2019-02-27 15:52:23 -0800 | [diff] [blame] | 50 | #define CMD_TRANS_TIMEOUT_MS 100 |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 51 | #define MEMDUMP_TIMEOUT_MS 8000 |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 52 | |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 53 | /* susclk rate */ |
| 54 | #define SUSCLK_RATE_32KHZ 32768 |
| 55 | |
Balakrishna Godavarthi | c614ca3 | 2018-10-16 19:51:35 +0530 | [diff] [blame] | 56 | /* Controller debug log header */ |
| 57 | #define QCA_DEBUG_HANDLE 0x2EDC |
| 58 | |
Rocky Liao | bb2500ab | 2020-01-15 16:55:51 +0800 | [diff] [blame] | 59 | /* max retry count when init fails */ |
| 60 | #define MAX_INIT_RETRIES 3 |
| 61 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 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 |
| 68 | |
Matthias Kaehlcke | 62a9199 | 2019-04-29 16:21:30 -0700 | [diff] [blame] | 69 | enum qca_flags { |
| 70 | QCA_IBS_ENABLED, |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 71 | QCA_DROP_VENDOR_EVENT, |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 72 | QCA_SUSPENDING, |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 73 | QCA_MEMDUMP_COLLECTION, |
| 74 | QCA_HW_ERROR_EVENT |
Matthias Kaehlcke | 62a9199 | 2019-04-29 16:21:30 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 77 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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, |
| 83 | }; |
| 84 | |
| 85 | /* HCI_IBS receive side sleep protocol states */ |
| 86 | enum rx_states { |
| 87 | HCI_IBS_RX_ASLEEP, |
| 88 | HCI_IBS_RX_AWAKE, |
| 89 | }; |
| 90 | |
| 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, |
| 98 | }; |
| 99 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 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, |
| 106 | }; |
| 107 | |
| 108 | struct qca_memdump_data { |
| 109 | char *memdump_buf_head; |
| 110 | char *memdump_buf_tail; |
| 111 | u32 current_seq_no; |
| 112 | u32 received_dump; |
| 113 | }; |
| 114 | |
| 115 | struct qca_memdump_event_hdr { |
| 116 | __u8 evt; |
| 117 | __u8 plen; |
| 118 | __u16 opcode; |
| 119 | __u16 seq_no; |
| 120 | __u8 reserved; |
| 121 | } __packed; |
| 122 | |
| 123 | |
| 124 | struct qca_dump_size { |
| 125 | u32 dump_size; |
| 126 | } __packed; |
| 127 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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 */ |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 133 | struct sk_buff_head rx_memdump_q; /* Memdump wait queue */ |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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 */ |
Viresh Kumar | 621a5f7 | 2015-09-26 15:04:07 -0700 | [diff] [blame] | 137 | bool tx_vote; /* Clock must be on for TX */ |
| 138 | bool rx_vote; /* Clock must be on for RX */ |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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; |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 148 | struct work_struct ctrl_memdump_evt; |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 149 | struct delayed_work ctrl_memdump_timeout; |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 150 | struct qca_memdump_data *qca_memdump; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 151 | unsigned long flags; |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 152 | struct completion drop_ev_comp; |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 153 | wait_queue_head_t suspend_wait_q; |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 154 | enum qca_memdump_states memdump_state; |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 155 | struct mutex hci_memdump_lock; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 156 | |
| 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; |
| 173 | }; |
| 174 | |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 175 | enum qca_speed_type { |
| 176 | QCA_INIT_SPEED = 1, |
| 177 | QCA_OPER_SPEED |
| 178 | }; |
| 179 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 180 | /* |
| 181 | * Voltage regulator information required for configuring the |
| 182 | * QCA Bluetooth chipset |
| 183 | */ |
| 184 | struct qca_vreg { |
| 185 | const char *name; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 186 | unsigned int load_uA; |
| 187 | }; |
| 188 | |
| 189 | struct qca_vreg_data { |
| 190 | enum qca_btsoc_type soc_type; |
| 191 | struct qca_vreg *vregs; |
| 192 | size_t num_vregs; |
| 193 | }; |
| 194 | |
| 195 | /* |
| 196 | * Platform data for the QCA Bluetooth power driver. |
| 197 | */ |
| 198 | struct qca_power { |
| 199 | struct device *dev; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 200 | struct regulator_bulk_data *vreg_bulk; |
Bjorn Andersson | 163d42f | 2019-10-17 22:24:03 -0700 | [diff] [blame] | 201 | int num_vregs; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 202 | bool vregs_on; |
| 203 | }; |
| 204 | |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 205 | struct qca_serdev { |
| 206 | struct hci_uart serdev_hu; |
| 207 | struct gpio_desc *bt_en; |
| 208 | struct clk *susclk; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 209 | enum qca_btsoc_type btsoc_type; |
| 210 | struct qca_power *bt_power; |
| 211 | u32 init_speed; |
| 212 | u32 oper_speed; |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 213 | const char *firmware_name; |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 214 | }; |
| 215 | |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 216 | static int qca_regulator_enable(struct qca_serdev *qcadev); |
| 217 | static void qca_regulator_disable(struct qca_serdev *qcadev); |
Balakrishna Godavarthi | c2d7827 | 2018-08-22 17:50:05 +0530 | [diff] [blame] | 218 | static void qca_power_shutdown(struct hci_uart *hu); |
Balakrishna Godavarthi | 3e4be65 | 2018-09-24 20:14:45 +0530 | [diff] [blame] | 219 | static int qca_power_off(struct hci_dev *hdev); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 220 | static void qca_controller_memdump(struct work_struct *work); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 221 | |
Matthias Kaehlcke | 4fdd5a4 | 2019-03-11 11:38:31 -0700 | [diff] [blame] | 222 | static enum qca_btsoc_type qca_soc_type(struct hci_uart *hu) |
| 223 | { |
| 224 | enum qca_btsoc_type soc_type; |
| 225 | |
| 226 | if (hu->serdev) { |
| 227 | struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev); |
| 228 | |
| 229 | soc_type = qsd->btsoc_type; |
| 230 | } else { |
| 231 | soc_type = QCA_ROME; |
| 232 | } |
| 233 | |
| 234 | return soc_type; |
| 235 | } |
| 236 | |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 237 | static const char *qca_get_firmware_name(struct hci_uart *hu) |
| 238 | { |
| 239 | if (hu->serdev) { |
| 240 | struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev); |
| 241 | |
| 242 | return qsd->firmware_name; |
| 243 | } else { |
| 244 | return NULL; |
| 245 | } |
| 246 | } |
| 247 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 248 | static void __serial_clock_on(struct tty_struct *tty) |
| 249 | { |
| 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 |
| 253 | */ |
| 254 | } |
| 255 | |
| 256 | static void __serial_clock_off(struct tty_struct *tty) |
| 257 | { |
| 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 |
| 261 | */ |
| 262 | } |
| 263 | |
| 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) |
| 266 | { |
| 267 | struct qca_data *qca = hu->priv; |
| 268 | unsigned int diff; |
| 269 | |
| 270 | bool old_vote = (qca->tx_vote | qca->rx_vote); |
| 271 | bool new_vote; |
| 272 | |
| 273 | switch (vote) { |
| 274 | case HCI_IBS_VOTE_STATS_UPDATE: |
| 275 | diff = jiffies_to_msecs(jiffies - qca->vote_last_jif); |
| 276 | |
| 277 | if (old_vote) |
| 278 | qca->vote_off_ms += diff; |
| 279 | else |
| 280 | qca->vote_on_ms += diff; |
| 281 | return; |
| 282 | |
| 283 | case HCI_IBS_TX_VOTE_CLOCK_ON: |
| 284 | qca->tx_vote = true; |
| 285 | qca->tx_votes_on++; |
| 286 | new_vote = true; |
| 287 | break; |
| 288 | |
| 289 | case HCI_IBS_RX_VOTE_CLOCK_ON: |
| 290 | qca->rx_vote = true; |
| 291 | qca->rx_votes_on++; |
| 292 | new_vote = true; |
| 293 | break; |
| 294 | |
| 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; |
| 300 | |
| 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; |
| 306 | |
| 307 | default: |
| 308 | BT_ERR("Voting irregularity"); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | if (new_vote != old_vote) { |
| 313 | if (new_vote) |
| 314 | __serial_clock_on(hu->tty); |
| 315 | else |
| 316 | __serial_clock_off(hu->tty); |
| 317 | |
Prasanna Karthik | ce26d81 | 2015-09-15 12:19:45 +0000 | [diff] [blame] | 318 | BT_DBG("Vote serial clock %s(%s)", new_vote ? "true" : "false", |
| 319 | vote ? "true" : "false"); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 320 | |
| 321 | diff = jiffies_to_msecs(jiffies - qca->vote_last_jif); |
| 322 | |
| 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; |
| 329 | } |
| 330 | qca->vote_last_jif = jiffies; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /* Builds and sends an HCI_IBS command packet. |
| 335 | * These are very simple packets with only 1 cmd byte. |
| 336 | */ |
| 337 | static int send_hci_ibs_cmd(u8 cmd, struct hci_uart *hu) |
| 338 | { |
| 339 | int err = 0; |
| 340 | struct sk_buff *skb = NULL; |
| 341 | struct qca_data *qca = hu->priv; |
| 342 | |
| 343 | BT_DBG("hu %p send hci ibs cmd 0x%x", hu, cmd); |
| 344 | |
| 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; |
| 349 | } |
| 350 | |
| 351 | /* Assign HCI_IBS type */ |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 352 | skb_put_u8(skb, cmd); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 353 | |
| 354 | skb_queue_tail(&qca->txq, skb); |
| 355 | |
| 356 | return err; |
| 357 | } |
| 358 | |
| 359 | static void qca_wq_awake_device(struct work_struct *work) |
| 360 | { |
| 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; |
Harish Bandi | 31fb1bb | 2019-09-04 10:04:16 +0530 | [diff] [blame] | 365 | unsigned long flags; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 366 | |
| 367 | BT_DBG("hu %p wq awake device", hu); |
| 368 | |
| 369 | /* Vote for serial clock */ |
| 370 | serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_ON, hu); |
| 371 | |
Harish Bandi | 31fb1bb | 2019-09-04 10:04:16 +0530 | [diff] [blame] | 372 | spin_lock_irqsave(&qca->hci_ibs_lock, flags); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 373 | |
| 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"); |
| 377 | |
| 378 | qca->ibs_sent_wakes++; |
| 379 | |
| 380 | /* Start retransmit timer */ |
| 381 | retrans_delay = msecs_to_jiffies(qca->wake_retrans); |
| 382 | mod_timer(&qca->wake_retrans_timer, jiffies + retrans_delay); |
| 383 | |
Harish Bandi | 31fb1bb | 2019-09-04 10:04:16 +0530 | [diff] [blame] | 384 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 385 | |
| 386 | /* Actually send the packets */ |
| 387 | hci_uart_tx_wakeup(hu); |
| 388 | } |
| 389 | |
| 390 | static void qca_wq_awake_rx(struct work_struct *work) |
| 391 | { |
| 392 | struct qca_data *qca = container_of(work, struct qca_data, |
| 393 | ws_awake_rx); |
| 394 | struct hci_uart *hu = qca->hu; |
Harish Bandi | 31fb1bb | 2019-09-04 10:04:16 +0530 | [diff] [blame] | 395 | unsigned long flags; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 396 | |
| 397 | BT_DBG("hu %p wq awake rx", hu); |
| 398 | |
| 399 | serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_ON, hu); |
| 400 | |
Harish Bandi | 31fb1bb | 2019-09-04 10:04:16 +0530 | [diff] [blame] | 401 | spin_lock_irqsave(&qca->hci_ibs_lock, flags); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 402 | qca->rx_ibs_state = HCI_IBS_RX_AWAKE; |
| 403 | |
| 404 | /* Always acknowledge device wake up, |
| 405 | * sending IBS message doesn't count as TX ON. |
| 406 | */ |
| 407 | if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK, hu) < 0) |
| 408 | BT_ERR("Failed to acknowledge device wake up"); |
| 409 | |
| 410 | qca->ibs_sent_wacks++; |
| 411 | |
Harish Bandi | 31fb1bb | 2019-09-04 10:04:16 +0530 | [diff] [blame] | 412 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 413 | |
| 414 | /* Actually send the packets */ |
| 415 | hci_uart_tx_wakeup(hu); |
| 416 | } |
| 417 | |
| 418 | static void qca_wq_serial_rx_clock_vote_off(struct work_struct *work) |
| 419 | { |
| 420 | struct qca_data *qca = container_of(work, struct qca_data, |
| 421 | ws_rx_vote_off); |
| 422 | struct hci_uart *hu = qca->hu; |
| 423 | |
| 424 | BT_DBG("hu %p rx clock vote off", hu); |
| 425 | |
| 426 | serial_clock_vote(HCI_IBS_RX_VOTE_CLOCK_OFF, hu); |
| 427 | } |
| 428 | |
| 429 | static void qca_wq_serial_tx_clock_vote_off(struct work_struct *work) |
| 430 | { |
| 431 | struct qca_data *qca = container_of(work, struct qca_data, |
| 432 | ws_tx_vote_off); |
| 433 | struct hci_uart *hu = qca->hu; |
| 434 | |
| 435 | BT_DBG("hu %p tx clock vote off", hu); |
| 436 | |
| 437 | /* Run HCI tx handling unlocked */ |
| 438 | hci_uart_tx_wakeup(hu); |
| 439 | |
| 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. |
| 442 | */ |
| 443 | serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF, hu); |
| 444 | } |
| 445 | |
Kees Cook | 0435605 | 2017-10-04 17:54:29 -0700 | [diff] [blame] | 446 | static void hci_ibs_tx_idle_timeout(struct timer_list *t) |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 447 | { |
Kees Cook | 0435605 | 2017-10-04 17:54:29 -0700 | [diff] [blame] | 448 | struct qca_data *qca = from_timer(qca, t, tx_idle_timer); |
| 449 | struct hci_uart *hu = qca->hu; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 450 | unsigned long flags; |
| 451 | |
| 452 | BT_DBG("hu %p idle timeout in %d state", hu, qca->tx_ibs_state); |
| 453 | |
| 454 | spin_lock_irqsave_nested(&qca->hci_ibs_lock, |
| 455 | flags, SINGLE_DEPTH_NESTING); |
| 456 | |
| 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; |
| 463 | } |
| 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; |
| 468 | |
| 469 | case HCI_IBS_TX_ASLEEP: |
| 470 | case HCI_IBS_TX_WAKING: |
| 471 | /* Fall through */ |
| 472 | |
| 473 | default: |
Colin Ian King | e059a46 | 2017-02-17 19:58:10 +0000 | [diff] [blame] | 474 | BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 475 | break; |
| 476 | } |
| 477 | |
| 478 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 479 | } |
| 480 | |
Kees Cook | 0435605 | 2017-10-04 17:54:29 -0700 | [diff] [blame] | 481 | static void hci_ibs_wake_retrans_timeout(struct timer_list *t) |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 482 | { |
Kees Cook | 0435605 | 2017-10-04 17:54:29 -0700 | [diff] [blame] | 483 | struct qca_data *qca = from_timer(qca, t, wake_retrans_timer); |
| 484 | struct hci_uart *hu = qca->hu; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 485 | unsigned long flags, retrans_delay; |
Prasanna Karthik | a913718 | 2015-09-28 08:03:24 +0000 | [diff] [blame] | 486 | bool retransmit = false; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 487 | |
| 488 | BT_DBG("hu %p wake retransmit timeout in %d state", |
| 489 | hu, qca->tx_ibs_state); |
| 490 | |
| 491 | spin_lock_irqsave_nested(&qca->hci_ibs_lock, |
| 492 | flags, SINGLE_DEPTH_NESTING); |
| 493 | |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 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; |
| 498 | } |
| 499 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 500 | switch (qca->tx_ibs_state) { |
| 501 | case HCI_IBS_TX_WAKING: |
| 502 | /* No WAKE_ACK, retransmit WAKE */ |
Prasanna Karthik | a913718 | 2015-09-28 08:03:24 +0000 | [diff] [blame] | 503 | retransmit = true; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 504 | if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND, hu) < 0) { |
| 505 | BT_ERR("Failed to acknowledge device wake up"); |
| 506 | break; |
| 507 | } |
| 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; |
| 512 | |
| 513 | case HCI_IBS_TX_ASLEEP: |
| 514 | case HCI_IBS_TX_AWAKE: |
| 515 | /* Fall through */ |
| 516 | |
| 517 | default: |
Colin Ian King | e059a46 | 2017-02-17 19:58:10 +0000 | [diff] [blame] | 518 | BT_ERR("Spurious timeout tx state %d", qca->tx_ibs_state); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 519 | break; |
| 520 | } |
| 521 | |
| 522 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 523 | |
| 524 | if (retransmit) |
| 525 | hci_uart_tx_wakeup(hu); |
| 526 | } |
| 527 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 528 | |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 529 | static void qca_controller_memdump_timeout(struct work_struct *work) |
| 530 | { |
| 531 | struct qca_data *qca = container_of(work, struct qca_data, |
| 532 | ctrl_memdump_timeout.work); |
| 533 | struct hci_uart *hu = qca->hu; |
| 534 | |
| 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. |
| 541 | */ |
| 542 | hci_reset_dev(hu->hdev); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | mutex_unlock(&qca->hci_memdump_lock); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 547 | } |
| 548 | |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 549 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 550 | /* Initialize protocol */ |
| 551 | static int qca_open(struct hci_uart *hu) |
| 552 | { |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 553 | struct qca_serdev *qcadev; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 554 | struct qca_data *qca; |
| 555 | |
| 556 | BT_DBG("hu %p qca_open", hu); |
| 557 | |
Vladis Dronov | b36a155 | 2019-07-30 11:33:45 +0200 | [diff] [blame] | 558 | if (!hci_uart_has_flow_control(hu)) |
| 559 | return -EOPNOTSUPP; |
| 560 | |
Jia-Ju Bai | 25a13e38 | 2018-07-23 11:56:51 +0800 | [diff] [blame] | 561 | qca = kzalloc(sizeof(struct qca_data), GFP_KERNEL); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 562 | if (!qca) |
| 563 | return -ENOMEM; |
| 564 | |
| 565 | skb_queue_head_init(&qca->txq); |
| 566 | skb_queue_head_init(&qca->tx_wait_q); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 567 | skb_queue_head_init(&qca->rx_memdump_q); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 568 | spin_lock_init(&qca->hci_ibs_lock); |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 569 | mutex_init(&qca->hci_memdump_lock); |
Bhaktipriya Shridhar | fac9a60 | 2016-08-30 22:42:53 +0530 | [diff] [blame] | 570 | qca->workqueue = alloc_ordered_workqueue("qca_wq", 0); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 571 | if (!qca->workqueue) { |
| 572 | BT_ERR("QCA Workqueue not initialized properly"); |
| 573 | kfree(qca); |
| 574 | return -ENOMEM; |
| 575 | } |
| 576 | |
| 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); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 581 | INIT_WORK(&qca->ctrl_memdump_evt, qca_controller_memdump); |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 582 | INIT_DELAYED_WORK(&qca->ctrl_memdump_timeout, |
| 583 | qca_controller_memdump_timeout); |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 584 | init_waitqueue_head(&qca->suspend_wait_q); |
| 585 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 586 | qca->hu = hu; |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 587 | init_completion(&qca->drop_ev_comp); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 588 | |
| 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; |
| 592 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 593 | qca->vote_last_jif = jiffies; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 594 | |
| 595 | hu->priv = qca; |
| 596 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 597 | if (hu->serdev) { |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 598 | qcadev = serdev_device_get_drvdata(hu->serdev); |
Rocky Liao | 5e6d840 | 2020-01-13 12:30:20 +0800 | [diff] [blame] | 599 | if (qca_is_wcn399x(qcadev->btsoc_type)) { |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 600 | hu->init_speed = qcadev->init_speed; |
| 601 | hu->oper_speed = qcadev->oper_speed; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Kees Cook | 0435605 | 2017-10-04 17:54:29 -0700 | [diff] [blame] | 605 | timer_setup(&qca->wake_retrans_timer, hci_ibs_wake_retrans_timeout, 0); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 606 | qca->wake_retrans = IBS_WAKE_RETRANS_TIMEOUT_MS; |
| 607 | |
Kees Cook | 0435605 | 2017-10-04 17:54:29 -0700 | [diff] [blame] | 608 | timer_setup(&qca->tx_idle_timer, hci_ibs_tx_idle_timeout, 0); |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 609 | qca->tx_idle_delay = IBS_HOST_TX_IDLE_TIMEOUT_MS; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 610 | |
| 611 | BT_DBG("HCI_UART_QCA open, tx_idle_delay=%u, wake_retrans=%u", |
| 612 | qca->tx_idle_delay, qca->wake_retrans); |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | static void qca_debugfs_init(struct hci_dev *hdev) |
| 618 | { |
| 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; |
| 623 | |
| 624 | if (!hdev->debugfs) |
| 625 | return; |
| 626 | |
| 627 | ibs_dir = debugfs_create_dir("ibs", hdev->debugfs); |
| 628 | |
| 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); |
Ben YoungTae Kim | 10be6c0 | 2015-08-13 22:09:42 -0700 | [diff] [blame] | 645 | debugfs_create_bool("tx_vote", mode, ibs_dir, &qca->tx_vote); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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); |
Ben YoungTae Kim | 10be6c0 | 2015-08-13 22:09:42 -0700 | [diff] [blame] | 648 | debugfs_create_bool("rx_vote", mode, ibs_dir, &qca->rx_vote); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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); |
| 655 | |
| 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); |
| 661 | } |
| 662 | |
| 663 | /* Flush protocol data */ |
| 664 | static int qca_flush(struct hci_uart *hu) |
| 665 | { |
| 666 | struct qca_data *qca = hu->priv; |
| 667 | |
| 668 | BT_DBG("hu %p qca flush", hu); |
| 669 | |
| 670 | skb_queue_purge(&qca->tx_wait_q); |
| 671 | skb_queue_purge(&qca->txq); |
| 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | /* Close protocol */ |
| 677 | static int qca_close(struct hci_uart *hu) |
| 678 | { |
| 679 | struct qca_data *qca = hu->priv; |
| 680 | |
| 681 | BT_DBG("hu %p qca close", hu); |
| 682 | |
| 683 | serial_clock_vote(HCI_IBS_VOTE_STATS_UPDATE, hu); |
| 684 | |
| 685 | skb_queue_purge(&qca->tx_wait_q); |
| 686 | skb_queue_purge(&qca->txq); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 687 | skb_queue_purge(&qca->rx_memdump_q); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 688 | del_timer(&qca->tx_idle_timer); |
| 689 | del_timer(&qca->wake_retrans_timer); |
| 690 | destroy_workqueue(qca->workqueue); |
| 691 | qca->hu = NULL; |
| 692 | |
Rocky Liao | 5559904 | 2020-01-15 16:55:50 +0800 | [diff] [blame] | 693 | qca_power_shutdown(hu); |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 694 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 695 | kfree_skb(qca->rx_skb); |
| 696 | |
| 697 | hu->priv = NULL; |
| 698 | |
| 699 | kfree(qca); |
| 700 | |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | /* Called upon a wake-up-indication from the device. |
| 705 | */ |
| 706 | static void device_want_to_wakeup(struct hci_uart *hu) |
| 707 | { |
| 708 | unsigned long flags; |
| 709 | struct qca_data *qca = hu->priv; |
| 710 | |
| 711 | BT_DBG("hu %p want to wake up", hu); |
| 712 | |
| 713 | spin_lock_irqsave(&qca->hci_ibs_lock, flags); |
| 714 | |
| 715 | qca->ibs_recv_wakes++; |
| 716 | |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 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; |
| 721 | } |
| 722 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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. |
| 727 | */ |
| 728 | queue_work(qca->workqueue, &qca->ws_awake_rx); |
| 729 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 730 | return; |
| 731 | |
| 732 | case HCI_IBS_RX_AWAKE: |
| 733 | /* Always acknowledge device wake up, |
| 734 | * sending IBS message doesn't count as TX ON. |
| 735 | */ |
| 736 | if (send_hci_ibs_cmd(HCI_IBS_WAKE_ACK, hu) < 0) { |
| 737 | BT_ERR("Failed to acknowledge device wake up"); |
| 738 | break; |
| 739 | } |
| 740 | qca->ibs_sent_wacks++; |
| 741 | break; |
| 742 | |
| 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; |
| 748 | } |
| 749 | |
| 750 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 751 | |
| 752 | /* Actually send the packets */ |
| 753 | hci_uart_tx_wakeup(hu); |
| 754 | } |
| 755 | |
| 756 | /* Called upon a sleep-indication from the device. |
| 757 | */ |
| 758 | static void device_want_to_sleep(struct hci_uart *hu) |
| 759 | { |
| 760 | unsigned long flags; |
| 761 | struct qca_data *qca = hu->priv; |
| 762 | |
Rocky Liao | 6600c08 | 2019-08-14 15:42:39 +0800 | [diff] [blame] | 763 | BT_DBG("hu %p want to sleep in %d state", hu, qca->rx_ibs_state); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 764 | |
| 765 | spin_lock_irqsave(&qca->hci_ibs_lock, flags); |
| 766 | |
| 767 | qca->ibs_recv_slps++; |
| 768 | |
| 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; |
| 776 | |
| 777 | case HCI_IBS_RX_ASLEEP: |
Rocky Liao | 6600c08 | 2019-08-14 15:42:39 +0800 | [diff] [blame] | 778 | break; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 779 | |
| 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; |
| 785 | } |
| 786 | |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 787 | wake_up_interruptible(&qca->suspend_wait_q); |
| 788 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 789 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 790 | } |
| 791 | |
| 792 | /* Called upon wake-up-acknowledgement from the device |
| 793 | */ |
| 794 | static void device_woke_up(struct hci_uart *hu) |
| 795 | { |
| 796 | unsigned long flags, idle_delay; |
| 797 | struct qca_data *qca = hu->priv; |
| 798 | struct sk_buff *skb = NULL; |
| 799 | |
| 800 | BT_DBG("hu %p woke up", hu); |
| 801 | |
| 802 | spin_lock_irqsave(&qca->hci_ibs_lock, flags); |
| 803 | |
| 804 | qca->ibs_recv_wacks++; |
| 805 | |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 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; |
| 810 | } |
| 811 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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; |
| 818 | |
| 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); |
| 823 | |
| 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; |
| 830 | |
| 831 | case HCI_IBS_TX_ASLEEP: |
| 832 | /* Fall through */ |
| 833 | |
| 834 | default: |
| 835 | BT_ERR("Received HCI_IBS_WAKE_ACK in tx state %d", |
| 836 | qca->tx_ibs_state); |
| 837 | break; |
| 838 | } |
| 839 | |
| 840 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 841 | |
| 842 | /* Actually send the packets */ |
| 843 | hci_uart_tx_wakeup(hu); |
| 844 | } |
| 845 | |
| 846 | /* Enqueue frame for transmittion (padding, crc, etc) may be called from |
| 847 | * two simultaneous tasklets. |
| 848 | */ |
| 849 | static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb) |
| 850 | { |
| 851 | unsigned long flags = 0, idle_delay; |
| 852 | struct qca_data *qca = hu->priv; |
| 853 | |
| 854 | BT_DBG("hu %p qca enq skb %p tx_ibs_state %d", hu, skb, |
| 855 | qca->tx_ibs_state); |
| 856 | |
| 857 | /* Prepend skb with frame type */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 858 | memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 859 | |
Balakrishna Godavarthi | 035a960 | 2019-02-04 20:36:43 +0530 | [diff] [blame] | 860 | spin_lock_irqsave(&qca->hci_ibs_lock, flags); |
| 861 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 862 | /* Don't go to sleep in middle of patch download or |
| 863 | * Out-Of-Band(GPIOs control) sleep is selected. |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 864 | * Don't wake the device up when suspending. |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 865 | */ |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 866 | if (!test_bit(QCA_IBS_ENABLED, &qca->flags) || |
| 867 | test_bit(QCA_SUSPENDING, &qca->flags)) { |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 868 | skb_queue_tail(&qca->txq, skb); |
Balakrishna Godavarthi | 035a960 | 2019-02-04 20:36:43 +0530 | [diff] [blame] | 869 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 870 | return 0; |
| 871 | } |
| 872 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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; |
| 881 | |
| 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); |
| 886 | |
| 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; |
| 891 | |
| 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; |
| 897 | |
| 898 | default: |
| 899 | BT_ERR("Illegal tx state: %d (losing packet)", |
| 900 | qca->tx_ibs_state); |
| 901 | kfree_skb(skb); |
| 902 | break; |
| 903 | } |
| 904 | |
| 905 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 906 | |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | static int qca_ibs_sleep_ind(struct hci_dev *hdev, struct sk_buff *skb) |
| 911 | { |
| 912 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 913 | |
| 914 | BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_SLEEP_IND); |
| 915 | |
| 916 | device_want_to_sleep(hu); |
| 917 | |
| 918 | kfree_skb(skb); |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | static int qca_ibs_wake_ind(struct hci_dev *hdev, struct sk_buff *skb) |
| 923 | { |
| 924 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 925 | |
| 926 | BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_WAKE_IND); |
| 927 | |
| 928 | device_want_to_wakeup(hu); |
| 929 | |
| 930 | kfree_skb(skb); |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static int qca_ibs_wake_ack(struct hci_dev *hdev, struct sk_buff *skb) |
| 935 | { |
| 936 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 937 | |
| 938 | BT_DBG("hu %p recv hci ibs cmd 0x%x", hu, HCI_IBS_WAKE_ACK); |
| 939 | |
| 940 | device_woke_up(hu); |
| 941 | |
| 942 | kfree_skb(skb); |
| 943 | return 0; |
| 944 | } |
| 945 | |
Balakrishna Godavarthi | c614ca3 | 2018-10-16 19:51:35 +0530 | [diff] [blame] | 946 | static int qca_recv_acl_data(struct hci_dev *hdev, struct sk_buff *skb) |
| 947 | { |
| 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. |
| 952 | */ |
| 953 | if (get_unaligned_le16(skb->data) == QCA_DEBUG_HANDLE) |
| 954 | return hci_recv_diag(hdev, skb); |
| 955 | |
| 956 | return hci_recv_frame(hdev, skb); |
| 957 | } |
| 958 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 959 | static void qca_controller_memdump(struct work_struct *work) |
| 960 | { |
| 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 }; |
YueHaibing | 56b084e | 2020-01-08 01:54:31 +0000 | [diff] [blame] | 970 | u16 seq_no; |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 971 | u32 dump_size; |
| 972 | |
| 973 | while ((skb = skb_dequeue(&qca->rx_memdump_q))) { |
| 974 | |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 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; |
| 980 | } |
| 981 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 982 | if (!qca_memdump) { |
| 983 | qca_memdump = kzalloc(sizeof(struct qca_memdump_data), |
| 984 | GFP_ATOMIC); |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 985 | if (!qca_memdump) { |
| 986 | mutex_unlock(&qca->hci_memdump_lock); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 987 | return; |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 988 | } |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 989 | |
| 990 | qca->qca_memdump = qca_memdump; |
| 991 | } |
| 992 | |
| 993 | qca->memdump_state = QCA_MEMDUMP_COLLECTING; |
| 994 | cmd_hdr = (void *) skb->data; |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 995 | seq_no = __le16_to_cpu(cmd_hdr->seq_no); |
| 996 | skb_pull(skb, sizeof(struct qca_memdump_event_hdr)); |
| 997 | |
| 998 | if (!seq_no) { |
| 999 | |
| 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. |
| 1005 | */ |
| 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); |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1013 | mutex_unlock(&qca->hci_memdump_lock); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | bt_dev_info(hu->hdev, "QCA collecting dump of size:%u", |
| 1018 | dump_size); |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1019 | queue_delayed_work(qca->workqueue, |
| 1020 | &qca->ctrl_memdump_timeout, |
| 1021 | msecs_to_jiffies(MEMDUMP_TIMEOUT_MS)); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1022 | |
| 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; |
| 1027 | } |
| 1028 | |
| 1029 | memdump_buf = qca_memdump->memdump_buf_tail; |
| 1030 | |
| 1031 | /* If sequence no 0 is missed then there is no point in |
| 1032 | * accepting the other sequences. |
| 1033 | */ |
| 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; |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1039 | mutex_unlock(&qca->hci_memdump_lock); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1040 | return; |
| 1041 | } |
| 1042 | |
| 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. |
| 1046 | */ |
| 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++; |
| 1055 | } |
| 1056 | |
| 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); |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1070 | cancel_delayed_work(&qca->ctrl_memdump_timeout); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1071 | kfree(qca->qca_memdump); |
| 1072 | qca->qca_memdump = NULL; |
| 1073 | qca->memdump_state = QCA_MEMDUMP_COLLECTED; |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1074 | clear_bit(QCA_MEMDUMP_COLLECTION, &qca->flags); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1075 | } |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1076 | |
| 1077 | mutex_unlock(&qca->hci_memdump_lock); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | } |
| 1081 | |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1082 | static int qca_controller_memdump_event(struct hci_dev *hdev, |
| 1083 | struct sk_buff *skb) |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1084 | { |
| 1085 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1086 | struct qca_data *qca = hu->priv; |
| 1087 | |
| 1088 | skb_queue_tail(&qca->rx_memdump_q, skb); |
| 1089 | queue_work(qca->workqueue, &qca->ctrl_memdump_evt); |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 1094 | static int qca_recv_event(struct hci_dev *hdev, struct sk_buff *skb) |
| 1095 | { |
| 1096 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1097 | struct qca_data *qca = hu->priv; |
| 1098 | |
| 1099 | if (test_bit(QCA_DROP_VENDOR_EVENT, &qca->flags)) { |
| 1100 | struct hci_event_hdr *hdr = (void *)skb->data; |
| 1101 | |
| 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). |
| 1110 | */ |
| 1111 | |
| 1112 | if (hdr->evt == HCI_EV_VENDOR) |
| 1113 | complete(&qca->drop_ev_comp); |
| 1114 | |
Wei Yongjun | 4974c83 | 2019-07-09 01:35:30 +0000 | [diff] [blame] | 1115 | kfree_skb(skb); |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 1116 | |
| 1117 | return 0; |
| 1118 | } |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 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. |
| 1123 | */ |
| 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); |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 1127 | |
| 1128 | return hci_recv_frame(hdev, skb); |
| 1129 | } |
| 1130 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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 |
| 1137 | |
| 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 |
| 1144 | |
| 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 |
| 1151 | |
| 1152 | static const struct h4_recv_pkt qca_recv_pkts[] = { |
Balakrishna Godavarthi | c614ca3 | 2018-10-16 19:51:35 +0530 | [diff] [blame] | 1153 | { H4_RECV_ACL, .recv = qca_recv_acl_data }, |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1154 | { H4_RECV_SCO, .recv = hci_recv_frame }, |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 1155 | { H4_RECV_EVENT, .recv = qca_recv_event }, |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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 }, |
| 1159 | }; |
| 1160 | |
| 1161 | static int qca_recv(struct hci_uart *hu, const void *data, int count) |
| 1162 | { |
| 1163 | struct qca_data *qca = hu->priv; |
| 1164 | |
| 1165 | if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) |
| 1166 | return -EUNATCH; |
| 1167 | |
| 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); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1172 | bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1173 | qca->rx_skb = NULL; |
| 1174 | return err; |
| 1175 | } |
| 1176 | |
| 1177 | return count; |
| 1178 | } |
| 1179 | |
| 1180 | static struct sk_buff *qca_dequeue(struct hci_uart *hu) |
| 1181 | { |
| 1182 | struct qca_data *qca = hu->priv; |
| 1183 | |
| 1184 | return skb_dequeue(&qca->txq); |
| 1185 | } |
| 1186 | |
| 1187 | static uint8_t qca_get_baudrate_value(int speed) |
| 1188 | { |
Prasanna Karthik | ce26d81 | 2015-09-15 12:19:45 +0000 | [diff] [blame] | 1189 | switch (speed) { |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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; |
Balakrishna Godavarthi | be93a49 | 2018-08-03 17:46:30 +0530 | [diff] [blame] | 1214 | case 3200000: |
| 1215 | return QCA_BAUDRATE_3200000; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1216 | case 3500000: |
| 1217 | return QCA_BAUDRATE_3500000; |
| 1218 | default: |
| 1219 | return QCA_BAUDRATE_115200; |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate) |
| 1224 | { |
| 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 }; |
| 1229 | |
Balakrishna Godavarthi | be93a49 | 2018-08-03 17:46:30 +0530 | [diff] [blame] | 1230 | if (baudrate > QCA_BAUDRATE_3200000) |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1231 | return -EINVAL; |
| 1232 | |
| 1233 | cmd[4] = baudrate; |
| 1234 | |
Jia-Ju Bai | 25a13e38 | 2018-07-23 11:56:51 +0800 | [diff] [blame] | 1235 | skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1236 | if (!skb) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1237 | bt_dev_err(hdev, "Failed to allocate baudrate packet"); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1238 | return -ENOMEM; |
| 1239 | } |
| 1240 | |
| 1241 | /* Assign commands to change baudrate and packet type. */ |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 1242 | skb_put_data(skb, cmd, sizeof(cmd)); |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 1243 | hci_skb_pkt_type(skb) = HCI_COMMAND_PKT; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1244 | |
| 1245 | skb_queue_tail(&qca->txq, skb); |
| 1246 | hci_uart_tx_wakeup(hu); |
| 1247 | |
Matthias Kaehlcke | 94d6671 | 2019-02-27 15:52:23 -0800 | [diff] [blame] | 1248 | /* Wait for the baudrate change request to be sent */ |
| 1249 | |
| 1250 | while (!skb_queue_empty(&qca->txq)) |
| 1251 | usleep_range(100, 200); |
| 1252 | |
Matthias Kaehlcke | ecf2b76 | 2019-04-23 11:16:52 -0700 | [diff] [blame] | 1253 | if (hu->serdev) |
| 1254 | serdev_device_wait_until_sent(hu->serdev, |
Matthias Kaehlcke | 94d6671 | 2019-02-27 15:52:23 -0800 | [diff] [blame] | 1255 | msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS)); |
| 1256 | |
| 1257 | /* Give the controller time to process the request */ |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1258 | if (qca_is_wcn399x(qca_soc_type(hu))) |
Matthias Kaehlcke | 94d6671 | 2019-02-27 15:52:23 -0800 | [diff] [blame] | 1259 | msleep(10); |
| 1260 | else |
| 1261 | msleep(300); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1262 | |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1266 | static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed) |
| 1267 | { |
| 1268 | if (hu->serdev) |
| 1269 | serdev_device_set_baudrate(hu->serdev, speed); |
| 1270 | else |
| 1271 | hci_uart_set_baudrate(hu, speed); |
| 1272 | } |
| 1273 | |
Matthias Kaehlcke | 9836b80 | 2019-02-26 11:46:45 -0800 | [diff] [blame] | 1274 | static int qca_send_power_pulse(struct hci_uart *hu, bool on) |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1275 | { |
Balakrishna Godavarthi | f955827 | 2019-02-04 20:36:41 +0530 | [diff] [blame] | 1276 | int ret; |
Matthias Kaehlcke | 94d6671 | 2019-02-27 15:52:23 -0800 | [diff] [blame] | 1277 | int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS); |
Matthias Kaehlcke | 9836b80 | 2019-02-26 11:46:45 -0800 | [diff] [blame] | 1278 | u8 cmd = on ? QCA_WCN3990_POWERON_PULSE : QCA_WCN3990_POWEROFF_PULSE; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1279 | |
| 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. |
| 1289 | */ |
Balakrishna Godavarthi | f955827 | 2019-02-04 20:36:41 +0530 | [diff] [blame] | 1290 | bt_dev_dbg(hu->hdev, "sending power pulse %02x to controller", cmd); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1291 | |
Balakrishna Godavarthi | f955827 | 2019-02-04 20:36:41 +0530 | [diff] [blame] | 1292 | serdev_device_write_flush(hu->serdev); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1293 | hci_uart_set_flow_control(hu, true); |
Balakrishna Godavarthi | f955827 | 2019-02-04 20:36:41 +0530 | [diff] [blame] | 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; |
| 1298 | } |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1299 | |
Balakrishna Godavarthi | f955827 | 2019-02-04 20:36:41 +0530 | [diff] [blame] | 1300 | serdev_device_wait_until_sent(hu->serdev, timeout); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1301 | hci_uart_set_flow_control(hu, false); |
| 1302 | |
Matthias Kaehlcke | 0ebcddd | 2019-02-26 11:46:47 -0800 | [diff] [blame] | 1303 | /* Give to controller time to boot/shutdown */ |
Matthias Kaehlcke | ad571d7 | 2019-02-26 11:46:46 -0800 | [diff] [blame] | 1304 | if (on) |
| 1305 | msleep(100); |
Matthias Kaehlcke | 0ebcddd | 2019-02-26 11:46:47 -0800 | [diff] [blame] | 1306 | else |
| 1307 | msleep(10); |
Matthias Kaehlcke | ad571d7 | 2019-02-26 11:46:46 -0800 | [diff] [blame] | 1308 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1309 | return 0; |
| 1310 | } |
| 1311 | |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1312 | static unsigned int qca_get_speed(struct hci_uart *hu, |
| 1313 | enum qca_speed_type speed_type) |
| 1314 | { |
| 1315 | unsigned int speed = 0; |
| 1316 | |
| 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; |
| 1327 | } |
| 1328 | |
| 1329 | return speed; |
| 1330 | } |
| 1331 | |
| 1332 | static int qca_check_speeds(struct hci_uart *hu) |
| 1333 | { |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1334 | if (qca_is_wcn399x(qca_soc_type(hu))) { |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 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; |
| 1342 | } |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1343 | |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) |
| 1348 | { |
| 1349 | unsigned int speed, qca_baudrate; |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 1350 | struct qca_data *qca = hu->priv; |
Balakrishna Godavarthi | 78e8fa2 | 2019-02-04 20:36:42 +0530 | [diff] [blame] | 1351 | int ret = 0; |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1352 | |
| 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 { |
Matthias Kaehlcke | 4fdd5a4 | 2019-03-11 11:38:31 -0700 | [diff] [blame] | 1358 | enum qca_btsoc_type soc_type = qca_soc_type(hu); |
| 1359 | |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1360 | speed = qca_get_speed(hu, QCA_OPER_SPEED); |
| 1361 | if (!speed) |
| 1362 | return 0; |
| 1363 | |
Balakrishna Godavarthi | 78e8fa2 | 2019-02-04 20:36:42 +0530 | [diff] [blame] | 1364 | /* Disable flow control for wcn3990 to deassert RTS while |
| 1365 | * changing the baudrate of chip and host. |
| 1366 | */ |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1367 | if (qca_is_wcn399x(soc_type)) |
Balakrishna Godavarthi | 78e8fa2 | 2019-02-04 20:36:42 +0530 | [diff] [blame] | 1368 | hci_uart_set_flow_control(hu, true); |
| 1369 | |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 1370 | if (soc_type == QCA_WCN3990) { |
| 1371 | reinit_completion(&qca->drop_ev_comp); |
| 1372 | set_bit(QCA_DROP_VENDOR_EVENT, &qca->flags); |
| 1373 | } |
| 1374 | |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1375 | qca_baudrate = qca_get_baudrate_value(speed); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1376 | bt_dev_dbg(hu->hdev, "Set UART speed to %d", speed); |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1377 | ret = qca_set_baudrate(hu->hdev, qca_baudrate); |
| 1378 | if (ret) |
Balakrishna Godavarthi | 78e8fa2 | 2019-02-04 20:36:42 +0530 | [diff] [blame] | 1379 | goto error; |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1380 | |
| 1381 | host_set_baudrate(hu, speed); |
Balakrishna Godavarthi | 78e8fa2 | 2019-02-04 20:36:42 +0530 | [diff] [blame] | 1382 | |
| 1383 | error: |
Jeffrey Hugo | bba79fe | 2019-10-21 07:18:27 -0700 | [diff] [blame] | 1384 | if (qca_is_wcn399x(soc_type)) |
Balakrishna Godavarthi | 78e8fa2 | 2019-02-04 20:36:42 +0530 | [diff] [blame] | 1385 | hci_uart_set_flow_control(hu, false); |
Matthias Kaehlcke | 2faa3f1 | 2019-05-21 12:53:07 -0700 | [diff] [blame] | 1386 | |
| 1387 | if (soc_type == QCA_WCN3990) { |
| 1388 | /* Wait for the controller to send the vendor event |
| 1389 | * for the baudrate change command. |
| 1390 | */ |
| 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; |
| 1396 | } |
| 1397 | |
| 1398 | clear_bit(QCA_DROP_VENDOR_EVENT, &qca->flags); |
| 1399 | } |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1400 | } |
| 1401 | |
Balakrishna Godavarthi | 78e8fa2 | 2019-02-04 20:36:42 +0530 | [diff] [blame] | 1402 | return ret; |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1403 | } |
| 1404 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1405 | static int qca_send_crashbuffer(struct hci_uart *hu) |
| 1406 | { |
| 1407 | struct qca_data *qca = hu->priv; |
| 1408 | struct sk_buff *skb; |
| 1409 | |
| 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; |
| 1414 | } |
| 1415 | |
| 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. |
| 1419 | */ |
| 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); |
| 1426 | |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
| 1430 | static void qca_wait_for_dump_collection(struct hci_dev *hdev) |
| 1431 | { |
| 1432 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1433 | struct qca_data *qca = hu->priv; |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1434 | |
| 1435 | wait_on_bit_timeout(&qca->flags, QCA_MEMDUMP_COLLECTION, |
| 1436 | TASK_UNINTERRUPTIBLE, MEMDUMP_TIMEOUT_MS); |
| 1437 | |
| 1438 | clear_bit(QCA_MEMDUMP_COLLECTION, &qca->flags); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | static void qca_hw_error(struct hci_dev *hdev, u8 code) |
| 1442 | { |
| 1443 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1444 | struct qca_data *qca = hu->priv; |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1445 | struct qca_memdump_data *qca_memdump = qca->qca_memdump; |
| 1446 | char *memdump_buf = NULL; |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1447 | |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1448 | set_bit(QCA_HW_ERROR_EVENT, &qca->flags); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1449 | bt_dev_info(hdev, "mem_dump_status: %d", qca->memdump_state); |
| 1450 | |
| 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. |
| 1457 | */ |
| 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. |
| 1464 | */ |
| 1465 | bt_dev_info(hdev, "waiting for dump to complete"); |
| 1466 | qca_wait_for_dump_collection(hdev); |
| 1467 | } |
Venkata Lakshmi Narayana Gubba | 7c2c3e6 | 2020-02-14 21:47:15 +0530 | [diff] [blame] | 1468 | |
| 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); |
| 1482 | } |
| 1483 | |
| 1484 | clear_bit(QCA_HW_ERROR_EVENT, &qca->flags); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | static void qca_cmd_timeout(struct hci_dev *hdev) |
| 1488 | { |
| 1489 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1490 | struct qca_data *qca = hu->priv; |
| 1491 | |
| 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"); |
| 1496 | } |
| 1497 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1498 | static int qca_wcn3990_init(struct hci_uart *hu) |
| 1499 | { |
Balakrishna Godavarthi | 3e4be65 | 2018-09-24 20:14:45 +0530 | [diff] [blame] | 1500 | struct qca_serdev *qcadev; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1501 | int ret; |
| 1502 | |
Balakrishna Godavarthi | 3e4be65 | 2018-09-24 20:14:45 +0530 | [diff] [blame] | 1503 | /* Check for vregs status, may be hci down has turned |
| 1504 | * off the voltage regulator. |
| 1505 | */ |
| 1506 | qcadev = serdev_device_get_drvdata(hu->serdev); |
| 1507 | if (!qcadev->bt_power->vregs_on) { |
| 1508 | serdev_device_close(hu->serdev); |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1509 | ret = qca_regulator_enable(qcadev); |
Balakrishna Godavarthi | 3e4be65 | 2018-09-24 20:14:45 +0530 | [diff] [blame] | 1510 | if (ret) |
| 1511 | return ret; |
| 1512 | |
| 1513 | ret = serdev_device_open(hu->serdev); |
| 1514 | if (ret) { |
| 1515 | bt_dev_err(hu->hdev, "failed to open port"); |
| 1516 | return ret; |
| 1517 | } |
| 1518 | } |
| 1519 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1520 | /* Forcefully enable wcn3990 to enter in to boot mode. */ |
| 1521 | host_set_baudrate(hu, 2400); |
Matthias Kaehlcke | 9836b80 | 2019-02-26 11:46:45 -0800 | [diff] [blame] | 1522 | ret = qca_send_power_pulse(hu, false); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1523 | if (ret) |
| 1524 | return ret; |
| 1525 | |
| 1526 | qca_set_speed(hu, QCA_INIT_SPEED); |
Matthias Kaehlcke | 9836b80 | 2019-02-26 11:46:45 -0800 | [diff] [blame] | 1527 | ret = qca_send_power_pulse(hu, true); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1528 | if (ret) |
| 1529 | return ret; |
| 1530 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 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. |
| 1535 | */ |
| 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; |
| 1541 | } |
| 1542 | |
| 1543 | hci_uart_set_flow_control(hu, false); |
| 1544 | |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
Rocky Liao | 5e6d840 | 2020-01-13 12:30:20 +0800 | [diff] [blame] | 1548 | static int qca_power_on(struct hci_dev *hdev) |
| 1549 | { |
| 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; |
| 1554 | |
| 1555 | /* Non-serdev device usually is powered by external power |
| 1556 | * and don't need additional action in driver for power on |
| 1557 | */ |
| 1558 | if (!hu->serdev) |
| 1559 | return 0; |
| 1560 | |
| 1561 | if (qca_is_wcn399x(soc_type)) { |
| 1562 | ret = qca_wcn3990_init(hu); |
| 1563 | } else { |
| 1564 | qcadev = serdev_device_get_drvdata(hu->serdev); |
Rocky Liao | 8a208b2 | 2020-03-04 09:54:29 +0800 | [diff] [blame^] | 1565 | if (!IS_ERR(qcadev->bt_en)) { |
| 1566 | gpiod_set_value_cansleep(qcadev->bt_en, 1); |
| 1567 | /* Controller needs time to bootup. */ |
| 1568 | msleep(150); |
| 1569 | } |
Rocky Liao | 5e6d840 | 2020-01-13 12:30:20 +0800 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | return ret; |
| 1573 | } |
| 1574 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1575 | static int qca_setup(struct hci_uart *hu) |
| 1576 | { |
| 1577 | struct hci_dev *hdev = hu->hdev; |
| 1578 | struct qca_data *qca = hu->priv; |
| 1579 | unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200; |
Rocky Liao | bb2500ab | 2020-01-15 16:55:51 +0800 | [diff] [blame] | 1580 | unsigned int retries = 0; |
Matthias Kaehlcke | 4fdd5a4 | 2019-03-11 11:38:31 -0700 | [diff] [blame] | 1581 | enum qca_btsoc_type soc_type = qca_soc_type(hu); |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 1582 | const char *firmware_name = qca_get_firmware_name(hu); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1583 | int ret; |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 1584 | int soc_ver = 0; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1585 | |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1586 | ret = qca_check_speeds(hu); |
| 1587 | if (ret) |
| 1588 | return ret; |
| 1589 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1590 | /* Patch downloading has to be done without IBS mode */ |
Matthias Kaehlcke | 62a9199 | 2019-04-29 16:21:30 -0700 | [diff] [blame] | 1591 | clear_bit(QCA_IBS_ENABLED, &qca->flags); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1592 | |
Rocky Liao | e14c167 | 2019-08-21 14:23:39 +0800 | [diff] [blame] | 1593 | /* Enable controller to do both LE scan and BR/EDR inquiry |
| 1594 | * simultaneously. |
| 1595 | */ |
| 1596 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
| 1597 | |
Rocky Liao | 5e6d840 | 2020-01-13 12:30:20 +0800 | [diff] [blame] | 1598 | bt_dev_info(hdev, "setting up %s", |
| 1599 | qca_is_wcn399x(soc_type) ? "wcn399x" : "ROME"); |
Balakrishna Godavarthi | 3e4be65 | 2018-09-24 20:14:45 +0530 | [diff] [blame] | 1600 | |
Rocky Liao | bb2500ab | 2020-01-15 16:55:51 +0800 | [diff] [blame] | 1601 | retry: |
Rocky Liao | 5e6d840 | 2020-01-13 12:30:20 +0800 | [diff] [blame] | 1602 | ret = qca_power_on(hdev); |
| 1603 | if (ret) |
| 1604 | return ret; |
| 1605 | |
| 1606 | if (qca_is_wcn399x(soc_type)) { |
Matthias Kaehlcke | 5971752d | 2019-02-19 12:05:59 -0800 | [diff] [blame] | 1607 | set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1608 | |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 1609 | ret = qca_read_soc_version(hdev, &soc_ver, soc_type); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1610 | if (ret) |
| 1611 | return ret; |
| 1612 | } else { |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1613 | qca_set_speed(hu, QCA_INIT_SPEED); |
| 1614 | } |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1615 | |
| 1616 | /* Setup user speed if needed */ |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1617 | speed = qca_get_speed(hu, QCA_OPER_SPEED); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1618 | if (speed) { |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1619 | ret = qca_set_speed(hu, QCA_OPER_SPEED); |
| 1620 | if (ret) |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1621 | return ret; |
Balakrishna Godavarthi | 83d9c5e | 2018-08-03 17:46:29 +0530 | [diff] [blame] | 1622 | |
| 1623 | qca_baudrate = qca_get_baudrate_value(speed); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1626 | if (!qca_is_wcn399x(soc_type)) { |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1627 | /* Get QCA version information */ |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 1628 | ret = qca_read_soc_version(hdev, &soc_ver, soc_type); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1629 | if (ret) |
| 1630 | return ret; |
| 1631 | } |
Balakrishna Godavarthi | aadebac | 2018-08-03 17:46:28 +0530 | [diff] [blame] | 1632 | |
| 1633 | bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1634 | /* Setup patch / NVM configurations */ |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 1635 | ret = qca_uart_setup(hdev, qca_baudrate, soc_type, soc_ver, |
| 1636 | firmware_name); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1637 | if (!ret) { |
Matthias Kaehlcke | 62a9199 | 2019-04-29 16:21:30 -0700 | [diff] [blame] | 1638 | set_bit(QCA_IBS_ENABLED, &qca->flags); |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1639 | qca_debugfs_init(hdev); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1640 | hu->hdev->hw_error = qca_hw_error; |
| 1641 | hu->hdev->cmd_timeout = qca_cmd_timeout; |
Loic Poulain | ba8f359 | 2017-11-06 12:16:56 +0100 | [diff] [blame] | 1642 | } else if (ret == -ENOENT) { |
| 1643 | /* No patch/nvm-config found, run with original fw/config */ |
| 1644 | ret = 0; |
Amit Pundir | 7dc5fe0 | 2018-04-16 12:10:24 +0530 | [diff] [blame] | 1645 | } else if (ret == -EAGAIN) { |
| 1646 | /* |
| 1647 | * Userspace firmware loader will return -EAGAIN in case no |
| 1648 | * patch/nvm-config is found, so run with original fw/config. |
| 1649 | */ |
| 1650 | ret = 0; |
Rocky Liao | bb2500ab | 2020-01-15 16:55:51 +0800 | [diff] [blame] | 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; |
| 1660 | } |
| 1661 | } |
| 1662 | retries++; |
| 1663 | goto retry; |
| 1664 | } |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /* Setup bdaddr */ |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1668 | if (qca_is_wcn399x(soc_type)) |
Balakrishna Godavarthi | 5c0a1001 | 2019-01-16 18:01:15 +0530 | [diff] [blame] | 1669 | hu->hdev->set_bdaddr = qca_set_bdaddr; |
| 1670 | else |
| 1671 | hu->hdev->set_bdaddr = qca_set_bdaddr_rome; |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1672 | |
| 1673 | return ret; |
| 1674 | } |
| 1675 | |
Nishka Dasgupta | 2edc9c5 | 2019-08-15 11:21:49 +0530 | [diff] [blame] | 1676 | static const struct hci_uart_proto qca_proto = { |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 1677 | .id = HCI_UART_QCA, |
| 1678 | .name = "QCA", |
Marcel Holtmann | aee61f7 | 2015-10-20 21:30:45 +0200 | [diff] [blame] | 1679 | .manufacturer = 29, |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 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, |
| 1689 | }; |
| 1690 | |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1691 | static const struct qca_vreg_data qca_soc_data_wcn3990 = { |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1692 | .soc_type = QCA_WCN3990, |
| 1693 | .vregs = (struct qca_vreg []) { |
Bjorn Andersson | f2edd66 | 2019-10-17 22:24:02 -0700 | [diff] [blame] | 1694 | { "vddio", 15000 }, |
| 1695 | { "vddxo", 80000 }, |
| 1696 | { "vddrf", 300000 }, |
| 1697 | { "vddch0", 450000 }, |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1698 | }, |
| 1699 | .num_vregs = 4, |
| 1700 | }; |
| 1701 | |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 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 }, |
| 1709 | }, |
| 1710 | .num_vregs = 4, |
| 1711 | }; |
| 1712 | |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1713 | static const struct qca_vreg_data qca_soc_data_wcn3998 = { |
| 1714 | .soc_type = QCA_WCN3998, |
| 1715 | .vregs = (struct qca_vreg []) { |
Bjorn Andersson | f2edd66 | 2019-10-17 22:24:02 -0700 | [diff] [blame] | 1716 | { "vddio", 10000 }, |
| 1717 | { "vddxo", 80000 }, |
| 1718 | { "vddrf", 300000 }, |
| 1719 | { "vddch0", 450000 }, |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1720 | }, |
| 1721 | .num_vregs = 4, |
| 1722 | }; |
| 1723 | |
Balakrishna Godavarthi | c2d7827 | 2018-08-22 17:50:05 +0530 | [diff] [blame] | 1724 | static void qca_power_shutdown(struct hci_uart *hu) |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1725 | { |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1726 | struct qca_serdev *qcadev; |
Balakrishna Godavarthi | 035a960 | 2019-02-04 20:36:43 +0530 | [diff] [blame] | 1727 | struct qca_data *qca = hu->priv; |
| 1728 | unsigned long flags; |
Rocky Liao | 5559904 | 2020-01-15 16:55:50 +0800 | [diff] [blame] | 1729 | enum qca_btsoc_type soc_type = qca_soc_type(hu); |
Balakrishna Godavarthi | 035a960 | 2019-02-04 20:36:43 +0530 | [diff] [blame] | 1730 | |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1731 | qcadev = serdev_device_get_drvdata(hu->serdev); |
| 1732 | |
Balakrishna Godavarthi | 035a960 | 2019-02-04 20:36:43 +0530 | [diff] [blame] | 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. |
| 1736 | */ |
| 1737 | spin_lock_irqsave(&qca->hci_ibs_lock, flags); |
Matthias Kaehlcke | 62a9199 | 2019-04-29 16:21:30 -0700 | [diff] [blame] | 1738 | clear_bit(QCA_IBS_ENABLED, &qca->flags); |
Balakrishna Godavarthi | 035a960 | 2019-02-04 20:36:43 +0530 | [diff] [blame] | 1739 | qca_flush(hu); |
| 1740 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 1741 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1742 | hu->hdev->hw_error = NULL; |
| 1743 | hu->hdev->cmd_timeout = NULL; |
Rocky Liao | 5559904 | 2020-01-15 16:55:50 +0800 | [diff] [blame] | 1744 | |
| 1745 | /* Non-serdev device usually is powered by external power |
| 1746 | * and don't need additional action in driver for power down |
| 1747 | */ |
| 1748 | if (!hu->serdev) |
| 1749 | return; |
| 1750 | |
| 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); |
Rocky Liao | 8a208b2 | 2020-03-04 09:54:29 +0800 | [diff] [blame^] | 1755 | } else if (!IS_ERR(qcadev->bt_en)) { |
Rocky Liao | 5559904 | 2020-01-15 16:55:50 +0800 | [diff] [blame] | 1756 | gpiod_set_value_cansleep(qcadev->bt_en, 0); |
| 1757 | } |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1758 | } |
| 1759 | |
Balakrishna Godavarthi | 3e4be65 | 2018-09-24 20:14:45 +0530 | [diff] [blame] | 1760 | static int qca_power_off(struct hci_dev *hdev) |
| 1761 | { |
| 1762 | struct hci_uart *hu = hci_get_drvdata(hdev); |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1763 | struct qca_data *qca = hu->priv; |
Rocky Liao | 4f9ed5b | 2020-02-29 20:21:18 +0800 | [diff] [blame] | 1764 | enum qca_btsoc_type soc_type = qca_soc_type(hu); |
Balakrishna Godavarthi | 3e4be65 | 2018-09-24 20:14:45 +0530 | [diff] [blame] | 1765 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1766 | /* Stop sending shutdown command if soc crashes. */ |
Rocky Liao | 4f9ed5b | 2020-02-29 20:21:18 +0800 | [diff] [blame] | 1767 | if (qca_is_wcn399x(soc_type) |
| 1768 | && qca->memdump_state == QCA_MEMDUMP_IDLE) { |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1769 | qca_send_pre_shutdown_cmd(hdev); |
| 1770 | usleep_range(8000, 10000); |
| 1771 | } |
Harish Bandi | a278088 | 2019-07-12 10:39:40 +0530 | [diff] [blame] | 1772 | |
Balakrishna Godavarthi | d841502 | 2020-01-02 20:19:11 +0530 | [diff] [blame] | 1773 | qca->memdump_state = QCA_MEMDUMP_IDLE; |
Balakrishna Godavarthi | 3e4be65 | 2018-09-24 20:14:45 +0530 | [diff] [blame] | 1774 | qca_power_shutdown(hu); |
| 1775 | return 0; |
| 1776 | } |
| 1777 | |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1778 | static int qca_regulator_enable(struct qca_serdev *qcadev) |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1779 | { |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1780 | struct qca_power *power = qcadev->bt_power; |
| 1781 | int ret; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1782 | |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1783 | /* Already enabled */ |
| 1784 | if (power->vregs_on) |
| 1785 | return 0; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1786 | |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1787 | BT_DBG("enabling %d regulators)", power->num_vregs); |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1788 | |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1789 | ret = regulator_bulk_enable(power->num_vregs, power->vreg_bulk); |
| 1790 | if (ret) |
| 1791 | return ret; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1792 | |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1793 | power->vregs_on = true; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1794 | |
Venkata Lakshmi Narayana Gubba | 66cb705 | 2020-02-03 16:10:40 +0530 | [diff] [blame] | 1795 | ret = clk_prepare_enable(qcadev->susclk); |
Venkata Lakshmi Narayana Gubba | f3d63f5 | 2020-02-05 16:21:43 +0530 | [diff] [blame] | 1796 | if (ret) |
Venkata Lakshmi Narayana Gubba | 66cb705 | 2020-02-03 16:10:40 +0530 | [diff] [blame] | 1797 | qca_regulator_disable(qcadev); |
Venkata Lakshmi Narayana Gubba | 66cb705 | 2020-02-03 16:10:40 +0530 | [diff] [blame] | 1798 | |
Venkata Lakshmi Narayana Gubba | f3d63f5 | 2020-02-05 16:21:43 +0530 | [diff] [blame] | 1799 | return ret; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1800 | } |
| 1801 | |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1802 | static void qca_regulator_disable(struct qca_serdev *qcadev) |
| 1803 | { |
| 1804 | struct qca_power *power; |
| 1805 | |
| 1806 | if (!qcadev) |
| 1807 | return; |
| 1808 | |
| 1809 | power = qcadev->bt_power; |
| 1810 | |
| 1811 | /* Already disabled? */ |
| 1812 | if (!power->vregs_on) |
| 1813 | return; |
| 1814 | |
| 1815 | regulator_bulk_disable(power->num_vregs, power->vreg_bulk); |
| 1816 | power->vregs_on = false; |
Venkata Lakshmi Narayana Gubba | 66cb705 | 2020-02-03 16:10:40 +0530 | [diff] [blame] | 1817 | |
Venkata Lakshmi Narayana Gubba | f3d63f5 | 2020-02-05 16:21:43 +0530 | [diff] [blame] | 1818 | clk_disable_unprepare(qcadev->susclk); |
Bjorn Andersson | a9314e7 | 2019-10-17 22:24:04 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1821 | static int qca_init_regulators(struct qca_power *qca, |
| 1822 | const struct qca_vreg *vregs, size_t num_vregs) |
| 1823 | { |
Bjorn Andersson | c29ff10 | 2019-10-17 22:24:01 -0700 | [diff] [blame] | 1824 | struct regulator_bulk_data *bulk; |
| 1825 | int ret; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1826 | int i; |
| 1827 | |
Bjorn Andersson | c29ff10 | 2019-10-17 22:24:01 -0700 | [diff] [blame] | 1828 | bulk = devm_kcalloc(qca->dev, num_vregs, sizeof(*bulk), GFP_KERNEL); |
| 1829 | if (!bulk) |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1830 | return -ENOMEM; |
| 1831 | |
| 1832 | for (i = 0; i < num_vregs; i++) |
Bjorn Andersson | c29ff10 | 2019-10-17 22:24:01 -0700 | [diff] [blame] | 1833 | bulk[i].supply = vregs[i].name; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1834 | |
Bjorn Andersson | c29ff10 | 2019-10-17 22:24:01 -0700 | [diff] [blame] | 1835 | ret = devm_regulator_bulk_get(qca->dev, num_vregs, bulk); |
| 1836 | if (ret < 0) |
| 1837 | return ret; |
| 1838 | |
| 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; |
| 1843 | } |
| 1844 | |
| 1845 | qca->vreg_bulk = bulk; |
Bjorn Andersson | 163d42f | 2019-10-17 22:24:03 -0700 | [diff] [blame] | 1846 | qca->num_vregs = num_vregs; |
Bjorn Andersson | c29ff10 | 2019-10-17 22:24:01 -0700 | [diff] [blame] | 1847 | |
| 1848 | return 0; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1849 | } |
| 1850 | |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1851 | static int qca_serdev_probe(struct serdev_device *serdev) |
| 1852 | { |
| 1853 | struct qca_serdev *qcadev; |
Rocky Liao | ae56318 | 2020-01-16 11:22:54 +0800 | [diff] [blame] | 1854 | struct hci_dev *hdev; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1855 | const struct qca_vreg_data *data; |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1856 | int err; |
Rocky Liao | 8a208b2 | 2020-03-04 09:54:29 +0800 | [diff] [blame^] | 1857 | bool power_ctrl_enabled = true; |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1858 | |
| 1859 | qcadev = devm_kzalloc(&serdev->dev, sizeof(*qcadev), GFP_KERNEL); |
| 1860 | if (!qcadev) |
| 1861 | return -ENOMEM; |
| 1862 | |
| 1863 | qcadev->serdev_hu.serdev = serdev; |
Rocky Liao | 9f3565b | 2019-12-13 16:50:45 +0800 | [diff] [blame] | 1864 | data = device_get_match_data(&serdev->dev); |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1865 | serdev_device_set_drvdata(serdev, qcadev); |
Rocky Liao | 99c905c | 2019-06-06 17:40:30 +0800 | [diff] [blame] | 1866 | device_property_read_string(&serdev->dev, "firmware-name", |
| 1867 | &qcadev->firmware_name); |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1868 | if (data && qca_is_wcn399x(data->soc_type)) { |
| 1869 | qcadev->btsoc_type = data->soc_type; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1870 | qcadev->bt_power = devm_kzalloc(&serdev->dev, |
| 1871 | sizeof(struct qca_power), |
| 1872 | GFP_KERNEL); |
| 1873 | if (!qcadev->bt_power) |
| 1874 | return -ENOMEM; |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1875 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1876 | qcadev->bt_power->dev = &serdev->dev; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 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); |
Rocky Liao | ae56318 | 2020-01-16 11:22:54 +0800 | [diff] [blame] | 1881 | return err; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | qcadev->bt_power->vregs_on = false; |
| 1885 | |
Venkata Lakshmi Narayana Gubba | 66cb705 | 2020-02-03 16:10:40 +0530 | [diff] [blame] | 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); |
| 1890 | } |
| 1891 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 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"); |
| 1896 | |
| 1897 | err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto); |
| 1898 | if (err) { |
| 1899 | BT_ERR("wcn3990 serdev registration failed"); |
Rocky Liao | ae56318 | 2020-01-16 11:22:54 +0800 | [diff] [blame] | 1900 | return err; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1901 | } |
| 1902 | } else { |
| 1903 | qcadev->btsoc_type = QCA_ROME; |
| 1904 | qcadev->bt_en = devm_gpiod_get(&serdev->dev, "enable", |
| 1905 | GPIOD_OUT_LOW); |
| 1906 | if (IS_ERR(qcadev->bt_en)) { |
Rocky Liao | 8a208b2 | 2020-03-04 09:54:29 +0800 | [diff] [blame^] | 1907 | dev_warn(&serdev->dev, "failed to acquire enable gpio\n"); |
| 1908 | power_ctrl_enabled = false; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | qcadev->susclk = devm_clk_get(&serdev->dev, NULL); |
| 1912 | if (IS_ERR(qcadev->susclk)) { |
Rocky Liao | 8a208b2 | 2020-03-04 09:54:29 +0800 | [diff] [blame^] | 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; |
| 1918 | |
| 1919 | err = clk_prepare_enable(qcadev->susclk); |
| 1920 | if (err) |
| 1921 | return err; |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1922 | } |
| 1923 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1924 | err = hci_uart_register_device(&qcadev->serdev_hu, &qca_proto); |
Rocky Liao | ae56318 | 2020-01-16 11:22:54 +0800 | [diff] [blame] | 1925 | if (err) { |
| 1926 | BT_ERR("Rome serdev registration failed"); |
Rocky Liao | 8a208b2 | 2020-03-04 09:54:29 +0800 | [diff] [blame^] | 1927 | if (!IS_ERR(qcadev->susclk)) |
| 1928 | clk_disable_unprepare(qcadev->susclk); |
Rocky Liao | ae56318 | 2020-01-16 11:22:54 +0800 | [diff] [blame] | 1929 | return err; |
| 1930 | } |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1931 | } |
| 1932 | |
Rocky Liao | 8a208b2 | 2020-03-04 09:54:29 +0800 | [diff] [blame^] | 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; |
| 1937 | } |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1938 | |
Rocky Liao | ae56318 | 2020-01-16 11:22:54 +0800 | [diff] [blame] | 1939 | return 0; |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | static void qca_serdev_remove(struct serdev_device *serdev) |
| 1943 | { |
| 1944 | struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev); |
| 1945 | |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 1946 | if (qca_is_wcn399x(qcadev->btsoc_type)) |
Balakrishna Godavarthi | c2d7827 | 2018-08-22 17:50:05 +0530 | [diff] [blame] | 1947 | qca_power_shutdown(&qcadev->serdev_hu); |
Rocky Liao | 8a208b2 | 2020-03-04 09:54:29 +0800 | [diff] [blame^] | 1948 | else if (!IS_ERR(qcadev->susclk)) |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1949 | clk_disable_unprepare(qcadev->susclk); |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1950 | |
Balakrishna Godavarthi | fa9ad87 | 2018-08-03 17:46:32 +0530 | [diff] [blame] | 1951 | hci_uart_unregister_device(&qcadev->serdev_hu); |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 1952 | } |
| 1953 | |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 1954 | static int __maybe_unused qca_suspend(struct device *dev) |
| 1955 | { |
| 1956 | struct hci_dev *hdev = container_of(dev, struct hci_dev, dev); |
| 1957 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 1958 | struct qca_data *qca = hu->priv; |
| 1959 | unsigned long flags; |
| 1960 | int ret = 0; |
| 1961 | u8 cmd; |
| 1962 | |
| 1963 | set_bit(QCA_SUSPENDING, &qca->flags); |
| 1964 | |
| 1965 | /* Device is downloading patch or doesn't support in-band sleep. */ |
| 1966 | if (!test_bit(QCA_IBS_ENABLED, &qca->flags)) |
| 1967 | return 0; |
| 1968 | |
| 1969 | cancel_work_sync(&qca->ws_awake_device); |
| 1970 | cancel_work_sync(&qca->ws_awake_rx); |
| 1971 | |
| 1972 | spin_lock_irqsave_nested(&qca->hci_ibs_lock, |
| 1973 | flags, SINGLE_DEPTH_NESTING); |
| 1974 | |
| 1975 | switch (qca->tx_ibs_state) { |
| 1976 | case HCI_IBS_TX_WAKING: |
| 1977 | del_timer(&qca->wake_retrans_timer); |
| 1978 | /* Fall through */ |
| 1979 | case HCI_IBS_TX_AWAKE: |
| 1980 | del_timer(&qca->tx_idle_timer); |
| 1981 | |
| 1982 | serdev_device_write_flush(hu->serdev); |
| 1983 | cmd = HCI_IBS_SLEEP_IND; |
| 1984 | ret = serdev_device_write_buf(hu->serdev, &cmd, sizeof(cmd)); |
| 1985 | |
| 1986 | if (ret < 0) { |
| 1987 | BT_ERR("Failed to send SLEEP to device"); |
| 1988 | break; |
| 1989 | } |
| 1990 | |
| 1991 | qca->tx_ibs_state = HCI_IBS_TX_ASLEEP; |
| 1992 | qca->ibs_sent_slps++; |
| 1993 | |
| 1994 | qca_wq_serial_tx_clock_vote_off(&qca->ws_tx_vote_off); |
| 1995 | break; |
| 1996 | |
| 1997 | case HCI_IBS_TX_ASLEEP: |
| 1998 | break; |
| 1999 | |
| 2000 | default: |
| 2001 | BT_ERR("Spurious tx state %d", qca->tx_ibs_state); |
| 2002 | ret = -EINVAL; |
| 2003 | break; |
| 2004 | } |
| 2005 | |
| 2006 | spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); |
| 2007 | |
| 2008 | if (ret < 0) |
| 2009 | goto error; |
| 2010 | |
| 2011 | serdev_device_wait_until_sent(hu->serdev, |
| 2012 | msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS)); |
| 2013 | |
| 2014 | /* Wait for HCI_IBS_SLEEP_IND sent by device to indicate its Tx is going |
| 2015 | * to sleep, so that the packet does not wake the system later. |
| 2016 | */ |
| 2017 | |
| 2018 | ret = wait_event_interruptible_timeout(qca->suspend_wait_q, |
| 2019 | qca->rx_ibs_state == HCI_IBS_RX_ASLEEP, |
| 2020 | msecs_to_jiffies(IBS_BTSOC_TX_IDLE_TIMEOUT_MS)); |
| 2021 | |
| 2022 | if (ret > 0) |
| 2023 | return 0; |
| 2024 | |
| 2025 | if (ret == 0) |
| 2026 | ret = -ETIMEDOUT; |
| 2027 | |
| 2028 | error: |
| 2029 | clear_bit(QCA_SUSPENDING, &qca->flags); |
| 2030 | |
| 2031 | return ret; |
| 2032 | } |
| 2033 | |
| 2034 | static int __maybe_unused qca_resume(struct device *dev) |
| 2035 | { |
| 2036 | struct hci_dev *hdev = container_of(dev, struct hci_dev, dev); |
| 2037 | struct hci_uart *hu = hci_get_drvdata(hdev); |
| 2038 | struct qca_data *qca = hu->priv; |
| 2039 | |
| 2040 | clear_bit(QCA_SUSPENDING, &qca->flags); |
| 2041 | |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
| 2045 | static SIMPLE_DEV_PM_OPS(qca_pm_ops, qca_suspend, qca_resume); |
| 2046 | |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 2047 | static const struct of_device_id qca_bluetooth_of_match[] = { |
| 2048 | { .compatible = "qcom,qca6174-bt" }, |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 2049 | { .compatible = "qcom,wcn3990-bt", .data = &qca_soc_data_wcn3990}, |
Balakrishna Godavarthi | 7d250a0 | 2019-11-06 15:18:32 +0530 | [diff] [blame] | 2050 | { .compatible = "qcom,wcn3991-bt", .data = &qca_soc_data_wcn3991}, |
Harish Bandi | 523760b | 2019-04-26 19:26:01 +0530 | [diff] [blame] | 2051 | { .compatible = "qcom,wcn3998-bt", .data = &qca_soc_data_wcn3998}, |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 2052 | { /* sentinel */ } |
| 2053 | }; |
| 2054 | MODULE_DEVICE_TABLE(of, qca_bluetooth_of_match); |
| 2055 | |
| 2056 | static struct serdev_device_driver qca_serdev_driver = { |
| 2057 | .probe = qca_serdev_probe, |
| 2058 | .remove = qca_serdev_remove, |
| 2059 | .driver = { |
| 2060 | .name = "hci_uart_qca", |
| 2061 | .of_match_table = qca_bluetooth_of_match, |
Claire Chang | 41d5b25 | 2019-10-31 18:46:14 +0800 | [diff] [blame] | 2062 | .pm = &qca_pm_ops, |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 2063 | }, |
| 2064 | }; |
| 2065 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 2066 | int __init qca_init(void) |
| 2067 | { |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 2068 | serdev_device_driver_register(&qca_serdev_driver); |
| 2069 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 2070 | return hci_uart_register_proto(&qca_proto); |
| 2071 | } |
| 2072 | |
| 2073 | int __exit qca_deinit(void) |
| 2074 | { |
Thierry Escande | 05ba533 | 2018-03-29 21:15:24 +0200 | [diff] [blame] | 2075 | serdev_device_driver_unregister(&qca_serdev_driver); |
| 2076 | |
Ben Young Tae Kim | 0ff252c | 2015-08-10 14:24:17 -0700 | [diff] [blame] | 2077 | return hci_uart_unregister_proto(&qca_proto); |
| 2078 | } |