大家好,又见面了,我是你们的朋友全栈君。
(1)添加头文件:
#include “core.h”
在core.h文件中有:
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
(2)在wifi驱动ath6kl结构体中添加early_suspend结构:
#ifdef CONFIG_HAS_EARLYSUSPEND
struct early_suspend early_suspend;
bool screen_off;
#endif
(3)在wifi驱动的电源管理文件pm.c中填充early_suspend结构体,并将其向android电源管理系统注册:
#ifdef CONFIG_HAS_EARLYSUSPEND
ar->screen_off = false;
ar->early_suspend.suspend = ath6kl_early_suspend;
ar->early_suspend.resume = ath6kl_late_resume;
ar->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN;
register_early_suspend(&ar->early_suspend);
#endif
所有注册到系统中的early_suspend结构都会按level值按顺序加入到全局链表early_suspend_handlers中。
希望执行early suspend的设备,他的设备驱动程序需要向电源管理系统注册,该结构体用于向电源管理系统注册earlysuspend/lateresume,当电源管理系统启动suspend流程时,回调函数suspend会被调用,相反,resume的最后阶段,回调函数resume会被调用,level字段用于调整该结构体在注册链表中的位置,suspend时,level的数值越小,回调函数的被调用的时间越早,resume时则反过来。
Android在earlysuspend.h中预先定义了3个level等级:
enum {
EARLY_SUSPEND_LEVEL_BLANK_SCREEN = 50,
EARLY_SUSPEND_LEVEL_STOP_DRAWING = 100,
EARLY_SUSPEND_LEVEL_DISABLE_FB = 150,
};
具体请见附件kernel/include/linux/earlysuspend.h
(4)在wifi驱动电源管理文件pm.c中取消early_suspend结构体的注册:
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&ar->early_suspend);
#endif
(5)定义相关suspend和resume函数:
#ifdef CONFIG_HAS_EARLYSUSPEND
static void ath6kl_early_suspend(struct early_suspend *handler) { struct ath6kl *ar = container_of(handler, struct ath6kl, early_suspend); if (ar) ar->screen_off = true; } static void ath6kl_late_resume(struct early_suspend *handler) { struct ath6kl *ar = container_of(handler, struct ath6kl, early_suspend); if (ar) ar->screen_off = false; } #endif 附:kernel/include/linux/earlysuspend.h #ifndef _LINUX_EARLYSUSPEND_H #define _LINUX_EARLYSUSPEND_H #ifdef CONFIG_HAS_EARLYSUSPEND #include <linux/list.h> #endif /* The early_suspend structure defines suspend and resume hooks to be called * when the user visible sleep state of the system changes, and a level to * control the order. They can be used to turn off the screen and input * devices that are not used for wakeup. * Suspend handlers are called in low to high level order, resume handlers are * called in the opposite order. If, when calling register_early_suspend, * the suspend handlers have already been called without a matching call to the * Suspend handlers are called in low to high level order, resume handlers are * called in the opposite order. If, when calling register_early_suspend, * the suspend handlers have already been called without a matching call to the * resume handlers, the suspend handler will be called directly from * register_early_suspend. This direct call can violate the normal level order. */ 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 }; #ifdef CONFIG_HAS_EARLYSUSPEND void register_early_suspend(struct early_suspend *handler); void unregister_early_suspend(struct early_suspend *handler); #else #define register_early_suspend(handler) do { } while (0) #define unregister_early_suspend(handler) do { } while (0) #endif #endif
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/192266.html原文链接:https://javaforall.cn