The code is located in power/suspend. C, starting with the pm_suspend function.
The logic of suspend and driver is mainly to traverse all devices and call the suspend function pointer of their related driver (including the suspend function pointer of the device class and bus ).
The order of device calls is as follows: when we execute device_add, these devices will be added to a dpm_list list, the device added later will appear in the front of the list. That is to say, the device added earlier will be suspend later, and the device added later will be suspend first.
Resume is the opposite. The added device will be resume first.
When suspend is a device, these function pointers are called in sequence: The power domain to which the device belongs, the type of the device, the class to which the device belongs, and the bus to which the device belongs.
Before the preceding logic, a call named suspend_prepare will be called. Here, freeze userspace (it will be OK if it is not schedule) will freeze workqueue with the freezable attribute. After the above logic, the kernel will go to the arch layer to continue the suspend action. Each arch is used here, and each Mach is different. In this case, we usually perform operations such as state saving, clock gate, power gate, and prepare CPU reset handler for specific hardware.