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