標籤:toc 結構 containe types 實現 alt title 特定 裝置驅動
本文轉載自:http://blog.csdn.net/MyArrow/article/details/8136018
(1)添加標頭檔:
#include <linux/earlysuspend.h>
(2)在特定驅動結構體中添加early_suspend結構:
#ifdef CONFIG_HAS_EARLYSUSPEND
struct early_suspend early_suspend;
#endif
(3)在驅動probe函數中註冊相關early_suspend結構體:
#ifdef CONFIG_HAS_EARLYSUSPEND
ftk_ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
ftk_ts->early_suspend.suspend = stm_ts_early_suspend;
ftk_ts->early_suspend.resume =stm_ts_late_resume;
register_early_suspend(&ftk_ts->early_suspend);
#endif
所有註冊到系統中的early_suspend結構都會按level值按順序加入到全域鏈表early_suspend_handlers中。
希望執行early suspend的裝置,他的裝置驅動程式需要向電源管理系統註冊,該結構體用於向電源管理系統註冊earlysuspend/lateresume,當電源管理系統啟動suspend流程時,回呼函數suspend會被調用,相反,resume的最後階段,回呼函數resume會被調用,level欄位用於調整該結構體在註冊鏈表中的位置,suspend時,level的數值越小,回呼函數的被調用的時間越早,resume時則反過來。Android預先定義了3個level等級:
[cpp] view plain copy
- enum {
- EARLY_SUSPEND_LEVEL_BLANK_SCREEN = 50,
- EARLY_SUSPEND_LEVEL_STOP_DRAWING = 100,
- EARLY_SUSPEND_LEVEL_DISABLE_FB = 150,
- };
- struct early_suspend {
- #ifdef CONFIG_HAS_EARLYSUSPEND
- struct list_head link;
- int level;
- void (*suspend)(struct early_suspend *h);
- void (*resume)(struct early_suspend *h);
- #endif
- };
(4)在驅動remove函數取消early_suspend結構體的註冊:
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&ts->early_suspend);
#endif
(5)定義相關suspend和resume函數:
#ifdef CONFIG_HAS_EARLYSUSPEND
static void stm_ts_early_suspend(struct early_suspend *h)
{
struct ftk_ts *ts;
ts = container_of(h, struct ftk_ts, early_suspend);
stm_ts_suspend(ts->client, PMSG_SUSPEND);
}
static void stm_ts_late_resume(struct early_suspend *h)
{
struct ftk_ts *ts;
ts = container_of(h, struct ftk_ts, early_suspend);
stm_ts_resume(ts->client);
}
#endif
(6)在系統驅動結構體中設定未使用earlysuspend的函數介面:
#ifndef CONFIG_HAS_EARLYSUSPEND
.suspend = stm_ts_suspend,
.resume = stm_ts_resume,
#endif
Android驅動開發之earlysuspend睡眠模式--實現代碼【轉】