Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  Bluetooth support for Realtek devices
  4 *
  5 *  Copyright (C) 2015 Endless Mobile, Inc.
  6 */
  7
  8#include <linux/module.h>
  9#include <linux/firmware.h>
 10#include <asm/unaligned.h>
 11#include <linux/usb.h>
 12
 13#include <net/bluetooth/bluetooth.h>
 14#include <net/bluetooth/hci_core.h>
 15
 16#include "btrtl.h"
 17
 18#define VERSION "0.1"
 19
 20#define RTL_EPATCH_SIGNATURE	"Realtech"
 21#define RTL_ROM_LMP_8723A	0x1200
 22#define RTL_ROM_LMP_8723B	0x8723
 23#define RTL_ROM_LMP_8821A	0x8821
 24#define RTL_ROM_LMP_8761A	0x8761
 25#define RTL_ROM_LMP_8822B	0x8822
 26#define RTL_ROM_LMP_8852A	0x8852
 27#define RTL_CONFIG_MAGIC	0x8723ab55
 28
 29#define IC_MATCH_FL_LMPSUBV	(1 << 0)
 30#define IC_MATCH_FL_HCIREV	(1 << 1)
 31#define IC_MATCH_FL_HCIVER	(1 << 2)
 32#define IC_MATCH_FL_HCIBUS	(1 << 3)
 33#define IC_INFO(lmps, hcir, hciv, bus) \
 34	.match_flags = IC_MATCH_FL_LMPSUBV | IC_MATCH_FL_HCIREV | \
 35		       IC_MATCH_FL_HCIVER | IC_MATCH_FL_HCIBUS, \
 36	.lmp_subver = (lmps), \
 37	.hci_rev = (hcir), \
 38	.hci_ver = (hciv), \
 39	.hci_bus = (bus)
 40
 41enum btrtl_chip_id {
 42	CHIP_ID_8723A,
 43	CHIP_ID_8723B,
 44	CHIP_ID_8821A,
 45	CHIP_ID_8761A,
 46	CHIP_ID_8822B = 8,
 47	CHIP_ID_8723D,
 48	CHIP_ID_8821C,
 49	CHIP_ID_8822C = 13,
 50	CHIP_ID_8761B,
 51	CHIP_ID_8852A = 18,
 52	CHIP_ID_8852B = 20,
 53	CHIP_ID_8852C = 25,
 54};
 55
 56struct id_table {
 57	__u16 match_flags;
 58	__u16 lmp_subver;
 59	__u16 hci_rev;
 60	__u8 hci_ver;
 61	__u8 hci_bus;
 62	bool config_needed;
 63	bool has_rom_version;
 64	bool has_msft_ext;
 65	char *fw_name;
 66	char *cfg_name;
 67};
 68
 69struct btrtl_device_info {
 70	const struct id_table *ic_info;
 71	u8 rom_version;
 72	u8 *fw_data;
 73	int fw_len;
 74	u8 *cfg_data;
 75	int cfg_len;
 76	bool drop_fw;
 77	int project_id;
 78};
 79
 80static const struct id_table ic_id_table[] = {
 81	/* 8723A */
 82	{ IC_INFO(RTL_ROM_LMP_8723A, 0xb, 0x6, HCI_USB),
 83	  .config_needed = false,
 84	  .has_rom_version = false,
 85	  .fw_name = "rtl_bt/rtl8723a_fw.bin",
 86	  .cfg_name = NULL },
 87
 88	/* 8723BS */
 89	{ IC_INFO(RTL_ROM_LMP_8723B, 0xb, 0x6, HCI_UART),
 90	  .config_needed = true,
 91	  .has_rom_version = true,
 92	  .fw_name  = "rtl_bt/rtl8723bs_fw.bin",
 93	  .cfg_name = "rtl_bt/rtl8723bs_config" },
 94
 95	/* 8723B */
 96	{ IC_INFO(RTL_ROM_LMP_8723B, 0xb, 0x6, HCI_USB),
 97	  .config_needed = false,
 98	  .has_rom_version = true,
 99	  .fw_name  = "rtl_bt/rtl8723b_fw.bin",
100	  .cfg_name = "rtl_bt/rtl8723b_config" },
101
102	/* 8723D */
103	{ IC_INFO(RTL_ROM_LMP_8723B, 0xd, 0x8, HCI_USB),
104	  .config_needed = true,
105	  .has_rom_version = true,
106	  .fw_name  = "rtl_bt/rtl8723d_fw.bin",
107	  .cfg_name = "rtl_bt/rtl8723d_config" },
108
109	/* 8723DS */
110	{ IC_INFO(RTL_ROM_LMP_8723B, 0xd, 0x8, HCI_UART),
111	  .config_needed = true,
112	  .has_rom_version = true,
113	  .fw_name  = "rtl_bt/rtl8723ds_fw.bin",
114	  .cfg_name = "rtl_bt/rtl8723ds_config" },
115
116	/* 8821A */
117	{ IC_INFO(RTL_ROM_LMP_8821A, 0xa, 0x6, HCI_USB),
118	  .config_needed = false,
119	  .has_rom_version = true,
120	  .fw_name  = "rtl_bt/rtl8821a_fw.bin",
121	  .cfg_name = "rtl_bt/rtl8821a_config" },
122
123	/* 8821C */
124	{ IC_INFO(RTL_ROM_LMP_8821A, 0xc, 0x8, HCI_USB),
125	  .config_needed = false,
126	  .has_rom_version = true,
127	  .has_msft_ext = true,
128	  .fw_name  = "rtl_bt/rtl8821c_fw.bin",
129	  .cfg_name = "rtl_bt/rtl8821c_config" },
130
131	/* 8761A */
132	{ IC_INFO(RTL_ROM_LMP_8761A, 0xa, 0x6, HCI_USB),
133	  .config_needed = false,
134	  .has_rom_version = true,
135	  .fw_name  = "rtl_bt/rtl8761a_fw.bin",
136	  .cfg_name = "rtl_bt/rtl8761a_config" },
137
138	/* 8761B */
139	{ IC_INFO(RTL_ROM_LMP_8761A, 0xb, 0xa, HCI_UART),
140	  .config_needed = false,
141	  .has_rom_version = true,
142	  .has_msft_ext = true,
143	  .fw_name  = "rtl_bt/rtl8761b_fw.bin",
144	  .cfg_name = "rtl_bt/rtl8761b_config" },
145
146	/* 8761BU */
147	{ IC_INFO(RTL_ROM_LMP_8761A, 0xb, 0xa, HCI_USB),
148	  .config_needed = false,
149	  .has_rom_version = true,
150	  .fw_name  = "rtl_bt/rtl8761bu_fw.bin",
151	  .cfg_name = "rtl_bt/rtl8761bu_config" },
152
153	/* 8822C with UART interface */
154	{ IC_INFO(RTL_ROM_LMP_8822B, 0xc, 0x8, HCI_UART),
155	  .config_needed = true,
156	  .has_rom_version = true,
157	  .has_msft_ext = true,
158	  .fw_name  = "rtl_bt/rtl8822cs_fw.bin",
159	  .cfg_name = "rtl_bt/rtl8822cs_config" },
160
161	/* 8822C with UART interface */
162	{ IC_INFO(RTL_ROM_LMP_8822B, 0xc, 0xa, HCI_UART),
163	  .config_needed = true,
164	  .has_rom_version = true,
165	  .has_msft_ext = true,
166	  .fw_name  = "rtl_bt/rtl8822cs_fw.bin",
167	  .cfg_name = "rtl_bt/rtl8822cs_config" },
168
169	/* 8822C with USB interface */
170	{ IC_INFO(RTL_ROM_LMP_8822B, 0xc, 0xa, HCI_USB),
171	  .config_needed = false,
172	  .has_rom_version = true,
173	  .has_msft_ext = true,
174	  .fw_name  = "rtl_bt/rtl8822cu_fw.bin",
175	  .cfg_name = "rtl_bt/rtl8822cu_config" },
176
177	/* 8822B */
178	{ IC_INFO(RTL_ROM_LMP_8822B, 0xb, 0x7, HCI_USB),
179	  .config_needed = true,
180	  .has_rom_version = true,
181	  .has_msft_ext = true,
182	  .fw_name  = "rtl_bt/rtl8822b_fw.bin",
183	  .cfg_name = "rtl_bt/rtl8822b_config" },
184
185	/* 8852A */
186	{ IC_INFO(RTL_ROM_LMP_8852A, 0xa, 0xb, HCI_USB),
187	  .config_needed = false,
188	  .has_rom_version = true,
189	  .has_msft_ext = true,
190	  .fw_name  = "rtl_bt/rtl8852au_fw.bin",
191	  .cfg_name = "rtl_bt/rtl8852au_config" },
192
193	/* 8852B */
194	{ IC_INFO(RTL_ROM_LMP_8852A, 0xb, 0xb, HCI_USB),
195	  .config_needed = false,
196	  .has_rom_version = true,
197	  .has_msft_ext = true,
198	  .fw_name  = "rtl_bt/rtl8852bu_fw.bin",
199	  .cfg_name = "rtl_bt/rtl8852bu_config" },
200
201	/* 8852C */
202	{ IC_INFO(RTL_ROM_LMP_8852A, 0xc, 0xc, HCI_USB),
203	  .config_needed = false,
204	  .has_rom_version = true,
205	  .has_msft_ext = true,
206	  .fw_name  = "rtl_bt/rtl8852cu_fw.bin",
207	  .cfg_name = "rtl_bt/rtl8852cu_config" },
208	};
209
210static const struct id_table *btrtl_match_ic(u16 lmp_subver, u16 hci_rev,
211					     u8 hci_ver, u8 hci_bus)
212{
213	int i;
214
215	for (i = 0; i < ARRAY_SIZE(ic_id_table); i++) {
216		if ((ic_id_table[i].match_flags & IC_MATCH_FL_LMPSUBV) &&
217		    (ic_id_table[i].lmp_subver != lmp_subver))
218			continue;
219		if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIREV) &&
220		    (ic_id_table[i].hci_rev != hci_rev))
221			continue;
222		if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIVER) &&
223		    (ic_id_table[i].hci_ver != hci_ver))
224			continue;
225		if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIBUS) &&
226		    (ic_id_table[i].hci_bus != hci_bus))
227			continue;
228
229		break;
230	}
231	if (i >= ARRAY_SIZE(ic_id_table))
232		return NULL;
233
234	return &ic_id_table[i];
235}
236
237static struct sk_buff *btrtl_read_local_version(struct hci_dev *hdev)
238{
239	struct sk_buff *skb;
240
241	skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
242			     HCI_INIT_TIMEOUT);
243	if (IS_ERR(skb)) {
244		rtl_dev_err(hdev, "HCI_OP_READ_LOCAL_VERSION failed (%ld)",
245			    PTR_ERR(skb));
246		return skb;
247	}
248
249	if (skb->len != sizeof(struct hci_rp_read_local_version)) {
250		rtl_dev_err(hdev, "HCI_OP_READ_LOCAL_VERSION event length mismatch");
251		kfree_skb(skb);
252		return ERR_PTR(-EIO);
253	}
254
255	return skb;
256}
257
258static int rtl_read_rom_version(struct hci_dev *hdev, u8 *version)
259{
260	struct rtl_rom_version_evt *rom_version;
261	struct sk_buff *skb;
262
263	/* Read RTL ROM version command */
264	skb = __hci_cmd_sync(hdev, 0xfc6d, 0, NULL, HCI_INIT_TIMEOUT);
265	if (IS_ERR(skb)) {
266		rtl_dev_err(hdev, "Read ROM version failed (%ld)",
267			    PTR_ERR(skb));
268		return PTR_ERR(skb);
269	}
270
271	if (skb->len != sizeof(*rom_version)) {
272		rtl_dev_err(hdev, "version event length mismatch");
273		kfree_skb(skb);
274		return -EIO;
275	}
276
277	rom_version = (struct rtl_rom_version_evt *)skb->data;
278	rtl_dev_info(hdev, "rom_version status=%x version=%x",
279		     rom_version->status, rom_version->version);
280
281	*version = rom_version->version;
282
283	kfree_skb(skb);
284	return 0;
285}
286
287static int rtlbt_parse_firmware(struct hci_dev *hdev,
288				struct btrtl_device_info *btrtl_dev,
289				unsigned char **_buf)
290{
291	static const u8 extension_sig[] = { 0x51, 0x04, 0xfd, 0x77 };
292	struct rtl_epatch_header *epatch_info;
293	unsigned char *buf;
294	int i, len;
295	size_t min_size;
296	u8 opcode, length, data;
297	int project_id = -1;
298	const unsigned char *fwptr, *chip_id_base;
299	const unsigned char *patch_length_base, *patch_offset_base;
300	u32 patch_offset = 0;
301	u16 patch_length, num_patches;
302	static const struct {
303		__u16 lmp_subver;
304		__u8 id;
305	} project_id_to_lmp_subver[] = {
306		{ RTL_ROM_LMP_8723A, 0 },
307		{ RTL_ROM_LMP_8723B, 1 },
308		{ RTL_ROM_LMP_8821A, 2 },
309		{ RTL_ROM_LMP_8761A, 3 },
310		{ RTL_ROM_LMP_8822B, 8 },
311		{ RTL_ROM_LMP_8723B, 9 },	/* 8723D */
312		{ RTL_ROM_LMP_8821A, 10 },	/* 8821C */
313		{ RTL_ROM_LMP_8822B, 13 },	/* 8822C */
314		{ RTL_ROM_LMP_8761A, 14 },	/* 8761B */
315		{ RTL_ROM_LMP_8852A, 18 },	/* 8852A */
316		{ RTL_ROM_LMP_8852A, 20 },	/* 8852B */
317		{ RTL_ROM_LMP_8852A, 25 },	/* 8852C */
318	};
319
320	min_size = sizeof(struct rtl_epatch_header) + sizeof(extension_sig) + 3;
321	if (btrtl_dev->fw_len < min_size)
322		return -EINVAL;
323
324	fwptr = btrtl_dev->fw_data + btrtl_dev->fw_len - sizeof(extension_sig);
325	if (memcmp(fwptr, extension_sig, sizeof(extension_sig)) != 0) {
326		rtl_dev_err(hdev, "extension section signature mismatch");
327		return -EINVAL;
328	}
329
330	/* Loop from the end of the firmware parsing instructions, until
331	 * we find an instruction that identifies the "project ID" for the
332	 * hardware supported by this firwmare file.
333	 * Once we have that, we double-check that project_id is suitable
334	 * for the hardware we are working with.
335	 */
336	while (fwptr >= btrtl_dev->fw_data + (sizeof(*epatch_info) + 3)) {
337		opcode = *--fwptr;
338		length = *--fwptr;
339		data = *--fwptr;
340
341		BT_DBG("check op=%x len=%x data=%x", opcode, length, data);
342
343		if (opcode == 0xff) /* EOF */
344			break;
345
346		if (length == 0) {
347			rtl_dev_err(hdev, "found instruction with length 0");
348			return -EINVAL;
349		}
350
351		if (opcode == 0 && length == 1) {
352			project_id = data;
353			break;
354		}
355
356		fwptr -= length;
357	}
358
359	if (project_id < 0) {
360		rtl_dev_err(hdev, "failed to find version instruction");
361		return -EINVAL;
362	}
363
364	/* Find project_id in table */
365	for (i = 0; i < ARRAY_SIZE(project_id_to_lmp_subver); i++) {
366		if (project_id == project_id_to_lmp_subver[i].id) {
367			btrtl_dev->project_id = project_id;
368			break;
369		}
370	}
371
372	if (i >= ARRAY_SIZE(project_id_to_lmp_subver)) {
373		rtl_dev_err(hdev, "unknown project id %d", project_id);
374		return -EINVAL;
375	}
376
377	if (btrtl_dev->ic_info->lmp_subver !=
378				project_id_to_lmp_subver[i].lmp_subver) {
379		rtl_dev_err(hdev, "firmware is for %x but this is a %x",
380			    project_id_to_lmp_subver[i].lmp_subver,
381			    btrtl_dev->ic_info->lmp_subver);
382		return -EINVAL;
383	}
384
385	epatch_info = (struct rtl_epatch_header *)btrtl_dev->fw_data;
386	if (memcmp(epatch_info->signature, RTL_EPATCH_SIGNATURE, 8) != 0) {
387		rtl_dev_err(hdev, "bad EPATCH signature");
388		return -EINVAL;
389	}
390
391	num_patches = le16_to_cpu(epatch_info->num_patches);
392	BT_DBG("fw_version=%x, num_patches=%d",
393	       le32_to_cpu(epatch_info->fw_version), num_patches);
394
395	/* After the rtl_epatch_header there is a funky patch metadata section.
396	 * Assuming 2 patches, the layout is:
397	 * ChipID1 ChipID2 PatchLength1 PatchLength2 PatchOffset1 PatchOffset2
398	 *
399	 * Find the right patch for this chip.
400	 */
401	min_size += 8 * num_patches;
402	if (btrtl_dev->fw_len < min_size)
403		return -EINVAL;
404
405	chip_id_base = btrtl_dev->fw_data + sizeof(struct rtl_epatch_header);
406	patch_length_base = chip_id_base + (sizeof(u16) * num_patches);
407	patch_offset_base = patch_length_base + (sizeof(u16) * num_patches);
408	for (i = 0; i < num_patches; i++) {
409		u16 chip_id = get_unaligned_le16(chip_id_base +
410						 (i * sizeof(u16)));
411		if (chip_id == btrtl_dev->rom_version + 1) {
412			patch_length = get_unaligned_le16(patch_length_base +
413							  (i * sizeof(u16)));
414			patch_offset = get_unaligned_le32(patch_offset_base +
415							  (i * sizeof(u32)));
416			break;
417		}
418	}
419
420	if (!patch_offset) {
421		rtl_dev_err(hdev, "didn't find patch for chip id %d",
422			    btrtl_dev->rom_version);
423		return -EINVAL;
424	}
425
426	BT_DBG("length=%x offset=%x index %d", patch_length, patch_offset, i);
427	min_size = patch_offset + patch_length;
428	if (btrtl_dev->fw_len < min_size)
429		return -EINVAL;
430
431	/* Copy the firmware into a new buffer and write the version at
432	 * the end.
433	 */
434	len = patch_length;
435	buf = kvmalloc(patch_length, GFP_KERNEL);
436	if (!buf)
437		return -ENOMEM;
438
439	memcpy(buf, btrtl_dev->fw_data + patch_offset, patch_length - 4);
440	memcpy(buf + patch_length - 4, &epatch_info->fw_version, 4);
441
442	*_buf = buf;
443	return len;
444}
445
446static int rtl_download_firmware(struct hci_dev *hdev,
447				 const unsigned char *data, int fw_len)
448{
449	struct rtl_download_cmd *dl_cmd;
450	int frag_num = fw_len / RTL_FRAG_LEN + 1;
451	int frag_len = RTL_FRAG_LEN;
452	int ret = 0;
453	int i;
454	struct sk_buff *skb;
455	struct hci_rp_read_local_version *rp;
456
457	dl_cmd = kmalloc(sizeof(struct rtl_download_cmd), GFP_KERNEL);
458	if (!dl_cmd)
459		return -ENOMEM;
460
461	for (i = 0; i < frag_num; i++) {
462		struct sk_buff *skb;
463
464		BT_DBG("download fw (%d/%d)", i, frag_num);
465
466		if (i > 0x7f)
467			dl_cmd->index = (i & 0x7f) + 1;
468		else
469			dl_cmd->index = i;
470
471		if (i == (frag_num - 1)) {
472			dl_cmd->index |= 0x80; /* data end */
473			frag_len = fw_len % RTL_FRAG_LEN;
474		}
475		memcpy(dl_cmd->data, data, frag_len);
476
477		/* Send download command */
478		skb = __hci_cmd_sync(hdev, 0xfc20, frag_len + 1, dl_cmd,
479				     HCI_INIT_TIMEOUT);
480		if (IS_ERR(skb)) {
481			rtl_dev_err(hdev, "download fw command failed (%ld)",
482				    PTR_ERR(skb));
483			ret = PTR_ERR(skb);
484			goto out;
485		}
486
487		if (skb->len != sizeof(struct rtl_download_response)) {
488			rtl_dev_err(hdev, "download fw event length mismatch");
489			kfree_skb(skb);
490			ret = -EIO;
491			goto out;
492		}
493
494		kfree_skb(skb);
495		data += RTL_FRAG_LEN;
496	}
497
498	skb = btrtl_read_local_version(hdev);
499	if (IS_ERR(skb)) {
500		ret = PTR_ERR(skb);
501		rtl_dev_err(hdev, "read local version failed");
502		goto out;
503	}
504
505	rp = (struct hci_rp_read_local_version *)skb->data;
506	rtl_dev_info(hdev, "fw version 0x%04x%04x",
507		     __le16_to_cpu(rp->hci_rev), __le16_to_cpu(rp->lmp_subver));
508	kfree_skb(skb);
509
510out:
511	kfree(dl_cmd);
512	return ret;
513}
514
515static int rtl_load_file(struct hci_dev *hdev, const char *name, u8 **buff)
516{
517	const struct firmware *fw;
518	int ret;
519
520	rtl_dev_info(hdev, "loading %s", name);
521	ret = request_firmware(&fw, name, &hdev->dev);
522	if (ret < 0)
523		return ret;
524	ret = fw->size;
525	*buff = kvmalloc(fw->size, GFP_KERNEL);
526	if (*buff)
527		memcpy(*buff, fw->data, ret);
528	else
529		ret = -ENOMEM;
530
531	release_firmware(fw);
532
533	return ret;
534}
535
536static int btrtl_setup_rtl8723a(struct hci_dev *hdev,
537				struct btrtl_device_info *btrtl_dev)
538{
539	if (btrtl_dev->fw_len < 8)
540		return -EINVAL;
541
542	/* Check that the firmware doesn't have the epatch signature
543	 * (which is only for RTL8723B and newer).
544	 */
545	if (!memcmp(btrtl_dev->fw_data, RTL_EPATCH_SIGNATURE, 8)) {
546		rtl_dev_err(hdev, "unexpected EPATCH signature!");
547		return -EINVAL;
548	}
549
550	return rtl_download_firmware(hdev, btrtl_dev->fw_data,
551				     btrtl_dev->fw_len);
552}
553
554static int btrtl_setup_rtl8723b(struct hci_dev *hdev,
555				struct btrtl_device_info *btrtl_dev)
556{
557	unsigned char *fw_data = NULL;
558	int ret;
559	u8 *tbuff;
560
561	ret = rtlbt_parse_firmware(hdev, btrtl_dev, &fw_data);
562	if (ret < 0)
563		goto out;
564
565	if (btrtl_dev->cfg_len > 0) {
566		tbuff = kvzalloc(ret + btrtl_dev->cfg_len, GFP_KERNEL);
567		if (!tbuff) {
568			ret = -ENOMEM;
569			goto out;
570		}
571
572		memcpy(tbuff, fw_data, ret);
573		kvfree(fw_data);
574
575		memcpy(tbuff + ret, btrtl_dev->cfg_data, btrtl_dev->cfg_len);
576		ret += btrtl_dev->cfg_len;
577
578		fw_data = tbuff;
579	}
580
581	rtl_dev_info(hdev, "cfg_sz %d, total sz %d", btrtl_dev->cfg_len, ret);
582
583	ret = rtl_download_firmware(hdev, fw_data, ret);
584
585out:
586	kvfree(fw_data);
587	return ret;
588}
589
590void btrtl_free(struct btrtl_device_info *btrtl_dev)
591{
592	kvfree(btrtl_dev->fw_data);
593	kvfree(btrtl_dev->cfg_data);
594	kfree(btrtl_dev);
595}
596EXPORT_SYMBOL_GPL(btrtl_free);
597
598struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
599					   const char *postfix)
600{
601	struct btrtl_device_info *btrtl_dev;
602	struct sk_buff *skb;
603	struct hci_rp_read_local_version *resp;
604	char cfg_name[40];
605	u16 hci_rev, lmp_subver;
606	u8 hci_ver;
607	int ret;
608	u16 opcode;
609	u8 cmd[2];
610
611	btrtl_dev = kzalloc(sizeof(*btrtl_dev), GFP_KERNEL);
612	if (!btrtl_dev) {
613		ret = -ENOMEM;
614		goto err_alloc;
615	}
616
617	skb = btrtl_read_local_version(hdev);
618	if (IS_ERR(skb)) {
619		ret = PTR_ERR(skb);
620		goto err_free;
621	}
622
623	resp = (struct hci_rp_read_local_version *)skb->data;
624	rtl_dev_info(hdev, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x",
625		     resp->hci_ver, resp->hci_rev,
626		     resp->lmp_ver, resp->lmp_subver);
627
628	hci_ver = resp->hci_ver;
629	hci_rev = le16_to_cpu(resp->hci_rev);
630	lmp_subver = le16_to_cpu(resp->lmp_subver);
631
632	btrtl_dev->ic_info = btrtl_match_ic(lmp_subver, hci_rev, hci_ver,
633					    hdev->bus);
634
635	if (!btrtl_dev->ic_info)
636		btrtl_dev->drop_fw = true;
637
638	if (btrtl_dev->drop_fw) {
639		opcode = hci_opcode_pack(0x3f, 0x66);
640		cmd[0] = opcode & 0xff;
641		cmd[1] = opcode >> 8;
642
643		skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
644		if (!skb)
645			goto out_free;
646
647		skb_put_data(skb, cmd, sizeof(cmd));
648		hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
649
650		hdev->send(hdev, skb);
651
652		/* Ensure the above vendor command is sent to controller and
653		 * process has done.
654		 */
655		msleep(200);
656
657		/* Read the local version again. Expect to have the vanilla
658		 * version as cold boot.
659		 */
660		skb = btrtl_read_local_version(hdev);
661		if (IS_ERR(skb)) {
662			ret = PTR_ERR(skb);
663			goto err_free;
664		}
665
666		resp = (struct hci_rp_read_local_version *)skb->data;
667		rtl_dev_info(hdev, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x",
668			     resp->hci_ver, resp->hci_rev,
669			     resp->lmp_ver, resp->lmp_subver);
670
671		hci_ver = resp->hci_ver;
672		hci_rev = le16_to_cpu(resp->hci_rev);
673		lmp_subver = le16_to_cpu(resp->lmp_subver);
674
675		btrtl_dev->ic_info = btrtl_match_ic(lmp_subver, hci_rev, hci_ver,
676						    hdev->bus);
677	}
678out_free:
679	kfree_skb(skb);
680
 
 
 
681	if (!btrtl_dev->ic_info) {
682		rtl_dev_info(hdev, "unknown IC info, lmp subver %04x, hci rev %04x, hci ver %04x",
683			    lmp_subver, hci_rev, hci_ver);
684		return btrtl_dev;
685	}
686
687	if (btrtl_dev->ic_info->has_rom_version) {
688		ret = rtl_read_rom_version(hdev, &btrtl_dev->rom_version);
689		if (ret)
690			goto err_free;
691	}
692
693	btrtl_dev->fw_len = rtl_load_file(hdev, btrtl_dev->ic_info->fw_name,
694					  &btrtl_dev->fw_data);
695	if (btrtl_dev->fw_len < 0) {
696		rtl_dev_err(hdev, "firmware file %s not found",
697			    btrtl_dev->ic_info->fw_name);
698		ret = btrtl_dev->fw_len;
699		goto err_free;
700	}
701
702	if (btrtl_dev->ic_info->cfg_name) {
703		if (postfix) {
704			snprintf(cfg_name, sizeof(cfg_name), "%s-%s.bin",
705				 btrtl_dev->ic_info->cfg_name, postfix);
706		} else {
707			snprintf(cfg_name, sizeof(cfg_name), "%s.bin",
708				 btrtl_dev->ic_info->cfg_name);
709		}
710		btrtl_dev->cfg_len = rtl_load_file(hdev, cfg_name,
711						   &btrtl_dev->cfg_data);
712		if (btrtl_dev->ic_info->config_needed &&
713		    btrtl_dev->cfg_len <= 0) {
714			rtl_dev_err(hdev, "mandatory config file %s not found",
715				    btrtl_dev->ic_info->cfg_name);
716			ret = btrtl_dev->cfg_len;
717			goto err_free;
718		}
719	}
720
721	/* The following chips supports the Microsoft vendor extension,
722	 * therefore set the corresponding VsMsftOpCode.
723	 */
724	if (btrtl_dev->ic_info->has_msft_ext)
725		hci_set_msft_opcode(hdev, 0xFCF0);
726
727	return btrtl_dev;
728
729err_free:
730	btrtl_free(btrtl_dev);
731err_alloc:
732	return ERR_PTR(ret);
733}
734EXPORT_SYMBOL_GPL(btrtl_initialize);
735
736int btrtl_download_firmware(struct hci_dev *hdev,
737			    struct btrtl_device_info *btrtl_dev)
738{
739	/* Match a set of subver values that correspond to stock firmware,
740	 * which is not compatible with standard btusb.
741	 * If matched, upload an alternative firmware that does conform to
742	 * standard btusb. Once that firmware is uploaded, the subver changes
743	 * to a different value.
744	 */
745	if (!btrtl_dev->ic_info) {
746		rtl_dev_info(hdev, "assuming no firmware upload needed");
747		return 0;
748	}
749
750	switch (btrtl_dev->ic_info->lmp_subver) {
751	case RTL_ROM_LMP_8723A:
752		return btrtl_setup_rtl8723a(hdev, btrtl_dev);
753	case RTL_ROM_LMP_8723B:
754	case RTL_ROM_LMP_8821A:
755	case RTL_ROM_LMP_8761A:
756	case RTL_ROM_LMP_8822B:
757	case RTL_ROM_LMP_8852A:
758		return btrtl_setup_rtl8723b(hdev, btrtl_dev);
759	default:
760		rtl_dev_info(hdev, "assuming no firmware upload needed");
761		return 0;
762	}
763}
764EXPORT_SYMBOL_GPL(btrtl_download_firmware);
765
766void btrtl_set_quirks(struct hci_dev *hdev, struct btrtl_device_info *btrtl_dev)
767{
768	/* Enable controller to do both LE scan and BR/EDR inquiry
769	 * simultaneously.
770	 */
771	set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
772
773	/* Enable central-peripheral role (able to create new connections with
774	 * an existing connection in slave role).
775	 */
776	/* Enable WBS supported for the specific Realtek devices. */
777	switch (btrtl_dev->project_id) {
778	case CHIP_ID_8822C:
779	case CHIP_ID_8852A:
780	case CHIP_ID_8852B:
781	case CHIP_ID_8852C:
782		set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
783		set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks);
784
785		/* RTL8852C needs to transmit mSBC data continuously without
786		 * the zero length of USB packets for the ALT 6 supported chips
787		 */
788		if (btrtl_dev->project_id == CHIP_ID_8852C)
789			btrealtek_set_flag(hdev, REALTEK_ALT6_CONTINUOUS_TX_CHIP);
790
791		hci_set_aosp_capable(hdev);
792		break;
793	default:
794		rtl_dev_dbg(hdev, "Central-peripheral role not enabled.");
795		rtl_dev_dbg(hdev, "WBS supported not enabled.");
796		break;
797	}
798}
799EXPORT_SYMBOL_GPL(btrtl_set_quirks);
800
801int btrtl_setup_realtek(struct hci_dev *hdev)
802{
803	struct btrtl_device_info *btrtl_dev;
804	int ret;
805
806	btrtl_dev = btrtl_initialize(hdev, NULL);
807	if (IS_ERR(btrtl_dev))
808		return PTR_ERR(btrtl_dev);
809
810	ret = btrtl_download_firmware(hdev, btrtl_dev);
811
812	btrtl_set_quirks(hdev, btrtl_dev);
813
814	btrtl_free(btrtl_dev);
815	return ret;
816}
817EXPORT_SYMBOL_GPL(btrtl_setup_realtek);
818
819int btrtl_shutdown_realtek(struct hci_dev *hdev)
820{
821	struct sk_buff *skb;
822	int ret;
823
824	/* According to the vendor driver, BT must be reset on close to avoid
825	 * firmware crash.
826	 */
827	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
828	if (IS_ERR(skb)) {
829		ret = PTR_ERR(skb);
830		bt_dev_err(hdev, "HCI reset during shutdown failed");
831		return ret;
832	}
833	kfree_skb(skb);
834
835	return 0;
836}
837EXPORT_SYMBOL_GPL(btrtl_shutdown_realtek);
838
839static unsigned int btrtl_convert_baudrate(u32 device_baudrate)
840{
841	switch (device_baudrate) {
842	case 0x0252a00a:
843		return 230400;
844
845	case 0x05f75004:
846		return 921600;
847
848	case 0x00005004:
849		return 1000000;
850
851	case 0x04928002:
852	case 0x01128002:
853		return 1500000;
854
855	case 0x00005002:
856		return 2000000;
857
858	case 0x0000b001:
859		return 2500000;
860
861	case 0x04928001:
862		return 3000000;
863
864	case 0x052a6001:
865		return 3500000;
866
867	case 0x00005001:
868		return 4000000;
869
870	case 0x0252c014:
871	default:
872		return 115200;
873	}
874}
875
876int btrtl_get_uart_settings(struct hci_dev *hdev,
877			    struct btrtl_device_info *btrtl_dev,
878			    unsigned int *controller_baudrate,
879			    u32 *device_baudrate, bool *flow_control)
880{
881	struct rtl_vendor_config *config;
882	struct rtl_vendor_config_entry *entry;
883	int i, total_data_len;
884	bool found = false;
885
886	total_data_len = btrtl_dev->cfg_len - sizeof(*config);
887	if (total_data_len <= 0) {
888		rtl_dev_warn(hdev, "no config loaded");
889		return -EINVAL;
890	}
891
892	config = (struct rtl_vendor_config *)btrtl_dev->cfg_data;
893	if (le32_to_cpu(config->signature) != RTL_CONFIG_MAGIC) {
894		rtl_dev_err(hdev, "invalid config magic");
895		return -EINVAL;
896	}
897
898	if (total_data_len < le16_to_cpu(config->total_len)) {
899		rtl_dev_err(hdev, "config is too short");
900		return -EINVAL;
901	}
902
903	for (i = 0; i < total_data_len; ) {
904		entry = ((void *)config->entry) + i;
905
906		switch (le16_to_cpu(entry->offset)) {
907		case 0xc:
908			if (entry->len < sizeof(*device_baudrate)) {
909				rtl_dev_err(hdev, "invalid UART config entry");
910				return -EINVAL;
911			}
912
913			*device_baudrate = get_unaligned_le32(entry->data);
914			*controller_baudrate = btrtl_convert_baudrate(
915							*device_baudrate);
916
917			if (entry->len >= 13)
918				*flow_control = !!(entry->data[12] & BIT(2));
919			else
920				*flow_control = false;
921
922			found = true;
923			break;
924
925		default:
926			rtl_dev_dbg(hdev, "skipping config entry 0x%x (len %u)",
927				   le16_to_cpu(entry->offset), entry->len);
928			break;
929		}
930
931		i += sizeof(*entry) + entry->len;
932	}
933
934	if (!found) {
935		rtl_dev_err(hdev, "no UART config entry found");
936		return -ENOENT;
937	}
938
939	rtl_dev_dbg(hdev, "device baudrate = 0x%08x", *device_baudrate);
940	rtl_dev_dbg(hdev, "controller baudrate = %u", *controller_baudrate);
941	rtl_dev_dbg(hdev, "flow control %d", *flow_control);
942
943	return 0;
944}
945EXPORT_SYMBOL_GPL(btrtl_get_uart_settings);
946
947MODULE_AUTHOR("Daniel Drake <drake@endlessm.com>");
948MODULE_DESCRIPTION("Bluetooth support for Realtek devices ver " VERSION);
949MODULE_VERSION(VERSION);
950MODULE_LICENSE("GPL");
951MODULE_FIRMWARE("rtl_bt/rtl8723a_fw.bin");
952MODULE_FIRMWARE("rtl_bt/rtl8723b_fw.bin");
953MODULE_FIRMWARE("rtl_bt/rtl8723b_config.bin");
954MODULE_FIRMWARE("rtl_bt/rtl8723bs_fw.bin");
955MODULE_FIRMWARE("rtl_bt/rtl8723bs_config.bin");
956MODULE_FIRMWARE("rtl_bt/rtl8723ds_fw.bin");
957MODULE_FIRMWARE("rtl_bt/rtl8723ds_config.bin");
958MODULE_FIRMWARE("rtl_bt/rtl8761a_fw.bin");
959MODULE_FIRMWARE("rtl_bt/rtl8761a_config.bin");
960MODULE_FIRMWARE("rtl_bt/rtl8821a_fw.bin");
961MODULE_FIRMWARE("rtl_bt/rtl8821a_config.bin");
962MODULE_FIRMWARE("rtl_bt/rtl8822b_fw.bin");
963MODULE_FIRMWARE("rtl_bt/rtl8822b_config.bin");
964MODULE_FIRMWARE("rtl_bt/rtl8852au_fw.bin");
965MODULE_FIRMWARE("rtl_bt/rtl8852au_config.bin");
966MODULE_FIRMWARE("rtl_bt/rtl8852bu_fw.bin");
967MODULE_FIRMWARE("rtl_bt/rtl8852bu_config.bin");
968MODULE_FIRMWARE("rtl_bt/rtl8852cu_fw.bin");
969MODULE_FIRMWARE("rtl_bt/rtl8852cu_config.bin");
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  Bluetooth support for Realtek devices
  4 *
  5 *  Copyright (C) 2015 Endless Mobile, Inc.
  6 */
  7
  8#include <linux/module.h>
  9#include <linux/firmware.h>
 10#include <asm/unaligned.h>
 11#include <linux/usb.h>
 12
 13#include <net/bluetooth/bluetooth.h>
 14#include <net/bluetooth/hci_core.h>
 15
 16#include "btrtl.h"
 17
 18#define VERSION "0.1"
 19
 20#define RTL_EPATCH_SIGNATURE	"Realtech"
 21#define RTL_ROM_LMP_8723A	0x1200
 22#define RTL_ROM_LMP_8723B	0x8723
 23#define RTL_ROM_LMP_8821A	0x8821
 24#define RTL_ROM_LMP_8761A	0x8761
 25#define RTL_ROM_LMP_8822B	0x8822
 26#define RTL_ROM_LMP_8852A	0x8852
 27#define RTL_CONFIG_MAGIC	0x8723ab55
 28
 29#define IC_MATCH_FL_LMPSUBV	(1 << 0)
 30#define IC_MATCH_FL_HCIREV	(1 << 1)
 31#define IC_MATCH_FL_HCIVER	(1 << 2)
 32#define IC_MATCH_FL_HCIBUS	(1 << 3)
 33#define IC_INFO(lmps, hcir, hciv, bus) \
 34	.match_flags = IC_MATCH_FL_LMPSUBV | IC_MATCH_FL_HCIREV | \
 35		       IC_MATCH_FL_HCIVER | IC_MATCH_FL_HCIBUS, \
 36	.lmp_subver = (lmps), \
 37	.hci_rev = (hcir), \
 38	.hci_ver = (hciv), \
 39	.hci_bus = (bus)
 40
 41enum btrtl_chip_id {
 42	CHIP_ID_8723A,
 43	CHIP_ID_8723B,
 44	CHIP_ID_8821A,
 45	CHIP_ID_8761A,
 46	CHIP_ID_8822B = 8,
 47	CHIP_ID_8723D,
 48	CHIP_ID_8821C,
 49	CHIP_ID_8822C = 13,
 50	CHIP_ID_8761B,
 51	CHIP_ID_8852A = 18,
 
 
 52};
 53
 54struct id_table {
 55	__u16 match_flags;
 56	__u16 lmp_subver;
 57	__u16 hci_rev;
 58	__u8 hci_ver;
 59	__u8 hci_bus;
 60	bool config_needed;
 61	bool has_rom_version;
 
 62	char *fw_name;
 63	char *cfg_name;
 64};
 65
 66struct btrtl_device_info {
 67	const struct id_table *ic_info;
 68	u8 rom_version;
 69	u8 *fw_data;
 70	int fw_len;
 71	u8 *cfg_data;
 72	int cfg_len;
 73	bool drop_fw;
 74	int project_id;
 75};
 76
 77static const struct id_table ic_id_table[] = {
 78	/* 8723A */
 79	{ IC_INFO(RTL_ROM_LMP_8723A, 0xb, 0x6, HCI_USB),
 80	  .config_needed = false,
 81	  .has_rom_version = false,
 82	  .fw_name = "rtl_bt/rtl8723a_fw.bin",
 83	  .cfg_name = NULL },
 84
 85	/* 8723BS */
 86	{ IC_INFO(RTL_ROM_LMP_8723B, 0xb, 0x6, HCI_UART),
 87	  .config_needed = true,
 88	  .has_rom_version = true,
 89	  .fw_name  = "rtl_bt/rtl8723bs_fw.bin",
 90	  .cfg_name = "rtl_bt/rtl8723bs_config" },
 91
 92	/* 8723B */
 93	{ IC_INFO(RTL_ROM_LMP_8723B, 0xb, 0x6, HCI_USB),
 94	  .config_needed = false,
 95	  .has_rom_version = true,
 96	  .fw_name  = "rtl_bt/rtl8723b_fw.bin",
 97	  .cfg_name = "rtl_bt/rtl8723b_config" },
 98
 99	/* 8723D */
100	{ IC_INFO(RTL_ROM_LMP_8723B, 0xd, 0x8, HCI_USB),
101	  .config_needed = true,
102	  .has_rom_version = true,
103	  .fw_name  = "rtl_bt/rtl8723d_fw.bin",
104	  .cfg_name = "rtl_bt/rtl8723d_config" },
105
106	/* 8723DS */
107	{ IC_INFO(RTL_ROM_LMP_8723B, 0xd, 0x8, HCI_UART),
108	  .config_needed = true,
109	  .has_rom_version = true,
110	  .fw_name  = "rtl_bt/rtl8723ds_fw.bin",
111	  .cfg_name = "rtl_bt/rtl8723ds_config" },
112
113	/* 8821A */
114	{ IC_INFO(RTL_ROM_LMP_8821A, 0xa, 0x6, HCI_USB),
115	  .config_needed = false,
116	  .has_rom_version = true,
117	  .fw_name  = "rtl_bt/rtl8821a_fw.bin",
118	  .cfg_name = "rtl_bt/rtl8821a_config" },
119
120	/* 8821C */
121	{ IC_INFO(RTL_ROM_LMP_8821A, 0xc, 0x8, HCI_USB),
122	  .config_needed = false,
123	  .has_rom_version = true,
 
124	  .fw_name  = "rtl_bt/rtl8821c_fw.bin",
125	  .cfg_name = "rtl_bt/rtl8821c_config" },
126
127	/* 8761A */
128	{ IC_INFO(RTL_ROM_LMP_8761A, 0xa, 0x6, HCI_USB),
129	  .config_needed = false,
130	  .has_rom_version = true,
131	  .fw_name  = "rtl_bt/rtl8761a_fw.bin",
132	  .cfg_name = "rtl_bt/rtl8761a_config" },
133
134	/* 8761B */
135	{ IC_INFO(RTL_ROM_LMP_8761A, 0xb, 0xa, HCI_UART),
136	  .config_needed = false,
137	  .has_rom_version = true,
 
138	  .fw_name  = "rtl_bt/rtl8761b_fw.bin",
139	  .cfg_name = "rtl_bt/rtl8761b_config" },
140
141	/* 8761BU */
142	{ IC_INFO(RTL_ROM_LMP_8761A, 0xb, 0xa, HCI_USB),
143	  .config_needed = false,
144	  .has_rom_version = true,
145	  .fw_name  = "rtl_bt/rtl8761bu_fw.bin",
146	  .cfg_name = "rtl_bt/rtl8761bu_config" },
147
148	/* 8822C with UART interface */
 
 
 
 
 
 
 
 
149	{ IC_INFO(RTL_ROM_LMP_8822B, 0xc, 0xa, HCI_UART),
150	  .config_needed = true,
151	  .has_rom_version = true,
 
152	  .fw_name  = "rtl_bt/rtl8822cs_fw.bin",
153	  .cfg_name = "rtl_bt/rtl8822cs_config" },
154
155	/* 8822C with USB interface */
156	{ IC_INFO(RTL_ROM_LMP_8822B, 0xc, 0xa, HCI_USB),
157	  .config_needed = false,
158	  .has_rom_version = true,
 
159	  .fw_name  = "rtl_bt/rtl8822cu_fw.bin",
160	  .cfg_name = "rtl_bt/rtl8822cu_config" },
161
162	/* 8822B */
163	{ IC_INFO(RTL_ROM_LMP_8822B, 0xb, 0x7, HCI_USB),
164	  .config_needed = true,
165	  .has_rom_version = true,
 
166	  .fw_name  = "rtl_bt/rtl8822b_fw.bin",
167	  .cfg_name = "rtl_bt/rtl8822b_config" },
168
169	/* 8852A */
170	{ IC_INFO(RTL_ROM_LMP_8852A, 0xa, 0xb, HCI_USB),
171	  .config_needed = false,
172	  .has_rom_version = true,
 
173	  .fw_name  = "rtl_bt/rtl8852au_fw.bin",
174	  .cfg_name = "rtl_bt/rtl8852au_config" },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175	};
176
177static const struct id_table *btrtl_match_ic(u16 lmp_subver, u16 hci_rev,
178					     u8 hci_ver, u8 hci_bus)
179{
180	int i;
181
182	for (i = 0; i < ARRAY_SIZE(ic_id_table); i++) {
183		if ((ic_id_table[i].match_flags & IC_MATCH_FL_LMPSUBV) &&
184		    (ic_id_table[i].lmp_subver != lmp_subver))
185			continue;
186		if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIREV) &&
187		    (ic_id_table[i].hci_rev != hci_rev))
188			continue;
189		if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIVER) &&
190		    (ic_id_table[i].hci_ver != hci_ver))
191			continue;
192		if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIBUS) &&
193		    (ic_id_table[i].hci_bus != hci_bus))
194			continue;
195
196		break;
197	}
198	if (i >= ARRAY_SIZE(ic_id_table))
199		return NULL;
200
201	return &ic_id_table[i];
202}
203
204static struct sk_buff *btrtl_read_local_version(struct hci_dev *hdev)
205{
206	struct sk_buff *skb;
207
208	skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
209			     HCI_INIT_TIMEOUT);
210	if (IS_ERR(skb)) {
211		rtl_dev_err(hdev, "HCI_OP_READ_LOCAL_VERSION failed (%ld)",
212			    PTR_ERR(skb));
213		return skb;
214	}
215
216	if (skb->len != sizeof(struct hci_rp_read_local_version)) {
217		rtl_dev_err(hdev, "HCI_OP_READ_LOCAL_VERSION event length mismatch");
218		kfree_skb(skb);
219		return ERR_PTR(-EIO);
220	}
221
222	return skb;
223}
224
225static int rtl_read_rom_version(struct hci_dev *hdev, u8 *version)
226{
227	struct rtl_rom_version_evt *rom_version;
228	struct sk_buff *skb;
229
230	/* Read RTL ROM version command */
231	skb = __hci_cmd_sync(hdev, 0xfc6d, 0, NULL, HCI_INIT_TIMEOUT);
232	if (IS_ERR(skb)) {
233		rtl_dev_err(hdev, "Read ROM version failed (%ld)",
234			    PTR_ERR(skb));
235		return PTR_ERR(skb);
236	}
237
238	if (skb->len != sizeof(*rom_version)) {
239		rtl_dev_err(hdev, "version event length mismatch");
240		kfree_skb(skb);
241		return -EIO;
242	}
243
244	rom_version = (struct rtl_rom_version_evt *)skb->data;
245	rtl_dev_info(hdev, "rom_version status=%x version=%x",
246		     rom_version->status, rom_version->version);
247
248	*version = rom_version->version;
249
250	kfree_skb(skb);
251	return 0;
252}
253
254static int rtlbt_parse_firmware(struct hci_dev *hdev,
255				struct btrtl_device_info *btrtl_dev,
256				unsigned char **_buf)
257{
258	static const u8 extension_sig[] = { 0x51, 0x04, 0xfd, 0x77 };
259	struct rtl_epatch_header *epatch_info;
260	unsigned char *buf;
261	int i, len;
262	size_t min_size;
263	u8 opcode, length, data;
264	int project_id = -1;
265	const unsigned char *fwptr, *chip_id_base;
266	const unsigned char *patch_length_base, *patch_offset_base;
267	u32 patch_offset = 0;
268	u16 patch_length, num_patches;
269	static const struct {
270		__u16 lmp_subver;
271		__u8 id;
272	} project_id_to_lmp_subver[] = {
273		{ RTL_ROM_LMP_8723A, 0 },
274		{ RTL_ROM_LMP_8723B, 1 },
275		{ RTL_ROM_LMP_8821A, 2 },
276		{ RTL_ROM_LMP_8761A, 3 },
277		{ RTL_ROM_LMP_8822B, 8 },
278		{ RTL_ROM_LMP_8723B, 9 },	/* 8723D */
279		{ RTL_ROM_LMP_8821A, 10 },	/* 8821C */
280		{ RTL_ROM_LMP_8822B, 13 },	/* 8822C */
281		{ RTL_ROM_LMP_8761A, 14 },	/* 8761B */
282		{ RTL_ROM_LMP_8852A, 18 },	/* 8852A */
 
 
283	};
284
285	min_size = sizeof(struct rtl_epatch_header) + sizeof(extension_sig) + 3;
286	if (btrtl_dev->fw_len < min_size)
287		return -EINVAL;
288
289	fwptr = btrtl_dev->fw_data + btrtl_dev->fw_len - sizeof(extension_sig);
290	if (memcmp(fwptr, extension_sig, sizeof(extension_sig)) != 0) {
291		rtl_dev_err(hdev, "extension section signature mismatch");
292		return -EINVAL;
293	}
294
295	/* Loop from the end of the firmware parsing instructions, until
296	 * we find an instruction that identifies the "project ID" for the
297	 * hardware supported by this firwmare file.
298	 * Once we have that, we double-check that that project_id is suitable
299	 * for the hardware we are working with.
300	 */
301	while (fwptr >= btrtl_dev->fw_data + (sizeof(*epatch_info) + 3)) {
302		opcode = *--fwptr;
303		length = *--fwptr;
304		data = *--fwptr;
305
306		BT_DBG("check op=%x len=%x data=%x", opcode, length, data);
307
308		if (opcode == 0xff) /* EOF */
309			break;
310
311		if (length == 0) {
312			rtl_dev_err(hdev, "found instruction with length 0");
313			return -EINVAL;
314		}
315
316		if (opcode == 0 && length == 1) {
317			project_id = data;
318			break;
319		}
320
321		fwptr -= length;
322	}
323
324	if (project_id < 0) {
325		rtl_dev_err(hdev, "failed to find version instruction");
326		return -EINVAL;
327	}
328
329	/* Find project_id in table */
330	for (i = 0; i < ARRAY_SIZE(project_id_to_lmp_subver); i++) {
331		if (project_id == project_id_to_lmp_subver[i].id) {
332			btrtl_dev->project_id = project_id;
333			break;
334		}
335	}
336
337	if (i >= ARRAY_SIZE(project_id_to_lmp_subver)) {
338		rtl_dev_err(hdev, "unknown project id %d", project_id);
339		return -EINVAL;
340	}
341
342	if (btrtl_dev->ic_info->lmp_subver !=
343				project_id_to_lmp_subver[i].lmp_subver) {
344		rtl_dev_err(hdev, "firmware is for %x but this is a %x",
345			    project_id_to_lmp_subver[i].lmp_subver,
346			    btrtl_dev->ic_info->lmp_subver);
347		return -EINVAL;
348	}
349
350	epatch_info = (struct rtl_epatch_header *)btrtl_dev->fw_data;
351	if (memcmp(epatch_info->signature, RTL_EPATCH_SIGNATURE, 8) != 0) {
352		rtl_dev_err(hdev, "bad EPATCH signature");
353		return -EINVAL;
354	}
355
356	num_patches = le16_to_cpu(epatch_info->num_patches);
357	BT_DBG("fw_version=%x, num_patches=%d",
358	       le32_to_cpu(epatch_info->fw_version), num_patches);
359
360	/* After the rtl_epatch_header there is a funky patch metadata section.
361	 * Assuming 2 patches, the layout is:
362	 * ChipID1 ChipID2 PatchLength1 PatchLength2 PatchOffset1 PatchOffset2
363	 *
364	 * Find the right patch for this chip.
365	 */
366	min_size += 8 * num_patches;
367	if (btrtl_dev->fw_len < min_size)
368		return -EINVAL;
369
370	chip_id_base = btrtl_dev->fw_data + sizeof(struct rtl_epatch_header);
371	patch_length_base = chip_id_base + (sizeof(u16) * num_patches);
372	patch_offset_base = patch_length_base + (sizeof(u16) * num_patches);
373	for (i = 0; i < num_patches; i++) {
374		u16 chip_id = get_unaligned_le16(chip_id_base +
375						 (i * sizeof(u16)));
376		if (chip_id == btrtl_dev->rom_version + 1) {
377			patch_length = get_unaligned_le16(patch_length_base +
378							  (i * sizeof(u16)));
379			patch_offset = get_unaligned_le32(patch_offset_base +
380							  (i * sizeof(u32)));
381			break;
382		}
383	}
384
385	if (!patch_offset) {
386		rtl_dev_err(hdev, "didn't find patch for chip id %d",
387			    btrtl_dev->rom_version);
388		return -EINVAL;
389	}
390
391	BT_DBG("length=%x offset=%x index %d", patch_length, patch_offset, i);
392	min_size = patch_offset + patch_length;
393	if (btrtl_dev->fw_len < min_size)
394		return -EINVAL;
395
396	/* Copy the firmware into a new buffer and write the version at
397	 * the end.
398	 */
399	len = patch_length;
400	buf = kvmalloc(patch_length, GFP_KERNEL);
401	if (!buf)
402		return -ENOMEM;
403
404	memcpy(buf, btrtl_dev->fw_data + patch_offset, patch_length - 4);
405	memcpy(buf + patch_length - 4, &epatch_info->fw_version, 4);
406
407	*_buf = buf;
408	return len;
409}
410
411static int rtl_download_firmware(struct hci_dev *hdev,
412				 const unsigned char *data, int fw_len)
413{
414	struct rtl_download_cmd *dl_cmd;
415	int frag_num = fw_len / RTL_FRAG_LEN + 1;
416	int frag_len = RTL_FRAG_LEN;
417	int ret = 0;
418	int i;
419	struct sk_buff *skb;
420	struct hci_rp_read_local_version *rp;
421
422	dl_cmd = kmalloc(sizeof(struct rtl_download_cmd), GFP_KERNEL);
423	if (!dl_cmd)
424		return -ENOMEM;
425
426	for (i = 0; i < frag_num; i++) {
427		struct sk_buff *skb;
428
429		BT_DBG("download fw (%d/%d)", i, frag_num);
430
431		if (i > 0x7f)
432			dl_cmd->index = (i & 0x7f) + 1;
433		else
434			dl_cmd->index = i;
435
436		if (i == (frag_num - 1)) {
437			dl_cmd->index |= 0x80; /* data end */
438			frag_len = fw_len % RTL_FRAG_LEN;
439		}
440		memcpy(dl_cmd->data, data, frag_len);
441
442		/* Send download command */
443		skb = __hci_cmd_sync(hdev, 0xfc20, frag_len + 1, dl_cmd,
444				     HCI_INIT_TIMEOUT);
445		if (IS_ERR(skb)) {
446			rtl_dev_err(hdev, "download fw command failed (%ld)",
447				    PTR_ERR(skb));
448			ret = PTR_ERR(skb);
449			goto out;
450		}
451
452		if (skb->len != sizeof(struct rtl_download_response)) {
453			rtl_dev_err(hdev, "download fw event length mismatch");
454			kfree_skb(skb);
455			ret = -EIO;
456			goto out;
457		}
458
459		kfree_skb(skb);
460		data += RTL_FRAG_LEN;
461	}
462
463	skb = btrtl_read_local_version(hdev);
464	if (IS_ERR(skb)) {
465		ret = PTR_ERR(skb);
466		rtl_dev_err(hdev, "read local version failed");
467		goto out;
468	}
469
470	rp = (struct hci_rp_read_local_version *)skb->data;
471	rtl_dev_info(hdev, "fw version 0x%04x%04x",
472		     __le16_to_cpu(rp->hci_rev), __le16_to_cpu(rp->lmp_subver));
473	kfree_skb(skb);
474
475out:
476	kfree(dl_cmd);
477	return ret;
478}
479
480static int rtl_load_file(struct hci_dev *hdev, const char *name, u8 **buff)
481{
482	const struct firmware *fw;
483	int ret;
484
485	rtl_dev_info(hdev, "loading %s", name);
486	ret = request_firmware(&fw, name, &hdev->dev);
487	if (ret < 0)
488		return ret;
489	ret = fw->size;
490	*buff = kvmalloc(fw->size, GFP_KERNEL);
491	if (*buff)
492		memcpy(*buff, fw->data, ret);
493	else
494		ret = -ENOMEM;
495
496	release_firmware(fw);
497
498	return ret;
499}
500
501static int btrtl_setup_rtl8723a(struct hci_dev *hdev,
502				struct btrtl_device_info *btrtl_dev)
503{
504	if (btrtl_dev->fw_len < 8)
505		return -EINVAL;
506
507	/* Check that the firmware doesn't have the epatch signature
508	 * (which is only for RTL8723B and newer).
509	 */
510	if (!memcmp(btrtl_dev->fw_data, RTL_EPATCH_SIGNATURE, 8)) {
511		rtl_dev_err(hdev, "unexpected EPATCH signature!");
512		return -EINVAL;
513	}
514
515	return rtl_download_firmware(hdev, btrtl_dev->fw_data,
516				     btrtl_dev->fw_len);
517}
518
519static int btrtl_setup_rtl8723b(struct hci_dev *hdev,
520				struct btrtl_device_info *btrtl_dev)
521{
522	unsigned char *fw_data = NULL;
523	int ret;
524	u8 *tbuff;
525
526	ret = rtlbt_parse_firmware(hdev, btrtl_dev, &fw_data);
527	if (ret < 0)
528		goto out;
529
530	if (btrtl_dev->cfg_len > 0) {
531		tbuff = kvzalloc(ret + btrtl_dev->cfg_len, GFP_KERNEL);
532		if (!tbuff) {
533			ret = -ENOMEM;
534			goto out;
535		}
536
537		memcpy(tbuff, fw_data, ret);
538		kvfree(fw_data);
539
540		memcpy(tbuff + ret, btrtl_dev->cfg_data, btrtl_dev->cfg_len);
541		ret += btrtl_dev->cfg_len;
542
543		fw_data = tbuff;
544	}
545
546	rtl_dev_info(hdev, "cfg_sz %d, total sz %d", btrtl_dev->cfg_len, ret);
547
548	ret = rtl_download_firmware(hdev, fw_data, ret);
549
550out:
551	kvfree(fw_data);
552	return ret;
553}
554
555void btrtl_free(struct btrtl_device_info *btrtl_dev)
556{
557	kvfree(btrtl_dev->fw_data);
558	kvfree(btrtl_dev->cfg_data);
559	kfree(btrtl_dev);
560}
561EXPORT_SYMBOL_GPL(btrtl_free);
562
563struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
564					   const char *postfix)
565{
566	struct btrtl_device_info *btrtl_dev;
567	struct sk_buff *skb;
568	struct hci_rp_read_local_version *resp;
569	char cfg_name[40];
570	u16 hci_rev, lmp_subver;
571	u8 hci_ver;
572	int ret;
573	u16 opcode;
574	u8 cmd[2];
575
576	btrtl_dev = kzalloc(sizeof(*btrtl_dev), GFP_KERNEL);
577	if (!btrtl_dev) {
578		ret = -ENOMEM;
579		goto err_alloc;
580	}
581
582	skb = btrtl_read_local_version(hdev);
583	if (IS_ERR(skb)) {
584		ret = PTR_ERR(skb);
585		goto err_free;
586	}
587
588	resp = (struct hci_rp_read_local_version *)skb->data;
589	rtl_dev_info(hdev, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x",
590		     resp->hci_ver, resp->hci_rev,
591		     resp->lmp_ver, resp->lmp_subver);
592
593	hci_ver = resp->hci_ver;
594	hci_rev = le16_to_cpu(resp->hci_rev);
595	lmp_subver = le16_to_cpu(resp->lmp_subver);
596
597	if (resp->hci_ver == 0x8 && le16_to_cpu(resp->hci_rev) == 0x826c &&
598	    resp->lmp_ver == 0x8 && le16_to_cpu(resp->lmp_subver) == 0xa99e)
 
 
599		btrtl_dev->drop_fw = true;
600
601	if (btrtl_dev->drop_fw) {
602		opcode = hci_opcode_pack(0x3f, 0x66);
603		cmd[0] = opcode & 0xff;
604		cmd[1] = opcode >> 8;
605
606		skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
607		if (!skb)
608			goto out_free;
609
610		skb_put_data(skb, cmd, sizeof(cmd));
611		hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
612
613		hdev->send(hdev, skb);
614
615		/* Ensure the above vendor command is sent to controller and
616		 * process has done.
617		 */
618		msleep(200);
619
620		/* Read the local version again. Expect to have the vanilla
621		 * version as cold boot.
622		 */
623		skb = btrtl_read_local_version(hdev);
624		if (IS_ERR(skb)) {
625			ret = PTR_ERR(skb);
626			goto err_free;
627		}
628
629		resp = (struct hci_rp_read_local_version *)skb->data;
630		rtl_dev_info(hdev, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x",
631			     resp->hci_ver, resp->hci_rev,
632			     resp->lmp_ver, resp->lmp_subver);
633
634		hci_ver = resp->hci_ver;
635		hci_rev = le16_to_cpu(resp->hci_rev);
636		lmp_subver = le16_to_cpu(resp->lmp_subver);
 
 
 
637	}
638out_free:
639	kfree_skb(skb);
640
641	btrtl_dev->ic_info = btrtl_match_ic(lmp_subver, hci_rev, hci_ver,
642					    hdev->bus);
643
644	if (!btrtl_dev->ic_info) {
645		rtl_dev_info(hdev, "unknown IC info, lmp subver %04x, hci rev %04x, hci ver %04x",
646			    lmp_subver, hci_rev, hci_ver);
647		return btrtl_dev;
648	}
649
650	if (btrtl_dev->ic_info->has_rom_version) {
651		ret = rtl_read_rom_version(hdev, &btrtl_dev->rom_version);
652		if (ret)
653			goto err_free;
654	}
655
656	btrtl_dev->fw_len = rtl_load_file(hdev, btrtl_dev->ic_info->fw_name,
657					  &btrtl_dev->fw_data);
658	if (btrtl_dev->fw_len < 0) {
659		rtl_dev_err(hdev, "firmware file %s not found",
660			    btrtl_dev->ic_info->fw_name);
661		ret = btrtl_dev->fw_len;
662		goto err_free;
663	}
664
665	if (btrtl_dev->ic_info->cfg_name) {
666		if (postfix) {
667			snprintf(cfg_name, sizeof(cfg_name), "%s-%s.bin",
668				 btrtl_dev->ic_info->cfg_name, postfix);
669		} else {
670			snprintf(cfg_name, sizeof(cfg_name), "%s.bin",
671				 btrtl_dev->ic_info->cfg_name);
672		}
673		btrtl_dev->cfg_len = rtl_load_file(hdev, cfg_name,
674						   &btrtl_dev->cfg_data);
675		if (btrtl_dev->ic_info->config_needed &&
676		    btrtl_dev->cfg_len <= 0) {
677			rtl_dev_err(hdev, "mandatory config file %s not found",
678				    btrtl_dev->ic_info->cfg_name);
679			ret = btrtl_dev->cfg_len;
680			goto err_free;
681		}
682	}
683
684	/* RTL8822CE supports the Microsoft vendor extension and uses 0xFCF0
685	 * for VsMsftOpCode.
686	 */
687	if (lmp_subver == RTL_ROM_LMP_8822B)
688		hci_set_msft_opcode(hdev, 0xFCF0);
689
690	return btrtl_dev;
691
692err_free:
693	btrtl_free(btrtl_dev);
694err_alloc:
695	return ERR_PTR(ret);
696}
697EXPORT_SYMBOL_GPL(btrtl_initialize);
698
699int btrtl_download_firmware(struct hci_dev *hdev,
700			    struct btrtl_device_info *btrtl_dev)
701{
702	/* Match a set of subver values that correspond to stock firmware,
703	 * which is not compatible with standard btusb.
704	 * If matched, upload an alternative firmware that does conform to
705	 * standard btusb. Once that firmware is uploaded, the subver changes
706	 * to a different value.
707	 */
708	if (!btrtl_dev->ic_info) {
709		rtl_dev_info(hdev, "assuming no firmware upload needed");
710		return 0;
711	}
712
713	switch (btrtl_dev->ic_info->lmp_subver) {
714	case RTL_ROM_LMP_8723A:
715		return btrtl_setup_rtl8723a(hdev, btrtl_dev);
716	case RTL_ROM_LMP_8723B:
717	case RTL_ROM_LMP_8821A:
718	case RTL_ROM_LMP_8761A:
719	case RTL_ROM_LMP_8822B:
720	case RTL_ROM_LMP_8852A:
721		return btrtl_setup_rtl8723b(hdev, btrtl_dev);
722	default:
723		rtl_dev_info(hdev, "assuming no firmware upload needed");
724		return 0;
725	}
726}
727EXPORT_SYMBOL_GPL(btrtl_download_firmware);
728
729void btrtl_set_quirks(struct hci_dev *hdev, struct btrtl_device_info *btrtl_dev)
730{
731	/* Enable controller to do both LE scan and BR/EDR inquiry
732	 * simultaneously.
733	 */
734	set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
735
736	/* Enable central-peripheral role (able to create new connections with
737	 * an existing connection in slave role).
738	 */
739	/* Enable WBS supported for the specific Realtek devices. */
740	switch (btrtl_dev->project_id) {
741	case CHIP_ID_8822C:
742	case CHIP_ID_8852A:
 
 
743		set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
744		set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks);
 
 
 
 
 
 
 
 
745		break;
746	default:
747		rtl_dev_dbg(hdev, "Central-peripheral role not enabled.");
748		rtl_dev_dbg(hdev, "WBS supported not enabled.");
749		break;
750	}
751}
752EXPORT_SYMBOL_GPL(btrtl_set_quirks);
753
754int btrtl_setup_realtek(struct hci_dev *hdev)
755{
756	struct btrtl_device_info *btrtl_dev;
757	int ret;
758
759	btrtl_dev = btrtl_initialize(hdev, NULL);
760	if (IS_ERR(btrtl_dev))
761		return PTR_ERR(btrtl_dev);
762
763	ret = btrtl_download_firmware(hdev, btrtl_dev);
764
765	btrtl_set_quirks(hdev, btrtl_dev);
766
767	btrtl_free(btrtl_dev);
768	return ret;
769}
770EXPORT_SYMBOL_GPL(btrtl_setup_realtek);
771
772int btrtl_shutdown_realtek(struct hci_dev *hdev)
773{
774	struct sk_buff *skb;
775	int ret;
776
777	/* According to the vendor driver, BT must be reset on close to avoid
778	 * firmware crash.
779	 */
780	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
781	if (IS_ERR(skb)) {
782		ret = PTR_ERR(skb);
783		bt_dev_err(hdev, "HCI reset during shutdown failed");
784		return ret;
785	}
786	kfree_skb(skb);
787
788	return 0;
789}
790EXPORT_SYMBOL_GPL(btrtl_shutdown_realtek);
791
792static unsigned int btrtl_convert_baudrate(u32 device_baudrate)
793{
794	switch (device_baudrate) {
795	case 0x0252a00a:
796		return 230400;
797
798	case 0x05f75004:
799		return 921600;
800
801	case 0x00005004:
802		return 1000000;
803
804	case 0x04928002:
805	case 0x01128002:
806		return 1500000;
807
808	case 0x00005002:
809		return 2000000;
810
811	case 0x0000b001:
812		return 2500000;
813
814	case 0x04928001:
815		return 3000000;
816
817	case 0x052a6001:
818		return 3500000;
819
820	case 0x00005001:
821		return 4000000;
822
823	case 0x0252c014:
824	default:
825		return 115200;
826	}
827}
828
829int btrtl_get_uart_settings(struct hci_dev *hdev,
830			    struct btrtl_device_info *btrtl_dev,
831			    unsigned int *controller_baudrate,
832			    u32 *device_baudrate, bool *flow_control)
833{
834	struct rtl_vendor_config *config;
835	struct rtl_vendor_config_entry *entry;
836	int i, total_data_len;
837	bool found = false;
838
839	total_data_len = btrtl_dev->cfg_len - sizeof(*config);
840	if (total_data_len <= 0) {
841		rtl_dev_warn(hdev, "no config loaded");
842		return -EINVAL;
843	}
844
845	config = (struct rtl_vendor_config *)btrtl_dev->cfg_data;
846	if (le32_to_cpu(config->signature) != RTL_CONFIG_MAGIC) {
847		rtl_dev_err(hdev, "invalid config magic");
848		return -EINVAL;
849	}
850
851	if (total_data_len < le16_to_cpu(config->total_len)) {
852		rtl_dev_err(hdev, "config is too short");
853		return -EINVAL;
854	}
855
856	for (i = 0; i < total_data_len; ) {
857		entry = ((void *)config->entry) + i;
858
859		switch (le16_to_cpu(entry->offset)) {
860		case 0xc:
861			if (entry->len < sizeof(*device_baudrate)) {
862				rtl_dev_err(hdev, "invalid UART config entry");
863				return -EINVAL;
864			}
865
866			*device_baudrate = get_unaligned_le32(entry->data);
867			*controller_baudrate = btrtl_convert_baudrate(
868							*device_baudrate);
869
870			if (entry->len >= 13)
871				*flow_control = !!(entry->data[12] & BIT(2));
872			else
873				*flow_control = false;
874
875			found = true;
876			break;
877
878		default:
879			rtl_dev_dbg(hdev, "skipping config entry 0x%x (len %u)",
880				   le16_to_cpu(entry->offset), entry->len);
881			break;
882		}
883
884		i += sizeof(*entry) + entry->len;
885	}
886
887	if (!found) {
888		rtl_dev_err(hdev, "no UART config entry found");
889		return -ENOENT;
890	}
891
892	rtl_dev_dbg(hdev, "device baudrate = 0x%08x", *device_baudrate);
893	rtl_dev_dbg(hdev, "controller baudrate = %u", *controller_baudrate);
894	rtl_dev_dbg(hdev, "flow control %d", *flow_control);
895
896	return 0;
897}
898EXPORT_SYMBOL_GPL(btrtl_get_uart_settings);
899
900MODULE_AUTHOR("Daniel Drake <drake@endlessm.com>");
901MODULE_DESCRIPTION("Bluetooth support for Realtek devices ver " VERSION);
902MODULE_VERSION(VERSION);
903MODULE_LICENSE("GPL");
904MODULE_FIRMWARE("rtl_bt/rtl8723a_fw.bin");
905MODULE_FIRMWARE("rtl_bt/rtl8723b_fw.bin");
906MODULE_FIRMWARE("rtl_bt/rtl8723b_config.bin");
907MODULE_FIRMWARE("rtl_bt/rtl8723bs_fw.bin");
908MODULE_FIRMWARE("rtl_bt/rtl8723bs_config.bin");
909MODULE_FIRMWARE("rtl_bt/rtl8723ds_fw.bin");
910MODULE_FIRMWARE("rtl_bt/rtl8723ds_config.bin");
911MODULE_FIRMWARE("rtl_bt/rtl8761a_fw.bin");
912MODULE_FIRMWARE("rtl_bt/rtl8761a_config.bin");
913MODULE_FIRMWARE("rtl_bt/rtl8821a_fw.bin");
914MODULE_FIRMWARE("rtl_bt/rtl8821a_config.bin");
915MODULE_FIRMWARE("rtl_bt/rtl8822b_fw.bin");
916MODULE_FIRMWARE("rtl_bt/rtl8822b_config.bin");
917MODULE_FIRMWARE("rtl_bt/rtl8852au_fw.bin");
918MODULE_FIRMWARE("rtl_bt/rtl8852au_config.bin");