From patchwork Wed May 15 23:15:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13665594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB4FBC25B75 for ; Wed, 15 May 2024 23:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=s8lTrIOPp2rps4ETyvV9vi8AsmvDY3xHbsdrzyXbxxM=; b=RTA1zrdeyZDj8NBw14NmpRj7yU Bce3WDVE+fYsW6l+5kAGRoiFWAAKobB6hR/1PLVDGKwqVahSD7ZQviFFZ7MfvRIPsnyr4HdfR3+JC 8Cw79ebxR7JPy84eocViE1IrkPMyCGA47wT94AZcpI5ZAUUyITJknYkAoG0m61jkdvMpc7cKg6Y+D 64ZNM3pCs1QTraSvQIaOSYWTJyAj08vNp0L46y/KYuEzYMn9SRIiLaayqUDgoigW+XyVvviw3DEG7 vGLoCLMSvxV+aKMWqEvMbQyPCRsBboN6Xn9fuTHt/k24SCGr5mLW5HoEGm5DYl2F3hyKm9XSlfxTH HWUJTb/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7NqY-00000003861-13le; Wed, 15 May 2024 23:15:42 +0000 Received: from mail-oo1-f49.google.com ([209.85.161.49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7NqR-00000003828-2Gyf for linux-mediatek@lists.infradead.org; Wed, 15 May 2024 23:15:40 +0000 Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5b2f2a584c6so212198eaf.0 for ; Wed, 15 May 2024 16:15:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715814933; x=1716419733; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=s8lTrIOPp2rps4ETyvV9vi8AsmvDY3xHbsdrzyXbxxM=; b=irLUSq1mYsQ9lvZlGz8Ard/uOlNW4x2lSezLBs+Ab6tjWTzgpG7+zdfPGcLV+P4X9t 7OIwIjpcZnP+RQyCL6u7SzMoHevVW83O9jkG1oKoX6767d7BgRdsbNOX8c+TXhCk4bPj pNUCexAbTGQqwz+dit4UAC4NyZnJQ8D5l+x/4wM4XHpGGcMHVMz5+M48cLwKI1PLsJJA c3fCWtCBhxpKexxkePoS+xJHenTxk+388FJvj1lMT29hUFqQqbozbEYhVqbwI9d8b+fY OTiBMQiOpi1ZuA+mE1cSsHN2UTEbiP0HL5evJcnCbMQ643obRBEAr3bIKLveL8wqBNGe 2YnQ== X-Forwarded-Encrypted: i=1; AJvYcCVjj7fKsOlV+IKGln3ZeBBv2tYBecrDrP9kQxGmGN0YzyNnPRc5mZEB3EZFUgvhqXXvAJ/eVc+Lv7WH81RUS3zeEC47doYxywsg5xmGSoKNoBNm X-Gm-Message-State: AOJu0YxBzLZpAc75gGwV8l867xUVIfRuN06VayGl0KuYTfHwqlsHC4LH Oc9gAj27GlA/MPwhTwfqD4oDB92sg5RO/jSErpnHKgK0jR8u/c90 X-Google-Smtp-Source: AGHT+IHJZzy1efEISuW3awypyoQF6Uoeq89kZn447ERsBVT1h1CIAYblZT6dnBXhB5s6AqsgZ4ehKw== X-Received: by 2002:a05:6830:2051:b0:6f1:2171:4f9a with SMTP id 46e09a7af769-6f12171526cmr4177443a34.0.1715814932887; Wed, 15 May 2024 16:15:32 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0ec2e566dsm2032159a34.15.2024.05.15.16.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:15:32 -0700 (PDT) From: sean.wang@kernel.org To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Sean Wang Subject: [PATCH v5 1/5] Bluetooth: btmtk: add the function to get the fw name Date: Wed, 15 May 2024 16:15:17 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_161535_661977_81AAEBC8 X-CRM114-Status: GOOD ( 12.87 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Sean Wang Include a shared function to get the firmware name, to prevent repeating code for similar chipsets. Signed-off-by: Sean Wang --- v3: first added to the series v4: rebase onto the latest code and add an additional parameter fw_flavor into the function btmtk_fw_get_filename. v5: fix an issue about the directive output truncated writing caught by the linux test robot --- drivers/bluetooth/btmtk.c | 18 ++++++++++++++++++ drivers/bluetooth/btmtk.h | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 812fd2a8f853..a27c251bf56e 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -103,6 +103,24 @@ static void btmtk_coredump_notify(struct hci_dev *hdev, int state) } } +void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver, + u32 fw_flavor) +{ + if (dev_id == 0x7925) + snprintf(buf, size, + "mediatek/mt%04x/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", + dev_id & 0xffff, dev_id & 0xffff, (fw_ver & 0xff) + 1); + else if (dev_id == 0x7961 && fw_flavor) + snprintf(buf, size, + "mediatek/BT_RAM_CODE_MT%04x_1a_%x_hdr.bin", + dev_id & 0xffff, (fw_ver & 0xff) + 1); + else + snprintf(buf, size, + "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", + dev_id & 0xffff, (fw_ver & 0xff) + 1); +} +EXPORT_SYMBOL_GPL(btmtk_fw_get_filename); + int btmtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname, wmt_cmd_sync_func_t wmt_cmd_sync) { diff --git a/drivers/bluetooth/btmtk.h b/drivers/bluetooth/btmtk.h index cbcdb99a22e6..e76b8a358be8 100644 --- a/drivers/bluetooth/btmtk.h +++ b/drivers/bluetooth/btmtk.h @@ -160,6 +160,9 @@ int btmtk_register_coredump(struct hci_dev *hdev, const char *name, u32 fw_version); int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb); + +void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver, + u32 fw_flavor); #else static inline int btmtk_set_bdaddr(struct hci_dev *hdev, @@ -194,4 +197,9 @@ static int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb) { return -EOPNOTSUPP; } + +static void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, + u32 fw_ver, u32 fw_flavor) +{ +} #endif From patchwork Wed May 15 23:15:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13665595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8071C25B7A for ; Wed, 15 May 2024 23:15:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dhvsCgYPvB92Q5BFBKTie57uhIEMm1z1mEV6N05fCRE=; b=Hp3gkY3Ye+PBIABJmu/9B/oiSR MoTA8aLcU6s/KdYIIvq43Ew5wZis3xl8lWE3v5PFAEaayMxPs/Y9n0bqkySkH9r2DxGNp6PXT3IOW 4OIHVVt7rG3CDyOWVOtIJLHYlrdkL+GdUImMAdB7UXolxahQSwEeiFJxt1XGQ27b6HUi4RX2N8srY R1tGa5adNS3dpaHOAyIoi8tK2xyWrNftT2Yzv1HgXcJ3jFEqmgR5FzkEw54aQsywNjomNZix82Lxx ZIjqENz4RdNCL1OkS+GXk3A59vCZwvNg3eLbugMixfyB3Fj+NOBiuj7WPJ3gYiZGgVwvfXPlmyFkN gmCbnDxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7Nqa-0000000386p-0EVM; Wed, 15 May 2024 23:15:44 +0000 Received: from mail-ot1-f52.google.com ([209.85.210.52]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7NqS-0000000383D-3tmh for linux-mediatek@lists.infradead.org; Wed, 15 May 2024 23:15:40 +0000 Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-6f0e35b60f1so539652a34.2 for ; Wed, 15 May 2024 16:15:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715814935; x=1716419735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dhvsCgYPvB92Q5BFBKTie57uhIEMm1z1mEV6N05fCRE=; b=WFEfWW9UUiUOpyE24qfub5yOcrdOYXsnE1bGrxxEfrFmCpCQD/GyxnbAjx7pzbu6ON Kd0etX/Olepdb3G0ND5JyUE5QI0XnjNBODQbERQALazIL9qLuYVDWDzwIGv4wGPoXdZP t2pEjvrRfwz9/PIXrNRxGpV5wLOg/MjZyWrAnVcqmvkYWVcVbOcYpxNu/1m4IzXO6Xgc EJXdCkHx054/iY2uwyNUhL7ifvmJ3vyQJqyxLj7VjNleZN74GvZ2mzM8h2WXhirE6v5f rgQc5U1Jn2RZ0OyWYpYesCdBFvOnU7uZg8uI7BfKHGha7RwuI7JYt5HJDNRQAroNmSuX s9kw== X-Forwarded-Encrypted: i=1; AJvYcCWsvpRylTr5M33R0cYePkydH8jAQwlYkphhPKzgOoDxG5JewSdGrXy+m4ELRnK+WFzKuixERiQwoeAZWBeuskcSHSt7vi0CS/z6ovFvRsvVclqX X-Gm-Message-State: AOJu0Ywi+DE1FzD38RkCcbupJ3UN84EbSH29ct9LdTOH2zSmw3oG9jsl 5WzVIWUtkBxXivdJCH+ixTbBUROvSr/AEGEjqVFY4r09ID7cqGOc X-Google-Smtp-Source: AGHT+IEE6LNZ3dq4LwLZKPsCEi4p+ERRiPUUnv07W4qArNWrUWhhCwZjNS6tXxt72v25gQ1W/iMpaA== X-Received: by 2002:a9d:6d95:0:b0:6f0:85dd:131e with SMTP id 46e09a7af769-6f0e92a69bfmr21075455a34.2.1715814934801; Wed, 15 May 2024 16:15:34 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0ec2e566dsm2032159a34.15.2024.05.15.16.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:15:34 -0700 (PDT) From: sean.wang@kernel.org To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Sean Wang Subject: [PATCH v5 2/5] Bluetooth: btmtk: apply the common btmtk_fw_get_filename Date: Wed, 15 May 2024 16:15:18 -0700 Message-Id: <1e9c955a0b311ede0bafedd4c49436cb5a04c9b1.1715813148.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_161537_148660_B9030381 X-CRM114-Status: GOOD ( 11.28 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Sean Wang Apply the common btmtk_fw_get_filename to avoid the similar coding in each driver. Signed-off-by: Sean Wang --- v3: first added to the series v4: rebase onto the latest code v5: update the caller usage with btmtk_fw_get_filename --- drivers/bluetooth/btmtksdio.c | 3 +++ drivers/bluetooth/btusb.c | 14 ++------------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index ff4868c83cd8..04be06f73e05 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -1117,6 +1117,9 @@ static int btmtksdio_setup(struct hci_dev *hdev) return err; } + btmtk_fw_get_filename(fwname, sizeof(fwname), dev_id, + fw_version, 0); + snprintf(fwname, sizeof(fwname), "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", dev_id & 0xffff, (fw_version & 0xff) + 1); diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index e384ef6ff050..611135d1ce01 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3166,18 +3166,8 @@ static int btusb_mtk_setup(struct hci_dev *hdev) case 0x7922: case 0x7961: case 0x7925: - if (dev_id == 0x7925) - snprintf(fw_bin_name, sizeof(fw_bin_name), - "mediatek/mt%04x/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", - dev_id & 0xffff, dev_id & 0xffff, (fw_version & 0xff) + 1); - else if (dev_id == 0x7961 && fw_flavor) - snprintf(fw_bin_name, sizeof(fw_bin_name), - "mediatek/BT_RAM_CODE_MT%04x_1a_%x_hdr.bin", - dev_id & 0xffff, (fw_version & 0xff) + 1); - else - snprintf(fw_bin_name, sizeof(fw_bin_name), - "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", - dev_id & 0xffff, (fw_version & 0xff) + 1); + btmtk_fw_get_filename(fw_bin_name, sizeof(fw_bin_name), dev_id, + fw_version, fw_flavor); err = btmtk_setup_firmware_79xx(hdev, fw_bin_name, btusb_mtk_hci_wmt_sync); From patchwork Wed May 15 23:15:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13665597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1C4EC25B78 for ; Wed, 15 May 2024 23:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FFGLv+/W/92QSc/vAIXNlWmURdmlafsCOBe70BkQWmk=; b=A+UUTyv6HV9OxOQppyDIMaokLa Bb3kPkM+rnzJFU9MwAW0V47m0TnaVHERMm5TZRONYPRr9e5D6r+YL1Cj9YXplvqU8AOLx/e6PINbK vPuSrYRwoLR4AvFaLX/F+sdmGJbsvPWpHiDyo1oHUDjiA6mpz37zT5wnXOU3maBtW/MZL8touKrZQ v7T8qiqTnQ3Q7mLgsAe2tzbm4DlD78iIZkW7hdm1cH7qY7XzE/veaLQBbL/cIZB/Nb7eITrJc1yTO jNDXadqNuj59WI36THhTNapX216BDOdzfbmWv5P14c52KDSgTb/LmREFOfHXhkUYPuiGfvQsQ/025 nqlz2dnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7Nqa-0000000386z-2oCN; Wed, 15 May 2024 23:15:47 +0000 Received: from mail-oi1-f177.google.com ([209.85.167.177]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7NqU-0000000383z-3BCv for linux-mediatek@lists.infradead.org; Wed, 15 May 2024 23:15:41 +0000 Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3c9b5776fbfso359027b6e.1 for ; Wed, 15 May 2024 16:15:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715814937; x=1716419737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FFGLv+/W/92QSc/vAIXNlWmURdmlafsCOBe70BkQWmk=; b=dD67ndMMankmi/Ex6ChvkP3MCZGI5qgL01MGM0EARgdYtji5jU0C0fau+/+g3H0aUF bLs/7y1j08e6b0souUwc5hp8oMgAQOPAEi+sxJ9abUbPMKqgZwePaNENkSUBStR2b3ks rNuuuJ7D1ei5nTcq9nSjjzRnApd2voAwb3Z2BYyWYFyXIKtP0QCY3a8PjGE7GI/67gxr EEE/w8TceKJWykw7PlyHkMS3b6eyVsURTylZncqvFypkYvA5uzVbFwWkqe11gfQECgg0 iIFfaas0FKfuCAfsXqeRnt3KI/cQombj1bArVsUWAqhuEwQuP1PVHpQzkYGDvNxUyOW1 wdww== X-Forwarded-Encrypted: i=1; AJvYcCXfcJSdhSI8qImhkIuPhPy/1D1TsDNtSHuXrLj2GuKU4+1u/5Tnqjqhk9VcuXwHYqIUmKOKMSkKoV1Y9aqRxyJQ0h/VowxWnBnmLDjvNTbipCmn X-Gm-Message-State: AOJu0YwHLc4QFzrt9T4fDcC0v2UCxqo/GE92jjQ1sAPuNO9qde0jYK/y Jk7P4zE+w7noRHQU4v7zeez0UpZNPtABBWyhc2TTMn8m4oXrVHvU X-Google-Smtp-Source: AGHT+IGPg0TcyM5FM5P2N8MzncJHqBNaf4XUzVq0k/1hKGGahsM8lm6b1acACn8c1v7G9KBmrprMLQ== X-Received: by 2002:a05:6830:14cd:b0:6f0:e2aa:ea49 with SMTP id 46e09a7af769-6f0e92ce674mr19960426a34.3.1715814936703; Wed, 15 May 2024 16:15:36 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0ec2e566dsm2032159a34.15.2024.05.15.16.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:15:36 -0700 (PDT) From: sean.wang@kernel.org To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Hao Qin , Sean Wang Subject: [PATCH v5 3/5] Bluetooth: btusb: mediatek: refactor the function btusb_mtk_reset Date: Wed, 15 May 2024 16:15:19 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_161538_907706_DB036D31 X-CRM114-Status: GOOD ( 12.70 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Hao Qin Extract the function btusb_mtk_subsys_reset from the btusb_mtk_reset for the future handling of resetting bluetooth controller without the USB reset. Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Hao Qin --- v3: refine the git message v4: rebase onto the latest code v5: no change --- drivers/bluetooth/btusb.c | 45 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 611135d1ce01..602456e94fdb 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3033,28 +3033,13 @@ static u32 btusb_mtk_reset_done(struct hci_dev *hdev) return val & MTK_BT_RST_DONE; } -static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) +static int btusb_mtk_subsys_reset(struct hci_dev *hdev, u32 dev_id) { struct btusb_data *data = hci_get_drvdata(hdev); - struct btmediatek_data *mediatek; u32 val; int err; - /* It's MediaTek specific bluetooth reset mechanism via USB */ - if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { - bt_dev_err(hdev, "last reset failed? Not resetting again"); - return -EBUSY; - } - - err = usb_autopm_get_interface(data->intf); - if (err < 0) - return err; - - btusb_stop_traffic(data); - usb_kill_anchored_urbs(&data->tx_anchor); - mediatek = hci_get_priv(hdev); - - if (mediatek->dev_id == 0x7925) { + if (dev_id == 0x7925) { btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &val); val |= (1 << 5); btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val); @@ -3098,8 +3083,32 @@ static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) if (!val) bt_dev_err(hdev, "Can't get device id, subsys reset fail."); - usb_queue_reset_device(data->intf); + return err; +} +static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + struct btmediatek_data *mtk_data; + int err; + + /* It's MediaTek specific bluetooth reset mechanism via USB */ + if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { + bt_dev_err(hdev, "last reset failed? Not resetting again"); + return -EBUSY; + } + + err = usb_autopm_get_interface(data->intf); + if (err < 0) + return err; + + btusb_stop_traffic(data); + usb_kill_anchored_urbs(&data->tx_anchor); + mtk_data = hci_get_priv(hdev); + + err = btusb_mtk_subsys_reset(hdev, mtk_data->dev_id); + + usb_queue_reset_device(data->intf); clear_bit(BTUSB_HW_RESET_ACTIVE, &data->flags); return err; From patchwork Wed May 15 23:15:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13665596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3F64C25B7B for ; Wed, 15 May 2024 23:15:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2gZhkoZh+996W2MlO/z0y0kus/aLno+FBdFhG28ujRw=; b=GsJcxl8Y1MZJs9wZ2yDZUyJ8jm rt12VqsDKJ0sjYwBG2kRY0ug/MiqOdn166tFw3ZKMt2RhHR+gzZ4EEYrXk2BPD46kuwNU2tsSlqAQ w9L8kguWoAINUhs9ESOWOJe6o+Z1Fh+iKmcxR59Kml7sjvyC1b1geyy3aE0+dcWSIzja3AZUUJ4rG /4LQi1G/o103HKT8pXTLvimv2TQO1EL8pMqGuiZ+6POC7A9wUXXYeQcO4wEJpYOOIAErNj1W//C6v bbnex0+mksGTVpkfcNmsoSz1T8t3hyTIzovMe2rbyF3WxCYN3iCm/sluUewFhCqs1F1+0zhfPWE/a adr1EMeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7Nqf-0000000388q-19kS; Wed, 15 May 2024 23:15:49 +0000 Received: from mail-oo1-f51.google.com ([209.85.161.51]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7NqW-0000000384i-3ZrH for linux-mediatek@lists.infradead.org; Wed, 15 May 2024 23:15:42 +0000 Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5b2f4090ac9so337345eaf.2 for ; Wed, 15 May 2024 16:15:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715814939; x=1716419739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2gZhkoZh+996W2MlO/z0y0kus/aLno+FBdFhG28ujRw=; b=vJOXZxxV7hqVAn/TNFi1Yr1hlRKXqrpmRLKBv/xjNtH0Ml4oyEvTuq41aGoGF1xynN 5neSoBb7R39aEyirD6zjFxefY+fSC+nOQg9GH2imZc5WPfxJijAQWIRkA6PrWbZiH1FH vDK6dAzxMT6YVSzfepP6ftzOGJ9vS85a3QY2VT5x+a17RrQxvf8cjoupsUpnSOZxY/ds SvEiSrKKY+apVliN7M2QxnlEGEapNSLy7pDWx3yMgMm/sItaYmeiqecBTISMmoMbOKsN SvvGP+Kd4co1PXcpHK1wIJxz6vaXcB9q/916nv6QCar6Aj+5CdQWGczu8YaxvWGSb0P0 6O9A== X-Forwarded-Encrypted: i=1; AJvYcCXdXmYTHCYXUEHYRVCr13tOIiMp6JWkYrGJA9062LCacFhoYIlQ718LqI5VeFhhBWtU7vCTfngxuaqt6bhNx8ana1BV0h2kfC737mA+BxOZNiAi X-Gm-Message-State: AOJu0Yyz4BsyJrUFV2lqMv9dRyHnljO0p+xO28zzBSMJ3NLJ0nJKSyQW LNyLuphgmYC23euqTxwCZ4NG/AJEOSGyRrOtY29zD6dI33A84q72 X-Google-Smtp-Source: AGHT+IF0POBtkQziU+q0qOxtQZ52Him+GxehNpFjP35Htw+MWHS2pgEhKry+qlvjd5BNWQnU4udiGA== X-Received: by 2002:a9d:400c:0:b0:6f0:52fb:c693 with SMTP id 46e09a7af769-6f0e90f24camr18546313a34.1.1715814938820; Wed, 15 May 2024 16:15:38 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0ec2e566dsm2032159a34.15.2024.05.15.16.15.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:15:37 -0700 (PDT) From: sean.wang@kernel.org To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Hao Qin , Sean Wang , Chris Lu Subject: [PATCH v5 4/5] Bluetooth: btusb: mediatek: reset the controller before downloading the fw Date: Wed, 15 May 2024 16:15:20 -0700 Message-Id: <38805679fd6abf8fec46224fa8edb81152adb6dc.1715813148.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_161541_087254_A50EC1E5 X-CRM114-Status: GOOD ( 13.29 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Hao Qin 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 Signed-off-by: Sean Wang Co-developed-by: Chris Lu Signed-off-by: Chris Lu Signed-off-by: Hao Qin --- v3: split from the v2 to make the patch do one thing in a patch and ensure the reset the controller only when we actually need it to avoid the regression on the time spent in opening the controller. v4: rebase onto the latest code v5: no change --- drivers/bluetooth/btusb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 602456e94fdb..ddd5ca7596e5 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3175,6 +3175,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, fw_flavor); @@ -3182,9 +3189,12 @@ 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); + 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); From patchwork Wed May 15 23:15:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13665598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82447C25B75 for ; Wed, 15 May 2024 23:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ze1QygMwN68meqo9PDmwz469IrrkJxaffJS5Hm7aDfQ=; b=aCGzLjAzGDQyZrXtyjnROGRTl5 I8Fz35mFSrfm3aUHkhyC4hz5jkEzhoHw9dmogN2Y5dnb4XUUg5idKKPWAw+IX2+wot+ou4Mu4R+1s KImUDKHOWArPYKjJErQ9zw12MNuSGDyBciqoZIt0J7yywuaCk4iWL85O1VouLxaW0n20vlqf1QU0R 5JVxQ8FnUD4Zg4219sNu/JFshA7zX+wm2KWvIfZ/y+MZvhMelYn1nDFnmzgElSLN7H5mF4AxMNVGq 1PJUtcwgsKgrdkfdoJhh0kiwVSovGBCRnuxX0lpXLkKTAITfFUJk8y0MAuN9KTdDXjDgGhZ44aZ0H QjLByyfA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7Nqg-000000038Ab-46dv; Wed, 15 May 2024 23:15:51 +0000 Received: from mail-oo1-f51.google.com ([209.85.161.51]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7NqX-0000000385h-38Ts for linux-mediatek@lists.infradead.org; Wed, 15 May 2024 23:15:43 +0000 Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5b282c5fe88so366705eaf.2 for ; Wed, 15 May 2024 16:15:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715814941; x=1716419741; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ze1QygMwN68meqo9PDmwz469IrrkJxaffJS5Hm7aDfQ=; b=HDr3DpZnKaWPWlOo0OwXyo5kpllNCnxMziDHzMl+YyPcA61Mc2wSdDb11Lg5RAvEM6 Of8NlMCzwzpx80YpvCTk94a20jYxPsfnYbMu54SIxAYHR+yLFUdT2R7TIHYxhHx3cz2P MJrOh99kdfsElarhYz4zE5SQnAcY8EhPXGYMBkV8wnfnwYqJ9cYWUzUclghLzHXC7CZp Zw7CoZG2uwgnlRYowsdvkHde2xCK/+27OYPkhNd8Rb4yzFbVOuRLLZVhSifOCyC/fJYW VHMUaDBhxvXLv4VYZqkl3Ubb4czRxmg4BnucfTPaf97beuwObXaziB9+YZgCD99IjBqQ estA== X-Forwarded-Encrypted: i=1; AJvYcCXmeekkAgoiAXqsnQdOxtZr8lUNel+R/BeU87PK+aygAwExCVMwo2wJu361CfsrgdREL7TKR2HcwT/g7VQL8PjInlg8SafTwNyVfuyY4P4NREAT X-Gm-Message-State: AOJu0Yx/IAARlyLnGqULKZ+Lynxbc+abJ1JhUTD6QZk6n5DshU+FkR77 tziM9sDMaw6eNNldp4vCUwONlsWNltnvF4N9xUAve+sr1iMsnpSE X-Google-Smtp-Source: AGHT+IFeY6IBOmS16l1KarBie8GoRXUZtYtFiMESabNjNgeh9/aF2ykz5OpkEZWWolf+VV2rf5fl6g== X-Received: by 2002:a4a:de14:0:b0:5b2:7aa7:7b29 with SMTP id 006d021491bc7-5b28193d5e7mr17763186eaf.1.1715814940930; Wed, 15 May 2024 16:15:40 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0ec2e566dsm2032159a34.15.2024.05.15.16.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:15:40 -0700 (PDT) From: sean.wang@kernel.org To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Hao Qin , Sean Wang Subject: [PATCH v5 5/5] Bluetooth: btusb: mediatek: add MT7922 subsystem reset Date: Wed, 15 May 2024 16:15:21 -0700 Message-Id: <90f8b0663933990ed1bf47dd6698d8ff69f1a948.1715813148.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240515_161541_937854_5B1B3844 X-CRM114-Status: GOOD ( 11.47 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Hao Qin Add the support of MT7922 bluetooth subsystem reset that was called the auto revert to self-recover from the fatal error in the controller like the host encounters HCI cmd timeout or the controller crashes. Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Hao Qin --- v3: split from the v2 to make the patch do one thing in a patch. v4: rebase onto the latest code v5: no change --- drivers/bluetooth/btusb.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index ddd5ca7596e5..79aefdb3324d 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3039,7 +3039,16 @@ 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); btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val); @@ -3079,6 +3088,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.");