From nobody Wed Oct 8 14:18:32 2025 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7B8E2A8D0; Fri, 27 Jun 2025 06:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751004059; cv=none; b=foG1I7BMTYo/PlQzEBdmMfoyqpYPh/IHFpi8aNlorj/io2MZ7VpiuWGyqjrSA0GQp7i3WZ+CPTDakWNn5LGcCQPSegUFUqCQBNJKqsxw3iIu6ApVHmSODNp9NoLnMcaUozjMWkP9lS44vwhTimHqoohO4x95NKjmU62yZeB9eys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751004059; c=relaxed/simple; bh=k5NOw47UPY7eaR6HLHAHEgqZYpBfimJ7iXHlHwIZZS8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Pw0SboL5dPtozKVH6BpXcf1zlW/WojBLdqhNjckB2aYxujYawSF2+H0BFovUHpysx5FTqvL3guG4FUfYfO//FoYwaJShC+ML0wTAdikf5yFdtZQ9HDbLnqvrhF7J4d5cJMc48v7LI9Gm+WBlcGQRSZaJ8T/gafp2h+ibvq2scXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=lTROLruv; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="lTROLruv" X-UUID: 1023dd60531c11f0b33aeb1e7f16c2b6-20250627 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=Hj+8VWgZyMRjquqn0hwzE+KmeYgvePWRgg9FPuxuQU0=; b=lTROLruvzuICWuOPThlfEE+1w0KzMwOianO8yIXyk/WtO0nWGrb7m0Nm1PWzRW+AJmSWuPOGiEVccM6LdD3X4M3q3mQ1eWGDgSivdrGPnDWecY9Z5+P76T97ipxiWJuFwnDz0UnaBDq9ZwkwmAS6wLbvXGQc2Ird0WbeL9fZS8k=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.2,REQID:5df7bfd4-7d3b-4fef-998c-cfd251d30810,IP:0,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:0 X-CID-META: VersionHash:9eb4ff7,CLOUDID:d77b4282-cc21-4267-87cf-e75829fa6365,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 1023dd60531c11f0b33aeb1e7f16c2b6-20250627 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1455803116; Fri, 27 Jun 2025 14:00:44 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.39; Fri, 27 Jun 2025 14:00:41 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Fri, 27 Jun 2025 14:00:40 +0800 From: Zhangchao Zhang To: Marcel Holtmann , Matthias Brugger , Luiz Von Dentz , AngeloGioacchino Del Regno , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: Sean Wang , Jiande Lu , Deren Wu , Chris Lu , Hao Qin , linux-bluetooth , linux-kernel , linux-arm-kernel , linux-mediatek , devicetree , Zhangchao Zhang Subject: [PATCH v5 1/2] Bluetooth: mediatek: add gpio pin to reset bt Date: Fri, 27 Jun 2025 13:59:23 +0800 Message-ID: <20250627055924.7716-2-ot_zhangchao.zhang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250627055924.7716-1-ot_zhangchao.zhang@mediatek.com> References: <20250627055924.7716-1-ot_zhangchao.zhang@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Makes the platform Bluetooth to be reset by hardware pin, it provides two methods to do it for mediatek controller, and it has been tested locally many times and can reset normally. When an exception occurs, resetting Bluetooth by hardware pin is more stable than resetting Bluetooth by software. If the corresponding pin is not found in dts, bluetooth can also be reset successfully. Co-developed: Hao Qin Co-developed: Chris Lu Co-developed: Jiande Lu Signed-off-by: Zhangchao Zhang --- drivers/bluetooth/btmtk.c | 69 +++++++++++++++++++++++++++++++++++++++ drivers/bluetooth/btmtk.h | 5 +++ 2 files changed, 74 insertions(+) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 4390fd571dbd..4f677f86af1e 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include =20 #include @@ -109,6 +111,65 @@ static void btmtk_coredump_notify(struct hci_dev *hdev= , int state) } } =20 +static void btmtk_reset_by_gpio_work(struct work_struct *work) +{ + struct btmtk_reset_gpio *reset_gpio_data =3D + container_of(work, struct btmtk_reset_gpio, reset_work.work); + + gpio_direction_output(reset_gpio_data->gpio_number, 1); + kfree(reset_gpio_data); +} + +static int btmtk_reset_by_gpio(struct hci_dev *hdev) +{ + struct btmtk_data *data =3D hci_get_priv(hdev); + struct btmtk_reset_gpio *reset_gpio_data; + struct device_node *node; + int reset_gpio_number; + + node =3D of_find_compatible_node(NULL, NULL, "mediatek,usb-bluetooth"); + if (node) { + reset_gpio_number =3D of_get_named_gpio(node, "reset-gpios", 0); + if (!gpio_is_valid(reset_gpio_number)) { + bt_dev_warn(hdev, "invalid reset GPIO, use software reset"); + return -EINVAL; + } + } else { + bt_dev_warn(hdev, "no reset GPIO, use software reset"); + return -ENODEV; + } + + /* Toggle the hard reset line. The Mediatek device is going to + * yank itself off the USB and then replug. The cleanup is handled + * correctly on the way out (standard USB disconnect), and the new + * device is detected cleanly and bound to the driver again like + * it should be. + */ + + if (test_and_set_bit(BTMTK_HW_RESET_ACTIVE, &data->flags)) { + bt_dev_err(hdev, "last reset failed? Not resetting again"); + return 0; + } + + reset_gpio_data =3D kzalloc(sizeof(*reset_gpio_data), GFP_KERNEL); + if (!reset_gpio_data) + return -ENOMEM; + + INIT_DELAYED_WORK(&reset_gpio_data->reset_work, btmtk_reset_by_gpio_work); + reset_gpio_data->gpio_number =3D reset_gpio_number; + + gpio_direction_output(reset_gpio_number, 0); + + /* It requires 200ms for mtk bt chip to do reset, + * although Schedule_delayed_work is asynchronous, + * it is risk-free. If it is not completed in 200ms, + * it will only postpone the next probe, which will + * only make the probe run later. There is no other risk. + */ + schedule_delayed_work(&reset_gpio_data->reset_work, msecs_to_jiffies(200)= ); + return 0; +} + void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver, u32 fw_flavor) { @@ -364,6 +425,14 @@ void btmtk_reset_sync(struct hci_dev *hdev) struct btmtk_data *reset_work =3D hci_get_priv(hdev); int err; =20 + /* Toggle reset gpio if the platform provides one, + * if the compatibility field or pin cannot be found + * in the dts files, it can still reset bluetooth using + * software reset. + */ + err =3D btmtk_reset_by_gpio(hdev); + if (!err) + return; hci_dev_lock(hdev); =20 err =3D hci_cmd_sync_queue(hdev, reset_work->reset_sync, NULL, NULL); diff --git a/drivers/bluetooth/btmtk.h b/drivers/bluetooth/btmtk.h index 5df7c3296624..8a265ce367d1 100644 --- a/drivers/bluetooth/btmtk.h +++ b/drivers/bluetooth/btmtk.h @@ -179,6 +179,11 @@ struct btmtk_data { spinlock_t isorxlock; }; =20 +struct btmtk_reset_gpio { + struct delayed_work reset_work; + int gpio_number; +}; + typedef int (*wmt_cmd_sync_func_t)(struct hci_dev *, struct btmtk_hci_wmt_params *); =20 --=20 2.46.0 From nobody Wed Oct 8 14:18:32 2025 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 458DA2A8D0; Fri, 27 Jun 2025 06:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751004065; cv=none; b=DPLReUizpnaBkwve3LIBTczn+q/LFZbbYs5NL7ejCF/pP5iUjvmA87hw84shOFz1kZKsUj/yv4B4FfVrthCANxQBS+rBJO+v1mzwMZSuJSRZKVbV4oES4HGNxl8qXEBmqoKH4FYJzo62j9sFrtfdfrzy8rMYiRn16++Jp5djgA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751004065; c=relaxed/simple; bh=voemzvAWLfQp6jD04lENr3YCH/ivpEANy4lakY3ery4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oi81Hhj2hbOyZ9DUAtqMHVkPK7ApXIN81wfPkNrpdAnk7DH7s7yVinZlV1kFzPzyuB67X6t66QhMdmVyJuof9l7TxJXoCkR2gXup2POyQBNZZbRoamSVeDw4ko97kR9aIcFmVAW7MJM13tem8FHYCCb+ON3xY5BJ1ucuMHCchK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=RM4ZEzkV; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="RM4ZEzkV" X-UUID: 18c4b61a531c11f0b910cdf5d4d8066a-20250627 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=14pd4QpWllGl8PV/mXJ+LzKhlaqqBqybi64T3zF9M/I=; b=RM4ZEzkVjmykKbHFOUa1izmJsF1SgZAKYvND2Kk6zIX2AwbwcWLvfUPoaoylCDkvDwGFs49OzBubX1t6+3787vo+ABGxtV74IPEn3N2shnLHB7vKCpqfVI7APJvQQVM2zpxo+f83lV+GXhOwFjemse50uUNiEZLFVeCd4B77Db8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.2,REQID:a1e19b59-e5ff-4ab9-a37c-79fb58794cc9,IP:0,UR L:25,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:25 X-CID-META: VersionHash:9eb4ff7,CLOUDID:42f09f73-15a7-4ae6-ad4b-94c27b45c266,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3 ,IP:nil,URL:11|97|99|83|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OS I:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 18c4b61a531c11f0b910cdf5d4d8066a-20250627 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2030193749; Fri, 27 Jun 2025 14:00:58 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.39; Fri, 27 Jun 2025 14:00:56 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Fri, 27 Jun 2025 14:00:55 +0800 From: Zhangchao Zhang To: Marcel Holtmann , Matthias Brugger , Luiz Von Dentz , AngeloGioacchino Del Regno , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: Sean Wang , Jiande Lu , Deren Wu , Chris Lu , Hao Qin , linux-bluetooth , linux-kernel , linux-arm-kernel , linux-mediatek , devicetree , Zhangchao Zhang Subject: [PATCH v5 2/2] dt-bindings: net: mediatek,mt7925-bluetooth.yaml Date: Fri, 27 Jun 2025 13:59:24 +0800 Message-ID: <20250627055924.7716-3-ot_zhangchao.zhang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250627055924.7716-1-ot_zhangchao.zhang@mediatek.com> References: <20250627055924.7716-1-ot_zhangchao.zhang@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add hardware pins and compatible strings. As a binding file for the MTK Bluetooth driver code, it provides a set of compatible fields and hardware pins for the driver to use. Signed-off-by: Zhangchao Zhang --- .../bluetooth/mediatek,mt7925-bluetooth.yaml | 57 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/bluetooth/mediate= k,mt7925-bluetooth.yaml diff --git a/Documentation/devicetree/bindings/net/bluetooth/mediatek,mt792= 5-bluetooth.yaml b/Documentation/devicetree/bindings/net/bluetooth/mediatek= ,mt7925-bluetooth.yaml new file mode 100644 index 000000000000..230c24ada3b4 --- /dev/null +++ b/Documentation/devicetree/bindings/net/bluetooth/mediatek,mt7925-bluet= ooth.yaml @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/bluetooth/mediatek,mt7925-bluetooth= .yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Bluetooth mediatek add gpio pin to reset bt + +maintainers: + - Sean Wang + +description: + 7925 uses the USB bus to communicate with the host. + Two methods are used to reset Bluetooth. + Provide hardware pin, when an exception occurs, + resetting Bluetooth by hardware pin is more stable + than resetting Bluetooth by software. + If the corresponding pin is not found in dts, + bluetooth can also be reset successfully. + +allOf: + - $ref: bluetooth-controller.yaml# + +properties: + compatible: + enum: + - mediatek,usb-bluetooth + + gpio-controller: + description: + Marks the device node as s GPIO controller. + + "#gpio-cells": + const: 2 + + reset-gpios: + maxItems: 1 + + description: + An active-high reset pin for the Bluetooth core; on typical M.2 + key E modules this is the W_DISABLE2# pin. + +required: + - compatible + - "#gpio-cells" + - reset-gpios + +unevaluatedProperties: false +examples: + - | + #include + + bluetooth { + compatible =3D "mediatek,usb-bluetooth"; + #gpio-cells =3D <2>; + reset-gpios =3D <&pio 248 GPIO_ACTIVE_HIGH>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 5959513a7359..d104a5821f20 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14676,6 +14676,7 @@ L: linux-mediatek@lists.infradead.org (moderated fo= r non-subscribers) S: Maintained F: Documentation/devicetree/bindings/net/bluetooth/mediatek,bluetooth.txt F: Documentation/devicetree/bindings/net/bluetooth/mediatek,mt7921s-blueto= oth.yaml +F: Documentation/devicetree/bindings/net/bluetooth/mediatek,mt7925-bluetoo= th.yaml F: drivers/bluetooth/btmtkuart.c =20 MEDIATEK BOARD LEVEL SHUTDOWN DRIVERS --=20 2.46.0