[PATCH v2 1/4] Bluetooth: hci_serdev: Track whether the serial port is open
From: Michael McAllister
Date: Sat Nov 14 2026 - 13:41:34 EST
HCI_UART_PROTO_READY is cleared before protocol close during unregister,
even though the serial port stays open. QCA needs to distinguish that
case from a port left closed by a failed setup reopen before sending
its power-off pulse.
Track the port state in the transport and QCA open/close helpers. Keep
the existing PROTO_READY handling for setup failures and use the actual
open state when closing the port during unregister.
Signed-off-by: Michael McAllister <me@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/bluetooth/hci_qca.c | 4 ++--
drivers/bluetooth/hci_serdev.c | 34 ++++++++++++++++++++++++++++------
drivers/bluetooth/hci_uart.h | 3 +++
3 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index d693e2842..28e84fc24 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -1762,14 +1762,14 @@ static void qca_port_close(struct hci_uart *hu)
* hci_uart_close() or hci_uart_unregister_device().
*/
if (test_and_clear_bit(HCI_UART_PROTO_READY, &hu->flags))
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
}
static int qca_port_open(struct hci_uart *hu)
{
int ret;
- ret = serdev_device_open(hu->serdev);
+ ret = hci_uart_serdev_open(hu);
if (!ret)
set_bit(HCI_UART_PROTO_READY, &hu->flags);
diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
index d2c48df34..3d10d8d75 100644
--- a/drivers/bluetooth/hci_serdev.c
+++ b/drivers/bluetooth/hci_serdev.c
@@ -21,6 +21,29 @@
#include "hci_uart.h"
+int hci_uart_serdev_open(struct hci_uart *hu)
+{
+ int err;
+
+ if (hu->serdev_open)
+ return 0;
+
+ err = serdev_device_open(hu->serdev);
+ if (!err)
+ hu->serdev_open = true;
+
+ return err;
+}
+
+void hci_uart_serdev_close(struct hci_uart *hu)
+{
+ if (!hu->serdev_open)
+ return;
+
+ hu->serdev_open = false;
+ serdev_device_close(hu->serdev);
+}
+
static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
{
struct hci_dev *hdev = hu->hdev;
@@ -125,7 +148,7 @@ static int hci_uart_open(struct hci_dev *hdev)
* BT OFF. Upon next BT ON UART port should be opened.
*/
if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
- err = serdev_device_open(hu->serdev);
+ err = hci_uart_serdev_open(hu);
if (err)
return err;
set_bit(HCI_UART_PROTO_READY, &hu->flags);
@@ -156,7 +179,7 @@ static int hci_uart_close(struct hci_dev *hdev)
*/
if (hci_test_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP)) {
clear_bit(HCI_UART_PROTO_READY, &hu->flags);
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
}
return 0;
@@ -316,7 +339,7 @@ int hci_uart_register_device_priv(struct hci_uart *hu,
if (percpu_init_rwsem(&hu->proto_lock))
return -ENOMEM;
- err = serdev_device_open(hu->serdev);
+ err = hci_uart_serdev_open(hu);
if (err)
goto err_rwsem;
@@ -387,7 +410,7 @@ int hci_uart_register_device_priv(struct hci_uart *hu,
clear_bit(HCI_UART_PROTO_READY, &hu->flags);
p->close(hu);
err_open:
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
err_rwsem:
percpu_free_rwsem(&hu->proto_lock);
return err;
@@ -440,8 +463,7 @@ void hci_uart_unregister_device(struct hci_uart *hu)
*/
hu->proto->close(hu);
- if (proto_ready)
- serdev_device_close(hu->serdev);
+ hci_uart_serdev_close(hu);
hci_free_dev(hdev);
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h
index 7fbe8dffa..2f8e346f3 100644
--- a/drivers/bluetooth/hci_uart.h
+++ b/drivers/bluetooth/hci_uart.h
@@ -66,6 +66,7 @@ struct hci_uart_proto {
struct hci_uart {
struct tty_struct *tty;
struct serdev_device *serdev;
+ bool serdev_open;
struct hci_dev *hdev;
unsigned long flags;
unsigned long hdev_flags;
@@ -112,6 +113,8 @@ static inline int hci_uart_register_device(struct hci_uart *hu,
}
void hci_uart_unregister_device(struct hci_uart *hu);
+int hci_uart_serdev_open(struct hci_uart *hu);
+void hci_uart_serdev_close(struct hci_uart *hu);
int hci_uart_tx_wakeup(struct hci_uart *hu);
int hci_uart_wait_until_sent(struct hci_uart *hu);
--
2.39.5