From: Hao Qin <hao.qin@mediatek.com>
To: Marcel Holtmann <marcel@holtmann.org>,
Johan Hedberg <johan.hedberg@gmail.com>,
Luiz Von Dentz <luiz.dentz@gmail.com>
Cc: Sean Wang <sean.wang@mediatek.com>,
Deren Wu <deren.Wu@mediatek.com>,
Aaron Hou <aaron.hou@mediatek.com>,
Chris Lu <chris.lu@mediatek.com>,
Steve Lee <steve.lee@mediatek.com>,
linux-bluetooth <linux-bluetooth@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
linux-mediatek <linux-mediatek@lists.infradead.org>,
hao.qin <hao.qin@mediatek.com>
Subject: [PATCH v2 2/2] Bluetooth: btusb: mediatek: add a recovery method for MT7922 and MT7925
Date: Tue, 2 Jan 2024 20:47:47 +0800 [thread overview]
Message-ID: <20240102124747.21644-2-hao.qin@mediatek.com> (raw)
In-Reply-To: <20240102124747.21644-1-hao.qin@mediatek.com>
From: "hao.qin" <hao.qin@mediatek.com>
For MT7922 and MT7925, add USB reset retry to recover from patch
download failure, and perform a reset before patch download to
avoid unexpected problems caused by unkonwn status of dongle.
Signed-off-by: hao.qin <hao.qin@mediatek.com>
---
drivers/bluetooth/btusb.c | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index abefcd1a089d..26ad4864d06c 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -3000,17 +3000,26 @@ static int btusb_mtk_subsys_reset(struct hci_dev *hdev, u32 dev_id)
u32 val;
int err;
- if (dev_id == 0x7925) {
+ if (dev_id == 0x7922) {
+ btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val);
+ val |= 0x00002020;
+ btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, val);
+ btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, 0x00010001);
+ btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val);
+ val |= BIT(0);
+ btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, val);
+ msleep(100);
+ } else if (dev_id == 0x7925) {
btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &val);
- val |= (1 << 5);
+ val |= BIT(5);
btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val);
btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &val);
val &= 0xFFFF00FF;
- val |= (1 << 13);
+ val |= BIT(13);
btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val);
btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, 0x00010001);
btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &val);
- val |= (1 << 0);
+ val |= BIT(0);
btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val);
btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT, 0x000000FF);
btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT, &val);
@@ -3040,6 +3049,9 @@ static int btusb_mtk_subsys_reset(struct hci_dev *hdev, u32 dev_id)
if (err < 0)
bt_dev_err(hdev, "Reset timeout");
+ if (dev_id == 0x7922)
+ btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT, 0x000000FF);
+
btusb_mtk_id_get(data, 0x70010200, &val);
if (!val)
bt_dev_err(hdev, "Can't get device id, subsys reset fail.");
@@ -3128,8 +3140,10 @@ static int btusb_mtk_setup(struct hci_dev *hdev)
fwname = FIRMWARE_MT7668;
break;
case 0x7922:
- case 0x7961:
case 0x7925:
+ btusb_mtk_subsys_reset(hdev, dev_id);
+ fallthrough;
+ case 0x7961:
if (dev_id == 0x7925)
snprintf(fw_bin_name, sizeof(fw_bin_name),
"mediatek/mt%04x/BT_RAM_CODE_MT%04x_1_%x_hdr.bin",
@@ -3143,6 +3157,11 @@ static int btusb_mtk_setup(struct hci_dev *hdev)
btusb_mtk_hci_wmt_sync);
if (err < 0) {
bt_dev_err(hdev, "Failed to set up firmware (%d)", err);
+ if (dev_id == 0x7922 || dev_id == 0x7925) {
+ btusb_stop_traffic(data);
+ usb_kill_anchored_urbs(&data->tx_anchor);
+ usb_queue_reset_device(data->intf);
+ }
return err;
}
--
2.18.0
next prev parent reply other threads:[~2024-01-02 12:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 12:47 [PATCH v2 1/2] Bluetooth: btusb: mediatek: refactor btusb_mtk_reset function Hao Qin
2024-01-02 12:47 ` Hao Qin [this message]
2024-02-03 0:39 ` [PATCH v2 2/2] Bluetooth: btusb: mediatek: add a recovery method for MT7922 and MT7925 Sean Wang
2024-02-03 0:28 ` [PATCH v2 1/2] Bluetooth: btusb: mediatek: refactor btusb_mtk_reset function Sean Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240102124747.21644-2-hao.qin@mediatek.com \
--to=hao.qin@mediatek.com \
--cc=aaron.hou@mediatek.com \
--cc=chris.lu@mediatek.com \
--cc=deren.Wu@mediatek.com \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=sean.wang@mediatek.com \
--cc=steve.lee@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®