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: 795581 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (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 3DFAD16D9B4; Tue, 7 May 2024 19:22:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109726; cv=none; b=s27oQUsYRNF1VTauRYITE9ajjrOBoKeaTvawP0gylFiZr2Dl0sXk95lR4RK32w3wpLWwvwtHuOjTnQwVm3XKzvbaQbXo3HQBK1neopjN18mmXcWP3Fjx1da8dXtTRSChhz1CDy/UKxyfVwrk5kSLhB++gnRSyiDShTkR6YvHAJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109726; c=relaxed/simple; bh=qp+EXX+SaGOTNAAk6fUdXyQK4DSdv3tg215Ei2Un+OA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=HcuZjSzIfcBPv9kJYGYZDiOgGDcCdv3sksG2AQkYAue9jjD8dyHsAqbMDkh6X/117Kf3Luv8CEHfQWlAQwDBVXRRlDIPq5xh5rt+l1C6Kitkuan/NHoWYzD6bUU3j3klvpdkQO0Rnvbp7M9u41C3YNpmG3MMgFURQUlNQpqeYQU= 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.173 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-f173.google.com with SMTP id 5614622812f47-3c96ef6bda1so114975b6e.0; 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=AwOhFxKub4GRIue+5Z7GLykguaNo8ozgMhimxRKy7PaISIOTJzL4JcK9L075TjJrer CVLXKCn27jBzWZQ9fIgUpjOEZ6oUltAR4uldenXi/CcYdDGGyyJ0cZJVkCNdKEIANWn7 JRwI3rsrmirMzMZHCMdm158lksWrz1J7cmNeRGD2Uklp74DUkBqFAJQY3kG+HD5ncMrX RHg1pWJA4LrEzTGqPt1sLDC6fMJOEBFbDraP0R60O3Y9+2kKulcr+etxkjKkcnpRf7Z8 F4E+hDNdATp/W0Iwtv6mwn2M183LgLqmg+2sb02+LlAhATCvbboyuJEZUry3FTvYEMnj IIyA== X-Forwarded-Encrypted: i=1; AJvYcCWfq6xSoaA7DvJt8dSTJ8g2Ht/tLOObMe/JOrhxqvTBOpn/api/bhoDyT0v0dunK2cVK5dxkbKlzEShUB93Xl40IHtxXFbHg1sqWfq9 X-Gm-Message-State: AOJu0YzNzCqftRGEBZDpg2gW98/hHUVJhMMekxXjPef/eM9FOZKeGFo7 obDyDRZiqA5PGc8J4nzXvxGVuxGlnyZJqMZr9tbhh901GP3QdkVZ 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 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. --- 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: 795327 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 6883E16DECF; Tue, 7 May 2024 19:22:07 +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=1715109728; cv=none; b=hnmmRRFaagbtkCDfrkZs1B6zKlyDRoZfy7sml+OSsrB/V5CchGZ9sGzGhttu3m4oWOUHkPLGflr6bl3nuNYU3A6zBHNXK1vOP0MxVP8IhaHvRoAoYUU3w4Ig4mAimCkW3TKtK94RWi2cySNHbw1ERZuq5A8moiEbt9lmcDXTpOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109728; c=relaxed/simple; bh=p2WcEKEhwoNTo10Ew+OtVoaB84xhMJC42oHb4GD7Lfg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dt4z0Vx5JqbRMi+uHQzAiZjT9kR7CNkk76ursziMbIiLK9NJ77BGQPTZgW52rWf5PxqFfLbfKSfXfqsyD17kKkNkDwHxr+NrMs9183M9iTH3DxbbRZfff0TKyEfEcLvc/x9j0n+Qt4pbrwBkaVx3HP9Vu+zSOLSmWdyvqo8fhAw= 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-3c6febc1506so97285b6e.1; 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=hXmn2htT/SHsrx28gz05zJNiZkWpLgpD2CCqTjXItdaLMBuKLu4Hq1ZvK1JXCrpLBT kjJFr982zbbfwoN2E42jf+ws+R3swx2FPZRB+DsefIldwuqZM8QZWscSNQcUZjqu3Tuj Zqf30QsjcWH9yays1SikDEBq9IpQ0gsyQgbJzVSb9kBpnenoYDNntPtpOnXTOOTri2HF mkYcUSujsWnPHMwPSlremYu5++RXCmElw0CPQdbcP9buFccyQ4KE09otfvKq7SIrKOsM NAputCJy2w5ThtUrL8Q+qy5tXotvvZvdTe6UW3AXuMLwMQAeOsrabn/2ptTQR3v/+otT 6SKA== X-Forwarded-Encrypted: i=1; AJvYcCWWJzHqVhmmxT26muRFjBffOdbvSCZJ+JexaBDoZ4eUAxw2QAqJvOoUiswy1b/Y/CXT8RvVLlQ9rR9zdnhx07TOLfmGo9vbcZ9w26l6 X-Gm-Message-State: AOJu0Ywn07lxC32LlmFVlN0xbmQKxH3nriKuVT2uG5eE6Rd+HWZHHj4D qim1cNLM3LewuDH8Ck6cHfmlL9U3/LrTxYPLs9xIZyjp/kQEFiCk 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> 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 --- 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: 795580 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 3FC7516E89B; Tue, 7 May 2024 19:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109730; cv=none; b=aBUprHEDHq0Ql0D7uXgEd/I9tgzymhrSo6t1+u3+mFafnh6sD56dho7DtCfmPXXbZlDC3rcbuFmhjN4/m1Yj/FfMGXBoZysCykOza1h3Y3mHiVFosxAt5NgM/5EUbPvA/FWhp+8Ix/1m4mc4FvC+3uSM/l902Pyrkj1WTB76IXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109730; c=relaxed/simple; bh=aQ9zB0CP0QI6bN2ZiPhiwNsW9sXlvmMqsyyaMqc13nY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uHe04fzF1DTLY/1SvvHvRY9CtONa/7qaT4BxXXUxs1RNkzb+cW3+W5gEUgSs9ndOVX01DzNGq3o7yjpxRCAxN79J37kyRErbhe8qUqAKZjGuocJR5AnLhgRw+i8QcDorGJf+KdANbjH+FCt/CyasAkcq3Bj7m+bFf+ShkGp4bRc= 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.54 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-f54.google.com with SMTP id 46e09a7af769-6f0471efe4cso66795a34.1; Tue, 07 May 2024 12:22:08 -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=EBx62FHebC781rgLp/m27RZ1jC5UYzYCoVXt5TGdYr2du93DR6euCH9Biyd4LAvT4r LyRyU+gr8wX15jQ8yAwn0s6dkwkY3hpGUPCbgQLrdWy6GnAeT9OlA2orvtoDJPGtM+pm maT92GEPX5Yaju5dI/cUitydG+90MhIJd5cmN3titQXqGpuZOUTxArIuDncrscgt95oc FTFIf7QMY/2H801d3202X2qgfqg0yO79NfP3AC6rxBNYuYufWlKXc+FeXulr4x2ky4C3 g7RjH9KhELdNSD1V1CtDuVJ16ShgPsgRuPLrCpMvGgTW4FezxCsjMGp5r7ppDblgUwsq VO5w== X-Forwarded-Encrypted: i=1; AJvYcCXICL9MIEIEg1dQHk7Scb1EayfA9vvDB/6Q0GhF97ZCfjHMOrzFWyq0z6xbvd4bU3I1jBsRPqXvBddLy7iLNwcpjyst0nfUBah/qcyW X-Gm-Message-State: AOJu0YxH2Qp/YqZYMeSKNeMvuh3YRXfJ1rWlwP+7u5dlRUO7rtd18aOX 8hxOPzjay1H+8YGnUnuZwHci9N7LydIkbOTm887Oxoch1R63fbxw 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> 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 --- 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: 795326 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (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 BEBD016EC11; Tue, 7 May 2024 19:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109732; cv=none; b=hE89LkTM5VR7VeP8hwdER5iYiw1Ows+iCBAaV/pvFNiiRdAU0580BlSK0DUzUMtTSDg75iUHr39R9+7mKWtoWtrs2ens+aeHp95pWvVR1quiykU/E6pvcG4YlGcV64DplGag0I/vldXMixb+RjGzqw2I132gbxnrYMruC25D66E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109732; c=relaxed/simple; bh=zeX93PqWQJOMUqO7tMUXpYKyT0p2tqeT0oe7g6GyVJY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=udnTPGixs82Y2o4P7RwSdeKVj/zuUCqNIJO/7qvyBPV63KWDcFasBVqTZDWC4hr7Ty0vbjvP00lF+bREb7numyIJJyRvyhGcUvQxMQG63QuCOUIsDS4nDOgzwFY3tl0XR47akAmv2ZV5V1MHlSJUNJoMzfD4P/4/aVBRfPueDmQ= 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.44 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-f44.google.com with SMTP id 006d021491bc7-5af12f48b72so734988eaf.3; 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=let7ueCbXut993voTs7aTJyQF0BFhsIXTmP6vKK1z1iXnavXh2Zfr1rT4/0rD7uFA1 nY+exWTgzhC5RXa9J9L4sYc+mo2vKiG6+zj4FGylYHzG2mTCUMzaN22yfKnvoqhunRD4 /VK26KHrn4qplKLusZDymLDzax+o4ShjsXo3XBq3xRE3Juu9WPj4OND5hI6BYggzoKpu ljYCFw4k6BpOLAlQJZELGpjKO3D0XIFrBRCjXTd+uLsrA5YQ5U7eWcanHytUpoivKHU9 pD1OerGFPWwaL3dTwZdQS+JrmVL6WesYMNJAPfefDtyRrm2OyVU8NT0+cVGXYlAUrTxP Lepw== X-Forwarded-Encrypted: i=1; AJvYcCUxdz/IBSZU6Z82NJxb5M6DbHlzolR8w63WP8qwyIcULyc/cbGzDCUvdH9UeSqWxG8HyD5S4833UX/dtrOUiZVXBtb1s+i/2QywywmY X-Gm-Message-State: AOJu0YyOr8/23rBQR0Zq1phG7w/HZhNqPiRj3W508B8eh9S9UNCtz2Hd uiQDm3YKopGaaxHXRc3K41lQXnVyoTNKabEvIoT63NPauODJSCPU 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> 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 --- 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: 795579 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 5149C16F0DF; Tue, 7 May 2024 19:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109733; cv=none; b=QzvIkiFHiqPJaFRfk7nQG9YCOWdn3AStbNY+o7F9JlA4a89cdImYQK+AeRjzu2shTtaECycpGK6GPvTsPzCR+cJH+s8qB/rWlXGy3Cns8FaEAAFLz7Z8j2dwGiwoUS/2msVuLqnz+cAo4KJNenxYYIEeWM4a1JSK1Ae81kyXUHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109733; c=relaxed/simple; bh=t3anCqoQvYawKfAJbp+mSiJnVoopchGAQ15If8ihT9A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N1YM5XMdSQpXtK412plbt35bYWD8J5FDYYPMAPAD3TbbH+OBsKrHEyoMXSQB4zUXDVoWltKBTtHeNkHKf9SbVNXjACponA3TCJA2pjZPACD6y1ox7LSTgEP1YscDpQvKRsI65S+ZjojE4XeLV0DgOZrDE69o9t7EcBwwgkqiRZU= 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.54 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-f54.google.com with SMTP id 46e09a7af769-6ea0a6856d7so194684a34.1; 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=EX1pYKfUgxomkYtL7nu2rsUmJJfEG/z+iR5zfCupC3EIxU8YYkF+4K3mbiC9m0NcVz Tvpc2VN+A/lsTTGATKbyS2wyzWeYURVCrLB5FCYKPAoPQPSq+Vh/UqqG/t8786chAoKN s3glmEUN4xQ2gmLy/fcY7R25ygC0j+ZPhhiGVpJ09KJU2afO84EqiwbYFVBftOz76EZa IRZM1UtUqNt7uOiWvWKhK6OjcmIUfUnEyG71B6k2uQhsyJTulWqfKHzD3bfEDKO78OiD R60u4Ji3GFfY33gpax35Z1LQnN7MunJck6zjYwtv1A/0lsI5w9ucUsHvBV/6USDB14yl c56w== X-Forwarded-Encrypted: i=1; AJvYcCWX24lMdz8pJJSAnl4tTZNTMPFHn9ooQdEyhr6/Fw0SXGdnLqqkc0SDn3uZXeiTCj9+kPGl6+zwkTsGW1xyB9KVyjsIxbRs/5aj6CxF X-Gm-Message-State: AOJu0YxNOu0VyIDIPlKU/Lne5N0Su4E/M3zrLi0Q5nO+jLig63wECN5T wB+ojAN8LtYilWC+B44sTZv8kxGZcUal9RfavvAbb14/JBg4gMPj 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> 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 --- 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.");