1 /*
2 * devmgr_pm.c
3 *
4 * HDF power manager of linux
5 *
6 * Copyright (c) 2021 Huawei Device Co., Ltd.
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19 #include <linux/notifier.h>
20 #include <linux/suspend.h>
21
22 #include "devmgr_service.h"
23 #include "hdf_base.h"
24 #include "hdf_log.h"
25
26 #define HDF_LOG_TAG devmgr_pm
27
DevmgrPmSuspend(void)28 static int DevmgrPmSuspend(void)
29 {
30 HDF_LOGD("%s enter", __func__);
31 struct IDevmgrService *devmgrService = DevmgrServiceGetInstance();
32 if (devmgrService == NULL) {
33 return HDF_FAILURE;
34 }
35
36 if (devmgrService->PowerStateChange(devmgrService, POWER_STATE_SUSPEND) != HDF_SUCCESS) {
37 HDF_LOGE("%s drivers suspend failed", __func__);
38 devmgrService->PowerStateChange(devmgrService, POWER_STATE_RESUME);
39 return HDF_FAILURE;
40 }
41
42 return HDF_SUCCESS;
43 }
44
DevmgrPmResume(void)45 static int DevmgrPmResume(void)
46 {
47 HDF_LOGD("%s enter", __func__);
48 struct IDevmgrService *devmgrService = DevmgrServiceGetInstance();
49 if (devmgrService == NULL) {
50 return HDF_FAILURE;
51 }
52
53 devmgrService->PowerStateChange(devmgrService, POWER_STATE_RESUME);
54 HDF_LOGD("%s resume done", __func__);
55 return HDF_SUCCESS;
56 }
57
DevmgrPmNotifier(struct notifier_block * nb,unsigned long mode,void * data)58 static int DevmgrPmNotifier(struct notifier_block *nb, unsigned long mode, void *data)
59 {
60 int ret = HDF_SUCCESS;
61 switch (mode) {
62 case PM_SUSPEND_PREPARE:
63 ret = DevmgrPmSuspend();
64 break;
65 case PM_POST_SUSPEND:
66 ret = DevmgrPmResume();
67 break;
68 default:
69 break;
70 }
71 return ret;
72 }
73 static struct notifier_block PmNotifier = {
74 .notifier_call = DevmgrPmNotifier,
75 };
76
DevMgrPmRegister(void)77 int DevMgrPmRegister(void)
78 {
79 int ret;
80
81 HDF_LOGD("%s enter", __func__);
82 ret = register_pm_notifier(&PmNotifier);
83 if (ret) {
84 HDF_LOGE("%s register_pm_notifier failed", __func__);
85 }
86
87 return ret;
88 }
89 EXPORT_SYMBOL(DevMgrPmRegister);
90