1e02c6b
From 20eeb02a0a489e35de0830b2d61f09d43763c982 Mon Sep 17 00:00:00 2001
1e02c6b
From: Hans de Goede <hdegoede@redhat.com>
1e02c6b
Date: Mon, 13 Nov 2017 09:23:19 +0100
1e02c6b
Subject: [PATCH] Bluetooth: btusb: Add a Kconfig option to enable USB
1e02c6b
 autosuspend by default
1e02c6b
1e02c6b
On many laptops the btusb device is the only USB device not having USB
1e02c6b
autosuspend enabled, this causes not only the HCI but also the USB
1e02c6b
controller to stay awake, together using aprox. 0.4W of power.
1e02c6b
1e02c6b
Modern ultrabooks idle around 6W (at 50% screen brightness), 3.5W for
1e02c6b
Apollo Lake devices. 0.4W is a significant chunk of this (7 / 11%).
1e02c6b
1e02c6b
The btusb driver already contains code to allow enabling USB autosuspend,
1e02c6b
but currently leaves it up to the user / userspace to enable it. This
1e02c6b
means that for most people it will not be enabled, leading to an
1e02c6b
unnecessarily high power consumption.
1e02c6b
1e02c6b
Since enabling it is not entirely without risk of regressions, this
1e02c6b
commit adds a Kconfig option so that Linux distributions can choose to
1e02c6b
enable it by default. This commit also adds a module option so that when
1e02c6b
distros receive bugs they can easily ask the user to disable it again
1e02c6b
for easy debugging.
1e02c6b
1e02c6b
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1e02c6b
---
1e02c6b
Changes in v2:
1e02c6b
-s/BT_USB_AUTOSUSPEND/BT_HCIBTUSB_AUTOSUSPEND/
1e02c6b
-s/enable_usb_autosuspend/enable_autosuspend/
1e02c6b
---
1e02c6b
 drivers/bluetooth/Kconfig | 10 ++++++++++
1e02c6b
 drivers/bluetooth/btusb.c |  7 +++++++
1e02c6b
 2 files changed, 17 insertions(+)
1e02c6b
1e02c6b
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
1e02c6b
index 6475f8c0d3b2..20940417d937 100644
1e02c6b
--- a/drivers/bluetooth/Kconfig
1e02c6b
+++ b/drivers/bluetooth/Kconfig
1e02c6b
@@ -30,6 +30,16 @@ config BT_HCIBTUSB
1e02c6b
 	  Say Y here to compile support for Bluetooth USB devices into the
1e02c6b
 	  kernel or say M to compile it as module (btusb).
1e02c6b
 
1e02c6b
+config BT_HCIBTUSB_AUTOSUSPEND
1e02c6b
+	bool "Enable USB autosuspend for Bluetooth USB devices by default"
1e02c6b
+	depends on BT_HCIBTUSB
1e02c6b
+	help
1e02c6b
+	  Say Y here to enable USB autosuspend for Bluetooth USB devices by
1e02c6b
+	  default.
1e02c6b
+
1e02c6b
+	  This can be overridden by passing btusb.enable_autosuspend=[y|n]
1e02c6b
+	  on the kernel commandline.
1e02c6b
+
1e02c6b
 config BT_HCIBTUSB_BCM
1e02c6b
 	bool "Broadcom protocol support"
1e02c6b
 	depends on BT_HCIBTUSB
1e02c6b
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
1e02c6b
index c054d7bce490..3386034a44aa 100644
1e02c6b
--- a/drivers/bluetooth/btusb.c
1e02c6b
+++ b/drivers/bluetooth/btusb.c
1e02c6b
@@ -40,6 +40,7 @@
1e02c6b
 
1e02c6b
 static bool disable_scofix;
1e02c6b
 static bool force_scofix;
1e02c6b
+static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND);
1e02c6b
 
1e02c6b
 static bool reset = true;
1e02c6b
 
1e02c6b
@@ -3175,6 +3176,9 @@ static int btusb_probe(struct usb_interface *intf,
1e02c6b
 	}
1e02c6b
 #endif
1e02c6b
 
1e02c6b
+	if (enable_autosuspend)
1e02c6b
+		usb_enable_autosuspend(data->udev);
1e02c6b
+
1e02c6b
 	err = hci_register_dev(hdev);
1e02c6b
 	if (err < 0)
1e02c6b
 		goto out_free_dev;
1e02c6b
@@ -3387,6 +3391,9 @@ MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
1e02c6b
 module_param(force_scofix, bool, 0644);
1e02c6b
 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
1e02c6b
 
1e02c6b
+module_param(enable_autosuspend, bool, 0644);
1e02c6b
+MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default");
1e02c6b
+
1e02c6b
 module_param(reset, bool, 0644);
1e02c6b
 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
1e02c6b
 
1e02c6b
-- 
1e02c6b
2.14.3
1e02c6b