blob: 0e00dd5e69371f5926515f18079373b50d17ced4 [file]
From fcba7a18c7e71c97132a18b6c1c00b92478b9f2b Mon Sep 17 00:00:00 2001
From: Sasha Levin <sashal@kernel.org>
Date: Wed, 15 May 2024 16:15:20 -0700
Subject: Bluetooth: btusb: mediatek: reset the controller before downloading
the fw
From: Hao Qin <hao.qin@mediatek.com>
[ Upstream commit ccfc8948d7e4d93cab341a99774b24586717d89a ]
Reset the controller before downloading the firmware to improve its
reliability. This includes situations like cold or warm reboots, ensuring
the controller is in its initial state before starting the firmware
download.
Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Co-developed-by: Chris Lu <chris.lu@mediatek.com>
Signed-off-by: Chris Lu <chris.lu@mediatek.com>
Signed-off-by: Hao Qin <hao.qin@mediatek.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Stable-dep-of: 5c5e8c52e3ca ("Bluetooth: btmtk: move btusb_mtk_[setup, shutdown] to btmtk.c")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/bluetooth/btusb.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 048929e336cf64..c6b62437be2d5a 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2940,6 +2940,13 @@ static int btusb_mtk_setup(struct hci_dev *hdev)
case 0x7922:
case 0x7961:
case 0x7925:
+ /* Reset the device to ensure it's in the initial state before
+ * downloading the firmware to ensure.
+ */
+
+ if (!test_bit(BTUSB_FIRMWARE_LOADED, &data->flags))
+ btusb_mtk_subsys_reset(hdev, dev_id);
+
btmtk_fw_get_filename(fw_bin_name, sizeof(fw_bin_name), dev_id,
fw_version, 0);
@@ -2947,9 +2954,12 @@ static int btusb_mtk_setup(struct hci_dev *hdev)
btmtk_usb_hci_wmt_sync);
if (err < 0) {
bt_dev_err(hdev, "Failed to set up firmware (%d)", err);
+ clear_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
return err;
}
+ set_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
+
/* It's Device EndPoint Reset Option Register */
btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, MTK_EP_RST_IN_OUT_OPT);
--
2.53.0