Skip to content

Fix Wdfserial power management checkbox "Allow the computer to turn off this device to save power"#30

Merged
5656hcx merged 2 commits intoqualcomm:mainfrom
CristianManca:wdfserial-power-management-checkbox
May 4, 2026
Merged

Fix Wdfserial power management checkbox "Allow the computer to turn off this device to save power"#30
5656hcx merged 2 commits intoqualcomm:mainfrom
CristianManca:wdfserial-power-management-checkbox

Conversation

@CristianManca
Copy link
Copy Markdown
Contributor

Problem

For qcwdfser devices, unchecking "Allow the computer to turn off this device to save power" sets IdleInWorkingState
= 0 and disables selective suspend. Re-checking the box does not restore IdleInWorkingState = 1 — selective suspend
stays disabled until a manual registry edit and device re-enumeration.

Root Cause Analysis

  1. EnableSelectiveSuspend never sets Enabled = WdfTrue — when called after re-checking the box, WDF sees
    IdleInWorkingState = 0 in the registry and does not re-enable idle, because the driver provides no explicit
    override. This is the direct cause of the bug.
  2. DisableSelectiveSuspend uses a mismatched IdleCaps — it hardcodes IdleCannotWakeFromS0, but WDF locked
    IdleUsbSelectiveSuspend on the first successful enable call. The mismatch causes STATUS_INVALID_DEVICE_REQUEST, so
    the disable call silently fails.
  3. DisableSelectiveSuspend does not set UserControlOfIdleSettings — without IdleAllowUserControl, WDF may ignore
    user-initiated power management toggles.

Solution

  • Set idleSettings.Enabled = WdfTrue explicitly in EnableSelectiveSuspend when SS should be active, forcing WDF to
    restore IdleInWorkingState = 1 regardless of the registry state.
  • Track the accepted IdleCaps in a new DEVICE_CONTEXT field (AssignedIdleCaps), stored after every successful
    WdfDeviceAssignS0IdleSettings call.
  • Use pDevContext->AssignedIdleCaps in DisableSelectiveSuspend instead of a hardcoded value, ensuring the IdleCaps
    always matches what WDF locked — across all code paths (normal, STATUS_POWER_STATE_INVALID fallback, and LPC).
  • Set UserControlOfIdleSettings = IdleAllowUserControl in DisableSelectiveSuspend so user toggles are honored.

- Remove unnecessary IdleCaps assignment when SS is disabled (registry not set)
- Explicitly enable selective suspend in high timeout case to override user/registry settings
- Use IdleUsbSelectiveSuspend instead of IdleCannotWakeFromS0 when disabling SS
- Add UserControlOfIdleSettings to restore user control when disabling selective suspend
Ensures proper power policy state transitions and respects user preferences.

Signed-off-by: Cristian Manca <Cristian.Manca@telit.com>
Copy link
Copy Markdown
Contributor

@5656hcx 5656hcx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea to make enabling explicit and store the capabilities is good.

My suggestion is to save this value in the end of function, set and save it only once, and use it in both enable and disable function.

Comment thread src/windows/wdfserial/QCPNP.c Outdated
Store assigned idle capabilities in device context to maintain power policy
consistency when toggling selective suspend enable/disable.
- Add AssignedIdleCaps field to device context to track idle capabilities
- Store assigned idle caps once at function end
- Restore stored idle caps or fallback to IdleCannotWakeFromS0 when disabling selective suspend
- Ensures power policy state consistency across enable/disable cycles

Signed-off-by: Cristian Manca <Cristian.Manca@telit.com>
@CristianManca CristianManca force-pushed the wdfserial-power-management-checkbox branch from a13740a to 1907900 Compare May 4, 2026 09:38
@CristianManca CristianManca requested a review from 5656hcx May 4, 2026 10:24
@5656hcx 5656hcx merged commit ca7dab4 into qualcomm:main May 4, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good first issue Good for newcomers

Projects

None yet

3 participants