From nobody Tue Oct 7 18:24:29 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 EE049288A8; Tue, 8 Jul 2025 06:02:29 +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=1751954553; cv=none; b=BIK5tjfhHRTAbCAdqJCg/8XMCxZ9F7sqnrBwIdUB4Kqv8o84PRkd+OXwmqcj/jH6VRrHWt8xApBr5gG1GI/IbpxCAa7d8gCRBtcZHm0I+F30pcnEgnLoFkyZ0Lz1cWWOl/reHz2V7oeWNTXkkOz6W1jYwAAbrTWP/rM22TX1D/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751954553; c=relaxed/simple; bh=jZTV6oldO8RbAoJOIa7zaYMA6xqHMl8KU8ZPSA1Jnno=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mNANowW1nlLQQo5mBZT/ThD2DMKQspTu+mPpixpdeqE/3uDSD59ZqEZUE2xiUkpwu7q1AVbBAd/Whr+njDcx6uo9mkEo4sAfbATPba4KWQjj5zKJ9PpsnwvRrvZIUqOhkL9qKQ7dPhkCt/sJJf/N6mkObyldmM77hIIvCrbPmVw= 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=CwSo/AWl; 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="CwSo/AWl" X-UUID: 1e268c205bc111f0b33aeb1e7f16c2b6-20250708 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=nXbKKktsKUtibdmB3N2JJXL6syUineT/8bO4Pbx50Lo=; b=CwSo/AWlPgfo46IyuZbK/XAujGmK0mw6Pcnrcm4arFA6KoA8y69wG/LtBekUwua9aaucMHLbCllTu2ZQtvwTAfCitRk1gV8hXPKt3A63wPyliAOnWF6mPrL6USQBCbthzwPxa6T9o6kWxDvaURAZTNFevzOiWBJeWfaOVOJO0gI=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.2,REQID:0e0280b5-43c7-4a44-9220-906b74d8983b,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:8381fd73-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: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: 1e268c205bc111f0b33aeb1e7f16c2b6-20250708 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1633315690; Tue, 08 Jul 2025 14:02:24 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.39; Tue, 8 Jul 2025 14:02:22 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Tue, 8 Jul 2025 14:02:21 +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 , Wallace Yu , linux-bluetooth , linux-kernel , linux-arm-kernel , linux-mediatek , devicetree , Zhangchao Zhang Subject: [PATCH v6 1/1] Bluetooth: mediatek: add gpio pin to reset bt Date: Tue, 8 Jul 2025 14:01:48 +0800 Message-ID: <20250708060150.27375-2-ot_zhangchao.zhang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250708060150.27375-1-ot_zhangchao.zhang@mediatek.com> References: <20250708060150.27375-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..cdb90143be61 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,mt7925-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 Tue Oct 7 18:24:29 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 27BB3219A97; Tue, 8 Jul 2025 06:02:41 +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=1751954564; cv=none; b=Md+SzceIQRB5qPuTFPWZlH0iZSDarkiVWNfKnWjZGSGaiF5g0Y9l00BNI745IfPe0u21XJBKJcNCLjU3iGLuF/gFkDI3Q1NyT+ppdEnKFfrA/A7RraAcSWayFeX4ivEqlar68vJKCyNfji1EGlnXtqlsmXho/TawAARFRFdbmhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751954564; c=relaxed/simple; bh=sGctqi73E2wqiZFaYszxlUL9QxQ3AG70NtaCwWg07TA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pQEXH5xZSxfckieak3GoNF7i/hxOVvIXqKbgrPzjilY2l0/o6x16FzxMfH9+gz36f6FY0rdY8hHIDooGIZXZF0aPdkD0rsA+sthQBQIAoAmfzqrrkuLPFsTe10/TKYGSNjA8UtybTF0e/fKXC3SjjQknHBFEiXKgV/JQdHAoxBo= 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=dkpPTDgY; 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="dkpPTDgY" X-UUID: 2170f9c45bc111f0b1510d84776b8c0b-20250708 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=9PKHQ/mFxNZbAIae9wAVHTQfR/S1prWOZmagk8WbpsI=; b=dkpPTDgYztjfs7i8x6X4Csx1CX457znZun0OwPOS4JmS9BjOp1RUXHfrlCsNlTUqEBvznQ80LwK5Pnhjw+W1zsAhaDzSH1HSgvXZVxGuaNQZkIPN4c6TXbquRg1Z9pf+v4pBWx+gKHMc2juhSKl4BePofTQmN7/4/KRtQn8M8XY=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.2,REQID:789c7101-5088-4cc5-9ad0-2399d40c317d,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:0c07a082-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:11|97|99|83|106|1,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 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 2170f9c45bc111f0b1510d84776b8c0b-20250708 Received: from mtkmbs09n1.mediatek.inc [(172.21.101.35)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 268198922; Tue, 08 Jul 2025 14:02:29 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.39; Tue, 8 Jul 2025 14:02:28 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Tue, 8 Jul 2025 14:02:27 +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 , Wallace Yu , linux-bluetooth , linux-kernel , linux-arm-kernel , linux-mediatek , devicetree , Zhangchao Zhang Subject: [PATCH v6] dt-bindings: net: mediatek,mt7925-bluetooth.yaml Date: Tue, 8 Jul 2025 14:01:49 +0800 Message-ID: <20250708060150.27375-3-ot_zhangchao.zhang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250708060150.27375-1-ot_zhangchao.zhang@mediatek.com> References: <20250708060150.27375-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" Reset BT via BT_KILL_1V2_L hardware pin. On the M.2 standard hardware pin interface, the MTK chip has a pin called BT_KILL_1V2_L or W_DISABLE#2, it uses function-level device reset (FLDR) to reset Bluetooth. When it is pulled low, it can external shut down the BT function, it is defined as 5 on the MT7925 chip, and is defined as 248 on the device tree pio controller. Signed-off-by: Zhangchao Zhang --- .../bluetooth/mediatek,mt7925-bluetooth.yaml | 55 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 56 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..636b8b3d6a14 --- /dev/null +++ b/Documentation/devicetree/bindings/net/bluetooth/mediatek,mt7925-bluet= ooth.yaml @@ -0,0 +1,55 @@ +# 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 use BT_KILL_1V2_L hardware pin to reset BT + +maintainers: + - Sean Wang + +description: + MT7925 chip uses the USB bus to communicate with the host. + Two methods are used to reset Bluetooth. It 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,mt7925-bluetooth + + "#gpio-cells": + const: 2 + + reset-gpios: + maxItems: 1 + description: + Default high level, this pin can external shut down the BT function + when this pin is pull low, at the same time, USB interface will be a= lso + disabled. When this function is not required, external pull high is = not + required. After 200ms, it is pulled high to 3.3v and the next probe = is + performed. 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,mt7925-bluetooth"; + #gpio-cells =3D <2>; + reset-gpios =3D <&pio 248 GPIO_ACTIVE_LOW>; + }; 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