• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <los_pm.h>
32 #include "devmgr_service.h"
33 #include "hdf_base.h"
34 #include "hdf_log.h"
35 
36 #define HDF_LOG_TAG devmgr_pm
37 
DevmgrPmSuspend(UINT32 mode)38 UINT32 DevmgrPmSuspend(UINT32 mode)
39 {
40     if (mode != LOS_SYS_LIGHT_SLEEP) {
41         HDF_LOGI("%s: hdf Suspend %d", __func__, mode);
42     }
43 
44     HDF_LOGI("%s hdf suspend start", __func__);
45     struct IDevmgrService *devmgrService = DevmgrServiceGetInstance();
46     if (devmgrService == NULL) {
47         return LOS_NOK;
48     }
49 
50     if (devmgrService->PowerStateChange(devmgrService, POWER_STATE_SUSPEND) != HDF_SUCCESS) {
51         HDF_LOGE("%s drivers suspend failed", __func__);
52         devmgrService->PowerStateChange(devmgrService, POWER_STATE_RESUME);
53         return LOS_NOK;
54     }
55 
56     HDF_LOGI("%s hdf suspend done", __func__);
57     return LOS_OK;
58 }
59 
DevmgrPmResume(UINT32 mode)60 void DevmgrPmResume(UINT32 mode)
61 {
62     if (mode != LOS_SYS_LIGHT_SLEEP) {
63         HDF_LOGI("%s: hdf resume %d", __func__, mode);
64     }
65 
66     HDF_LOGI("%s hdf resume start", __func__);
67     struct IDevmgrService *devmgrService = DevmgrServiceGetInstance();
68     if (devmgrService == NULL) {
69         return;
70     }
71 
72     devmgrService->PowerStateChange(devmgrService, POWER_STATE_RESUME);
73     HDF_LOGI("%s hdf resume done", __func__);
74 }
75 
DevMgrPmRegister(void)76 int DevMgrPmRegister(void)
77 {
78     static LosPmDevice pmOpt = {
79         .suspend = DevmgrPmSuspend,
80         .resume = DevmgrPmResume,
81     };
82 
83     HDF_LOGI("%s hdf enter", __func__);
84 
85     if (LOS_PmRegister(LOS_PM_TYPE_DEVICE, &pmOpt) != 0) {
86         HDF_LOGE("failed to register los pm opt");
87         return HDF_FAILURE;
88     }
89     return HDF_SUCCESS;
90 }
91 
92