Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp5832413rwn; Mon, 12 Sep 2022 15:20:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR4gnvdKFkkOpGzNR05MDsskfYKI4wOYeNk3I8oOnAkhMoTFyChKM9mFr/3YsQZvQBbym/6j X-Received: by 2002:a05:6402:1909:b0:451:ace7:ccbd with SMTP id e9-20020a056402190900b00451ace7ccbdmr6571494edz.276.1663021228347; Mon, 12 Sep 2022 15:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663021228; cv=none; d=google.com; s=arc-20160816; b=DPQLrIn8e/CsA1u1rhsKeTEUeLjvffFnoM4jk2jMtB5wreaG6ceAAMAbjqO0cbRSCr qb0TK/nKT5nY2+PRIeuDZAoo2AkYk8iLuzaavXWXKqBVfOUDmMpGl6rf9xoXtmc52/Lq RlXRdjuiRzH0RdO0kx8Rp6PxjSDAIja9KXis5NRWC5BQ0LykhiVTLl2bRES69aHt6331 LJC+3LtUOojROsm8JMmzXCD2fDvKYuUixmuCQPVgt2ohIZJlf5yQ9C6lcnuCyenbZAJY VspdI9b8s08eLixM3nJAL+fRJx7r/ViBACKWfxkVfZNcZPXurth+xzZStq3JyXUll5kV pfqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=SitFztFHL7cuvst79spCHgqtrFJ8x6qYvVGwj95cDPM=; b=T3EYjxlKQpnXllkesX7aPX6XjLD3pGhbCaGWzhkoYbX6sBrCw4yX7cgemMaP+Rt8Wi 7A/xRICywpDZYS1KfZoURITzTqJy8Ga5S3IomtJaNed864P6UAEZipCar/Uo4pWUlXVx az1FpgJbiNO7sgLigYOmDY7hGrXszwfESZrs0kzZsGt0FdgZN4D1VLgFD/56vSCxUubL +ZgRKfqM10VdXp2/w6iC09gdz8g/cCWurEB0xRc9Qkl1NORFOaTLHhJZwFSDrFSx54sE jad/4yzcuITdGlHM4FFi2YlNaZraphPOtrm7OkivGGn6fDnsyjalMDW44g/6+Mk2cqM6 2Dfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=NPJTUQUs; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a17090699c300b0077d1df3967asi3424165ejn.563.2022.09.12.15.20.02; Mon, 12 Sep 2022 15:20:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=NPJTUQUs; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229511AbiILWTo (ORCPT + 99 others); Mon, 12 Sep 2022 18:19:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbiILWTV (ORCPT ); Mon, 12 Sep 2022 18:19:21 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 151B44F1AD; Mon, 12 Sep 2022 15:18:21 -0700 (PDT) X-UUID: 4456d76a20f54368816bbb3721225753-20220913 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=SitFztFHL7cuvst79spCHgqtrFJ8x6qYvVGwj95cDPM=; b=NPJTUQUs7TDPFHZW/+RL6t7QXyUhnY2o3z4Jc//uh7PI/8mBOPoMlFRcfHnmfv6D5K+tdyGwE6z4HjfQdOhyqczJTlMYRulTQq5wh/Wy9JSHfSA6pmL0KFTuiomse4ZgSwxOUyW+zUphQjVcrUp32VK3G0rtwadzCkQtIE0s+Yw=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.10,REQID:125078df-1c8c-496a-a3b4-22d7fafc706e,OB:10, LOB:0,IP:0,URL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Releas e_Ham,ACTION:release,TS:95 X-CID-INFO: VERSION:1.1.10,REQID:125078df-1c8c-496a-a3b4-22d7fafc706e,OB:10,LO B:0,IP:0,URL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS9 81B3D,ACTION:quarantine,TS:95 X-CID-META: VersionHash:84eae18,CLOUDID:612d635d-5ed4-4e28-8b00-66ed9f042fbd,C OID:4945ced5a53e,Recheck:0,SF:28|17|19|48,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:40,QS:nil,BEC:nil,COL:0 X-UUID: 4456d76a20f54368816bbb3721225753-20220913 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 221344183; Tue, 13 Sep 2022 06:18:17 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Tue, 13 Sep 2022 06:18:15 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Tue, 13 Sep 2022 06:18:15 +0800 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH 1/4] Bluetooth: btusb: mediatek: use readx_poll_timeout instead of open coding Date: Tue, 13 Sep 2022 06:18:10 +0800 Message-ID: <43b68b1f48c20b1dfcd7e6663c3dcb38e4e0648c.1663020936.git.objelf@gmail.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Sean Wang Use readx_poll_timeout instead of open coding to poll the hardware reset status until it is done. Signed-off-by: Sean Wang --- 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 c3daba17de7f..4dc9cae3e937 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2318,8 +2318,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) { @@ -2690,6 +2688,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); @@ -2879,7 +2887,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)) { @@ -2910,18 +2918,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, + 100000, 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) -- 2.25.1