This article was reproduced from: http://blog.csdn.net/MyArrow/article/details/8136018
(1) Add header file:
#include <linux/earlysuspend.h>
(2) Adding a early_suspend structure to a specific drive structure:
#ifdef Config_has_earlysuspend
struct Early_suspend early_suspend;
#endif
(3) Registering the relevant early_suspend structure in the driver probe function:
#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
All early_suspend structures registered to the system are added sequentially to the global list early_suspend_handlers by level values.
To perform a early suspend device, his device driver needs to register with the Power management system, which is used to register earlysuspend/lateresume with the Power management system, and when the power management system initiates the suspend process, The callback function suspend is called, instead, in the final stage of the resume, the callback function resume is called, and the Level field is used to adjust the position of the struct in the registered list, and when suspend, the lower the number of levels, the sooner the callback function is called. Resume is the reverse. Android has pre-defined 3 levels:
[CPP]View PlainCopy
- 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) In the drive remove function cancels the registration of the Early_suspend struct:
#ifdef Config_has_earlysuspend
Unregister_early_suspend (&ts->early_suspend);
#endif
(5) Define the relevant suspend and resume functions:
#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) Set up a function interface in the system-driven structure that does not use Earlysuspend:
#ifndef Config_has_earlysuspend
. Suspend = Stm_ts_suspend,
. Resume = Stm_ts_resume,
#endif
Android-powered Earlysuspend Sleep mode-Implementing code "go"