Android驅動開發之earlysuspend睡眠模式--實現代碼【轉】

來源:互聯網
上載者:User

標籤: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 
  1. enum {  
  2.     EARLY_SUSPEND_LEVEL_BLANK_SCREEN = 50,  
  3.     EARLY_SUSPEND_LEVEL_STOP_DRAWING = 100,  
  4.     EARLY_SUSPEND_LEVEL_DISABLE_FB = 150,  
  5. };  
  6. struct early_suspend {  
  7. #ifdef CONFIG_HAS_EARLYSUSPEND  
  8.     struct list_head link;  
  9.     int level;  
  10.     void (*suspend)(struct early_suspend *h);  
  11.     void (*resume)(struct early_suspend *h);  
  12. #endif  
  13. };  

 

(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睡眠模式--實現代碼【轉】

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.