Android wifi驱动之earlysuspend睡眠模式

1)添加头文件:

        #include "core.h"

       在core.h文件中有:

        #ifdef CONFIG_HAS_EARLYSUSPEND

              #include 

        #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预先定义了3level等级

       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)定义相关suspendresume函数:

       #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 

#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

你可能感兴趣的:(wifi专题)