.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * |
---|
3 | 4 | * Generic Bluetooth USB driver |
---|
4 | 5 | * |
---|
5 | 6 | * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org> |
---|
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 | 7 | */ |
---|
23 | 8 | |
---|
24 | 9 | #include <linux/dmi.h> |
---|
.. | .. |
---|
26 | 11 | #include <linux/usb.h> |
---|
27 | 12 | #include <linux/usb/quirks.h> |
---|
28 | 13 | #include <linux/firmware.h> |
---|
| 14 | +#include <linux/iopoll.h> |
---|
29 | 15 | #include <linux/of_device.h> |
---|
30 | 16 | #include <linux/of_irq.h> |
---|
31 | 17 | #include <linux/suspend.h> |
---|
| 18 | +#include <linux/gpio/consumer.h> |
---|
32 | 19 | #include <asm/unaligned.h> |
---|
33 | 20 | |
---|
34 | 21 | #include <net/bluetooth/bluetooth.h> |
---|
.. | .. |
---|
69 | 56 | #define BTUSB_BCM2045 0x40000 |
---|
70 | 57 | #define BTUSB_IFNUM_2 0x80000 |
---|
71 | 58 | #define BTUSB_CW6622 0x100000 |
---|
| 59 | +#define BTUSB_MEDIATEK 0x200000 |
---|
| 60 | +#define BTUSB_WIDEBAND_SPEECH 0x400000 |
---|
| 61 | +#define BTUSB_VALID_LE_STATES 0x800000 |
---|
| 62 | +#define BTUSB_QCA_WCN6855 0x1000000 |
---|
72 | 63 | |
---|
73 | 64 | static const struct usb_device_id btusb_table[] = { |
---|
74 | 65 | /* Generic Bluetooth USB device */ |
---|
.. | .. |
---|
264 | 255 | { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, |
---|
265 | 256 | |
---|
266 | 257 | /* QCA ROME chipset */ |
---|
267 | | - { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME }, |
---|
268 | | - { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME }, |
---|
269 | | - { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME }, |
---|
270 | | - { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME }, |
---|
271 | | - { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME }, |
---|
272 | | - { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME }, |
---|
273 | | - { USB_DEVICE(0x0489, 0xe092), .driver_info = BTUSB_QCA_ROME }, |
---|
274 | | - { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME }, |
---|
275 | | - { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME }, |
---|
276 | | - { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME }, |
---|
277 | | - { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME }, |
---|
278 | | - { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME }, |
---|
279 | | - { USB_DEVICE(0x04ca, 0x301a), .driver_info = BTUSB_QCA_ROME }, |
---|
280 | | - { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA_ROME }, |
---|
281 | | - { USB_DEVICE(0x13d3, 0x3496), .driver_info = BTUSB_QCA_ROME }, |
---|
282 | | - { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA_ROME }, |
---|
| 258 | + { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME | |
---|
| 259 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 260 | + { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME | |
---|
| 261 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 262 | + { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME | |
---|
| 263 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 264 | + { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME | |
---|
| 265 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 266 | + { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME | |
---|
| 267 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 268 | + { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME | |
---|
| 269 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 270 | + { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME | |
---|
| 271 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 272 | + { USB_DEVICE(0x0cf3, 0xe500), .driver_info = BTUSB_QCA_ROME | |
---|
| 273 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 274 | + { USB_DEVICE(0x0489, 0xe092), .driver_info = BTUSB_QCA_ROME | |
---|
| 275 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 276 | + { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME | |
---|
| 277 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 278 | + { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME | |
---|
| 279 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 280 | + { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME | |
---|
| 281 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 282 | + { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME | |
---|
| 283 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 284 | + { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME | |
---|
| 285 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 286 | + { USB_DEVICE(0x04ca, 0x301a), .driver_info = BTUSB_QCA_ROME | |
---|
| 287 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 288 | + { USB_DEVICE(0x04ca, 0x3021), .driver_info = BTUSB_QCA_ROME | |
---|
| 289 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 290 | + { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA_ROME | |
---|
| 291 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 292 | + { USB_DEVICE(0x13d3, 0x3496), .driver_info = BTUSB_QCA_ROME | |
---|
| 293 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 294 | + { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA_ROME | |
---|
| 295 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 296 | + |
---|
| 297 | + /* QCA WCN6855 chipset */ |
---|
| 298 | + { USB_DEVICE(0x0cf3, 0xe600), .driver_info = BTUSB_QCA_WCN6855 | |
---|
| 299 | + BTUSB_WIDEBAND_SPEECH }, |
---|
283 | 300 | |
---|
284 | 301 | /* Broadcom BCM2035 */ |
---|
285 | 302 | { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 }, |
---|
.. | .. |
---|
343 | 360 | { USB_DEVICE(0x1286, 0x204e), .driver_info = BTUSB_MARVELL }, |
---|
344 | 361 | |
---|
345 | 362 | /* Intel Bluetooth devices */ |
---|
346 | | - { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_NEW }, |
---|
347 | | - { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_NEW }, |
---|
348 | | - { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_NEW }, |
---|
| 363 | + { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_NEW | |
---|
| 364 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 365 | + BTUSB_VALID_LE_STATES }, |
---|
| 366 | + { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_NEW | |
---|
| 367 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 368 | + { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_NEW | |
---|
| 369 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 370 | + { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_NEW | |
---|
| 371 | + BTUSB_WIDEBAND_SPEECH}, |
---|
349 | 372 | { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, |
---|
350 | 373 | { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL }, |
---|
351 | 374 | { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL }, |
---|
352 | | - { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW }, |
---|
353 | | - { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL }, |
---|
354 | | - { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_NEW }, |
---|
| 375 | + { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW | |
---|
| 376 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 377 | + { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL | |
---|
| 378 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 379 | + { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_NEW | |
---|
| 380 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 381 | + BTUSB_VALID_LE_STATES }, |
---|
| 382 | + { USB_DEVICE(0x10ab, 0x9309), .driver_info = BTUSB_QCA_WCN6855 | |
---|
| 383 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 384 | + BTUSB_VALID_LE_STATES }, |
---|
| 385 | + { USB_DEVICE(0x10ab, 0x9409), .driver_info = BTUSB_QCA_WCN6855 | |
---|
| 386 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 387 | + BTUSB_VALID_LE_STATES }, |
---|
| 388 | + { USB_DEVICE(0x0489, 0xe0d0), .driver_info = BTUSB_QCA_WCN6855 | |
---|
| 389 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 390 | + BTUSB_VALID_LE_STATES }, |
---|
355 | 391 | |
---|
356 | 392 | /* Other Intel Bluetooth devices */ |
---|
357 | 393 | { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01), |
---|
358 | 394 | .driver_info = BTUSB_IGNORE }, |
---|
359 | 395 | |
---|
| 396 | + /* Realtek 8821CE Bluetooth devices */ |
---|
| 397 | + { USB_DEVICE(0x13d3, 0x3529), .driver_info = BTUSB_REALTEK | |
---|
| 398 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 399 | + |
---|
| 400 | + /* Realtek 8822CE Bluetooth devices */ |
---|
| 401 | + { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK | |
---|
| 402 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 403 | + { USB_DEVICE(0x0bda, 0xc822), .driver_info = BTUSB_REALTEK | |
---|
| 404 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 405 | + |
---|
| 406 | + /* Realtek 8852CE Bluetooth devices */ |
---|
| 407 | + { USB_DEVICE(0x04ca, 0x4007), .driver_info = BTUSB_REALTEK | |
---|
| 408 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 409 | + { USB_DEVICE(0x04c5, 0x1675), .driver_info = BTUSB_REALTEK | |
---|
| 410 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 411 | + { USB_DEVICE(0x0cb8, 0xc558), .driver_info = BTUSB_REALTEK | |
---|
| 412 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 413 | + { USB_DEVICE(0x13d3, 0x3587), .driver_info = BTUSB_REALTEK | |
---|
| 414 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 415 | + { USB_DEVICE(0x13d3, 0x3586), .driver_info = BTUSB_REALTEK | |
---|
| 416 | + BTUSB_WIDEBAND_SPEECH }, |
---|
| 417 | + |
---|
360 | 418 | /* Realtek Bluetooth devices */ |
---|
361 | 419 | { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01), |
---|
362 | 420 | .driver_info = BTUSB_REALTEK }, |
---|
| 421 | + |
---|
| 422 | + /* MediaTek Bluetooth devices */ |
---|
| 423 | + { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01), |
---|
| 424 | + .driver_info = BTUSB_MEDIATEK | |
---|
| 425 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 426 | + BTUSB_VALID_LE_STATES }, |
---|
| 427 | + |
---|
| 428 | + /* MediaTek MT7922A Bluetooth devices */ |
---|
| 429 | + { USB_DEVICE(0x0489, 0xe0d8), .driver_info = BTUSB_MEDIATEK | |
---|
| 430 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 431 | + BTUSB_VALID_LE_STATES }, |
---|
| 432 | + { USB_DEVICE(0x0489, 0xe0d9), .driver_info = BTUSB_MEDIATEK | |
---|
| 433 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 434 | + BTUSB_VALID_LE_STATES }, |
---|
| 435 | + { USB_DEVICE(0x0489, 0xe0f5), .driver_info = BTUSB_MEDIATEK | |
---|
| 436 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 437 | + BTUSB_VALID_LE_STATES }, |
---|
| 438 | + { USB_DEVICE(0x13d3, 0x3568), .driver_info = BTUSB_MEDIATEK | |
---|
| 439 | + BTUSB_WIDEBAND_SPEECH | |
---|
| 440 | + BTUSB_VALID_LE_STATES }, |
---|
363 | 441 | |
---|
364 | 442 | /* Additional Realtek 8723AE Bluetooth devices */ |
---|
365 | 443 | { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK }, |
---|
.. | .. |
---|
393 | 471 | |
---|
394 | 472 | /* Additional Realtek 8822CE Bluetooth devices */ |
---|
395 | 473 | { USB_DEVICE(0x04ca, 0x4005), .driver_info = BTUSB_REALTEK }, |
---|
| 474 | + { USB_DEVICE(0x13d3, 0x3548), .driver_info = BTUSB_REALTEK }, |
---|
396 | 475 | |
---|
397 | 476 | /* Silicon Wave based devices */ |
---|
398 | 477 | { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE }, |
---|
.. | .. |
---|
443 | 522 | #define BTUSB_BOOTING 9 |
---|
444 | 523 | #define BTUSB_DIAG_RUNNING 10 |
---|
445 | 524 | #define BTUSB_OOB_WAKE_ENABLED 11 |
---|
| 525 | +#define BTUSB_HW_RESET_ACTIVE 12 |
---|
| 526 | +#define BTUSB_TX_WAIT_VND_EVT 13 |
---|
| 527 | +#define BTUSB_WAKEUP_DISABLE 14 |
---|
| 528 | +#define BTUSB_USE_ALT3_FOR_WBS 15 |
---|
446 | 529 | |
---|
447 | 530 | struct btusb_data { |
---|
448 | 531 | struct hci_dev *hdev; |
---|
.. | .. |
---|
466 | 549 | struct usb_anchor bulk_anchor; |
---|
467 | 550 | struct usb_anchor isoc_anchor; |
---|
468 | 551 | struct usb_anchor diag_anchor; |
---|
| 552 | + struct usb_anchor ctrl_anchor; |
---|
469 | 553 | spinlock_t rxlock; |
---|
470 | 554 | |
---|
471 | 555 | struct sk_buff *evt_skb; |
---|
.. | .. |
---|
480 | 564 | struct usb_endpoint_descriptor *diag_tx_ep; |
---|
481 | 565 | struct usb_endpoint_descriptor *diag_rx_ep; |
---|
482 | 566 | |
---|
| 567 | + struct gpio_desc *reset_gpio; |
---|
| 568 | + |
---|
483 | 569 | __u8 cmdreq_type; |
---|
484 | 570 | __u8 cmdreq; |
---|
485 | 571 | |
---|
486 | 572 | unsigned int sco_num; |
---|
| 573 | + unsigned int air_mode; |
---|
| 574 | + bool usb_alt6_packet_flow; |
---|
487 | 575 | int isoc_altsetting; |
---|
488 | 576 | int suspend_count; |
---|
489 | 577 | |
---|
.. | .. |
---|
493 | 581 | int (*setup_on_usb)(struct hci_dev *hdev); |
---|
494 | 582 | |
---|
495 | 583 | int oob_wake_irq; /* irq for out-of-band wake-on-bt */ |
---|
| 584 | + unsigned cmd_timeout_cnt; |
---|
496 | 585 | }; |
---|
| 586 | + |
---|
| 587 | +static void btusb_intel_cmd_timeout(struct hci_dev *hdev) |
---|
| 588 | +{ |
---|
| 589 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 590 | + struct gpio_desc *reset_gpio = data->reset_gpio; |
---|
| 591 | + |
---|
| 592 | + if (++data->cmd_timeout_cnt < 5) |
---|
| 593 | + return; |
---|
| 594 | + |
---|
| 595 | + if (!reset_gpio) { |
---|
| 596 | + bt_dev_err(hdev, "No way to reset. Ignoring and continuing"); |
---|
| 597 | + return; |
---|
| 598 | + } |
---|
| 599 | + |
---|
| 600 | + /* |
---|
| 601 | + * Toggle the hard reset line if the platform provides one. The reset |
---|
| 602 | + * is going to yank the device off the USB and then replug. So doing |
---|
| 603 | + * once is enough. The cleanup is handled correctly on the way out |
---|
| 604 | + * (standard USB disconnect), and the new device is detected cleanly |
---|
| 605 | + * and bound to the driver again like it should be. |
---|
| 606 | + */ |
---|
| 607 | + if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
---|
| 608 | + bt_dev_err(hdev, "last reset failed? Not resetting again"); |
---|
| 609 | + return; |
---|
| 610 | + } |
---|
| 611 | + |
---|
| 612 | + bt_dev_err(hdev, "Initiating HW reset via gpio"); |
---|
| 613 | + gpiod_set_value_cansleep(reset_gpio, 1); |
---|
| 614 | + msleep(100); |
---|
| 615 | + gpiod_set_value_cansleep(reset_gpio, 0); |
---|
| 616 | +} |
---|
| 617 | + |
---|
| 618 | +static void btusb_rtl_cmd_timeout(struct hci_dev *hdev) |
---|
| 619 | +{ |
---|
| 620 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 621 | + struct gpio_desc *reset_gpio = data->reset_gpio; |
---|
| 622 | + |
---|
| 623 | + if (++data->cmd_timeout_cnt < 5) |
---|
| 624 | + return; |
---|
| 625 | + |
---|
| 626 | + if (!reset_gpio) { |
---|
| 627 | + bt_dev_err(hdev, "No gpio to reset Realtek device, ignoring"); |
---|
| 628 | + return; |
---|
| 629 | + } |
---|
| 630 | + |
---|
| 631 | + /* Toggle the hard reset line. The Realtek device is going to |
---|
| 632 | + * yank itself off the USB and then replug. The cleanup is handled |
---|
| 633 | + * correctly on the way out (standard USB disconnect), and the new |
---|
| 634 | + * device is detected cleanly and bound to the driver again like |
---|
| 635 | + * it should be. |
---|
| 636 | + */ |
---|
| 637 | + if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
---|
| 638 | + bt_dev_err(hdev, "last reset failed? Not resetting again"); |
---|
| 639 | + return; |
---|
| 640 | + } |
---|
| 641 | + |
---|
| 642 | + bt_dev_err(hdev, "Reset Realtek device via gpio"); |
---|
| 643 | + gpiod_set_value_cansleep(reset_gpio, 1); |
---|
| 644 | + msleep(200); |
---|
| 645 | + gpiod_set_value_cansleep(reset_gpio, 0); |
---|
| 646 | +} |
---|
| 647 | + |
---|
| 648 | +static void btusb_qca_cmd_timeout(struct hci_dev *hdev) |
---|
| 649 | +{ |
---|
| 650 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 651 | + int err; |
---|
| 652 | + |
---|
| 653 | + if (++data->cmd_timeout_cnt < 5) |
---|
| 654 | + return; |
---|
| 655 | + |
---|
| 656 | + bt_dev_err(hdev, "Multiple cmd timeouts seen. Resetting usb device."); |
---|
| 657 | + /* This is not an unbalanced PM reference since the device will reset */ |
---|
| 658 | + err = usb_autopm_get_interface(data->intf); |
---|
| 659 | + if (!err) |
---|
| 660 | + usb_queue_reset_device(data->intf); |
---|
| 661 | + else |
---|
| 662 | + bt_dev_err(hdev, "Failed usb_autopm_get_interface with %d", err); |
---|
| 663 | +} |
---|
497 | 664 | |
---|
498 | 665 | static inline void btusb_free_frags(struct btusb_data *data) |
---|
499 | 666 | { |
---|
.. | .. |
---|
501 | 668 | |
---|
502 | 669 | spin_lock_irqsave(&data->rxlock, flags); |
---|
503 | 670 | |
---|
504 | | - kfree_skb(data->evt_skb); |
---|
| 671 | + dev_kfree_skb_irq(data->evt_skb); |
---|
505 | 672 | data->evt_skb = NULL; |
---|
506 | 673 | |
---|
507 | | - kfree_skb(data->acl_skb); |
---|
| 674 | + dev_kfree_skb_irq(data->acl_skb); |
---|
508 | 675 | data->acl_skb = NULL; |
---|
509 | 676 | |
---|
510 | | - kfree_skb(data->sco_skb); |
---|
| 677 | + dev_kfree_skb_irq(data->sco_skb); |
---|
511 | 678 | data->sco_skb = NULL; |
---|
512 | 679 | |
---|
513 | 680 | spin_unlock_irqrestore(&data->rxlock, flags); |
---|
.. | .. |
---|
912 | 1079 | } |
---|
913 | 1080 | } |
---|
914 | 1081 | |
---|
| 1082 | +static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len, |
---|
| 1083 | + int mtu, struct btusb_data *data) |
---|
| 1084 | +{ |
---|
| 1085 | + int i, offset = 0; |
---|
| 1086 | + unsigned int interval; |
---|
| 1087 | + |
---|
| 1088 | + BT_DBG("len %d mtu %d", len, mtu); |
---|
| 1089 | + |
---|
| 1090 | + /* For mSBC ALT 6 setting the host will send the packet at continuous |
---|
| 1091 | + * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting |
---|
| 1092 | + * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets. |
---|
| 1093 | + * To maintain the rate we send 63bytes of usb packets alternatively for |
---|
| 1094 | + * 7ms and 8ms to maintain the rate as 7.5ms. |
---|
| 1095 | + */ |
---|
| 1096 | + if (data->usb_alt6_packet_flow) { |
---|
| 1097 | + interval = 7; |
---|
| 1098 | + data->usb_alt6_packet_flow = false; |
---|
| 1099 | + } else { |
---|
| 1100 | + interval = 6; |
---|
| 1101 | + data->usb_alt6_packet_flow = true; |
---|
| 1102 | + } |
---|
| 1103 | + |
---|
| 1104 | + for (i = 0; i < interval; i++) { |
---|
| 1105 | + urb->iso_frame_desc[i].offset = offset; |
---|
| 1106 | + urb->iso_frame_desc[i].length = offset; |
---|
| 1107 | + } |
---|
| 1108 | + |
---|
| 1109 | + if (len && i < BTUSB_MAX_ISOC_FRAMES) { |
---|
| 1110 | + urb->iso_frame_desc[i].offset = offset; |
---|
| 1111 | + urb->iso_frame_desc[i].length = len; |
---|
| 1112 | + i++; |
---|
| 1113 | + } |
---|
| 1114 | + |
---|
| 1115 | + urb->number_of_packets = i; |
---|
| 1116 | +} |
---|
| 1117 | + |
---|
915 | 1118 | static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu) |
---|
916 | 1119 | { |
---|
917 | 1120 | int i, offset = 0; |
---|
.. | .. |
---|
1143 | 1346 | |
---|
1144 | 1347 | data->intf->needs_remote_wakeup = 1; |
---|
1145 | 1348 | |
---|
| 1349 | + /* Disable device remote wakeup when host is suspended |
---|
| 1350 | + * For Realtek chips, global suspend without |
---|
| 1351 | + * SET_FEATURE (DEVICE_REMOTE_WAKEUP) can save more power in device. |
---|
| 1352 | + */ |
---|
| 1353 | + if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) |
---|
| 1354 | + device_wakeup_disable(&data->udev->dev); |
---|
| 1355 | + |
---|
1146 | 1356 | if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) |
---|
1147 | 1357 | goto done; |
---|
1148 | 1358 | |
---|
.. | .. |
---|
1181 | 1391 | usb_kill_anchored_urbs(&data->bulk_anchor); |
---|
1182 | 1392 | usb_kill_anchored_urbs(&data->isoc_anchor); |
---|
1183 | 1393 | usb_kill_anchored_urbs(&data->diag_anchor); |
---|
| 1394 | + usb_kill_anchored_urbs(&data->ctrl_anchor); |
---|
1184 | 1395 | } |
---|
1185 | 1396 | |
---|
1186 | 1397 | static int btusb_close(struct hci_dev *hdev) |
---|
.. | .. |
---|
1206 | 1417 | goto failed; |
---|
1207 | 1418 | |
---|
1208 | 1419 | data->intf->needs_remote_wakeup = 0; |
---|
| 1420 | + |
---|
| 1421 | + /* Enable remote wake up for auto-suspend */ |
---|
| 1422 | + if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) |
---|
| 1423 | + data->intf->needs_remote_wakeup = 1; |
---|
| 1424 | + |
---|
1209 | 1425 | usb_autopm_put_interface(data->intf); |
---|
1210 | 1426 | |
---|
1211 | 1427 | failed: |
---|
.. | .. |
---|
1302 | 1518 | |
---|
1303 | 1519 | urb->transfer_flags = URB_ISO_ASAP; |
---|
1304 | 1520 | |
---|
1305 | | - __fill_isoc_descriptor(urb, skb->len, |
---|
1306 | | - le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); |
---|
1307 | | - |
---|
| 1521 | + if (data->isoc_altsetting == 6) |
---|
| 1522 | + __fill_isoc_descriptor_msbc(urb, skb->len, |
---|
| 1523 | + le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize), |
---|
| 1524 | + data); |
---|
| 1525 | + else |
---|
| 1526 | + __fill_isoc_descriptor(urb, skb->len, |
---|
| 1527 | + le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); |
---|
1308 | 1528 | skb->dev = (void *)hdev; |
---|
1309 | 1529 | |
---|
1310 | 1530 | return urb; |
---|
.. | .. |
---|
1400 | 1620 | |
---|
1401 | 1621 | if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) { |
---|
1402 | 1622 | data->sco_num = hci_conn_num(hdev, SCO_LINK); |
---|
| 1623 | + data->air_mode = evt; |
---|
1403 | 1624 | schedule_work(&data->work); |
---|
1404 | 1625 | } |
---|
1405 | 1626 | } |
---|
.. | .. |
---|
1447 | 1668 | return 0; |
---|
1448 | 1669 | } |
---|
1449 | 1670 | |
---|
| 1671 | +static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts) |
---|
| 1672 | +{ |
---|
| 1673 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 1674 | + int err; |
---|
| 1675 | + |
---|
| 1676 | + if (data->isoc_altsetting != new_alts) { |
---|
| 1677 | + unsigned long flags; |
---|
| 1678 | + |
---|
| 1679 | + clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
---|
| 1680 | + usb_kill_anchored_urbs(&data->isoc_anchor); |
---|
| 1681 | + |
---|
| 1682 | + /* When isochronous alternate setting needs to be |
---|
| 1683 | + * changed, because SCO connection has been added |
---|
| 1684 | + * or removed, a packet fragment may be left in the |
---|
| 1685 | + * reassembling state. This could lead to wrongly |
---|
| 1686 | + * assembled fragments. |
---|
| 1687 | + * |
---|
| 1688 | + * Clear outstanding fragment when selecting a new |
---|
| 1689 | + * alternate setting. |
---|
| 1690 | + */ |
---|
| 1691 | + spin_lock_irqsave(&data->rxlock, flags); |
---|
| 1692 | + dev_kfree_skb_irq(data->sco_skb); |
---|
| 1693 | + data->sco_skb = NULL; |
---|
| 1694 | + spin_unlock_irqrestore(&data->rxlock, flags); |
---|
| 1695 | + |
---|
| 1696 | + err = __set_isoc_interface(hdev, new_alts); |
---|
| 1697 | + if (err < 0) |
---|
| 1698 | + return err; |
---|
| 1699 | + } |
---|
| 1700 | + |
---|
| 1701 | + if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
---|
| 1702 | + if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0) |
---|
| 1703 | + clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
---|
| 1704 | + else |
---|
| 1705 | + btusb_submit_isoc_urb(hdev, GFP_KERNEL); |
---|
| 1706 | + } |
---|
| 1707 | + |
---|
| 1708 | + return 0; |
---|
| 1709 | +} |
---|
| 1710 | + |
---|
| 1711 | +static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data, |
---|
| 1712 | + int alt) |
---|
| 1713 | +{ |
---|
| 1714 | + struct usb_interface *intf = data->isoc; |
---|
| 1715 | + int i; |
---|
| 1716 | + |
---|
| 1717 | + BT_DBG("Looking for Alt no :%d", alt); |
---|
| 1718 | + |
---|
| 1719 | + if (!intf) |
---|
| 1720 | + return NULL; |
---|
| 1721 | + |
---|
| 1722 | + for (i = 0; i < intf->num_altsetting; i++) { |
---|
| 1723 | + if (intf->altsetting[i].desc.bAlternateSetting == alt) |
---|
| 1724 | + return &intf->altsetting[i]; |
---|
| 1725 | + } |
---|
| 1726 | + |
---|
| 1727 | + return NULL; |
---|
| 1728 | +} |
---|
| 1729 | + |
---|
1450 | 1730 | static void btusb_work(struct work_struct *work) |
---|
1451 | 1731 | { |
---|
1452 | 1732 | struct btusb_data *data = container_of(work, struct btusb_data, work); |
---|
1453 | 1733 | struct hci_dev *hdev = data->hdev; |
---|
1454 | | - int new_alts; |
---|
| 1734 | + int new_alts = 0; |
---|
1455 | 1735 | int err; |
---|
1456 | 1736 | |
---|
1457 | 1737 | if (data->sco_num > 0) { |
---|
.. | .. |
---|
1466 | 1746 | set_bit(BTUSB_DID_ISO_RESUME, &data->flags); |
---|
1467 | 1747 | } |
---|
1468 | 1748 | |
---|
1469 | | - if (hdev->voice_setting & 0x0020) { |
---|
1470 | | - static const int alts[3] = { 2, 4, 5 }; |
---|
| 1749 | + if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) { |
---|
| 1750 | + if (hdev->voice_setting & 0x0020) { |
---|
| 1751 | + static const int alts[3] = { 2, 4, 5 }; |
---|
1471 | 1752 | |
---|
1472 | | - new_alts = alts[data->sco_num - 1]; |
---|
1473 | | - } else { |
---|
1474 | | - new_alts = data->sco_num; |
---|
1475 | | - } |
---|
1476 | | - |
---|
1477 | | - if (data->isoc_altsetting != new_alts) { |
---|
1478 | | - unsigned long flags; |
---|
1479 | | - |
---|
1480 | | - clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
---|
1481 | | - usb_kill_anchored_urbs(&data->isoc_anchor); |
---|
1482 | | - |
---|
1483 | | - /* When isochronous alternate setting needs to be |
---|
1484 | | - * changed, because SCO connection has been added |
---|
1485 | | - * or removed, a packet fragment may be left in the |
---|
1486 | | - * reassembling state. This could lead to wrongly |
---|
1487 | | - * assembled fragments. |
---|
1488 | | - * |
---|
1489 | | - * Clear outstanding fragment when selecting a new |
---|
1490 | | - * alternate setting. |
---|
| 1753 | + new_alts = alts[data->sco_num - 1]; |
---|
| 1754 | + } else { |
---|
| 1755 | + new_alts = data->sco_num; |
---|
| 1756 | + } |
---|
| 1757 | + } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) { |
---|
| 1758 | + /* Bluetooth USB spec recommends alt 6 (63 bytes), but |
---|
| 1759 | + * many adapters do not support it. Alt 1 appears to |
---|
| 1760 | + * work for all adapters that do not have alt 6, and |
---|
| 1761 | + * which work with WBS at all. Some devices prefer |
---|
| 1762 | + * alt 3 (HCI payload >= 60 Bytes let air packet |
---|
| 1763 | + * data satisfy 60 bytes), requiring |
---|
| 1764 | + * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72 |
---|
| 1765 | + * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1. |
---|
1491 | 1766 | */ |
---|
1492 | | - spin_lock_irqsave(&data->rxlock, flags); |
---|
1493 | | - kfree_skb(data->sco_skb); |
---|
1494 | | - data->sco_skb = NULL; |
---|
1495 | | - spin_unlock_irqrestore(&data->rxlock, flags); |
---|
1496 | | - |
---|
1497 | | - if (__set_isoc_interface(hdev, new_alts) < 0) |
---|
1498 | | - return; |
---|
1499 | | - } |
---|
1500 | | - |
---|
1501 | | - if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
---|
1502 | | - if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0) |
---|
1503 | | - clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
---|
| 1767 | + if (btusb_find_altsetting(data, 6)) |
---|
| 1768 | + new_alts = 6; |
---|
| 1769 | + else if (btusb_find_altsetting(data, 3) && |
---|
| 1770 | + hdev->sco_mtu >= 72 && |
---|
| 1771 | + test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags)) |
---|
| 1772 | + new_alts = 3; |
---|
1504 | 1773 | else |
---|
1505 | | - btusb_submit_isoc_urb(hdev, GFP_KERNEL); |
---|
| 1774 | + new_alts = 1; |
---|
1506 | 1775 | } |
---|
| 1776 | + |
---|
| 1777 | + if (btusb_switch_alt_setting(hdev, new_alts) < 0) |
---|
| 1778 | + bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts); |
---|
1507 | 1779 | } else { |
---|
1508 | 1780 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
---|
1509 | 1781 | usb_kill_anchored_urbs(&data->isoc_anchor); |
---|
.. | .. |
---|
1544 | 1816 | |
---|
1545 | 1817 | static int btusb_setup_csr(struct hci_dev *hdev) |
---|
1546 | 1818 | { |
---|
| 1819 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 1820 | + u16 bcdDevice = le16_to_cpu(data->udev->descriptor.bcdDevice); |
---|
1547 | 1821 | struct hci_rp_read_local_version *rp; |
---|
1548 | 1822 | struct sk_buff *skb; |
---|
| 1823 | + bool is_fake = false; |
---|
1549 | 1824 | |
---|
1550 | 1825 | BT_DBG("%s", hdev->name); |
---|
1551 | 1826 | |
---|
.. | .. |
---|
1565 | 1840 | |
---|
1566 | 1841 | rp = (struct hci_rp_read_local_version *)skb->data; |
---|
1567 | 1842 | |
---|
1568 | | - /* Detect controllers which aren't real CSR ones. */ |
---|
| 1843 | + bt_dev_info(hdev, "CSR: Setting up dongle with HCI ver=%u rev=%04x; LMP ver=%u subver=%04x; manufacturer=%u", |
---|
| 1844 | + le16_to_cpu(rp->hci_ver), le16_to_cpu(rp->hci_rev), |
---|
| 1845 | + le16_to_cpu(rp->lmp_ver), le16_to_cpu(rp->lmp_subver), |
---|
| 1846 | + le16_to_cpu(rp->manufacturer)); |
---|
| 1847 | + |
---|
| 1848 | + /* Detect a wide host of Chinese controllers that aren't CSR. |
---|
| 1849 | + * |
---|
| 1850 | + * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891 |
---|
| 1851 | + * |
---|
| 1852 | + * The main thing they have in common is that these are really popular low-cost |
---|
| 1853 | + * options that support newer Bluetooth versions but rely on heavy VID/PID |
---|
| 1854 | + * squatting of this poor old Bluetooth 1.1 device. Even sold as such. |
---|
| 1855 | + * |
---|
| 1856 | + * We detect actual CSR devices by checking that the HCI manufacturer code |
---|
| 1857 | + * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and |
---|
| 1858 | + * HCI rev values always match. As they both store the firmware number. |
---|
| 1859 | + */ |
---|
1569 | 1860 | if (le16_to_cpu(rp->manufacturer) != 10 || |
---|
1570 | | - le16_to_cpu(rp->lmp_subver) == 0x0c5c) { |
---|
| 1861 | + le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver)) |
---|
| 1862 | + is_fake = true; |
---|
| 1863 | + |
---|
| 1864 | + /* Known legit CSR firmware build numbers and their supported BT versions: |
---|
| 1865 | + * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e |
---|
| 1866 | + * - 1.2 (0x2) -> 0x04d9, 0x0529 |
---|
| 1867 | + * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c |
---|
| 1868 | + * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External) |
---|
| 1869 | + * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb |
---|
| 1870 | + * |
---|
| 1871 | + * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that |
---|
| 1872 | + * support BT 1.1 only; so it's a dead giveaway when some |
---|
| 1873 | + * third-party BT 4.0 dongle reuses it. |
---|
| 1874 | + */ |
---|
| 1875 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x034e && |
---|
| 1876 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_1) |
---|
| 1877 | + is_fake = true; |
---|
| 1878 | + |
---|
| 1879 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 && |
---|
| 1880 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_2) |
---|
| 1881 | + is_fake = true; |
---|
| 1882 | + |
---|
| 1883 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c && |
---|
| 1884 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_0) |
---|
| 1885 | + is_fake = true; |
---|
| 1886 | + |
---|
| 1887 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 && |
---|
| 1888 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_1) |
---|
| 1889 | + is_fake = true; |
---|
| 1890 | + |
---|
| 1891 | + else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb && |
---|
| 1892 | + le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_4_0) |
---|
| 1893 | + is_fake = true; |
---|
| 1894 | + |
---|
| 1895 | + /* Other clones which beat all the above checks */ |
---|
| 1896 | + else if (bcdDevice == 0x0134 && |
---|
| 1897 | + le16_to_cpu(rp->lmp_subver) == 0x0c5c && |
---|
| 1898 | + le16_to_cpu(rp->hci_ver) == BLUETOOTH_VER_2_0) |
---|
| 1899 | + is_fake = true; |
---|
| 1900 | + |
---|
| 1901 | + if (is_fake) { |
---|
| 1902 | + bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds..."); |
---|
| 1903 | + |
---|
| 1904 | + /* Generally these clones have big discrepancies between |
---|
| 1905 | + * advertised features and what's actually supported. |
---|
| 1906 | + * Probably will need to be expanded in the future; |
---|
| 1907 | + * without these the controller will lock up. |
---|
| 1908 | + */ |
---|
| 1909 | + set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
---|
| 1910 | + set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks); |
---|
| 1911 | + |
---|
1571 | 1912 | /* Clear the reset quirk since this is not an actual |
---|
1572 | 1913 | * early Bluetooth 1.1 device from CSR. |
---|
1573 | 1914 | */ |
---|
1574 | 1915 | clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
---|
1575 | | - |
---|
1576 | | - /* These fake CSR controllers have all a broken |
---|
1577 | | - * stored link key handling and so just disable it. |
---|
1578 | | - */ |
---|
1579 | | - set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
---|
| 1916 | + clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
---|
1580 | 1917 | } |
---|
1581 | 1918 | |
---|
1582 | 1919 | kfree_skb(skb); |
---|
.. | .. |
---|
1854 | 2191 | if (err) |
---|
1855 | 2192 | return err; |
---|
1856 | 2193 | |
---|
1857 | | - bt_dev_info(hdev, "Intel firmware patch completed and activated"); |
---|
| 2194 | + /* Need build number for downloaded fw patches in |
---|
| 2195 | + * every power-on boot |
---|
| 2196 | + */ |
---|
| 2197 | + err = btintel_read_version(hdev, &ver); |
---|
| 2198 | + if (err) |
---|
| 2199 | + return err; |
---|
| 2200 | + bt_dev_info(hdev, "Intel BT fw patch 0x%02x completed & activated", |
---|
| 2201 | + ver.fw_patch_num); |
---|
1858 | 2202 | |
---|
1859 | 2203 | goto complete; |
---|
1860 | 2204 | |
---|
.. | .. |
---|
1936 | 2280 | if (len != sizeof(*evt)) |
---|
1937 | 2281 | return; |
---|
1938 | 2282 | |
---|
1939 | | - if (test_and_clear_bit(BTUSB_BOOTING, &data->flags)) { |
---|
1940 | | - smp_mb__after_atomic(); |
---|
| 2283 | + if (test_and_clear_bit(BTUSB_BOOTING, &data->flags)) |
---|
1941 | 2284 | wake_up_bit(&data->flags, BTUSB_BOOTING); |
---|
1942 | | - } |
---|
1943 | 2285 | } |
---|
1944 | 2286 | |
---|
1945 | 2287 | static void btusb_intel_secure_send_result(struct btusb_data *data, |
---|
.. | .. |
---|
1954 | 2296 | set_bit(BTUSB_FIRMWARE_FAILED, &data->flags); |
---|
1955 | 2297 | |
---|
1956 | 2298 | if (test_and_clear_bit(BTUSB_DOWNLOADING, &data->flags) && |
---|
1957 | | - test_bit(BTUSB_FIRMWARE_LOADED, &data->flags)) { |
---|
1958 | | - smp_mb__after_atomic(); |
---|
| 2299 | + test_bit(BTUSB_FIRMWARE_LOADED, &data->flags)) |
---|
1959 | 2300 | wake_up_bit(&data->flags, BTUSB_DOWNLOADING); |
---|
1960 | | - } |
---|
1961 | 2301 | } |
---|
1962 | 2302 | |
---|
1963 | 2303 | static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb) |
---|
.. | .. |
---|
2085 | 2425 | return true; |
---|
2086 | 2426 | } |
---|
2087 | 2427 | |
---|
2088 | | -static int btusb_setup_intel_new(struct hci_dev *hdev) |
---|
| 2428 | +static int btusb_intel_download_firmware(struct hci_dev *hdev, |
---|
| 2429 | + struct intel_version *ver, |
---|
| 2430 | + struct intel_boot_params *params, |
---|
| 2431 | + u32 *boot_param) |
---|
2089 | 2432 | { |
---|
2090 | | - struct btusb_data *data = hci_get_drvdata(hdev); |
---|
2091 | | - struct intel_version ver; |
---|
2092 | | - struct intel_boot_params params; |
---|
2093 | 2433 | const struct firmware *fw; |
---|
2094 | | - u32 boot_param; |
---|
2095 | 2434 | char fwname[64]; |
---|
2096 | | - ktime_t calltime, delta, rettime; |
---|
2097 | | - unsigned long long duration; |
---|
2098 | 2435 | int err; |
---|
| 2436 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
2099 | 2437 | |
---|
2100 | | - BT_DBG("%s", hdev->name); |
---|
2101 | | - |
---|
2102 | | - /* Set the default boot parameter to 0x0 and it is updated to |
---|
2103 | | - * SKU specific boot parameter after reading Intel_Write_Boot_Params |
---|
2104 | | - * command while downloading the firmware. |
---|
2105 | | - */ |
---|
2106 | | - boot_param = 0x00000000; |
---|
2107 | | - |
---|
2108 | | - calltime = ktime_get(); |
---|
2109 | | - |
---|
2110 | | - /* Read the Intel version information to determine if the device |
---|
2111 | | - * is in bootloader mode or if it already has operational firmware |
---|
2112 | | - * loaded. |
---|
2113 | | - */ |
---|
2114 | | - err = btintel_read_version(hdev, &ver); |
---|
2115 | | - if (err) |
---|
2116 | | - return err; |
---|
| 2438 | + if (!ver || !params) |
---|
| 2439 | + return -EINVAL; |
---|
2117 | 2440 | |
---|
2118 | 2441 | /* The hardware platform number has a fixed value of 0x37 and |
---|
2119 | 2442 | * for now only accept this single value. |
---|
2120 | 2443 | */ |
---|
2121 | | - if (ver.hw_platform != 0x37) { |
---|
| 2444 | + if (ver->hw_platform != 0x37) { |
---|
2122 | 2445 | bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)", |
---|
2123 | | - ver.hw_platform); |
---|
| 2446 | + ver->hw_platform); |
---|
2124 | 2447 | return -EINVAL; |
---|
2125 | 2448 | } |
---|
2126 | 2449 | |
---|
.. | .. |
---|
2130 | 2453 | * This check has been put in place to ensure correct forward |
---|
2131 | 2454 | * compatibility options when newer hardware variants come along. |
---|
2132 | 2455 | */ |
---|
2133 | | - switch (ver.hw_variant) { |
---|
| 2456 | + switch (ver->hw_variant) { |
---|
2134 | 2457 | case 0x0b: /* SfP */ |
---|
2135 | 2458 | case 0x0c: /* WsP */ |
---|
2136 | 2459 | case 0x11: /* JfP */ |
---|
.. | .. |
---|
2140 | 2463 | break; |
---|
2141 | 2464 | default: |
---|
2142 | 2465 | bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)", |
---|
2143 | | - ver.hw_variant); |
---|
| 2466 | + ver->hw_variant); |
---|
2144 | 2467 | return -EINVAL; |
---|
2145 | 2468 | } |
---|
2146 | 2469 | |
---|
2147 | | - btintel_version_info(hdev, &ver); |
---|
| 2470 | + btintel_version_info(hdev, ver); |
---|
2148 | 2471 | |
---|
2149 | 2472 | /* The firmware variant determines if the device is in bootloader |
---|
2150 | 2473 | * mode or is running operational firmware. The value 0x06 identifies |
---|
.. | .. |
---|
2159 | 2482 | * It is not possible to use the Secure Boot Parameters in this |
---|
2160 | 2483 | * case since that command is only available in bootloader mode. |
---|
2161 | 2484 | */ |
---|
2162 | | - if (ver.fw_variant == 0x23) { |
---|
| 2485 | + if (ver->fw_variant == 0x23) { |
---|
2163 | 2486 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
---|
2164 | 2487 | btintel_check_bdaddr(hdev); |
---|
2165 | 2488 | return 0; |
---|
.. | .. |
---|
2168 | 2491 | /* If the device is not in bootloader mode, then the only possible |
---|
2169 | 2492 | * choice is to return an error and abort the device initialization. |
---|
2170 | 2493 | */ |
---|
2171 | | - if (ver.fw_variant != 0x06) { |
---|
| 2494 | + if (ver->fw_variant != 0x06) { |
---|
2172 | 2495 | bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)", |
---|
2173 | | - ver.fw_variant); |
---|
| 2496 | + ver->fw_variant); |
---|
2174 | 2497 | return -ENODEV; |
---|
2175 | 2498 | } |
---|
2176 | 2499 | |
---|
2177 | 2500 | /* Read the secure boot parameters to identify the operating |
---|
2178 | 2501 | * details of the bootloader. |
---|
2179 | 2502 | */ |
---|
2180 | | - err = btintel_read_boot_params(hdev, ¶ms); |
---|
| 2503 | + err = btintel_read_boot_params(hdev, params); |
---|
2181 | 2504 | if (err) |
---|
2182 | 2505 | return err; |
---|
2183 | 2506 | |
---|
.. | .. |
---|
2185 | 2508 | * with a command complete event. If the boot parameters indicate |
---|
2186 | 2509 | * that this bootloader does not send them, then abort the setup. |
---|
2187 | 2510 | */ |
---|
2188 | | - if (params.limited_cce != 0x00) { |
---|
| 2511 | + if (params->limited_cce != 0x00) { |
---|
2189 | 2512 | bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)", |
---|
2190 | | - params.limited_cce); |
---|
| 2513 | + params->limited_cce); |
---|
2191 | 2514 | return -EINVAL; |
---|
2192 | 2515 | } |
---|
2193 | 2516 | |
---|
2194 | 2517 | /* If the OTP has no valid Bluetooth device address, then there will |
---|
2195 | 2518 | * also be no valid address for the operational firmware. |
---|
2196 | 2519 | */ |
---|
2197 | | - if (!bacmp(¶ms.otp_bdaddr, BDADDR_ANY)) { |
---|
| 2520 | + if (!bacmp(¶ms->otp_bdaddr, BDADDR_ANY)) { |
---|
2198 | 2521 | bt_dev_info(hdev, "No device address configured"); |
---|
2199 | 2522 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); |
---|
2200 | 2523 | } |
---|
.. | .. |
---|
2220 | 2543 | * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi. |
---|
2221 | 2544 | * |
---|
2222 | 2545 | */ |
---|
2223 | | - err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, fwname, |
---|
| 2546 | + err = btusb_setup_intel_new_get_fw_name(ver, params, fwname, |
---|
2224 | 2547 | sizeof(fwname), "sfi"); |
---|
2225 | 2548 | if (!err) { |
---|
2226 | 2549 | bt_dev_err(hdev, "Unsupported Intel firmware naming"); |
---|
.. | .. |
---|
2235 | 2558 | |
---|
2236 | 2559 | bt_dev_info(hdev, "Found device firmware: %s", fwname); |
---|
2237 | 2560 | |
---|
2238 | | - /* Save the DDC file name for later use to apply once the firmware |
---|
2239 | | - * downloading is done. |
---|
2240 | | - */ |
---|
2241 | | - err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, fwname, |
---|
2242 | | - sizeof(fwname), "ddc"); |
---|
2243 | | - if (!err) { |
---|
2244 | | - bt_dev_err(hdev, "Unsupported Intel firmware naming"); |
---|
2245 | | - return -EINVAL; |
---|
2246 | | - } |
---|
2247 | | - |
---|
2248 | 2561 | if (fw->size < 644) { |
---|
2249 | 2562 | bt_dev_err(hdev, "Invalid size of firmware file (%zu)", |
---|
2250 | 2563 | fw->size); |
---|
.. | .. |
---|
2255 | 2568 | set_bit(BTUSB_DOWNLOADING, &data->flags); |
---|
2256 | 2569 | |
---|
2257 | 2570 | /* Start firmware downloading and get boot parameter */ |
---|
2258 | | - err = btintel_download_firmware(hdev, fw, &boot_param); |
---|
2259 | | - if (err < 0) |
---|
| 2571 | + err = btintel_download_firmware(hdev, fw, boot_param); |
---|
| 2572 | + if (err < 0) { |
---|
| 2573 | + /* When FW download fails, send Intel Reset to retry |
---|
| 2574 | + * FW download. |
---|
| 2575 | + */ |
---|
| 2576 | + btintel_reset_to_bootloader(hdev); |
---|
2260 | 2577 | goto done; |
---|
2261 | | - |
---|
| 2578 | + } |
---|
2262 | 2579 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
---|
2263 | 2580 | |
---|
2264 | 2581 | bt_dev_info(hdev, "Waiting for firmware download to complete"); |
---|
.. | .. |
---|
2285 | 2602 | if (err) { |
---|
2286 | 2603 | bt_dev_err(hdev, "Firmware loading timeout"); |
---|
2287 | 2604 | err = -ETIMEDOUT; |
---|
| 2605 | + btintel_reset_to_bootloader(hdev); |
---|
2288 | 2606 | goto done; |
---|
2289 | 2607 | } |
---|
2290 | 2608 | |
---|
.. | .. |
---|
2294 | 2612 | goto done; |
---|
2295 | 2613 | } |
---|
2296 | 2614 | |
---|
| 2615 | +done: |
---|
| 2616 | + release_firmware(fw); |
---|
| 2617 | + return err; |
---|
| 2618 | +} |
---|
| 2619 | + |
---|
| 2620 | +static int btusb_setup_intel_new(struct hci_dev *hdev) |
---|
| 2621 | +{ |
---|
| 2622 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 2623 | + struct intel_version ver; |
---|
| 2624 | + struct intel_boot_params params; |
---|
| 2625 | + u32 boot_param; |
---|
| 2626 | + char ddcname[64]; |
---|
| 2627 | + ktime_t calltime, delta, rettime; |
---|
| 2628 | + unsigned long long duration; |
---|
| 2629 | + int err; |
---|
| 2630 | + struct intel_debug_features features; |
---|
| 2631 | + |
---|
| 2632 | + BT_DBG("%s", hdev->name); |
---|
| 2633 | + |
---|
| 2634 | + /* Set the default boot parameter to 0x0 and it is updated to |
---|
| 2635 | + * SKU specific boot parameter after reading Intel_Write_Boot_Params |
---|
| 2636 | + * command while downloading the firmware. |
---|
| 2637 | + */ |
---|
| 2638 | + boot_param = 0x00000000; |
---|
| 2639 | + |
---|
| 2640 | + calltime = ktime_get(); |
---|
| 2641 | + |
---|
| 2642 | + /* Read the Intel version information to determine if the device |
---|
| 2643 | + * is in bootloader mode or if it already has operational firmware |
---|
| 2644 | + * loaded. |
---|
| 2645 | + */ |
---|
| 2646 | + err = btintel_read_version(hdev, &ver); |
---|
| 2647 | + if (err) { |
---|
| 2648 | + bt_dev_err(hdev, "Intel Read version failed (%d)", err); |
---|
| 2649 | + btintel_reset_to_bootloader(hdev); |
---|
| 2650 | + return err; |
---|
| 2651 | + } |
---|
| 2652 | + |
---|
| 2653 | + err = btusb_intel_download_firmware(hdev, &ver, ¶ms, &boot_param); |
---|
| 2654 | + if (err) |
---|
| 2655 | + return err; |
---|
| 2656 | + |
---|
| 2657 | + /* controller is already having an operational firmware */ |
---|
| 2658 | + if (ver.fw_variant == 0x23) |
---|
| 2659 | + goto finish; |
---|
| 2660 | + |
---|
2297 | 2661 | rettime = ktime_get(); |
---|
2298 | 2662 | delta = ktime_sub(rettime, calltime); |
---|
2299 | 2663 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; |
---|
2300 | 2664 | |
---|
2301 | 2665 | bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration); |
---|
2302 | 2666 | |
---|
2303 | | -done: |
---|
2304 | | - release_firmware(fw); |
---|
2305 | | - |
---|
2306 | | - if (err < 0) |
---|
2307 | | - return err; |
---|
2308 | | - |
---|
2309 | 2667 | calltime = ktime_get(); |
---|
2310 | 2668 | |
---|
2311 | 2669 | set_bit(BTUSB_BOOTING, &data->flags); |
---|
2312 | 2670 | |
---|
2313 | 2671 | err = btintel_send_intel_reset(hdev, boot_param); |
---|
2314 | | - if (err) |
---|
| 2672 | + if (err) { |
---|
| 2673 | + bt_dev_err(hdev, "Intel Soft Reset failed (%d)", err); |
---|
| 2674 | + btintel_reset_to_bootloader(hdev); |
---|
2315 | 2675 | return err; |
---|
| 2676 | + } |
---|
2316 | 2677 | |
---|
2317 | 2678 | /* The bootloader will not indicate when the device is ready. This |
---|
2318 | 2679 | * is done by the operational firmware sending bootup notification. |
---|
.. | .. |
---|
2334 | 2695 | |
---|
2335 | 2696 | if (err) { |
---|
2336 | 2697 | bt_dev_err(hdev, "Device boot timeout"); |
---|
| 2698 | + btintel_reset_to_bootloader(hdev); |
---|
2337 | 2699 | return -ETIMEDOUT; |
---|
2338 | 2700 | } |
---|
2339 | 2701 | |
---|
.. | .. |
---|
2345 | 2707 | |
---|
2346 | 2708 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
---|
2347 | 2709 | |
---|
2348 | | - /* Once the device is running in operational mode, it needs to apply |
---|
2349 | | - * the device configuration (DDC) parameters. |
---|
2350 | | - * |
---|
2351 | | - * The device can work without DDC parameters, so even if it fails |
---|
2352 | | - * to load the file, no need to fail the setup. |
---|
| 2710 | + err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, ddcname, |
---|
| 2711 | + sizeof(ddcname), "ddc"); |
---|
| 2712 | + |
---|
| 2713 | + if (!err) { |
---|
| 2714 | + bt_dev_err(hdev, "Unsupported Intel firmware naming"); |
---|
| 2715 | + } else { |
---|
| 2716 | + /* Once the device is running in operational mode, it needs to |
---|
| 2717 | + * apply the device configuration (DDC) parameters. |
---|
| 2718 | + * |
---|
| 2719 | + * The device can work without DDC parameters, so even if it |
---|
| 2720 | + * fails to load the file, no need to fail the setup. |
---|
| 2721 | + */ |
---|
| 2722 | + btintel_load_ddc_config(hdev, ddcname); |
---|
| 2723 | + } |
---|
| 2724 | + |
---|
| 2725 | + /* Read the Intel supported features and if new exception formats |
---|
| 2726 | + * supported, need to load the additional DDC config to enable. |
---|
2353 | 2727 | */ |
---|
2354 | | - btintel_load_ddc_config(hdev, fwname); |
---|
| 2728 | + btintel_read_debug_features(hdev, &features); |
---|
| 2729 | + |
---|
| 2730 | + /* Set DDC mask for available debug features */ |
---|
| 2731 | + btintel_set_debug_features(hdev, &features); |
---|
| 2732 | + |
---|
| 2733 | + /* Read the Intel version information after loading the FW */ |
---|
| 2734 | + err = btintel_read_version(hdev, &ver); |
---|
| 2735 | + if (err) |
---|
| 2736 | + return err; |
---|
| 2737 | + |
---|
| 2738 | + btintel_version_info(hdev, &ver); |
---|
| 2739 | + |
---|
| 2740 | +finish: |
---|
| 2741 | + /* All Intel controllers that support the Microsoft vendor |
---|
| 2742 | + * extension are using 0xFC1E for VsMsftOpCode. |
---|
| 2743 | + */ |
---|
| 2744 | + switch (ver.hw_variant) { |
---|
| 2745 | + case 0x12: /* ThP */ |
---|
| 2746 | + hci_set_msft_opcode(hdev, 0xFC1E); |
---|
| 2747 | + break; |
---|
| 2748 | + } |
---|
2355 | 2749 | |
---|
2356 | 2750 | /* Set the event mask for Intel specific vendor events. This enables |
---|
2357 | 2751 | * a few extra events that are useful during general operation. It |
---|
.. | .. |
---|
2400 | 2794 | |
---|
2401 | 2795 | return 0; |
---|
2402 | 2796 | } |
---|
| 2797 | + |
---|
| 2798 | +static int btusb_shutdown_intel_new(struct hci_dev *hdev) |
---|
| 2799 | +{ |
---|
| 2800 | + struct sk_buff *skb; |
---|
| 2801 | + |
---|
| 2802 | + /* Send HCI Reset to the controller to stop any BT activity which |
---|
| 2803 | + * were triggered. This will help to save power and maintain the |
---|
| 2804 | + * sync b/w Host and controller |
---|
| 2805 | + */ |
---|
| 2806 | + skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
---|
| 2807 | + if (IS_ERR(skb)) { |
---|
| 2808 | + bt_dev_err(hdev, "HCI reset during shutdown failed"); |
---|
| 2809 | + return PTR_ERR(skb); |
---|
| 2810 | + } |
---|
| 2811 | + kfree_skb(skb); |
---|
| 2812 | + |
---|
| 2813 | + return 0; |
---|
| 2814 | +} |
---|
| 2815 | + |
---|
| 2816 | +#define FIRMWARE_MT7663 "mediatek/mt7663pr2h.bin" |
---|
| 2817 | +#define FIRMWARE_MT7668 "mediatek/mt7668pr2h.bin" |
---|
| 2818 | + |
---|
| 2819 | +#define HCI_WMT_MAX_EVENT_SIZE 64 |
---|
| 2820 | + |
---|
| 2821 | +enum { |
---|
| 2822 | + BTMTK_WMT_PATCH_DWNLD = 0x1, |
---|
| 2823 | + BTMTK_WMT_FUNC_CTRL = 0x6, |
---|
| 2824 | + BTMTK_WMT_RST = 0x7, |
---|
| 2825 | + BTMTK_WMT_SEMAPHORE = 0x17, |
---|
| 2826 | +}; |
---|
| 2827 | + |
---|
| 2828 | +enum { |
---|
| 2829 | + BTMTK_WMT_INVALID, |
---|
| 2830 | + BTMTK_WMT_PATCH_UNDONE, |
---|
| 2831 | + BTMTK_WMT_PATCH_PROGRESS, |
---|
| 2832 | + BTMTK_WMT_PATCH_DONE, |
---|
| 2833 | + BTMTK_WMT_ON_UNDONE, |
---|
| 2834 | + BTMTK_WMT_ON_DONE, |
---|
| 2835 | + BTMTK_WMT_ON_PROGRESS, |
---|
| 2836 | +}; |
---|
| 2837 | + |
---|
| 2838 | +struct btmtk_wmt_hdr { |
---|
| 2839 | + u8 dir; |
---|
| 2840 | + u8 op; |
---|
| 2841 | + __le16 dlen; |
---|
| 2842 | + u8 flag; |
---|
| 2843 | +} __packed; |
---|
| 2844 | + |
---|
| 2845 | +struct btmtk_hci_wmt_cmd { |
---|
| 2846 | + struct btmtk_wmt_hdr hdr; |
---|
| 2847 | + u8 data[]; |
---|
| 2848 | +} __packed; |
---|
| 2849 | + |
---|
| 2850 | +struct btmtk_hci_wmt_evt { |
---|
| 2851 | + struct hci_event_hdr hhdr; |
---|
| 2852 | + struct btmtk_wmt_hdr whdr; |
---|
| 2853 | +} __packed; |
---|
| 2854 | + |
---|
| 2855 | +struct btmtk_hci_wmt_evt_funcc { |
---|
| 2856 | + struct btmtk_hci_wmt_evt hwhdr; |
---|
| 2857 | + __be16 status; |
---|
| 2858 | +} __packed; |
---|
| 2859 | + |
---|
| 2860 | +struct btmtk_tci_sleep { |
---|
| 2861 | + u8 mode; |
---|
| 2862 | + __le16 duration; |
---|
| 2863 | + __le16 host_duration; |
---|
| 2864 | + u8 host_wakeup_pin; |
---|
| 2865 | + u8 time_compensation; |
---|
| 2866 | +} __packed; |
---|
| 2867 | + |
---|
| 2868 | +struct btmtk_hci_wmt_params { |
---|
| 2869 | + u8 op; |
---|
| 2870 | + u8 flag; |
---|
| 2871 | + u16 dlen; |
---|
| 2872 | + const void *data; |
---|
| 2873 | + u32 *status; |
---|
| 2874 | +}; |
---|
| 2875 | + |
---|
| 2876 | +static void btusb_mtk_wmt_recv(struct urb *urb) |
---|
| 2877 | +{ |
---|
| 2878 | + struct hci_dev *hdev = urb->context; |
---|
| 2879 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 2880 | + struct hci_event_hdr *hdr; |
---|
| 2881 | + struct sk_buff *skb; |
---|
| 2882 | + int err; |
---|
| 2883 | + |
---|
| 2884 | + if (urb->status == 0 && urb->actual_length > 0) { |
---|
| 2885 | + hdev->stat.byte_rx += urb->actual_length; |
---|
| 2886 | + |
---|
| 2887 | + /* WMT event shouldn't be fragmented and the size should be |
---|
| 2888 | + * less than HCI_WMT_MAX_EVENT_SIZE. |
---|
| 2889 | + */ |
---|
| 2890 | + skb = bt_skb_alloc(HCI_WMT_MAX_EVENT_SIZE, GFP_ATOMIC); |
---|
| 2891 | + if (!skb) { |
---|
| 2892 | + hdev->stat.err_rx++; |
---|
| 2893 | + kfree(urb->setup_packet); |
---|
| 2894 | + return; |
---|
| 2895 | + } |
---|
| 2896 | + |
---|
| 2897 | + hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
---|
| 2898 | + skb_put_data(skb, urb->transfer_buffer, urb->actual_length); |
---|
| 2899 | + |
---|
| 2900 | + hdr = (void *)skb->data; |
---|
| 2901 | + /* Fix up the vendor event id with 0xff for vendor specific |
---|
| 2902 | + * instead of 0xe4 so that event send via monitoring socket can |
---|
| 2903 | + * be parsed properly. |
---|
| 2904 | + */ |
---|
| 2905 | + hdr->evt = 0xff; |
---|
| 2906 | + |
---|
| 2907 | + /* When someone waits for the WMT event, the skb is being cloned |
---|
| 2908 | + * and being processed the events from there then. |
---|
| 2909 | + */ |
---|
| 2910 | + if (test_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags)) { |
---|
| 2911 | + data->evt_skb = skb_clone(skb, GFP_ATOMIC); |
---|
| 2912 | + if (!data->evt_skb) { |
---|
| 2913 | + kfree_skb(skb); |
---|
| 2914 | + kfree(urb->setup_packet); |
---|
| 2915 | + return; |
---|
| 2916 | + } |
---|
| 2917 | + } |
---|
| 2918 | + |
---|
| 2919 | + err = hci_recv_frame(hdev, skb); |
---|
| 2920 | + if (err < 0) { |
---|
| 2921 | + kfree_skb(data->evt_skb); |
---|
| 2922 | + data->evt_skb = NULL; |
---|
| 2923 | + kfree(urb->setup_packet); |
---|
| 2924 | + return; |
---|
| 2925 | + } |
---|
| 2926 | + |
---|
| 2927 | + if (test_and_clear_bit(BTUSB_TX_WAIT_VND_EVT, |
---|
| 2928 | + &data->flags)) { |
---|
| 2929 | + /* Barrier to sync with other CPUs */ |
---|
| 2930 | + smp_mb__after_atomic(); |
---|
| 2931 | + wake_up_bit(&data->flags, |
---|
| 2932 | + BTUSB_TX_WAIT_VND_EVT); |
---|
| 2933 | + } |
---|
| 2934 | + kfree(urb->setup_packet); |
---|
| 2935 | + return; |
---|
| 2936 | + } else if (urb->status == -ENOENT) { |
---|
| 2937 | + /* Avoid suspend failed when usb_kill_urb */ |
---|
| 2938 | + return; |
---|
| 2939 | + } |
---|
| 2940 | + |
---|
| 2941 | + usb_mark_last_busy(data->udev); |
---|
| 2942 | + |
---|
| 2943 | + /* The URB complete handler is still called with urb->actual_length = 0 |
---|
| 2944 | + * when the event is not available, so we should keep re-submitting |
---|
| 2945 | + * URB until WMT event returns, Also, It's necessary to wait some time |
---|
| 2946 | + * between the two consecutive control URBs to relax the target device |
---|
| 2947 | + * to generate the event. Otherwise, the WMT event cannot return from |
---|
| 2948 | + * the device successfully. |
---|
| 2949 | + */ |
---|
| 2950 | + udelay(500); |
---|
| 2951 | + |
---|
| 2952 | + usb_anchor_urb(urb, &data->ctrl_anchor); |
---|
| 2953 | + err = usb_submit_urb(urb, GFP_ATOMIC); |
---|
| 2954 | + if (err < 0) { |
---|
| 2955 | + kfree(urb->setup_packet); |
---|
| 2956 | + /* -EPERM: urb is being killed; |
---|
| 2957 | + * -ENODEV: device got disconnected |
---|
| 2958 | + */ |
---|
| 2959 | + if (err != -EPERM && err != -ENODEV) |
---|
| 2960 | + bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
---|
| 2961 | + urb, -err); |
---|
| 2962 | + usb_unanchor_urb(urb); |
---|
| 2963 | + } |
---|
| 2964 | +} |
---|
| 2965 | + |
---|
| 2966 | +static int btusb_mtk_submit_wmt_recv_urb(struct hci_dev *hdev) |
---|
| 2967 | +{ |
---|
| 2968 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 2969 | + struct usb_ctrlrequest *dr; |
---|
| 2970 | + unsigned char *buf; |
---|
| 2971 | + int err, size = 64; |
---|
| 2972 | + unsigned int pipe; |
---|
| 2973 | + struct urb *urb; |
---|
| 2974 | + |
---|
| 2975 | + urb = usb_alloc_urb(0, GFP_KERNEL); |
---|
| 2976 | + if (!urb) |
---|
| 2977 | + return -ENOMEM; |
---|
| 2978 | + |
---|
| 2979 | + dr = kmalloc(sizeof(*dr), GFP_KERNEL); |
---|
| 2980 | + if (!dr) { |
---|
| 2981 | + usb_free_urb(urb); |
---|
| 2982 | + return -ENOMEM; |
---|
| 2983 | + } |
---|
| 2984 | + |
---|
| 2985 | + dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_IN; |
---|
| 2986 | + dr->bRequest = 1; |
---|
| 2987 | + dr->wIndex = cpu_to_le16(0); |
---|
| 2988 | + dr->wValue = cpu_to_le16(48); |
---|
| 2989 | + dr->wLength = cpu_to_le16(size); |
---|
| 2990 | + |
---|
| 2991 | + buf = kmalloc(size, GFP_KERNEL); |
---|
| 2992 | + if (!buf) { |
---|
| 2993 | + kfree(dr); |
---|
| 2994 | + usb_free_urb(urb); |
---|
| 2995 | + return -ENOMEM; |
---|
| 2996 | + } |
---|
| 2997 | + |
---|
| 2998 | + pipe = usb_rcvctrlpipe(data->udev, 0); |
---|
| 2999 | + |
---|
| 3000 | + usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, |
---|
| 3001 | + buf, size, btusb_mtk_wmt_recv, hdev); |
---|
| 3002 | + |
---|
| 3003 | + urb->transfer_flags |= URB_FREE_BUFFER; |
---|
| 3004 | + |
---|
| 3005 | + usb_anchor_urb(urb, &data->ctrl_anchor); |
---|
| 3006 | + err = usb_submit_urb(urb, GFP_KERNEL); |
---|
| 3007 | + if (err < 0) { |
---|
| 3008 | + if (err != -EPERM && err != -ENODEV) |
---|
| 3009 | + bt_dev_err(hdev, "urb %p submission failed (%d)", |
---|
| 3010 | + urb, -err); |
---|
| 3011 | + usb_unanchor_urb(urb); |
---|
| 3012 | + } |
---|
| 3013 | + |
---|
| 3014 | + usb_free_urb(urb); |
---|
| 3015 | + |
---|
| 3016 | + return err; |
---|
| 3017 | +} |
---|
| 3018 | + |
---|
| 3019 | +static int btusb_mtk_hci_wmt_sync(struct hci_dev *hdev, |
---|
| 3020 | + struct btmtk_hci_wmt_params *wmt_params) |
---|
| 3021 | +{ |
---|
| 3022 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 3023 | + struct btmtk_hci_wmt_evt_funcc *wmt_evt_funcc; |
---|
| 3024 | + u32 hlen, status = BTMTK_WMT_INVALID; |
---|
| 3025 | + struct btmtk_hci_wmt_evt *wmt_evt; |
---|
| 3026 | + struct btmtk_hci_wmt_cmd *wc; |
---|
| 3027 | + struct btmtk_wmt_hdr *hdr; |
---|
| 3028 | + int err; |
---|
| 3029 | + |
---|
| 3030 | + /* Send the WMT command and wait until the WMT event returns */ |
---|
| 3031 | + hlen = sizeof(*hdr) + wmt_params->dlen; |
---|
| 3032 | + if (hlen > 255) |
---|
| 3033 | + return -EINVAL; |
---|
| 3034 | + |
---|
| 3035 | + wc = kzalloc(hlen, GFP_KERNEL); |
---|
| 3036 | + if (!wc) |
---|
| 3037 | + return -ENOMEM; |
---|
| 3038 | + |
---|
| 3039 | + hdr = &wc->hdr; |
---|
| 3040 | + hdr->dir = 1; |
---|
| 3041 | + hdr->op = wmt_params->op; |
---|
| 3042 | + hdr->dlen = cpu_to_le16(wmt_params->dlen + 1); |
---|
| 3043 | + hdr->flag = wmt_params->flag; |
---|
| 3044 | + memcpy(wc->data, wmt_params->data, wmt_params->dlen); |
---|
| 3045 | + |
---|
| 3046 | + set_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
---|
| 3047 | + |
---|
| 3048 | + /* WMT cmd/event doesn't follow up the generic HCI cmd/event handling, |
---|
| 3049 | + * it needs constantly polling control pipe until the host received the |
---|
| 3050 | + * WMT event, thus, we should require to specifically acquire PM counter |
---|
| 3051 | + * on the USB to prevent the interface from entering auto suspended |
---|
| 3052 | + * while WMT cmd/event in progress. |
---|
| 3053 | + */ |
---|
| 3054 | + err = usb_autopm_get_interface(data->intf); |
---|
| 3055 | + if (err < 0) |
---|
| 3056 | + goto err_free_wc; |
---|
| 3057 | + |
---|
| 3058 | + err = __hci_cmd_send(hdev, 0xfc6f, hlen, wc); |
---|
| 3059 | + |
---|
| 3060 | + if (err < 0) { |
---|
| 3061 | + clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
---|
| 3062 | + usb_autopm_put_interface(data->intf); |
---|
| 3063 | + goto err_free_wc; |
---|
| 3064 | + } |
---|
| 3065 | + |
---|
| 3066 | + /* Submit control IN URB on demand to process the WMT event */ |
---|
| 3067 | + err = btusb_mtk_submit_wmt_recv_urb(hdev); |
---|
| 3068 | + |
---|
| 3069 | + usb_autopm_put_interface(data->intf); |
---|
| 3070 | + |
---|
| 3071 | + if (err < 0) |
---|
| 3072 | + return err; |
---|
| 3073 | + |
---|
| 3074 | + /* The vendor specific WMT commands are all answered by a vendor |
---|
| 3075 | + * specific event and will have the Command Status or Command |
---|
| 3076 | + * Complete as with usual HCI command flow control. |
---|
| 3077 | + * |
---|
| 3078 | + * After sending the command, wait for BTUSB_TX_WAIT_VND_EVT |
---|
| 3079 | + * state to be cleared. The driver specific event receive routine |
---|
| 3080 | + * will clear that state and with that indicate completion of the |
---|
| 3081 | + * WMT command. |
---|
| 3082 | + */ |
---|
| 3083 | + err = wait_on_bit_timeout(&data->flags, BTUSB_TX_WAIT_VND_EVT, |
---|
| 3084 | + TASK_INTERRUPTIBLE, HCI_INIT_TIMEOUT); |
---|
| 3085 | + if (err == -EINTR) { |
---|
| 3086 | + bt_dev_err(hdev, "Execution of wmt command interrupted"); |
---|
| 3087 | + clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
---|
| 3088 | + goto err_free_wc; |
---|
| 3089 | + } |
---|
| 3090 | + |
---|
| 3091 | + if (err) { |
---|
| 3092 | + bt_dev_err(hdev, "Execution of wmt command timed out"); |
---|
| 3093 | + clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
---|
| 3094 | + err = -ETIMEDOUT; |
---|
| 3095 | + goto err_free_wc; |
---|
| 3096 | + } |
---|
| 3097 | + |
---|
| 3098 | + /* Parse and handle the return WMT event */ |
---|
| 3099 | + wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data; |
---|
| 3100 | + if (wmt_evt->whdr.op != hdr->op) { |
---|
| 3101 | + bt_dev_err(hdev, "Wrong op received %d expected %d", |
---|
| 3102 | + wmt_evt->whdr.op, hdr->op); |
---|
| 3103 | + err = -EIO; |
---|
| 3104 | + goto err_free_skb; |
---|
| 3105 | + } |
---|
| 3106 | + |
---|
| 3107 | + switch (wmt_evt->whdr.op) { |
---|
| 3108 | + case BTMTK_WMT_SEMAPHORE: |
---|
| 3109 | + if (wmt_evt->whdr.flag == 2) |
---|
| 3110 | + status = BTMTK_WMT_PATCH_UNDONE; |
---|
| 3111 | + else |
---|
| 3112 | + status = BTMTK_WMT_PATCH_DONE; |
---|
| 3113 | + break; |
---|
| 3114 | + case BTMTK_WMT_FUNC_CTRL: |
---|
| 3115 | + wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt; |
---|
| 3116 | + if (be16_to_cpu(wmt_evt_funcc->status) == 0x404) |
---|
| 3117 | + status = BTMTK_WMT_ON_DONE; |
---|
| 3118 | + else if (be16_to_cpu(wmt_evt_funcc->status) == 0x420) |
---|
| 3119 | + status = BTMTK_WMT_ON_PROGRESS; |
---|
| 3120 | + else |
---|
| 3121 | + status = BTMTK_WMT_ON_UNDONE; |
---|
| 3122 | + break; |
---|
| 3123 | + } |
---|
| 3124 | + |
---|
| 3125 | + if (wmt_params->status) |
---|
| 3126 | + *wmt_params->status = status; |
---|
| 3127 | + |
---|
| 3128 | +err_free_skb: |
---|
| 3129 | + kfree_skb(data->evt_skb); |
---|
| 3130 | + data->evt_skb = NULL; |
---|
| 3131 | +err_free_wc: |
---|
| 3132 | + kfree(wc); |
---|
| 3133 | + return err; |
---|
| 3134 | +} |
---|
| 3135 | + |
---|
| 3136 | +static int btusb_mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) |
---|
| 3137 | +{ |
---|
| 3138 | + struct btmtk_hci_wmt_params wmt_params; |
---|
| 3139 | + const struct firmware *fw; |
---|
| 3140 | + const u8 *fw_ptr; |
---|
| 3141 | + size_t fw_size; |
---|
| 3142 | + int err, dlen; |
---|
| 3143 | + u8 flag, param; |
---|
| 3144 | + |
---|
| 3145 | + err = request_firmware(&fw, fwname, &hdev->dev); |
---|
| 3146 | + if (err < 0) { |
---|
| 3147 | + bt_dev_err(hdev, "Failed to load firmware file (%d)", err); |
---|
| 3148 | + return err; |
---|
| 3149 | + } |
---|
| 3150 | + |
---|
| 3151 | + /* Power on data RAM the firmware relies on. */ |
---|
| 3152 | + param = 1; |
---|
| 3153 | + wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
---|
| 3154 | + wmt_params.flag = 3; |
---|
| 3155 | + wmt_params.dlen = sizeof(param); |
---|
| 3156 | + wmt_params.data = ¶m; |
---|
| 3157 | + wmt_params.status = NULL; |
---|
| 3158 | + |
---|
| 3159 | + err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
---|
| 3160 | + if (err < 0) { |
---|
| 3161 | + bt_dev_err(hdev, "Failed to power on data RAM (%d)", err); |
---|
| 3162 | + goto err_release_fw; |
---|
| 3163 | + } |
---|
| 3164 | + |
---|
| 3165 | + fw_ptr = fw->data; |
---|
| 3166 | + fw_size = fw->size; |
---|
| 3167 | + |
---|
| 3168 | + /* The size of patch header is 30 bytes, should be skip */ |
---|
| 3169 | + if (fw_size < 30) { |
---|
| 3170 | + err = -EINVAL; |
---|
| 3171 | + goto err_release_fw; |
---|
| 3172 | + } |
---|
| 3173 | + |
---|
| 3174 | + fw_size -= 30; |
---|
| 3175 | + fw_ptr += 30; |
---|
| 3176 | + flag = 1; |
---|
| 3177 | + |
---|
| 3178 | + wmt_params.op = BTMTK_WMT_PATCH_DWNLD; |
---|
| 3179 | + wmt_params.status = NULL; |
---|
| 3180 | + |
---|
| 3181 | + while (fw_size > 0) { |
---|
| 3182 | + dlen = min_t(int, 250, fw_size); |
---|
| 3183 | + |
---|
| 3184 | + /* Tell deivice the position in sequence */ |
---|
| 3185 | + if (fw_size - dlen <= 0) |
---|
| 3186 | + flag = 3; |
---|
| 3187 | + else if (fw_size < fw->size - 30) |
---|
| 3188 | + flag = 2; |
---|
| 3189 | + |
---|
| 3190 | + wmt_params.flag = flag; |
---|
| 3191 | + wmt_params.dlen = dlen; |
---|
| 3192 | + wmt_params.data = fw_ptr; |
---|
| 3193 | + |
---|
| 3194 | + err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
---|
| 3195 | + if (err < 0) { |
---|
| 3196 | + bt_dev_err(hdev, "Failed to send wmt patch dwnld (%d)", |
---|
| 3197 | + err); |
---|
| 3198 | + goto err_release_fw; |
---|
| 3199 | + } |
---|
| 3200 | + |
---|
| 3201 | + fw_size -= dlen; |
---|
| 3202 | + fw_ptr += dlen; |
---|
| 3203 | + } |
---|
| 3204 | + |
---|
| 3205 | + wmt_params.op = BTMTK_WMT_RST; |
---|
| 3206 | + wmt_params.flag = 4; |
---|
| 3207 | + wmt_params.dlen = 0; |
---|
| 3208 | + wmt_params.data = NULL; |
---|
| 3209 | + wmt_params.status = NULL; |
---|
| 3210 | + |
---|
| 3211 | + /* Activate funciton the firmware providing to */ |
---|
| 3212 | + err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
---|
| 3213 | + if (err < 0) { |
---|
| 3214 | + bt_dev_err(hdev, "Failed to send wmt rst (%d)", err); |
---|
| 3215 | + goto err_release_fw; |
---|
| 3216 | + } |
---|
| 3217 | + |
---|
| 3218 | + /* Wait a few moments for firmware activation done */ |
---|
| 3219 | + usleep_range(10000, 12000); |
---|
| 3220 | + |
---|
| 3221 | +err_release_fw: |
---|
| 3222 | + release_firmware(fw); |
---|
| 3223 | + |
---|
| 3224 | + return err; |
---|
| 3225 | +} |
---|
| 3226 | + |
---|
| 3227 | +static int btusb_mtk_func_query(struct hci_dev *hdev) |
---|
| 3228 | +{ |
---|
| 3229 | + struct btmtk_hci_wmt_params wmt_params; |
---|
| 3230 | + int status, err; |
---|
| 3231 | + u8 param = 0; |
---|
| 3232 | + |
---|
| 3233 | + /* Query whether the function is enabled */ |
---|
| 3234 | + wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
---|
| 3235 | + wmt_params.flag = 4; |
---|
| 3236 | + wmt_params.dlen = sizeof(param); |
---|
| 3237 | + wmt_params.data = ¶m; |
---|
| 3238 | + wmt_params.status = &status; |
---|
| 3239 | + |
---|
| 3240 | + err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
---|
| 3241 | + if (err < 0) { |
---|
| 3242 | + bt_dev_err(hdev, "Failed to query function status (%d)", err); |
---|
| 3243 | + return err; |
---|
| 3244 | + } |
---|
| 3245 | + |
---|
| 3246 | + return status; |
---|
| 3247 | +} |
---|
| 3248 | + |
---|
| 3249 | +static int btusb_mtk_reg_read(struct btusb_data *data, u32 reg, u32 *val) |
---|
| 3250 | +{ |
---|
| 3251 | + int pipe, err, size = sizeof(u32); |
---|
| 3252 | + void *buf; |
---|
| 3253 | + |
---|
| 3254 | + buf = kzalloc(size, GFP_KERNEL); |
---|
| 3255 | + if (!buf) |
---|
| 3256 | + return -ENOMEM; |
---|
| 3257 | + |
---|
| 3258 | + pipe = usb_rcvctrlpipe(data->udev, 0); |
---|
| 3259 | + err = usb_control_msg(data->udev, pipe, 0x63, |
---|
| 3260 | + USB_TYPE_VENDOR | USB_DIR_IN, |
---|
| 3261 | + reg >> 16, reg & 0xffff, |
---|
| 3262 | + buf, size, USB_CTRL_SET_TIMEOUT); |
---|
| 3263 | + if (err < 0) |
---|
| 3264 | + goto err_free_buf; |
---|
| 3265 | + |
---|
| 3266 | + *val = get_unaligned_le32(buf); |
---|
| 3267 | + |
---|
| 3268 | +err_free_buf: |
---|
| 3269 | + kfree(buf); |
---|
| 3270 | + |
---|
| 3271 | + return err; |
---|
| 3272 | +} |
---|
| 3273 | + |
---|
| 3274 | +static int btusb_mtk_id_get(struct btusb_data *data, u32 reg, u32 *id) |
---|
| 3275 | +{ |
---|
| 3276 | + return btusb_mtk_reg_read(data, reg, id); |
---|
| 3277 | +} |
---|
| 3278 | + |
---|
| 3279 | +static int btusb_mtk_setup(struct hci_dev *hdev) |
---|
| 3280 | +{ |
---|
| 3281 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 3282 | + struct btmtk_hci_wmt_params wmt_params; |
---|
| 3283 | + ktime_t calltime, delta, rettime; |
---|
| 3284 | + struct btmtk_tci_sleep tci_sleep; |
---|
| 3285 | + unsigned long long duration; |
---|
| 3286 | + struct sk_buff *skb; |
---|
| 3287 | + const char *fwname; |
---|
| 3288 | + int err, status; |
---|
| 3289 | + u32 dev_id; |
---|
| 3290 | + u8 param; |
---|
| 3291 | + |
---|
| 3292 | + calltime = ktime_get(); |
---|
| 3293 | + |
---|
| 3294 | + err = btusb_mtk_id_get(data, 0x80000008, &dev_id); |
---|
| 3295 | + if (err < 0) { |
---|
| 3296 | + bt_dev_err(hdev, "Failed to get device id (%d)", err); |
---|
| 3297 | + return err; |
---|
| 3298 | + } |
---|
| 3299 | + |
---|
| 3300 | + switch (dev_id) { |
---|
| 3301 | + case 0x7663: |
---|
| 3302 | + fwname = FIRMWARE_MT7663; |
---|
| 3303 | + break; |
---|
| 3304 | + case 0x7668: |
---|
| 3305 | + fwname = FIRMWARE_MT7668; |
---|
| 3306 | + break; |
---|
| 3307 | + default: |
---|
| 3308 | + bt_dev_err(hdev, "Unsupported support hardware variant (%08x)", |
---|
| 3309 | + dev_id); |
---|
| 3310 | + return -ENODEV; |
---|
| 3311 | + } |
---|
| 3312 | + |
---|
| 3313 | + /* Query whether the firmware is already download */ |
---|
| 3314 | + wmt_params.op = BTMTK_WMT_SEMAPHORE; |
---|
| 3315 | + wmt_params.flag = 1; |
---|
| 3316 | + wmt_params.dlen = 0; |
---|
| 3317 | + wmt_params.data = NULL; |
---|
| 3318 | + wmt_params.status = &status; |
---|
| 3319 | + |
---|
| 3320 | + err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
---|
| 3321 | + if (err < 0) { |
---|
| 3322 | + bt_dev_err(hdev, "Failed to query firmware status (%d)", err); |
---|
| 3323 | + return err; |
---|
| 3324 | + } |
---|
| 3325 | + |
---|
| 3326 | + if (status == BTMTK_WMT_PATCH_DONE) { |
---|
| 3327 | + bt_dev_info(hdev, "firmware already downloaded"); |
---|
| 3328 | + goto ignore_setup_fw; |
---|
| 3329 | + } |
---|
| 3330 | + |
---|
| 3331 | + /* Setup a firmware which the device definitely requires */ |
---|
| 3332 | + err = btusb_mtk_setup_firmware(hdev, fwname); |
---|
| 3333 | + if (err < 0) |
---|
| 3334 | + return err; |
---|
| 3335 | + |
---|
| 3336 | +ignore_setup_fw: |
---|
| 3337 | + err = readx_poll_timeout(btusb_mtk_func_query, hdev, status, |
---|
| 3338 | + status < 0 || status != BTMTK_WMT_ON_PROGRESS, |
---|
| 3339 | + 2000, 5000000); |
---|
| 3340 | + /* -ETIMEDOUT happens */ |
---|
| 3341 | + if (err < 0) |
---|
| 3342 | + return err; |
---|
| 3343 | + |
---|
| 3344 | + /* The other errors happen in btusb_mtk_func_query */ |
---|
| 3345 | + if (status < 0) |
---|
| 3346 | + return status; |
---|
| 3347 | + |
---|
| 3348 | + if (status == BTMTK_WMT_ON_DONE) { |
---|
| 3349 | + bt_dev_info(hdev, "function already on"); |
---|
| 3350 | + goto ignore_func_on; |
---|
| 3351 | + } |
---|
| 3352 | + |
---|
| 3353 | + /* Enable Bluetooth protocol */ |
---|
| 3354 | + param = 1; |
---|
| 3355 | + wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
---|
| 3356 | + wmt_params.flag = 0; |
---|
| 3357 | + wmt_params.dlen = sizeof(param); |
---|
| 3358 | + wmt_params.data = ¶m; |
---|
| 3359 | + wmt_params.status = NULL; |
---|
| 3360 | + |
---|
| 3361 | + err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
---|
| 3362 | + if (err < 0) { |
---|
| 3363 | + bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
---|
| 3364 | + return err; |
---|
| 3365 | + } |
---|
| 3366 | + |
---|
| 3367 | +ignore_func_on: |
---|
| 3368 | + /* Apply the low power environment setup */ |
---|
| 3369 | + tci_sleep.mode = 0x5; |
---|
| 3370 | + tci_sleep.duration = cpu_to_le16(0x640); |
---|
| 3371 | + tci_sleep.host_duration = cpu_to_le16(0x640); |
---|
| 3372 | + tci_sleep.host_wakeup_pin = 0; |
---|
| 3373 | + tci_sleep.time_compensation = 0; |
---|
| 3374 | + |
---|
| 3375 | + skb = __hci_cmd_sync(hdev, 0xfc7a, sizeof(tci_sleep), &tci_sleep, |
---|
| 3376 | + HCI_INIT_TIMEOUT); |
---|
| 3377 | + if (IS_ERR(skb)) { |
---|
| 3378 | + err = PTR_ERR(skb); |
---|
| 3379 | + bt_dev_err(hdev, "Failed to apply low power setting (%d)", err); |
---|
| 3380 | + return err; |
---|
| 3381 | + } |
---|
| 3382 | + kfree_skb(skb); |
---|
| 3383 | + |
---|
| 3384 | + rettime = ktime_get(); |
---|
| 3385 | + delta = ktime_sub(rettime, calltime); |
---|
| 3386 | + duration = (unsigned long long)ktime_to_ns(delta) >> 10; |
---|
| 3387 | + |
---|
| 3388 | + bt_dev_info(hdev, "Device setup in %llu usecs", duration); |
---|
| 3389 | + |
---|
| 3390 | + return 0; |
---|
| 3391 | +} |
---|
| 3392 | + |
---|
| 3393 | +static int btusb_mtk_shutdown(struct hci_dev *hdev) |
---|
| 3394 | +{ |
---|
| 3395 | + struct btmtk_hci_wmt_params wmt_params; |
---|
| 3396 | + u8 param = 0; |
---|
| 3397 | + int err; |
---|
| 3398 | + |
---|
| 3399 | + /* Disable the device */ |
---|
| 3400 | + wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
---|
| 3401 | + wmt_params.flag = 0; |
---|
| 3402 | + wmt_params.dlen = sizeof(param); |
---|
| 3403 | + wmt_params.data = ¶m; |
---|
| 3404 | + wmt_params.status = NULL; |
---|
| 3405 | + |
---|
| 3406 | + err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
---|
| 3407 | + if (err < 0) { |
---|
| 3408 | + bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
---|
| 3409 | + return err; |
---|
| 3410 | + } |
---|
| 3411 | + |
---|
| 3412 | + return 0; |
---|
| 3413 | +} |
---|
| 3414 | + |
---|
| 3415 | +MODULE_FIRMWARE(FIRMWARE_MT7663); |
---|
| 3416 | +MODULE_FIRMWARE(FIRMWARE_MT7668); |
---|
2403 | 3417 | |
---|
2404 | 3418 | #ifdef CONFIG_PM |
---|
2405 | 3419 | /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */ |
---|
.. | .. |
---|
2492 | 3506 | return 0; |
---|
2493 | 3507 | } |
---|
2494 | 3508 | |
---|
| 3509 | +static int btusb_set_bdaddr_wcn6855(struct hci_dev *hdev, |
---|
| 3510 | + const bdaddr_t *bdaddr) |
---|
| 3511 | +{ |
---|
| 3512 | + struct sk_buff *skb; |
---|
| 3513 | + u8 buf[6]; |
---|
| 3514 | + long ret; |
---|
| 3515 | + |
---|
| 3516 | + memcpy(buf, bdaddr, sizeof(bdaddr_t)); |
---|
| 3517 | + |
---|
| 3518 | + skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(buf), buf, |
---|
| 3519 | + HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT); |
---|
| 3520 | + if (IS_ERR(skb)) { |
---|
| 3521 | + ret = PTR_ERR(skb); |
---|
| 3522 | + bt_dev_err(hdev, "Change address command failed (%ld)", ret); |
---|
| 3523 | + return ret; |
---|
| 3524 | + } |
---|
| 3525 | + kfree_skb(skb); |
---|
| 3526 | + |
---|
| 3527 | + return 0; |
---|
| 3528 | +} |
---|
| 3529 | + |
---|
2495 | 3530 | #define QCA_DFU_PACKET_LEN 4096 |
---|
2496 | 3531 | |
---|
2497 | 3532 | #define QCA_GET_TARGET_VERSION 0x09 |
---|
.. | .. |
---|
2511 | 3546 | } __packed; |
---|
2512 | 3547 | |
---|
2513 | 3548 | struct qca_rampatch_version { |
---|
2514 | | - __le16 rom_version; |
---|
| 3549 | + __le16 rom_version_high; |
---|
| 3550 | + __le16 rom_version_low; |
---|
2515 | 3551 | __le16 patch_version; |
---|
2516 | 3552 | } __packed; |
---|
2517 | 3553 | |
---|
.. | .. |
---|
2523 | 3559 | }; |
---|
2524 | 3560 | |
---|
2525 | 3561 | static const struct qca_device_info qca_devices_table[] = { |
---|
2526 | | - { 0x00000100, 20, 4, 10 }, /* Rome 1.0 */ |
---|
2527 | | - { 0x00000101, 20, 4, 10 }, /* Rome 1.1 */ |
---|
2528 | | - { 0x00000200, 28, 4, 18 }, /* Rome 2.0 */ |
---|
2529 | | - { 0x00000201, 28, 4, 18 }, /* Rome 2.1 */ |
---|
2530 | | - { 0x00000300, 28, 4, 18 }, /* Rome 3.0 */ |
---|
2531 | | - { 0x00000302, 28, 4, 18 }, /* Rome 3.2 */ |
---|
| 3562 | + { 0x00000100, 20, 4, 8 }, /* Rome 1.0 */ |
---|
| 3563 | + { 0x00000101, 20, 4, 8 }, /* Rome 1.1 */ |
---|
| 3564 | + { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */ |
---|
| 3565 | + { 0x00000201, 28, 4, 16 }, /* Rome 2.1 */ |
---|
| 3566 | + { 0x00000300, 28, 4, 16 }, /* Rome 3.0 */ |
---|
| 3567 | + { 0x00000302, 28, 4, 16 }, /* Rome 3.2 */ |
---|
| 3568 | + { 0x00130100, 40, 4, 16 }, /* WCN6855 1.0 */ |
---|
| 3569 | + { 0x00130200, 40, 4, 16 }, /* WCN6855 2.0 */ |
---|
2532 | 3570 | }; |
---|
2533 | 3571 | |
---|
2534 | 3572 | static int btusb_qca_send_vendor_req(struct usb_device *udev, u8 request, |
---|
.. | .. |
---|
2635 | 3673 | { |
---|
2636 | 3674 | struct qca_rampatch_version *rver; |
---|
2637 | 3675 | const struct firmware *fw; |
---|
2638 | | - u32 ver_rom, ver_patch; |
---|
2639 | | - u16 rver_rom, rver_patch; |
---|
| 3676 | + u32 ver_rom, ver_patch, rver_rom; |
---|
| 3677 | + u16 rver_rom_low, rver_rom_high, rver_patch; |
---|
2640 | 3678 | char fwname[64]; |
---|
2641 | 3679 | int err; |
---|
2642 | 3680 | |
---|
.. | .. |
---|
2655 | 3693 | bt_dev_info(hdev, "using rampatch file: %s", fwname); |
---|
2656 | 3694 | |
---|
2657 | 3695 | rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset); |
---|
2658 | | - rver_rom = le16_to_cpu(rver->rom_version); |
---|
| 3696 | + rver_rom_low = le16_to_cpu(rver->rom_version_low); |
---|
2659 | 3697 | rver_patch = le16_to_cpu(rver->patch_version); |
---|
| 3698 | + |
---|
| 3699 | + if (ver_rom & ~0xffffU) { |
---|
| 3700 | + rver_rom_high = le16_to_cpu(rver->rom_version_high); |
---|
| 3701 | + rver_rom = le32_to_cpu(rver_rom_high << 16 | rver_rom_low); |
---|
| 3702 | + } else { |
---|
| 3703 | + rver_rom = rver_rom_low; |
---|
| 3704 | + } |
---|
2660 | 3705 | |
---|
2661 | 3706 | bt_dev_info(hdev, "QCA: patch rome 0x%x build 0x%x, " |
---|
2662 | 3707 | "firmware rome 0x%x build 0x%x", |
---|
.. | .. |
---|
2731 | 3776 | return err; |
---|
2732 | 3777 | |
---|
2733 | 3778 | ver_rom = le32_to_cpu(ver.rom_version); |
---|
2734 | | - /* Don't care about high ROM versions */ |
---|
2735 | | - if (ver_rom & ~0xffffU) |
---|
2736 | | - return 0; |
---|
2737 | 3779 | |
---|
2738 | 3780 | for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) { |
---|
2739 | 3781 | if (ver_rom == qca_devices_table[i].rom_version) |
---|
2740 | 3782 | info = &qca_devices_table[i]; |
---|
2741 | 3783 | } |
---|
2742 | 3784 | if (!info) { |
---|
| 3785 | + /* If the rom_version is not matched in the qca_devices_table |
---|
| 3786 | + * and the high ROM version is not zero, we assume this chip no |
---|
| 3787 | + * need to load the rampatch and nvm. |
---|
| 3788 | + */ |
---|
| 3789 | + if (ver_rom & ~0xffffU) |
---|
| 3790 | + return 0; |
---|
| 3791 | + |
---|
2743 | 3792 | bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom); |
---|
2744 | 3793 | return -ENODEV; |
---|
2745 | 3794 | } |
---|
.. | .. |
---|
2764 | 3813 | return 0; |
---|
2765 | 3814 | } |
---|
2766 | 3815 | |
---|
2767 | | -#ifdef CONFIG_BT_HCIBTUSB_BCM |
---|
2768 | 3816 | static inline int __set_diag_interface(struct hci_dev *hdev) |
---|
2769 | 3817 | { |
---|
2770 | 3818 | struct btusb_data *data = hci_get_drvdata(hdev); |
---|
.. | .. |
---|
2851 | 3899 | |
---|
2852 | 3900 | return submit_or_queue_tx_urb(hdev, urb); |
---|
2853 | 3901 | } |
---|
2854 | | -#endif |
---|
2855 | 3902 | |
---|
2856 | 3903 | #ifdef CONFIG_PM |
---|
2857 | 3904 | static irqreturn_t btusb_oob_wake_handler(int irq, void *priv) |
---|
.. | .. |
---|
2871 | 3918 | |
---|
2872 | 3919 | static const struct of_device_id btusb_match_table[] = { |
---|
2873 | 3920 | { .compatible = "usb1286,204e" }, |
---|
| 3921 | + { .compatible = "usbcf3,e300" }, /* QCA6174A */ |
---|
| 3922 | + { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */ |
---|
2874 | 3923 | { } |
---|
2875 | 3924 | }; |
---|
2876 | 3925 | MODULE_DEVICE_TABLE(of, btusb_match_table); |
---|
.. | .. |
---|
2920 | 3969 | interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; |
---|
2921 | 3970 | } |
---|
2922 | 3971 | |
---|
| 3972 | +static bool btusb_prevent_wake(struct hci_dev *hdev) |
---|
| 3973 | +{ |
---|
| 3974 | + struct btusb_data *data = hci_get_drvdata(hdev); |
---|
| 3975 | + |
---|
| 3976 | + if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) |
---|
| 3977 | + return true; |
---|
| 3978 | + |
---|
| 3979 | + return !device_may_wakeup(&data->udev->dev); |
---|
| 3980 | +} |
---|
| 3981 | + |
---|
2923 | 3982 | static int btusb_probe(struct usb_interface *intf, |
---|
2924 | 3983 | const struct usb_device_id *id) |
---|
2925 | 3984 | { |
---|
2926 | 3985 | struct usb_endpoint_descriptor *ep_desc; |
---|
| 3986 | + struct gpio_desc *reset_gpio; |
---|
2927 | 3987 | struct btusb_data *data; |
---|
2928 | 3988 | struct hci_dev *hdev; |
---|
2929 | 3989 | unsigned ifnum_base; |
---|
.. | .. |
---|
3010 | 4070 | init_usb_anchor(&data->bulk_anchor); |
---|
3011 | 4071 | init_usb_anchor(&data->isoc_anchor); |
---|
3012 | 4072 | init_usb_anchor(&data->diag_anchor); |
---|
| 4073 | + init_usb_anchor(&data->ctrl_anchor); |
---|
3013 | 4074 | spin_lock_init(&data->rxlock); |
---|
3014 | 4075 | |
---|
3015 | 4076 | if (id->driver_info & BTUSB_INTEL_NEW) { |
---|
.. | .. |
---|
3037 | 4098 | |
---|
3038 | 4099 | SET_HCIDEV_DEV(hdev, &intf->dev); |
---|
3039 | 4100 | |
---|
| 4101 | + reset_gpio = gpiod_get_optional(&data->udev->dev, "reset", |
---|
| 4102 | + GPIOD_OUT_LOW); |
---|
| 4103 | + if (IS_ERR(reset_gpio)) { |
---|
| 4104 | + err = PTR_ERR(reset_gpio); |
---|
| 4105 | + goto out_free_dev; |
---|
| 4106 | + } else if (reset_gpio) { |
---|
| 4107 | + data->reset_gpio = reset_gpio; |
---|
| 4108 | + } |
---|
| 4109 | + |
---|
3040 | 4110 | hdev->open = btusb_open; |
---|
3041 | 4111 | hdev->close = btusb_close; |
---|
3042 | 4112 | hdev->flush = btusb_flush; |
---|
3043 | 4113 | hdev->send = btusb_send_frame; |
---|
3044 | 4114 | hdev->notify = btusb_notify; |
---|
| 4115 | + hdev->prevent_wake = btusb_prevent_wake; |
---|
3045 | 4116 | |
---|
3046 | 4117 | #ifdef CONFIG_PM |
---|
3047 | 4118 | err = btusb_config_oob_wake(hdev); |
---|
.. | .. |
---|
3064 | 4135 | if (id->driver_info & BTUSB_BCM92035) |
---|
3065 | 4136 | hdev->setup = btusb_setup_bcm92035; |
---|
3066 | 4137 | |
---|
3067 | | -#ifdef CONFIG_BT_HCIBTUSB_BCM |
---|
3068 | | - if (id->driver_info & BTUSB_BCM_PATCHRAM) { |
---|
| 4138 | + if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && |
---|
| 4139 | + (id->driver_info & BTUSB_BCM_PATCHRAM)) { |
---|
3069 | 4140 | hdev->manufacturer = 15; |
---|
3070 | 4141 | hdev->setup = btbcm_setup_patchram; |
---|
3071 | 4142 | hdev->set_diag = btusb_bcm_set_diag; |
---|
.. | .. |
---|
3075 | 4146 | data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); |
---|
3076 | 4147 | } |
---|
3077 | 4148 | |
---|
3078 | | - if (id->driver_info & BTUSB_BCM_APPLE) { |
---|
| 4149 | + if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && |
---|
| 4150 | + (id->driver_info & BTUSB_BCM_APPLE)) { |
---|
3079 | 4151 | hdev->manufacturer = 15; |
---|
3080 | 4152 | hdev->setup = btbcm_setup_apple; |
---|
3081 | 4153 | hdev->set_diag = btusb_bcm_set_diag; |
---|
.. | .. |
---|
3083 | 4155 | /* Broadcom LM_DIAG Interface numbers are hardcoded */ |
---|
3084 | 4156 | data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); |
---|
3085 | 4157 | } |
---|
3086 | | -#endif |
---|
3087 | 4158 | |
---|
3088 | 4159 | if (id->driver_info & BTUSB_INTEL) { |
---|
3089 | 4160 | hdev->manufacturer = 2; |
---|
.. | .. |
---|
3091 | 4162 | hdev->shutdown = btusb_shutdown_intel; |
---|
3092 | 4163 | hdev->set_diag = btintel_set_diag_mfg; |
---|
3093 | 4164 | hdev->set_bdaddr = btintel_set_bdaddr; |
---|
| 4165 | + hdev->cmd_timeout = btusb_intel_cmd_timeout; |
---|
3094 | 4166 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
---|
3095 | 4167 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
---|
3096 | 4168 | set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); |
---|
.. | .. |
---|
3100 | 4172 | hdev->manufacturer = 2; |
---|
3101 | 4173 | hdev->send = btusb_send_frame_intel; |
---|
3102 | 4174 | hdev->setup = btusb_setup_intel_new; |
---|
| 4175 | + hdev->shutdown = btusb_shutdown_intel_new; |
---|
3103 | 4176 | hdev->hw_error = btintel_hw_error; |
---|
3104 | 4177 | hdev->set_diag = btintel_set_diag; |
---|
3105 | 4178 | hdev->set_bdaddr = btintel_set_bdaddr; |
---|
| 4179 | + hdev->cmd_timeout = btusb_intel_cmd_timeout; |
---|
3106 | 4180 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
---|
| 4181 | + set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
---|
3107 | 4182 | set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); |
---|
3108 | 4183 | } |
---|
3109 | 4184 | |
---|
3110 | 4185 | if (id->driver_info & BTUSB_MARVELL) |
---|
3111 | 4186 | hdev->set_bdaddr = btusb_set_bdaddr_marvell; |
---|
| 4187 | + |
---|
| 4188 | + if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) && |
---|
| 4189 | + (id->driver_info & BTUSB_MEDIATEK)) { |
---|
| 4190 | + hdev->setup = btusb_mtk_setup; |
---|
| 4191 | + hdev->shutdown = btusb_mtk_shutdown; |
---|
| 4192 | + hdev->manufacturer = 70; |
---|
| 4193 | + set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); |
---|
| 4194 | + } |
---|
3112 | 4195 | |
---|
3113 | 4196 | if (id->driver_info & BTUSB_SWAVE) { |
---|
3114 | 4197 | set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks); |
---|
.. | .. |
---|
3130 | 4213 | if (id->driver_info & BTUSB_QCA_ROME) { |
---|
3131 | 4214 | data->setup_on_usb = btusb_setup_qca; |
---|
3132 | 4215 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
---|
| 4216 | + hdev->cmd_timeout = btusb_qca_cmd_timeout; |
---|
3133 | 4217 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
---|
3134 | 4218 | btusb_check_needs_reset_resume(intf); |
---|
3135 | 4219 | } |
---|
3136 | 4220 | |
---|
3137 | | -#ifdef CONFIG_BT_HCIBTUSB_RTL |
---|
3138 | | - if (id->driver_info & BTUSB_REALTEK) { |
---|
3139 | | - hdev->setup = btrtl_setup_realtek; |
---|
3140 | | - hdev->shutdown = btrtl_shutdown_realtek; |
---|
3141 | | - |
---|
3142 | | - /* Realtek devices lose their updated firmware over suspend, |
---|
3143 | | - * but the USB hub doesn't notice any status change. |
---|
3144 | | - * Explicitly request a device reset on resume. |
---|
3145 | | - */ |
---|
3146 | | - interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; |
---|
| 4221 | + if (id->driver_info & BTUSB_QCA_WCN6855) { |
---|
| 4222 | + data->setup_on_usb = btusb_setup_qca; |
---|
| 4223 | + hdev->set_bdaddr = btusb_set_bdaddr_wcn6855; |
---|
| 4224 | + hdev->cmd_timeout = btusb_qca_cmd_timeout; |
---|
| 4225 | + set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
---|
3147 | 4226 | } |
---|
3148 | | -#endif |
---|
3149 | 4227 | |
---|
3150 | 4228 | if (id->driver_info & BTUSB_AMP) { |
---|
3151 | 4229 | /* AMP controllers do not support SCO packets */ |
---|
.. | .. |
---|
3154 | 4232 | /* Interface orders are hardcoded in the specification */ |
---|
3155 | 4233 | data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); |
---|
3156 | 4234 | data->isoc_ifnum = ifnum_base + 1; |
---|
| 4235 | + } |
---|
| 4236 | + |
---|
| 4237 | + if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) && |
---|
| 4238 | + (id->driver_info & BTUSB_REALTEK)) { |
---|
| 4239 | + hdev->setup = btrtl_setup_realtek; |
---|
| 4240 | + hdev->shutdown = btrtl_shutdown_realtek; |
---|
| 4241 | + hdev->cmd_timeout = btusb_rtl_cmd_timeout; |
---|
| 4242 | + |
---|
| 4243 | + /* Realtek devices lose their updated firmware over global |
---|
| 4244 | + * suspend that means host doesn't send SET_FEATURE |
---|
| 4245 | + * (DEVICE_REMOTE_WAKEUP) |
---|
| 4246 | + */ |
---|
| 4247 | + set_bit(BTUSB_WAKEUP_DISABLE, &data->flags); |
---|
| 4248 | + set_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags); |
---|
3157 | 4249 | } |
---|
3158 | 4250 | |
---|
3159 | 4251 | if (!reset) |
---|
.. | .. |
---|
3166 | 4258 | |
---|
3167 | 4259 | if (id->driver_info & BTUSB_BROKEN_ISOC) |
---|
3168 | 4260 | data->isoc = NULL; |
---|
| 4261 | + |
---|
| 4262 | + if (id->driver_info & BTUSB_WIDEBAND_SPEECH) |
---|
| 4263 | + set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks); |
---|
| 4264 | + |
---|
| 4265 | + if (id->driver_info & BTUSB_VALID_LE_STATES) |
---|
| 4266 | + set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks); |
---|
3169 | 4267 | |
---|
3170 | 4268 | if (id->driver_info & BTUSB_DIGIANSWER) { |
---|
3171 | 4269 | data->cmdreq_type = USB_TYPE_VENDOR; |
---|
.. | .. |
---|
3180 | 4278 | if (bcdDevice < 0x117) |
---|
3181 | 4279 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
---|
3182 | 4280 | |
---|
3183 | | - /* Fake CSR devices with broken commands */ |
---|
3184 | | - if (bcdDevice <= 0x100 || bcdDevice == 0x134) |
---|
3185 | | - hdev->setup = btusb_setup_csr; |
---|
3186 | | - |
---|
| 4281 | + /* This must be set first in case we disable it for fakes */ |
---|
3187 | 4282 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
---|
| 4283 | + |
---|
| 4284 | + /* Fake CSR devices with broken commands */ |
---|
| 4285 | + if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 && |
---|
| 4286 | + le16_to_cpu(udev->descriptor.idProduct) == 0x0001) |
---|
| 4287 | + hdev->setup = btusb_setup_csr; |
---|
3188 | 4288 | } |
---|
3189 | 4289 | |
---|
3190 | 4290 | if (id->driver_info & BTUSB_SNIFFER) { |
---|
.. | .. |
---|
3213 | 4313 | goto out_free_dev; |
---|
3214 | 4314 | } |
---|
3215 | 4315 | |
---|
3216 | | -#ifdef CONFIG_BT_HCIBTUSB_BCM |
---|
3217 | | - if (data->diag) { |
---|
| 4316 | + if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) { |
---|
3218 | 4317 | if (!usb_driver_claim_interface(&btusb_driver, |
---|
3219 | 4318 | data->diag, data)) |
---|
3220 | 4319 | __set_diag_interface(hdev); |
---|
3221 | 4320 | else |
---|
3222 | 4321 | data->diag = NULL; |
---|
3223 | 4322 | } |
---|
3224 | | -#endif |
---|
3225 | 4323 | |
---|
3226 | 4324 | if (enable_autosuspend) |
---|
3227 | 4325 | usb_enable_autosuspend(data->udev); |
---|
.. | .. |
---|
3235 | 4333 | return 0; |
---|
3236 | 4334 | |
---|
3237 | 4335 | out_free_dev: |
---|
| 4336 | + if (data->reset_gpio) |
---|
| 4337 | + gpiod_put(data->reset_gpio); |
---|
3238 | 4338 | hci_free_dev(hdev); |
---|
3239 | 4339 | return err; |
---|
3240 | 4340 | } |
---|
.. | .. |
---|
3278 | 4378 | if (data->oob_wake_irq) |
---|
3279 | 4379 | device_init_wakeup(&data->udev->dev, false); |
---|
3280 | 4380 | |
---|
| 4381 | + if (data->reset_gpio) |
---|
| 4382 | + gpiod_put(data->reset_gpio); |
---|
| 4383 | + |
---|
3281 | 4384 | hci_free_dev(hdev); |
---|
3282 | 4385 | } |
---|
3283 | 4386 | |
---|
.. | .. |
---|
3312 | 4415 | enable_irq(data->oob_wake_irq); |
---|
3313 | 4416 | } |
---|
3314 | 4417 | |
---|
| 4418 | + /* For global suspend, Realtek devices lose the loaded fw |
---|
| 4419 | + * in them. But for autosuspend, firmware should remain. |
---|
| 4420 | + * Actually, it depends on whether the usb host sends |
---|
| 4421 | + * set feature (enable wakeup) or not. |
---|
| 4422 | + */ |
---|
| 4423 | + if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) { |
---|
| 4424 | + if (PMSG_IS_AUTO(message) && |
---|
| 4425 | + device_can_wakeup(&data->udev->dev)) |
---|
| 4426 | + data->udev->do_remote_wakeup = 1; |
---|
| 4427 | + else if (!PMSG_IS_AUTO(message)) |
---|
| 4428 | + data->udev->reset_resume = 1; |
---|
| 4429 | + } |
---|
| 4430 | + |
---|
3315 | 4431 | return 0; |
---|
3316 | 4432 | } |
---|
3317 | 4433 | |
---|