power: resource: Add new DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK 56/297356/2
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 17 Aug 2023 06:24:00 +0000 (15:24 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 17 Aug 2023 09:38:40 +0000 (18:38 +0900)
DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK attribute provides the
setter function to acquire the wakelock in order to prevent the suspending.

[Detailed description of newly added attribute]
- attr id   : DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK
- setter    : O
- getter    : X
- 1st param : Event ID
- 2nd param : Timeout to release the wakelock count

Change-Id: I9ffdecac5ddd538b22ae2cd9397abb0fe93dd98a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/power/resource-power.c

index fedd659..4ad739d 100644 (file)
@@ -73,6 +73,50 @@ static int get_wakeup_reason(int resource_id,
        return 0;
 }
 
+/**
+ * FIXME: After developing the power abstraction layer, this attribute should
+ * be fixed. Because the suspend-to-ram supports both echo-mem and wakelock
+ * style without any different external interface.
+ */
+static int g_wakelock_counter;
+static gboolean event_release_wakelock(gpointer data)
+{
+       if (g_wakelock_counter < 0)
+               return G_SOURCE_REMOVE;
+
+       --g_wakelock_counter;
+
+       if (g_wakelock_counter == 0)
+               syscommon_notifier_emit_notify(DEVICED_NOTIFIER_EVENT_RELEASE_WAKELOCK, NULL);
+
+       return G_SOURCE_REMOVE;
+}
+
+static int set_wakelock(int resource_id, const struct syscommon_resman_resource_attribute *attr,
+       const void *data1, const void *data2, int count1, int count2)
+{
+       uint64_t event_id;
+       uint64_t timeout;
+
+       if (!data1 || !data2)
+               return -EINVAL;
+
+       event_id = *(uint64_t *) data1;
+       timeout = *(uint64_t *) data2;
+
+       if (timeout <= 0)
+               return -EINVAL;
+
+       ++g_wakelock_counter;
+
+       g_timeout_add_seconds(timeout, event_release_wakelock, (gpointer)(intptr_t) event_id);
+
+       if (g_wakelock_counter == 1)
+               syscommon_notifier_emit_notify(DEVICED_NOTIFIER_EVENT_ACQUIRE_WAKELOCK, NULL);
+
+       return 0;
+}
+
 static const struct syscommon_resman_resource_attribute power_attrs[] = {
        {
                .name = "DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE",
@@ -101,6 +145,15 @@ static const struct syscommon_resman_resource_attribute power_attrs[] = {
                        .get = get_wakeup_reason,
                        .is_supported = syscommon_resman_resource_attr_supported_always,
                },
+       }, {
+               .name = "DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK",
+               .id = DEVICED_POWER_ATTR_TUPLE2_SET_WAKELOCK,
+               .type = SYSCOMMON_RESMAN_DATA_TYPE_UINT64_UINT64,
+               .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
+               .ops = {
+                       .set_2_tuple = set_wakelock,
+                       .is_supported = syscommon_resman_resource_attr_supported_always,
+               },
        }
 };