From patchwork Thu Apr 25 22:06:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 792446 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (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 E50B715665D; Thu, 25 Apr 2024 22:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082834; cv=none; b=AWjwVJx9diij45au/keRJfh7oK7f219NxQTF/gOmZAyuorl6viwtwmoUu0JPpsuQ3HcowMlxFQSfvbyKyqtrhHoLNs+9UHNFR+dM+DblTAYh7MpeC7knoKcghMp7KJJ/GnIqVAEsTElkvddOIBhUEyGCsaHgluvW5i3WVIJ00l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082834; c=relaxed/simple; bh=BzmTF0f6Or1J1FCkmctHWn62o6eb0FlQ08LbgnxooCg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Vk9Y4gq3bL8aS7zvGEaRzBMXFIcfsjb9CEcXeI4pZAPYoyqOKYM0Pv9idivwkVXHvJpZVeiykIIZbyRKfVo8XAwpDOG5rMdFCocNG6Y8eqt2mSYRKfsOSW7LjEU3zIDPp2fBtKzzEfH24UVnVC8MYr3Glf3kfK//GLJ4azTyOGU= 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.176 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-f176.google.com with SMTP id 5614622812f47-3c70418ef53so147606b6e.1; Thu, 25 Apr 2024 15:07:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714082832; x=1714687632; 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=lStmgiqTJIXMZ0FpbHnHRZG5n3g0ZAPBxl1jPCO//LA=; b=n/HRGcqCDz/ELZUei9/10BD2rUl8XxgXwAHs+QiQiC0S6Z+PFQ4zEd050QvNQHSYZB MJ7PW4T2OJZFvkU6JirfavHeJSx54E/BAfCsdrOZrrzRQFFqRTVT+fN54HqbHRFqqnOk 8ZqBfSafs8OVEPv9lMQTZ5U7rhn73dXlLSML6AyfGc5YB/VqildMwAwnzzeo7pzxD2qp Eu5uoiPmoKbo4E4XgnOzSHQNCqqjhc7eU5IBe77dnZoz6IZ/O4U70IKsFbBOOcOJ2Ggq l8pIu0W0172FTgoP88+nm+q+BAL5EVMdr0IeKWM3+bw8D2kPd66XDJgH9BB3IrzDBDtK ci7w== X-Forwarded-Encrypted: i=1; AJvYcCV8tiEXTZbzczbw46+4UTfMMWkO+qoWwVh1jRQt2ICuFzTWxOBwz9hW7JveOkx90OHIqETTucLstL9lV6SU4xcpz1FV8c6iscByFod5 X-Gm-Message-State: AOJu0YyOqGq30nFsaqJXvLxFqNdA8xe0Xr0Zubm7tY1S6M7+BO2uZkTO vLo1cM6HU5anb0nArHct1xLy9aH073AfuTu2AixT2T3XweDDbkdl X-Google-Smtp-Source: AGHT+IGnZRhr6DaC2jeDPcFMkAZdwigwlzS7ta02Yx9OWUvO003Lg3x4ruU18ekQ5ot8jHcYzT7pcQ== X-Received: by 2002:a05:6808:bc8:b0:3c8:4de7:6736 with SMTP id o8-20020a0568080bc800b003c84de76736mr970276oik.4.1714082832086; Thu, 25 Apr 2024 15:07:12 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id a9-20020aca1a09000000b003c76f98321esm1514421oia.41.2024.04.25.15.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:07:11 -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 v3 1/5] Bluetooth: btmtk: add the function to get the fw name Date: Thu, 25 Apr 2024 15:06:27 -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 --- drivers/bluetooth/btmtk.c | 13 +++++++++++++ drivers/bluetooth/btmtk.h | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index e882613036a0..7ead7f967019 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -103,6 +103,19 @@ 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) +{ + 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 + 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 56f5502baadf..ef225980f110 100644 --- a/drivers/bluetooth/btmtk.h +++ b/drivers/bluetooth/btmtk.h @@ -159,6 +159,8 @@ 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); #else static inline int btmtk_set_bdaddr(struct hci_dev *hdev, @@ -193,4 +195,8 @@ 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) +{ +} #endif From patchwork Thu Apr 25 22:06:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 792116 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 E4CC8171663; Thu, 25 Apr 2024 22:07:14 +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=1714082836; cv=none; b=JH5JIp+U2WE0N9y70YJ5JYwW+FniF6Hsrq2JNdKs43/42+gwNxjaov3BwqCEqmhqj8CMFMSb4a/ISfPLQZ01HCZ5LcxKChYaZX616EzvX/lJ++gLjlcXaOMQPHmW83cgo34+zZT+gofR12HaCM0OOVcaoInPAFAUBHNZV+CGUH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082836; c=relaxed/simple; bh=13D6JKK2klk5hO/uMY8wEvGkd6yHJImAi0ZXLYZZe5o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fzK+54SIS/BHeVNyalfXEbZ3KrIper5s7LUJ90GtKnxGDSoRB6eJp++5fbHlJA28NCslGNgooyDOcDR/GIoY7Qe2Pp/qkKAG/dR1fKTkpR8e2UX+cPbKZWe7Z2J8kRsJdFDrqq9Tn/VKAx0uS0NRIy4BcJqGpNcVp6SQhYcHQe4= 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-6eba841d83cso341013a34.2; Thu, 25 Apr 2024 15:07:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714082834; x=1714687634; 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=aOSUTMsrzGUh+EZaDgRrzzwhmdgrzIn+vCN9MSjqzbg=; b=Wh9A/NCfx4JiBswaUIyBz/O7VE1rDERKyx89a1lDZQtuczR1XacRtn7P0RxHajXVJs tv16pHx0GynzZxv1DSyObcs77e4/xnQ+hy1w4WzXdMx/xtmXaUVWpARRiT7GKUBW49MY Eyued7HdZENJEdk8Q0fL0oB/wYC+LLXXGqj+r70YdZbVRjlasOO/pFBaM5iL6mgq+UlH Wmdw58aUlA2/tR0ryhj2WMHVRlsAW5hEKfrmbpmRx9YhyxAcDXCdZzn0b0rysfJX6MgU IBGYx3V0b5CKzsvGS/y3ZEE4FybgMPlsrj90Je8HafPRHNk8rDfYDj39b8AfE6Qoav3Z eZDg== X-Forwarded-Encrypted: i=1; AJvYcCXfqxCrXonRlVi/Kq9PhXHQ9LMw7SKyNozkZFRQIE9rJ1Ms9hgon8RLKfd00fIqIn1lwcAQiczFdIMutShqAoiyQP/a1+rUH+329/pG X-Gm-Message-State: AOJu0Yy/U6tEW9MjXvWiSSr1d93ZoVZ41T2RCzHOmRKQRSUCba9FPhWN MNHG4rO1F6bqfIDXlx79nqc+IiAr4B03oZZ01aZLilgmxbnCcLfe X-Google-Smtp-Source: AGHT+IG6gSzPWbwWp5355tnnWnT7Vm9ciJl/9skpqxx0WDAK641I6qUFYo2xHAnEVdPXyLh3QBgctg== X-Received: by 2002:a05:6808:189e:b0:3c8:4d54:94d with SMTP id bi30-20020a056808189e00b003c84d54094dmr1149679oib.4.1714082834143; Thu, 25 Apr 2024 15:07:14 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id a9-20020aca1a09000000b003c76f98321esm1514421oia.41.2024.04.25.15.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:07:12 -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 v3 2/5] Bluetooth: btmtk: apply the common btmtk_fw_get_filename Date: Thu, 25 Apr 2024 15:06:28 -0700 Message-Id: <9c22c80334d5a895e9d47681d57d6c7965f3c086.1714082459.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 --- drivers/bluetooth/btmtksdio.c | 6 +++--- drivers/bluetooth/btusb.c | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c index ff4868c83cd8..10bf273120d6 100644 --- a/drivers/bluetooth/btmtksdio.c +++ b/drivers/bluetooth/btmtksdio.c @@ -1117,9 +1117,9 @@ static int btmtksdio_setup(struct hci_dev *hdev) return err; } - snprintf(fwname, sizeof(fwname), - "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", - dev_id & 0xffff, (fw_version & 0xff) + 1); + btmtk_fw_get_filename(fwname, sizeof(fwname), dev_id, + fw_version); + err = mt79xx_setup(hdev, fwname); if (err < 0) return err; diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 7835170b1d66..bad6a9888dca 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3123,14 +3123,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 - 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); err = btmtk_setup_firmware_79xx(hdev, fw_bin_name, btusb_mtk_hci_wmt_sync); From patchwork Thu Apr 25 22:06:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 792445 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 E8A8317B501; Thu, 25 Apr 2024 22:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082838; cv=none; b=Tkp5W9klEucdKYnSDa08OHbAWj2F3hpvre3pcx+WhUK8fq8GXNFok62tEgXswANbRzQ93DCTtMW5kksGA9KDHD7wjDReQ7KXFV6AVWP1gzYqi7p8szVPHKExGuSRUyEiQomGylAZvmussKj7YPgSZYlD8+mcytxXGhAl+W3wsKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082838; c=relaxed/simple; bh=umhtewTB4BfLLgpEvQ+Dp1EDXrNUIEf2w2QrQYChkIg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Gp5efv3BuwreCQaIzADBbyJC1qohIOtv5o0D0+dd1xzVUpw+9aP3HWEBiG+4PGZvL8R8vOCSwg0dWMfCWk5bfDl6b/naPSh183xkDruONjD9yOQV2DV3eoNSoZE23t2WA7QUWwb4zD2SQ/NXdqxiubEjMYea1wQlEkdRQ9PkaL8= 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.43 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-f43.google.com with SMTP id 006d021491bc7-5acdbfa6e95so348872eaf.3; Thu, 25 Apr 2024 15:07:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714082836; x=1714687636; 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=NDeY9bcalP61bq7Yrea1EZ8X+JxvOuN8Y2tqOpBrKaI=; b=n4UXb6AJ0bH9PmH0511HIBBe3iHBbt9hB4YRQF1TNTGtqdygbqkdvucDZTPYNdpmTd iRNu+hRTPoivfO9k8V2rpV8jQZoe6HCeS5wPrbqNStAhmqoxVBbve4p7V4MXnyBfbAXi 3SpNjwuglsYi/gCOTHMrThDNkXVrO1HfQUfytLfYhAJ8dco+N4Bn8OvbopHjsNh9KwCD bT3BhI7+kGPTACpvo5T3nv0qVe4NbRxH6Y1nFbNE+HPZCxoL70O6IOu1v3v0mcJwrRtN 3bxNWnmuNiU59YczgWajqoY1ict2SzYMTvGh1lbdLv8ShK+HF1KP9yYCJn0DyCXw1x8e yqIQ== X-Forwarded-Encrypted: i=1; AJvYcCWISb12zHgNgIO96aLepypWdrs3OJ0mrbBMubc85Gcpvc7K8mweCBgRYgXmTZxkFqknvQiEtgfXTrTqtbhGmT4ieD/MAJi4WZ2pAKvU X-Gm-Message-State: AOJu0YxSMTvCIcw8jeHEScDEi0cDgybp/NxGIWVCygFfTggvUkVJ3VNW MhxSXIlda5IlmsE+ozfo3R25CTVGbDwqrJpO09c+dAqgjrGwnwHV X-Google-Smtp-Source: AGHT+IFX6ngfhSp/W7LZ7JR+f93Nfg4mCIdoKo+WNIvi95e0Bl/AV+9Q/L5kQJNxPBNf+UiZSKodcA== X-Received: by 2002:a05:6808:1a26:b0:3c8:4b12:107b with SMTP id bk38-20020a0568081a2600b003c84b12107bmr1180386oib.2.1714082836118; Thu, 25 Apr 2024 15:07:16 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id a9-20020aca1a09000000b003c76f98321esm1514421oia.41.2024.04.25.15.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:07:14 -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 v3 3/5] Bluetooth: btusb: mediatek: refactor the function btusb_mtk_reset Date: Thu, 25 Apr 2024 15:06:29 -0700 Message-Id: <2eeb87a4360356fbf2496bd0567f6432edf818ca.1714082459.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 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 --- 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 bad6a9888dca..a25543ff6472 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2996,28 +2996,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); @@ -3061,8 +3046,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 Thu Apr 25 22:06:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 792115 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.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 F35191802B4; Thu, 25 Apr 2024 22:07:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082840; cv=none; b=Blgys5hub4KP3ci0kYOJ/vrvAan6KOHyBo0JhShg1OM57eYCq3cAFmPACI429AonKevqe6Vv3fQqGms1AYlBsUy/n5pMQOQkFKggAoglWUmNLVBMqb5MFdIH+O6zBqxWrXBLIRExQveNhS51rgnKcYmrMCPfZiCcFZuOhWQZvgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082840; c=relaxed/simple; bh=dREXaFKoCNdQM9WiONzzfAPbqjcnDe/Cq2y9I3UGsLg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kz4yTz3gfLghtXmrWH7IzruPaQS9JWuzHB9Srwg90QusHwlcQv4NXu7GvMJ0kj7cV8v+6ZClhm6pAd8fSIig3AcbHrHVESSjc6mF61yA5LiLLgf4rIRuSHaOK9dLQLpJKhlejzzxBc8G9M0MzAXHJPrDGiNIKIm36J4hcXWdJDw= 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.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-ot1-f44.google.com with SMTP id 46e09a7af769-6eb7a4d64e8so345885a34.0; Thu, 25 Apr 2024 15:07:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714082838; x=1714687638; 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=Ghe6Ntj3w82U0VJxVyYvLCInhwuNPbaLekvh/4FENKg=; b=acM8/bXRUUJ26A1kHOI12MwKLyFWuq3jrsVXGAus0FJxfJxWYO0q/lztCIUKgtOBew 3nVbVhLWHlbi4AZlrEsPW4Fbp0PGiLR5ercFIt+/UHb8E6lVl1LKcI1u+4FFleEEBdFZ ZO90KrevAT71L1gtNuUwihxvz5Hlwx4n1zc9qa8fTefeIkaXb+N6h9NNP+hpWVyvs0mJ q25eJsVAT2yabRpksEZycT1P6FXnvmkBwhlbAspJrsvnt2aeXG6Et6bVedXNTuABJQBy NaX996cpbmKzqg41Bs1qQYGguu1rPySS5zgL7p1HVnxdAdNLZxLrShQkHKrtUzZTLnhf HBTg== X-Forwarded-Encrypted: i=1; AJvYcCWTsrVbOxotJxUrGbobH8WoLfqudK2x0NJ7oZtaNCxTu6n4PwFKU+jXTqpXdPUJrohLK6GhVNt8WZZ8iKjnNHtfNV/L3po9FETyYFae X-Gm-Message-State: AOJu0YwpUN2/CaO/fQyamdN93R1saq0XJNc33z9v2ZInZWfgn7hKM8aT 5BeHTWUGE/52IEwK/Ms8UwZ8OM1U2bbbT/zmoKUlde/b4e8eV6ns X-Google-Smtp-Source: AGHT+IEM+H4ncyT8CeCSalp8L8SuB7uAot40z6mDnViuZECMPrVG9EHcQbkeCYdfrDJwoDtUA3GvwA== X-Received: by 2002:a05:6808:189e:b0:3c8:4d54:94d with SMTP id bi30-20020a056808189e00b003c84d54094dmr1149898oib.4.1714082838135; Thu, 25 Apr 2024 15:07:18 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id a9-20020aca1a09000000b003c76f98321esm1514421oia.41.2024.04.25.15.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:07:16 -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 v3 4/5] Bluetooth: btusb: mediatek: reset the controller before downloading the fw Date: Thu, 25 Apr 2024 15:06:30 -0700 Message-Id: <13854f7ce7d4607d37dc24f39c69b3fe6d6e44f3.1714082459.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. --- drivers/bluetooth/btusb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index a25543ff6472..6cfeec2118e9 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3132,6 +3132,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); @@ -3139,9 +3146,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 Thu Apr 25 22:06:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Wang X-Patchwork-Id: 792444 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (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 9F83017F37C; Thu, 25 Apr 2024 22:07:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082842; cv=none; b=jHG3Nu+gUsKfy5i0J/6nustWlE1fyiTp4QUaRHTqOhzKH8OzfPTjY/RD9WA1L4Q1O/wlnAAMGNLHgtqx8M5L26vyb5jS5oVTfTm4AwSfw7KEGcFMeY+0JVFTHFqGG3aP2xJWQkoJr6FJJD7T2ID464DZLNvU2uZ7IwRo1f6nbY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082842; c=relaxed/simple; bh=xW5D0AJDPSU5A/+eb+O10+/Z0Uzde0cSge0o0CivJsI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=miWq1bGzmCcacb3104FutxAS6D46z0m6hwuyFYdhd4/B0ZmeoJH/EdS0e5awuRdud3u523PG08L0XML0UMCbMv70NLS1udb4+CJJBy1/ZJ+x5EqUaYP0Jrz1MtygFqT+LXzMpvjtiV+0M0WgNBwdHSwH7x7NXkl3t83ByfH/5P4= 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.177 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-f177.google.com with SMTP id 5614622812f47-3c5f7a3a127so57854b6e.0; Thu, 25 Apr 2024 15:07:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714082840; x=1714687640; 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=nB6sdF7ZT2w7lYhw/XLWMRpdlEQQxivt35Hb9FtYEA4=; b=CecIKH1ESHLdt/vwzCX85c3qXgDJ2CuUSbxllCTq3hWds7gpnenXtOOaPz5nsMQtR+ ve4TFubN7j5/xATT3gCwgzYKwa+sYE1D9Q5m7PpahuvH9em+IL+02A3Za42BtiK+Q2z7 JfUOW3IbMlN3GiVQVinx1adCBtsToL/Zdm2s3m5YIHZcXFXk+Loit7isTMgC8xBV/HKN yuU54RJLrHYdl2KRcslw7vbCQhMJg8vbBXm7ZxZ/OoK1nrIhE0PK/uXok30YUaY1xjiX wvHSEfU6tFYXNVgZhYiR8Ow8Fcxb0L+KbMrZvocWvv51AvqkV7jUwmB3Y72Ee6OPgXX9 OPzg== X-Forwarded-Encrypted: i=1; AJvYcCWq7uc3v+bFmFJ7PRUFqMEi9yljrbvS2GSqFtzA7JA4ZiUpN9mjiKZy84+oB0Rfxl3wZHhtKrCTLNJJEQzYByyG2kfyaxKv7YLwQl7y X-Gm-Message-State: AOJu0YzZsYmGGrfP7w5jBfGLA/JkEW/KCrhFPaH6cWHP5tp1HVh/fLvJ jHQYq2zADs8iHFqB95YPo3GG64MTAxndt+hkh5O1d0m+1YgzVG/fIGir91U4 X-Google-Smtp-Source: AGHT+IFTLYQOtDKukzZ2CiKwcNjWdiffw6kNmAkr9+apA39RTZI7invH/+p4ORH+TKEGqVRy/8qcZg== X-Received: by 2002:a05:6808:1985:b0:3c8:3076:f54f with SMTP id bj5-20020a056808198500b003c83076f54fmr1220361oib.1.1714082839739; Thu, 25 Apr 2024 15:07:19 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id a9-20020aca1a09000000b003c76f98321esm1514421oia.41.2024.04.25.15.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:07:18 -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 v3 5/5] Bluetooth: btusb: mediatek: add MT7922 subsystem reset Date: Thu, 25 Apr 2024 15:06:31 -0700 Message-Id: <986bef1b3b92452ca0d212ccd9b2bbe1267f320a.1714082459.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. --- 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 6cfeec2118e9..3485fefc8bad 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3002,7 +3002,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); @@ -3042,6 +3051,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.");