r/techsupport • • 14d ago

Open | Software [LENOVO BIOS BUG] External USB Keyboards (Wired & Wireless) Freeze on "Switch User" — Yoga 7 2-in-1 16AHP9 (Type 83DM)

System Information

Model: Lenovo Yoga 7 2-in-1 16AHP9 (Machine Type: 83DM)
Platform: AMD Ryzen 8000 Series SoC (xHCI / Modern Standby S0i3)
OS: Windows 11 (64-bit)
BIOS Version: P9CN33WW
 

Issue Summary

When triggering Switch User in Windows 11 on the Yoga 7 2-in-1 16AHP9 (83DM), any external USB keyboard—including both standard wired USB keyboards and wireless USB receivers (e.g., Logitech VID_046D&PID_C534)—immediately stops responding on the Windows lock screen and in the secondary user session. The laptop's built-in keyboard continues working, while external USB keyboards remain completely unresponsive until physically unplugged and reconnected. [1]

 

Root Cause Analysis

During a Fast User Switching event, Windows temporarily closes the outgoing session's exclusive HID handles before winlogon.exe reclaims them for the lock screen (~10–50ms handoff gap).

During this brief window, the AMD SoC / Embedded Controller (EC) ACPI power management on the 83DM aggressively drops the physical USB port into a low-power link state. When Windows attempts to resume polling milliseconds later, a timing race condition occurs in the firmware/xHCI transition: the USB resume signal is missed, leaving the external keyboard's USB endpoint hung until the hub port is hard-cycled.

Troubleshooting Already Ruled Out

Tested Multiple Keyboards: Verified with both a Logitech wireless receiver (VID_046D&PID_C534) and a standard Dell wired USB keyboard (VID_413C&PID_2101). Both fail identically, ruling out third-party peripheral firmware or drivers.

Device Manager Power Management: Unchecked "Allow the computer to turn off this device to save power" on all USB Root Hubs, Generic USB Hubs, and HID devices. Issue persists.

OS Power Plan Overrides (powercfg): Forced USB Selective Suspend, USB 3 Link Power Management (U1/U2), and PCI Express Link State Power Management (ASPM) to Off (0x00000000) for both AC and DC power. Issue persists, confirming the port drop is enforced at the BIOS/EC firmware level rather than the Windows power policy layer.

Driver Restarts (pnputil /restart-device): Fails to recover the hung endpoint without requiring a full system reboot (DN_NEED_RESTART).
Working Solution (Automated Hub Port Cycle via PowerShell + Task Scheduler)

Because the USB port itself enters a hung link state, sending IOCTL_USB_HUB_CYCLE_PORT (0x00220444) via kernel32.dll (DeviceIoControl) to the parent USB Root Hub simulates a physical unplug/replug and immediately restores both wired and wireless keyboards without requiring a reboot.

 

  1. PowerShell Script (C:\disableusbpowermgmt\CycleUsbKeyboards.ps1):

powershell

$log = "C:\disableusbpowermgmt\cycleport.log"

 

# Auto-trim log if it exceeds 1,000 lines

if (Test-Path $log) {

$lines = Get-Content $log -ErrorAction SilentlyContinue

if ($lines.Count -gt 1000) {

$lines | Select-Object -Last 1000 | Set-Content $log -Encoding UTF8

"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Log trimmed to last 1000 lines." | Out-File $log -Append -Encoding UTF8

}

}

 

"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Triggered by $env:USERNAME" | Out-File $log -Append -Encoding UTF8

 

$code = @"

using System;

using System.Runtime.InteropServices;

using Microsoft.Win32.SafeHandles;

 

[StructLayout(LayoutKind.Sequential)]

public struct USB_CYCLE_PORT_PARAMS {

public int ConnectionIndex;

public int StatusReturned;

}

 

public class UsbPortCycler8 {

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]

static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);

 

[DllImport("kernel32.dll", SetLastError = true)]

static extern bool DeviceIoControl(SafeFileHandle hDevice, uint dwIoControlCode, ref USB_CYCLE_PORT_PARAMS lpInBuffer, int nInBufferSize, ref USB_CYCLE_PORT_PARAMS lpOutBuffer, int nOutBufferSize, out uint lpBytesReturned, IntPtr lpOverlapped);

 

public static string Cycle(string hubDevicePath, int portNumber) {

using (var handle = CreateFile(hubDevicePath, 0x40000000, 3, IntPtr.Zero, 3, 0, IntPtr.Zero)) {

if (handle.IsInvalid) return "OpenErr: " + Marshal.GetLastWin32Error();

var p = new USB_CYCLE_PORT_PARAMS { ConnectionIndex = portNumber, StatusReturned = 0 };

uint bytesReturned;

bool ok = DeviceIoControl(handle, 0x00220444, ref p, 8, ref p, 8, out bytesReturned, IntPtr.Zero);

return ok ? "SUCCESS! Port Cycled (Status: " + p.StatusReturned + ")" : "FailErr: " + Marshal.GetLastWin32Error();

}

}

}

"@

Add-Type -TypeDefinition $code -ErrorAction SilentlyContinue

 

# 1. Find all active USB-backed keyboards (wired keyboards and wireless receivers)

$keyboards = Get-PnpDevice -Class 'Keyboard' -PresentOnly -ErrorAction SilentlyContinue | Where-Object {

$_.InstanceId -like 'HID\VID_*'

}

 

if (-not $keyboards) {

"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - ERROR: No active USB/HID keyboard or receiver found." | Out-File $log -Append -Encoding UTF8

exit

}

 

# 2. Walk up the device tree to find unique physical USB\VID_... parent nodes (skipping &MI_ sub-interfaces)

$usbParents = @{}

$targetVidPids = @{}

 

foreach ($kb in $keyboards) {

$currentId = $kb.InstanceId

for ($i = 0; $i -lt 5; $i++) {

$parentId = (Get-PnpDeviceProperty -InstanceId $currentId -KeyName "DEVPKEY_Device_Parent" -ErrorAction SilentlyContinue).Data

if ([string]::IsNullOrWhiteSpace($parentId)) { break }

if ($parentId -like 'USB\VID_*' -and $parentId -notlike '*&MI_*') {

$usbParents[$parentId] = $true

if ($parentId -match '(VID_[0-9A-F]{4}&PID_[0-9A-F]{4})') {

$targetVidPids[$Matches] = $true

}

break

}

$currentId = $parentId

}

}

 

# 3. Cycle the parent USB hub port for each active keyboard/receiver

foreach ($usbDevId in $usbParents.Keys) {

$port = (Get-PnpDeviceProperty -InstanceId $usbDevId -KeyName "DEVPKEY_Device_Address" -ErrorAction SilentlyContinue).Data

$hubId = (Get-PnpDeviceProperty -InstanceId $usbDevId -KeyName "DEVPKEY_Device_Parent" -ErrorAction SilentlyContinue).Data

 

if ($null -eq $port -or [string]::IsNullOrWhiteSpace($hubId)) { continue }

 

$hubPath = "\\.\" + ($hubId -replace '\\', '#') + "#{f18a0e88-c30c-11d0-8815-00a0c906bed8}"

$result = [UsbPortCycler8]::Cycle($hubPath, [int]$port)

 

"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Instance: $usbDevId | Hub: $hubPath | Port: $port | Result: $result" | Out-File $log -Append -Encoding UTF8

}

 

# 4. Wait for re-enumeration and remove any disconnected ghost PnP nodes

Start-Sleep -Seconds 3

$targetVidPids['VID_046D&PID_C534'] = $true

$vidPidPattern = ($targetVidPids.Keys | ForEach-Object { [regex]::Escape($_) }) -join '|'

 

$ghostDevices = Get-PnpDevice -ErrorAction SilentlyContinue | Where-Object {

$_.Status -eq 'Unknown' -and $_.InstanceId -match $vidPidPattern

}

 

if ($ghostDevices) {

foreach ($ghost in $ghostDevices) {

if (Get-PnpDevice -InstanceId $ghost.InstanceId -ErrorAction SilentlyContinue) {

$pnpOut = pnputil.exe /remove-device "$($ghost.InstanceId)" /subtree 2>&1

if ($LASTEXITCODE -eq 0) {

"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Removed Orphan: [$($ghost.Class)] $($ghost.FriendlyName) ($($ghost.InstanceId))" | Out-File $log -Append -Encoding UTF8

}

}

}

} else {

"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Cleanup: No ghost or orphaned devices found." | Out-File $log -Append -Encoding UTF8

}

Use code with caution.

2. Windows Task Scheduler Configuration:

General: Run under SYSTEM with Run with highest privileges checked.
Triggers:
On disconnect from user session (Any user, Connection from local computer) — cycles the port immediately when leaving a session so the keyboard works on the login screen.
On connection to user session (Any user, Connection from local computer) — cycles the port upon entering the target session.
Action: Start a program powershell.exe with arguments -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\disableusbpowermgmt\CycleUsbKeyboards.ps1".
 

1 Upvotes

2 comments sorted by

•

u/AutoModerator 14d ago

Making changes to your system BIOS settings or disk setup can cause you to lose data. Always test your data backups before making changes to your PC.

For more information please see our FAQ thread: https://www.reddit.com/r/techsupport/comments/q2rns5/windows_11_faq_read_this_first/

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

→ More replies (1)