Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Bluetooth support for Broadcom devices |
| 4 | * |
| 5 | * Copyright (C) 2015 Intel Corporation |
| 6 | * |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 25 | #include <linux/firmware.h> |
| 26 | #include <asm/unaligned.h> |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 27 | |
| 28 | #include <net/bluetooth/bluetooth.h> |
| 29 | #include <net/bluetooth/hci_core.h> |
| 30 | |
| 31 | #include "btbcm.h" |
| 32 | |
| 33 | #define VERSION "0.1" |
| 34 | |
| 35 | #define BDADDR_BCM20702A0 (&(bdaddr_t) {{0x00, 0xa0, 0x02, 0x70, 0x20, 0x00}}) |
Maxime Ripard | 92ffe0d | 2018-12-17 12:04:45 +0800 | [diff] [blame] | 36 | #define BDADDR_BCM20702A1 (&(bdaddr_t) {{0x00, 0x00, 0xa0, 0x02, 0x70, 0x20}}) |
Chen-Yu Tsai | 0697607a | 2018-12-17 12:04:47 +0800 | [diff] [blame^] | 37 | #define BDADDR_BCM43430A0 (&(bdaddr_t) {{0xac, 0x1f, 0x12, 0xa0, 0x43, 0x43}}) |
Frederic Danis | a8f3b94 | 2015-05-28 11:25:02 +0200 | [diff] [blame] | 38 | #define BDADDR_BCM4324B3 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb3, 0x24, 0x43}}) |
Frederic Danis | 4a546ec | 2015-07-27 18:02:25 +0200 | [diff] [blame] | 39 | #define BDADDR_BCM4330B1 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb1, 0x30, 0x43}}) |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 40 | |
| 41 | int btbcm_check_bdaddr(struct hci_dev *hdev) |
| 42 | { |
| 43 | struct hci_rp_read_bd_addr *bda; |
| 44 | struct sk_buff *skb; |
| 45 | |
| 46 | skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL, |
| 47 | HCI_INIT_TIMEOUT); |
| 48 | if (IS_ERR(skb)) { |
| 49 | int err = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 50 | bt_dev_err(hdev, "BCM: Reading device address failed (%d)", err); |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 51 | return err; |
| 52 | } |
| 53 | |
| 54 | if (skb->len != sizeof(*bda)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 55 | bt_dev_err(hdev, "BCM: Device address length mismatch"); |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 56 | kfree_skb(skb); |
| 57 | return -EIO; |
| 58 | } |
| 59 | |
| 60 | bda = (struct hci_rp_read_bd_addr *)skb->data; |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 61 | |
Frederic Danis | a8f3b94 | 2015-05-28 11:25:02 +0200 | [diff] [blame] | 62 | /* Check if the address indicates a controller with either an |
| 63 | * invalid or default address. In both cases the device needs |
| 64 | * to be marked as not having a valid address. |
| 65 | * |
| 66 | * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 67 | * with no configured address. |
Frederic Danis | a8f3b94 | 2015-05-28 11:25:02 +0200 | [diff] [blame] | 68 | * |
Maxime Ripard | 92ffe0d | 2018-12-17 12:04:45 +0800 | [diff] [blame] | 69 | * The address 20:70:02:A0:00:00 indicates a BCM20702A1 controller |
| 70 | * with no configured address. |
| 71 | * |
Frederic Danis | a8f3b94 | 2015-05-28 11:25:02 +0200 | [diff] [blame] | 72 | * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller |
| 73 | * with waiting for configuration state. |
Frederic Danis | 4a546ec | 2015-07-27 18:02:25 +0200 | [diff] [blame] | 74 | * |
| 75 | * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller |
| 76 | * with waiting for configuration state. |
Chen-Yu Tsai | 0697607a | 2018-12-17 12:04:47 +0800 | [diff] [blame^] | 77 | * |
| 78 | * The address 43:43:A0:12:1F:AC indicates a BCM43430A0 controller |
| 79 | * with no configured address. |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 80 | */ |
Frederic Danis | a8f3b94 | 2015-05-28 11:25:02 +0200 | [diff] [blame] | 81 | if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0) || |
Maxime Ripard | 92ffe0d | 2018-12-17 12:04:45 +0800 | [diff] [blame] | 82 | !bacmp(&bda->bdaddr, BDADDR_BCM20702A1) || |
Frederic Danis | 4a546ec | 2015-07-27 18:02:25 +0200 | [diff] [blame] | 83 | !bacmp(&bda->bdaddr, BDADDR_BCM4324B3) || |
Chen-Yu Tsai | 0697607a | 2018-12-17 12:04:47 +0800 | [diff] [blame^] | 84 | !bacmp(&bda->bdaddr, BDADDR_BCM4330B1) || |
| 85 | !bacmp(&bda->bdaddr, BDADDR_BCM43430A0)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 86 | bt_dev_info(hdev, "BCM: Using default device address (%pMR)", |
| 87 | &bda->bdaddr); |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 88 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); |
| 89 | } |
| 90 | |
| 91 | kfree_skb(skb); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | EXPORT_SYMBOL_GPL(btbcm_check_bdaddr); |
| 96 | |
| 97 | int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
| 98 | { |
| 99 | struct sk_buff *skb; |
| 100 | int err; |
| 101 | |
| 102 | skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT); |
| 103 | if (IS_ERR(skb)) { |
| 104 | err = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 105 | bt_dev_err(hdev, "BCM: Change address command failed (%d)", err); |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 106 | return err; |
| 107 | } |
| 108 | kfree_skb(skb); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | EXPORT_SYMBOL_GPL(btbcm_set_bdaddr); |
| 113 | |
Frederic Danis | 18aeb44 | 2015-05-28 11:25:01 +0200 | [diff] [blame] | 114 | int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw) |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 115 | { |
| 116 | const struct hci_command_hdr *cmd; |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 117 | const u8 *fw_ptr; |
| 118 | size_t fw_size; |
| 119 | struct sk_buff *skb; |
| 120 | u16 opcode; |
Frederic Danis | 18aeb44 | 2015-05-28 11:25:01 +0200 | [diff] [blame] | 121 | int err = 0; |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 122 | |
| 123 | /* Start Download */ |
| 124 | skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT); |
| 125 | if (IS_ERR(skb)) { |
| 126 | err = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 127 | bt_dev_err(hdev, "BCM: Download Minidrv command failed (%d)", |
| 128 | err); |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 129 | goto done; |
| 130 | } |
| 131 | kfree_skb(skb); |
| 132 | |
| 133 | /* 50 msec delay after Download Minidrv completes */ |
| 134 | msleep(50); |
| 135 | |
| 136 | fw_ptr = fw->data; |
| 137 | fw_size = fw->size; |
| 138 | |
| 139 | while (fw_size >= sizeof(*cmd)) { |
| 140 | const u8 *cmd_param; |
| 141 | |
| 142 | cmd = (struct hci_command_hdr *)fw_ptr; |
| 143 | fw_ptr += sizeof(*cmd); |
| 144 | fw_size -= sizeof(*cmd); |
| 145 | |
| 146 | if (fw_size < cmd->plen) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 147 | bt_dev_err(hdev, "BCM: Patch is corrupted"); |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 148 | err = -EINVAL; |
| 149 | goto done; |
| 150 | } |
| 151 | |
| 152 | cmd_param = fw_ptr; |
| 153 | fw_ptr += cmd->plen; |
| 154 | fw_size -= cmd->plen; |
| 155 | |
| 156 | opcode = le16_to_cpu(cmd->opcode); |
| 157 | |
| 158 | skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param, |
| 159 | HCI_INIT_TIMEOUT); |
| 160 | if (IS_ERR(skb)) { |
| 161 | err = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 162 | bt_dev_err(hdev, "BCM: Patch command %04x failed (%d)", |
| 163 | opcode, err); |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 164 | goto done; |
| 165 | } |
| 166 | kfree_skb(skb); |
| 167 | } |
| 168 | |
| 169 | /* 250 msec delay after Launch Ram completes */ |
| 170 | msleep(250); |
| 171 | |
| 172 | done: |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 173 | return err; |
| 174 | } |
| 175 | EXPORT_SYMBOL(btbcm_patchram); |
| 176 | |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 177 | static int btbcm_reset(struct hci_dev *hdev) |
| 178 | { |
| 179 | struct sk_buff *skb; |
| 180 | |
| 181 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 182 | if (IS_ERR(skb)) { |
| 183 | int err = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 184 | bt_dev_err(hdev, "BCM: Reset failed (%d)", err); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 185 | return err; |
| 186 | } |
| 187 | kfree_skb(skb); |
| 188 | |
Wen-chien Jesse Sung | 3af3a59 | 2017-01-10 11:46:28 +0800 | [diff] [blame] | 189 | /* 100 msec delay for module to complete reset process */ |
| 190 | msleep(100); |
| 191 | |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
Marcel Holtmann | 9bc63ca | 2015-10-05 12:43:57 +0200 | [diff] [blame] | 195 | static struct sk_buff *btbcm_read_local_name(struct hci_dev *hdev) |
| 196 | { |
| 197 | struct sk_buff *skb; |
| 198 | |
| 199 | skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL, |
| 200 | HCI_INIT_TIMEOUT); |
| 201 | if (IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 202 | bt_dev_err(hdev, "BCM: Reading local name failed (%ld)", |
| 203 | PTR_ERR(skb)); |
Marcel Holtmann | 9bc63ca | 2015-10-05 12:43:57 +0200 | [diff] [blame] | 204 | return skb; |
| 205 | } |
| 206 | |
| 207 | if (skb->len != sizeof(struct hci_rp_read_local_name)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 208 | bt_dev_err(hdev, "BCM: Local name length mismatch"); |
Marcel Holtmann | 9bc63ca | 2015-10-05 12:43:57 +0200 | [diff] [blame] | 209 | kfree_skb(skb); |
| 210 | return ERR_PTR(-EIO); |
| 211 | } |
| 212 | |
| 213 | return skb; |
| 214 | } |
| 215 | |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 216 | static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev) |
| 217 | { |
| 218 | struct sk_buff *skb; |
| 219 | |
| 220 | skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL, |
| 221 | HCI_INIT_TIMEOUT); |
| 222 | if (IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 223 | bt_dev_err(hdev, "BCM: Reading local version info failed (%ld)", |
| 224 | PTR_ERR(skb)); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 225 | return skb; |
| 226 | } |
| 227 | |
| 228 | if (skb->len != sizeof(struct hci_rp_read_local_version)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 229 | bt_dev_err(hdev, "BCM: Local version length mismatch"); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 230 | kfree_skb(skb); |
| 231 | return ERR_PTR(-EIO); |
| 232 | } |
| 233 | |
| 234 | return skb; |
| 235 | } |
| 236 | |
| 237 | static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev) |
| 238 | { |
| 239 | struct sk_buff *skb; |
| 240 | |
| 241 | skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT); |
| 242 | if (IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 243 | bt_dev_err(hdev, "BCM: Read verbose config info failed (%ld)", |
| 244 | PTR_ERR(skb)); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 245 | return skb; |
| 246 | } |
| 247 | |
| 248 | if (skb->len != 7) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 249 | bt_dev_err(hdev, "BCM: Verbose config length mismatch"); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 250 | kfree_skb(skb); |
| 251 | return ERR_PTR(-EIO); |
| 252 | } |
| 253 | |
| 254 | return skb; |
| 255 | } |
| 256 | |
Marcel Holtmann | 4284ecb | 2017-06-10 14:33:16 +0200 | [diff] [blame] | 257 | static struct sk_buff *btbcm_read_controller_features(struct hci_dev *hdev) |
| 258 | { |
| 259 | struct sk_buff *skb; |
| 260 | |
| 261 | skb = __hci_cmd_sync(hdev, 0xfc6e, 0, NULL, HCI_INIT_TIMEOUT); |
| 262 | if (IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 263 | bt_dev_err(hdev, "BCM: Read controller features failed (%ld)", |
| 264 | PTR_ERR(skb)); |
Marcel Holtmann | 4284ecb | 2017-06-10 14:33:16 +0200 | [diff] [blame] | 265 | return skb; |
| 266 | } |
| 267 | |
| 268 | if (skb->len != 9) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 269 | bt_dev_err(hdev, "BCM: Controller features length mismatch"); |
Marcel Holtmann | 4284ecb | 2017-06-10 14:33:16 +0200 | [diff] [blame] | 270 | kfree_skb(skb); |
| 271 | return ERR_PTR(-EIO); |
| 272 | } |
| 273 | |
| 274 | return skb; |
| 275 | } |
| 276 | |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 277 | static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev) |
| 278 | { |
| 279 | struct sk_buff *skb; |
| 280 | |
| 281 | skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT); |
| 282 | if (IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 283 | bt_dev_err(hdev, "BCM: Read USB product info failed (%ld)", |
| 284 | PTR_ERR(skb)); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 285 | return skb; |
| 286 | } |
| 287 | |
| 288 | if (skb->len != 5) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 289 | bt_dev_err(hdev, "BCM: USB product length mismatch"); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 290 | kfree_skb(skb); |
| 291 | return ERR_PTR(-EIO); |
| 292 | } |
| 293 | |
| 294 | return skb; |
| 295 | } |
| 296 | |
Marcel Holtmann | e76dc1d | 2017-08-17 11:02:40 +0200 | [diff] [blame] | 297 | static int btbcm_read_info(struct hci_dev *hdev) |
| 298 | { |
| 299 | struct sk_buff *skb; |
| 300 | |
| 301 | /* Read Verbose Config Version Info */ |
| 302 | skb = btbcm_read_verbose_config(hdev); |
| 303 | if (IS_ERR(skb)) |
| 304 | return PTR_ERR(skb); |
| 305 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 306 | bt_dev_info(hdev, "BCM: chip id %u", skb->data[1]); |
Marcel Holtmann | e76dc1d | 2017-08-17 11:02:40 +0200 | [diff] [blame] | 307 | kfree_skb(skb); |
| 308 | |
| 309 | /* Read Controller Features */ |
| 310 | skb = btbcm_read_controller_features(hdev); |
| 311 | if (IS_ERR(skb)) |
| 312 | return PTR_ERR(skb); |
| 313 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 314 | bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]); |
Marcel Holtmann | e76dc1d | 2017-08-17 11:02:40 +0200 | [diff] [blame] | 315 | kfree_skb(skb); |
| 316 | |
| 317 | /* Read Local Name */ |
| 318 | skb = btbcm_read_local_name(hdev); |
| 319 | if (IS_ERR(skb)) |
| 320 | return PTR_ERR(skb); |
| 321 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 322 | bt_dev_info(hdev, "%s", (char *)(skb->data + 1)); |
Marcel Holtmann | e76dc1d | 2017-08-17 11:02:40 +0200 | [diff] [blame] | 323 | kfree_skb(skb); |
| 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
Hans de Goede | f732838 | 2018-04-20 14:44:03 +0200 | [diff] [blame] | 328 | struct bcm_subver_table { |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 329 | u16 subver; |
| 330 | const char *name; |
Hans de Goede | f732838 | 2018-04-20 14:44:03 +0200 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | static const struct bcm_subver_table bcm_uart_subver_table[] = { |
Frederic Danis | 4a546ec | 2015-07-27 18:02:25 +0200 | [diff] [blame] | 334 | { 0x4103, "BCM4330B1" }, /* 002.001.003 */ |
Marcel Holtmann | 9a0bb57 | 2015-04-05 22:52:19 -0700 | [diff] [blame] | 335 | { 0x410e, "BCM43341B0" }, /* 002.001.014 */ |
Frederic Danis | a8f3b94 | 2015-05-28 11:25:02 +0200 | [diff] [blame] | 336 | { 0x4406, "BCM4324B3" }, /* 002.004.006 */ |
Christian Hewitt | a357ea0 | 2018-09-04 21:50:57 +0400 | [diff] [blame] | 337 | { 0x6109, "BCM4335C0" }, /* 003.001.009 */ |
Ilya Faenson | 40db5f0 | 2015-06-17 11:42:46 -0400 | [diff] [blame] | 338 | { 0x610c, "BCM4354" }, /* 003.001.012 */ |
Jörg Krause | d456f67 | 2018-01-18 10:21:55 +0100 | [diff] [blame] | 339 | { 0x2122, "BCM4343A0" }, /* 001.001.034 */ |
Ian Molton | feb1672 | 2017-06-28 20:10:55 +0100 | [diff] [blame] | 340 | { 0x2209, "BCM43430A1" }, /* 001.002.009 */ |
Ian W MORRISON | 18a39b9 | 2017-10-06 18:34:18 +1100 | [diff] [blame] | 341 | { 0x6119, "BCM4345C0" }, /* 003.001.025 */ |
Hans de Goede | b133e0c | 2017-10-13 17:54:01 +0200 | [diff] [blame] | 342 | { 0x230f, "BCM4356A2" }, /* 001.003.015 */ |
Maxime Ripard | 92ffe0d | 2018-12-17 12:04:45 +0800 | [diff] [blame] | 343 | { 0x220e, "BCM20702A1" }, /* 001.002.014 */ |
Marcel Holtmann | 9a0bb57 | 2015-04-05 22:52:19 -0700 | [diff] [blame] | 344 | { } |
| 345 | }; |
| 346 | |
Hans de Goede | fec0de2 | 2018-04-20 14:44:04 +0200 | [diff] [blame] | 347 | static const struct bcm_subver_table bcm_usb_subver_table[] = { |
| 348 | { 0x210b, "BCM43142A0" }, /* 001.001.011 */ |
| 349 | { 0x2112, "BCM4314A0" }, /* 001.001.018 */ |
| 350 | { 0x2118, "BCM20702A0" }, /* 001.001.024 */ |
| 351 | { 0x2126, "BCM4335A0" }, /* 001.001.038 */ |
| 352 | { 0x220e, "BCM20702A1" }, /* 001.002.014 */ |
| 353 | { 0x230f, "BCM4354A2" }, /* 001.003.015 */ |
| 354 | { 0x4106, "BCM4335B0" }, /* 002.001.006 */ |
| 355 | { 0x410e, "BCM20702B0" }, /* 002.001.014 */ |
| 356 | { 0x6109, "BCM4335C0" }, /* 003.001.009 */ |
| 357 | { 0x610c, "BCM4354" }, /* 003.001.012 */ |
| 358 | { } |
| 359 | }; |
| 360 | |
Hans de Goede | 22ac191 | 2018-04-20 14:44:05 +0200 | [diff] [blame] | 361 | int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len, |
| 362 | bool reinit) |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 363 | { |
Hans de Goede | fec0de2 | 2018-04-20 14:44:04 +0200 | [diff] [blame] | 364 | u16 subver, rev, pid, vid; |
Hans de Goede | 2cc6d07 | 2018-04-20 14:44:07 +0200 | [diff] [blame] | 365 | const char *hw_name = "BCM"; |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 366 | struct sk_buff *skb; |
| 367 | struct hci_rp_read_local_version *ver; |
Hans de Goede | fec0de2 | 2018-04-20 14:44:04 +0200 | [diff] [blame] | 368 | const struct bcm_subver_table *bcm_subver_table; |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 369 | int i, err; |
| 370 | |
| 371 | /* Reset */ |
| 372 | err = btbcm_reset(hdev); |
| 373 | if (err) |
| 374 | return err; |
| 375 | |
| 376 | /* Read Local Version Info */ |
| 377 | skb = btbcm_read_local_version(hdev); |
| 378 | if (IS_ERR(skb)) |
| 379 | return PTR_ERR(skb); |
| 380 | |
| 381 | ver = (struct hci_rp_read_local_version *)skb->data; |
| 382 | rev = le16_to_cpu(ver->hci_rev); |
| 383 | subver = le16_to_cpu(ver->lmp_subver); |
| 384 | kfree_skb(skb); |
| 385 | |
Marcel Holtmann | e76dc1d | 2017-08-17 11:02:40 +0200 | [diff] [blame] | 386 | /* Read controller information */ |
Hans de Goede | 22ac191 | 2018-04-20 14:44:05 +0200 | [diff] [blame] | 387 | if (!reinit) { |
| 388 | err = btbcm_read_info(hdev); |
| 389 | if (err) |
| 390 | return err; |
| 391 | } |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 392 | |
Hans de Goede | fec0de2 | 2018-04-20 14:44:04 +0200 | [diff] [blame] | 393 | /* Upper nibble of rev should be between 0 and 3? */ |
| 394 | if (((rev & 0xf000) >> 12) > 3) |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 395 | return 0; |
Hans de Goede | fec0de2 | 2018-04-20 14:44:04 +0200 | [diff] [blame] | 396 | |
| 397 | bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table : |
| 398 | bcm_uart_subver_table; |
| 399 | |
| 400 | for (i = 0; bcm_subver_table[i].name; i++) { |
| 401 | if (subver == bcm_subver_table[i].subver) { |
| 402 | hw_name = bcm_subver_table[i].name; |
| 403 | break; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if (hdev->bus == HCI_USB) { |
| 408 | /* Read USB Product Info */ |
| 409 | skb = btbcm_read_usb_product(hdev); |
| 410 | if (IS_ERR(skb)) |
| 411 | return PTR_ERR(skb); |
| 412 | |
| 413 | vid = get_unaligned_le16(skb->data + 1); |
| 414 | pid = get_unaligned_le16(skb->data + 3); |
| 415 | kfree_skb(skb); |
| 416 | |
| 417 | snprintf(fw_name, len, "brcm/%s-%4.4x-%4.4x.hcd", |
Hans de Goede | 2cc6d07 | 2018-04-20 14:44:07 +0200 | [diff] [blame] | 418 | hw_name, vid, pid); |
Hans de Goede | fec0de2 | 2018-04-20 14:44:04 +0200 | [diff] [blame] | 419 | } else { |
Hans de Goede | 2cc6d07 | 2018-04-20 14:44:07 +0200 | [diff] [blame] | 420 | snprintf(fw_name, len, "brcm/%s.hcd", hw_name); |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 423 | bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u", |
Hans de Goede | 2cc6d07 | 2018-04-20 14:44:07 +0200 | [diff] [blame] | 424 | hw_name, (subver & 0xe000) >> 13, |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 425 | (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff); |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | EXPORT_SYMBOL_GPL(btbcm_initialize); |
| 430 | |
| 431 | int btbcm_finalize(struct hci_dev *hdev) |
| 432 | { |
Hans de Goede | 22ac191 | 2018-04-20 14:44:05 +0200 | [diff] [blame] | 433 | char fw_name[64]; |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 434 | int err; |
| 435 | |
Hans de Goede | 22ac191 | 2018-04-20 14:44:05 +0200 | [diff] [blame] | 436 | /* Re-initialize */ |
| 437 | err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true); |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 438 | if (err) |
| 439 | return err; |
| 440 | |
Frederic Danis | 75e167e | 2015-05-28 11:25:04 +0200 | [diff] [blame] | 441 | btbcm_check_bdaddr(hdev); |
| 442 | |
| 443 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | EXPORT_SYMBOL_GPL(btbcm_finalize); |
| 448 | |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 449 | int btbcm_setup_patchram(struct hci_dev *hdev) |
| 450 | { |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 451 | char fw_name[64]; |
Frederic Danis | 18aeb44 | 2015-05-28 11:25:01 +0200 | [diff] [blame] | 452 | const struct firmware *fw; |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 453 | struct sk_buff *skb; |
Hans de Goede | 59ce569 | 2018-04-20 14:44:06 +0200 | [diff] [blame] | 454 | int err; |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 455 | |
Hans de Goede | 59ce569 | 2018-04-20 14:44:06 +0200 | [diff] [blame] | 456 | /* Initialize */ |
| 457 | err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), false); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 458 | if (err) |
| 459 | return err; |
| 460 | |
Frederic Danis | 18aeb44 | 2015-05-28 11:25:01 +0200 | [diff] [blame] | 461 | err = request_firmware(&fw, fw_name, &hdev->dev); |
| 462 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 463 | bt_dev_info(hdev, "BCM: Patch %s not found", fw_name); |
Petri Gynther | ad750fa1 | 2016-02-10 12:00:46 -0800 | [diff] [blame] | 464 | goto done; |
Frederic Danis | 18aeb44 | 2015-05-28 11:25:01 +0200 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | btbcm_patchram(hdev, fw); |
| 468 | |
| 469 | release_firmware(fw); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 470 | |
Hans de Goede | 59ce569 | 2018-04-20 14:44:06 +0200 | [diff] [blame] | 471 | /* Re-initialize */ |
| 472 | err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true); |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 473 | if (err) |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 474 | return err; |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 475 | |
Marcel Holtmann | 9bc63ca | 2015-10-05 12:43:57 +0200 | [diff] [blame] | 476 | /* Read Local Name */ |
| 477 | skb = btbcm_read_local_name(hdev); |
| 478 | if (IS_ERR(skb)) |
| 479 | return PTR_ERR(skb); |
| 480 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 481 | bt_dev_info(hdev, "%s", (char *)(skb->data + 1)); |
Marcel Holtmann | 9bc63ca | 2015-10-05 12:43:57 +0200 | [diff] [blame] | 482 | kfree_skb(skb); |
| 483 | |
Petri Gynther | ad750fa1 | 2016-02-10 12:00:46 -0800 | [diff] [blame] | 484 | done: |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 485 | btbcm_check_bdaddr(hdev); |
| 486 | |
Marcel Holtmann | 941521e | 2015-04-05 22:52:15 -0700 | [diff] [blame] | 487 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
| 488 | |
Marcel Holtmann | 50862ee | 2015-04-10 14:02:20 -0700 | [diff] [blame] | 489 | return 0; |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 490 | } |
| 491 | EXPORT_SYMBOL_GPL(btbcm_setup_patchram); |
| 492 | |
| 493 | int btbcm_setup_apple(struct hci_dev *hdev) |
| 494 | { |
| 495 | struct sk_buff *skb; |
Marcel Holtmann | b224d3f | 2015-10-03 12:01:08 +0200 | [diff] [blame] | 496 | int err; |
| 497 | |
| 498 | /* Reset */ |
| 499 | err = btbcm_reset(hdev); |
| 500 | if (err) |
| 501 | return err; |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 502 | |
| 503 | /* Read Verbose Config Version Info */ |
| 504 | skb = btbcm_read_verbose_config(hdev); |
Chris Mason | 7bee8b0 | 2015-07-14 16:25:30 -0400 | [diff] [blame] | 505 | if (!IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 506 | bt_dev_info(hdev, "BCM: chip id %u build %4.4u", |
| 507 | skb->data[1], get_unaligned_le16(skb->data + 5)); |
Chris Mason | 7bee8b0 | 2015-07-14 16:25:30 -0400 | [diff] [blame] | 508 | kfree_skb(skb); |
| 509 | } |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 510 | |
Marcel Holtmann | 34cea41 | 2015-10-18 22:48:28 +0200 | [diff] [blame] | 511 | /* Read USB Product Info */ |
| 512 | skb = btbcm_read_usb_product(hdev); |
| 513 | if (!IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 514 | bt_dev_info(hdev, "BCM: product %4.4x:%4.4x", |
| 515 | get_unaligned_le16(skb->data + 1), |
| 516 | get_unaligned_le16(skb->data + 3)); |
Marcel Holtmann | 34cea41 | 2015-10-18 22:48:28 +0200 | [diff] [blame] | 517 | kfree_skb(skb); |
| 518 | } |
| 519 | |
Marcel Holtmann | 4284ecb | 2017-06-10 14:33:16 +0200 | [diff] [blame] | 520 | /* Read Controller Features */ |
| 521 | skb = btbcm_read_controller_features(hdev); |
| 522 | if (!IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 523 | bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]); |
Marcel Holtmann | 4284ecb | 2017-06-10 14:33:16 +0200 | [diff] [blame] | 524 | kfree_skb(skb); |
| 525 | } |
| 526 | |
Marcel Holtmann | 9bc63ca | 2015-10-05 12:43:57 +0200 | [diff] [blame] | 527 | /* Read Local Name */ |
| 528 | skb = btbcm_read_local_name(hdev); |
| 529 | if (!IS_ERR(skb)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 530 | bt_dev_info(hdev, "%s", (char *)(skb->data + 1)); |
Marcel Holtmann | 9bc63ca | 2015-10-05 12:43:57 +0200 | [diff] [blame] | 531 | kfree_skb(skb); |
| 532 | } |
| 533 | |
Marcel Holtmann | 941521e | 2015-04-05 22:52:15 -0700 | [diff] [blame] | 534 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
| 535 | |
Marcel Holtmann | 1c8ba6d | 2015-04-05 22:52:13 -0700 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | EXPORT_SYMBOL_GPL(btbcm_setup_apple); |
| 539 | |
Marcel Holtmann | 4fba30f | 2015-04-05 22:52:10 -0700 | [diff] [blame] | 540 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); |
| 541 | MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION); |
| 542 | MODULE_VERSION(VERSION); |
| 543 | MODULE_LICENSE("GPL"); |