Merge v5.9-rc1 into drm-misc-next
[linux-2.6-microblaze.git] / drivers / bluetooth / btusb.c
index 3bdec42..8d2608d 100644 (file)
@@ -58,6 +58,7 @@ static struct usb_driver btusb_driver;
 #define BTUSB_CW6622           0x100000
 #define BTUSB_MEDIATEK         0x200000
 #define BTUSB_WIDEBAND_SPEECH  0x400000
+#define BTUSB_VALID_LE_STATES   0x800000
 
 static const struct usb_device_id btusb_table[] = {
        /* Generic Bluetooth USB device */
@@ -335,11 +336,14 @@ static const struct usb_device_id blacklist_table[] = {
 
        /* Intel Bluetooth devices */
        { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_NEW |
-                                                    BTUSB_WIDEBAND_SPEECH },
+                                                    BTUSB_WIDEBAND_SPEECH |
+                                                    BTUSB_VALID_LE_STATES },
        { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_NEW |
                                                     BTUSB_WIDEBAND_SPEECH },
        { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_NEW |
                                                     BTUSB_WIDEBAND_SPEECH },
+       { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_NEW |
+                                                    BTUSB_WIDEBAND_SPEECH},
        { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR },
        { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL },
        { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL },
@@ -348,12 +352,17 @@ static const struct usb_device_id blacklist_table[] = {
        { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL |
                                                     BTUSB_WIDEBAND_SPEECH },
        { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_NEW |
-                                                    BTUSB_WIDEBAND_SPEECH },
+                                                    BTUSB_WIDEBAND_SPEECH |
+                                                    BTUSB_VALID_LE_STATES },
 
        /* Other Intel Bluetooth devices */
        { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01),
          .driver_info = BTUSB_IGNORE },
 
+       /* Realtek 8822CE Bluetooth devices */
+       { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK |
+                                                    BTUSB_WIDEBAND_SPEECH },
+
        /* Realtek Bluetooth devices */
        { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01),
          .driver_info = BTUSB_REALTEK },
@@ -448,6 +457,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
 #define BTUSB_HW_RESET_ACTIVE  12
 #define BTUSB_TX_WAIT_VND_EVT  13
 #define BTUSB_WAKEUP_DISABLE   14
+#define BTUSB_USE_ALT1_FOR_WBS 15
 
 struct btusb_data {
        struct hci_dev       *hdev;
@@ -492,6 +502,8 @@ struct btusb_data {
        __u8 cmdreq;
 
        unsigned int sco_num;
+       unsigned int air_mode;
+       bool usb_alt6_packet_flow;
        int isoc_altsetting;
        int suspend_count;
 
@@ -504,7 +516,6 @@ struct btusb_data {
        unsigned cmd_timeout_cnt;
 };
 
-
 static void btusb_intel_cmd_timeout(struct hci_dev *hdev)
 {
        struct btusb_data *data = hci_get_drvdata(hdev);
@@ -566,6 +577,23 @@ static void btusb_rtl_cmd_timeout(struct hci_dev *hdev)
        gpiod_set_value_cansleep(reset_gpio, 0);
 }
 
+static void btusb_qca_cmd_timeout(struct hci_dev *hdev)
+{
+       struct btusb_data *data = hci_get_drvdata(hdev);
+       int err;
+
+       if (++data->cmd_timeout_cnt < 5)
+               return;
+
+       bt_dev_err(hdev, "Multiple cmd timeouts seen. Resetting usb device.");
+       /* This is not an unbalanced PM reference since the device will reset */
+       err = usb_autopm_get_interface(data->intf);
+       if (!err)
+               usb_queue_reset_device(data->intf);
+       else
+               bt_dev_err(hdev, "Failed usb_autopm_get_interface with %d", err);
+}
+
 static inline void btusb_free_frags(struct btusb_data *data)
 {
        unsigned long flags;
@@ -983,6 +1011,42 @@ static void btusb_isoc_complete(struct urb *urb)
        }
 }
 
+static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len,
+                                              int mtu, struct btusb_data *data)
+{
+       int i, offset = 0;
+       unsigned int interval;
+
+       BT_DBG("len %d mtu %d", len, mtu);
+
+       /* For mSBC ALT 6 setting the host will send the packet at continuous
+        * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting
+        * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets.
+        * To maintain the rate we send 63bytes of usb packets alternatively for
+        * 7ms and 8ms to maintain the rate as 7.5ms.
+        */
+       if (data->usb_alt6_packet_flow) {
+               interval = 7;
+               data->usb_alt6_packet_flow = false;
+       } else {
+               interval = 6;
+               data->usb_alt6_packet_flow = true;
+       }
+
+       for (i = 0; i < interval; i++) {
+               urb->iso_frame_desc[i].offset = offset;
+               urb->iso_frame_desc[i].length = offset;
+       }
+
+       if (len && i < BTUSB_MAX_ISOC_FRAMES) {
+               urb->iso_frame_desc[i].offset = offset;
+               urb->iso_frame_desc[i].length = len;
+               i++;
+       }
+
+       urb->number_of_packets = i;
+}
+
 static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
 {
        int i, offset = 0;
@@ -1386,9 +1450,13 @@ static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb)
 
        urb->transfer_flags  = URB_ISO_ASAP;
 
-       __fill_isoc_descriptor(urb, skb->len,
-                              le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
-
+       if (data->isoc_altsetting == 6)
+               __fill_isoc_descriptor_msbc(urb, skb->len,
+                                           le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize),
+                                           data);
+       else
+               __fill_isoc_descriptor(urb, skb->len,
+                                      le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
        skb->dev = (void *)hdev;
 
        return urb;
@@ -1484,6 +1552,7 @@ static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
 
        if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) {
                data->sco_num = hci_conn_num(hdev, SCO_LINK);
+               data->air_mode = evt;
                schedule_work(&data->work);
        }
 }
@@ -1531,11 +1600,70 @@ static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
        return 0;
 }
 
+static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts)
+{
+       struct btusb_data *data = hci_get_drvdata(hdev);
+       int err;
+
+       if (data->isoc_altsetting != new_alts) {
+               unsigned long flags;
+
+               clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
+               usb_kill_anchored_urbs(&data->isoc_anchor);
+
+               /* When isochronous alternate setting needs to be
+                * changed, because SCO connection has been added
+                * or removed, a packet fragment may be left in the
+                * reassembling state. This could lead to wrongly
+                * assembled fragments.
+                *
+                * Clear outstanding fragment when selecting a new
+                * alternate setting.
+                */
+               spin_lock_irqsave(&data->rxlock, flags);
+               kfree_skb(data->sco_skb);
+               data->sco_skb = NULL;
+               spin_unlock_irqrestore(&data->rxlock, flags);
+
+               err = __set_isoc_interface(hdev, new_alts);
+               if (err < 0)
+                       return err;
+       }
+
+       if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
+               if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
+                       clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
+               else
+                       btusb_submit_isoc_urb(hdev, GFP_KERNEL);
+       }
+
+       return 0;
+}
+
+static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data,
+                                                       int alt)
+{
+       struct usb_interface *intf = data->isoc;
+       int i;
+
+       BT_DBG("Looking for Alt no :%d", alt);
+
+       if (!intf)
+               return NULL;
+
+       for (i = 0; i < intf->num_altsetting; i++) {
+               if (intf->altsetting[i].desc.bAlternateSetting == alt)
+                       return &intf->altsetting[i];
+       }
+
+       return NULL;
+}
+
 static void btusb_work(struct work_struct *work)
 {
        struct btusb_data *data = container_of(work, struct btusb_data, work);
        struct hci_dev *hdev = data->hdev;
-       int new_alts;
+       int new_alts = 0;
        int err;
 
        if (data->sco_num > 0) {
@@ -1550,44 +1678,28 @@ static void btusb_work(struct work_struct *work)
                        set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
                }
 
-               if (hdev->voice_setting & 0x0020) {
-                       static const int alts[3] = { 2, 4, 5 };
-
-                       new_alts = alts[data->sco_num - 1];
-               } else {
-                       new_alts = data->sco_num;
-               }
-
-               if (data->isoc_altsetting != new_alts) {
-                       unsigned long flags;
+               if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) {
+                       if (hdev->voice_setting & 0x0020) {
+                               static const int alts[3] = { 2, 4, 5 };
 
-                       clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
-                       usb_kill_anchored_urbs(&data->isoc_anchor);
-
-                       /* When isochronous alternate setting needs to be
-                        * changed, because SCO connection has been added
-                        * or removed, a packet fragment may be left in the
-                        * reassembling state. This could lead to wrongly
-                        * assembled fragments.
-                        *
-                        * Clear outstanding fragment when selecting a new
-                        * alternate setting.
-                        */
-                       spin_lock_irqsave(&data->rxlock, flags);
-                       kfree_skb(data->sco_skb);
-                       data->sco_skb = NULL;
-                       spin_unlock_irqrestore(&data->rxlock, flags);
-
-                       if (__set_isoc_interface(hdev, new_alts) < 0)
-                               return;
+                               new_alts = alts[data->sco_num - 1];
+                       } else {
+                               new_alts = data->sco_num;
+                       }
+               } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) {
+                       /* Check if Alt 6 is supported for Transparent audio */
+                       if (btusb_find_altsetting(data, 6)) {
+                               data->usb_alt6_packet_flow = true;
+                               new_alts = 6;
+                       } else if (test_bit(BTUSB_USE_ALT1_FOR_WBS, &data->flags)) {
+                               new_alts = 1;
+                       } else {
+                               bt_dev_err(hdev, "Device does not support ALT setting 6");
+                       }
                }
 
-               if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
-                       if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
-                               clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
-                       else
-                               btusb_submit_isoc_urb(hdev, GFP_KERNEL);
-               }
+               if (btusb_switch_alt_setting(hdev, new_alts) < 0)
+                       bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts);
        } else {
                clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
                usb_kill_anchored_urbs(&data->isoc_anchor);
@@ -1630,6 +1742,7 @@ static int btusb_setup_csr(struct hci_dev *hdev)
 {
        struct hci_rp_read_local_version *rp;
        struct sk_buff *skb;
+       bool is_fake = false;
 
        BT_DBG("%s", hdev->name);
 
@@ -1649,18 +1762,69 @@ static int btusb_setup_csr(struct hci_dev *hdev)
 
        rp = (struct hci_rp_read_local_version *)skb->data;
 
-       /* Detect controllers which aren't real CSR ones. */
+       /* Detect a wide host of Chinese controllers that aren't CSR.
+        *
+        * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891
+        *
+        * The main thing they have in common is that these are really popular low-cost
+        * options that support newer Bluetooth versions but rely on heavy VID/PID
+        * squatting of this poor old Bluetooth 1.1 device. Even sold as such.
+        *
+        * We detect actual CSR devices by checking that the HCI manufacturer code
+        * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and
+        * HCI rev values always match. As they both store the firmware number.
+        */
        if (le16_to_cpu(rp->manufacturer) != 10 ||
-           le16_to_cpu(rp->lmp_subver) == 0x0c5c) {
+           le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver))
+               is_fake = true;
+
+       /* Known legit CSR firmware build numbers and their supported BT versions:
+        * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e
+        * - 1.2 (0x2) ->                 0x04d9, 0x0529
+        * - 2.0 (0x3) ->         0x07a6, 0x07ad, 0x0c5c
+        * - 2.1 (0x4) ->         0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External)
+        * - 4.0 (0x6) ->         0x1d86, 0x2031, 0x22bb
+        *
+        * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that
+        *      support BT 1.1 only; so it's a dead giveaway when some
+        *      third-party BT 4.0 dongle reuses it.
+        */
+       else if (le16_to_cpu(rp->lmp_subver) <= 0x034e &&
+                le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_1)
+               is_fake = true;
+
+       else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 &&
+                le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_2)
+               is_fake = true;
+
+       else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c &&
+                le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_0)
+               is_fake = true;
+
+       else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 &&
+                le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_1)
+               is_fake = true;
+
+       else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb &&
+                le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_4_0)
+               is_fake = true;
+
+       if (is_fake) {
+               bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds...");
+
+               /* Generally these clones have big discrepancies between
+                * advertised features and what's actually supported.
+                * Probably will need to be expanded in the future;
+                * without these the controller will lock up.
+                */
+               set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
+               set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks);
+
                /* Clear the reset quirk since this is not an actual
                 * early Bluetooth 1.1 device from CSR.
                 */
                clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
-
-               /* These fake CSR controllers have all a broken
-                * stored link key handling and so just disable it.
-                */
-               set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks);
+               clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
        }
 
        kfree_skb(skb);
@@ -2172,45 +2336,25 @@ static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver,
        return true;
 }
 
-static int btusb_setup_intel_new(struct hci_dev *hdev)
+static int btusb_intel_download_firmware(struct hci_dev *hdev,
+                                        struct intel_version *ver,
+                                        struct intel_boot_params *params)
 {
-       struct btusb_data *data = hci_get_drvdata(hdev);
-       struct intel_version ver;
-       struct intel_boot_params params;
        const struct firmware *fw;
        u32 boot_param;
        char fwname[64];
-       ktime_t calltime, delta, rettime;
-       unsigned long long duration;
        int err;
+       struct btusb_data *data = hci_get_drvdata(hdev);
 
-       BT_DBG("%s", hdev->name);
-
-       /* Set the default boot parameter to 0x0 and it is updated to
-        * SKU specific boot parameter after reading Intel_Write_Boot_Params
-        * command while downloading the firmware.
-        */
-       boot_param = 0x00000000;
-
-       calltime = ktime_get();
-
-       /* Read the Intel version information to determine if the device
-        * is in bootloader mode or if it already has operational firmware
-        * loaded.
-        */
-       err = btintel_read_version(hdev, &ver);
-       if (err) {
-               bt_dev_err(hdev, "Intel Read version failed (%d)", err);
-               btintel_reset_to_bootloader(hdev);
-               return err;
-       }
+       if (!ver || !params)
+               return -EINVAL;
 
        /* The hardware platform number has a fixed value of 0x37 and
         * for now only accept this single value.
         */
-       if (ver.hw_platform != 0x37) {
+       if (ver->hw_platform != 0x37) {
                bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)",
-                          ver.hw_platform);
+                          ver->hw_platform);
                return -EINVAL;
        }
 
@@ -2220,7 +2364,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
         * This check has been put in place to ensure correct forward
         * compatibility options when newer hardware variants come along.
         */
-       switch (ver.hw_variant) {
+       switch (ver->hw_variant) {
        case 0x0b:      /* SfP */
        case 0x0c:      /* WsP */
        case 0x11:      /* JfP */
@@ -2230,11 +2374,11 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
                break;
        default:
                bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)",
-                          ver.hw_variant);
+                          ver->hw_variant);
                return -EINVAL;
        }
 
-       btintel_version_info(hdev, &ver);
+       btintel_version_info(hdev, ver);
 
        /* The firmware variant determines if the device is in bootloader
         * mode or is running operational firmware. The value 0x06 identifies
@@ -2249,7 +2393,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
         * It is not possible to use the Secure Boot Parameters in this
         * case since that command is only available in bootloader mode.
         */
-       if (ver.fw_variant == 0x23) {
+       if (ver->fw_variant == 0x23) {
                clear_bit(BTUSB_BOOTLOADER, &data->flags);
                btintel_check_bdaddr(hdev);
                return 0;
@@ -2258,16 +2402,16 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
        /* If the device is not in bootloader mode, then the only possible
         * choice is to return an error and abort the device initialization.
         */
-       if (ver.fw_variant != 0x06) {
+       if (ver->fw_variant != 0x06) {
                bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)",
-                          ver.fw_variant);
+                          ver->fw_variant);
                return -ENODEV;
        }
 
        /* Read the secure boot parameters to identify the operating
         * details of the bootloader.
         */
-       err = btintel_read_boot_params(hdev, &params);
+       err = btintel_read_boot_params(hdev, params);
        if (err)
                return err;
 
@@ -2275,16 +2419,16 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
         * with a command complete event. If the boot parameters indicate
         * that this bootloader does not send them, then abort the setup.
         */
-       if (params.limited_cce != 0x00) {
+       if (params->limited_cce != 0x00) {
                bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)",
-                          params.limited_cce);
+                          params->limited_cce);
                return -EINVAL;
        }
 
        /* If the OTP has no valid Bluetooth device address, then there will
         * also be no valid address for the operational firmware.
         */
-       if (!bacmp(&params.otp_bdaddr, BDADDR_ANY)) {
+       if (!bacmp(&params->otp_bdaddr, BDADDR_ANY)) {
                bt_dev_info(hdev, "No device address configured");
                set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
        }
@@ -2310,7 +2454,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
         * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
         *
         */
-       err = btusb_setup_intel_new_get_fw_name(&ver, &params, fwname,
+       err = btusb_setup_intel_new_get_fw_name(ver, params, fwname,
                                                sizeof(fwname), "sfi");
        if (!err) {
                bt_dev_err(hdev, "Unsupported Intel firmware naming");
@@ -2325,16 +2469,6 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
 
        bt_dev_info(hdev, "Found device firmware: %s", fwname);
 
-       /* Save the DDC file name for later use to apply once the firmware
-        * downloading is done.
-        */
-       err = btusb_setup_intel_new_get_fw_name(&ver, &params, fwname,
-                                               sizeof(fwname), "ddc");
-       if (!err) {
-               bt_dev_err(hdev, "Unsupported Intel firmware naming");
-               return -EINVAL;
-       }
-
        if (fw->size < 644) {
                bt_dev_err(hdev, "Invalid size of firmware file (%zu)",
                           fw->size);
@@ -2389,18 +2523,58 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
                goto done;
        }
 
+done:
+       release_firmware(fw);
+       return err;
+}
+
+static int btusb_setup_intel_new(struct hci_dev *hdev)
+{
+       struct btusb_data *data = hci_get_drvdata(hdev);
+       struct intel_version ver;
+       struct intel_boot_params params;
+       u32 boot_param;
+       char ddcname[64];
+       ktime_t calltime, delta, rettime;
+       unsigned long long duration;
+       int err;
+       struct intel_debug_features features;
+
+       BT_DBG("%s", hdev->name);
+
+       /* Set the default boot parameter to 0x0 and it is updated to
+        * SKU specific boot parameter after reading Intel_Write_Boot_Params
+        * command while downloading the firmware.
+        */
+       boot_param = 0x00000000;
+
+       calltime = ktime_get();
+
+       /* Read the Intel version information to determine if the device
+        * is in bootloader mode or if it already has operational firmware
+        * loaded.
+        */
+       err = btintel_read_version(hdev, &ver);
+       if (err) {
+               bt_dev_err(hdev, "Intel Read version failed (%d)", err);
+               btintel_reset_to_bootloader(hdev);
+               return err;
+       }
+
+       err = btusb_intel_download_firmware(hdev, &ver, &params);
+       if (err)
+               return err;
+
+       /* controller is already having an operational firmware */
+       if (ver.fw_variant == 0x23)
+               goto finish;
+
        rettime = ktime_get();
        delta = ktime_sub(rettime, calltime);
        duration = (unsigned long long) ktime_to_ns(delta) >> 10;
 
        bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration);
 
-done:
-       release_firmware(fw);
-
-       if (err < 0)
-               return err;
-
        calltime = ktime_get();
 
        set_bit(BTUSB_BOOTING, &data->flags);
@@ -2444,13 +2618,45 @@ done:
 
        clear_bit(BTUSB_BOOTLOADER, &data->flags);
 
-       /* Once the device is running in operational mode, it needs to apply
-        * the device configuration (DDC) parameters.
-        *
-        * The device can work without DDC parameters, so even if it fails
-        * to load the file, no need to fail the setup.
+       err = btusb_setup_intel_new_get_fw_name(&ver, &params, ddcname,
+                                               sizeof(ddcname), "ddc");
+
+       if (!err) {
+               bt_dev_err(hdev, "Unsupported Intel firmware naming");
+       } else {
+               /* Once the device is running in operational mode, it needs to
+                * apply the device configuration (DDC) parameters.
+                *
+                * The device can work without DDC parameters, so even if it
+                * fails to load the file, no need to fail the setup.
+                */
+               btintel_load_ddc_config(hdev, ddcname);
+       }
+
+       /* Read the Intel supported features and if new exception formats
+        * supported, need to load the additional DDC config to enable.
         */
-       btintel_load_ddc_config(hdev, fwname);
+       btintel_read_debug_features(hdev, &features);
+
+       /* Set DDC mask for available debug features */
+       btintel_set_debug_features(hdev, &features);
+
+       /* Read the Intel version information after loading the FW  */
+       err = btintel_read_version(hdev, &ver);
+       if (err)
+               return err;
+
+       btintel_version_info(hdev, &ver);
+
+finish:
+       /* All Intel controllers that support the Microsoft vendor
+        * extension are using 0xFC1E for VsMsftOpCode.
+        */
+       switch (ver.hw_variant) {
+       case 0x12:      /* ThP */
+               hci_set_msft_opcode(hdev, 0xFC1E);
+               break;
+       }
 
        /* Set the event mask for Intel specific vendor events. This enables
         * a few extra events that are useful during general operation. It
@@ -2461,13 +2667,6 @@ done:
         */
        btintel_set_event_mask(hdev, false);
 
-       /* Read the Intel version information after loading the FW  */
-       err = btintel_read_version(hdev, &ver);
-       if (err)
-               return err;
-
-       btintel_version_info(hdev, &ver);
-
        return 0;
 }
 
@@ -2825,7 +3024,7 @@ static int btusb_mtk_setup_firmware(struct hci_dev *hdev, const char *fwname)
        const u8 *fw_ptr;
        size_t fw_size;
        int err, dlen;
-       u8 flag;
+       u8 flag, param;
 
        err = request_firmware(&fw, fwname, &hdev->dev);
        if (err < 0) {
@@ -2833,6 +3032,20 @@ static int btusb_mtk_setup_firmware(struct hci_dev *hdev, const char *fwname)
                return err;
        }
 
+       /* Power on data RAM the firmware relies on. */
+       param = 1;
+       wmt_params.op = BTMTK_WMT_FUNC_CTRL;
+       wmt_params.flag = 3;
+       wmt_params.dlen = sizeof(param);
+       wmt_params.data = &param;
+       wmt_params.status = NULL;
+
+       err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params);
+       if (err < 0) {
+               bt_dev_err(hdev, "Failed to power on data RAM (%d)", err);
+               return err;
+       }
+
        fw_ptr = fw->data;
        fw_size = fw->size;
 
@@ -3600,6 +3813,16 @@ static void btusb_check_needs_reset_resume(struct usb_interface *intf)
                interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME;
 }
 
+static bool btusb_prevent_wake(struct hci_dev *hdev)
+{
+       struct btusb_data *data = hci_get_drvdata(hdev);
+
+       if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags))
+               return true;
+
+       return !device_may_wakeup(&data->udev->dev);
+}
+
 static int btusb_probe(struct usb_interface *intf,
                       const struct usb_device_id *id)
 {
@@ -3733,6 +3956,7 @@ static int btusb_probe(struct usb_interface *intf,
        hdev->flush  = btusb_flush;
        hdev->send   = btusb_send_frame;
        hdev->notify = btusb_notify;
+       hdev->prevent_wake = btusb_prevent_wake;
 
 #ifdef CONFIG_PM
        err = btusb_config_oob_wake(hdev);
@@ -3833,10 +4057,20 @@ static int btusb_probe(struct usb_interface *intf,
        if (id->driver_info & BTUSB_QCA_ROME) {
                data->setup_on_usb = btusb_setup_qca;
                hdev->set_bdaddr = btusb_set_bdaddr_ath3012;
+               hdev->cmd_timeout = btusb_qca_cmd_timeout;
                set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
                btusb_check_needs_reset_resume(intf);
        }
 
+       if (id->driver_info & BTUSB_AMP) {
+               /* AMP controllers do not support SCO packets */
+               data->isoc = NULL;
+       } else {
+               /* Interface orders are hardcoded in the specification */
+               data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1);
+               data->isoc_ifnum = ifnum_base + 1;
+       }
+
        if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) &&
            (id->driver_info & BTUSB_REALTEK)) {
                hdev->setup = btrtl_setup_realtek;
@@ -3848,19 +4082,10 @@ static int btusb_probe(struct usb_interface *intf,
                 * (DEVICE_REMOTE_WAKEUP)
                 */
                set_bit(BTUSB_WAKEUP_DISABLE, &data->flags);
-
-               err = usb_autopm_get_interface(intf);
-               if (err < 0)
-                       goto out_free_dev;
-       }
-
-       if (id->driver_info & BTUSB_AMP) {
-               /* AMP controllers do not support SCO packets */
-               data->isoc = NULL;
-       } else {
-               /* Interface orders are hardcoded in the specification */
-               data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1);
-               data->isoc_ifnum = ifnum_base + 1;
+               if (btusb_find_altsetting(data, 1))
+                       set_bit(BTUSB_USE_ALT1_FOR_WBS, &data->flags);
+               else
+                       bt_dev_err(hdev, "Device does not support ALT setting 1");
        }
 
        if (!reset)
@@ -3877,6 +4102,9 @@ static int btusb_probe(struct usb_interface *intf,
        if (id->driver_info & BTUSB_WIDEBAND_SPEECH)
                set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks);
 
+       if (id->driver_info & BTUSB_VALID_LE_STATES)
+               set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
+
        if (id->driver_info & BTUSB_DIGIANSWER) {
                data->cmdreq_type = USB_TYPE_VENDOR;
                set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
@@ -3890,11 +4118,13 @@ static int btusb_probe(struct usb_interface *intf,
                if (bcdDevice < 0x117)
                        set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
 
+               /* This must be set first in case we disable it for fakes */
+               set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
+
                /* Fake CSR devices with broken commands */
-               if (bcdDevice <= 0x100 || bcdDevice == 0x134)
+               if (le16_to_cpu(udev->descriptor.idVendor)  == 0x0a12 &&
+                   le16_to_cpu(udev->descriptor.idProduct) == 0x0001)
                        hdev->setup = btusb_setup_csr;
-
-               set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
        }
 
        if (id->driver_info & BTUSB_SNIFFER) {