[Bugfix][API-1034]cant sleep after enter suspend_ctrl

Change-Id: I540d9cfc19c3db7a57b999c8d2b7a9dde25fff47
diff --git a/meta/meta-mediatek-mt2735/recipes-lynq/suspend-service/files/autosuspend_wakeup_count.c b/meta/meta-mediatek-mt2735/recipes-lynq/suspend-service/files/autosuspend_wakeup_count.c
index 7c7db07..f4bd3cb 100755
--- a/meta/meta-mediatek-mt2735/recipes-lynq/suspend-service/files/autosuspend_wakeup_count.c
+++ b/meta/meta-mediatek-mt2735/recipes-lynq/suspend-service/files/autosuspend_wakeup_count.c
@@ -231,6 +231,9 @@
 {
     char buf[80];
     int ret = 0;
+    int i;
+    int flag = -1;
+    
     system("echo \"Sys standby mode\" >/dev/console");
     // sleep(1);
     system("echo 7 | emdlogger_ctrl");
@@ -246,27 +249,8 @@
     RLOGD("ring GPIO PASS\n");
     system("hwclock -w");
     RLOGD("TIME: sys to rtc\n");
-    lseek(wakeup_count_fd, 0, SEEK_SET);
     system("echo \"autosuspend:Sys seek\" >/dev/console");
-    
-    RLOGD("suspend_ctrl: start read wakkeup_count\n");
-    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;
-            return -1;
-     }
-    
-    RLOGD("suspend_ctrl: start write wakkeup_count\n");
-    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);
-            return -1;
-        }
-    system("echo \"autosuspend:Sys suspend\" >/dev/console");
+
     RLOGD("suspend_ctrl: start write reg_netsys\n");
     for(int i = 0;i < 5;i++)  //notify spm (other core) to handle pre-sleep configuration
     {
@@ -277,15 +261,51 @@
             return -1;
         }    
     }
-    RLOGD("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
+    for(i=0;i<5;i++)
     {
-        strerror_r(errno, buf, sizeof(buf));
-        ALOGI("Error writing to %s: %s\n", SYS_POWER_STATE, buf);
+        RLOGD("suspend_ctrl: start read wakeup_count\n");
+        lseek(wakeup_count_fd, 0, SEEK_SET);
+        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;
+        }
+    
+        RLOGD("suspend_ctrl: start write wakkeup_count\n");
+        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);
+            continue;
+        }
+        system("echo \"autosuspend:Sys suspend\" >/dev/console");
+        RLOGD("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));
+            ALOGI("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;
 }
 
 
@@ -448,7 +468,7 @@
          
         //  sleep(2); //delay 2s for ril handling screen on
 
-         if(adb_debug_mode == 1) // it's neccessary to wait for autosuspend_disable function calling in debug mode when finish resume procedure.
+         if(adb_debug_mode == 2) // it's neccessary to wait for autosuspend_disable function calling in debug mode when finish resume procedure.
          {