Bluetooth: hci_bcm: Configure sleep mode on RPM suspend/resume
PATCH 1/1 Bluetooth: hci_bcm: Configure sleep mode on RPM suspend/resume
The Infineon CYW43439 Bluetooth device enters suspend mode right after receiving the Set_Sleepmode_Param sleep_mode=1 HCI command, even if the BT_DEV_WAKE input is HIGH, i.e. device ought to be awake. This triggers a timeout of any follow up HCI command, in case of regular boot, that is HCI_OP_RESET command issued from hci_init1_sync() .
Rework the code such that during probe, the device is configured to not enter sleep mode by issuing Set_Sleepmode_Param sleep_mode=0 instead of sleep_mode=1 in bcm_setup(). Upon RPM suspend, issue Set_Sleepmode_Param with sleep_mode=1 to allow the device to enter the sleep mode when the BT_DEV_WAKE signal is deasserted, which is deasserted soon after in the RPM suspend callback. Upon RPM resume, assert BT_DEV_WAKE to resume the chip from sleep mode and then issue Set_Sleepmode_Param sleep_mode=0 to yet again prevent the device from entering sleep mode until the next RPM suspend.
---
Cc: Hans de Goede <[email protected]>
Cc: Luiz Augusto von Dentz <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- drivers/bluetooth/hci_bcm.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)
drivers/bluetooth/hci_bcm.c +29 -3
@@ -389,13 +389,19 @@ static const struct bcm_set_sleep_mode default_sleep_params = { .pulsed_host_wake = 1, }; -static int bcm_setup_sleep (struct hci_uart *hu) +static int bcm_setup_sleep (struct hci_uart *hu,bool sync,int mode) {struct bcm_data *bcm = hu->priv;struct sk_buff *skb;struct bcm_set_sleep_mode sleep_params = default_sleep_params; sleep_params.host_wake_active = !bcm->dev->irq_active_low; + sleep_params.sleep_mode = mode; + +if (!sync) { +return __hci_cmd_send (hu->hdev,0xfc27 ,sizeof (sleep_params), + &sleep_params); + } skb =__hci_cmd_sync (hu->hdev,0xfc27 ,sizeof (sleep_params), &sleep_params,HCI_INIT_TIMEOUT );
@@ -412,7 +418,7 @@ static int bcm_setup_sleep(struct hci_uart *hu) }#else static inline int bcm_request_irq (struct bcm_data *bcm) {return 0 ; } -static inline int bcm_setup_sleep (struct hci_uart *hu) {return 0 ; } +static inline int bcm_setup_sleep (struct hci_uart *hu,bool sync,int mode) {return 0 ; }#endif static int bcm_set_diag (struct hci_dev *hdev,bool enable)
@@ -647,7 +653,7 @@ static int bcm_setup(struct hci_uart *hu)set_bit (HCI_QUIRK_USE_BDADDR_PROPERTY , &hu->hdev->quirks);if (!bcm_request_irq (bcm)) - err =bcm_setup_sleep (hu); + err =bcm_setup_sleep (hu, true,0 );return err; }
@@ -767,6 +773,16 @@ static int bcm_suspend_device(struct device *dev)bt_dev_dbg (bdev,"" );if (!bdev->is_suspended && bdev->hu) { + err =bcm_setup_sleep (bdev->hu, false,1 ); +/* +* If the sleep mode cannot be enabled, the BT device +* may consume more power, but this should not prevent +* RPM suspend from completion. Warn about this, but +* attempt to suspend anyway. +*/ +if (err) +dev_err (dev,"Failed to enable sleep mode\n" ); +hci_uart_set_flow_control (bdev->hu, true);/* Once this returns, driver suspends BT via GPIO */
@@ -810,6 +826,16 @@ static int bcm_resume_device(struct device *dev) bdev->is_suspended = false;hci_uart_set_flow_control (bdev->hu, false); + + err =bcm_setup_sleep (bdev->hu, false,0 ); +/* +* If the sleep mode cannot be disabled, the BT device +* may fail to respond to commands at times, or may be +* completely unresponsive. Warn user about this, but +* attempt to resume anyway in best effort manner. +*/ +if (err) +dev_err (dev,"Failed to disable sleep mode\n" ); }return 0 ;
Signature · 1 line
2.43.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=866844
---Test result---
Test Summary:
CheckPatch PASS 0.70 seconds GitLint PASS 0.33 seconds SubjectPrefix PASS 0.14 seconds BuildKernel PASS 28.77 seconds CheckAllWarning PASS 31.02 seconds CheckSparse PASS 36.35 seconds CheckSmatch PASS 99.34 seconds BuildKernel32 PASS 30.39 seconds TestRunnerSetup PASS 504.07 seconds TestRunner_l2cap-tester PASS 19.65 seconds TestRunner_iso-tester FAIL 42.46 seconds TestRunner_bnep-tester PASS 4.64 seconds TestRunner_mgmt-tester PASS 110.15 seconds TestRunner_rfcomm-tester PASS 7.21 seconds TestRunner_sco-tester PASS 14.80 seconds TestRunner_ioctl-tester PASS 7.61 seconds TestRunner_mesh-tester PASS 10.21 seconds TestRunner_smp-tester PASS 6.67 seconds TestRunner_userchan-tester PASS 4.88 seconds IncrementalBuild PASS 26.91 seconds
Details
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
Total: 122, Passed: 116 (95.1%), Failed: 2, Not Run: 4
Failed Test Cases
ISO Connect Suspend - Success Failed 6.185 seconds ISO Connect2 Suspend - Success Failed 6.233 seconds
---
Regards,
Linux Bluetooth
Quoted 6 lines · Marek Vasut
The Infineon CYW43439 Bluetooth device enters suspend mode right after receiving the
Set_Sleepmode_Paramsleep_mode=1 HCI command, even if theBT_DEV_WAKEinput is HIGH, i.e. device ought to be awake. This triggers a timeout of any follow up HCI command, in case of regular boot, that isHCI_OP_RESETcommand issued fromhci_init1_sync().
Quoted 9 lines
Rework the code such that during probe, the device is configured to not enter sleep mode by issuing
Set_Sleepmode_Paramsleep_mode=0 instead of sleep_mode=1 inbcm_setup(). Upon RPM suspend, issueSet_Sleepmode_Paramwith sleep_mode=1 to allow the device to enter the sleep mode when theBT_DEV_WAKEsignal is deasserted, which is deasserted soon after in the RPM suspend callback. Upon RPM resume, assertBT_DEV_WAKEto resume the chip from sleep mode and then issueSet_Sleepmode_Paramsleep_mode=0 to yet again prevent the device from entering sleep mode until the next RPM suspend.
Is there any feedback on this patch ?
Hi Marek,
Quoted 16 lines · Marek Vasut
The Infineon CYW43439 Bluetooth device enters suspend mode right after receiving the
Set_Sleepmode_Paramsleep_mode=1 HCI command, even if theBT_DEV_WAKEinput is HIGH, i.e. device ought to be awake. This triggers a timeout of any follow up HCI command, in case of regular boot, that isHCI_OP_RESETcommand issued fromhci_init1_sync().Rework the code such that during probe, the device is configured to not enter sleep mode by issuing
Set_Sleepmode_Paramsleep_mode=0 instead of sleep_mode=1 inbcm_setup(). Upon RPM suspend, issueSet_Sleepmode_Paramwith sleep_mode=1 to allow the device to enter the sleep mode when theBT_DEV_WAKEsignal is deasserted, which is deasserted soon after in the RPM suspend callback. Upon RPM resume, assertBT_DEV_WAKEto resume the chip from sleep mode and then issueSet_Sleepmode_Paramsleep_mode=0 to yet again prevent the device from entering sleep mode until the next RPM suspend.
Quoted 1 line
Signed-off-by Marek Vasut <[email protected]>
Thank you for your patch. The patch looks good to me and I've been running this in my personal tree / test-kernels which includes various devices with BCM BT serdevs without issues:
Regards,
Hans
Quoted 87 lines
---
Cc: Hans de Goede <[email protected]>
Cc: Luiz Augusto von Dentz <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/bluetooth/hci_bcm.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)drivers/bluetooth/hci_bcm.c +29
-3@@ -389,13 +389,19 @@ static const struct bcm_set_sleep_mode default_sleep_params = { .pulsed_host_wake = 1, }; -static int bcm_setup_sleep (struct hci_uart *hu) +static int bcm_setup_sleep (struct hci_uart *hu,bool sync,int mode) {struct bcm_data *bcm = hu->priv;struct sk_buff *skb;struct bcm_set_sleep_mode sleep_params = default_sleep_params; sleep_params.host_wake_active = !bcm->dev->irq_active_low; + sleep_params.sleep_mode = mode; + +if (!sync) { +return __hci_cmd_send (hu->hdev,0xfc27 ,sizeof (sleep_params), + &sleep_params); + } skb =__hci_cmd_sync (hu->hdev,0xfc27 ,sizeof (sleep_params), &sleep_params,HCI_INIT_TIMEOUT );@@ -412,7 +418,7 @@ static int bcm_setup_sleep(struct hci_uart *hu) }#else static inline int bcm_request_irq (struct bcm_data *bcm) {return 0 ; } -static inline int bcm_setup_sleep (struct hci_uart *hu) {return 0 ; } +static inline int bcm_setup_sleep (struct hci_uart *hu,bool sync,int mode) {return 0 ; }#endif static int bcm_set_diag (struct hci_dev *hdev,bool enable)@@ -647,7 +653,7 @@ static int bcm_setup(struct hci_uart *hu)set_bit (HCI_QUIRK_USE_BDADDR_PROPERTY , &hu->hdev->quirks);if (!bcm_request_irq (bcm)) - err =bcm_setup_sleep (hu); + err =bcm_setup_sleep (hu, true,0 );return err; }@@ -767,6 +773,16 @@ static int bcm_suspend_device(struct device *dev)bt_dev_dbg (bdev,"" );if (!bdev->is_suspended && bdev->hu) { + err =bcm_setup_sleep (bdev->hu, false,1 ); +/* +* If the sleep mode cannot be enabled, the BT device +* may consume more power, but this should not prevent +* RPM suspend from completion. Warn about this, but +* attempt to suspend anyway. +*/ +if (err) +dev_err (dev,"Failed to enable sleep mode\n" ); +hci_uart_set_flow_control (bdev->hu, true);/* Once this returns, driver suspends BT via GPIO */ @@ -810,6 +826,16 @@ static int bcm_resume_device(struct device *dev) bdev->is_suspended = false;hci_uart_set_flow_control (bdev->hu, false); + + err =bcm_setup_sleep (bdev->hu, false,0 ); +/* +* If the sleep mode cannot be disabled, the BT device +* may fail to respond to commands at times, or may be +* completely unresponsive. Warn user about this, but +* attempt to resume anyway in best effort manner. +*/ +if (err) +dev_err (dev,"Failed to disable sleep mode\n" ); }return 0 ;
Dear Marek,
Thank you for your patch. I was made aware of it by Hans’ recent review. Some minor nits. Probably, you need to resend the patch anyway.
Am 29.06.24 um 19:22 schrieb Marek Vasut:
Quoted 4 lines
The Infineon CYW43439 Bluetooth device enters suspend mode right after receiving the
Set_Sleepmode_Paramsleep_mode=1 HCI command, even if theBT_DEV_WAKEinput is HIGH, i.e. device ought to be awake. This triggers a timeout of any follow up HCI command, in case of regular boot, that is
follow-up
Quoted 11 lines
HCI_OP_RESETcommand issued fromhci_init1_sync().Rework the code such that during probe, the device is configured to not enter sleep mode by issuing
Set_Sleepmode_Paramsleep_mode=0 instead of sleep_mode=1 inbcm_setup(). Upon RPM suspend, issueSet_Sleepmode_Paramwith sleep_mode=1 to allow the device to enter the sleep mode when theBT_DEV_WAKEsignal is deasserted, which is deasserted soon after in the RPM suspend callback. Upon RPM resume, assertBT_DEV_WAKEto resume the chip from sleep mode and then issueSet_Sleepmode_Paramsleep_mode=0 to yet again prevent the device from entering sleep mode until the next RPM suspend.
How did you test this? It’d be great if you gave more details.
Quoted 37 lines
Signed-off-by Marek Vasut <[email protected]>---
Cc: Hans de Goede <[email protected]>
Cc: Luiz Augusto von Dentz <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/bluetooth/hci_bcm.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)drivers/bluetooth/hci_bcm.c +7
-1@@ -389,13 +389,19 @@ static const struct bcm_set_sleep_mode default_sleep_params = { .pulsed_host_wake = 1, }; -static int bcm_setup_sleep (struct hci_uart *hu) +static int bcm_setup_sleep (struct hci_uart *hu,bool sync,int mode) {struct bcm_data *bcm = hu->priv;struct sk_buff *skb;struct bcm_set_sleep_mode sleep_params = default_sleep_params; sleep_params.host_wake_active = !bcm->dev->irq_active_low; + sleep_params.sleep_mode = mode; + +if (!sync) { +return __hci_cmd_send (hu->hdev,0xfc27 ,sizeof (sleep_params), + &sleep_params); + } skb =__hci_cmd_sync (hu->hdev,0xfc27 ,sizeof (sleep_params), &sleep_params,HCI_INIT_TIMEOUT );
drivers/bluetooth/hci_bcm.c static int bcm_setup_sleep(struct hci_uart *hu) · line 421
Quoted 5 lines
drivers/bluetooth/hci_bcm.c +1
-1@@ -412,7 +418,7 @@ static int bcm_setup_sleep(struct hci_uart *hu) }#else static inline int bcm_request_irq (struct bcm_data *bcm) {return 0 ; } -static inline int bcm_setup_sleep (struct hci_uart *hu) {return 0 ; } +static inline int bcm_setup_sleep (struct hci_uart *hu,bool sync,int mode) {return 0 ; }
Without an IDE, I always wonder, if an enum or macro should be used for modes, so readers do not need to look up what 0 and 1 mean.
Quoted 15 lines
drivers/bluetooth/hci_bcm.c +1
-1#endif static int bcm_set_diag (struct hci_dev *hdev,bool enable)@@ -647,7 +653,7 @@ static int bcm_setup(struct hci_uart *hu)set_bit (HCI_QUIRK_USE_BDADDR_PROPERTY , &hu->hdev->quirks);if (!bcm_request_irq (bcm)) - err =bcm_setup_sleep (hu); + err =bcm_setup_sleep (hu, true,0 );return err; }@@ -767,6 +773,16 @@ static int bcm_suspend_device(struct device *dev)bt_dev_dbg (bdev,"" );
drivers/bluetooth/hci_bcm.c static int bcm_suspend_device(struct device *dev) · line 784
Quoted 10 lines
drivers/bluetooth/hci_bcm.c +9
-0if (!bdev->is_suspended && bdev->hu) { + err =bcm_setup_sleep (bdev->hu, false,1 ); +/* +* If the sleep mode cannot be enabled, the BT device +* may consume more power, but this should not prevent +* RPM suspend from completion. Warn about this, but +* attempt to suspend anyway. +*/ +if (err) +dev_err (dev,"Failed to enable sleep mode\n" );
Please print out the returned error, and maybe give suggestion, what the user should do in this case.
Quoted 8 lines
drivers/bluetooth/hci_bcm.c +1
-0+hci_uart_set_flow_control (bdev->hu, true);/* Once this returns, driver suspends BT via GPIO */ @@ -810,6 +826,16 @@ static int bcm_resume_device(struct device *dev) bdev->is_suspended = false;hci_uart_set_flow_control (bdev->hu, false);
drivers/bluetooth/hci_bcm.c static int bcm_resume_device(struct device *dev) · line 838
Quoted 10 lines
drivers/bluetooth/hci_bcm.c +10
-0+ + err =bcm_setup_sleep (bdev->hu, false,0 ); +/* +* If the sleep mode cannot be disabled, the BT device +* may fail to respond to commands at times, or may be +* completely unresponsive. Warn user about this, but +* attempt to resume anyway in best effort manner. +*/ +if (err) +dev_err (dev,"Failed to disable sleep mode\n" );
Ditto.
drivers/bluetooth/hci_bcm.c static int bcm_resume_device(struct device *dev) · line 841
Quoted 3 lines
drivers/bluetooth/hci_bcm.c +0
-0}return 0 ;
Overall this looks good.
Kind regards,
Paul