power: add hal interface and getter wakeup reason 38/284938/9 accepted/tizen/unified/20221220.180326
authorTaeminYeom <taemin.yeom@samsung.com>
Thu, 1 Dec 2022 09:07:44 +0000 (18:07 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Fri, 16 Dec 2022 08:05:27 +0000 (17:05 +0900)
Add power hal interface including getter wakeup reason function.

"wakeup reason" is the power transition state reason of sleep to normal.
There are several reasons why the device wakeup such as power key, Wifi and touchscreen.
Sometimes it Is needed to get the reason.

hal-interface
- hal_backend_device_power_funcs
- hal_device_power_get_backend
- hal_device_power_put_backend

function
- hal_device_power_get_wakeup_reason

enum
hal_device_power_wakeup_reason
  It is same value with "device_power_transition_reason_e" in device API

  HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN                : Unknown reason
  HAL_DEVICE_POWER_TRANSITION_REASON_POWER_KEY              : Power key pressed
  HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_NORMAL_LEVEL   : Battery capacity reaches normal level
  HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_WARNING_LEVEL  : Battery capacity reaches warning level
  HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_CRITICAL_LEVEL : Battery capacity reaches critical level
  HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_POWEROFF_LEVEL : Battery capacity reaches poweroff level
  HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF            : Display off
  HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_KEY              : Touch key pressed
  HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_SCREEN           : Touch screen pressed
  HAL_DEVICE_POWER_TRANSITION_REASON_USB                    : USB attached or detached
  HAL_DEVICE_POWER_TRANSITION_REASON_CHARGER                : Charger attached or detached
  HAL_DEVICE_POWER_TRANSITION_REASON_WIFI                   : WIFI event
  HAL_DEVICE_POWER_TRANSITION_REASON_BLUETOOTH              : Bluetooth event
  HAL_DEVICE_POWER_TRANSITION_REASON_AUDIO                  : Audio event
  HAL_DEVICE_POWER_TRANSITION_REASON_ALARM                  : Alarm event
  HAL_DEVICE_POWER_TRANSITION_REASON_SENSOR                 : Sensor event
  HAL_DEVICE_POWER_TRANSITION_REASON_RTC                    : RTC event
  HAL_DEVICE_POWER_TRANSITION_REASON_HEADSET                : Headset attatched or detached or button pressed
  HAL_DEVICE_POWER_TRANSITION_REASON_EXTERNAL_MEMORY        : External memory inserted or deleted
  HAL_DEVICE_POWER_TRANSITION_REASON_DOWNLOAD               : Download event

Change-Id: I4580b6b336f6f081d45315bc786d1e92c00d790b
Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
include/backend/hal-device-power-interface.h [new file with mode: 0644]
include/hal-device-power.h [new file with mode: 0644]
src/power.c [new file with mode: 0644]

diff --git a/include/backend/hal-device-power-interface.h b/include/backend/hal-device-power-interface.h
new file mode 100644 (file)
index 0000000..fd3dd5f
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __HAL_DEVICE_POWER_INTERFACE_H__
+#define __HAL_DEVICE_POWER_INTERFACE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum hal_device_power_transition_reason {
+       HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN,
+       HAL_DEVICE_POWER_TRANSITION_REASON_POWER_KEY,
+       HAL_DEVICE_POWER_TRANSITION_REASON_VOLUME_UP_KEY,
+       HAL_DEVICE_POWER_TRANSITION_REASON_VOLUME_DOWN_KEY,
+       HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_NORMAL_LEVEL,
+       HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_WARNING_LEVEL,
+       HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_CRITICAL_LEVEL,
+       HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_POWEROFF_LEVEL,
+       HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF,
+       HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_KEY,
+       HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_SCREEN,
+       HAL_DEVICE_POWER_TRANSITION_REASON_USB,
+       HAL_DEVICE_POWER_TRANSITION_REASON_CHARGER,
+       HAL_DEVICE_POWER_TRANSITION_REASON_HDMI,
+       HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_PORT,
+       HAL_DEVICE_POWER_TRANSITION_REASON_EMBEDDED_DISPLAY_PORT,
+       HAL_DEVICE_POWER_TRANSITION_REASON_WIFI,
+       HAL_DEVICE_POWER_TRANSITION_REASON_BLUETOOTH,
+       HAL_DEVICE_POWER_TRANSITION_REASON_NFC,
+       HAL_DEVICE_POWER_TRANSITION_REASON_TELEPHONY,
+       HAL_DEVICE_POWER_TRANSITION_REASON_ZIGBEE,
+       HAL_DEVICE_POWER_TRANSITION_REASON_ETHERNET,
+       HAL_DEVICE_POWER_TRANSITION_REASON_AUDIO,
+       HAL_DEVICE_POWER_TRANSITION_REASON_ALARM,
+       HAL_DEVICE_POWER_TRANSITION_REASON_SENSOR,
+       HAL_DEVICE_POWER_TRANSITION_REASON_RTC,
+       HAL_DEVICE_POWER_TRANSITION_REASON_HEADSET,
+       HAL_DEVICE_POWER_TRANSITION_REASON_EXTERNAL_MEMORY,
+
+       HAL_DEVICE_POWER_TRANSITION_REASON_CUSTOM = 1000,       /**< Define custom reason from here */
+};
+
+typedef struct _hal_backend_device_power_funcs {
+       int (*get_wakeup_reason)(enum hal_device_power_transition_reason *reason);
+} hal_backend_device_power_funcs;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_DEVICE_POWER_INTERFACE_H__ */
diff --git a/include/hal-device-power.h b/include/hal-device-power.h
new file mode 100644 (file)
index 0000000..5c81144
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __HAL_DEVICE_POWER_H__
+#define __HAL_DEVICE_POWER_H__
+
+#include "hal-device-power-interface.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_device_power_get_backend(void);
+int hal_device_power_put_backend(void);
+int hal_device_power_get_wakeup_reason(enum hal_device_power_transition_reason *reason);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  // __HAL_DEVICE_POWER_H__
diff --git a/src/power.c b/src/power.c
new file mode 100644 (file)
index 0000000..cb03720
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hal/hal-common.h>
+
+#include "hal-device-power-interface.h"
+#include "common.h"
+
+static hal_backend_device_power_funcs *hal_device_power_funcs = NULL;
+static int hal_initialized = HAL_INITIALIZED_NOT;
+
+int hal_device_power_get_backend(void)
+{
+       int ret;
+       if (hal_device_power_funcs)
+               return 0;
+
+       ret = hal_common_get_backend(HAL_MODULE_DEVICE_POWER, (void **)&hal_device_power_funcs);
+       if (ret < 0) {
+               _E("Failed to get device power backend");
+               hal_initialized = HAL_INITIALIZED_FAILED;
+               return ret;
+       }
+
+       hal_initialized = HAL_INITIALIZED_SUCCEEDED;
+       return 0;
+}
+
+int hal_device_power_put_backend(void)
+{
+       int ret;
+       if (!hal_device_power_funcs)
+               return 0;
+
+       ret = hal_common_put_backend(HAL_MODULE_DEVICE_POWER, (void *)hal_device_power_funcs);
+       if (ret < 0) {
+               _E("Failed to put device power backend");
+               return ret;
+       }
+
+       hal_device_power_funcs = NULL;
+       hal_initialized = HAL_INITIALIZED_NOT;
+
+       return 0;
+}
+
+int hal_device_power_get_wakeup_reason(enum hal_device_power_transition_reason *reason)
+{
+       int ret;
+
+       if (!hal_device_power_funcs && !hal_initialized) {
+               if ((ret = hal_device_power_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_device_power_funcs ||
+           !hal_device_power_funcs->get_wakeup_reason)
+               return -ENODEV;
+
+       return hal_device_power_funcs->get_wakeup_reason(reason);
+}