[Feature][task-view-656][AUTOSUSPEND]add dtr callback func
Only Configure: No
Affected branch: master
Affected module: AUTOSUSPEND
Is it affected on both ZXIC and MTK: only MTK
Self-test: yes
Doc Update: Yes
Change-Id: I138c942d90cf2e7a3e2fc593e780fd0c9ec460bb
diff --git a/common_src/lib/libautosuspend/libautosuspend.c b/common_src/lib/libautosuspend/libautosuspend.c
index defbff3..c8f8d0c 100755
--- a/common_src/lib/libautosuspend/libautosuspend.c
+++ b/common_src/lib/libautosuspend/libautosuspend.c
@@ -11,6 +11,8 @@
#include <pthread.h>
#include <stdbool.h>
#include <time.h>
+#include <unistd.h>
+#include <fcntl.h>
#define LOG_TAG "libautosuspend"
@@ -21,6 +23,13 @@
#define SERVER_DATA_PATH "/tmp/autosuspend.data.server"
// #define CLIENT_PATH "/tmp/autosuspend.client"
+typedef void (*lynq_lpm_Handler_t)(int lpm_edge);
+
+lynq_lpm_Handler_t g_lpm_handler = NULL;
+
+pthread_t dtr_thid;
+
+int g_init_flag;
static int client_sock_fd;
@@ -474,8 +483,90 @@
{
return -1;
}
-
+}
+
+
+
+static void *check_dtr(void * arg)
+{
+ int lpm_edge;
+ char msg[32];
+ int fd=0;
+ int ret=0;
+
+ while(1)
+ {
+ fd = open("/dev/wakeup_dtr_dev", O_RDONLY);
+ ret=read(fd, &msg,31);
+ ALOGI("wakeup_dtr_dev: %s\n", msg);
+ close(fd);
+
+ if(msg[14] == '0')
+ {
+ lpm_edge = 0;
+ }
+ else if(msg[14] =='1')
+ {
+ lpm_edge = 1;
+ }
+ else
+ {
+ continue;
+ }
+ ALOGI("dtr status: %d\n", lpm_edge);
+ g_lpm_handler(lpm_edge);
+
+ }
+
+ return 0;
+}
+
+
+int lynq_dtr_register(lynq_lpm_Handler_t qser_lpm_handler)
+{
+ int ret;
+ if(lynq_lpm_handler == NULL)
+ {
+ RLOGI("lynq_lpm_handler is NULL\n");
+ return -1;
+ }
+ if(g_init_flag != 0)
+ {
+ RLOGI("g_init_flag is error\n");
+ return -1;
+ }
+ g_init_flag = 1;
+ g_lpm_handler = qser_lpm_handler;
+ ret = pthread_create(&dtr_thid,NULL,check_dtr,NULL);
+ if(ret != 0)
+ {
+ RLOGI("pthread create fail, qser_lpm_init fail\n");
+ }
+ return ret;
+}
+
+int qser_dtr_deregister(void)
+{
+ int ret;
+ if(g_init_flag != 1)
+ {
+ RLOGI("g_init_flag is error");
+ return -1;
+ }
+ g_init_flag = 0;
+ g_lpm_handler=NULL;
+ ret = pthread_cancel(dtr_thid);
+ if(!ret)
+ {
+ RLOGI("pthread cancel success, lpm deinit success\n");
+ }
+ else
+ {
+ RLOGI("pthread cancel fail, lpm deinit fail\n");
+ }
+ return ret;
}
+