Reputation: 991
I observed that the whole device topology is based on Buses --> Device + Driver
. The power management offered by linux (suspend + resume)
is present in bus. And similar functionality is there in device driver.
struct bus_type { ***
int (*suspend)(struct device *dev, pm_message_t state);
int (*resume)(struct device *dev);
*** }
struct device_driver { ***
int (*suspend) (struct device *dev, pm_message_t state);
int (*resume) (struct device *dev);
*** }
So how is this implemented?
Upvotes: 2
Views: 1193
Reputation: 991
I searched a lot and finally got my answer in Documentation:
To ensure that bridges and similar links needing to talk to a device are available when the device is suspended or resumed, the device tree is walked in a bottom-up order to suspend devices. A top-down order is used to resume those devices.
The ordering of the device tree is defined by the order in which devices get registered: a child can never be registered, probed or resumed before its parent; and can't be removed or suspended after that parent.
The policy is that the device tree should match hardware bus topology.
And regarding the bus and device suspend and resume callback:
All phases use bus, type, or class callbacks (that is, methods defined in dev->bus->pm, dev->type->pm, or dev->class->pm).
These callbacks are mutually exclusive, so if the device type provides a struct dev_pm_ops object pointed to by its pm field (i.e. both dev->type and dev->type->pm are defined), the callbacks included in that object (i.e. dev->type->pm) will be used. Otherwise, if the class provides a struct dev_pm_ops object pointed to by its pm field (i.e. both dev->class and dev->class->pm are defined), the PM core will use the callbacks from that object (i.e. dev->class->pm).
Finally, if the pm fields of both the device type and class objects are NULL (or those objects do not exist), the callbacks provided by the bus (that is, the callbacks from dev->bus->pm) will be used (this allows device types to override callbacks provided by bus types or classes if necessary).
Upvotes: 1