在platform_device_register()中調用device_initialize(),
在device_initialize()中調用device_pm_init(),
device_pm_init() 在drivers/base/power/main.c裡, 詳細如下:
/**
* device_pm_init - Initialize the PM-related part of a device object.
* @dev: Device object being initialized.
*/
void device_pm_init(struct device *dev) // 此函數初始化device的power域
{
dev->power.is_prepared = false;
dev->power.is_suspended = false;
init_completion(&dev->power.completion);
complete_all(&dev->power.completion);
dev->power.wakeup = NULL;
spin_lock_init(&dev->power.lock);
pm_runtime_init(dev); //此函數在drivers/base/power/runtime.c裡,難道就是傳說中的runtime core?
INIT_LIST_HEAD(&dev->power.entry);
}
初始化power域後power域如下
然後,
在device_add()中會調用dpm_sysfs_add()向sysfs檔案系統中添加相應裝置的power介面,此函數在/drivers/base/power/sysfs.c中
再調用device_pm_add(),此函數在driver/base/power/main.c中,
void device_pm_add(struct device *dev)
{
pr_debug("PM: Adding info for %s:%s\n",
dev->bus ? dev->bus->name : "No Bus", dev_name(dev));
mutex_lock(&dpm_list_mtx);
if (dev->parent && dev->parent->power.is_prepared) //如果有父裝置,如果父裝置的power.is_prepared為false, 則不允許此子裝置註冊, 這點跟參考文章出的大同小異
dev_warn(dev, "parent %s should not be sleeping\n",
dev_name(dev->parent));
list_add_tail(&dev->power.entry, &dpm_list); //將device結構體通過power.entry添加到裝置電源管理鏈dpm_list裡
mutex_unlock(&dpm_list_mtx);
}
參考:http://blog.csdn.net/coolraining/article/details/6678759