Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp12114625ybi; Fri, 26 Jul 2019 05:03:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDj6N2wo0pGvuehv0i+qhXq1op/yG+LG7MvuD8wQjmLPpdD9BGe6O1eJzJR2AIyjNjtN5T X-Received: by 2002:a65:500a:: with SMTP id f10mr60247082pgo.105.1564142585524; Fri, 26 Jul 2019 05:03:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564142585; cv=none; d=google.com; s=arc-20160816; b=mTAcyPa5ILmrtnr9ZD0EuGBdfyjBjE9dr9vKZxv5uLTABvx47bQvHtApriakI1Ms4y 7AlFtnOiFCF13By4ns92zCLS14xFSK+ycpTVrtVDj/C5jxS/UsPHAIn9G7soFv3WOS3m lyZGby0yxXz89fQYdW3pzet3S4ral/D4GKpdj592pL2egckMU+AOA8RJv18YeI3UV8XP a1OYdUcfBkWdfrw6bcd7usB7egpKFfIU0mQAv2kU6AStExGV05KsakLkdNtI5YL5UBbs G98J3bceeRWzSk326sokLG/vX0qaFX4hehjGx+ptcSMtw3pFtwZ99ckkOhSkm9HMrV9e ua5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:authenticated-by; bh=/6T+32eJxiWx8AVWCDc/gQW6fRfvSbc9V6yXjE4qdLs=; b=E71sCs7MTGsN2vwIV2zV0VJw8ePJIf3VXddquwV0FHxffNlNj2CtuRNIK+7w0XUeXs oMoTeKs8fKMyQGye0l8mZLeErbmiBLHB+rdtGWJm8X7wGXeAsea5rcVPHVCtWu9hxivb YGq5I4aCigyhLINd7/pkS/5uq5nP9aTtBc4PCpis/LUFRfy7vXip8Ps9AYs4dVEJDr7/ UYmAObGPWe7CoghdeXk0ekCk4NqvbcqsOkkkM4aRfQ2bZupI4woXs1UbeHMll3yM3Wdo TzKcgdu+ZguyTQPE5YlPjytEFhAX39AhJTL2SYi6OAlalOwXyjxnztgtXz4rZwnXdJCB vdMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e21si22057797pfl.68.2019.07.26.05.02.21; Fri, 26 Jul 2019 05:03:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726789AbfGZLwF (ORCPT + 99 others); Fri, 26 Jul 2019 07:52:05 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:47272 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726604AbfGZLwE (ORCPT ); Fri, 26 Jul 2019 07:52:04 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID x6QBpqSd015619, This message is accepted by code: ctloc85258 Received: from RS-CAS02.realsil.com.cn (msx.realsil.com.cn[172.29.17.3](maybeforged)) by rtits2.realtek.com.tw (8.15.2/2.57/5.78) with ESMTPS id x6QBpqSd015619 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 26 Jul 2019 19:51:52 +0800 Received: from toshiba (172.29.36.108) by RS-CAS02.realsil.com.cn (172.29.17.3) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 26 Jul 2019 19:51:51 +0800 Date: Fri, 26 Jul 2019 19:52:08 +0800 From: Alex Lu To: Marcel Holtmann , Johan Hedberg CC: , , Max Chou Subject: [PATCH] Bluetooth: btusb: Fix suspend issue for Realtek Message-ID: <20190726115208.GA8152@toshiba> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Originating-IP: [172.29.36.108] Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Alex Lu From the perspective of controller, global suspend means there is no SET_FEATURE (DEVICE_REMOTE_WAKEUP) and controller would drop the firmware. It would consume less power. So we should not send this kind of SET_FEATURE when host goes to suspend state. Otherwise, when making device enter selective suspend, host should send SET_FEATURE to make sure the firmware remains. Signed-off-by: Alex Lu --- drivers/bluetooth/btusb.c | 40 +++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 50aed5259c2b..69f6b4208901 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -426,6 +426,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = { #define BTUSB_DIAG_RUNNING 10 #define BTUSB_OOB_WAKE_ENABLED 11 #define BTUSB_HW_RESET_ACTIVE 12 +#define BTUSB_QUIRK_SUSPEND 13 struct btusb_data { struct hci_dev *hdev; @@ -1165,6 +1166,15 @@ static int btusb_open(struct hci_dev *hdev) */ device_wakeup_enable(&data->udev->dev); + /* Disable device remote wakeup when host is suspended + * For Realtek chips, global suspend without + * SET_FEATURE (DEVICE_REMOTE_WAKEUP) can save more power in device. + */ +#ifdef CONFIG_BT_HCIBTUSB_RTL + if (test_bit(BTUSB_QUIRK_SUSPEND, &data->flags)) + device_wakeup_disable(&data->udev->dev); +#endif + if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) goto done; @@ -1227,6 +1237,13 @@ static int btusb_close(struct hci_dev *hdev) goto failed; data->intf->needs_remote_wakeup = 0; + + /* Enable remote wake up for auto-suspend */ +#ifdef CONFIG_BT_HCIBTUSB_RTL + if (test_bit(BTUSB_QUIRK_SUSPEND, &data->flags)) + data->intf->needs_remote_wakeup = 1; +#endif + device_wakeup_disable(&data->udev->dev); usb_autopm_put_interface(data->intf); @@ -3185,11 +3202,11 @@ static int btusb_probe(struct usb_interface *intf, if (id->driver_info & BTUSB_REALTEK) { hdev->setup = btrtl_setup_realtek; - /* Realtek devices lose their updated firmware over suspend, - * but the USB hub doesn't notice any status change. - * Explicitly request a device reset on resume. + /* Realtek devices lose their updated firmware over global + * suspend that means host doesn't send SET_FEATURE + * (DEVICE_REMOTE_WAKEUP) */ - interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; + set_bit(BTUSB_QUIRK_SUSPEND, &data->flags); } #endif @@ -3363,6 +3380,21 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message) enable_irq(data->oob_wake_irq); } +#ifdef CONFIG_BT_HCIBTUSB_RTL + /* For global suspend, Realtek devices lose the loaded fw + * in them. But for autosuspend, firmware should remain. + * Actually, it depends on whether the usb host sends + * set feature (enable wakeup) or not. + */ + if (test_bit(BTUSB_QUIRK_SUSPEND, &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; + } +#endif + return 0; } -- 2.19.2