diff mbox series

[v2,1/3] Bluetooth: btusb: mediatek: use readx_poll_timeout instead of open coding

Message ID ab8958da839ecadc0ebff9f0a221ef49a2e5a4cc.1664497281.git.objelf@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/3] Bluetooth: btusb: mediatek: use readx_poll_timeout instead of open coding | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint fail [v2,1/3] Bluetooth: btusb: mediatek: use readx_poll_timeout instead of open coding 1: T1 Title exceeds max length (82>80): "[v2,1/3] Bluetooth: btusb: mediatek: use readx_poll_timeout instead of open coding"
tedd_an/subjectprefix success PASS
tedd_an/buildkernel fail Build Kernel make FAIL: drivers/bluetooth/btmtk.c: In function ‘btmtk_coredump_notify’: drivers/bluetooth/btmtk.c:111:7: error: ‘HCI_DEVCOREDUMP_ACTIVE’ undeclared (first use in this function); did you mean ‘BTMTK_COREDUMP_ACTIVE’? 111 | case HCI_DEVCOREDUMP_ACTIVE: | ^~~~~~~~~~~~~~~~~~~~~~ | BTMTK_COREDUMP_ACTIVE drivers/bluetooth/btmtk.c:111:7: note: each undeclared identifier is reported only once for each function it appears in drivers/bluetooth/btmtk.c:114:7: error: ‘HCI_DEVCOREDUMP_TIMEOUT’ undeclared (first use in this function); did you mean ‘HCI_DISCONN_TIMEOUT’? 114 | case HCI_DEVCOREDUMP_TIMEOUT: | ^~~~~~~~~~~~~~~~~~~~~~~ | HCI_DISCONN_TIMEOUT drivers/bluetooth/btmtk.c:115:7: error: ‘HCI_DEVCOREDUMP_ABORT’ undeclared (first use in this function) 115 | case HCI_DEVCOREDUMP_ABORT: | ^~~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c:116:7: error: ‘HCI_DEVCOREDUMP_DONE’ undeclared (first use in this function) 116 | case HCI_DEVCOREDUMP_DONE: | ^~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c: In function ‘btmtk_register_coredump’: drivers/bluetooth/btmtk.c:376:2: error: implicit declaration of function ‘hci_devcoredump_register’ [-Werror=implicit-function-declaration] 376 | hci_devcoredump_register(hdev, btmtk_coredump, btmtk_coredump_hdr, | ^~~~~~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’: drivers/bluetooth/btmtk.c:393:9: error: implicit declaration of function ‘hci_devcoredump_init’ [-Werror=implicit-function-declaration] 393 | err = hci_devcoredump_init(hdev, 1024000); | ^~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c:397:30: error: ‘struct hci_dev’ has no member named ‘dump’ 397 | schedule_delayed_work(&hdev->dump.dump_timeout, | ^~ drivers/bluetooth/btmtk.c:402:9: error: implicit declaration of function ‘hci_devcoredump_append’ [-Werror=implicit-function-declaration] 402 | err = hci_devcoredump_append(hdev, skb); | ^~~~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c:409:4: error: implicit declaration of function ‘hci_devcoredump_complete’ [-Werror=implicit-function-declaration] 409 | hci_devcoredump_complete(hdev); | ^~~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors make[2]: *** [scripts/Makefile.build:249: drivers/bluetooth/btmtk.o] Error 1 make[1]: *** [scripts/Makefile.build:465: drivers/bluetooth] Error 2 make: *** [Makefile:1855: drivers] Error 2
tedd_an/buildkernel32 fail Build Kernel32 make FAIL: drivers/bluetooth/btmtk.c: In function ‘btmtk_coredump_notify’: drivers/bluetooth/btmtk.c:111:7: error: ‘HCI_DEVCOREDUMP_ACTIVE’ undeclared (first use in this function); did you mean ‘BTMTK_COREDUMP_ACTIVE’? 111 | case HCI_DEVCOREDUMP_ACTIVE: | ^~~~~~~~~~~~~~~~~~~~~~ | BTMTK_COREDUMP_ACTIVE drivers/bluetooth/btmtk.c:111:7: note: each undeclared identifier is reported only once for each function it appears in drivers/bluetooth/btmtk.c:114:7: error: ‘HCI_DEVCOREDUMP_TIMEOUT’ undeclared (first use in this function); did you mean ‘HCI_DISCONN_TIMEOUT’? 114 | case HCI_DEVCOREDUMP_TIMEOUT: | ^~~~~~~~~~~~~~~~~~~~~~~ | HCI_DISCONN_TIMEOUT drivers/bluetooth/btmtk.c:115:7: error: ‘HCI_DEVCOREDUMP_ABORT’ undeclared (first use in this function) 115 | case HCI_DEVCOREDUMP_ABORT: | ^~~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c:116:7: error: ‘HCI_DEVCOREDUMP_DONE’ undeclared (first use in this function) 116 | case HCI_DEVCOREDUMP_DONE: | ^~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c: In function ‘btmtk_register_coredump’: drivers/bluetooth/btmtk.c:376:2: error: implicit declaration of function ‘hci_devcoredump_register’ [-Werror=implicit-function-declaration] 376 | hci_devcoredump_register(hdev, btmtk_coredump, btmtk_coredump_hdr, | ^~~~~~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’: drivers/bluetooth/btmtk.c:393:9: error: implicit declaration of function ‘hci_devcoredump_init’ [-Werror=implicit-function-declaration] 393 | err = hci_devcoredump_init(hdev, 1024000); | ^~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c:397:30: error: ‘struct hci_dev’ has no member named ‘dump’ 397 | schedule_delayed_work(&hdev->dump.dump_timeout, | ^~ drivers/bluetooth/btmtk.c:402:9: error: implicit declaration of function ‘hci_devcoredump_append’ [-Werror=implicit-function-declaration] 402 | err = hci_devcoredump_append(hdev, skb); | ^~~~~~~~~~~~~~~~~~~~~~ drivers/bluetooth/btmtk.c:409:4: error: implicit declaration of function ‘hci_devcoredump_complete’ [-Werror=implicit-function-declaration] 409 | hci_devcoredump_complete(hdev); | ^~~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors make[2]: *** [scripts/Makefile.build:249: drivers/bluetooth/btmtk.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [scripts/Makefile.build:465: drivers/bluetooth] Error 2 make: *** [Makefile:1855: drivers] Error 2
tedd_an/incremental_build pending Incremental Build Kernel SKIP(Build Fail)
tedd_an/testrunnersetup success Test Runner Setup PASS
tedd_an/testrunnerl2cap-tester success Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunneriso-tester success Total: 55, Passed: 55 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerbnep-tester success Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnermgmt-tester success Total: 494, Passed: 494 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerrfcomm-tester success Total: 11, Passed: 11 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnersco-tester success Total: 12, Passed: 12 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerioctl-tester success Total: 28, Passed: 28 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnersmp-tester success Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunneruserchan-tester success Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0

Commit Message

Sean Wang Sept. 30, 2022, 12:23 a.m. UTC
From: Sean Wang <sean.wang@mediatek.com>

Use readx_poll_timeout instead of open coding to poll the hardware reset
status until it is done.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
The patch is built and tested on the top of the patches
[v6,1/3] Bluetooth: Add support for hci devcoredump
[v6,2/3] Bluetooth: btusb: Add btusb devcoredump support
[v6,3/3] Bluetooth: btintel: Add Intel devcoredump support
which are contributed from Manish Mandlik

v2: use 20ms as the unit to poll according to the requirement of
    readx_poll_timeout
---
 drivers/bluetooth/btusb.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

Comments

bluez.test.bot@gmail.com Sept. 30, 2022, 4:01 a.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=682088

---Test result---

Test Summary:
CheckPatch                    PASS      4.64 seconds
GitLint                       FAIL      0.73 seconds
SubjectPrefix                 PASS      1.91 seconds
BuildKernel                   FAIL      34.02 seconds
BuildKernel32                 FAIL      30.92 seconds
Incremental Build with patchesERROR     0.29 seconds
TestRunner: Setup             PASS      514.02 seconds
TestRunner: l2cap-tester      PASS      17.20 seconds
TestRunner: iso-tester        PASS      16.20 seconds
TestRunner: bnep-tester       PASS      6.49 seconds
TestRunner: mgmt-tester       PASS      104.57 seconds
TestRunner: rfcomm-tester     PASS      10.22 seconds
TestRunner: sco-tester        PASS      9.74 seconds
TestRunner: ioctl-tester      PASS      11.04 seconds
TestRunner: smp-tester        PASS      9.73 seconds
TestRunner: userchan-tester   PASS      6.80 seconds

Details
##############################
Test: GitLint - FAIL - 0.73 seconds
Run gitlint with rule in .gitlint
[v2,1/3] Bluetooth: btusb: mediatek: use readx_poll_timeout instead of open coding
1: T1 Title exceeds max length (82>80): "[v2,1/3] Bluetooth: btusb: mediatek: use readx_poll_timeout instead of open coding"


##############################
Test: BuildKernel - FAIL - 34.02 seconds
Build Kernel with minimal configuration supports Bluetooth
drivers/bluetooth/btmtk.c: In function ‘btmtk_coredump_notify’:
drivers/bluetooth/btmtk.c:111:7: error: ‘HCI_DEVCOREDUMP_ACTIVE’ undeclared (first use in this function); did you mean ‘BTMTK_COREDUMP_ACTIVE’?
  111 |  case HCI_DEVCOREDUMP_ACTIVE:
      |       ^~~~~~~~~~~~~~~~~~~~~~
      |       BTMTK_COREDUMP_ACTIVE
drivers/bluetooth/btmtk.c:111:7: note: each undeclared identifier is reported only once for each function it appears in
drivers/bluetooth/btmtk.c:114:7: error: ‘HCI_DEVCOREDUMP_TIMEOUT’ undeclared (first use in this function); did you mean ‘HCI_DISCONN_TIMEOUT’?
  114 |  case HCI_DEVCOREDUMP_TIMEOUT:
      |       ^~~~~~~~~~~~~~~~~~~~~~~
      |       HCI_DISCONN_TIMEOUT
drivers/bluetooth/btmtk.c:115:7: error: ‘HCI_DEVCOREDUMP_ABORT’ undeclared (first use in this function)
  115 |  case HCI_DEVCOREDUMP_ABORT:
      |       ^~~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c:116:7: error: ‘HCI_DEVCOREDUMP_DONE’ undeclared (first use in this function)
  116 |  case HCI_DEVCOREDUMP_DONE:
      |       ^~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c: In function ‘btmtk_register_coredump’:
drivers/bluetooth/btmtk.c:376:2: error: implicit declaration of function ‘hci_devcoredump_register’ [-Werror=implicit-function-declaration]
  376 |  hci_devcoredump_register(hdev, btmtk_coredump, btmtk_coredump_hdr,
      |  ^~~~~~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’:
drivers/bluetooth/btmtk.c:393:9: error: implicit declaration of function ‘hci_devcoredump_init’ [-Werror=implicit-function-declaration]
  393 |   err = hci_devcoredump_init(hdev, 1024000);
      |         ^~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c:397:30: error: ‘struct hci_dev’ has no member named ‘dump’
  397 |   schedule_delayed_work(&hdev->dump.dump_timeout,
      |                              ^~
drivers/bluetooth/btmtk.c:402:9: error: implicit declaration of function ‘hci_devcoredump_append’ [-Werror=implicit-function-declaration]
  402 |   err = hci_devcoredump_append(hdev, skb);
      |         ^~~~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c:409:4: error: implicit declaration of function ‘hci_devcoredump_complete’ [-Werror=implicit-function-declaration]
  409 |    hci_devcoredump_complete(hdev);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:249: drivers/bluetooth/btmtk.o] Error 1
make[1]: *** [scripts/Makefile.build:465: drivers/bluetooth] Error 2
make: *** [Makefile:1855: drivers] Error 2


##############################
Test: BuildKernel32 - FAIL - 30.92 seconds
Build 32bit Kernel with minimal configuration supports Bluetooth
drivers/bluetooth/btmtk.c: In function ‘btmtk_coredump_notify’:
drivers/bluetooth/btmtk.c:111:7: error: ‘HCI_DEVCOREDUMP_ACTIVE’ undeclared (first use in this function); did you mean ‘BTMTK_COREDUMP_ACTIVE’?
  111 |  case HCI_DEVCOREDUMP_ACTIVE:
      |       ^~~~~~~~~~~~~~~~~~~~~~
      |       BTMTK_COREDUMP_ACTIVE
drivers/bluetooth/btmtk.c:111:7: note: each undeclared identifier is reported only once for each function it appears in
drivers/bluetooth/btmtk.c:114:7: error: ‘HCI_DEVCOREDUMP_TIMEOUT’ undeclared (first use in this function); did you mean ‘HCI_DISCONN_TIMEOUT’?
  114 |  case HCI_DEVCOREDUMP_TIMEOUT:
      |       ^~~~~~~~~~~~~~~~~~~~~~~
      |       HCI_DISCONN_TIMEOUT
drivers/bluetooth/btmtk.c:115:7: error: ‘HCI_DEVCOREDUMP_ABORT’ undeclared (first use in this function)
  115 |  case HCI_DEVCOREDUMP_ABORT:
      |       ^~~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c:116:7: error: ‘HCI_DEVCOREDUMP_DONE’ undeclared (first use in this function)
  116 |  case HCI_DEVCOREDUMP_DONE:
      |       ^~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c: In function ‘btmtk_register_coredump’:
drivers/bluetooth/btmtk.c:376:2: error: implicit declaration of function ‘hci_devcoredump_register’ [-Werror=implicit-function-declaration]
  376 |  hci_devcoredump_register(hdev, btmtk_coredump, btmtk_coredump_hdr,
      |  ^~~~~~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c: In function ‘btmtk_process_coredump’:
drivers/bluetooth/btmtk.c:393:9: error: implicit declaration of function ‘hci_devcoredump_init’ [-Werror=implicit-function-declaration]
  393 |   err = hci_devcoredump_init(hdev, 1024000);
      |         ^~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c:397:30: error: ‘struct hci_dev’ has no member named ‘dump’
  397 |   schedule_delayed_work(&hdev->dump.dump_timeout,
      |                              ^~
drivers/bluetooth/btmtk.c:402:9: error: implicit declaration of function ‘hci_devcoredump_append’ [-Werror=implicit-function-declaration]
  402 |   err = hci_devcoredump_append(hdev, skb);
      |         ^~~~~~~~~~~~~~~~~~~~~~
drivers/bluetooth/btmtk.c:409:4: error: implicit declaration of function ‘hci_devcoredump_complete’ [-Werror=implicit-function-declaration]
  409 |    hci_devcoredump_complete(hdev);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:249: drivers/bluetooth/btmtk.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [scripts/Makefile.build:465: drivers/bluetooth] Error 2
make: *** [Makefile:1855: drivers] Error 2


##############################
Test: Incremental Build with patches - SKIPPED - 0.29 seconds
Incremental build per patch in the series
buildkernel failed



---
Regards,
Linux Bluetooth
AngeloGioacchino Del Regno Sept. 30, 2022, 8:48 a.m. UTC | #2
Il 30/09/22 02:23, sean.wang@mediatek.com ha scritto:
> From: Sean Wang <sean.wang@mediatek.com>
> 
> Use readx_poll_timeout instead of open coding to poll the hardware reset
> status until it is done.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
> The patch is built and tested on the top of the patches
> [v6,1/3] Bluetooth: Add support for hci devcoredump
> [v6,2/3] Bluetooth: btusb: Add btusb devcoredump support
> [v6,3/3] Bluetooth: btintel: Add Intel devcoredump support
> which are contributed from Manish Mandlik
> 
> v2: use 20ms as the unit to poll according to the requirement of
>      readx_poll_timeout
> ---
>   drivers/bluetooth/btusb.c | 32 ++++++++++++++++++--------------
>   1 file changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index 4eb79e88f1d9..9ef0dc648573 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -2361,8 +2361,6 @@ static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb)
>   #define MTK_EP_RST_OPT		0x74011890
>   #define MTK_EP_RST_IN_OUT_OPT	0x00010001
>   #define MTK_BT_RST_DONE		0x00000100
> -#define MTK_BT_RESET_WAIT_MS	100
> -#define MTK_BT_RESET_NUM_TRIES	10
>   
>   static void btusb_mtk_wmt_recv(struct urb *urb)
>   {
> @@ -2733,6 +2731,16 @@ static int btusb_mtk_id_get(struct btusb_data *data, u32 reg, u32 *id)
>   	return btusb_mtk_reg_read(data, reg, id);
>   }
>   
> +static u32 btusb_mtk_reset_done(struct hci_dev *hdev)

I'm sorry for not noticing that in v1, but...

...If you call this function "btusb_mtk_reset_done"...

> +{
> +	struct btusb_data *data = hci_get_drvdata(hdev);
> +	u32 val = 0;
> +
> +	btusb_mtk_uhw_reg_read(data, MTK_BT_MISC, &val);
> +
> +	return val;

...you shouldn't return the value of the entire MTK_BT_MISC register,
otherwise you should call this "btusb_mtk_read_bt_misc_reg".

I think that here, you should do

	return val & MTK_BT_RST_DONE;

and then, for the readx_poll_timeout, you simply check if this function
returned 1, like:

	err = readx_poll_timeout(btusb_mtk_reset_done, hdev, val, val,
				 20000, 1000000);

> +}
> +
>   static int btusb_mtk_setup(struct hci_dev *hdev)
>   {
>   	struct btusb_data *data = hci_get_drvdata(hdev);
> @@ -2922,7 +2930,7 @@ static void btusb_mtk_cmd_timeout(struct hci_dev *hdev)
>   {
>   	struct btusb_data *data = hci_get_drvdata(hdev);
>   	u32 val;
> -	int err, retry = 0;
> +	int err;
>   
>   	/* It's MediaTek specific bluetooth reset mechanism via USB */
>   	if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
> @@ -2953,18 +2961,14 @@ static void btusb_mtk_cmd_timeout(struct hci_dev *hdev)
>   	btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 0);
>   	btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val);
>   
> -	/* Poll the register until reset is completed */
> -	do {
> -		btusb_mtk_uhw_reg_read(data, MTK_BT_MISC, &val);
> -		if (val & MTK_BT_RST_DONE) {
> -			bt_dev_dbg(hdev, "Bluetooth Reset Successfully");
> -			break;
> -		}
> +	err = readx_poll_timeout(btusb_mtk_reset_done, hdev, val,
> +				 val & MTK_BT_RST_DONE,
> +				 20000, 1000000);
> +	if (err < 0)
> +		bt_dev_err(hdev, "Reset timeout");
>   
> -		bt_dev_dbg(hdev, "Polling Bluetooth Reset CR");
> -		retry++;
> -		msleep(MTK_BT_RESET_WAIT_MS);
> -	} while (retry < MTK_BT_RESET_NUM_TRIES);
> +	if (val & MTK_BT_RST_DONE)

You're already checking `if (err < 0)`, so this check is redundant.
If the polling didn't return a timeout, the register value contains
MTK_BT_RST_DONE for sure, so you can safely remove this check.

> +		bt_dev_dbg(hdev, "Bluetooth Reset Successfully");
>   

Regards,
Angelo
diff mbox series

Patch

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 4eb79e88f1d9..9ef0dc648573 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2361,8 +2361,6 @@  static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb)
 #define MTK_EP_RST_OPT		0x74011890
 #define MTK_EP_RST_IN_OUT_OPT	0x00010001
 #define MTK_BT_RST_DONE		0x00000100
-#define MTK_BT_RESET_WAIT_MS	100
-#define MTK_BT_RESET_NUM_TRIES	10
 
 static void btusb_mtk_wmt_recv(struct urb *urb)
 {
@@ -2733,6 +2731,16 @@  static int btusb_mtk_id_get(struct btusb_data *data, u32 reg, u32 *id)
 	return btusb_mtk_reg_read(data, reg, id);
 }
 
+static u32 btusb_mtk_reset_done(struct hci_dev *hdev)
+{
+	struct btusb_data *data = hci_get_drvdata(hdev);
+	u32 val = 0;
+
+	btusb_mtk_uhw_reg_read(data, MTK_BT_MISC, &val);
+
+	return val;
+}
+
 static int btusb_mtk_setup(struct hci_dev *hdev)
 {
 	struct btusb_data *data = hci_get_drvdata(hdev);
@@ -2922,7 +2930,7 @@  static void btusb_mtk_cmd_timeout(struct hci_dev *hdev)
 {
 	struct btusb_data *data = hci_get_drvdata(hdev);
 	u32 val;
-	int err, retry = 0;
+	int err;
 
 	/* It's MediaTek specific bluetooth reset mechanism via USB */
 	if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) {
@@ -2953,18 +2961,14 @@  static void btusb_mtk_cmd_timeout(struct hci_dev *hdev)
 	btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 0);
 	btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val);
 
-	/* Poll the register until reset is completed */
-	do {
-		btusb_mtk_uhw_reg_read(data, MTK_BT_MISC, &val);
-		if (val & MTK_BT_RST_DONE) {
-			bt_dev_dbg(hdev, "Bluetooth Reset Successfully");
-			break;
-		}
+	err = readx_poll_timeout(btusb_mtk_reset_done, hdev, val,
+				 val & MTK_BT_RST_DONE,
+				 20000, 1000000);
+	if (err < 0)
+		bt_dev_err(hdev, "Reset timeout");
 
-		bt_dev_dbg(hdev, "Polling Bluetooth Reset CR");
-		retry++;
-		msleep(MTK_BT_RESET_WAIT_MS);
-	} while (retry < MTK_BT_RESET_NUM_TRIES);
+	if (val & MTK_BT_RST_DONE)
+		bt_dev_dbg(hdev, "Bluetooth Reset Successfully");
 
 	btusb_mtk_id_get(data, 0x70010200, &val);
 	if (!val)