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: 13643970 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 4771AC10F1A for ; Thu, 25 Apr 2024 22:07:22 +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=lStmgiqTJIXMZ0FpbHnHRZG5n3g0ZAPBxl1jPCO//LA=; b=2yASQfZpfFQwvHqgL9LnNfPTC8 l4qB0y3msQgBHLuWusDrBzG1RPcj0RjkX1ae92x8NxYW/thNCR3dXrXa6td05mU8wcoHqLdf16dPK j6SUoaSERBeop9e92oyZ6xeAoHLlBwYP4zqc3+GCgVPtuNTCQyTzyJogP1h1lM25IdkshjTtlC/rf ZH94yFEx512t5T5N9lFnDfL1+3ESdkOTqZG+iA6lyQZ9szzsv8A8ud8ivefwhQiksRQ/VTSQJFi0y Rz32sYIXSHKNjZszI9t0AuUXZTBmz15bb0eDR6vO+U75KQcAY8qBJCQn614VPRgRmaAhS6hjVIg1X ylSluleA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FR-0000000APIA-3Zbm; Thu, 25 Apr 2024 22:07:21 +0000 Received: from mail-oi1-f173.google.com ([209.85.167.173]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FM-0000000APD5-3ML5 for linux-mediatek@lists.infradead.org; Thu, 25 Apr 2024 22:07:18 +0000 Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3c73b33383aso139534b6e.3 for ; 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=fewz9Ucl2aXHw7LrVMPTT3wR35kHW6zReO7ygjzyqMQ9D5O1wRZtDQbMXDR+CiYIrR bID27H8lrYOlOP9MtrooLVA/lq1Xo65mzsxfwDm7RVkKuuVpHjvJVRuL4EE+B0pNA6F4 ZFLE9kO1KBW0b1NkFQMihpXujhYL9EmfqnPtAjAuNOldzOnzcjJFT3+Ti+dcFnciHgQ8 3M5TRhYlFNLSrObTlYEXsH0D/sQhfNIJ5lVjRJkjejNVCOyyHz9m+n4xkwXpmlbZ8Aow lpWVz+biLjrStzjJVG+MnTrgBnWBrnKAGNj6A3tIWnp7uSZ7nSXq+5Lm7897KiPATUCt vGRg== X-Forwarded-Encrypted: i=1; AJvYcCXZPk8LjmRKwLZEkQ5hoztDrUlUKKX2mdZfvltnRGBXxbQpOpKzAPXrktjm8wtiFdoFijTfo3QY0EamMm8fbeb8LxBmfKObo00cq6nKxjq/bEgG X-Gm-Message-State: AOJu0YyuBnQqNGiHUsFMMQfbTBKvxf7I84cm1sBpBHZKEQ+m+7ah1U8d sCeROnIEJk4YNcyy0CnmCA1aFezZnIydWpTl1s75dks9L4b0gGTsaqIuCFMQ 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 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240425_150716_885988_6255C1BC X-CRM114-Status: GOOD ( 10.26 ) 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 --- 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: 13643968 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 50056C10F15 for ; Thu, 25 Apr 2024 22:07:22 +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=aOSUTMsrzGUh+EZaDgRrzzwhmdgrzIn+vCN9MSjqzbg=; b=KsDY5Bj8KUhRcWx36GedVHkTwt 2BJtd5Ojbrr8Jlj8eWPJ/aykzBQk+XBSaYZ2IBkhkO9O4g18qRMC6QxhK/JOce9V56LsNQsZJHCzB 37YWhOz+yMI8ee/ygaKLF1CSTXMbG4dfRE0jsxWx1M8ncN6Q+xEhvTkyrE3Y8xIuP6WOVI96jKGCU T1k4aVUl12TQ5rQCYvE7FTlegotjmjMdBkfa5lfjwGoqMiiw8fh0fzc8/cU0VXs+iMU6UkL9qr24n i3LFD2wOboSnxf8q0srkyMaooiDyuF7ik028iThrWuAyx0a8YNTAhHh3ePl1WO49SZhjjMmioMqBA pIgsNmqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FP-0000000APG1-1DVZ; Thu, 25 Apr 2024 22:07:19 +0000 Received: from mail-ot1-f46.google.com ([209.85.210.46]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FM-0000000APDX-1UPX for linux-mediatek@lists.infradead.org; Thu, 25 Apr 2024 22:07:17 +0000 Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6eba841d83cso341012a34.2 for ; 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=D24H884kgnG/9LpoxYXDcrDQ+mRK7CxKVEVjJNfhN5JT+BsY6EqELe83s7bsJYxJRb SnjRfqg8yRNBNYj4K8qtlN+yYEciKEazzDw7IQVqkD8I8mfZqeuwvkut6j31FcPNpDKj k1YBFAbXe1b8qZIauXlLS3sAEv19rnaduI1ZhZLi0bA1NuTqOF2IqgG4Re38MXqXv8iy hyrdXWvfpV+hw7OooZ+3gtkpOyWyIbTICn+tzDQ3jAEfN4iaG2uVIPiVrFk4Hv5MMXgl UIA3kjvP/DQDOxQ1OCy5Vjqsmyzvui23OgTJik0z1tHycR7ttO8xiJN4xv4D1AFM+DeG qq7A== X-Forwarded-Encrypted: i=1; AJvYcCVv6gBXmbPXWJYEi7wYQtEyV6YrO5gMaF/6wTtVOIkk6j28OMRJBbj7lZbwyS6pmkPOYQ1hI65A52kJ3VLgJzBwZv3vTc+iwlFPYu3/vZ6+2679 X-Gm-Message-State: AOJu0YwJusAdUq1llzFJI1vYKH6Rdkz71YBhhDfPynSkKX/dRRx7vETy TFXVSeEj6QAg907v4ut7tdHeWfTwpzfm7FvQY3oVB2h9JtlGmVbK 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: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240425_150716_539845_AE790109 X-CRM114-Status: GOOD ( 11.20 ) 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 --- 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: 13643969 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 EBF29C19F4F for ; Thu, 25 Apr 2024 22:07:22 +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=NDeY9bcalP61bq7Yrea1EZ8X+JxvOuN8Y2tqOpBrKaI=; b=LpjAZHHBk2zFg5QBpOjO360UAq VIuIWpmL6CI3HAdpCJ9hYK7UmYSj0A1NKncxYRQ3RSXBLhuQRtGQN/+tyAqYWvImDbYKH4+q5juYI PK5g0PxTLVpOa4rsNZc5bLD/dFDH/xaKPDNHR1Zm4W3REaSrsAqwflXX6dk4Gavec3buh5YPeKtUA Lb8UucPVkeHMYmAN523KHufwh4krM/B+kfBBD5CKkyjFtQjwV8PfndpAqj6s6c8C6Uz2cEsizlkjW ltVw4kE+iXWoi2h/Z3xjs+xTIvpkAu3+QksRAsKWLHJW80ggRPy8rHI995ZuSzGrdO+5os98jrDrB tQKYOHZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FS-0000000APIT-1uQt; Thu, 25 Apr 2024 22:07:22 +0000 Received: from mail-oo1-f41.google.com ([209.85.161.41]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FN-0000000APEE-2kwJ for linux-mediatek@lists.infradead.org; Thu, 25 Apr 2024 22:07:18 +0000 Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5acf5723325so406750eaf.0 for ; Thu, 25 Apr 2024 15:07:17 -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=HPqnIJhzlm+BRjwIv3FkT64dlgT7jnRNOelRLuBLts6kvgk0b6ncmRGKQqEWeabm8L RMP1PFysTRB+2TifBv6dMZh6EQncqC9ovR5L3Ml4CSgQmN1bqRBq7B97LEB4QQGwCyj6 sZcpaWipDV8kw9F80PnJweiSm2I4S48+0w6sxc/hgzptQ8baBrtLBRYiHj14vHbH7rnb hRH1+GwtxSsJZKJRUUAbdwu15dviKoAW+GFpMwtDoO+S/xPTW2wYhe1s/BK5o/6KdCtw Rz7XnEfxurzWSFCuoL31W4VYVggUross3uzL1Z0XGkJf4CPNYkZhVP+kEQ1/R/2hNz5O 5guA== X-Forwarded-Encrypted: i=1; AJvYcCVNlftv0BEeoo8+9JYJUIIDf45QzWZz5oj7kTxv2NjuOZYOyXvH49f12PBG3m9hmuAVcgfYUZQ1bRQ67TJgK7C1FbiIT3oUasV81Ka7VS8VvY9r X-Gm-Message-State: AOJu0YxKfLzeO5phIOuKefdgIYEkKNrsCvzuUNSEJRKUzjw/oY8DOVRg agZzxLUcsx4c30pB4eHiogGRw8suNLDn3g6EAsyao3AGEcWkgB9h 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: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240425_150717_728545_D66E28EF X-CRM114-Status: GOOD ( 12.40 ) 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 --- 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: 13643972 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 558A4C4345F for ; Thu, 25 Apr 2024 22:07:26 +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=Ghe6Ntj3w82U0VJxVyYvLCInhwuNPbaLekvh/4FENKg=; b=lyG74N3TfzmzJ1uWPs9+cX1J5R 6FEU6EyT9IGGnziiHxLmT2aYfD3BWgMhSJTAAfB34Nr/E+XxQhq8c2GJcy6y2TXkCQCGb/8M8Z3Rc LcWP8PtqwaZPV/m+KEYL5ZRt3oqFmA1eGwyXUgKSWhtSl6GRIEk2R5J9fyuDKYEjMZdi6Z2jf2vm/ efin8UbePw3VEI03Py/tnLiMiMHC+5CGEqmjc0OaNRse1kh1UERf274QiXxAB2LDq8HQc9KPEjEov kSpng3gL8UFU1A/m6adL4gp3GUwa+Mi/TJ3fk+00afebGexO442kL4OY0bcbdwGLiCx7oi02t7SyG rmFl4AlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FW-0000000APKI-0DGM; Thu, 25 Apr 2024 22:07:26 +0000 Received: from mail-ot1-f41.google.com ([209.85.210.41]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FP-0000000APFj-22Eg for linux-mediatek@lists.infradead.org; Thu, 25 Apr 2024 22:07:22 +0000 Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-6ea0a6856d7so237617a34.1 for ; 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=oXG1mAMnwXi48+0SpuWOO/K+aW56MRANRxY/R/djuwSuHbXuHINcCjhIK/W1RiUtBM 58Kozw6DOL8tpe772M28k13YRX3YKBAqZ+0b0u7HEQoU/HtHClqHZBz0Ce93sB+qCin/ veM5hJ0tpLoEJElUAv0+7zZbPknm6DQ7Nn0qNEoYwPkAQd+P5fMKzsIAP6yEaUzHRWd0 /ZIXfc+GmhC+rnLntBUPmx9Wkmjt2LeZBaZ26/HQzHXYgQm+jpE2nRThO9zzL/n5Dilx PzzhYoK2UEaxLTlqaI810mnzx/i3fERAlS/4HiZbgy1JIg3gVFOLt5Tg6qsCd6cG7a3g c+kQ== X-Forwarded-Encrypted: i=1; AJvYcCW+aIo03z2nOpKGnLk4yTSKMJbFpYbMij865nsGmRS2XQpIRNvXVyPBqIKhTa7de1flqhpZMC/ZjSWk3KJQJpOFqazXJVW30mf82Lq5YkyMQxpA X-Gm-Message-State: AOJu0Yyy/Nf8xLLCCkEY2d4w/AD4m6yNqkqkvL0pEkPDFhqAiC8karSR +9Pg7HxPSVYYS0ucwyGfMQJCh1oYoAXln6zBpOetFequVw4FTWzWHTWtPP4L 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: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240425_150719_573673_22CC2EBE X-CRM114-Status: GOOD ( 13.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: 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: 13643971 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 B6B43C25B10 for ; Thu, 25 Apr 2024 22:07:26 +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=nB6sdF7ZT2w7lYhw/XLWMRpdlEQQxivt35Hb9FtYEA4=; b=jsTDOf81ZVcKXzMU97KytVZNLV 4K7RID8dk1J1gyFNCOnORS2N3x83Ur7gjHQLsYr+6OiC5l2ijfzCoOPXqB4mQ0J2ylozDrKK0YFWW AYqiFl39TfhnPPyKRwoBpY5oBM4lkpOO3xE/t8bXiI7aqyuwX8TuKEoZgdGWFHvUkN30mX/69Q9I/ pgcvitONpfrJIQTGF4dL7r/5GyZxz30V4++ihnwdENtIOt0CT4ojAIKBwm8+ZyWAiCfNktr4rgJ75 haX5OC1s/cjPcCUVv+1DhmZfOyR7LCydrNhbwkawOEpWR+9jJfUJvYV2IKHu5yib1CWyW1fKMoU5N iZosCo2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FW-0000000APKe-1iXQ; Thu, 25 Apr 2024 22:07:26 +0000 Received: from mail-oi1-f175.google.com ([209.85.167.175]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07FU-0000000APHN-0Ar5 for linux-mediatek@lists.infradead.org; Thu, 25 Apr 2024 22:07:25 +0000 Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3c73b33383aso139557b6e.3 for ; 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=QC0ge0VG9BdTe90bkd0EPaYMSrRewtxfSTXn8xT22iAOuRyzEYrf0LhE3HGE23KO7L EBomEvFfF1EaW+jkCAssCLPDLuCWQIxv9rQmeG7Yhe2YoDOQbc4/0CrBFbROc5lDcCsE gibhMYbKbqdeDzrKXR0rM/K4ZZBsnZBSL55KLuEQM+Mvx9fF7/QI4S8lvMJzO4/ssZU5 GqfU+DeTIQ1YU8AtyPCkT0+UaGjhxSgZbUcSHEbfPlsjQdkWmwTghftKwVzEek1mNJRU 5cvJn/Bq9J1A9a7wnP1m8h2xMv05wiGiEzSGFKeG612qU87tNkOm742UOOSRSBTA8dM7 nCAg== X-Forwarded-Encrypted: i=1; AJvYcCVxSOwhR4WHaTDkXyQEyTpUh4g03SHVGcp2Micm7DdhnDzfprZhevAL2hbCWQX/JdjNo0Puu2I2qzBoX8QkGQAa3IjKSU2JOhgUpoVnHotK1UPT X-Gm-Message-State: AOJu0YzsnlFtGvL8r9TOTUD6EVImdhHDtmjFU3aCM3c/4mPOdbEyoGGU o0G5MUGbSKFAghUxPkcqTKRXL417zCnEgnVG3vzGc5omlKbBWEI+ 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: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240425_150724_110059_B7DDD05F X-CRM114-Status: GOOD ( 11.34 ) 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. --- 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.");