通過SIMPLE_DEV_PM_OPS定義suspend和resume函式【轉】
本文轉載自:https://blog.csdn.net/tiantao2012/article/details/77851782
通過SIMPLE_DEV_PM_OPS 定義這個驅動的suspend和resume函式,如果沒有定義CONFIG_PM_SLEEP的時候就將CONFIG_PM_SLEEP定義為空函式,這樣可以避免build error
static SIMPLE_DEV_PM_OPS(asic3_led_pm_ops, asic3_led_suspend, asic3_led_resume);
static struct platform_driver asic3_led_driver = {
.probe = asic3_led_probe,
.remove = asic3_led_remove,
.driver = {
.name = "leds-asic3",
.pm = &asic3_led_pm_ops,
},
};
SIMPLE_DEV_PM_OPS 定義如下:
#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
const struct dev_pm_ops name = { \
SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
}
如果定義CONFIG_PM_SLEEP的話,就給suspend和resume的函式指標賦值
#ifdef CONFIG_PM_SLEEP
#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
.suspend = suspend_fn, \
.resume = resume_fn, \
.freeze = suspend_fn, \
.thaw = resume_fn, \
.poweroff = suspend_fn, \
.restore = resume_fn,
#else
#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
#endif
可以看到如果沒有定義CONFIG_PM_SLEEP的話,SIMPLE_DEV_PM_OPS 就相當於空函式
#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
const struct dev_pm_ops name = { \
---------------------
作者:tiantao2012
來源:CSDN
原文:https://blog.csdn.net/tiantao2012/article/details/77851782
版權宣告:本文為博主原創文章,轉載請附上博文連結!