Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Bluetooth supports for Qualcomm Atheros chips |
| 3 | * |
| 4 | * Copyright (c) 2015 The Linux Foundation. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 |
| 8 | * as published by the Free Software Foundation |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | * |
| 19 | */ |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/firmware.h> |
| 22 | |
| 23 | #include <net/bluetooth/bluetooth.h> |
| 24 | #include <net/bluetooth/hci_core.h> |
| 25 | |
| 26 | #include "btqca.h" |
| 27 | |
| 28 | #define VERSION "0.1" |
| 29 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 30 | int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 31 | { |
| 32 | struct sk_buff *skb; |
| 33 | struct edl_event_hdr *edl; |
| 34 | struct rome_version *ver; |
| 35 | char cmd; |
| 36 | int err = 0; |
| 37 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 38 | bt_dev_dbg(hdev, "QCA Version Request"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 39 | |
| 40 | cmd = EDL_PATCH_VER_REQ_CMD; |
| 41 | skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, EDL_PATCH_CMD_LEN, |
| 42 | &cmd, HCI_VENDOR_PKT, HCI_INIT_TIMEOUT); |
| 43 | if (IS_ERR(skb)) { |
| 44 | err = PTR_ERR(skb); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 45 | bt_dev_err(hdev, "Reading QCA version information failed (%d)", |
| 46 | err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 47 | return err; |
| 48 | } |
| 49 | |
| 50 | if (skb->len != sizeof(*edl) + sizeof(*ver)) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 51 | bt_dev_err(hdev, "QCA Version size mismatch len %d", skb->len); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 52 | err = -EILSEQ; |
| 53 | goto out; |
| 54 | } |
| 55 | |
| 56 | edl = (struct edl_event_hdr *)(skb->data); |
Colin Ian King | 0676cab | 2016-09-06 13:15:49 +0100 | [diff] [blame] | 57 | if (!edl) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 58 | bt_dev_err(hdev, "QCA TLV with no header"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 59 | err = -EILSEQ; |
| 60 | goto out; |
| 61 | } |
| 62 | |
| 63 | if (edl->cresp != EDL_CMD_REQ_RES_EVT || |
| 64 | edl->rtype != EDL_APP_VER_RES_EVT) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 65 | bt_dev_err(hdev, "QCA Wrong packet received %d %d", edl->cresp, |
| 66 | edl->rtype); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 67 | err = -EIO; |
| 68 | goto out; |
| 69 | } |
| 70 | |
| 71 | ver = (struct rome_version *)(edl->data); |
| 72 | |
| 73 | BT_DBG("%s: Product:0x%08x", hdev->name, le32_to_cpu(ver->product_id)); |
| 74 | BT_DBG("%s: Patch :0x%08x", hdev->name, le16_to_cpu(ver->patch_ver)); |
| 75 | BT_DBG("%s: ROM :0x%08x", hdev->name, le16_to_cpu(ver->rome_ver)); |
| 76 | BT_DBG("%s: SOC :0x%08x", hdev->name, le32_to_cpu(ver->soc_id)); |
| 77 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 78 | /* QCA chipset version can be decided by patch and SoC |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 79 | * version, combination with upper 2 bytes from SoC |
| 80 | * and lower 2 bytes from patch will be used. |
| 81 | */ |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 82 | *soc_version = (le32_to_cpu(ver->soc_id) << 16) | |
Joan Jani | 2193a98 | 2017-07-06 20:35:32 +0000 | [diff] [blame] | 83 | (le16_to_cpu(ver->rome_ver) & 0x0000ffff); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 84 | |
| 85 | out: |
| 86 | kfree_skb(skb); |
| 87 | |
| 88 | return err; |
| 89 | } |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 90 | EXPORT_SYMBOL_GPL(qca_read_soc_version); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 91 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 92 | static int qca_send_reset(struct hci_dev *hdev) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 93 | { |
| 94 | struct sk_buff *skb; |
| 95 | int err; |
| 96 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 97 | bt_dev_dbg(hdev, "QCA HCI_RESET"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 98 | |
| 99 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 100 | if (IS_ERR(skb)) { |
| 101 | err = PTR_ERR(skb); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 102 | bt_dev_err(hdev, "QCA Reset failed (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 103 | return err; |
| 104 | } |
| 105 | |
| 106 | kfree_skb(skb); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 111 | static void qca_tlv_check_data(struct rome_config *config, |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 112 | const struct firmware *fw) |
| 113 | { |
| 114 | const u8 *data; |
| 115 | u32 type_len; |
| 116 | u16 tag_id, tag_len; |
| 117 | int idx, length; |
| 118 | struct tlv_type_hdr *tlv; |
| 119 | struct tlv_type_patch *tlv_patch; |
| 120 | struct tlv_type_nvm *tlv_nvm; |
| 121 | |
| 122 | tlv = (struct tlv_type_hdr *)fw->data; |
| 123 | |
| 124 | type_len = le32_to_cpu(tlv->type_len); |
| 125 | length = (type_len >> 8) & 0x00ffffff; |
| 126 | |
| 127 | BT_DBG("TLV Type\t\t : 0x%x", type_len & 0x000000ff); |
| 128 | BT_DBG("Length\t\t : %d bytes", length); |
| 129 | |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 130 | config->dnld_mode = ROME_SKIP_EVT_NONE; |
| 131 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 132 | switch (config->type) { |
| 133 | case TLV_TYPE_PATCH: |
| 134 | tlv_patch = (struct tlv_type_patch *)tlv->data; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 135 | |
| 136 | /* For Rome version 1.1 to 3.1, all segment commands |
| 137 | * are acked by a vendor specific event (VSE). |
| 138 | * For Rome >= 3.2, the download mode field indicates |
| 139 | * if VSE is skipped by the controller. |
| 140 | * In case VSE is skipped, only the last segment is acked. |
| 141 | */ |
| 142 | config->dnld_mode = tlv_patch->download_mode; |
| 143 | |
| 144 | BT_DBG("Total Length : %d bytes", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 145 | le32_to_cpu(tlv_patch->total_size)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 146 | BT_DBG("Patch Data Length : %d bytes", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 147 | le32_to_cpu(tlv_patch->data_length)); |
| 148 | BT_DBG("Signing Format Version : 0x%x", |
| 149 | tlv_patch->format_version); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 150 | BT_DBG("Signature Algorithm : 0x%x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 151 | tlv_patch->signature); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 152 | BT_DBG("Download mode : 0x%x", |
| 153 | tlv_patch->download_mode); |
| 154 | BT_DBG("Reserved : 0x%x", |
| 155 | tlv_patch->reserved1); |
| 156 | BT_DBG("Product ID : 0x%04x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 157 | le16_to_cpu(tlv_patch->product_id)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 158 | BT_DBG("Rom Build Version : 0x%04x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 159 | le16_to_cpu(tlv_patch->rom_build)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 160 | BT_DBG("Patch Version : 0x%04x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 161 | le16_to_cpu(tlv_patch->patch_version)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 162 | BT_DBG("Reserved : 0x%x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 163 | le16_to_cpu(tlv_patch->reserved2)); |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 164 | BT_DBG("Patch Entry Address : 0x%x", |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 165 | le32_to_cpu(tlv_patch->entry)); |
| 166 | break; |
| 167 | |
| 168 | case TLV_TYPE_NVM: |
| 169 | idx = 0; |
| 170 | data = tlv->data; |
| 171 | while (idx < length) { |
| 172 | tlv_nvm = (struct tlv_type_nvm *)(data + idx); |
| 173 | |
| 174 | tag_id = le16_to_cpu(tlv_nvm->tag_id); |
| 175 | tag_len = le16_to_cpu(tlv_nvm->tag_len); |
| 176 | |
| 177 | /* Update NVM tags as needed */ |
| 178 | switch (tag_id) { |
| 179 | case EDL_TAG_ID_HCI: |
| 180 | /* HCI transport layer parameters |
| 181 | * enabling software inband sleep |
| 182 | * onto controller side. |
| 183 | */ |
| 184 | tlv_nvm->data[0] |= 0x80; |
| 185 | |
| 186 | /* UART Baud Rate */ |
| 187 | tlv_nvm->data[2] = config->user_baud_rate; |
| 188 | |
| 189 | break; |
| 190 | |
| 191 | case EDL_TAG_ID_DEEP_SLEEP: |
| 192 | /* Sleep enable mask |
| 193 | * enabling deep sleep feature on controller. |
| 194 | */ |
| 195 | tlv_nvm->data[0] |= 0x01; |
| 196 | |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | idx += (sizeof(u16) + sizeof(u16) + 8 + tag_len); |
| 201 | } |
| 202 | break; |
| 203 | |
| 204 | default: |
| 205 | BT_ERR("Unknown TLV type %d", config->type); |
| 206 | break; |
| 207 | } |
| 208 | } |
| 209 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 210 | static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size, |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 211 | const u8 *data, enum rome_tlv_dnld_mode mode) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 212 | { |
| 213 | struct sk_buff *skb; |
| 214 | struct edl_event_hdr *edl; |
| 215 | struct tlv_seg_resp *tlv_resp; |
| 216 | u8 cmd[MAX_SIZE_PER_TLV_SEGMENT + 2]; |
| 217 | int err = 0; |
| 218 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 219 | cmd[0] = EDL_PATCH_TLV_REQ_CMD; |
| 220 | cmd[1] = seg_size; |
| 221 | memcpy(cmd + 2, data, seg_size); |
| 222 | |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 223 | if (mode == ROME_SKIP_EVT_VSE_CC || mode == ROME_SKIP_EVT_VSE) |
| 224 | return __hci_cmd_send(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, |
| 225 | cmd); |
| 226 | |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 227 | skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, cmd, |
| 228 | HCI_VENDOR_PKT, HCI_INIT_TIMEOUT); |
| 229 | if (IS_ERR(skb)) { |
| 230 | err = PTR_ERR(skb); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 231 | bt_dev_err(hdev, "QCA Failed to send TLV segment (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 232 | return err; |
| 233 | } |
| 234 | |
| 235 | if (skb->len != sizeof(*edl) + sizeof(*tlv_resp)) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 236 | bt_dev_err(hdev, "QCA TLV response size mismatch"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 237 | err = -EILSEQ; |
| 238 | goto out; |
| 239 | } |
| 240 | |
| 241 | edl = (struct edl_event_hdr *)(skb->data); |
Colin Ian King | 0676cab | 2016-09-06 13:15:49 +0100 | [diff] [blame] | 242 | if (!edl) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 243 | bt_dev_err(hdev, "TLV with no header"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 244 | err = -EILSEQ; |
| 245 | goto out; |
| 246 | } |
| 247 | |
| 248 | tlv_resp = (struct tlv_seg_resp *)(edl->data); |
| 249 | |
| 250 | if (edl->cresp != EDL_CMD_REQ_RES_EVT || |
| 251 | edl->rtype != EDL_TVL_DNLD_RES_EVT || tlv_resp->result != 0x00) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 252 | bt_dev_err(hdev, "QCA TLV with error stat 0x%x rtype 0x%x (0x%x)", |
| 253 | edl->cresp, edl->rtype, tlv_resp->result); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 254 | err = -EIO; |
| 255 | } |
| 256 | |
| 257 | out: |
| 258 | kfree_skb(skb); |
| 259 | |
| 260 | return err; |
| 261 | } |
| 262 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 263 | static int qca_download_firmware(struct hci_dev *hdev, |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 264 | struct rome_config *config) |
| 265 | { |
| 266 | const struct firmware *fw; |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 267 | const u8 *segment; |
| 268 | int ret, remain, i = 0; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 269 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 270 | bt_dev_info(hdev, "QCA Downloading %s", config->fwname); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 271 | |
| 272 | ret = request_firmware(&fw, config->fwname, &hdev->dev); |
| 273 | if (ret) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 274 | bt_dev_err(hdev, "QCA Failed to request file: %s (%d)", |
| 275 | config->fwname, ret); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 276 | return ret; |
| 277 | } |
| 278 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 279 | qca_tlv_check_data(config, fw); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 280 | |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 281 | segment = fw->data; |
| 282 | remain = fw->size; |
| 283 | while (remain > 0) { |
| 284 | int segsize = min(MAX_SIZE_PER_TLV_SEGMENT, remain); |
| 285 | |
| 286 | bt_dev_dbg(hdev, "Send segment %d, size %d", i++, segsize); |
| 287 | |
| 288 | remain -= segsize; |
| 289 | /* The last segment is always acked regardless download mode */ |
| 290 | if (!remain || segsize < MAX_SIZE_PER_TLV_SEGMENT) |
| 291 | config->dnld_mode = ROME_SKIP_EVT_NONE; |
| 292 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 293 | ret = qca_tlv_send_segment(hdev, segsize, segment, |
Loic Poulain | 6e03126 | 2018-04-26 13:13:27 +0200 | [diff] [blame] | 294 | config->dnld_mode); |
| 295 | if (ret) |
| 296 | break; |
| 297 | |
| 298 | segment += segsize; |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | release_firmware(fw); |
| 302 | |
| 303 | return ret; |
| 304 | } |
| 305 | |
| 306 | int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
| 307 | { |
| 308 | struct sk_buff *skb; |
| 309 | u8 cmd[9]; |
| 310 | int err; |
| 311 | |
| 312 | cmd[0] = EDL_NVM_ACCESS_SET_REQ_CMD; |
| 313 | cmd[1] = 0x02; /* TAG ID */ |
| 314 | cmd[2] = sizeof(bdaddr_t); /* size */ |
| 315 | memcpy(cmd + 3, bdaddr, sizeof(bdaddr_t)); |
| 316 | skb = __hci_cmd_sync_ev(hdev, EDL_NVM_ACCESS_OPCODE, sizeof(cmd), cmd, |
| 317 | HCI_VENDOR_PKT, HCI_INIT_TIMEOUT); |
| 318 | if (IS_ERR(skb)) { |
| 319 | err = PTR_ERR(skb); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 320 | bt_dev_err(hdev, "QCA Change address command failed (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 321 | return err; |
| 322 | } |
| 323 | |
| 324 | kfree_skb(skb); |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome); |
| 329 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 330 | int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate) |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 331 | { |
| 332 | u32 rome_ver = 0; |
| 333 | struct rome_config config; |
| 334 | int err; |
| 335 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 336 | bt_dev_dbg(hdev, "QCA setup on UART"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 337 | |
| 338 | config.user_baud_rate = baudrate; |
| 339 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 340 | /* Get QCA version information */ |
| 341 | err = qca_read_soc_version(hdev, &rome_ver); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 342 | if (err < 0 || rome_ver == 0) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 343 | bt_dev_err(hdev, "QCA Failed to get version %d", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 344 | return err; |
| 345 | } |
| 346 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 347 | bt_dev_info(hdev, "QCA controller version 0x%08x", rome_ver); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 348 | |
| 349 | /* Download rampatch file */ |
| 350 | config.type = TLV_TYPE_PATCH; |
| 351 | snprintf(config.fwname, sizeof(config.fwname), "qca/rampatch_%08x.bin", |
| 352 | rome_ver); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 353 | err = qca_download_firmware(hdev, &config); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 354 | if (err < 0) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 355 | bt_dev_err(hdev, "QCA Failed to download patch (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 356 | return err; |
| 357 | } |
| 358 | |
| 359 | /* Download NVM configuration */ |
| 360 | config.type = TLV_TYPE_NVM; |
| 361 | snprintf(config.fwname, sizeof(config.fwname), "qca/nvm_%08x.bin", |
| 362 | rome_ver); |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 363 | err = qca_download_firmware(hdev, &config); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 364 | if (err < 0) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 365 | bt_dev_err(hdev, "QCA Failed to download NVM (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 366 | return err; |
| 367 | } |
| 368 | |
| 369 | /* Perform HCI reset */ |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 370 | err = qca_send_reset(hdev); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 371 | if (err < 0) { |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 372 | bt_dev_err(hdev, "QCA Failed to run HCI_RESET (%d)", err); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 373 | return err; |
| 374 | } |
| 375 | |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 376 | bt_dev_info(hdev, "QCA setup on UART is completed"); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 377 | |
| 378 | return 0; |
| 379 | } |
Balakrishna Godavarthi | ba493d4 | 2018-08-03 17:46:27 +0530 | [diff] [blame^] | 380 | EXPORT_SYMBOL_GPL(qca_uart_setup); |
Ben Young Tae Kim | 83e8196 | 2015-08-10 14:24:12 -0700 | [diff] [blame] | 381 | |
| 382 | MODULE_AUTHOR("Ben Young Tae Kim <ytkim@qca.qualcomm.com>"); |
| 383 | MODULE_DESCRIPTION("Bluetooth support for Qualcomm Atheros family ver " VERSION); |
| 384 | MODULE_VERSION(VERSION); |
| 385 | MODULE_LICENSE("GPL"); |