• Lv0
    粉丝1

积分19 / 贡献0

提问1答案被采纳0文章1

作者动态

[经验分享] DozeResume/DozeSuspend Resume/Suspend 的区别

刘允礼 显示全部楼层 发表于 2024-6-3 16:17:33
HdfTouch的驱动代码,发现只注册了DozeResume  /DozeSuspend ,没有使用 Resume /Suspend
static void HdfTouchDriverRegisterPowerListener(struct HdfDeviceObject *device)
{
    int ret;
    static struct IPowerEventListener powerListener = {0};
    HDF_LOGI("%s::enter!", __func__);
    powerListener.DozeResume = HdfTouchDriverDozeResume;
    powerListener.DozeSuspend = HdfTouchDriverDozeSuspend;
    powerListener.Resume = NULL;
    powerListener.Suspend = NULL;

    ret = HdfPmRegisterPowerListener(device, &powerListener);
    HDF_LOGI("%s:register power listener, ret = %d", __func__, ret);
}
检查IPowerEventListener 接口,并没有关于DozeSuspend  和 Suspend  区别的详细介绍。
struct IPowerEventListener {
    int (*DozeResume)(struct HdfDeviceObject *deviceObject);
    int (*DozeSuspend)(struct HdfDeviceObject *deviceObject);
    /** Wakes up the driver device. The driver developer implements the operation. */
    int (*Resume)(struct HdfDeviceObject *deviceObject);
    /** Hibernates the driver device. The driver developer implements the operation. */
    int (*Suspend)(struct HdfDeviceObject *deviceObject);
};
反查IPowerEventListener  代码
int PowerStateChange(struct PowerStateToken *stateToken, uint32_t pEvent)
{
    switch (pEvent) {
        case POWER_STATE_SUSPEND:
                return stateToken->listener->Suspend(stateToken->deviceObject);
        case POWER_STATE_RESUME:
                return stateToken->listener->Resume(stateToken->deviceObject);
        case POWER_STATE_DOZE_SUSPEND:
                return stateToken->listener->DozeSuspend(stateToken->deviceObject);
        case POWER_STATE_DOZE_RESUME:
                return stateToken->listener->DozeResume(stateToken->deviceObject);
    }
}
PowerStateChange根据 POWER_STATE 的不同调用不同的函数接口。
再继续查
static int32_t KernalSpacePmNotify(int32_t powerEvent)
{
    switch (powerEvent) {
        case KEVENT_POWER_SUSPEND:
            pmStatus = POWER_STATE_SUSPEND;
        case KEVENT_POWER_DISPLAY_OFF:
            pmStatus = POWER_STATE_DOZE_SUSPEND;
        case KEVENT_POWER_RESUME:
            pmStatus = POWER_STATE_RESUME;
        case KEVENT_POWER_DISPLAY_ON:
            pmStatus = POWER_STATE_DOZE_RESUME;
    }
    return devmgrClnt->devMgrSvcIf->PowerStateChange(devmgrClnt->devMgrSvcIf, pmStatus);
}
由KernalSpacePmNotify根据 KEVENT_POWER 走不同的分支。这里就能能看到 KEVENT_POWER_DISPLAY_OFF 走到了 POWER_STATE_DOZE_SUSPEND,KEVENT_POWER_SUSPEND 走到了 POWER_STATE_SUSPEND。

int32_t KeventFbNotifierFn(struct notifier_block *nb, unsigned long event, void *data)
{
    keventModule = CONTAINER_OF(nb, struct HdfKeventModule, fbNotifier);
    blank = fbEvent->data;
    if (*blank == FB_BLANK_UNBLANK) {
        powerEvent = KEVENT_POWER_DISPLAY_ON;
    } else {
        HDF_LOGI("%s:receive display off event", __func__);
        powerEvent = KEVENT_POWER_DISPLAY_OFF;

    ret = SendKevent(keventModule, HDF_SYSEVENT_CLASS_POWER, powerEvent, NULL, sync);
    return KernalSpacePmNotify(powerEvent);
}

static int32_t KeventPmNotifierFn(struct notifier_block *nb, unsigned long action, void *dummy)
{
      keventModule = CONTAINER_OF(nb, struct HdfKeventModule, keventPmNotifier);
    switch (action) {
        case PM_SUSPEND_PREPARE:
            powerEvent = KEVENT_POWER_SUSPEND;
        case PM_POST_SUSPEND:
            powerEvent = KEVENT_POWER_RESUME;
    }
    ret = SendKevent(keventModule, HDF_SYSEVENT_CLASS_POWER, powerEvent, NULL, sync);
    return KernalSpacePmNotify(powerEvent);
}


©著作权归作者所有,转载或内容合作请联系作者

您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部