Merge "[Feature][T106]version update to T106-V2.01.01.02P56U09.AP.17.07_CAP.17.07"
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-autosuspend/autosuspend_wakeup_count.c b/cap/zx297520v3/src/lynq/framework/lynq-autosuspend/autosuspend_wakeup_count.c
index 6a235b3..48cbe12 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-autosuspend/autosuspend_wakeup_count.c
+++ b/cap/zx297520v3/src/lynq/framework/lynq-autosuspend/autosuspend_wakeup_count.c
@@ -378,7 +378,7 @@
 #endif
 
 #ifdef MOBILETEK_SUSPEND_CFG
-int t800_early_suspend(char *wakeup_count, int wakeup_count_len)
+int t800_early_suspend(void)
 {
     char buf[80];
     system("echo \"Sys standby mode\" >/dev/console");
@@ -398,15 +398,6 @@
     RLOGD("TIME: sys to rtc\n");
     lseek(wakeup_count_fd, 0, SEEK_SET);
     system("echo \"autosuspend:Sys seek\" >/dev/console");
-    wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
-               200));
-    ALOGE("%s: %d, write %s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
-    if (wakeup_count_len < 0) {
-            strerror_r(errno, buf, sizeof(buf));
-            ALOGE("Error reading from %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
-            wakeup_count_len = 0;
-            return -1;
-     }
 
     for(int i = 0;i < 5;i++)  //notify spm (other core) to handle pre-sleep configuration
     {
@@ -451,14 +442,17 @@
 #endif
 
 
-static int suspend_ctrl(char *wakeup_count,int wakeup_count_len)
+static int suspend_ctrl(void)
 {
 
-
+    char wakeup_count[16] = {0};
+    int wakeup_count_len;
     char buf[80];
     int ret = 0;
+    int flag = -1;
+    
 #ifdef MOBILETEK_SUSPEND_CFG
-    ret = t800_early_suspend(char *wakeup_count, wakeup_count_len);
+    ret = t800_early_suspend();
     if(ret != 0)
     {
 	ALOGD("t800_early_suspend fail\n");
@@ -476,15 +470,55 @@
     }
 #endif
 
-    system("echo \"autosuspend:Sys suspend\" >/dev/console");
-    if(TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state))) < 0) //enter suspend procedures in kernel
+    for(int i=0;i<5;i++)
     {
-        strerror_r(errno, buf, sizeof(buf));
-        ALOGI("Error writing to %s: %s\n", SYS_POWER_STATE, buf);
+        
+        RLOGI("suspend_ctrl: start read wakeup_count\n");
+        lseek(wakeup_count_fd, 0, SEEK_SET);
+        memset(&wakeup_count,0,sizeof(char));
+        wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
+               sizeof(wakeup_count)));
+        if (wakeup_count_len < 0)
+        {
+            strerror_r(errno, buf, sizeof(buf));
+            ALOGE("Error reading from %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
+            wakeup_count_len = 0;
+            continue;
+        }
+    
+        RLOGI("suspend_ctrl: start write wakeup_count\n");
+        ret = write(wakeup_count_fd, wakeup_count, wakeup_count_len);
+        if (ret < 0)
+        {
+            strerror_r(errno, buf, sizeof(buf));
+            RLOGE("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT,buf);
+            continue;
+        }
+        
+        system("echo \"autosuspend:Sys suspend\" >/dev/console");
+        RLOGI("suspend_ctrl: start write power_state\n");
+        if(TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state))) < 0) //enter suspend procedures in kernel
+        {
+            strerror_r(errno, buf, sizeof(buf));
+            ALOGE("Error writing to %s: %s\n", SYS_POWER_STATE, buf);
+            continue;
+        }
+        else
+        {
+            flag = 0;
+            break;
+        }
+
+    }
+    if(flag == 0)
+    {
+        return 0;
+    }
+    else
+    {
         return -1;
     }
 
-    return 0;
 }
 
 
@@ -539,7 +573,7 @@
 static void *suspend_thread_func(void *arg __attribute__((unused)))
 {
     char buf[80];
-    char wakeup_count[20];
+    char wakeup_count[16];
     int wakeup_count_len;
     int ret;
     bool success = true;
@@ -572,6 +606,20 @@
             continue;
         }
 
+
+        ret = write(wakeup_count_fd, wakeup_count, wakeup_count_len);
+        if (ret < 0) {
+            strerror_r(errno, buf, sizeof(buf));
+            RLOGD("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT,buf);
+            RLOGD("%s: sem_post\n", __func__);
+            ret = sem_post(&suspend_lockout);
+            if (ret < 0)
+            {
+                strerror_r(errno, buf, sizeof(buf));
+                ALOGI("Error releasing semaphore: %s\n", buf);
+            }
+            continue;
+        }
         ALOGI("%s: start suspend_ctrl\n", __func__);
         memset(&tv,0,sizeof(struct timeval));
         // memset(&time_info,0 ,sizeof(struct time_info_t));
@@ -581,7 +629,7 @@
         ALOGI("%s: suspend start time: %ld ms\n", __func__,start_time);
         // time_info.sleep_start_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
 
-        ret = suspend_ctrl(wakeup_count,wakeup_count_len);
+        ret = suspend_ctrl();
 
         if (ret >= 0) {
                 ALOGI("suspend_ctrl success.\n");
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/soc/sc/pcu/pcu-zx297520v3.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/soc/sc/pcu/pcu-zx297520v3.c
index f9b23d7..e8d8e88 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/soc/sc/pcu/pcu-zx297520v3.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/soc/sc/pcu/pcu-zx297520v3.c
@@ -729,7 +729,7 @@
 	switch (action) {
 
 	case PM_POST_SUSPEND:
-		__pm_wakeup_event(zx_main_ws, 1000);		
+		__pm_wakeup_event(zx_main_ws, 500);//LYNQ_AUTOSUSPEND add for bug-view-372 by jb.qi on 20241114	
 		break;
 
 	default: