55CHESTNUT_USB_IDS = ((0xADD1 , 0x0001 ), (0x3801 , 0x0001 ))
66CHESTNUT_ROM_USB_IDS = ((0x174C , 0x2464 ), (0x174C , 0x2463 ))
77USB_DEVICES_PATH = Path ("/sys/bus/usb/devices" )
8+ TYPEC_CC_ORIENTATION_PATH = Path ("/sys/class/power_supply/usb/typec_cc_orientation" )
9+ PRIMARY_USB_CONTROLLER = "a600000.ssusb"
810
911
1012def get_usb_topology () -> set [str ]:
@@ -45,6 +47,7 @@ def controller(device: Path) -> Path | None:
4547
4648def get_usb_state () -> list [dict ]:
4749 devices = []
50+ typec_orientation = read_int (TYPEC_CC_ORIENTATION_PATH )
4851 for device in usb_devices ():
4952 vendor_id = read_int (device / "idVendor" , 16 )
5053 product_id = read_int (device / "idProduct" , 16 )
@@ -58,6 +61,7 @@ def get_usb_state() -> list[dict]:
5861 "manufacturer" : read (device / "manufacturer" ) or "" ,
5962 "product" : read (device / "product" ) or "" ,
6063 "linkErrorCount" : read_int (ctrl / "portli" , 0 ) & 0xFFFF if ctrl is not None else 0 ,
64+ "usb3Lane" : {1 : "a" , 2 : "b" }.get (typec_orientation , "unknown" ) if ctrl is not None and ctrl .name == PRIMARY_USB_CONTROLLER else "unknown" ,
6165 })
6266 return devices
6367
@@ -75,6 +79,7 @@ def set_usb_state(device_state, devices: list[dict]) -> None:
7579 entry .manufacturer = device ["manufacturer" ]
7680 entry .product = device ["product" ]
7781 entry .linkErrorCount = device ["linkErrorCount" ]
82+ entry .usb3Lane = device .get ("usb3Lane" , "unknown" )
7883
7984 if (entry .vendorId , entry .productId ) in CHESTNUT_USB_IDS :
8085 chestnut_present = True
0 commit comments