Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp970164ybi; Fri, 2 Aug 2019 07:17:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJT2yjNtSkDzGpfcnPdz0gSfwCxIOjJiADSSZxJqwYieBj7GLHegXyz7S8B808h1W5Oy2/ X-Received: by 2002:a62:b60e:: with SMTP id j14mr60617377pff.54.1564755421827; Fri, 02 Aug 2019 07:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564755421; cv=none; d=google.com; s=arc-20160816; b=lfM5396pH/TxIMFEV7egs7S5kebV+5L8NuM+W7PAmR+yv3ysZJLjvbQ042Yo6wHgUA Ul/64MJRIo887ytY0iImF2jh0q9wHR68m3XFXQyByFUkOBoCR67TbM3rK8IlBvt6pEwA mfnmEeo183EZmaJAxqyzYyjfbqn3L6JUMCjG6EHgsVaOlTiyeQKTRCNosBvyOSk1pgzT P/HtODSjGP3HdyLlSclLUtNLaeQ3/TAes7Tkylnp34dl99rpCVYZDIAW4zuZoEFZKgr+ hS98idkxDBTpqclAPjwc1GdD3g/Vi3vZ2KKhtn8jirvA+pjufqhrHy728EXmT/72nkrm 2shw== 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=ggH4JlveHmpfWW7/MmtJH3GZFJ/tyWmUClGZgRRWVos=; b=SjV1fyqHoksT6fsP41vUFzD2lm9mhvwf0PspZX7rsEuPrOOfE2der8BJnif+r2vn5y w3FdUrRAJJPmVgjhxbd+ILj9LQkHeBeoZM55sNpyDoK6hG7hQMgNOhUIoCaKe6EikcIP 4B2bH3m8+qSGE5XPknqGx4lejJ+pg3uDfskMhYRkEGcLVEu1wwLhyw1i0sCetogfpFRi S0XQzVqdzujwAapc0JiJIHPlnRgnOvT2qAsfk06OqluQM2J9Gb6h9z6Sq425taWvUuRl 1PuiF0Mx3qrz+bWUerRk/3mxC1jc8rZ2UMcQ7W5aDazrYvmjTnGIMP9jYxg1eJkis92u KtZQ== 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 w21si32995535plq.91.2019.08.02.07.16.35; Fri, 02 Aug 2019 07:17:01 -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 S1729251AbfHBMCT (ORCPT + 99 others); Fri, 2 Aug 2019 08:02:19 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:57016 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729065AbfHBMCT (ORCPT ); Fri, 2 Aug 2019 08:02:19 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID x72C21Oj020109, 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 x72C21Oj020109 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 2 Aug 2019 20:02:01 +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, 2 Aug 2019 20:02:00 +0800 Date: Fri, 2 Aug 2019 20:02:18 +0800 From: Alex Lu To: Marcel Holtmann CC: Johan Hedberg , , , Max Chou Subject: [PATCH v2] Bluetooth: btusb: Fix suspend issue for Realtek devices Message-ID: <20190802120217.GA8712@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 | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 50aed5259c2b..1995e26fa4cd 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_WAKEUP_DISABLE 13 struct btusb_data { struct hci_dev *hdev; @@ -1165,6 +1166,13 @@ 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. + */ + if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) + device_wakeup_disable(&data->udev->dev); + if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) goto done; @@ -1227,6 +1235,11 @@ static int btusb_close(struct hci_dev *hdev) goto failed; data->intf->needs_remote_wakeup = 0; + + /* Enable remote wake up for auto-suspend */ + if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) + data->intf->needs_remote_wakeup = 1; + device_wakeup_disable(&data->udev->dev); usb_autopm_put_interface(data->intf); @@ -3185,11 +3198,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_WAKEUP_DISABLE, &data->flags); } #endif @@ -3363,6 +3376,19 @@ 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. + * Actually, it depends on whether the usb host sends + * set feature (enable wakeup) or not. + */ + if (test_bit(BTUSB_WAKEUP_DISABLE, &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; + } + return 0; } -- 2.19.2