blob: a4f7cace66b067f987e7f90539fd04c52b09f34d [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Carlo Caionedb33c772015-05-14 10:49:09 +02002/*
3 * Bluetooth support for Realtek devices
4 *
5 * Copyright (C) 2015 Endless Mobile, Inc.
Carlo Caionedb33c772015-05-14 10:49:09 +02006 */
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"
Carlo Caionedb33c772015-05-14 10:49:09 +020021#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
Larry Finger1110a2d2016-09-09 10:02:05 -050025#define RTL_ROM_LMP_8822B 0x8822
Max Chou0d484db2020-11-10 11:38:37 +080026#define RTL_ROM_LMP_8852A 0x8852
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +020027#define RTL_CONFIG_MAGIC 0x8723ab55
Carlo Caionedb33c772015-05-14 10:49:09 +020028
Alex Lu907f8492018-02-11 12:24:33 -060029#define IC_MATCH_FL_LMPSUBV (1 << 0)
30#define IC_MATCH_FL_HCIREV (1 << 1)
Martin Blumenstinglc50903e2018-08-02 16:57:16 +020031#define IC_MATCH_FL_HCIVER (1 << 2)
32#define IC_MATCH_FL_HCIBUS (1 << 3)
Max Chou6f9ff242020-11-04 20:04:14 +080033#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, \
Alex Lu907f8492018-02-11 12:24:33 -060036 .lmp_subver = (lmps), \
Max Chou6f9ff242020-11-04 20:04:14 +080037 .hci_rev = (hcir), \
38 .hci_ver = (hciv), \
39 .hci_bus = (bus)
Alex Lu907f8492018-02-11 12:24:33 -060040
41struct id_table {
42 __u16 match_flags;
43 __u16 lmp_subver;
44 __u16 hci_rev;
Martin Blumenstinglc50903e2018-08-02 16:57:16 +020045 __u8 hci_ver;
46 __u8 hci_bus;
Alex Lu907f8492018-02-11 12:24:33 -060047 bool config_needed;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +020048 bool has_rom_version;
Alex Lu907f8492018-02-11 12:24:33 -060049 char *fw_name;
50 char *cfg_name;
51};
52
Martin Blumenstingl26503ad22018-08-02 16:57:13 +020053struct btrtl_device_info {
54 const struct id_table *ic_info;
55 u8 rom_version;
56 u8 *fw_data;
57 int fw_len;
58 u8 *cfg_data;
59 int cfg_len;
Kai-Heng Feng1996d9c2020-10-26 16:28:38 +080060 bool drop_fw;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +020061};
62
Alex Lu907f8492018-02-11 12:24:33 -060063static const struct id_table ic_id_table[] = {
Max Chou6f9ff242020-11-04 20:04:14 +080064 /* 8723A */
65 { IC_INFO(RTL_ROM_LMP_8723A, 0xb, 0x6, HCI_USB),
Martin Blumenstingl26503ad22018-08-02 16:57:13 +020066 .config_needed = false,
67 .has_rom_version = false,
68 .fw_name = "rtl_bt/rtl8723a_fw.bin",
69 .cfg_name = NULL },
70
Martin Blumenstinglc50903e2018-08-02 16:57:16 +020071 /* 8723BS */
Max Chou6f9ff242020-11-04 20:04:14 +080072 { IC_INFO(RTL_ROM_LMP_8723B, 0xb, 0x6, HCI_UART),
Martin Blumenstinglc50903e2018-08-02 16:57:16 +020073 .config_needed = true,
74 .has_rom_version = true,
75 .fw_name = "rtl_bt/rtl8723bs_fw.bin",
Hans de Goede1cc194c2018-08-02 16:57:17 +020076 .cfg_name = "rtl_bt/rtl8723bs_config" },
Martin Blumenstinglc50903e2018-08-02 16:57:16 +020077
Alex Lu907f8492018-02-11 12:24:33 -060078 /* 8723B */
Max Chou6f9ff242020-11-04 20:04:14 +080079 { IC_INFO(RTL_ROM_LMP_8723B, 0xb, 0x6, HCI_USB),
Alex Lu907f8492018-02-11 12:24:33 -060080 .config_needed = false,
Martin Blumenstingl26503ad22018-08-02 16:57:13 +020081 .has_rom_version = true,
Alex Lu907f8492018-02-11 12:24:33 -060082 .fw_name = "rtl_bt/rtl8723b_fw.bin",
Hans de Goede1cc194c2018-08-02 16:57:17 +020083 .cfg_name = "rtl_bt/rtl8723b_config" },
Alex Lu907f8492018-02-11 12:24:33 -060084
85 /* 8723D */
Max Chou6f9ff242020-11-04 20:04:14 +080086 { IC_INFO(RTL_ROM_LMP_8723B, 0xd, 0x8, HCI_USB),
Alex Lu907f8492018-02-11 12:24:33 -060087 .config_needed = true,
Martin Blumenstingl26503ad22018-08-02 16:57:13 +020088 .has_rom_version = true,
Alex Lu907f8492018-02-11 12:24:33 -060089 .fw_name = "rtl_bt/rtl8723d_fw.bin",
Hans de Goede1cc194c2018-08-02 16:57:17 +020090 .cfg_name = "rtl_bt/rtl8723d_config" },
Alex Lu907f8492018-02-11 12:24:33 -060091
Martin Blumenstinglc50903e2018-08-02 16:57:16 +020092 /* 8723DS */
Max Chou6f9ff242020-11-04 20:04:14 +080093 { IC_INFO(RTL_ROM_LMP_8723B, 0xd, 0x8, HCI_UART),
Martin Blumenstinglc50903e2018-08-02 16:57:16 +020094 .config_needed = true,
95 .has_rom_version = true,
96 .fw_name = "rtl_bt/rtl8723ds_fw.bin",
Hans de Goede1cc194c2018-08-02 16:57:17 +020097 .cfg_name = "rtl_bt/rtl8723ds_config" },
Martin Blumenstinglc50903e2018-08-02 16:57:16 +020098
Alex Lu907f8492018-02-11 12:24:33 -060099 /* 8821A */
Max Chou6f9ff242020-11-04 20:04:14 +0800100 { IC_INFO(RTL_ROM_LMP_8821A, 0xa, 0x6, HCI_USB),
Alex Lu907f8492018-02-11 12:24:33 -0600101 .config_needed = false,
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200102 .has_rom_version = true,
Alex Lu907f8492018-02-11 12:24:33 -0600103 .fw_name = "rtl_bt/rtl8821a_fw.bin",
Hans de Goede1cc194c2018-08-02 16:57:17 +0200104 .cfg_name = "rtl_bt/rtl8821a_config" },
Alex Lu907f8492018-02-11 12:24:33 -0600105
106 /* 8821C */
Max Chou6f9ff242020-11-04 20:04:14 +0800107 { IC_INFO(RTL_ROM_LMP_8821A, 0xc, 0x8, HCI_USB),
Alex Lu907f8492018-02-11 12:24:33 -0600108 .config_needed = false,
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200109 .has_rom_version = true,
Alex Lu907f8492018-02-11 12:24:33 -0600110 .fw_name = "rtl_bt/rtl8821c_fw.bin",
Hans de Goede1cc194c2018-08-02 16:57:17 +0200111 .cfg_name = "rtl_bt/rtl8821c_config" },
Alex Lu907f8492018-02-11 12:24:33 -0600112
113 /* 8761A */
Max Chou6f9ff242020-11-04 20:04:14 +0800114 { IC_INFO(RTL_ROM_LMP_8761A, 0xa, 0x6, HCI_USB),
Alex Lu907f8492018-02-11 12:24:33 -0600115 .config_needed = false,
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200116 .has_rom_version = true,
Alex Lu907f8492018-02-11 12:24:33 -0600117 .fw_name = "rtl_bt/rtl8761a_fw.bin",
Hans de Goede1cc194c2018-08-02 16:57:17 +0200118 .cfg_name = "rtl_bt/rtl8761a_config" },
Alex Lu907f8492018-02-11 12:24:33 -0600119
Ziqian SUN (Zamir)04896832020-04-11 09:34:27 +0800120 /* 8761B */
Max Chou6f9ff242020-11-04 20:04:14 +0800121 { IC_INFO(RTL_ROM_LMP_8761A, 0xb, 0xa, HCI_USB),
Ziqian SUN (Zamir)04896832020-04-11 09:34:27 +0800122 .config_needed = false,
123 .has_rom_version = true,
124 .fw_name = "rtl_bt/rtl8761b_fw.bin",
125 .cfg_name = "rtl_bt/rtl8761b_config" },
126
Max Chou848fc612020-02-17 16:14:55 +0800127 /* 8822C with UART interface */
Max Chou6f9ff242020-11-04 20:04:14 +0800128 { IC_INFO(RTL_ROM_LMP_8822B, 0xc, 0xa, HCI_UART),
Max Chou848fc612020-02-17 16:14:55 +0800129 .config_needed = true,
130 .has_rom_version = true,
131 .fw_name = "rtl_bt/rtl8822cs_fw.bin",
132 .cfg_name = "rtl_bt/rtl8822cs_config" },
133
Alex Lu8ecfdc92018-09-08 12:05:59 -0500134 /* 8822C with USB interface */
Max Chou6f9ff242020-11-04 20:04:14 +0800135 { IC_INFO(RTL_ROM_LMP_8822B, 0xc, 0xa, HCI_USB),
Alex Lu8ecfdc92018-09-08 12:05:59 -0500136 .config_needed = false,
137 .has_rom_version = true,
138 .fw_name = "rtl_bt/rtl8822cu_fw.bin",
139 .cfg_name = "rtl_bt/rtl8822cu_config" },
140
Alex Lu907f8492018-02-11 12:24:33 -0600141 /* 8822B */
Max Chou6f9ff242020-11-04 20:04:14 +0800142 { IC_INFO(RTL_ROM_LMP_8822B, 0xb, 0x7, HCI_USB),
Alex Lu907f8492018-02-11 12:24:33 -0600143 .config_needed = true,
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200144 .has_rom_version = true,
Alex Lu907f8492018-02-11 12:24:33 -0600145 .fw_name = "rtl_bt/rtl8822b_fw.bin",
Hans de Goede1cc194c2018-08-02 16:57:17 +0200146 .cfg_name = "rtl_bt/rtl8822b_config" },
Max Chou0d484db2020-11-10 11:38:37 +0800147
148 /* 8852A */
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" },
Alex Lu907f8492018-02-11 12:24:33 -0600154 };
155
Martin Blumenstinglc50903e2018-08-02 16:57:16 +0200156static const struct id_table *btrtl_match_ic(u16 lmp_subver, u16 hci_rev,
157 u8 hci_ver, u8 hci_bus)
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200158{
159 int i;
160
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))
164 continue;
165 if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIREV) &&
166 (ic_id_table[i].hci_rev != hci_rev))
167 continue;
Martin Blumenstinglc50903e2018-08-02 16:57:16 +0200168 if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIVER) &&
169 (ic_id_table[i].hci_ver != hci_ver))
170 continue;
171 if ((ic_id_table[i].match_flags & IC_MATCH_FL_HCIBUS) &&
172 (ic_id_table[i].hci_bus != hci_bus))
173 continue;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200174
175 break;
176 }
177 if (i >= ARRAY_SIZE(ic_id_table))
178 return NULL;
179
180 return &ic_id_table[i];
181}
182
Alex Lu240b64a2019-08-31 16:36:02 +0800183static struct sk_buff *btrtl_read_local_version(struct hci_dev *hdev)
184{
185 struct sk_buff *skb;
186
187 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
188 HCI_INIT_TIMEOUT);
189 if (IS_ERR(skb)) {
190 rtl_dev_err(hdev, "HCI_OP_READ_LOCAL_VERSION failed (%ld)",
191 PTR_ERR(skb));
192 return skb;
193 }
194
195 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
196 rtl_dev_err(hdev, "HCI_OP_READ_LOCAL_VERSION event length mismatch");
197 kfree_skb(skb);
198 return ERR_PTR(-EIO);
199 }
200
201 return skb;
202}
203
Carlo Caionedb33c772015-05-14 10:49:09 +0200204static int rtl_read_rom_version(struct hci_dev *hdev, u8 *version)
205{
206 struct rtl_rom_version_evt *rom_version;
207 struct sk_buff *skb;
208
209 /* Read RTL ROM version command */
210 skb = __hci_cmd_sync(hdev, 0xfc6d, 0, NULL, HCI_INIT_TIMEOUT);
211 if (IS_ERR(skb)) {
Alex Luf1300c02019-08-31 16:46:11 +0800212 rtl_dev_err(hdev, "Read ROM version failed (%ld)",
Hans de Goedea5c76e62018-08-02 16:57:14 +0200213 PTR_ERR(skb));
Carlo Caionedb33c772015-05-14 10:49:09 +0200214 return PTR_ERR(skb);
215 }
216
217 if (skb->len != sizeof(*rom_version)) {
Alex Luf1300c02019-08-31 16:46:11 +0800218 rtl_dev_err(hdev, "version event length mismatch");
Carlo Caionedb33c772015-05-14 10:49:09 +0200219 kfree_skb(skb);
220 return -EIO;
221 }
222
223 rom_version = (struct rtl_rom_version_evt *)skb->data;
Alex Luf1300c02019-08-31 16:46:11 +0800224 rtl_dev_info(hdev, "rom_version status=%x version=%x",
Hans de Goedea5c76e62018-08-02 16:57:14 +0200225 rom_version->status, rom_version->version);
Carlo Caionedb33c772015-05-14 10:49:09 +0200226
227 *version = rom_version->version;
228
229 kfree_skb(skb);
230 return 0;
231}
232
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200233static int rtlbt_parse_firmware(struct hci_dev *hdev,
234 struct btrtl_device_info *btrtl_dev,
Alex Lu907f8492018-02-11 12:24:33 -0600235 unsigned char **_buf)
Carlo Caionedb33c772015-05-14 10:49:09 +0200236{
Colin Ian Kinge5070e072018-09-26 09:32:08 +0100237 static const u8 extension_sig[] = { 0x51, 0x04, 0xfd, 0x77 };
Carlo Caionedb33c772015-05-14 10:49:09 +0200238 struct rtl_epatch_header *epatch_info;
239 unsigned char *buf;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200240 int i, len;
Carlo Caionedb33c772015-05-14 10:49:09 +0200241 size_t min_size;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200242 u8 opcode, length, data;
Carlo Caionedb33c772015-05-14 10:49:09 +0200243 int project_id = -1;
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;
Larry Finger1110a2d2016-09-09 10:02:05 -0500248 static const struct {
249 __u16 lmp_subver;
250 __u8 id;
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 },
Alex Lu907f8492018-02-11 12:24:33 -0600257 { RTL_ROM_LMP_8723B, 9 }, /* 8723D */
258 { RTL_ROM_LMP_8821A, 10 }, /* 8821C */
Alex Lu8ecfdc92018-09-08 12:05:59 -0500259 { RTL_ROM_LMP_8822B, 13 }, /* 8822C */
Ziqian SUN (Zamir)04896832020-04-11 09:34:27 +0800260 { RTL_ROM_LMP_8761A, 14 }, /* 8761B */
Max Chou0d484db2020-11-10 11:38:37 +0800261 { RTL_ROM_LMP_8852A, 18 }, /* 8852A */
Carlo Caionedb33c772015-05-14 10:49:09 +0200262 };
263
Carlo Caionedb33c772015-05-14 10:49:09 +0200264 min_size = sizeof(struct rtl_epatch_header) + sizeof(extension_sig) + 3;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200265 if (btrtl_dev->fw_len < min_size)
Carlo Caionedb33c772015-05-14 10:49:09 +0200266 return -EINVAL;
267
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200268 fwptr = btrtl_dev->fw_data + btrtl_dev->fw_len - sizeof(extension_sig);
Carlo Caionedb33c772015-05-14 10:49:09 +0200269 if (memcmp(fwptr, extension_sig, sizeof(extension_sig)) != 0) {
Alex Luf1300c02019-08-31 16:46:11 +0800270 rtl_dev_err(hdev, "extension section signature mismatch");
Carlo Caionedb33c772015-05-14 10:49:09 +0200271 return -EINVAL;
272 }
273
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.
279 */
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200280 while (fwptr >= btrtl_dev->fw_data + (sizeof(*epatch_info) + 3)) {
Carlo Caionedb33c772015-05-14 10:49:09 +0200281 opcode = *--fwptr;
282 length = *--fwptr;
283 data = *--fwptr;
284
285 BT_DBG("check op=%x len=%x data=%x", opcode, length, data);
286
287 if (opcode == 0xff) /* EOF */
288 break;
289
290 if (length == 0) {
Alex Luf1300c02019-08-31 16:46:11 +0800291 rtl_dev_err(hdev, "found instruction with length 0");
Carlo Caionedb33c772015-05-14 10:49:09 +0200292 return -EINVAL;
293 }
294
295 if (opcode == 0 && length == 1) {
296 project_id = data;
297 break;
298 }
299
300 fwptr -= length;
301 }
302
303 if (project_id < 0) {
Alex Luf1300c02019-08-31 16:46:11 +0800304 rtl_dev_err(hdev, "failed to find version instruction");
Carlo Caionedb33c772015-05-14 10:49:09 +0200305 return -EINVAL;
306 }
307
Larry Finger1110a2d2016-09-09 10:02:05 -0500308 /* 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)
311 break;
312 }
313
314 if (i >= ARRAY_SIZE(project_id_to_lmp_subver)) {
Alex Luf1300c02019-08-31 16:46:11 +0800315 rtl_dev_err(hdev, "unknown project id %d", project_id);
Carlo Caionedb33c772015-05-14 10:49:09 +0200316 return -EINVAL;
317 }
318
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200319 if (btrtl_dev->ic_info->lmp_subver !=
320 project_id_to_lmp_subver[i].lmp_subver) {
Alex Luf1300c02019-08-31 16:46:11 +0800321 rtl_dev_err(hdev, "firmware is for %x but this is a %x",
Hans de Goedea5c76e62018-08-02 16:57:14 +0200322 project_id_to_lmp_subver[i].lmp_subver,
323 btrtl_dev->ic_info->lmp_subver);
Carlo Caionedb33c772015-05-14 10:49:09 +0200324 return -EINVAL;
325 }
326
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200327 epatch_info = (struct rtl_epatch_header *)btrtl_dev->fw_data;
Carlo Caionedb33c772015-05-14 10:49:09 +0200328 if (memcmp(epatch_info->signature, RTL_EPATCH_SIGNATURE, 8) != 0) {
Alex Luf1300c02019-08-31 16:46:11 +0800329 rtl_dev_err(hdev, "bad EPATCH signature");
Carlo Caionedb33c772015-05-14 10:49:09 +0200330 return -EINVAL;
331 }
332
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);
336
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
340 *
341 * Find the right patch for this chip.
342 */
343 min_size += 8 * num_patches;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200344 if (btrtl_dev->fw_len < min_size)
Carlo Caionedb33c772015-05-14 10:49:09 +0200345 return -EINVAL;
346
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200347 chip_id_base = btrtl_dev->fw_data + sizeof(struct rtl_epatch_header);
Carlo Caionedb33c772015-05-14 10:49:09 +0200348 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 +
352 (i * sizeof(u16)));
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200353 if (chip_id == btrtl_dev->rom_version + 1) {
Carlo Caionedb33c772015-05-14 10:49:09 +0200354 patch_length = get_unaligned_le16(patch_length_base +
355 (i * sizeof(u16)));
356 patch_offset = get_unaligned_le32(patch_offset_base +
357 (i * sizeof(u32)));
358 break;
359 }
360 }
361
362 if (!patch_offset) {
Hans de Goedea5c76e62018-08-02 16:57:14 +0200363 rtl_dev_err(hdev, "didn't find patch for chip id %d",
364 btrtl_dev->rom_version);
Carlo Caionedb33c772015-05-14 10:49:09 +0200365 return -EINVAL;
366 }
367
368 BT_DBG("length=%x offset=%x index %d", patch_length, patch_offset, i);
369 min_size = patch_offset + patch_length;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200370 if (btrtl_dev->fw_len < min_size)
Carlo Caionedb33c772015-05-14 10:49:09 +0200371 return -EINVAL;
372
373 /* Copy the firmware into a new buffer and write the version at
374 * the end.
375 */
376 len = patch_length;
Maxim Mikityanskiy268d3632020-01-24 19:15:35 +0200377 buf = kvmalloc(patch_length, GFP_KERNEL);
Carlo Caionedb33c772015-05-14 10:49:09 +0200378 if (!buf)
379 return -ENOMEM;
380
Maxim Mikityanskiy268d3632020-01-24 19:15:35 +0200381 memcpy(buf, btrtl_dev->fw_data + patch_offset, patch_length - 4);
Carlo Caionedb33c772015-05-14 10:49:09 +0200382 memcpy(buf + patch_length - 4, &epatch_info->fw_version, 4);
383
384 *_buf = buf;
385 return len;
386}
387
388static int rtl_download_firmware(struct hci_dev *hdev,
389 const unsigned char *data, int fw_len)
390{
391 struct rtl_download_cmd *dl_cmd;
392 int frag_num = fw_len / RTL_FRAG_LEN + 1;
393 int frag_len = RTL_FRAG_LEN;
394 int ret = 0;
395 int i;
Alex Lu240b64a2019-08-31 16:36:02 +0800396 struct sk_buff *skb;
397 struct hci_rp_read_local_version *rp;
Carlo Caionedb33c772015-05-14 10:49:09 +0200398
399 dl_cmd = kmalloc(sizeof(struct rtl_download_cmd), GFP_KERNEL);
400 if (!dl_cmd)
401 return -ENOMEM;
402
403 for (i = 0; i < frag_num; i++) {
404 struct sk_buff *skb;
405
406 BT_DBG("download fw (%d/%d)", i, frag_num);
407
Max Choucf0d9a72019-09-05 13:21:57 +0800408 if (i > 0x7f)
409 dl_cmd->index = (i & 0x7f) + 1;
410 else
411 dl_cmd->index = i;
412
Carlo Caionedb33c772015-05-14 10:49:09 +0200413 if (i == (frag_num - 1)) {
414 dl_cmd->index |= 0x80; /* data end */
415 frag_len = fw_len % RTL_FRAG_LEN;
416 }
417 memcpy(dl_cmd->data, data, frag_len);
418
419 /* Send download command */
420 skb = __hci_cmd_sync(hdev, 0xfc20, frag_len + 1, dl_cmd,
421 HCI_INIT_TIMEOUT);
422 if (IS_ERR(skb)) {
Alex Luf1300c02019-08-31 16:46:11 +0800423 rtl_dev_err(hdev, "download fw command failed (%ld)",
Hans de Goedea5c76e62018-08-02 16:57:14 +0200424 PTR_ERR(skb));
Max Choud171dfb2019-09-18 16:56:41 +0800425 ret = PTR_ERR(skb);
Carlo Caionedb33c772015-05-14 10:49:09 +0200426 goto out;
427 }
428
429 if (skb->len != sizeof(struct rtl_download_response)) {
Alex Luf1300c02019-08-31 16:46:11 +0800430 rtl_dev_err(hdev, "download fw event length mismatch");
Carlo Caionedb33c772015-05-14 10:49:09 +0200431 kfree_skb(skb);
432 ret = -EIO;
433 goto out;
434 }
435
436 kfree_skb(skb);
437 data += RTL_FRAG_LEN;
438 }
439
Alex Lu240b64a2019-08-31 16:36:02 +0800440 skb = btrtl_read_local_version(hdev);
441 if (IS_ERR(skb)) {
442 ret = PTR_ERR(skb);
443 rtl_dev_err(hdev, "read local version failed");
444 goto out;
445 }
446
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));
450 kfree_skb(skb);
451
Carlo Caionedb33c772015-05-14 10:49:09 +0200452out:
453 kfree(dl_cmd);
454 return ret;
455}
456
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200457static int rtl_load_file(struct hci_dev *hdev, const char *name, u8 **buff)
Larry Finger1110a2d2016-09-09 10:02:05 -0500458{
459 const struct firmware *fw;
460 int ret;
461
Alex Luf1300c02019-08-31 16:46:11 +0800462 rtl_dev_info(hdev, "loading %s", name);
Larry Finger1110a2d2016-09-09 10:02:05 -0500463 ret = request_firmware(&fw, name, &hdev->dev);
Larry Fingerabed84a2017-02-19 20:04:57 -0600464 if (ret < 0)
Larry Finger1110a2d2016-09-09 10:02:05 -0500465 return ret;
Larry Finger1110a2d2016-09-09 10:02:05 -0500466 ret = fw->size;
Maxim Mikityanskiy268d3632020-01-24 19:15:35 +0200467 *buff = kvmalloc(fw->size, GFP_KERNEL);
468 if (*buff)
469 memcpy(*buff, fw->data, ret);
470 else
Dan Carpenterc3327bd2017-07-28 17:41:11 +0300471 ret = -ENOMEM;
Larry Finger1110a2d2016-09-09 10:02:05 -0500472
473 release_firmware(fw);
474
475 return ret;
476}
477
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200478static int btrtl_setup_rtl8723a(struct hci_dev *hdev,
479 struct btrtl_device_info *btrtl_dev)
Carlo Caionedb33c772015-05-14 10:49:09 +0200480{
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200481 if (btrtl_dev->fw_len < 8)
482 return -EINVAL;
Carlo Caionedb33c772015-05-14 10:49:09 +0200483
484 /* Check that the firmware doesn't have the epatch signature
485 * (which is only for RTL8723B and newer).
486 */
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200487 if (!memcmp(btrtl_dev->fw_data, RTL_EPATCH_SIGNATURE, 8)) {
Alex Luf1300c02019-08-31 16:46:11 +0800488 rtl_dev_err(hdev, "unexpected EPATCH signature!");
Alex Lu907f8492018-02-11 12:24:33 -0600489 return -EINVAL;
490 }
491
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200492 return rtl_download_firmware(hdev, btrtl_dev->fw_data,
493 btrtl_dev->fw_len);
494}
Alex Lu907f8492018-02-11 12:24:33 -0600495
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200496static int btrtl_setup_rtl8723b(struct hci_dev *hdev,
497 struct btrtl_device_info *btrtl_dev)
498{
499 unsigned char *fw_data = NULL;
500 int ret;
501 u8 *tbuff;
Carlo Caionedb33c772015-05-14 10:49:09 +0200502
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200503 ret = rtlbt_parse_firmware(hdev, btrtl_dev, &fw_data);
Carlo Caionedb33c772015-05-14 10:49:09 +0200504 if (ret < 0)
505 goto out;
506
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200507 if (btrtl_dev->cfg_len > 0) {
Maxim Mikityanskiy268d3632020-01-24 19:15:35 +0200508 tbuff = kvzalloc(ret + btrtl_dev->cfg_len, GFP_KERNEL);
Larry Finger1110a2d2016-09-09 10:02:05 -0500509 if (!tbuff) {
510 ret = -ENOMEM;
511 goto out;
512 }
513
514 memcpy(tbuff, fw_data, ret);
Maxim Mikityanskiy268d3632020-01-24 19:15:35 +0200515 kvfree(fw_data);
Larry Finger1110a2d2016-09-09 10:02:05 -0500516
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200517 memcpy(tbuff + ret, btrtl_dev->cfg_data, btrtl_dev->cfg_len);
518 ret += btrtl_dev->cfg_len;
Larry Finger1110a2d2016-09-09 10:02:05 -0500519
520 fw_data = tbuff;
521 }
522
Alex Luf1300c02019-08-31 16:46:11 +0800523 rtl_dev_info(hdev, "cfg_sz %d, total sz %d", btrtl_dev->cfg_len, ret);
Larry Finger1110a2d2016-09-09 10:02:05 -0500524
Carlo Caionedb33c772015-05-14 10:49:09 +0200525 ret = rtl_download_firmware(hdev, fw_data, ret);
Carlo Caionedb33c772015-05-14 10:49:09 +0200526
527out:
Maxim Mikityanskiy268d3632020-01-24 19:15:35 +0200528 kvfree(fw_data);
Carlo Caionedb33c772015-05-14 10:49:09 +0200529 return ret;
530}
531
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200532void btrtl_free(struct btrtl_device_info *btrtl_dev)
Carlo Caionedb33c772015-05-14 10:49:09 +0200533{
Maxim Mikityanskiy268d3632020-01-24 19:15:35 +0200534 kvfree(btrtl_dev->fw_data);
535 kvfree(btrtl_dev->cfg_data);
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200536 kfree(btrtl_dev);
537}
538EXPORT_SYMBOL_GPL(btrtl_free);
539
Hans de Goede1cc194c2018-08-02 16:57:17 +0200540struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
541 const char *postfix)
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200542{
543 struct btrtl_device_info *btrtl_dev;
Carlo Caionedb33c772015-05-14 10:49:09 +0200544 struct sk_buff *skb;
545 struct hci_rp_read_local_version *resp;
Hans de Goede1cc194c2018-08-02 16:57:17 +0200546 char cfg_name[40];
Alex Lu907f8492018-02-11 12:24:33 -0600547 u16 hci_rev, lmp_subver;
Martin Blumenstinglc50903e2018-08-02 16:57:16 +0200548 u8 hci_ver;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200549 int ret;
Kai-Heng Feng1996d9c2020-10-26 16:28:38 +0800550 u16 opcode;
551 u8 cmd[2];
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200552
553 btrtl_dev = kzalloc(sizeof(*btrtl_dev), GFP_KERNEL);
554 if (!btrtl_dev) {
555 ret = -ENOMEM;
556 goto err_alloc;
557 }
Carlo Caionedb33c772015-05-14 10:49:09 +0200558
559 skb = btrtl_read_local_version(hdev);
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200560 if (IS_ERR(skb)) {
561 ret = PTR_ERR(skb);
562 goto err_free;
563 }
Carlo Caionedb33c772015-05-14 10:49:09 +0200564
565 resp = (struct hci_rp_read_local_version *)skb->data;
Alex Luf1300c02019-08-31 16:46:11 +0800566 rtl_dev_info(hdev, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x",
Hans de Goedea5c76e62018-08-02 16:57:14 +0200567 resp->hci_ver, resp->hci_rev,
568 resp->lmp_ver, resp->lmp_subver);
Carlo Caionedb33c772015-05-14 10:49:09 +0200569
Martin Blumenstinglc50903e2018-08-02 16:57:16 +0200570 hci_ver = resp->hci_ver;
Alex Lu907f8492018-02-11 12:24:33 -0600571 hci_rev = le16_to_cpu(resp->hci_rev);
Carlo Caionedb33c772015-05-14 10:49:09 +0200572 lmp_subver = le16_to_cpu(resp->lmp_subver);
Kai-Heng Feng1996d9c2020-10-26 16:28:38 +0800573
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;
577
578 if (btrtl_dev->drop_fw) {
579 opcode = hci_opcode_pack(0x3f, 0x66);
580 cmd[0] = opcode & 0xff;
581 cmd[1] = opcode >> 8;
582
583 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
Colin Ian Kingf5e8e212020-11-10 12:39:15 +0000584 if (!skb)
Kai-Heng Feng1996d9c2020-10-26 16:28:38 +0800585 goto out_free;
586
587 skb_put_data(skb, cmd, sizeof(cmd));
588 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
589
590 hdev->send(hdev, skb);
591
592 /* Ensure the above vendor command is sent to controller and
593 * process has done.
594 */
595 msleep(200);
596
597 /* Read the local version again. Expect to have the vanilla
598 * version as cold boot.
599 */
600 skb = btrtl_read_local_version(hdev);
601 if (IS_ERR(skb)) {
602 ret = PTR_ERR(skb);
603 goto err_free;
604 }
605
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);
610
611 hci_ver = resp->hci_ver;
612 hci_rev = le16_to_cpu(resp->hci_rev);
613 lmp_subver = le16_to_cpu(resp->lmp_subver);
614 }
615out_free:
Carlo Caionedb33c772015-05-14 10:49:09 +0200616 kfree_skb(skb);
617
Martin Blumenstinglc50903e2018-08-02 16:57:16 +0200618 btrtl_dev->ic_info = btrtl_match_ic(lmp_subver, hci_rev, hci_ver,
619 hdev->bus);
620
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200621 if (!btrtl_dev->ic_info) {
Alex Lud1822152019-08-31 16:41:13 +0800622 rtl_dev_info(hdev, "unknown IC info, lmp subver %04x, hci rev %04x, hci ver %04x",
Martin Blumenstinglc50903e2018-08-02 16:57:16 +0200623 lmp_subver, hci_rev, hci_ver);
Kai-Heng Feng00df2142019-01-27 16:33:59 +0800624 return btrtl_dev;
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200625 }
626
627 if (btrtl_dev->ic_info->has_rom_version) {
628 ret = rtl_read_rom_version(hdev, &btrtl_dev->rom_version);
629 if (ret)
630 goto err_free;
631 }
632
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) {
Alex Luf1300c02019-08-31 16:46:11 +0800636 rtl_dev_err(hdev, "firmware file %s not found",
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200637 btrtl_dev->ic_info->fw_name);
638 ret = btrtl_dev->fw_len;
639 goto err_free;
640 }
641
642 if (btrtl_dev->ic_info->cfg_name) {
Hans de Goede1cc194c2018-08-02 16:57:17 +0200643 if (postfix) {
644 snprintf(cfg_name, sizeof(cfg_name), "%s-%s.bin",
645 btrtl_dev->ic_info->cfg_name, postfix);
646 } else {
647 snprintf(cfg_name, sizeof(cfg_name), "%s.bin",
648 btrtl_dev->ic_info->cfg_name);
649 }
650 btrtl_dev->cfg_len = rtl_load_file(hdev, cfg_name,
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200651 &btrtl_dev->cfg_data);
652 if (btrtl_dev->ic_info->config_needed &&
653 btrtl_dev->cfg_len <= 0) {
Alex Luf1300c02019-08-31 16:46:11 +0800654 rtl_dev_err(hdev, "mandatory config file %s not found",
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200655 btrtl_dev->ic_info->cfg_name);
656 ret = btrtl_dev->cfg_len;
657 goto err_free;
658 }
659 }
660
661 return btrtl_dev;
662
663err_free:
664 btrtl_free(btrtl_dev);
665err_alloc:
666 return ERR_PTR(ret);
667}
668EXPORT_SYMBOL_GPL(btrtl_initialize);
669
670int btrtl_download_firmware(struct hci_dev *hdev,
671 struct btrtl_device_info *btrtl_dev)
672{
Carlo Caionedb33c772015-05-14 10:49:09 +0200673 /* 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.
678 */
Kai-Heng Feng00df2142019-01-27 16:33:59 +0800679 if (!btrtl_dev->ic_info) {
Alex Luf1300c02019-08-31 16:46:11 +0800680 rtl_dev_info(hdev, "assuming no firmware upload needed");
Kai-Heng Feng00df2142019-01-27 16:33:59 +0800681 return 0;
682 }
683
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200684 switch (btrtl_dev->ic_info->lmp_subver) {
Carlo Caionedb33c772015-05-14 10:49:09 +0200685 case RTL_ROM_LMP_8723A:
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200686 return btrtl_setup_rtl8723a(hdev, btrtl_dev);
Carlo Caionedb33c772015-05-14 10:49:09 +0200687 case RTL_ROM_LMP_8723B:
Carlo Caionedb33c772015-05-14 10:49:09 +0200688 case RTL_ROM_LMP_8821A:
Carlo Caionedb33c772015-05-14 10:49:09 +0200689 case RTL_ROM_LMP_8761A:
Larry Finger1110a2d2016-09-09 10:02:05 -0500690 case RTL_ROM_LMP_8822B:
Max Chou0d484db2020-11-10 11:38:37 +0800691 case RTL_ROM_LMP_8852A:
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200692 return btrtl_setup_rtl8723b(hdev, btrtl_dev);
Carlo Caionedb33c772015-05-14 10:49:09 +0200693 default:
Alex Luf1300c02019-08-31 16:46:11 +0800694 rtl_dev_info(hdev, "assuming no firmware upload needed");
Carlo Caionedb33c772015-05-14 10:49:09 +0200695 return 0;
696 }
697}
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200698EXPORT_SYMBOL_GPL(btrtl_download_firmware);
699
700int btrtl_setup_realtek(struct hci_dev *hdev)
701{
702 struct btrtl_device_info *btrtl_dev;
703 int ret;
704
Hans de Goede1cc194c2018-08-02 16:57:17 +0200705 btrtl_dev = btrtl_initialize(hdev, NULL);
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200706 if (IS_ERR(btrtl_dev))
707 return PTR_ERR(btrtl_dev);
708
709 ret = btrtl_download_firmware(hdev, btrtl_dev);
710
711 btrtl_free(btrtl_dev);
712
Alex Lu65251e22019-08-30 20:02:14 +0800713 /* Enable controller to do both LE scan and BR/EDR inquiry
714 * simultaneously.
715 */
716 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
717
Martin Blumenstingl26503ad22018-08-02 16:57:13 +0200718 return ret;
719}
Carlo Caionedb33c772015-05-14 10:49:09 +0200720EXPORT_SYMBOL_GPL(btrtl_setup_realtek);
721
Jian-Hong Pan7af3f5582019-06-25 16:30:51 +0800722int btrtl_shutdown_realtek(struct hci_dev *hdev)
723{
724 struct sk_buff *skb;
725 int ret;
726
727 /* According to the vendor driver, BT must be reset on close to avoid
728 * firmware crash.
729 */
730 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
731 if (IS_ERR(skb)) {
732 ret = PTR_ERR(skb);
733 bt_dev_err(hdev, "HCI reset during shutdown failed");
734 return ret;
735 }
736 kfree_skb(skb);
737
738 return 0;
739}
740EXPORT_SYMBOL_GPL(btrtl_shutdown_realtek);
741
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200742static unsigned int btrtl_convert_baudrate(u32 device_baudrate)
743{
744 switch (device_baudrate) {
745 case 0x0252a00a:
746 return 230400;
747
748 case 0x05f75004:
749 return 921600;
750
751 case 0x00005004:
752 return 1000000;
753
754 case 0x04928002:
755 case 0x01128002:
756 return 1500000;
757
758 case 0x00005002:
759 return 2000000;
760
761 case 0x0000b001:
762 return 2500000;
763
764 case 0x04928001:
765 return 3000000;
766
767 case 0x052a6001:
768 return 3500000;
769
770 case 0x00005001:
771 return 4000000;
772
773 case 0x0252c014:
774 default:
775 return 115200;
776 }
777}
778
779int 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)
783{
784 struct rtl_vendor_config *config;
785 struct rtl_vendor_config_entry *entry;
786 int i, total_data_len;
787 bool found = false;
788
789 total_data_len = btrtl_dev->cfg_len - sizeof(*config);
790 if (total_data_len <= 0) {
Alex Luf1300c02019-08-31 16:46:11 +0800791 rtl_dev_warn(hdev, "no config loaded");
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200792 return -EINVAL;
793 }
794
795 config = (struct rtl_vendor_config *)btrtl_dev->cfg_data;
796 if (le32_to_cpu(config->signature) != RTL_CONFIG_MAGIC) {
Alex Luf1300c02019-08-31 16:46:11 +0800797 rtl_dev_err(hdev, "invalid config magic");
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200798 return -EINVAL;
799 }
800
801 if (total_data_len < le16_to_cpu(config->total_len)) {
Alex Luf1300c02019-08-31 16:46:11 +0800802 rtl_dev_err(hdev, "config is too short");
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200803 return -EINVAL;
804 }
805
806 for (i = 0; i < total_data_len; ) {
807 entry = ((void *)config->entry) + i;
808
809 switch (le16_to_cpu(entry->offset)) {
810 case 0xc:
811 if (entry->len < sizeof(*device_baudrate)) {
Alex Luf1300c02019-08-31 16:46:11 +0800812 rtl_dev_err(hdev, "invalid UART config entry");
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200813 return -EINVAL;
814 }
815
816 *device_baudrate = get_unaligned_le32(entry->data);
817 *controller_baudrate = btrtl_convert_baudrate(
818 *device_baudrate);
819
820 if (entry->len >= 13)
821 *flow_control = !!(entry->data[12] & BIT(2));
822 else
823 *flow_control = false;
824
825 found = true;
826 break;
827
828 default:
Alex Luf1300c02019-08-31 16:46:11 +0800829 rtl_dev_dbg(hdev, "skipping config entry 0x%x (len %u)",
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200830 le16_to_cpu(entry->offset), entry->len);
831 break;
YueHaibing515d6792019-10-25 17:26:53 +0800832 }
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200833
834 i += sizeof(*entry) + entry->len;
835 }
836
837 if (!found) {
Alex Luf1300c02019-08-31 16:46:11 +0800838 rtl_dev_err(hdev, "no UART config entry found");
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200839 return -ENOENT;
840 }
841
Alex Luf1300c02019-08-31 16:46:11 +0800842 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);
Martin Blumenstinglb85b0ee2018-08-02 16:57:15 +0200845
846 return 0;
847}
848EXPORT_SYMBOL_GPL(btrtl_get_uart_settings);
849
Carlo Caionedb33c772015-05-14 10:49:09 +0200850MODULE_AUTHOR("Daniel Drake <drake@endlessm.com>");
851MODULE_DESCRIPTION("Bluetooth support for Realtek devices ver " VERSION);
852MODULE_VERSION(VERSION);
853MODULE_LICENSE("GPL");
Martin Blumenstinglf96dbd32018-08-02 16:57:12 +0200854MODULE_FIRMWARE("rtl_bt/rtl8723a_fw.bin");
855MODULE_FIRMWARE("rtl_bt/rtl8723b_fw.bin");
856MODULE_FIRMWARE("rtl_bt/rtl8723b_config.bin");
Martin Blumenstinglc50903e2018-08-02 16:57:16 +0200857MODULE_FIRMWARE("rtl_bt/rtl8723bs_fw.bin");
858MODULE_FIRMWARE("rtl_bt/rtl8723bs_config.bin");
859MODULE_FIRMWARE("rtl_bt/rtl8723ds_fw.bin");
860MODULE_FIRMWARE("rtl_bt/rtl8723ds_config.bin");
Martin Blumenstinglf96dbd32018-08-02 16:57:12 +0200861MODULE_FIRMWARE("rtl_bt/rtl8761a_fw.bin");
862MODULE_FIRMWARE("rtl_bt/rtl8761a_config.bin");
863MODULE_FIRMWARE("rtl_bt/rtl8821a_fw.bin");
864MODULE_FIRMWARE("rtl_bt/rtl8821a_config.bin");
865MODULE_FIRMWARE("rtl_bt/rtl8822b_fw.bin");
866MODULE_FIRMWARE("rtl_bt/rtl8822b_config.bin");
Max Chou0d484db2020-11-10 11:38:37 +0800867MODULE_FIRMWARE("rtl_bt/rtl8852au_fw.bin");
868MODULE_FIRMWARE("rtl_bt/rtl8852au_config.bin");