Earlysuspend sleep mode for Android-implementation code

Source: Internet
Author: User

(1) Add a header file:

# Include <Linux/earlysuspend. h>

(2) Add the early_suspend structure to the specific driver struct:

# Ifdef config_has_earlysuspend
Struct early_suspend;
# Endif

(3) register the early_suspend struct in the driver probe function:

# Ifdef config_has_earlysuspend
Ftk_ts-> early_suspend.level = early_suspend_level_blk_screen + 1;
Ftk_ts-> early_suspend.suspend = pai_ts_early_suspend;
Ftk_ts-> early_suspend.resume = pai_ts_late_resume;
Register_early_suspend (& ftk_ts-> early_suspend );
# Endif

All early_suspend structures registered to the system are added to the global linked list early_suspend_handlers in order of level values.

The device that wants to execute early suspend, his device driverProgramYou need to register with the power management system. This struct is used to register earlysuspend/lateresume with the power management system. When the power management system starts the suspend process, the callback function suspend will be called. On the contrary, in the final stage of resume, the callback function resume will be called. The level field is used to adjust the position of the struct in the registered linked list. During suspend,The smaller the level value, the earlier the callback function is called.And resume. Android pre-defines three levels:

 

 
Enum {region = 50, region = 100, region = 150,}; struct early_suspend {# ifdef config_has_earlysuspendstruct list_head link; int level; void (* suspend) (struct early_suspend * H ); void (* resume) (struct early_suspend * H); # endif };

 

(4) cancel the registration of the early_suspend struct in the drive Remove function:

# Ifdef config_has_earlysuspend
Unregister_early_suspend (& TS-> early_suspend );
# Endif

(5) define related suspend and resume functions:

# Ifdef config_has_earlysuspend
Static void pai_ts_early_suspend (struct early_suspend * H)
{
Struct ftk_ts * ts;
TS = container_of (H, struct ftk_ts, early_suspend );
Pai_ts_suspend (ts-> client, pmsg_suspend );
}

Static void pai_ts_late_resume (struct early_suspend * H)
{
Struct ftk_ts * ts;
TS = container_of (H, struct ftk_ts, early_suspend );
Cmd_ts_resume (ts-> client );
}
# Endif

(6) set the function interface that does not use earlysuspend in the system driver struct:

# Ifndef config_has_earlysuspend
. Suspend = pai_ts_suspend,
. Resume = pai_ts_resume,
# Endif

Related Article

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.