From patchwork Tue May 7 19:21:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13657642 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 5B49CC10F1A for ; Tue, 7 May 2024 19:22:15 +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=EbHKc868SB9HcUl+k2ACtYV5D4mU/L/TbmBCs0TDn/g=; b=ebliMNmI77ctoj1N+mpAdak3ab HoppxMnTVejyx0XBr2gTUJxY28QeSCMbdQOMA72pOjLDvFa6du1yXoQwEh2n05G7q2Lo/x5uRLINy 9TlHpWh3+jOb+nOUBCde7dp6RL8HKYSJ+9v/c5QJzpBhn6IyXwrxfM0u9k3OxAaeFlUkDzp3pTipV 2QT1cs25oW9wyICxkobt4qjNt5YRF6m6qzx+EmL6+OJeGhjVqQDNRCtasjwQrHquK5whevsJZ3iEN XGNokHLZ6X3y4d8zajzMDBHMBksnkaikQ4asRB6onTCH1D0f/wOaltMTIemtLGUiC+uae4XTifFOw 30MQbKxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4QOF-0000000CXYC-03Z0; Tue, 07 May 2024 19:22:15 +0000 Received: from mail-oi1-f176.google.com ([209.85.167.176]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4QOA-0000000CXUj-3l4h for linux-mediatek@lists.infradead.org; Tue, 07 May 2024 19:22:12 +0000 Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3c96ef6bda1so114976b6e.0 for ; Tue, 07 May 2024 12:22:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715109724; x=1715714524; 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=EbHKc868SB9HcUl+k2ACtYV5D4mU/L/TbmBCs0TDn/g=; b=Wg7kecmQMxzw1q5tN5AvcZAD1WZ8TZs01PdzNa+27B9XUmcSCxZ/QrTnY4V0kVZlu8 vQkRl0EfAHNWDZ0glQuGZTGPt/EEWesydI4CGZK4Qy1fTk8CULNkUfyOSS8mahAUJ+Lr vbkxccaEBLQILkniogqMbC9s+NUMqZ951/hVJaN5r88e+Oo5LxJYJRZtCF2Qe/leBQAg UwIxH9K4XwbjJ2TH4pMZnQPBqyZYO/dHW7lnXdSNfdCWdQTBpRlU9vRviLnLFMRM60qw l80aq626kXC0uCfeRikoa6C2bWhm6Q1QU+IVfYQwsyqVO6sJc6o9AxmFAe1NJzezUez3 vMUQ== X-Forwarded-Encrypted: i=1; AJvYcCUux7Hn5KS0vLnNewYG0/nIZoy39hINTd8q2t4PhdImZa3sPewo8gYNIPkFaniZyQvLHVQChnhAS0kThSYjCpmuY3et+DvtfPDduRCwNFpmJ22k X-Gm-Message-State: AOJu0Yzp4QlXvlkBMA3c5AjO+BUnhUdfBXv/Px/l7ZzbH5ePW4Nuffbc 9PeKb11KVRDs/uc9RCY83vY6AMIy3rLcMDxrOeyp7Zn6l2dHRjQh X-Google-Smtp-Source: AGHT+IF6/Amm/9IUVwqPVK/3VfK6o6rocm8ala/XYv84JC/t3MO2ZMmHzbvtXvjZdxTbIyJfUGHM+w== X-Received: by 2002:a05:6808:1796:b0:3c8:64c2:73fa with SMTP id 5614622812f47-3c9851e5985mr601086b6e.0.1715109724427; Tue, 07 May 2024 12:22:04 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id ec18-20020a056808639200b003c8643f0e5csm1937839oib.16.2024.05.07.12.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:22:03 -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 v4 1/5] Bluetooth: btmtk: add the function to get the fw name Date: Tue, 7 May 2024 12:21:57 -0700 Message-Id: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> 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-20240507_122210_982579_19208E10 X-CRM114-Status: GOOD ( 12.38 ) 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. --- 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..a0a858a0706d 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, sizeof(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 Tue May 7 19:21:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13657641 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 36C6CC25B4F for ; Tue, 7 May 2024 19:22:15 +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=7sYQ7hw69f2uaeyraCUDwvaBx7HkdTU5mSjbOPq3iac=; b=vJxUKbGyf1pJuAwAKTWsXvTM6f EHPagVePt4foeLkyQKIJzaS5M0LUQkMy773Du8dtex4muNQydFW1WvwNDvghnKsKSrHhZzROmLUEk HSPIUHRDYujCspYg5kPb4gtjbEfx+NxiYy+AefP/CAeboCoUT9wzLhl2YOgMlqPdINJq4Nf3xyEYe sneuKBdTjo32mDWhTw5Qh33uq6QQ8Vz5wsaT3TzGKRR3ZbcA+VJWpawdqWnV0f6Ap2ctc2o9q7Rq9 owqQYoAqS806aX0Ewez9We9mnhZlHW2t6AVYJLB8vVIRSfi1sVW1dJHlA6KNfkwr0axy/xUXcFFIa 1XeJ4GfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4QOE-0000000CXXi-2GSL; Tue, 07 May 2024 19:22:14 +0000 Received: from mail-oi1-f181.google.com ([209.85.167.181]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4QOA-0000000CXVP-43Rk for linux-mediatek@lists.infradead.org; Tue, 07 May 2024 19:22:12 +0000 Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3c96ef6bda1so114987b6e.0 for ; Tue, 07 May 2024 12:22:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715109726; x=1715714526; 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=7sYQ7hw69f2uaeyraCUDwvaBx7HkdTU5mSjbOPq3iac=; b=FqMQxKiTWUIrKajKy2804V23NMwtG5McD5ZzaDbh+6c8ol6R+M4G/BUFUAzonvTxQ2 3DMGkCjOe0CV35oOKKxELzvA6owYMWlDD7hn2qYSUfVTYUR+grPWJE0nFjJHG9XvmbBa zZ6Bxo5x+ltcNU34zid7TGS0kizkca/nv0v5Zu94gLALTHxDkJF4aW+hcFA+Bv3uLfZ7 OAEv22WXUtS0me4DU/Yj/Qy//zH0A6RwRiQnO5LRqIopwALtyvXpsMpl7IRmy6cGSWYj h9W0NAUu4lqom1KmCJJie2UWV+d4krljBvVFhK5rmn6P1BAspYDK2Xhw86/JP8TSvQmn AaMg== X-Forwarded-Encrypted: i=1; AJvYcCW/KrydOMVLH6u6H0hmO36qqz7M/9RjWCMIz2IYSl9UsqtVoUl+YC1F2/4A4BrVoNcwIEZJwHTI5IepqcaV8Khtk7hiNPQZWL1CYuJKdEdladBw X-Gm-Message-State: AOJu0YxtLLbAIIWp1HqaMdsi64BYLaoo/dJEuuEITrA/ZQA8EYNDqdDq eDcd9iiJj16JlPeLb5B8TuSy6UmyNBkr2i79EyxlBCtJ/P5ZBxnB X-Google-Smtp-Source: AGHT+IFGJT+GhblVrXRIxWa/VWNiQry1JanDcqFMqp4jnjRxoRWMN+EgM7MNzwp7ukiMEffX9fLAGQ== X-Received: by 2002:a05:6808:181f:b0:3c8:4b12:107b with SMTP id 5614622812f47-3c9852ba08cmr595514b6e.2.1715109726543; Tue, 07 May 2024 12:22:06 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id ec18-20020a056808639200b003c8643f0e5csm1937839oib.16.2024.05.07.12.22.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:22:04 -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 v4 2/5] Bluetooth: btmtk: apply the common btmtk_fw_get_filename Date: Tue, 7 May 2024 12:21:58 -0700 Message-Id: <6aef1a64b54a32134f5e995d1dadacbcd9c9ce33.1715109394.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> References: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_122211_027838_45C8822A X-CRM114-Status: GOOD ( 11.35 ) 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 --- 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 90d1f1697357..1603e97f0d7c 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 Tue May 7 19:21:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13657644 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 1B7DCC25B74 for ; Tue, 7 May 2024 19:22:16 +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=eyGlXVbcuOBmT6INVyvYbqSZy7NpTaBdxh15HEARP+o=; b=MwiTeIKW116CZy1jn5h/TusU21 YERmmGguMIblXYK3rHF3LcPZFI3xn+do0xYZ16+IhMUQjE7W5jesoW9OjAMmKQVZ0M+HeLK0LJexp xn6ujfQA3qsUP3qOb7uYyVyFPs4YKYM7WFtJEeV66If20cJU8hqkP8sRnAwgI4tl1tY5mybZBqMkn yvAuDxFwtxmxsfFn+7nT+LN/uQnQakkH6w6Nf6B70QoGqNl3M7RcKffzUPxq37dpm5wvoz30WB4sK bsoGEvolmfdtpMX56zJk8RcPko6SeUa3l60sh9QQSHLX8PsEd15hllNUjvtMa+ITzrybyiUNjTwZS vkkZEa6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4QOF-0000000CXZ0-3J0q; Tue, 07 May 2024 19:22:15 +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 1s4QOC-0000000CXVi-14ja for linux-mediatek@lists.infradead.org; Tue, 07 May 2024 19:22:14 +0000 Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-6f035fb2b03so97625a34.3 for ; Tue, 07 May 2024 12:22:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715109728; x=1715714528; 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=eyGlXVbcuOBmT6INVyvYbqSZy7NpTaBdxh15HEARP+o=; b=lh4fHCPAv8A/h2MKxQeUYPJn9T+EQ7aomSkN+gkMigh9fwDq0ACWb2IP+bCwxoxHjV R3DmMMs3BnHQMd5AfnB4gCsHzGjlFPFRhHu5iyylYRnKK5fj5jFx75BWPIitwH8jOC8J mNJWhpRjK/yawfh3AlOFa9PhDdKjmIvZjTcygL5Xn6y4MNwz0NJuomnldgiM8rsfPc2q lZlbm4iFcVliOAWhfPpaSd2YGXdnO+P+tlVQwapOtsx/XKRZkpfY9OnNrxjdxM3p4SHv 04UrZyaIvZSozuLn+yYG1CtNvneTgwVioMtWex6aGfEot8mU1HMoyL3GpRQTHrGSgQla PgaQ== X-Forwarded-Encrypted: i=1; AJvYcCUt+2DUHOQBDrEFfj24HgfcCg3HZMVP8HzyFcOOTqJ+nsz/Lzs2ABKMwqnqqJcckeuDpe5aEL+XSBOaJzUUIYz/Na3+2FaUcjkRUPQn3fRCXPkU X-Gm-Message-State: AOJu0YxbOfSmi2B6IoJyBIY4SIwHEmey+jvPQ8fO/oiQdMaIbabpXiu6 E8rGkAGDLfEy75QhBhg5+cHKK4N57TqKT5gOeQxYbnCzZe2PH0qA3WjbzyPs X-Google-Smtp-Source: AGHT+IEpqc15K+aZH7Df8bQldnVSTf8pYsmcQxJbCA3BrQZr5kPInLxof+4kwH5BEOk7Gu+fJGF55A== X-Received: by 2002:a05:6808:2008:b0:3c8:4964:cc9d with SMTP id 5614622812f47-3c9851ea36amr575921b6e.0.1715109728245; Tue, 07 May 2024 12:22:08 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id ec18-20020a056808639200b003c8643f0e5csm1937839oib.16.2024.05.07.12.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:22:07 -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 v4 3/5] Bluetooth: btusb: mediatek: refactor the function btusb_mtk_reset Date: Tue, 7 May 2024 12:21:59 -0700 Message-Id: <457c7be3bbbeda1241e097e99056d9c5e2a734bb.1715109394.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> References: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_122212_339901_313CD767 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: 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 --- 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 1603e97f0d7c..76c52f2fe917 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 Tue May 7 19:22:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13657645 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 BB3CCC25B5F for ; Tue, 7 May 2024 19:22:15 +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=SlonihVk5HXWq/ZpBp4yUpJHwD260ZA8CaexGXiG9rQ=; b=lo7jWkDK1yphWtcqWNj4wfV/I8 2NflU730Qj5I1iU4oumHjhJiETot8ny/Xu8UE5HnE+jw9lu6ZftnDWgf6ZDr+os5jCTQPyJVpgTSK 9oCV7fwutNKHHhCArUwzm8GzPEWGC/Ikn3hZh5LWKUVB/JneaFTkwTVTHgYAx5s7akn3bEaXeRmaw fSqfL9bCtX14F5picTqdIgE6bd7RWFugDuVP/XtZ1xPORY+Y7NqpihuPRlHgUv8Oy57tnp5hIMtpI Ezz09mJpjPvsWozZS8IeVgY4xLTD5E7DY34YktGuaztSO71zY28VB2cnY2zBOU+sxDqndmT/PV6lt RNmGsVcA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4QOF-0000000CXYX-1v4a; Tue, 07 May 2024 19:22:15 +0000 Received: from mail-oo1-f50.google.com ([209.85.161.50]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4QOB-0000000CXVr-3S7w for linux-mediatek@lists.infradead.org; Tue, 07 May 2024 19:22:13 +0000 Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5b209a2c390so419185eaf.1 for ; Tue, 07 May 2024 12:22:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715109730; x=1715714530; 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=SlonihVk5HXWq/ZpBp4yUpJHwD260ZA8CaexGXiG9rQ=; b=Pr3IjYunaCDsQ5WL1F4ZJPWNHEnXwIZGsTgIAG1tWI6UCY+x0PpgxTu8VL63zWPkkf 96bGudnFFATZOZeABARTujX/NbtzMyqmPaZGUAsgaUsTA8t+/Ew5x0RJRv5FtJ7taW5M eYHIPuSJHVRgbeAjy04dnzQOooi9mpPnMg+1YKP48TkK5/Uiajnf950tlktl0B/Fdrdm N6yzsfoMA1Se8Q+CmxrXSnpqVNhYG2fMSoHKwtkPPeFofQFc31soN1EiICUvAdB+bavK DQCa1XZjuBcU8DTlAA7ymNs5roKbrkag9kdeBWyoopftxQLcJdiCdSl3rMad4Rtnux1A gqMw== X-Forwarded-Encrypted: i=1; AJvYcCXk/fQLpdDLBcBqg6L2M9M5mKQKuZGLaY0g/BhWizq7/D8FqCOk7qR5Md8hJ4w2JAzOmMhV5XYmaYmy016Iv49WdWkannJ7tN+/cHMG9jkLWosd X-Gm-Message-State: AOJu0YzCrtKNR2OY2BwoKcu6vo5qLgA9ZdPTmUb1JjrEJCmH2wYzQ7Kg QEyb8p5oFW0Y9GHL/r2cYd3yxNncukKi+D5D/FC4PRiPs0VzjyqP X-Google-Smtp-Source: AGHT+IF9UmOg15I3ALrBE4OUAVGBFCQP5hgkpg6/WXPLKaGBvsjk9953JlxPcrsBGu/BmVmoH76jVw== X-Received: by 2002:a05:6808:181a:b0:3c8:4de7:6736 with SMTP id 5614622812f47-3c98543850bmr542210b6e.4.1715109729785; Tue, 07 May 2024 12:22:09 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id ec18-20020a056808639200b003c8643f0e5csm1937839oib.16.2024.05.07.12.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:22:08 -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 v4 4/5] Bluetooth: btusb: mediatek: reset the controller before downloading the fw Date: Tue, 7 May 2024 12:22:00 -0700 Message-Id: <3c3dfe8efc70af04794035537c7c40a52f2266d5.1715109394.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> References: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_122211_887466_9DF3C2AB X-CRM114-Status: GOOD ( 13.54 ) 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 --- drivers/bluetooth/btusb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 76c52f2fe917..054e8c06bcf3 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 Tue May 7 19:22:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 13657643 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 99FADC25B77 for ; Tue, 7 May 2024 19:22:16 +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=ToNbBgB0lLDuXRtTbvd57CqqqGRtlld+OojUmDuwhxc=; b=zHT6AJbKR5HvZvnLvn13pP3BJs z0ep6t2pZejyxaNKhbodTx1RvdTci6e2zmUWmR1iwjMuuxxlcS828kUYfShBktEtJoiN5wHKzw33K GLgJVdbtDxQjnbB2XElP8U8Zxt2HyYH+ay0LCaAB85AMceb1MR8JnXu9fnEewyhvOJDZyz9blnuRT 8/rljT3J1qS4xqA3cbIdTsFa/G7MRqgo55Z7V3pLTViN5I0DXyHE7eSdzf2ZnZP5/TWLFtOWvldyu bU+rzWx3xDIUKNwdwnAhDQaI2dbJnE7ANviqc6+lny1/kLu4NExEE3h3OXne/XIZGJRzyeARsyPzJ FKNWsEwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4QOG-0000000CXZL-0Rvk; Tue, 07 May 2024 19:22:16 +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 1s4QOC-0000000CXWV-0iaH for linux-mediatek@lists.infradead.org; Tue, 07 May 2024 19:22:13 +0000 Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-6f02ba0713dso387412a34.0 for ; Tue, 07 May 2024 12:22:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715109731; x=1715714531; 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=ToNbBgB0lLDuXRtTbvd57CqqqGRtlld+OojUmDuwhxc=; b=bP7vsJkJdX/LKqYYWJnnSZTqxWkWRhe+ZIf3BL3d4/nxMobT2wawVSuC3A6ZxAqDoe V6KYf9moxyXylePv84i4wB/U9p6qmYbXFxTcj4+5WfcrhpEQPZIeVIbYxNGUI78Ptcgt rkeBwlvbPOMz/7rmJ58RhaHGfDUhJsbypjrPL85O8RutMxVGXQkg7PHpRYRpWtUBm6P2 BMyQb580dm3TIRTOwums4zEkp+D0deUD5RgayjYkCOUy9O/t8B6OOAlgu60mfrwDcL5u qlkeumYbk6+N3x16K/yFXyIvh8XCuau3ePHZat6xQIf4wm+hcm4MKdtUR3hCbJ4bE6zP SzOw== X-Forwarded-Encrypted: i=1; AJvYcCVQhxeOvrmM74lszQ2l1HL0Cccfa3uGYcG5o29tBxygDjkRHkJb7eLmfReTgNCWPNU+4pQ7inQG4//wlJGofMA7sLSJOcACAHs8CImc9Bs8op12 X-Gm-Message-State: AOJu0YwA4cse8uYj/fR8EDxvs6jLp9aH7kMJeOqhJyewVu26jNMCQmFV jD/pQcloo1xm9wRPTWUYt77j0VgKaQq7vSYHPelcS3AKzfEE8uG/ X-Google-Smtp-Source: AGHT+IF01EcqeEosejqPrZMGtaa/ozo1Yp4hkp6Himg1Sj+DlBjL0oa9WOSi3FgmAGqaf3rlpay/lg== X-Received: by 2002:a05:6808:1a21:b0:3c8:49d6:2df0 with SMTP id 5614622812f47-3c9851ea375mr670264b6e.0.1715109731470; Tue, 07 May 2024 12:22:11 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id ec18-20020a056808639200b003c8643f0e5csm1937839oib.16.2024.05.07.12.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:22:10 -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 v4 5/5] Bluetooth: btusb: mediatek: add MT7922 subsystem reset Date: Tue, 7 May 2024 12:22:01 -0700 Message-Id: <346166eebadac93848e733277e164d5ce4c1d8c2.1715109394.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> References: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240507_122212_252715_FE221E64 X-CRM114-Status: GOOD ( 11.72 ) 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 --- 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 054e8c06bcf3..a70a5e12912b 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.");