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