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: 797078 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E22564F213; Wed, 15 May 2024 23:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814935; cv=none; b=oBxsnR6biDq89Zi4kGFvkY3f2QXERFAavqJpUspswIpz+l2kZvhyCF5zto+EvYUBd3aSdoYrOCDvT448+5JP3K526uD7byoxuQIGhXQVu10ZnVAitKKdUDU9QSq20zrhDF+zXpR94BzCvkRQtMxXHoJHH0d7GrjEZZ3Kv5RK+WI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814935; c=relaxed/simple; bh=KkdBoviU2Vuexpn42UGlpxq9Hnymbw2uFQMmvXakpkY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=sFIySCDFABoj6Q685N2Qr1Uff/xHPz80j3Adc+/FrL27iO+RNYrb7rEhJorMF13oRZgysH9ajn/m6ek/EfVgck6crwtWSQw7/M2KpHvHKLHWD/pf2KNQZLyhiG7IWwrSaWnfvjcg2CVliaiI5MWXWEouqk0u6aV0IP2hbLvXUo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5b2f4090ac9so337323eaf.2; 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=NGegB6xXXuUEqFUqGAvah4O9regTfvUG0r3oImtQgP4dQIiI9VCmxNwMYKsnF4e6zf trXUrG/PS+TIXLo+oIArt1ppeA9wbvJvvTGTNMmUUR/FX/naoE57GcoBpwHzqxZL1lML yv4ZUVIVOrmNUcBk8yg3hf7YSRc10SnzpoPAb7TdiesviVgoOb9h4eyAAMe8a5HtQ/Jp FvVRuS8vBv7WNqgWwxV4qYBRdRRD00k8+Enq5cCdjJ5Wl0KesKqZELl1aJ5pPTta8WqQ dEU8VLD2xlUT1WTzCOaBJ4CaGNZlTQqANKKAA7Ji2Nq+VqqSL6E4OH6Txok/CDUwuGre aN3g== X-Forwarded-Encrypted: i=1; AJvYcCUVY/7TdqjtG2gjI6Yp52TfDumJ8OAfntrZtdo2zf1vjqkzz+H3L0hkmmj4BdzYc4dp/tkZxC8gQl4TA2MNx7mMfGciceGCSqcv+S7h X-Gm-Message-State: AOJu0Yz0uXhgUKRbAghIQMAsXUV9ZlyK0JFtGgskpfWnsehBvJqccIsH eZICZbwBJEGUTzS4HPkxunrWgoUtEQfLNerfnx4VxmW8h++M6XASxO0PCHaFFr8= 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 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 797332 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB32B52F99; Wed, 15 May 2024 23:15:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814937; cv=none; b=WUu1X2d/g0GTx/x1gTLZWLtYpn29WlIJLzC0YJwSTqK4XNuwhq7HDbvo8dl+16d2tuUbDqkOC+GdzI80KlvhHY2fksekGzbV4dUoNU62QI9eJt32j3oE+KPgnuu7o99kbpAvwzEuiFcmezQKEvWDzGl/dHgKTBhezbOyLUOqocg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814937; c=relaxed/simple; bh=Saa+Cv9T0K8Lpspg+3DK0q7kAqVgxKAxcJ1zxIGrbFY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fieb8SbOONMltp1CZvBJS1/j5/2KlvNl7CXRH9hpwzCqHVRIH7BXB6boZiXMGQdvZxUK/VZ78L8nPsaEvdlN5TvR77p8FrX/crXgR9LbIjSC2rrNj82wAIKdplz5jkYCMrdtFR+BycAgqQMaUo7SKBSjyzIfJcJdOquUlKUq5/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6f0e516ee2bso574858a34.1; 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=BlA64QNVk6bH5XTCGKwnx1qfedNSpCwOJZuUuQUq5iTtoKZ2OaYyvZSvGqCagfS1WT VYTNVAjaeZOzegvhhtt5eBE4bFiM+gehMPJ1NBWSXLNgDoQgjhkMPpXazE/YA/C4958q fBk++MS8lMSPiSl4GiSNweZU8UF4RV5Q+KvAITLmBEFVqvbGwCcqSIh32PPhOvVMsWFs fPvQh7ttsyVCENei/A5EDMtPbnD4Pvc+GWF2zCrnPC2aD71pmt3ua5WW133FiEW43mwT kymwcgaVM7wPCCdmBFeyF/BCH+ZvbVcexuLm5nsZ4MpCkHk2ev9f8m8bYw5UWc5nHEk5 AcLQ== X-Forwarded-Encrypted: i=1; AJvYcCWRU189kpyusLhVvxo3/YDTwwZkD8m/9B/rid0U/4+O+GXWPSAV2n/smMqlajfsFi0qjMIz5f4nJ2zNe8oH3LYNX7S6kCkUO3mRT8zc X-Gm-Message-State: AOJu0Yw1chs1QriYGQ551C4eC7qQq1ItTSVPR/K9S6gxJYxLPS4t+pLE aI5B7uBi4XF1qusvl0xL3q2U61aWWOCVaTVGnggHACweV3GhWE1o 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: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 797077 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B818815B541; Wed, 15 May 2024 23:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814939; cv=none; b=ZC0aQHr4+wlj/c6XPMR33p463j1VJlGvAXVrCoJ//LXoRqBY0y0WUZUDqgmMSy+c2UlNqYSrQrfI2rF+bE40V9PTJa6/3m2rgrRUEUlbiMPBwCrBol1XO3kFWdkKNCnzK5Upf8Cpa1Ri6SzKNxlZ7OI4NTs5VKX8h5vfs4BYY/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814939; c=relaxed/simple; bh=l7qaEhv18i07jkg7QgeZLvVfGZZI+7PyNiWrqAvRAG8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eso5wLJqYzKaq5HtALesc+WOL83tbu6oBPs1Oe/no8xQH/afRbtrC/3rO7cCwBY7v53FmtZ96/wfNFkt2j/FC5+vD0sVp4V9nMXqtc7G79F53yWl0j3MtOW+jLFfxf/uQptJqByhziiW/e6M6jjHtamJHKyMeuILzmgPYWESnPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3c998b36c6bso1208060b6e.3; 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=MMA/FL+uAenozHTrKmLgrwkS5eyzTMkF1yXsGZFSQ09aIaRK2kQA6KTn/FcmVXUjQC 5LWrO0VvF5YJQdChvRLzam6VBWPivse2YXqz9FLBYanG5dl46nY8zV1/r9H9P9hhg5Gq TI5Pw/iZ9hQ73VfTsFdJFtNyUbEHhReigaAoJQ5PmXAa8zs9h1vdSGUB67EXfemnSpgE RGHYk9BfA2I1QDzexUm1kgp14YqfLhUQUcW6+i9T9pfu52uwNNSyqWWAbc4t6mGPV+Qt TJU73oQmYvuCuSEA5k6iqBu0RXEzShOnuEwAox7bet0KI1dVGAIZ9+RPpd3fGk2X2iFi tBOQ== X-Forwarded-Encrypted: i=1; AJvYcCUU+0eB9WTLv6WR60muFw5RL2CDGC7IpkRUFbMqY+MtVh6R3s2IRGeFmsgeqEArRsWcNcw33vbMyqU+c2gJiGzRNhnmOYSNqoNx8aYj X-Gm-Message-State: AOJu0YyVXdAZOU/g9bfjePd9NVg3Eo6PI6mSw+BDne1MauU/l19SYOJV JFbAWNygHJH6MV7T9TmWfkvBDgHqv7zbDiW7Try5qfHYpl5G1l0U 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: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 797331 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9ECD15B97E; Wed, 15 May 2024 23:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814941; cv=none; b=aAnGzowI+pmYjcHa8tBLmQDfuRHhYDweh4Aa/zSrAZn0VBFxAH/GpqUKKDkerCisUa5e0JrBJyNECzboBVJGmoNcN13tsuEPgBmw03VY4qkk45wzQ+7C6yfAFnVp1UC1DHl2cD+2uls1BN3TqYnoNfsre/oK9V7tq9qBAwuXs2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814941; c=relaxed/simple; bh=J8svAqNhHH545H/TdjwK4kk3WFNcNp93EwVHK7qP0ko=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ezRx2R+bi7rnOWX46DXbTYae/oZQ1Thd5jq236aNOYgOOh/Q/7AvX+29TNTdRkMATN15u7n06C3HKPEONrL6HquRHIB2zB5OhVYFB3jM9V78IssD35t6n0uTp998Mw2cWSxZNzXRcafKouLzbqaeNQIor6tnnFLuQlO/E27vJ44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6f0e6a32754so18760a34.0; 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=sIAK6EBoPk3H0Tqz9qoQb9F13HX+HHApmwLL5JvMU00+KrbIhlQXKC8RzCVTgLZ8MK g93XmmPtaiOORc0MTx1akSTia01fQoV5Y3fplKouzh17+C5XLe3Gp0LmbyQuOQtw/kqZ RKejCxTj9i++b8c+x4mzrXMfOnTUswr7bT00rMLV/9kGoE9FVbepgPQAVfPF5wPxOZ0s we7TUFlmAfSYtuhtsZdO/IUyCA0YVxMX4A0A0j2veFTipRe6s5OPaRV5n5Rz4FgnFIQ8 IqmEXDTeZzn307bnTm6zgrMDfMX+tfcVj2/7y7UA9c8BzZwhLCdYcHFaFyg52iTPLORt Xu+w== X-Forwarded-Encrypted: i=1; AJvYcCVMsnNz97/vZ0zA/GcOtnEbD/Sxw1e3il9iJi3vWN3nGTPREqILgeZvlAdtoM1OCLAjsIaEwFtQOFInQGFUqAPkv7/sTi8JeCc2ical X-Gm-Message-State: AOJu0YyTDmwvsoU9oMJHrtlFUoym4gMq7d97wke0cs1aX4aQOGT/bX1+ 6+OivHui6EzD5TI0oaJxgGGOVSeQfQF5ih/5Wm+cHWH9GJJ37hea 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: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 797076 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDF9B15CD46; Wed, 15 May 2024 23:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814943; cv=none; b=F6RAzSkOlXxfx0jGxBmKmZBYNSq86kg9pKqoU2uwdXiPzDmAhyzOAW5irVuGB/BdqWRVC1u5cbjalvw+b0A2TFCpQZ14Gf1KJhYf7uhwloAdvc3xDLao3G0e/P3kH8e4sdrQgOkGOIvKMChfF5FbRS95Qq0o39152dwW3UU435M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814943; c=relaxed/simple; bh=Jp3BgbsRv61fdluoqzPcfIEveCnVhqg8xF3iPZw2188=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iG0aKf3dT4HNVIhMuwyR6KWMOP+7Le0BsF/gXWsDDWaBGcvv5xNEELH9suM5n9Pqy4aR3IsnrB5iyNZVwh1dNswTs6y2dGRQ4RZedICgAHE821T8zx+0USoxA94zCjv02lNOUVVMUQI3phcPE5fjzRdwfoVPUcJLmqBli14x0fs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3c998b36c6bso1208073b6e.3; 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=p/1DFGmnDUJn2dxuWA/VA4gbpJX0Q3UajADBE2wcWF/CGcB33g6FcgJQSkpjYI8bOl vgC9tcKQ3LT+ZclLD2LV40KiVBCjk5vo1Kq0QGysfLSQVBLprKrkOafmCYR43gmViQlE 12miX+dJMqZoLGg8XCYxIMiC16QsKCwd7GhJhdZD20FmZfBXAD64c1/x93N4aTevjxaO 7dXvoI00kKBgAQrl6jbf06ijwQ/hHqnq9hctXXjEjyZRTgLTMABfCF2/X4XNf8d/KfL/ TVHRj6E/kw8BhQIhyPhv1DWu9/jG8Tl+mBC7xwba6CyVaRBmSmk/o6cmqKRsuxAs5WtD T4sA== X-Forwarded-Encrypted: i=1; AJvYcCVchA+hcKpXZmISWS5ht3g2t5Tsaqzz9zHSnshF2YvjwI9M2PEABlKtW5tZOjgntlZpQiapAWdHKTYs77IUZQaGT626npPIYMkthRU6 X-Gm-Message-State: AOJu0YwF6F24yrdG/WyJuo0xz4J5pZ+FwTcqplJ5ADoADrKXmw9thB+d fPV+yMg1sXvV/v0WtMzz37Cvdm0iQrYMT+ES6t3JLvv/RTKGU+T2 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: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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.");