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