Can USB device detect if upstream/root is suspended?
Can USB device detect if upstream/root is suspended?


A USB device not only can, it must detect if the upstream port is suspended. This is a mandatory requirement from specs. The way USB devices detect if the bus is suspended is to check for bus activity. This is unconditionally true for USB 2.0 modes, and effectively true for USB 3.x super-speed modes. And you are right, VBUS will stay always on during sleep modes (which also depends on design).

However, there is one caveat in your approach: your fan must be an enumerable USB device to determine this and keep spinning when your hub (or root port) in not suspended. The thing is that even if you try to fake the USB2.0 connect with a simple pull-up resistor and make the host to react, it will try few times to reset the port and attempt to enumerate it, but if there is no real device, the host will give up and will disable the port, so your device will turn itself off.

The other caveat is that in modern laptop designs (and in old desktops) the OS will suspend the hub if there is no active USB devices. In modern laptops the external hubs will be suspended and mice-keyboards behind them will be suspended if no activity is detected. The hub will wake up if you move a mouse or press a key, with some extra lag. The functionality, however, depends on general power management setting for individual ports and devices.

So you have basically two options:


make your fan with some real USB IC controller, with ability to detect SUSPEND state over some GPIO.
make a pass-through sniffer on usb cable (using high-impedance CMOS mini-gates on D+/D- lines as activity sensors), and make a simple micro-controller to detect bus inactivity for, say 10 ms. Specification says that after 3 ms of inactivity (lost frame packets) every device must enter SUSPEND. So, if you make a sniffer device to test for inactivity, you will be able to turn your fan off. (your fan can take power from the same sniffer btw)


But again, in many cases the USB bus might be suspended while the laptop itself not, see the caveat above. So your mileage can vary.