Android Driver Development Earlysuspend sleep mode-Implementation code "go"

Source: Internet
Author: User

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
  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) 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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.