Skip to content

Commit ca7dab4

Browse files
authored
Merge pull request #30 from CristianManca/wdfserial-power-management-checkbox
Fix Wdfserial power management checkbox "Allow the computer to turn off this device to save power"
2 parents 72a8f56 + 1907900 commit ca7dab4

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/windows/wdfserial/QCMAIN.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ typedef struct _DEVICE_CONTEXT
261261
BOOLEAN InServiceSelectiveSuspension;
262262
ULONG SelectiveSuspendIdleTime;
263263
BOOLEAN SelectiveSuspendInMiliSeconds;
264+
WDF_POWER_POLICY_S0_IDLE_CAPABILITIES AssignedIdleCaps;
264265

265266
WMILIB_CONTEXT WmiLibInfo; // to query system power management tab
266267
CHAR DevSerialNumber[256]; // to hold USB_STRING_DESCRIPTOR of the serial number

src/windows/wdfserial/QCPNP.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,7 @@ NTSTATUS QCPNP_EnableSelectiveSuspend
21072107
{
21082108
idleSettings.IdleTimeout *= 1000;
21092109
}
2110+
idleSettings.Enabled = WdfTrue; // explicitly enable SS (overrides any user/registry disable)
21102111
status = WdfDeviceAssignS0IdleSettings(Device, &idleSettings);
21112112
if (status == STATUS_POWER_STATE_INVALID)
21122113
{
@@ -2129,6 +2130,8 @@ NTSTATUS QCPNP_EnableSelectiveSuspend
21292130
);
21302131
}
21312132

2133+
pDevContext->AssignedIdleCaps = idleSettings.IdleCaps;
2134+
21322135
return status;
21332136
}
21342137

@@ -2159,8 +2162,14 @@ NTSTATUS QCPNP_DisableSelectiveSuspend
21592162
("<%ws> QCPNP_DisableSelectiveSuspend\n", pDevContext->PortName)
21602163
);
21612164

2162-
WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&idleSettings, IdleCannotWakeFromS0);
2165+
WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(
2166+
&idleSettings,
2167+
(pDevContext->AssignedIdleCaps != IdleCapsInvalid)
2168+
? pDevContext->AssignedIdleCaps
2169+
: IdleCannotWakeFromS0
2170+
);
21632171
idleSettings.Enabled = WdfFalse;
2172+
idleSettings.UserControlOfIdleSettings = IdleAllowUserControl;
21642173
return WdfDeviceAssignS0IdleSettings(Device, &idleSettings);
21652174
}
21662175

0 commit comments

Comments
 (0)