[PATCH v3 3/5] Bluetooth: qca: Power off after unregistering the HCI device
From: Michael McAllister
Date: Mon Nov 16 2026 - 11:26:56 EST
qca_serdev_remove() powers off while HCI setup and UART writes can still
be running. Leave power-off to qca_close(), after HCI unregistration and
write-work cancellation, while the serial transport is still available.
Check the actual port state before sending the power-off pulse, since
PROTO_READY is already clear during protocol cleanup. Start serdev
controllers in QCA_BT_OFF so registration failure does not send a pulse
before HCI allocation or power-on.
Flush controller TX after stopping UART work, before protocol and port
close, so previously accepted bytes are discarded rather than drained.
Signed-off-by: Michael McAllister <me@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/bluetooth/hci_qca.c | 24 ++----------------------
drivers/bluetooth/hci_serdev.c | 3 +++
2 files changed, 5 insertions(+), 22 deletions(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 28e84fc24..ddbeb0787 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -620,6 +620,7 @@ static int qca_open(struct hci_uart *hu)
hu->priv = qca;
if (hu->serdev) {
+ set_bit(QCA_BT_OFF, &qca->flags);
qcadev = serdev_device_get_drvdata(hu->serdev);
switch (qcadev->btsoc_type) {
@@ -2285,11 +2286,7 @@ static void qca_power_off(struct hci_uart *hu)
case QCA_WCN3990:
case QCA_WCN3991:
case QCA_WCN3998:
- /* Both of these write to the serial port which may have
- * already been closed by hci_uart_close(), which closes
- * the port if HCI_QUIRK_NON_PERSISTENT_SETUP is set.
- */
- if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
+ if (hu->serdev_open) {
host_set_baudrate(hu, 2400);
qca_send_power_pulse(hu, false);
}
@@ -2618,23 +2615,6 @@ static int qca_serdev_probe(struct serdev_device *serdev)
static void qca_serdev_remove(struct serdev_device *serdev)
{
struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
- struct qca_power *power = qcadev->bt_power;
-
- switch (qcadev->btsoc_type) {
- case QCA_WCN3988:
- case QCA_WCN3990:
- case QCA_WCN3991:
- case QCA_WCN3998:
- case QCA_WCN6750:
- case QCA_QCA2066:
- case QCA_WCN6855:
- case QCA_WCN7850:
- if (power->vregs_on)
- qca_power_off(&qcadev->serdev_hu);
- break;
- default:
- break;
- }
hci_uart_unregister_device(&qcadev->serdev_hu);
}
diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
index f86d417b8..e279a7d61 100644
--- a/drivers/bluetooth/hci_serdev.c
+++ b/drivers/bluetooth/hci_serdev.c
@@ -464,6 +464,9 @@ void hci_uart_unregister_device(struct hci_uart *hu)
hu->tx_skb = NULL;
}
+ if (hu->serdev_open)
+ serdev_device_write_flush(hu->serdev);
+
/* Close the protocol before freeing hdev (intrinsically purges queues).
* Some protocol close handlers (e.g. qca_close) may still access the
* serdev device, so keep the serdev port open until this completes.
--
2.39.5