[Feature][ZXW-83]autosuspend service //
Only Configure: No
Affected branch: unknown
Affected module: unknown
Is it affected on both ZXIC and MTK: ZXIC and MTK
Self-test: Yes
Doc Update: No
Change-Id: I36468b54f22d686ddec112b3b6a50ece0edeed14
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/LICENSE b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/LICENSE
new file mode 100755
index 0000000..1b15bd2
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/LICENSE
@@ -0,0 +1,31 @@
+opyright Statement:
+
+This software/firmware and related documentation ("MobileTek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to MobileTek Inc. and/or its licensors. Without
+the prior written permission of MobileTek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of MobileTek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+MobileTek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MobileTek SOFTWARE")
+RECEIVED FROM MobileTek AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. MobileTek EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES MobileTek PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE MobileTek SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MobileTek
+SOFTWARE. MobileTek SHALL ALSO NOT BE RESPONSIBLE FOR ANY MobileTek SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MobileTek'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MobileTek SOFTWARE
+RELEASED HEREUNDER WILL BE, AT MobileTek'S OPTION, TO REVISE OR REPLACE THE
+MobileTek SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO MobileTek FOR SUCH MobileTek SOFTWARE AT ISSUE.
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.c b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.c
new file mode 100755
index 0000000..ff653f6
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#define LOG_TAG "AUTOSUSPEND"
+
+#include <stdbool.h>
+
+#include <log/log.h>
+#include <liblog/lynq_deflog.h>
+
+#include "autosuspend.h"
+
+#include "autosuspend_ops.h"
+
+static struct autosuspend_ops *autosuspend_ops;
+static bool autosuspend_enabled;
+static bool autosuspend_inited;
+
+static int autosuspend_init(void)
+{
+ if (autosuspend_inited) {
+ return 0;
+ }
+
+ autosuspend_ops = autosuspend_wakeup_count_init();
+ if (autosuspend_ops) {
+ goto out;
+ }
+
+ if (!autosuspend_ops) {
+ ALOGI("failed to initialize autosuspend\n");
+ return -1;
+ }
+
+out:
+ autosuspend_inited = true;
+
+ ALOGI("autosuspend initialized\n");
+ return 0;
+}
+
+int autosuspend_enable(void)
+{
+ int ret;
+
+ ret = autosuspend_init();
+ if (ret) {
+ return ret;
+ }
+
+ ALOGI("autosuspend_enable\n");
+
+ if (autosuspend_enabled) {
+ return 0;
+ }
+
+ ret = autosuspend_ops->enable();
+ if (ret) {
+ return ret;
+ }
+
+ autosuspend_enabled = true;
+ return 0;
+}
+
+int autosuspend_disable(void)
+{
+ int ret;
+
+ ret = autosuspend_init();
+ if (ret) {
+ return ret;
+ }
+
+ ALOGI("autosuspend_disable\n");
+
+ if (!autosuspend_enabled) {
+ return 0;
+ }
+
+ ret = autosuspend_ops->disable();
+ if (ret) {
+ return ret;
+ }
+
+ autosuspend_enabled = false;
+ return 0;
+}
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.h b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.h
new file mode 100755
index 0000000..59188a8
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 _LIBSUSPEND_AUTOSUSPEND_H_
+#define _LIBSUSPEND_AUTOSUSPEND_H_
+
+#include <sys/cdefs.h>
+#include <stdbool.h>
+
+__BEGIN_DECLS
+
+/*
+ * autosuspend_enable
+ *
+ * Turn on autosuspend in the kernel, allowing it to enter suspend if no
+ * wakelocks/wakeup_sources are held.
+ *
+ *
+ *
+ * Returns 0 on success, -1 if autosuspend was not enabled.
+ */
+int autosuspend_enable(void);
+
+/*
+ * autosuspend_disable
+ *
+ * Turn off autosuspend in the kernel, preventing suspend and synchronizing
+ * with any in-progress resume.
+ *
+ * Returns 0 on success, -1 if autosuspend was not disabled.
+ */
+int autosuspend_disable(void);
+
+/*
+ * set_wakeup_callback
+ *
+ * Set a function to be called each time the device returns from suspend.
+ * success is true if the suspend was sucessful and false if the suspend
+ * aborted due to some reason.
+ */
+void set_wakeup_callback(void (*func)(bool success));
+
+__END_DECLS
+
+#endif
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.service b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.service
new file mode 100755
index 0000000..3cbb46c
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=lynq-autosuspend-service
+
+[Service]
+ExecStart=/usr/bin/autosuspend
+Type=simple
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_ops.h b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_ops.h
new file mode 100755
index 0000000..698e25b
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_ops.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 _LIBSUSPEND_AUTOSUSPEND_OPS_H_
+#define _LIBSUSPEND_AUTOSUSPEND_OPS_H_
+
+struct autosuspend_ops {
+ int (*enable)(void);
+ int (*disable)(void);
+};
+
+struct autosuspend_ops *autosuspend_autosleep_init(void);
+struct autosuspend_ops *autosuspend_earlysuspend_init(void);
+struct autosuspend_ops *autosuspend_wakeup_count_init(void);
+
+#endif
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c
new file mode 100755
index 0000000..85fbc84
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c
@@ -0,0 +1,560 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#define LOG_TAG "AUTOSUSPEND"
+//#define LOG_NDEBUG 0
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <stddef.h>
+#include <stdbool.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <unistd.h>
+#include <dlfcn.h>
+//#include <cutils/properties.h>
+#define USER_LOG_TAG "PMS"
+#include <liblog/lynq_deflog.h>
+#include <log/log.h>
+#include <stdlib.h>
+#include "autosuspend_ops.h"
+
+#ifdef MOBILETEK_SUSPEND_CFG
+#define SYS_POWER_STATE "/sys/power/state"
+#endif
+
+#ifdef MOBILETEK_TARGET_PLATFORM_T106
+#define SYS_POWER_STATE "/sys/power/autosleep"
+#endif
+#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count"
+#define SYS_POWER_SPM_SUSPEND_CRTL "/sys/power/spm/suspend_ctrl"
+
+#define BASE_SLEEP_TIME 100000
+#define POSSIBLE_MAX_SLEEP_TIME 60000000
+
+static int state_fd;
+static int wakeup_count_fd;
+static int suspend_ctrl_fd;
+static pthread_t suspend_thread;
+static sem_t suspend_lockout;
+extern pthread_cond_t feedback_cond;
+extern pthread_mutex_t feedback_mutex;
+extern pthread_mutex_t time_info_mutex;
+static const char *sleep_state = "mem";
+#ifdef MOBILETEK_SUSPEND_CFG
+static const char *reg_netsys[5] = {"reg_netsys_srcclkena_mask_b 0",
+ "reg_netsys_infra_req_mask_b 0",
+ "reg_netsys_apsrc_req_mask_b 0",
+ "reg_netsys_vrf18_req_mask_b 0",
+ "reg_netsys_ddr_en_mask_b 0"};
+#endif
+static void (*wakeup_func)(bool success) = NULL;
+static int sleep_time = BASE_SLEEP_TIME;
+static int possible_max_sleep_time = POSSIBLE_MAX_SLEEP_TIME;
+
+extern int adb_debug_mode;
+
+static long start_time; // 出错点:time_info_t 结构体两个成员都是long,因此这两个变量必须是long型,不能定义成int
+static long end_time;
+
+
+
+# define TEMP_FAILURE_RETRY(expression) \
+ (__extension__ \
+ ({ long int __result; \
+ do __result = (long int) (expression); \
+ while (__result == -1L && errno == EINTR); \
+ __result; }))
+
+
+pid_t pid = 0;
+
+enum {
+ PARTIAL_WAKE_LOCK = 1, // the cpu stays on, but the screen is off
+ FULL_WAKE_LOCK = 2 // the screen is also on
+};
+
+// while you have a lock held, the device will stay on at least at the
+// level you request.
+
+struct time_info_t
+{
+ long sleep_start_time;
+ long wakeup_time;
+};
+
+extern struct time_info_t time_info;
+
+struct timeval tv;
+
+#ifdef MOBILETEK_SUSPEND_CFG
+void *dlHandle_wakelock;
+void *dlHandle_log;
+void *dlHandle_network;
+static void* dlHandle_sim;
+
+int (*lynq_screen)(int num);
+int (*lynq_sim_init)(int utoken);
+int (*acquire_wake_lock)(int lock, const char* id);
+int (*release_wake_lock)(const char* id);
+int (*lynq_query_registration_state)(const char *type,int* regState,int* imsRegState,char * LAC,char * CID,int *
+netType,int *radioTechFam,int *errorCode);
+int (*lynq_network_init)(int utoken);
+
+void init_wakelock_func(void)
+{
+ const char *lynqLibPath_WakeLock = "/usr/lib64/libpower.so";
+ const char *lynqLibPath_Log = "/lib64/liblynq-log.so";
+
+ dlHandle_wakelock = dlopen(lynqLibPath_WakeLock, RTLD_NOW);
+ if (dlHandle_wakelock == NULL)
+ {
+ ALOGI("dlopen lynqLibPath_WakeLock failed: %s", dlerror());
+ exit(EXIT_FAILURE);
+ }
+ dlHandle_log = dlopen(lynqLibPath_Log, RTLD_NOW);
+ if (dlHandle_log == NULL)
+ {
+ ALOGI("dlopen dlHandle_log failed: %s", dlerror());
+ exit(EXIT_FAILURE);
+ }
+ acquire_wake_lock = (int(*)(int,const char*))dlsym(dlHandle_wakelock, "acquire_wake_lock");
+ if (acquire_wake_lock == NULL) {
+ ALOGI("acquire_wake_lock not defined or exported in %s", lynqLibPath_WakeLock);
+ exit(EXIT_FAILURE);
+ }
+ release_wake_lock = (int(*)( const char*))dlsym(dlHandle_wakelock, "release_wake_lock");
+ if (release_wake_lock == NULL) {
+ ALOGI("release_wake_lock not defined or exported in %s", lynqLibPath_WakeLock);
+ exit(EXIT_FAILURE);
+ }
+ dlerror(); // Clear any previous dlerror
+
+ return;
+}
+
+
+ void init_sim_func()
+{
+ int res;
+ const char *lynqLibPath_Sim = "/lib64/liblynq-sim.so";
+
+ pid = getpid();
+ dlHandle_sim = dlopen(lynqLibPath_Sim, RTLD_NOW);
+ if (dlHandle_sim == NULL)
+ {
+ ALOGI("dlopen lynqLibPath_Sim failed: %s", dlerror());
+ exit(EXIT_FAILURE);
+ }
+
+ lynq_screen = (int(*)(int))dlsym(dlHandle_sim, "lynq_screen");
+ if (lynq_screen == NULL) {
+ ALOGI("lynq_screen not defined or exported in %s", lynqLibPath_Sim);
+ exit(EXIT_FAILURE);
+ }
+
+ lynq_sim_init = (int(*)(int utoken))dlsym(dlHandle_sim,"lynq_sim_init");
+ if (lynq_sim_init == NULL) {
+ ALOGI("lynq_sim_init not defined or exported in %s", lynqLibPath_Sim);
+ exit(EXIT_FAILURE);
+ }
+ dlerror(); // Clear any previous dlerror
+
+ res = lynq_sim_init((int)pid);
+ if(res == 0)
+ {
+ ALOGI("Run lynq_sim_init\n");
+ }else{
+ ALOGI("lynq sim init error\n");
+ }
+ sleep(1);
+
+ return;
+}
+
+
+void init_network_func()
+{
+ int res;
+ const char *lynqLibPath_Network = "/lib64/liblynq-network.so";
+ dlHandle_network = dlopen(lynqLibPath_Network, RTLD_NOW);
+ if (dlHandle_network == NULL)
+ {
+ ALOGI("dlopen lynqLibPath_Network failed: %s", dlerror());
+ exit(EXIT_FAILURE);
+ }
+
+ lynq_query_registration_state = (int(*)(const char*,int*,int*,char *,char *,int *,int *,int*))dlsym(
+dlHandle_network, "lynq_query_registration_state");
+ if (lynq_query_registration_state == NULL) {
+ ALOGI("lynq_query_registration_state not defined or exported in %s", lynqLibPath_Network);
+ exit(EXIT_FAILURE);
+ }
+
+ lynq_network_init = (int(*)(int))dlsym(dlHandle_network, "lynq_network_init");
+ if (lynq_network_init == NULL) {
+ ALOGI("lynq_network_init not defined or exported in %s", lynqLibPath_Network);
+ exit(EXIT_FAILURE);
+ }
+
+ ALOGI("start lynq_network_init\n");
+ printf("start lynq_network_init\n");
+ res = lynq_network_init(2);
+ sleep(10);
+
+ if(res == 0)
+ {
+ ALOGI("Run lynq_network_init\n");
+ printf("Run lynq_network_init\n");
+ }else{
+ ALOGI("lynq_network_init error\n");
+ printf("lynq_network_init error\n");
+ }
+
+ dlerror(); // Clear any previous dlerror
+ return;
+}
+#endif
+
+static int suspend_ctrl(char *wakeup_count,int wakeup_count_len)
+{
+
+
+ char buf[80];
+ int ret = 0;
+#ifdef MOBILETEK_SUSPEND_CFG
+ system("echo \"Sys standby mode\" >/dev/console");
+ // sleep(1);
+ system("echo 7 | emdlogger_ctrl");
+ // sleep(1);
+
+ if (lynq_screen(0) != 0) //notify ril for screen off
+ {
+ ALOGI("lynq_screen off fail\n");
+ return -1;
+ }
+ system("echo mode 4 0 >/sys/devices/platform/10005000.pinctrl/mt_gpio");
+ system("echo out 4 1 >/sys/devices/platform/10005000.pinctrl/mt_gpio");
+ 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");
+ 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
+ {
+ if(TEMP_FAILURE_RETRY(write(suspend_ctrl_fd,reg_netsys[i],strlen(reg_netsys[i]))) < 0)
+ {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error writing to %s: %s\n", SYS_POWER_SPM_SUSPEND_CRTL, buf);
+ return -1;
+ }
+ }
+#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
+ {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error writing to %s: %s\n", SYS_POWER_STATE, buf);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+void wakeup_feedback(bool success)
+{
+
+ char buf[80];
+ long sleeptime = 0;
+#ifdef MOBILETEK_SUSPEND_CFG
+ system("hwclock -s");
+ RLOGD("TIME: rtc to sys\n");
+ if (!success)
+ {
+
+ system("mdlogctl start");
+
+ system("echo 8 | emdlogger_ctrl");
+
+ usleep(200000);
+ ALOGI("Log on with failure\n");
+ return ;
+ }
+
+
+ if (lynq_screen(1) != 0) // notify ril for screen on
+ {
+ ALOGI("lynq_screen on fail\n");
+
+ }
+
+ system("mdlogctl start");
+
+// sleep(1);
+
+ system("echo 8 | emdlogger_ctrl");
+
+ usleep(300000); //delay 2s for ril handling screen on,at least 70ms
+#endif
+
+ pthread_mutex_lock(&time_info_mutex);
+ memset(&tv,0,sizeof(struct timeval));
+ gettimeofday(&tv,NULL);
+ // time_info.wakeup_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ end_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ ALOGI("%s: wake up time: %ld ms\n", __func__,end_time);
+
+ memset(&time_info,0,sizeof(struct time_info_t));
+
+ time_info.sleep_start_time = start_time;
+ time_info.wakeup_time = end_time;
+ sleeptime = end_time -start_time;
+ RLOGD("sleep time is %ld ms\n", sleeptime);
+ pthread_mutex_unlock(&time_info_mutex);
+
+ if (pthread_cond_broadcast(&feedback_cond) != 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error broadcast cond: %s\n", buf);
+ }
+
+ return ;
+
+}
+
+static void update_sleep_time(bool success) {
+ if (success) {
+ sleep_time = BASE_SLEEP_TIME;
+ return;
+ }
+ // double sleep time after each failure up to one minute
+ sleep_time = MIN(sleep_time * 2, possible_max_sleep_time);
+}
+
+static void *suspend_thread_func(void *arg __attribute__((unused)))
+{
+ char buf[80];
+ char wakeup_count[20];
+ int wakeup_count_len;
+ int ret;
+ bool success = true;
+
+ while (1) {
+ update_sleep_time(success);
+ usleep(sleep_time);
+ success = false;
+
+ ALOGI("%s: wait\n", __func__);
+ ret = sem_wait(&suspend_lockout);
+ if (ret < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error waiting on semaphore: %s\n", buf);
+ continue;
+ }
+
+ ALOGV("%s: read wakeup_count\n", __func__);
+ 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;
+ }
+ if (!wakeup_count_len) {
+ ALOGE("Empty wakeup count\n");
+ continue;
+ }
+
+ ALOGI("%s: start suspend_ctrl\n", __func__);
+ memset(&tv,0,sizeof(struct timeval));
+ // memset(&time_info,0 ,sizeof(struct time_info_t));
+ gettimeofday(&tv,NULL);
+
+ start_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ 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);
+
+ if (ret >= 0) {
+ ALOGI("suspend_ctrl success.\n");
+ success = true;
+ }
+ else
+ {
+ ALOGI("suspend_ctrl false.\n");
+ success = false;
+ }
+
+ void (*func)(bool success) = wakeup_func;
+ if (func != NULL) {
+ (*func)(success); //handling resume event for other libs /apps
+ }
+
+ ALOGI("%s: release sem\n", __func__);
+ ret = sem_post(&suspend_lockout);
+ if (ret < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error releasing semaphore: %s\n", buf);
+ }
+
+ if(adb_debug_mode == 1) // it's neccessary to wait for autosuspend_disable function calling in debug mode when finish resume procedure.
+ {
+ sleep(40);
+ }
+ else
+ {
+ ALOGI("%s: adb_debug unsupported\n", __func__);
+ }
+
+ ALOGI("%s: END SLEEP\n", __func__);
+ }
+ return NULL;
+}
+
+static int autosuspend_wakeup_count_enable(void)
+{
+ char buf[80];
+ int ret;
+
+ ALOGI("autosuspend_wakeup_count_enable\n");
+
+ ret = sem_post(&suspend_lockout);
+
+ if (ret < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error changing semaphore: %s\n", buf);
+ }
+
+ ALOGI("autosuspend_wakeup_count_enable done\n");
+
+ return ret;
+}
+
+static int autosuspend_wakeup_count_disable(void)
+{
+ char buf[80];
+ int ret;
+
+ ALOGI("autosuspend_wakeup_count_disable\n");
+
+ ret = sem_wait(&suspend_lockout);
+
+ if (ret < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error changing semaphore: %s\n", buf);
+ }
+
+ ALOGI("autosuspend_wakeup_count_disable done\n");
+
+ return ret;
+}
+
+void set_wakeup_callback(void (*func)(bool success))
+{
+ if (wakeup_func != NULL) {
+ ALOGI("Duplicate wakeup callback applied, keeping original");
+ return;
+ }
+ wakeup_func = func;
+}
+
+struct autosuspend_ops autosuspend_wakeup_count_ops = {
+ .enable = autosuspend_wakeup_count_enable,
+ .disable = autosuspend_wakeup_count_disable,
+};
+
+struct autosuspend_ops *autosuspend_wakeup_count_init(void)
+{
+ int ret;
+ char buf[80];
+ char timeout_str[100]="100000";
+
+ //if (property_get("sys.autosuspend.timeout", timeout_str, NULL))
+ {
+ possible_max_sleep_time = atoi(timeout_str);
+ ALOGI("autosuspend timeout is %d\n", possible_max_sleep_time);
+ }
+
+ state_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_STATE, O_RDWR));
+ if (state_fd < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error opening %s: %s\n", SYS_POWER_STATE, buf);
+ goto err_open_state;
+ }
+
+ wakeup_count_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_WAKEUP_COUNT, O_RDWR));
+ if (wakeup_count_fd < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error opening %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
+ goto err_open_wakeup_count;
+ }
+#ifdef MOBILETEK_SUSPEND_CFG
+ suspend_ctrl_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_SPM_SUSPEND_CRTL, O_RDWR));
+ if (suspend_ctrl_fd < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error opening %s: %s\n", SYS_POWER_SPM_SUSPEND_CRTL, buf);
+ goto err_open_suspend_ctrl;
+ }
+#endif
+ ret = sem_init(&suspend_lockout, 0, 0);
+ if (ret < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error creating semaphore: %s\n", buf);
+ goto err_sem_init;
+ }
+ ret = pthread_create(&suspend_thread, NULL, suspend_thread_func, NULL);
+ if (ret) {
+ strerror_r(ret, buf, sizeof(buf));
+ ALOGI("Error creating thread: %s\n", buf);
+ goto err_pthread_create;
+ }
+
+ ALOGI("Selected wakeup count\n");
+ return &autosuspend_wakeup_count_ops;
+
+err_pthread_create:
+ sem_destroy(&suspend_lockout);
+err_sem_init:
+ close(wakeup_count_fd);
+err_open_wakeup_count:
+ close(state_fd);
+#ifdef MOBILETEK_SUSPEND_CFG
+err_open_suspend_ctrl:
+ close(suspend_ctrl_fd);
+#endif
+err_open_state:
+ return NULL;
+}
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/lynq-autosuspend.sh b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/lynq-autosuspend.sh
new file mode 100644
index 0000000..8e96831
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/lynq-autosuspend.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# Run the daemon
+#
+
+DAEMON="lynq-autosuspend-service"
+PIDFILE="/var/run/$DAEMON.pid"
+EXEC="/usr/bin/autosuspend"
+EXEC_ARGS=""
+
+
+start() {
+ echo -n "Starting $DAEMON... "
+ start-stop-daemon --no-close -S -b -m -p $PIDFILE -x $EXEC -- $EXEC_ARGS
+ [ $? -eq 0 ] && echo "OK" || echo "ERROR"
+}
+
+stop() {
+ echo -n "Stopping $DAEMON... "
+ start-stop-daemon -K -p $PIDFILE
+ [ $? -eq 0 ] && echo "OK" || echo "ERROR"
+}
+
+restart() {
+ stop
+ start
+}
+
+case "$1" in
+ start|stop|restart)
+ "$1"
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ exit 1
+esac
+
+exit $?
+
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/main.c b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/main.c
new file mode 100755
index 0000000..d4e6960
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/main.c
@@ -0,0 +1,491 @@
+/* //device/system/rild/rild.c
+**
+** Copyright 2006 The Android Open Source Project
+**
+** 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 <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <dlfcn.h>
+#include <string.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <log/log.h>
+#include <liblog/lynq_deflog.h>
+#include <include/lynq_uci.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <signal.h>
+
+
+#define LOG_UCI_MODULE "lynq_autosuspend"
+#define LOG_UCI_FILE "lynq_uci"
+
+#define LOG_TAG "AUTOSUSPEND"
+
+#define USER_LOG_TAG "PMS"
+
+#define SOCK_PATH "/tmp/autosuspend.cmd.server" //不能在当前这个目录创建socket文件,否则报错找不到文件(可能是因为这是在共享文件夹下,不支持创建socket文件)
+
+#define SOCK_DATA_PATH "/tmp/autosuspend.data.server"
+
+// #define LYINFLOG(X...) lynq_log_global_output(LOG_INFO,X)
+
+#define TIME_OUT_TIME 30
+
+
+#define MAX_LIB_ARGS 16
+
+int adb_debug_mode = 0;
+
+
+pthread_cond_t feedback_cond = PTHREAD_COND_INITIALIZER;
+pthread_mutex_t feedback_mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t time_info_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+extern int autosuspend_enable(void);
+extern int autosuspend_disable(void);
+extern void init_wakelock_func(void);
+extern void init_sim_func();
+extern void init_network_func();
+extern void set_wakeup_callback(void (*func)(bool success));
+extern void wakeup_feedback(bool success);
+extern int (*lynq_screen)(int num);
+
+struct time_info_t
+{
+ long sleep_start_time;
+ long wakeup_time;
+};
+
+struct time_info_t time_info;
+
+static void usage(const char *argv0) {
+ fprintf(stderr, "Usage: %s -l <possible_max_sleep_time> [-- <args for Autosuspend Service>]\n", argv0);
+ exit(EXIT_FAILURE);
+}
+
+
+
+static int make_argv(char * args, char ** argv) {
+ // Note: reserve argv[0]
+ int count = 1;
+ char * tok;
+ char * s = args;
+
+ while ((tok = strtok(s, " \0"))) {
+ argv[count] = tok;
+ s = NULL;
+ count++;
+ }
+ return count;
+}
+
+static int Accept(int fd, struct sockaddr *sa, socklen_t *salenptr)
+{
+ int n;
+
+ while((n = accept(fd, sa, salenptr)) < 0)
+ {
+ if((errno == ECONNABORTED) || (errno == EINTR))
+ continue;
+ else
+ {
+ ALOGI("accept error\n");
+ return -1;
+ }
+ }
+ return n;
+}
+
+static int Bind(int fd, const struct sockaddr *sa, socklen_t salen)
+{
+ if(bind(fd, sa, salen) < 0)
+ {
+ // ALOGI("bind error\n");
+ perror("bind error");
+ return -1;
+ }
+ return 0;
+}
+
+
+static int Socket(int family, int type, int protocol)
+{
+ int n;
+
+ if ( (n = socket(family, type, protocol)) < 0)
+ {
+ ALOGI("socket error\n");
+ return -1;
+ }
+ return n;
+}
+
+static int Listen(int fd, int backlog)
+{
+ if(listen(fd, backlog) < 0)
+ {
+ ALOGI("listen error\n");
+ return -1;
+ }
+ return 0;
+}
+
+
+static int listen_port(struct sockaddr_un *addr, char *sockpath)
+{
+ int listenfd;
+ listenfd = Socket(AF_UNIX,SOCK_STREAM,0);
+ if(listenfd == -1)
+ return -1;
+ memset(addr, 0, sizeof(struct sockaddr_un));
+ addr->sun_family = AF_UNIX;
+ strcpy(addr->sun_path,sockpath);
+ // int opt = 1;
+ // if(setsockopt(listenfd, SOL_SOCKET,SO_REUSEADDR, (const void *)&opt, sizeof(opt)) == -1)
+ // {
+ // perror("setsockopt error");
+ // return -1;
+ // }
+
+// 以上方法对非网络的本地socket无效,应该用unlink函数避免Address already in use的错误
+
+
+ unlink(sockpath);
+ if(Bind(listenfd,(struct sockaddr *)addr,sizeof(*addr)) == -1)
+ return -1;
+
+ if(Listen(listenfd,20) == -1)
+ return -1;
+
+ return listenfd;
+}
+
+static ssize_t Read(int fd, void *ptr, size_t nbytes)
+{
+ ssize_t n;
+
+ while((n = read(fd, ptr, nbytes)) == -1)
+ {
+ //printf("READ,%d\n",fd);
+ if (errno == EINTR)
+ {
+ ALOGI("read error eintr\n");
+ continue;
+ }
+ else if(errno == EAGAIN || errno == EWOULDBLOCK)
+ {
+ ALOGI("read time out\n");
+ return -1;
+ }
+ else
+ {
+ ALOGI("read error\n");
+ return -1;
+ }
+ }
+ //sleep(2);
+ //printf("READ1,%d\n", fd);
+ return n;
+}
+
+static ssize_t Write(int fd, const void *ptr, size_t nbytes)
+{
+ ssize_t n;
+
+ while((n = write(fd, ptr, nbytes)) == -1)
+ {
+ if (errno == EINTR)
+ continue;
+ else if(errno == EPIPE)
+ {
+ ALOGI("write error epipe\n");
+ return -1;
+ }
+ else
+ return -1;
+ }
+ return n;
+}
+
+static int Close(int fd)
+{
+ if (close(fd) == -1)
+ {
+ ALOGI("close error\n");
+ return -1;
+ }
+ return 0;
+}
+
+
+void *deal_autosuspend(void *sockfd)
+{
+ int commfd = *((int *)sockfd);
+ char buf[20];
+ char res[15];
+
+ while(1)
+ {
+ memset(buf,0,sizeof(buf));
+ ALOGI("deal_autosuspend start to read.\n");
+ // 错误点:read函数在对端关闭后,也会直接返回0,不会阻塞,因此要判断是否返回0,返回0表示对端已经关闭,此时要跳出while循环不再监听
+ // 为什么对端会关闭?因为在客户端没有用nohup方式打开的情况下,系统睡眠后客户端进行会直接被杀死,对端会关闭,所以会导致read不阻塞,且总是返回0的现象
+ if(Read(commfd,buf,sizeof(buf)) <= 0)
+ {
+ ALOGI("service receive suspend_cmd fail or client is closed.\n");
+ Close(commfd);
+ break;
+ }
+ if(strcmp(buf,"enable") == 0)
+ {
+ if(autosuspend_enable() < 0)
+ {
+ ALOGI("autosuspend_enable fail.\n");
+ }
+ else
+ {
+ ALOGI("autosuspend_enable success.\n");
+ }
+ }
+ else if(strcmp(buf,"disable") == 0)
+ {
+ if(autosuspend_disable() < 0)
+ {
+ ALOGI("autosuspend_disable fail.\n");
+ }
+ else
+ {
+ ALOGI("autosuspend_disable success.\n");
+
+ }
+ }
+
+ else
+ {
+ ALOGI("Unknown cmd : %s\n",buf);
+ }
+
+ }
+
+
+
+}
+
+#ifdef GSW_SUSPEND_CFG
+/*jb.qi add for service send when DTR is low on 20221111 start */
+void *dtr_wakeup()
+{
+ FILE *fp;
+ int ret;
+ bool success = true;
+ char buf[30];
+ char dtr_buffer[25];
+ RLOGD("dtr_wakeup start\n");
+ while(1)
+ {
+ fp = popen("cat /sys/devices/platform/10005000.pinctrl/mt_gpio |grep 006:","r");
+ fgets(dtr_buffer, sizeof(dtr_buffer), fp);
+ if(dtr_buffer[7] == '0')
+ {
+ time_info.sleep_start_time = 123;
+ time_info.wakeup_time = 123;
+ if (pthread_cond_broadcast(&feedback_cond) != 0)
+ {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGI("Error broadcast cond: %s\n", buf);
+ }
+ RLOGD("dtr_wakeup success!\n");
+ sleep(3);
+ }
+ usleep(500);
+ pclose(fp);
+ }
+}
+/*jb.qi add for service send when DTR is low on 20221111 end */
+#endif
+
+void *send_feedback(void *sockfd)
+{
+ int commfd = *((int *)sockfd);
+ char buf[80];
+
+ while (1)
+ {
+ memset(buf,0,sizeof(buf));
+ ALOGI("send_feedback thread wait to send.\n");
+ pthread_mutex_lock(&feedback_mutex);
+ pthread_cond_wait(&feedback_cond,&feedback_mutex);
+
+ ALOGI("send_feedback thread is now sending the feedback to client.\n");
+ pthread_mutex_lock(&time_info_mutex);
+ if(Write(commfd,&time_info,sizeof(struct time_info_t)) <= 0)
+ {
+ ALOGI("service send wakeup_feedback struct fail.\n");
+ Close(commfd);
+ pthread_mutex_unlock(&time_info_mutex);
+ pthread_mutex_unlock(&feedback_mutex);
+#ifdef GSW_SUSPEND_CFG
+ continue ;//jb.qi add for service send when DTR is low on 20221111
+#endif
+
+#ifdef MOBILETEK_SUSPEND_CFG
+ break ;
+#endif
+ }
+ pthread_mutex_unlock(&time_info_mutex);
+
+ pthread_mutex_unlock(&feedback_mutex);
+
+
+
+ }
+
+}
+
+
+int main(int argc, char **argv) {
+
+
+ // int i = 0;
+ // RLOGD("**Autosuspend Service Daemon Started**");
+ // RLOGD("**Autosuspend Service param count=%d**", argc);
+ char tmp[20];
+
+ int commfd, commfd_data, server_sock, server_data_sock,len, len_data;
+
+ struct sockaddr_un server_sockaddr;
+ struct sockaddr_un server_data_sockaddr;
+ struct sockaddr_un client_sockaddr;
+
+ len = sizeof(server_sockaddr);
+
+
+ pthread_t tid;
+#ifdef GSW_SUSPEND_CFG
+ pthread_t tid_1;//jb.qi add for service send when DTR is low on 20221111
+#endif
+
+ LYLOGEINIT(USER_LOG_TAG);
+ LYLOGSET(LOG_DEBUG);
+ // LYLOGSET(LOG_ERROR);
+
+ int auto_enable = 0;
+
+ lynq_get_value(LOG_UCI_FILE, LOG_UCI_MODULE, "debug", tmp); // 即获取系统层面的环境变量
+ ALOGI("Autosuspend Service Daemon. debug %s\n",tmp);
+ adb_debug_mode=atoi(tmp);
+ lynq_get_value(LOG_UCI_FILE, LOG_UCI_MODULE, "auto_enable", tmp);
+ auto_enable=atoi(tmp);
+ ALOGI("Autosuspend Service Daemon. auto_enable %s\n",tmp);
+#ifdef MOBILETEK_SUSPEND_CFG
+ init_wakelock_func();
+ init_sim_func();
+#endif
+ signal(SIGPIPE,SIG_IGN); // 忽略SIGPIPE信号,防止由于客户端关闭,继续往客户端write,会导致服务端收到SIGPIPE信号而Broken pipe
+
+
+ // init_network_func();
+
+ // if(pthread_cond_init(&feedback_cond,NULL) != 0)
+ // {
+ // strerror_r(errno, buf, sizeof(buf));
+ // ALOGI("Error creating cond: %s\n", buf);
+ // return -1;
+ // }
+
+ set_wakeup_callback(wakeup_feedback);
+ // 注册回调函数
+
+ if(auto_enable==0)
+ {
+ if(autosuspend_disable() < 0)
+ {
+ ALOGI("autosuspend_disable fail.\n");
+ }
+ else
+ {
+ ALOGI("autosuspend_disable success.\n");
+ }
+ }
+ if(auto_enable==1)
+ {
+ if(autosuspend_enable() < 0)
+ {
+ ALOGI("autosuspend_enable fail.\n");
+ }
+ else
+ {
+ ALOGI("autosuspend_enable success.\n");
+ }
+ }
+
+
+ server_sock = listen_port(&server_sockaddr,SOCK_PATH);
+ if(server_sock == -1)
+ return -1;
+
+ server_data_sock = listen_port(&server_data_sockaddr,SOCK_DATA_PATH);
+ if(server_data_sock == -1)
+ return -1;
+#ifdef GSW_SUSPEND_CFG
+ /*jb.qi add for service send when DTR is low on 20221111 start*/
+ pthread_create(&tid_1,NULL,dtr_wakeup,NULL);
+ pthread_detach(tid_1);
+ /*jb.qi add for service send when DTR is low on 20221111 end*/
+#endif
+
+ while (1)
+ {
+ ALOGI("service socket listening...\n");
+ commfd = Accept(server_sock,(struct sockaddr *)&client_sockaddr,&len);
+ if(commfd == -1)
+ {
+ return -1;
+ }
+ if(getpeername(commfd, (struct sockaddr *)&client_sockaddr, &len) == -1)
+ {
+ ALOGI("GETPEERNAME ERROR.\n");
+ // Close(server_sock);
+ Close(commfd);
+ continue;
+ }
+ else
+ {
+ ALOGI("Client socket filepath: %s\n", client_sockaddr.sun_path);
+ }
+
+ commfd_data = Accept(server_data_sock,NULL,NULL);
+ if(commfd_data == -1)
+ {
+ return -1;
+ }
+ ALOGI("data channel connected.\n");
+
+ pthread_create(&tid,NULL,deal_autosuspend,(void*)&commfd);//这里很容易错,最后一个参数要取地址,这是一个指针
+ pthread_detach(tid);
+
+ pthread_create(&tid,NULL,send_feedback,(void*)&commfd_data);
+ pthread_detach(tid);
+
+
+ }
+
+
+}
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/makefile b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/makefile
new file mode 100755
index 0000000..0441d43
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/makefile
@@ -0,0 +1,67 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+ -g -Os \
+ -flto \
+ -DRIL_SHLIB \
+ -DATCI_PARSE \
+ -DKEEP_ALIVE \
+ -D__LINUX_OS__ \
+ -DECALL_SUPPORT
+
+
+
+ifeq ($(strip $(TARGET_PLATFORM)), T106)
+LOCAL_CFLAGS += -DHAVE_SYS_UIO_H -DRIL_TIME_CB
+endif
+
+ifeq ($(strip $(TARGET_PLATFORM)), T106)
+ LOCAL_CFLAGS += -DMOBILETEK_TARGET_PLATFORM_T106
+endif
+
+ifeq ($(strip $(MOBILETEK_SUSPEND_CFG)), GSW)
+ LOCAL_CFLAGS += -DGSW_SUSPEND_CFG
+
+endif
+
+ifeq ($(strip $(MOBILETEK_SUSPEND_CFG)), PLATFORM)
+ LOCAL_CFLAGS += -DMOBILETEK_SUSPEND_CFG
+
+endif
+
+
+LOCAL_PATH = .
+
+LOCAL_C_INCLUDES = \
+ -I. -I$(ROOT)$(includedir)/liblog -I$(ROOT)$(includedir) \
+
+
+
+
+LOCAL_LIBS := \
+ -L. \
+ -ldl \
+ -lpthread \
+ -llynq-log \
+ -llynq-uci \
+ -llog \
+ -lbsp \
+
+
+SOURCES = $(wildcard *.c )
+
+EXECUTABLE = autosuspend
+
+OBJECTS=$(SOURCES:.c=.o)
+all: $(EXECUTABLE)
+
+$(EXECUTABLE): $(OBJECTS)
+ $(CXX) $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.c
+ $(CC) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+.PHONY: clean
+clean:
+ $(RM) $(OBJECTS) $(EXECUTABLE)
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/lynq-autosuspend.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/lynq-autosuspend.bb
new file mode 100755
index 0000000..c646163
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/lynq-autosuspend.bb
@@ -0,0 +1,79 @@
+inherit externalsrc package systemd
+
+DESCRIPTION = "autosuspend.service"
+
+LICENSE = "MobileTekProprietary"
+LIC_FILES_CHKSUM = "file://${WORKDIR}/LICENSE;md5=44d8d2b6296ca24bcd4894bb7155bf27"
+
+SRC_URI = "file://autosuspend.c file://LICENSE \
+ file://autosuspend.h \
+ file://autosuspend_ops.h \
+ file://autosuspend_wakeup_count.c \
+ file://main.c \
+ file://autosuspend.service \
+ file://lynq-autosuspend.sh \
+ file://makefile \
+"
+
+EXTRA_OEMAKE = "'RAT_CONFIG_C2K_SUPPORT = ${RAT_CONFIG_C2K_SUPPORT}'\
+ 'MTK_MULTI_SIM_SUPPORT = ${MTK_MULTI_SIM_SUPPORT}'\
+ 'TARGET_PLATFORM = ${TARGET_PLATFORM}'"
+
+TARGET_CC_ARCH += "${LDFLAGS}"
+
+LOCAL_C_INCLUDES = "-I. "
+
+DEPENDS = "liblynq-log liblynq-uci"
+DEPENDS += "${@bb.utils.contains('TARGET_PLATFORM', 'mt2735', 'audio-mixer-ctrl streamer1.0', '', d)} liblynq-log liblynq-uci libbsp"
+LOCAL_LIBS = "-L. -ldl -lstdc++ -lpthread -llog"
+SOURCES = "$(wildcard *.c )"
+
+OBJECTS = "$(SOURCES:.c=.o)"
+
+EXTRA_OEMAKE += "'MOBILETEK_SUSPEND_CFG = ${MOBILETEK_SUSPEND_CFG}'\
+ 'TARGET_PLATFORM = ${TARGET_PLATFORM}'\
+ 'MTK_LED_SUPPORT = ${MTK_LED_SUPPORT}'\
+ 'TARGET_PLATFORM = ${TARGET_PLATFORM}'"
+
+EXECUTABLE = "autosuspend"
+S = "${WORKDIR}"
+TARGET_CC_ARCH += "${LDFLAGS}"
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE_${PN} = "autosuspend.service"
+FILES_${PN} += "${systemd_unitdir}/system/autosuspend.service"
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+
+ #${CXX} -Wall ${LOCAL_C_INCLUDES} autosuspend.c autosuspend_wakeup_count.c main.c ${LOCAL_LIBS} -o ${EXECUTABLE}
+ if test "${PACKAGE_ARCH}" = "cortexa7hf-vfp-vfpv4-neon" || test "${PACKAGE_ARCH}" = "cortexa7hf-neon-vfpv4"; then
+ oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -mhard-float"
+ else
+ oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST}"
+ fi
+}
+
+do_install() {
+ install -d ${D}${bindir}/
+ echo "Installing image PN ${PN}"
+ echo "Installing image systemd_unitdir ${systemd_unitdir}"
+ echo "Installing image D ${D}"
+ echo "Installing image B ${B}"
+ if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
+ install -d ${D}${systemd_unitdir}/system/
+ install -m 0644 ${B}/autosuspend.service ${D}${systemd_unitdir}/system
+ else
+ install -d ${D}${sysconfdir}/init.d
+ install -m 0755 ${S}/lynq-autosuspend.sh ${D}${sysconfdir}/init.d/
+ install -d ${D}${sysconfdir}/rcS.d
+ ln -s ../init.d/lynq-autosuspend.sh ${D}${sysconfdir}/rcS.d/S82lynq-autosuspend-service
+ fi
+
+ install -m 0755 ${S}/autosuspend ${D}${bindir}/
+ install -d ${D}${includedir}
+}
+
+
+
+
+
+