在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
",
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
",
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