Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp10333041pxu; Tue, 29 Dec 2020 22:58:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0akyW7Lo0MnGD//wkHa0vvg9js5e0rlxOBs+hMJd3tv08Bv7LRVhHwqBNExshRELUt1JG X-Received: by 2002:a17:906:4e53:: with SMTP id g19mr47731055ejw.454.1609311529328; Tue, 29 Dec 2020 22:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609311529; cv=none; d=google.com; s=arc-20160816; b=0g3mNsBBJXAuXvdW9v5Sf+BgTj9gHub1NwcBxEh/vo9JYizeJx01RU7Z/jvTQlgmkc 9922qDdI5I3VFAVoHg8xySXNi6S8HX+vnsfs/GWxZK9Y3wP9UbvNfDXEfcy4TSUt/U4d 3jOofsGmrchJ/00BGtBJ+GIKCobAezDp4bDNZzKFEsyUEc5006Uc+4PsCcmOMnrdfI3V 1CYkW5MaMEA+J2OOjy1Adv2ObUBqFtQo6O+VkqaK87FaITTJm/nffT5VIwvtpnZucbR4 77uMVcIBsU8plycciAkpd3t8JXZ9qO1UPIKn3vCJO12DFIOiWopf+YFiVhkgKmpxHgb6 ne1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :authenticated-by; bh=2aWFQ/gO1IGeyB53i3gyqh4gczsHAGQyjp8/ZvGBz2s=; b=0ZQPXWUVOiA+9DPeEhTHSVhFUG+6Cawa4FWven9YczJ+40qe5HARxs8IvBLQrK4b01 yo8P8H7hUojhlqyS+0l6sRiDemqUxgJLIHIW38A+UbYUq9ULFTU8YipdzBb+lV63Ebph gLy0vX9kmXFul3z91do6hT6g/YkKYPG4uGG9DXshC1rVK3usbimEec9h+ampKlz2clT6 gDuYo7nnq5Xr9W7NRr6kKuRz5ESBb43e4E5OyF8mJQPWq6bfMQ1UI7aJw3sESsa7YNVs 3RkbSC1XeEtr3t9ulES02u0ufYRCAb+jTOrCnUNc3KH9pHTW45bnpiag6q8nU8hLcqbg mQZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si23399901edq.169.2020.12.29.22.58.27; Tue, 29 Dec 2020 22:58:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726428AbgL3G4K (ORCPT + 99 others); Wed, 30 Dec 2020 01:56:10 -0500 Received: from rtits2.realtek.com ([211.75.126.72]:56470 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726354AbgL3G4J (ORCPT ); Wed, 30 Dec 2020 01:56:09 -0500 Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.73 with qID 0BU6sjcE7019892, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexmbs03.realtek.com.tw[172.21.6.96]) by rtits2.realtek.com.tw (8.15.2/2.70/5.88) with ESMTPS id 0BU6sjcE7019892 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 30 Dec 2020 14:54:45 +0800 Received: from localhost.localdomain (172.21.132.186) by RTEXMBS03.realtek.com.tw (172.21.6.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Wed, 30 Dec 2020 14:54:45 +0800 From: To: , , , CC: , , , , , , , Subject: [PATCH] Bluetooth: btusb: Add a Kconfig option to disable USB wakeup by default Date: Wed, 30 Dec 2020 14:54:41 +0800 Message-ID: <20201230065441.1179-1-max.chou@realtek.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.21.132.186] X-ClientProxiedBy: RTEXMBS02.realtek.com.tw (172.21.6.95) To RTEXMBS03.realtek.com.tw (172.21.6.96) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Max Chou For the original commit of 9e45524a011107a73bc2cdde8370c61e82e93a4d, wakeup is always disabled for Realtek Bluetooth devices. However, there's the capability for Realtek Bluetooth devices to apply USB wakeup. Otherwise, there's the better power consumption without USB wakeup during suspending. In this commit, divide the original commit into two parts. 1. Redefine the feature that Realtek devices should be enabled wakeup on auto-suspend as BTUSB_WAKEUP_AUTOSUSPEND. 2. Add a Kconfig option to switch disable_wakeup for Bluetooth USB devices by default as CONFIG_BT_HCIBTUSB_DISABLEWAKEUP. Signed-off-by: Max Chou --- drivers/bluetooth/Kconfig | 11 +++++++++++ drivers/bluetooth/btusb.c | 41 ++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 4e73a531b377..7af10897a248 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -41,6 +41,17 @@ config BT_HCIBTUSB_AUTOSUSPEND This can be overridden by passing btusb.enable_autosuspend=[y|n] on the kernel commandline. +config BT_HCIBTUSB_DISABLEWAKEUP + bool "Disable USB wakeup for Bluetooth USB devices by default" + depends on BT_HCIBTUSB + default n + help + Say Y here to disable USB wakeup for Bluetooth USB devices by + default. + + This can be overridden by passing btusb.disable_wakeup=[y|n] + on the kernel commandline. + config BT_HCIBTUSB_BCM bool "Broadcom protocol support" depends on BT_HCIBTUSB diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index b630a1d54c02..5f55111849b5 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -30,6 +30,7 @@ static bool disable_scofix; static bool force_scofix; static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND); +static bool disable_wakeup = IS_ENABLED(CONFIG_BT_HCIBTUSB_DISABLEWAKEUP); static bool reset = true; @@ -505,7 +506,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = { #define BTUSB_OOB_WAKE_ENABLED 11 #define BTUSB_HW_RESET_ACTIVE 12 #define BTUSB_TX_WAIT_VND_EVT 13 -#define BTUSB_WAKEUP_DISABLE 14 +#define BTUSB_WAKEUP_AUTOSUSPEND 14 struct btusb_data { struct hci_dev *hdev; @@ -1330,7 +1331,7 @@ static int btusb_open(struct hci_dev *hdev) * For Realtek chips, global suspend without * SET_FEATURE (DEVICE_REMOTE_WAKEUP) can save more power in device. */ - if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) + if (disable_wakeup) device_wakeup_disable(&data->udev->dev); if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) @@ -1399,7 +1400,7 @@ static int btusb_close(struct hci_dev *hdev) data->intf->needs_remote_wakeup = 0; /* Enable remote wake up for auto-suspend */ - if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) + if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) data->intf->needs_remote_wakeup = 1; usb_autopm_put_interface(data->intf); @@ -4257,7 +4258,7 @@ static bool btusb_prevent_wake(struct hci_dev *hdev) { struct btusb_data *data = hci_get_drvdata(hdev); - if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) + if (disable_wakeup) return true; return !device_may_wakeup(&data->udev->dev); @@ -4557,11 +4558,8 @@ static int btusb_probe(struct usb_interface *intf, hdev->shutdown = btrtl_shutdown_realtek; hdev->cmd_timeout = btusb_rtl_cmd_timeout; - /* Realtek devices lose their updated firmware over global - * suspend that means host doesn't send SET_FEATURE - * (DEVICE_REMOTE_WAKEUP) - */ - set_bit(BTUSB_WAKEUP_DISABLE, &data->flags); + /* Realtek devices need to set USB remote wakeup on auto-suspend */ + set_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags); } if (!reset) @@ -4731,17 +4729,29 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message) enable_irq(data->oob_wake_irq); } - /* For global suspend, Realtek devices lose the loaded fw - * in them. But for autosuspend, firmware should remain. + /* For suspend(S3), Realtek devices lose the loaded fw + * if USB wakeup is disabled. + * It can meet better power consumption. + * Otherwise, the fw is alive if USB wakeup is enabled. + * It's able to wake Host up by the paired devices. + * Note that disable_wakeup should be false, + * and device_may_wakeup() should return true. + * + * For autosuspend, firmware should remain. * Actually, it depends on whether the usb host sends * set feature (enable wakeup) or not. */ - if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) { + if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) { if (PMSG_IS_AUTO(message) && device_can_wakeup(&data->udev->dev)) data->udev->do_remote_wakeup = 1; - else if (!PMSG_IS_AUTO(message)) - data->udev->reset_resume = 1; + else if (!PMSG_IS_AUTO(message)) { + if (disable_wakeup || + !device_may_wakeup(&data->udev->dev)) { + data->udev->do_remote_wakeup = 0; + data->udev->reset_resume = 1; + } + } } return 0; @@ -4865,6 +4875,9 @@ MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size"); module_param(enable_autosuspend, bool, 0644); MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default"); +module_param(disable_wakeup, bool, 0644); +MODULE_PARM_DESC(disable_wakeup, "Disable USB wakeup by default"); + module_param(reset, bool, 0644); MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); -- 2.17.1