xref: /linux/drivers/bluetooth/btqca.c (revision b6459415b384cb829f0b2a4268f211c789f6cf0b)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *  Bluetooth supports for Qualcomm Atheros chips
4  *
5  *  Copyright (c) 2015 The Linux Foundation. All rights reserved.
6  */
7 #include <linux/module.h>
8 #include <linux/firmware.h>
9 #include <linux/vmalloc.h>
10 
11 #include <net/bluetooth/bluetooth.h>
12 #include <net/bluetooth/hci_core.h>
13 
14 #include "btqca.h"
15 
16 #define VERSION "0.1"
17 
18 int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver,
19 			 enum qca_btsoc_type soc_type)
20 {
21 	struct sk_buff *skb;
22 	struct edl_event_hdr *edl;
23 	char cmd;
24 	int err = 0;
25 	u8 event_type = HCI_EV_VENDOR;
26 	u8 rlen = sizeof(*edl) + sizeof(*ver);
27 	u8 rtype = EDL_APP_VER_RES_EVT;
28 
29 	bt_dev_dbg(hdev, "QCA Version Request");
30 
31 	/* Unlike other SoC's sending version command response as payload to
32 	 * VSE event. WCN3991 sends version command response as a payload to
33 	 * command complete event.
34 	 */
35 	if (soc_type >= QCA_WCN3991) {
36 		event_type = 0;
37 		rlen += 1;
38 		rtype = EDL_PATCH_VER_REQ_CMD;
39 	}
40 
41 	cmd = EDL_PATCH_VER_REQ_CMD;
42 	skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, EDL_PATCH_CMD_LEN,
43 				&cmd, event_type, HCI_INIT_TIMEOUT);
44 	if (IS_ERR(skb)) {
45 		err = PTR_ERR(skb);
46 		bt_dev_err(hdev, "Reading QCA version information failed (%d)",
47 			   err);
48 		return err;
49 	}
50 
51 	if (skb->len != rlen) {
52 		bt_dev_err(hdev, "QCA Version size mismatch len %d", skb->len);
53 		err = -EILSEQ;
54 		goto out;
55 	}
56 
57 	edl = (struct edl_event_hdr *)(skb->data);
58 	if (!edl) {
59 		bt_dev_err(hdev, "QCA TLV with no header");
60 		err = -EILSEQ;
61 		goto out;
62 	}
63 
64 	if (edl->cresp != EDL_CMD_REQ_RES_EVT ||
65 	    edl->rtype != rtype) {
66 		bt_dev_err(hdev, "QCA Wrong packet received %d %d", edl->cresp,
67 			   edl->rtype);
68 		err = -EIO;
69 		goto out;
70 	}
71 
72 	if (soc_type >= QCA_WCN3991)
73 		memcpy(ver, edl->data + 1, sizeof(*ver));
74 	else
75 		memcpy(ver, &edl->data, sizeof(*ver));
76 
77 	bt_dev_info(hdev, "QCA Product ID   :0x%08x",
78 		    le32_to_cpu(ver->product_id));
79 	bt_dev_info(hdev, "QCA SOC Version  :0x%08x",
80 		    le32_to_cpu(ver->soc_id));
81 	bt_dev_info(hdev, "QCA ROM Version  :0x%08x",
82 		    le16_to_cpu(ver->rom_ver));
83 	bt_dev_info(hdev, "QCA Patch Version:0x%08x",
84 		    le16_to_cpu(ver->patch_ver));
85 
86 	if (ver->soc_id == 0 || ver->rom_ver == 0)
87 		err = -EILSEQ;
88 
89 out:
90 	kfree_skb(skb);
91 	if (err)
92 		bt_dev_err(hdev, "QCA Failed to get version (%d)", err);
93 
94 	return err;
95 }
96 EXPORT_SYMBOL_GPL(qca_read_soc_version);
97 
98 static int qca_read_fw_build_info(struct hci_dev *hdev)
99 {
100 	struct sk_buff *skb;
101 	struct edl_event_hdr *edl;
102 	char cmd, build_label[QCA_FW_BUILD_VER_LEN];
103 	int build_lbl_len, err = 0;
104 
105 	bt_dev_dbg(hdev, "QCA read fw build info");
106 
107 	cmd = EDL_GET_BUILD_INFO_CMD;
108 	skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, EDL_PATCH_CMD_LEN,
109 				&cmd, 0, HCI_INIT_TIMEOUT);
110 	if (IS_ERR(skb)) {
111 		err = PTR_ERR(skb);
112 		bt_dev_err(hdev, "Reading QCA fw build info failed (%d)",
113 			   err);
114 		return err;
115 	}
116 
117 	edl = (struct edl_event_hdr *)(skb->data);
118 	if (!edl) {
119 		bt_dev_err(hdev, "QCA read fw build info with no header");
120 		err = -EILSEQ;
121 		goto out;
122 	}
123 
124 	if (edl->cresp != EDL_CMD_REQ_RES_EVT ||
125 	    edl->rtype != EDL_GET_BUILD_INFO_CMD) {
126 		bt_dev_err(hdev, "QCA Wrong packet received %d %d", edl->cresp,
127 			   edl->rtype);
128 		err = -EIO;
129 		goto out;
130 	}
131 
132 	build_lbl_len = edl->data[0];
133 	if (build_lbl_len <= QCA_FW_BUILD_VER_LEN - 1) {
134 		memcpy(build_label, edl->data + 1, build_lbl_len);
135 		*(build_label + build_lbl_len) = '\0';
136 	}
137 
138 	hci_set_fw_info(hdev, "%s", build_label);
139 
140 out:
141 	kfree_skb(skb);
142 	return err;
143 }
144 
145 static int qca_send_reset(struct hci_dev *hdev)
146 {
147 	struct sk_buff *skb;
148 	int err;
149 
150 	bt_dev_dbg(hdev, "QCA HCI_RESET");
151 
152 	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
153 	if (IS_ERR(skb)) {
154 		err = PTR_ERR(skb);
155 		bt_dev_err(hdev, "QCA Reset failed (%d)", err);
156 		return err;
157 	}
158 
159 	kfree_skb(skb);
160 
161 	return 0;
162 }
163 
164 int qca_send_pre_shutdown_cmd(struct hci_dev *hdev)
165 {
166 	struct sk_buff *skb;
167 	int err;
168 
169 	bt_dev_dbg(hdev, "QCA pre shutdown cmd");
170 
171 	skb = __hci_cmd_sync_ev(hdev, QCA_PRE_SHUTDOWN_CMD, 0,
172 				NULL, HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
173 
174 	if (IS_ERR(skb)) {
175 		err = PTR_ERR(skb);
176 		bt_dev_err(hdev, "QCA preshutdown_cmd failed (%d)", err);
177 		return err;
178 	}
179 
180 	kfree_skb(skb);
181 
182 	return 0;
183 }
184 EXPORT_SYMBOL_GPL(qca_send_pre_shutdown_cmd);
185 
186 static void qca_tlv_check_data(struct hci_dev *hdev,
187 			       struct qca_fw_config *config,
188 		u8 *fw_data, enum qca_btsoc_type soc_type)
189 {
190 	const u8 *data;
191 	u32 type_len;
192 	u16 tag_id, tag_len;
193 	int idx, length;
194 	struct tlv_type_hdr *tlv;
195 	struct tlv_type_patch *tlv_patch;
196 	struct tlv_type_nvm *tlv_nvm;
197 	uint8_t nvm_baud_rate = config->user_baud_rate;
198 
199 	config->dnld_mode = QCA_SKIP_EVT_NONE;
200 	config->dnld_type = QCA_SKIP_EVT_NONE;
201 
202 	switch (config->type) {
203 	case ELF_TYPE_PATCH:
204 		config->dnld_mode = QCA_SKIP_EVT_VSE_CC;
205 		config->dnld_type = QCA_SKIP_EVT_VSE_CC;
206 
207 		bt_dev_dbg(hdev, "File Class        : 0x%x", fw_data[4]);
208 		bt_dev_dbg(hdev, "Data Encoding     : 0x%x", fw_data[5]);
209 		bt_dev_dbg(hdev, "File version      : 0x%x", fw_data[6]);
210 		break;
211 	case TLV_TYPE_PATCH:
212 		tlv = (struct tlv_type_hdr *)fw_data;
213 		type_len = le32_to_cpu(tlv->type_len);
214 		tlv_patch = (struct tlv_type_patch *)tlv->data;
215 
216 		/* For Rome version 1.1 to 3.1, all segment commands
217 		 * are acked by a vendor specific event (VSE).
218 		 * For Rome >= 3.2, the download mode field indicates
219 		 * if VSE is skipped by the controller.
220 		 * In case VSE is skipped, only the last segment is acked.
221 		 */
222 		config->dnld_mode = tlv_patch->download_mode;
223 		config->dnld_type = config->dnld_mode;
224 
225 		BT_DBG("TLV Type\t\t : 0x%x", type_len & 0x000000ff);
226 		BT_DBG("Total Length           : %d bytes",
227 		       le32_to_cpu(tlv_patch->total_size));
228 		BT_DBG("Patch Data Length      : %d bytes",
229 		       le32_to_cpu(tlv_patch->data_length));
230 		BT_DBG("Signing Format Version : 0x%x",
231 		       tlv_patch->format_version);
232 		BT_DBG("Signature Algorithm    : 0x%x",
233 		       tlv_patch->signature);
234 		BT_DBG("Download mode          : 0x%x",
235 		       tlv_patch->download_mode);
236 		BT_DBG("Reserved               : 0x%x",
237 		       tlv_patch->reserved1);
238 		BT_DBG("Product ID             : 0x%04x",
239 		       le16_to_cpu(tlv_patch->product_id));
240 		BT_DBG("Rom Build Version      : 0x%04x",
241 		       le16_to_cpu(tlv_patch->rom_build));
242 		BT_DBG("Patch Version          : 0x%04x",
243 		       le16_to_cpu(tlv_patch->patch_version));
244 		BT_DBG("Reserved               : 0x%x",
245 		       le16_to_cpu(tlv_patch->reserved2));
246 		BT_DBG("Patch Entry Address    : 0x%x",
247 		       le32_to_cpu(tlv_patch->entry));
248 		break;
249 
250 	case TLV_TYPE_NVM:
251 		tlv = (struct tlv_type_hdr *)fw_data;
252 
253 		type_len = le32_to_cpu(tlv->type_len);
254 		length = (type_len >> 8) & 0x00ffffff;
255 
256 		BT_DBG("TLV Type\t\t : 0x%x", type_len & 0x000000ff);
257 		BT_DBG("Length\t\t : %d bytes", length);
258 
259 		idx = 0;
260 		data = tlv->data;
261 		while (idx < length) {
262 			tlv_nvm = (struct tlv_type_nvm *)(data + idx);
263 
264 			tag_id = le16_to_cpu(tlv_nvm->tag_id);
265 			tag_len = le16_to_cpu(tlv_nvm->tag_len);
266 
267 			/* Update NVM tags as needed */
268 			switch (tag_id) {
269 			case EDL_TAG_ID_HCI:
270 				/* HCI transport layer parameters
271 				 * enabling software inband sleep
272 				 * onto controller side.
273 				 */
274 				tlv_nvm->data[0] |= 0x80;
275 
276 				/* UART Baud Rate */
277 				if (soc_type >= QCA_WCN3991)
278 					tlv_nvm->data[1] = nvm_baud_rate;
279 				else
280 					tlv_nvm->data[2] = nvm_baud_rate;
281 
282 				break;
283 
284 			case EDL_TAG_ID_DEEP_SLEEP:
285 				/* Sleep enable mask
286 				 * enabling deep sleep feature on controller.
287 				 */
288 				tlv_nvm->data[0] |= 0x01;
289 
290 				break;
291 			}
292 
293 			idx += (sizeof(u16) + sizeof(u16) + 8 + tag_len);
294 		}
295 		break;
296 
297 	default:
298 		BT_ERR("Unknown TLV type %d", config->type);
299 		break;
300 	}
301 }
302 
303 static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size,
304 				const u8 *data, enum qca_tlv_dnld_mode mode,
305 				enum qca_btsoc_type soc_type)
306 {
307 	struct sk_buff *skb;
308 	struct edl_event_hdr *edl;
309 	struct tlv_seg_resp *tlv_resp;
310 	u8 cmd[MAX_SIZE_PER_TLV_SEGMENT + 2];
311 	int err = 0;
312 	u8 event_type = HCI_EV_VENDOR;
313 	u8 rlen = (sizeof(*edl) + sizeof(*tlv_resp));
314 	u8 rtype = EDL_TVL_DNLD_RES_EVT;
315 
316 	cmd[0] = EDL_PATCH_TLV_REQ_CMD;
317 	cmd[1] = seg_size;
318 	memcpy(cmd + 2, data, seg_size);
319 
320 	if (mode == QCA_SKIP_EVT_VSE_CC || mode == QCA_SKIP_EVT_VSE)
321 		return __hci_cmd_send(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2,
322 				      cmd);
323 
324 	/* Unlike other SoC's sending version command response as payload to
325 	 * VSE event. WCN3991 sends version command response as a payload to
326 	 * command complete event.
327 	 */
328 	if (soc_type >= QCA_WCN3991) {
329 		event_type = 0;
330 		rlen = sizeof(*edl);
331 		rtype = EDL_PATCH_TLV_REQ_CMD;
332 	}
333 
334 	skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, cmd,
335 				event_type, HCI_INIT_TIMEOUT);
336 	if (IS_ERR(skb)) {
337 		err = PTR_ERR(skb);
338 		bt_dev_err(hdev, "QCA Failed to send TLV segment (%d)", err);
339 		return err;
340 	}
341 
342 	if (skb->len != rlen) {
343 		bt_dev_err(hdev, "QCA TLV response size mismatch");
344 		err = -EILSEQ;
345 		goto out;
346 	}
347 
348 	edl = (struct edl_event_hdr *)(skb->data);
349 	if (!edl) {
350 		bt_dev_err(hdev, "TLV with no header");
351 		err = -EILSEQ;
352 		goto out;
353 	}
354 
355 	if (edl->cresp != EDL_CMD_REQ_RES_EVT || edl->rtype != rtype) {
356 		bt_dev_err(hdev, "QCA TLV with error stat 0x%x rtype 0x%x",
357 			   edl->cresp, edl->rtype);
358 		err = -EIO;
359 	}
360 
361 	if (soc_type >= QCA_WCN3991)
362 		goto out;
363 
364 	tlv_resp = (struct tlv_seg_resp *)(edl->data);
365 	if (tlv_resp->result) {
366 		bt_dev_err(hdev, "QCA TLV with error stat 0x%x rtype 0x%x (0x%x)",
367 			   edl->cresp, edl->rtype, tlv_resp->result);
368 	}
369 
370 out:
371 	kfree_skb(skb);
372 
373 	return err;
374 }
375 
376 static int qca_inject_cmd_complete_event(struct hci_dev *hdev)
377 {
378 	struct hci_event_hdr *hdr;
379 	struct hci_ev_cmd_complete *evt;
380 	struct sk_buff *skb;
381 
382 	skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL);
383 	if (!skb)
384 		return -ENOMEM;
385 
386 	hdr = skb_put(skb, sizeof(*hdr));
387 	hdr->evt = HCI_EV_CMD_COMPLETE;
388 	hdr->plen = sizeof(*evt) + 1;
389 
390 	evt = skb_put(skb, sizeof(*evt));
391 	evt->ncmd = 1;
392 	evt->opcode = cpu_to_le16(QCA_HCI_CC_OPCODE);
393 
394 	skb_put_u8(skb, QCA_HCI_CC_SUCCESS);
395 
396 	hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
397 
398 	return hci_recv_frame(hdev, skb);
399 }
400 
401 static int qca_download_firmware(struct hci_dev *hdev,
402 				 struct qca_fw_config *config,
403 				 enum qca_btsoc_type soc_type,
404 				 u8 rom_ver)
405 {
406 	const struct firmware *fw;
407 	u8 *data;
408 	const u8 *segment;
409 	int ret, size, remain, i = 0;
410 
411 	bt_dev_info(hdev, "QCA Downloading %s", config->fwname);
412 
413 	ret = request_firmware(&fw, config->fwname, &hdev->dev);
414 	if (ret) {
415 		/* For WCN6750, if mbn file is not present then check for
416 		 * tlv file.
417 		 */
418 		if (soc_type == QCA_WCN6750 && config->type == ELF_TYPE_PATCH) {
419 			bt_dev_dbg(hdev, "QCA Failed to request file: %s (%d)",
420 				   config->fwname, ret);
421 			config->type = TLV_TYPE_PATCH;
422 			snprintf(config->fwname, sizeof(config->fwname),
423 				 "qca/msbtfw%02x.tlv", rom_ver);
424 			bt_dev_info(hdev, "QCA Downloading %s", config->fwname);
425 			ret = request_firmware(&fw, config->fwname, &hdev->dev);
426 			if (ret) {
427 				bt_dev_err(hdev, "QCA Failed to request file: %s (%d)",
428 					   config->fwname, ret);
429 				return ret;
430 			}
431 		} else {
432 			bt_dev_err(hdev, "QCA Failed to request file: %s (%d)",
433 				   config->fwname, ret);
434 			return ret;
435 		}
436 	}
437 
438 	size = fw->size;
439 	data = vmalloc(fw->size);
440 	if (!data) {
441 		bt_dev_err(hdev, "QCA Failed to allocate memory for file: %s",
442 			   config->fwname);
443 		release_firmware(fw);
444 		return -ENOMEM;
445 	}
446 
447 	memcpy(data, fw->data, size);
448 	release_firmware(fw);
449 
450 	qca_tlv_check_data(hdev, config, data, soc_type);
451 
452 	segment = data;
453 	remain = size;
454 	while (remain > 0) {
455 		int segsize = min(MAX_SIZE_PER_TLV_SEGMENT, remain);
456 
457 		bt_dev_dbg(hdev, "Send segment %d, size %d", i++, segsize);
458 
459 		remain -= segsize;
460 		/* The last segment is always acked regardless download mode */
461 		if (!remain || segsize < MAX_SIZE_PER_TLV_SEGMENT)
462 			config->dnld_mode = QCA_SKIP_EVT_NONE;
463 
464 		ret = qca_tlv_send_segment(hdev, segsize, segment,
465 					   config->dnld_mode, soc_type);
466 		if (ret)
467 			goto out;
468 
469 		segment += segsize;
470 	}
471 
472 	/* Latest qualcomm chipsets are not sending a command complete event
473 	 * for every fw packet sent. They only respond with a vendor specific
474 	 * event for the last packet. This optimization in the chip will
475 	 * decrease the BT in initialization time. Here we will inject a command
476 	 * complete event to avoid a command timeout error message.
477 	 */
478 	if (config->dnld_type == QCA_SKIP_EVT_VSE_CC ||
479 	    config->dnld_type == QCA_SKIP_EVT_VSE)
480 		ret = qca_inject_cmd_complete_event(hdev);
481 
482 out:
483 	vfree(data);
484 
485 	return ret;
486 }
487 
488 static int qca_disable_soc_logging(struct hci_dev *hdev)
489 {
490 	struct sk_buff *skb;
491 	u8 cmd[2];
492 	int err;
493 
494 	cmd[0] = QCA_DISABLE_LOGGING_SUB_OP;
495 	cmd[1] = 0x00;
496 	skb = __hci_cmd_sync_ev(hdev, QCA_DISABLE_LOGGING, sizeof(cmd), cmd,
497 				HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT);
498 	if (IS_ERR(skb)) {
499 		err = PTR_ERR(skb);
500 		bt_dev_err(hdev, "QCA Failed to disable soc logging(%d)", err);
501 		return err;
502 	}
503 
504 	kfree_skb(skb);
505 
506 	return 0;
507 }
508 
509 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr)
510 {
511 	struct sk_buff *skb;
512 	u8 cmd[9];
513 	int err;
514 
515 	cmd[0] = EDL_NVM_ACCESS_SET_REQ_CMD;
516 	cmd[1] = 0x02; 			/* TAG ID */
517 	cmd[2] = sizeof(bdaddr_t);	/* size */
518 	memcpy(cmd + 3, bdaddr, sizeof(bdaddr_t));
519 	skb = __hci_cmd_sync_ev(hdev, EDL_NVM_ACCESS_OPCODE, sizeof(cmd), cmd,
520 				HCI_EV_VENDOR, HCI_INIT_TIMEOUT);
521 	if (IS_ERR(skb)) {
522 		err = PTR_ERR(skb);
523 		bt_dev_err(hdev, "QCA Change address command failed (%d)", err);
524 		return err;
525 	}
526 
527 	kfree_skb(skb);
528 
529 	return 0;
530 }
531 EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome);
532 
533 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
534 		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
535 		   const char *firmware_name)
536 {
537 	struct qca_fw_config config;
538 	int err;
539 	u8 rom_ver = 0;
540 	u32 soc_ver;
541 
542 	bt_dev_dbg(hdev, "QCA setup on UART");
543 
544 	soc_ver = get_soc_ver(ver.soc_id, ver.rom_ver);
545 
546 	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
547 
548 	config.user_baud_rate = baudrate;
549 
550 	/* Firmware files to download are based on ROM version.
551 	 * ROM version is derived from last two bytes of soc_ver.
552 	 */
553 	rom_ver = ((soc_ver & 0x00000f00) >> 0x04) | (soc_ver & 0x0000000f);
554 
555 	/* Download rampatch file */
556 	config.type = TLV_TYPE_PATCH;
557 	if (qca_is_wcn399x(soc_type)) {
558 		snprintf(config.fwname, sizeof(config.fwname),
559 			 "qca/crbtfw%02x.tlv", rom_ver);
560 	} else if (soc_type == QCA_QCA6390) {
561 		snprintf(config.fwname, sizeof(config.fwname),
562 			 "qca/htbtfw%02x.tlv", rom_ver);
563 	} else if (soc_type == QCA_WCN6750) {
564 		/* Choose mbn file by default.If mbn file is not found
565 		 * then choose tlv file
566 		 */
567 		config.type = ELF_TYPE_PATCH;
568 		snprintf(config.fwname, sizeof(config.fwname),
569 			 "qca/msbtfw%02x.mbn", rom_ver);
570 	} else {
571 		snprintf(config.fwname, sizeof(config.fwname),
572 			 "qca/rampatch_%08x.bin", soc_ver);
573 	}
574 
575 	err = qca_download_firmware(hdev, &config, soc_type, rom_ver);
576 	if (err < 0) {
577 		bt_dev_err(hdev, "QCA Failed to download patch (%d)", err);
578 		return err;
579 	}
580 
581 	/* Give the controller some time to get ready to receive the NVM */
582 	msleep(10);
583 
584 	/* Download NVM configuration */
585 	config.type = TLV_TYPE_NVM;
586 	if (firmware_name)
587 		snprintf(config.fwname, sizeof(config.fwname),
588 			 "qca/%s", firmware_name);
589 	else if (qca_is_wcn399x(soc_type)) {
590 		if (ver.soc_id == QCA_WCN3991_SOC_ID) {
591 			snprintf(config.fwname, sizeof(config.fwname),
592 				 "qca/crnv%02xu.bin", rom_ver);
593 		} else {
594 			snprintf(config.fwname, sizeof(config.fwname),
595 				 "qca/crnv%02x.bin", rom_ver);
596 		}
597 	}
598 	else if (soc_type == QCA_QCA6390)
599 		snprintf(config.fwname, sizeof(config.fwname),
600 			 "qca/htnv%02x.bin", rom_ver);
601 	else if (soc_type == QCA_WCN6750)
602 		snprintf(config.fwname, sizeof(config.fwname),
603 			 "qca/msnv%02x.bin", rom_ver);
604 	else
605 		snprintf(config.fwname, sizeof(config.fwname),
606 			 "qca/nvm_%08x.bin", soc_ver);
607 
608 	err = qca_download_firmware(hdev, &config, soc_type, rom_ver);
609 	if (err < 0) {
610 		bt_dev_err(hdev, "QCA Failed to download NVM (%d)", err);
611 		return err;
612 	}
613 
614 	if (soc_type >= QCA_WCN3991) {
615 		err = qca_disable_soc_logging(hdev);
616 		if (err < 0)
617 			return err;
618 	}
619 
620 	/* WCN399x and WCN6750 supports the Microsoft vendor extension with 0xFD70 as the
621 	 * VsMsftOpCode.
622 	 */
623 	switch (soc_type) {
624 	case QCA_WCN3990:
625 	case QCA_WCN3991:
626 	case QCA_WCN3998:
627 	case QCA_WCN6750:
628 		hci_set_msft_opcode(hdev, 0xFD70);
629 		break;
630 	default:
631 		break;
632 	}
633 
634 	/* Perform HCI reset */
635 	err = qca_send_reset(hdev);
636 	if (err < 0) {
637 		bt_dev_err(hdev, "QCA Failed to run HCI_RESET (%d)", err);
638 		return err;
639 	}
640 
641 	if (soc_type == QCA_WCN3991 || soc_type == QCA_WCN6750) {
642 		/* get fw build info */
643 		err = qca_read_fw_build_info(hdev);
644 		if (err < 0)
645 			return err;
646 	}
647 
648 	bt_dev_info(hdev, "QCA setup on UART is completed");
649 
650 	return 0;
651 }
652 EXPORT_SYMBOL_GPL(qca_uart_setup);
653 
654 int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
655 {
656 	struct sk_buff *skb;
657 	int err;
658 
659 	skb = __hci_cmd_sync_ev(hdev, EDL_WRITE_BD_ADDR_OPCODE, 6, bdaddr,
660 				HCI_EV_VENDOR, HCI_INIT_TIMEOUT);
661 	if (IS_ERR(skb)) {
662 		err = PTR_ERR(skb);
663 		bt_dev_err(hdev, "QCA Change address cmd failed (%d)", err);
664 		return err;
665 	}
666 
667 	kfree_skb(skb);
668 
669 	return 0;
670 }
671 EXPORT_SYMBOL_GPL(qca_set_bdaddr);
672 
673 
674 MODULE_AUTHOR("Ben Young Tae Kim <ytkim@qca.qualcomm.com>");
675 MODULE_DESCRIPTION("Bluetooth support for Qualcomm Atheros family ver " VERSION);
676 MODULE_VERSION(VERSION);
677 MODULE_LICENSE("GPL");
678