1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Bluetooth support for Realtek devices
5 * Copyright (C) 2015 Endless Mobile, Inc.
8 #include <linux/module.h>
9 #include <linux/firmware.h>
10 #include <asm/unaligned.h>
11 #include <linux/usb.h>
13 #include <net/bluetooth/bluetooth.h>
14 #include <net/bluetooth/hci_core.h>
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
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), \
53 struct btrtl_device_info
{
54 const struct id_table
*ic_info
;
63 static const struct id_table ic_id_table
[] = {
65 { IC_INFO(RTL_ROM_LMP_8723A
, 0xb, 0x6, HCI_USB
),
66 .config_needed
= false,
67 .has_rom_version
= false,
68 .fw_name
= "rtl_bt/rtl8723a_fw.bin",
72 { IC_INFO(RTL_ROM_LMP_8723B
, 0xb, 0x6, HCI_UART
),
73 .config_needed
= true,
74 .has_rom_version
= true,
75 .fw_name
= "rtl_bt/rtl8723bs_fw.bin",
76 .cfg_name
= "rtl_bt/rtl8723bs_config" },
79 { IC_INFO(RTL_ROM_LMP_8723B
, 0xb, 0x6, HCI_USB
),
80 .config_needed
= false,
81 .has_rom_version
= true,
82 .fw_name
= "rtl_bt/rtl8723b_fw.bin",
83 .cfg_name
= "rtl_bt/rtl8723b_config" },
86 { IC_INFO(RTL_ROM_LMP_8723B
, 0xd, 0x8, HCI_USB
),
87 .config_needed
= true,
88 .has_rom_version
= true,
89 .fw_name
= "rtl_bt/rtl8723d_fw.bin",
90 .cfg_name
= "rtl_bt/rtl8723d_config" },
93 { IC_INFO(RTL_ROM_LMP_8723B
, 0xd, 0x8, HCI_UART
),
94 .config_needed
= true,
95 .has_rom_version
= true,
96 .fw_name
= "rtl_bt/rtl8723ds_fw.bin",
97 .cfg_name
= "rtl_bt/rtl8723ds_config" },
100 { IC_INFO(RTL_ROM_LMP_8821A
, 0xa, 0x6, HCI_USB
),
101 .config_needed
= false,
102 .has_rom_version
= true,
103 .fw_name
= "rtl_bt/rtl8821a_fw.bin",
104 .cfg_name
= "rtl_bt/rtl8821a_config" },
107 { IC_INFO(RTL_ROM_LMP_8821A
, 0xc, 0x8, HCI_USB
),
108 .config_needed
= false,
109 .has_rom_version
= true,
110 .fw_name
= "rtl_bt/rtl8821c_fw.bin",
111 .cfg_name
= "rtl_bt/rtl8821c_config" },
114 { IC_INFO(RTL_ROM_LMP_8761A
, 0xa, 0x6, HCI_USB
),
115 .config_needed
= false,
116 .has_rom_version
= true,
117 .fw_name
= "rtl_bt/rtl8761a_fw.bin",
118 .cfg_name
= "rtl_bt/rtl8761a_config" },
121 { IC_INFO(RTL_ROM_LMP_8761A
, 0xb, 0xa, HCI_USB
),
122 .config_needed
= false,
123 .has_rom_version
= true,
124 .fw_name
= "rtl_bt/rtl8761b_fw.bin",
125 .cfg_name
= "rtl_bt/rtl8761b_config" },
127 /* 8822C with UART interface */
128 { IC_INFO(RTL_ROM_LMP_8822B
, 0xc, 0xa, HCI_UART
),
129 .config_needed
= true,
130 .has_rom_version
= true,
131 .fw_name
= "rtl_bt/rtl8822cs_fw.bin",
132 .cfg_name
= "rtl_bt/rtl8822cs_config" },
134 /* 8822C with USB interface */
135 { IC_INFO(RTL_ROM_LMP_8822B
, 0xc, 0xa, HCI_USB
),
136 .config_needed
= false,
137 .has_rom_version
= true,
138 .fw_name
= "rtl_bt/rtl8822cu_fw.bin",
139 .cfg_name
= "rtl_bt/rtl8822cu_config" },
142 { IC_INFO(RTL_ROM_LMP_8822B
, 0xb, 0x7, HCI_USB
),
143 .config_needed
= true,
144 .has_rom_version
= true,
145 .fw_name
= "rtl_bt/rtl8822b_fw.bin",
146 .cfg_name
= "rtl_bt/rtl8822b_config" },
149 { IC_INFO(RTL_ROM_LMP_8852A
, 0xa, 0xb, HCI_USB
),
150 .config_needed
= false,
151 .has_rom_version
= true,
152 .fw_name
= "rtl_bt/rtl8852au_fw.bin",
153 .cfg_name
= "rtl_bt/rtl8852au_config" },
156 static const struct id_table
*btrtl_match_ic(u16 lmp_subver
, u16 hci_rev
,
157 u8 hci_ver
, u8 hci_bus
)
161 for (i
= 0; i
< ARRAY_SIZE(ic_id_table
); i
++) {
162 if ((ic_id_table
[i
].match_flags
& IC_MATCH_FL_LMPSUBV
) &&
163 (ic_id_table
[i
].lmp_subver
!= lmp_subver
))
165 if ((ic_id_table
[i
].match_flags
& IC_MATCH_FL_HCIREV
) &&
166 (ic_id_table
[i
].hci_rev
!= hci_rev
))
168 if ((ic_id_table
[i
].match_flags
& IC_MATCH_FL_HCIVER
) &&
169 (ic_id_table
[i
].hci_ver
!= hci_ver
))
171 if ((ic_id_table
[i
].match_flags
& IC_MATCH_FL_HCIBUS
) &&
172 (ic_id_table
[i
].hci_bus
!= hci_bus
))
177 if (i
>= ARRAY_SIZE(ic_id_table
))
180 return &ic_id_table
[i
];
183 static struct sk_buff
*btrtl_read_local_version(struct hci_dev
*hdev
)
187 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
190 rtl_dev_err(hdev
, "HCI_OP_READ_LOCAL_VERSION failed (%ld)",
195 if (skb
->len
!= sizeof(struct hci_rp_read_local_version
)) {
196 rtl_dev_err(hdev
, "HCI_OP_READ_LOCAL_VERSION event length mismatch");
198 return ERR_PTR(-EIO
);
204 static int rtl_read_rom_version(struct hci_dev
*hdev
, u8
*version
)
206 struct rtl_rom_version_evt
*rom_version
;
209 /* Read RTL ROM version command */
210 skb
= __hci_cmd_sync(hdev
, 0xfc6d, 0, NULL
, HCI_INIT_TIMEOUT
);
212 rtl_dev_err(hdev
, "Read ROM version failed (%ld)",
217 if (skb
->len
!= sizeof(*rom_version
)) {
218 rtl_dev_err(hdev
, "version event length mismatch");
223 rom_version
= (struct rtl_rom_version_evt
*)skb
->data
;
224 rtl_dev_info(hdev
, "rom_version status=%x version=%x",
225 rom_version
->status
, rom_version
->version
);
227 *version
= rom_version
->version
;
233 static int rtlbt_parse_firmware(struct hci_dev
*hdev
,
234 struct btrtl_device_info
*btrtl_dev
,
235 unsigned char **_buf
)
237 static const u8 extension_sig
[] = { 0x51, 0x04, 0xfd, 0x77 };
238 struct rtl_epatch_header
*epatch_info
;
242 u8 opcode
, length
, data
;
244 const unsigned char *fwptr
, *chip_id_base
;
245 const unsigned char *patch_length_base
, *patch_offset_base
;
246 u32 patch_offset
= 0;
247 u16 patch_length
, num_patches
;
248 static const struct {
251 } project_id_to_lmp_subver
[] = {
252 { RTL_ROM_LMP_8723A
, 0 },
253 { RTL_ROM_LMP_8723B
, 1 },
254 { RTL_ROM_LMP_8821A
, 2 },
255 { RTL_ROM_LMP_8761A
, 3 },
256 { RTL_ROM_LMP_8822B
, 8 },
257 { RTL_ROM_LMP_8723B
, 9 }, /* 8723D */
258 { RTL_ROM_LMP_8821A
, 10 }, /* 8821C */
259 { RTL_ROM_LMP_8822B
, 13 }, /* 8822C */
260 { RTL_ROM_LMP_8761A
, 14 }, /* 8761B */
261 { RTL_ROM_LMP_8852A
, 18 }, /* 8852A */
264 min_size
= sizeof(struct rtl_epatch_header
) + sizeof(extension_sig
) + 3;
265 if (btrtl_dev
->fw_len
< min_size
)
268 fwptr
= btrtl_dev
->fw_data
+ btrtl_dev
->fw_len
- sizeof(extension_sig
);
269 if (memcmp(fwptr
, extension_sig
, sizeof(extension_sig
)) != 0) {
270 rtl_dev_err(hdev
, "extension section signature mismatch");
274 /* Loop from the end of the firmware parsing instructions, until
275 * we find an instruction that identifies the "project ID" for the
276 * hardware supported by this firwmare file.
277 * Once we have that, we double-check that that project_id is suitable
278 * for the hardware we are working with.
280 while (fwptr
>= btrtl_dev
->fw_data
+ (sizeof(*epatch_info
) + 3)) {
285 BT_DBG("check op=%x len=%x data=%x", opcode
, length
, data
);
287 if (opcode
== 0xff) /* EOF */
291 rtl_dev_err(hdev
, "found instruction with length 0");
295 if (opcode
== 0 && length
== 1) {
303 if (project_id
< 0) {
304 rtl_dev_err(hdev
, "failed to find version instruction");
308 /* Find project_id in table */
309 for (i
= 0; i
< ARRAY_SIZE(project_id_to_lmp_subver
); i
++) {
310 if (project_id
== project_id_to_lmp_subver
[i
].id
)
314 if (i
>= ARRAY_SIZE(project_id_to_lmp_subver
)) {
315 rtl_dev_err(hdev
, "unknown project id %d", project_id
);
319 if (btrtl_dev
->ic_info
->lmp_subver
!=
320 project_id_to_lmp_subver
[i
].lmp_subver
) {
321 rtl_dev_err(hdev
, "firmware is for %x but this is a %x",
322 project_id_to_lmp_subver
[i
].lmp_subver
,
323 btrtl_dev
->ic_info
->lmp_subver
);
327 epatch_info
= (struct rtl_epatch_header
*)btrtl_dev
->fw_data
;
328 if (memcmp(epatch_info
->signature
, RTL_EPATCH_SIGNATURE
, 8) != 0) {
329 rtl_dev_err(hdev
, "bad EPATCH signature");
333 num_patches
= le16_to_cpu(epatch_info
->num_patches
);
334 BT_DBG("fw_version=%x, num_patches=%d",
335 le32_to_cpu(epatch_info
->fw_version
), num_patches
);
337 /* After the rtl_epatch_header there is a funky patch metadata section.
338 * Assuming 2 patches, the layout is:
339 * ChipID1 ChipID2 PatchLength1 PatchLength2 PatchOffset1 PatchOffset2
341 * Find the right patch for this chip.
343 min_size
+= 8 * num_patches
;
344 if (btrtl_dev
->fw_len
< min_size
)
347 chip_id_base
= btrtl_dev
->fw_data
+ sizeof(struct rtl_epatch_header
);
348 patch_length_base
= chip_id_base
+ (sizeof(u16
) * num_patches
);
349 patch_offset_base
= patch_length_base
+ (sizeof(u16
) * num_patches
);
350 for (i
= 0; i
< num_patches
; i
++) {
351 u16 chip_id
= get_unaligned_le16(chip_id_base
+
353 if (chip_id
== btrtl_dev
->rom_version
+ 1) {
354 patch_length
= get_unaligned_le16(patch_length_base
+
356 patch_offset
= get_unaligned_le32(patch_offset_base
+
363 rtl_dev_err(hdev
, "didn't find patch for chip id %d",
364 btrtl_dev
->rom_version
);
368 BT_DBG("length=%x offset=%x index %d", patch_length
, patch_offset
, i
);
369 min_size
= patch_offset
+ patch_length
;
370 if (btrtl_dev
->fw_len
< min_size
)
373 /* Copy the firmware into a new buffer and write the version at
377 buf
= kvmalloc(patch_length
, GFP_KERNEL
);
381 memcpy(buf
, btrtl_dev
->fw_data
+ patch_offset
, patch_length
- 4);
382 memcpy(buf
+ patch_length
- 4, &epatch_info
->fw_version
, 4);
388 static int rtl_download_firmware(struct hci_dev
*hdev
,
389 const unsigned char *data
, int fw_len
)
391 struct rtl_download_cmd
*dl_cmd
;
392 int frag_num
= fw_len
/ RTL_FRAG_LEN
+ 1;
393 int frag_len
= RTL_FRAG_LEN
;
397 struct hci_rp_read_local_version
*rp
;
399 dl_cmd
= kmalloc(sizeof(struct rtl_download_cmd
), GFP_KERNEL
);
403 for (i
= 0; i
< frag_num
; i
++) {
406 BT_DBG("download fw (%d/%d)", i
, frag_num
);
409 dl_cmd
->index
= (i
& 0x7f) + 1;
413 if (i
== (frag_num
- 1)) {
414 dl_cmd
->index
|= 0x80; /* data end */
415 frag_len
= fw_len
% RTL_FRAG_LEN
;
417 memcpy(dl_cmd
->data
, data
, frag_len
);
419 /* Send download command */
420 skb
= __hci_cmd_sync(hdev
, 0xfc20, frag_len
+ 1, dl_cmd
,
423 rtl_dev_err(hdev
, "download fw command failed (%ld)",
429 if (skb
->len
!= sizeof(struct rtl_download_response
)) {
430 rtl_dev_err(hdev
, "download fw event length mismatch");
437 data
+= RTL_FRAG_LEN
;
440 skb
= btrtl_read_local_version(hdev
);
443 rtl_dev_err(hdev
, "read local version failed");
447 rp
= (struct hci_rp_read_local_version
*)skb
->data
;
448 rtl_dev_info(hdev
, "fw version 0x%04x%04x",
449 __le16_to_cpu(rp
->hci_rev
), __le16_to_cpu(rp
->lmp_subver
));
457 static int rtl_load_file(struct hci_dev
*hdev
, const char *name
, u8
**buff
)
459 const struct firmware
*fw
;
462 rtl_dev_info(hdev
, "loading %s", name
);
463 ret
= request_firmware(&fw
, name
, &hdev
->dev
);
467 *buff
= kvmalloc(fw
->size
, GFP_KERNEL
);
469 memcpy(*buff
, fw
->data
, ret
);
473 release_firmware(fw
);
478 static int btrtl_setup_rtl8723a(struct hci_dev
*hdev
,
479 struct btrtl_device_info
*btrtl_dev
)
481 if (btrtl_dev
->fw_len
< 8)
484 /* Check that the firmware doesn't have the epatch signature
485 * (which is only for RTL8723B and newer).
487 if (!memcmp(btrtl_dev
->fw_data
, RTL_EPATCH_SIGNATURE
, 8)) {
488 rtl_dev_err(hdev
, "unexpected EPATCH signature!");
492 return rtl_download_firmware(hdev
, btrtl_dev
->fw_data
,
496 static int btrtl_setup_rtl8723b(struct hci_dev
*hdev
,
497 struct btrtl_device_info
*btrtl_dev
)
499 unsigned char *fw_data
= NULL
;
503 ret
= rtlbt_parse_firmware(hdev
, btrtl_dev
, &fw_data
);
507 if (btrtl_dev
->cfg_len
> 0) {
508 tbuff
= kvzalloc(ret
+ btrtl_dev
->cfg_len
, GFP_KERNEL
);
514 memcpy(tbuff
, fw_data
, ret
);
517 memcpy(tbuff
+ ret
, btrtl_dev
->cfg_data
, btrtl_dev
->cfg_len
);
518 ret
+= btrtl_dev
->cfg_len
;
523 rtl_dev_info(hdev
, "cfg_sz %d, total sz %d", btrtl_dev
->cfg_len
, ret
);
525 ret
= rtl_download_firmware(hdev
, fw_data
, ret
);
532 void btrtl_free(struct btrtl_device_info
*btrtl_dev
)
534 kvfree(btrtl_dev
->fw_data
);
535 kvfree(btrtl_dev
->cfg_data
);
538 EXPORT_SYMBOL_GPL(btrtl_free
);
540 struct btrtl_device_info
*btrtl_initialize(struct hci_dev
*hdev
,
543 struct btrtl_device_info
*btrtl_dev
;
545 struct hci_rp_read_local_version
*resp
;
547 u16 hci_rev
, lmp_subver
;
553 btrtl_dev
= kzalloc(sizeof(*btrtl_dev
), GFP_KERNEL
);
559 skb
= btrtl_read_local_version(hdev
);
565 resp
= (struct hci_rp_read_local_version
*)skb
->data
;
566 rtl_dev_info(hdev
, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x",
567 resp
->hci_ver
, resp
->hci_rev
,
568 resp
->lmp_ver
, resp
->lmp_subver
);
570 hci_ver
= resp
->hci_ver
;
571 hci_rev
= le16_to_cpu(resp
->hci_rev
);
572 lmp_subver
= le16_to_cpu(resp
->lmp_subver
);
574 if (resp
->hci_ver
== 0x8 && le16_to_cpu(resp
->hci_rev
) == 0x826c &&
575 resp
->lmp_ver
== 0x8 && le16_to_cpu(resp
->lmp_subver
) == 0xa99e)
576 btrtl_dev
->drop_fw
= true;
578 if (btrtl_dev
->drop_fw
) {
579 opcode
= hci_opcode_pack(0x3f, 0x66);
580 cmd
[0] = opcode
& 0xff;
581 cmd
[1] = opcode
>> 8;
583 skb
= bt_skb_alloc(sizeof(cmd
), GFP_KERNEL
);
587 skb_put_data(skb
, cmd
, sizeof(cmd
));
588 hci_skb_pkt_type(skb
) = HCI_COMMAND_PKT
;
590 hdev
->send(hdev
, skb
);
592 /* Ensure the above vendor command is sent to controller and
597 /* Read the local version again. Expect to have the vanilla
598 * version as cold boot.
600 skb
= btrtl_read_local_version(hdev
);
606 resp
= (struct hci_rp_read_local_version
*)skb
->data
;
607 rtl_dev_info(hdev
, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x",
608 resp
->hci_ver
, resp
->hci_rev
,
609 resp
->lmp_ver
, resp
->lmp_subver
);
611 hci_ver
= resp
->hci_ver
;
612 hci_rev
= le16_to_cpu(resp
->hci_rev
);
613 lmp_subver
= le16_to_cpu(resp
->lmp_subver
);
618 btrtl_dev
->ic_info
= btrtl_match_ic(lmp_subver
, hci_rev
, hci_ver
,
621 if (!btrtl_dev
->ic_info
) {
622 rtl_dev_info(hdev
, "unknown IC info, lmp subver %04x, hci rev %04x, hci ver %04x",
623 lmp_subver
, hci_rev
, hci_ver
);
627 if (btrtl_dev
->ic_info
->has_rom_version
) {
628 ret
= rtl_read_rom_version(hdev
, &btrtl_dev
->rom_version
);
633 btrtl_dev
->fw_len
= rtl_load_file(hdev
, btrtl_dev
->ic_info
->fw_name
,
634 &btrtl_dev
->fw_data
);
635 if (btrtl_dev
->fw_len
< 0) {
636 rtl_dev_err(hdev
, "firmware file %s not found",
637 btrtl_dev
->ic_info
->fw_name
);
638 ret
= btrtl_dev
->fw_len
;
642 if (btrtl_dev
->ic_info
->cfg_name
) {
644 snprintf(cfg_name
, sizeof(cfg_name
), "%s-%s.bin",
645 btrtl_dev
->ic_info
->cfg_name
, postfix
);
647 snprintf(cfg_name
, sizeof(cfg_name
), "%s.bin",
648 btrtl_dev
->ic_info
->cfg_name
);
650 btrtl_dev
->cfg_len
= rtl_load_file(hdev
, cfg_name
,
651 &btrtl_dev
->cfg_data
);
652 if (btrtl_dev
->ic_info
->config_needed
&&
653 btrtl_dev
->cfg_len
<= 0) {
654 rtl_dev_err(hdev
, "mandatory config file %s not found",
655 btrtl_dev
->ic_info
->cfg_name
);
656 ret
= btrtl_dev
->cfg_len
;
664 btrtl_free(btrtl_dev
);
668 EXPORT_SYMBOL_GPL(btrtl_initialize
);
670 int btrtl_download_firmware(struct hci_dev
*hdev
,
671 struct btrtl_device_info
*btrtl_dev
)
673 /* Match a set of subver values that correspond to stock firmware,
674 * which is not compatible with standard btusb.
675 * If matched, upload an alternative firmware that does conform to
676 * standard btusb. Once that firmware is uploaded, the subver changes
677 * to a different value.
679 if (!btrtl_dev
->ic_info
) {
680 rtl_dev_info(hdev
, "assuming no firmware upload needed");
684 switch (btrtl_dev
->ic_info
->lmp_subver
) {
685 case RTL_ROM_LMP_8723A
:
686 return btrtl_setup_rtl8723a(hdev
, btrtl_dev
);
687 case RTL_ROM_LMP_8723B
:
688 case RTL_ROM_LMP_8821A
:
689 case RTL_ROM_LMP_8761A
:
690 case RTL_ROM_LMP_8822B
:
691 case RTL_ROM_LMP_8852A
:
692 return btrtl_setup_rtl8723b(hdev
, btrtl_dev
);
694 rtl_dev_info(hdev
, "assuming no firmware upload needed");
698 EXPORT_SYMBOL_GPL(btrtl_download_firmware
);
700 int btrtl_setup_realtek(struct hci_dev
*hdev
)
702 struct btrtl_device_info
*btrtl_dev
;
705 btrtl_dev
= btrtl_initialize(hdev
, NULL
);
706 if (IS_ERR(btrtl_dev
))
707 return PTR_ERR(btrtl_dev
);
709 ret
= btrtl_download_firmware(hdev
, btrtl_dev
);
711 btrtl_free(btrtl_dev
);
713 /* Enable controller to do both LE scan and BR/EDR inquiry
716 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
720 EXPORT_SYMBOL_GPL(btrtl_setup_realtek
);
722 int btrtl_shutdown_realtek(struct hci_dev
*hdev
)
727 /* According to the vendor driver, BT must be reset on close to avoid
730 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
733 bt_dev_err(hdev
, "HCI reset during shutdown failed");
740 EXPORT_SYMBOL_GPL(btrtl_shutdown_realtek
);
742 static unsigned int btrtl_convert_baudrate(u32 device_baudrate
)
744 switch (device_baudrate
) {
779 int btrtl_get_uart_settings(struct hci_dev
*hdev
,
780 struct btrtl_device_info
*btrtl_dev
,
781 unsigned int *controller_baudrate
,
782 u32
*device_baudrate
, bool *flow_control
)
784 struct rtl_vendor_config
*config
;
785 struct rtl_vendor_config_entry
*entry
;
786 int i
, total_data_len
;
789 total_data_len
= btrtl_dev
->cfg_len
- sizeof(*config
);
790 if (total_data_len
<= 0) {
791 rtl_dev_warn(hdev
, "no config loaded");
795 config
= (struct rtl_vendor_config
*)btrtl_dev
->cfg_data
;
796 if (le32_to_cpu(config
->signature
) != RTL_CONFIG_MAGIC
) {
797 rtl_dev_err(hdev
, "invalid config magic");
801 if (total_data_len
< le16_to_cpu(config
->total_len
)) {
802 rtl_dev_err(hdev
, "config is too short");
806 for (i
= 0; i
< total_data_len
; ) {
807 entry
= ((void *)config
->entry
) + i
;
809 switch (le16_to_cpu(entry
->offset
)) {
811 if (entry
->len
< sizeof(*device_baudrate
)) {
812 rtl_dev_err(hdev
, "invalid UART config entry");
816 *device_baudrate
= get_unaligned_le32(entry
->data
);
817 *controller_baudrate
= btrtl_convert_baudrate(
820 if (entry
->len
>= 13)
821 *flow_control
= !!(entry
->data
[12] & BIT(2));
823 *flow_control
= false;
829 rtl_dev_dbg(hdev
, "skipping config entry 0x%x (len %u)",
830 le16_to_cpu(entry
->offset
), entry
->len
);
834 i
+= sizeof(*entry
) + entry
->len
;
838 rtl_dev_err(hdev
, "no UART config entry found");
842 rtl_dev_dbg(hdev
, "device baudrate = 0x%08x", *device_baudrate
);
843 rtl_dev_dbg(hdev
, "controller baudrate = %u", *controller_baudrate
);
844 rtl_dev_dbg(hdev
, "flow control %d", *flow_control
);
848 EXPORT_SYMBOL_GPL(btrtl_get_uart_settings
);
850 MODULE_AUTHOR("Daniel Drake <drake@endlessm.com>");
851 MODULE_DESCRIPTION("Bluetooth support for Realtek devices ver " VERSION
);
852 MODULE_VERSION(VERSION
);
853 MODULE_LICENSE("GPL");
854 MODULE_FIRMWARE("rtl_bt/rtl8723a_fw.bin");
855 MODULE_FIRMWARE("rtl_bt/rtl8723b_fw.bin");
856 MODULE_FIRMWARE("rtl_bt/rtl8723b_config.bin");
857 MODULE_FIRMWARE("rtl_bt/rtl8723bs_fw.bin");
858 MODULE_FIRMWARE("rtl_bt/rtl8723bs_config.bin");
859 MODULE_FIRMWARE("rtl_bt/rtl8723ds_fw.bin");
860 MODULE_FIRMWARE("rtl_bt/rtl8723ds_config.bin");
861 MODULE_FIRMWARE("rtl_bt/rtl8761a_fw.bin");
862 MODULE_FIRMWARE("rtl_bt/rtl8761a_config.bin");
863 MODULE_FIRMWARE("rtl_bt/rtl8821a_fw.bin");
864 MODULE_FIRMWARE("rtl_bt/rtl8821a_config.bin");
865 MODULE_FIRMWARE("rtl_bt/rtl8822b_fw.bin");
866 MODULE_FIRMWARE("rtl_bt/rtl8822b_config.bin");
867 MODULE_FIRMWARE("rtl_bt/rtl8852au_fw.bin");
868 MODULE_FIRMWARE("rtl_bt/rtl8852au_config.bin");