diff mbox series

Bluetooth: btusb: Fix the autosuspend enable and disable

Message ID 20210203080245.5168-1-hui.wang@canonical.com
State New
Headers show
Series Bluetooth: btusb: Fix the autosuspend enable and disable | expand

Commit Message

Hui Wang Feb. 3, 2021, 8:02 a.m. UTC
I tried to disable the autosuspend on btusb through the module
parameter enable_autosuspend, this parameter is set to N, but the usb
bluetooth device is still runtime suspended.
$ cat /sys/module/btusb/parameters/enable_autosuspend
N
$ cat /sys/bus/usb/devices/3-10/power/runtime_status
suspended
$ cat /sys/bus/usb/devices/3-10/power/runtime_suspended_time
65187

We already set ".supports_autosuspend = 1" in the usb_driver, this
device will be set autosuspend enabled by usb core, we don't need
to call usb_enable_autosuspend() in the btusb_probe(). Instead if
users set the parameter enable_autosuspend to N, we need to call
usb_disable_autosuspend() in the btusb_probe(). After this change
and set the parameter to N, we could see the device is not runtime
suspended anymore.
$ cat /sys/module/btusb/parameters/enable_autosuspend
N
$ cat /sys/bus/usb/devices/3-10/power/runtime_status
active
$ cat /sys/bus/usb/devices/3-10/power/runtime_suspended_time
0

And if we disable the autosuspend in the btusb_probe(), we need to
enable the autosuspend in the disconnect(), this could guarantee
that the device could be runtime suspended after we rmmod the btusb.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
 drivers/bluetooth/btusb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Marcel Holtmann Feb. 3, 2021, 1:34 p.m. UTC | #1
Hi Hui,

> I tried to disable the autosuspend on btusb through the module
> parameter enable_autosuspend, this parameter is set to N, but the usb
> bluetooth device is still runtime suspended.
> $ cat /sys/module/btusb/parameters/enable_autosuspend
> N
> $ cat /sys/bus/usb/devices/3-10/power/runtime_status
> suspended
> $ cat /sys/bus/usb/devices/3-10/power/runtime_suspended_time
> 65187
> 
> We already set ".supports_autosuspend = 1" in the usb_driver, this
> device will be set autosuspend enabled by usb core, we don't need
> to call usb_enable_autosuspend() in the btusb_probe(). Instead if
> users set the parameter enable_autosuspend to N, we need to call
> usb_disable_autosuspend() in the btusb_probe(). After this change
> and set the parameter to N, we could see the device is not runtime
> suspended anymore.
> $ cat /sys/module/btusb/parameters/enable_autosuspend
> N
> $ cat /sys/bus/usb/devices/3-10/power/runtime_status
> active
> $ cat /sys/bus/usb/devices/3-10/power/runtime_suspended_time
> 0
> 
> And if we disable the autosuspend in the btusb_probe(), we need to
> enable the autosuspend in the disconnect(), this could guarantee
> that the device could be runtime suspended after we rmmod the btusb.
> 
> Signed-off-by: Hui Wang <hui.wang@canonical.com>
> ---
> drivers/bluetooth/btusb.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel
diff mbox series

Patch

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index b14102fba601..e019a6d6e934 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4639,8 +4639,8 @@  static int btusb_probe(struct usb_interface *intf,
 			data->diag = NULL;
 	}
 
-	if (enable_autosuspend)
-		usb_enable_autosuspend(data->udev);
+	if (!enable_autosuspend)
+		usb_disable_autosuspend(data->udev);
 
 	err = hci_register_dev(hdev);
 	if (err < 0)
@@ -4700,6 +4700,9 @@  static void btusb_disconnect(struct usb_interface *intf)
 		gpiod_put(data->reset_gpio);
 
 	hci_free_dev(hdev);
+
+	if (!enable_autosuspend)
+		usb_enable_autosuspend(data->udev);
 }
 
 #ifdef CONFIG_PM