[Feature][ZXW-235][DTR]DTR changed to waiting queue

Only Configure :No
Affected branch: master
Affected module: autosuspend
Is it affected on both ZXIC and MTK:only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I57c338fd0909cee1f1b277e8d7580c96fb814471
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/lynq-qser-autosuspend.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/lynq-qser-autosuspend.cpp
index 01ccd5d..260dcb6 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/lynq-qser-autosuspend.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/lynq-qser-autosuspend.cpp
@@ -7,7 +7,7 @@
 #include <errno.h>
 #include <pthread.h>
 #include <unistd.h>
-#include <cutils/uevent.h>
+
 
 #include <lynq_autosuspend.h>
 #include "lynq-qser-autosuspend.h"
@@ -31,16 +31,7 @@
 
 #define UEVENT_MSG_LEN 128
 
-int device_fd;
 int g_init_flag = 0;
-struct dtr_uevent {
-    const char *action;
-    const char *path;
-    const char *subsystem;
-    const char *usbevent;
-};
-
-static void parse_event(const char *msg, struct dtr_uevent *dtr_uevent);
 
 
 qser_lpm_Handler_t g_lpm_handler = NULL;
@@ -238,75 +229,35 @@
     return ret;
 }
 
-static void parse_event(const char *msg, struct dtr_uevent *dtr_uevent)
-{
-    dtr_uevent->action = "";
-    dtr_uevent->path = "";
-    dtr_uevent->subsystem = "";
-    dtr_uevent->usbevent = "";
-
-    while (*msg) {
-        if (!strncmp(msg, "ACTION=", 7))
-        {
-            msg += 7;
-            dtr_uevent->action = msg;
-        }
-        else if (!strncmp(msg, "DEVPATH=", 8))
-        {
-            msg += 8;
-            dtr_uevent->path = msg;
-        }
-        else if (!strncmp(msg, "SUBSYSTEM=", 10))
-        {
-            msg += 10;
-            dtr_uevent->subsystem = msg;
-        }
-        else if (!strncmp(msg, "USBEVENT=", 9)) {
-            msg += 9;
-            dtr_uevent->usbevent = msg;
-        }
-
-        while(*msg++);
-    }
-
-    LYINFLOG("event { '%s', '%s', '%s', '%s'}\n",
-                    dtr_uevent->action, dtr_uevent->path, dtr_uevent->subsystem,dtr_uevent->usbevent);
-}
-
-
 
 void *check_dtr(void * arg)
 {
     qser_lpm_edge_t lpm_edge;
-    char msg[UEVENT_MSG_LEN+2];
-    struct dtr_uevent dtr_uevent;
-    int n;
-    int i;
- 
-    device_fd = uevent_open_socket(4*UEVENT_MSG_LEN, true);
-    if(device_fd < 0)
-    {
-        LYERRLOG("uevent_open_socket fail\n");
-        return -1;
-    }
+    char msg[16];
+    int fd=0;
+    int ret=0;
+
     while(1) 
     {
-        n = uevent_kernel_multicast_recv(device_fd, msg, UEVENT_MSG_LEN);
-        msg[n] = '\0';
-        msg[n+1] = '\0';
-        parse_event(msg, &dtr_uevent);
-        if((!strcmp(dtr_uevent.subsystem, "xp2xp")))
+        fd = open("/sys/xp2xp/xp2xp_notify/xp2xp_state", O_RDONLY);
+        ret=read(fd, &msg,15);
+        LYERRLOG("xp2xp_state ret = %d\n", ret);
+        close(fd);
+
+        if(ret == 5)
         {
-            if(!strcmp(dtr_uevent.action, "online"))
-            {
-                lpm_edge =E_QL_LPM_FALLING;
-            }
-            else
-            {
-                lpm_edge =E_QL_LPM_RISING;
-            }
-            g_lpm_handler(lpm_edge);
+            lpm_edge =E_QL_LPM_FALLING;
         }
+        else if(ret == 6)
+        {
+            lpm_edge =E_QL_LPM_RISING;
+        }
+        else
+        {
+            continue;
+        }
+        g_lpm_handler(lpm_edge);
+
     }
  
     return 0;
@@ -343,7 +294,6 @@
     }
     g_init_flag = 0;
     ret = pthread_cancel(thid);
-    close(device_fd);
     if(!ret)
     {
         LYERRLOG("pthread cancel success, lpm deinit success\n");
diff --git a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/soc/sc/power_4line/hal_xp2xp.c b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/soc/sc/power_4line/hal_xp2xp.c
index 7d75efc..b9044fa 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/soc/sc/power_4line/hal_xp2xp.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/linux-5.10/drivers/soc/sc/power_4line/hal_xp2xp.c
@@ -50,14 +50,14 @@
 /****************************************************************************

 *											   Local Macros

 ****************************************************************************/

-#define AP2CP_WAKE_GPIO     50			/*AP»½ÐÑCPÖжÏÏß¶ÔÓ¦µÄGPIO*/

-#define AP2CP_SLEEP_GPIO    53			/*AP¸øCPµÄ˯Ãß»½ÐÑ״̬¶ÔÓ¦µÄGPIO*/

-#define CP2AP_WAKE_GPIO     131			/*CP»½ÐÑAPÖжÏÏß¶ÔÓ¦µÄGPIO*/

-#define CP2AP_SLEEP_GPIO    130			/*CP¸øAPµÄ˯Ãß»½ÐÑ״̬¶ÔÓ¦µÄGPIO*/

+#define AP2CP_WAKE_GPIO     50

+#define AP2CP_SLEEP_GPIO    53

+#define CP2AP_WAKE_GPIO     131

+#define CP2AP_SLEEP_GPIO    130

 

 

-#define AP_SLEEP_STATUS     0	/*AP˯Ãßʱ¸ÃÒý½ÅΪ0*/

-#define AP_WAKE_STATUS      1	/*AP»½ÐÑʱ¸ÃÒý½ÅΪ1*/

+#define AP_SLEEP_STATUS     0

+#define AP_WAKE_STATUS      1

 

 #define CP_SLEEP_STATUS     1	//jb.q add for dtr on 20231204

 #define CP_WAKE_STATUS      0	//jb.q add for dtr on 20231204

@@ -141,7 +141,8 @@
 /****************************************************************************

 *											  Global Variables

 ****************************************************************************/

-

+static wait_queue_head_t  wakeup_dtr_wqhead;

+static int wakeup_irq_occurs = 0;

 struct wakeup_source *xp2xp_wake_lock;

 static int xp2xp_init_flag = 0;

 static int irq_num = 0;

@@ -175,17 +176,16 @@
 

 ssize_t xp2xp_obj_show(struct kobject *kobject,struct attribute *attr,char *buf)

 {

-	

-	  if(!strcmp(attr->name, XP2XP_STATE)){

-	  		sprintf(buf, "curr_gpio_v:%d, currState:%s, sleep_cnt:%d, wake_cnt:%d, \n",g_xp2xp.curr_gpio_value,  (g_xp2xp.wake_state == 1 ? "work" : "sleep"),

-				g_xp2xp.sleep_cnt, g_xp2xp.wake_cnt

-				);

-			

-	  }	

+    wakeup_irq_occurs = 0;

+    wait_event_interruptible(wakeup_dtr_wqhead,wakeup_irq_occurs);

+    if(!strcmp(attr->name, XP2XP_STATE))

+    {

+      sprintf(buf, "%s\n",(g_xp2xp.wake_state == 1 ? "work" : "sleep"));

+    }

+

       return strlen(buf);

 }

 

-

 ssize_t xp2xp_obj_store(struct kobject *kobject,struct attribute *attr, const char *buf,size_t size)

 {

 	unsigned int value = 0;

@@ -402,8 +402,7 @@
 	unsigned int irq_type;

 	struct hal_xp2xp_dev *xp2xp_dev = (struct hal_xp2xp_dev *)priv;

 

-	disable_irq_nosync(irq);

-	xp2xp_dev->xp2xp_irq_state = 0;

+    disable_irq_nosync(irq);

 	gpio_value = 0 ;

 

 	if(xp2xp_dev->xp2xp_ws){

@@ -431,12 +430,13 @@
         xp2xp_dev->wake_state = 1;

         pm_stay_awake(g_xp2xp.dev);

 	}

-

 	if (pinctrl_select_state(xp2xp_dev->pctrl_wk_int, xp2xp_dev->st_int) < 0) {

 		printk( "setting card detect irq failed\n");

 	}

 	irq_set_irq_type(irq,irq_type);

-	up(&xp2xp_dev->wk_sem);

+	wakeup_irq_occurs = 1;

+	wake_up_interruptible(&wakeup_dtr_wqhead);

+    enable_irq(xp2xp_dev->eint_irq);

 	return IRQ_HANDLED;

 }

 /*jb.qi add for dtr uevent on 20231218 end*/

@@ -628,8 +628,7 @@
   int ret = 0;

 

    printk("kset test init!\n");

-   

-   /* ´´½¨²¢×¢²á kset_p */

+

    kset_xp2xp = kset_create_and_add("xp2xp", &xp2xp_uevent_ops, NULL);    

    

    xp2xpkobj = kzalloc(sizeof(*xp2xpkobj),GFP_KERNEL);

@@ -718,7 +717,7 @@
 	spin_lock_init(&g_xp2xp.wk_lock);

 

 	device_init_wakeup(&pdev->dev, true);//jb.q add for dtr on 20231204

-

+	init_waitqueue_head(&wakeup_dtr_wqhead);

 	g_xp2xp.xp2xp_ws = wakeup_source_register(NULL, "xp2xp");

 	if(g_xp2xp.xp2xp_ws  == NULL){

 		printk("adb_setup wakeup_source_create fail\n");

@@ -796,14 +795,14 @@
 		panic("hal_xp2xp_probe request_irq fail, %d", ret);

 	}

 

-

+	/*

 	g_xp2xp.wake_int_thread = kthread_run(xp2xp_wkcp_thread, (void *)&g_xp2xp, "xp2xp_wake_thread");

 	

 	if (IS_ERR(g_xp2xp.wake_int_thread)) {

 		printk("Can't start up our thread");

 		return PTR_ERR(g_xp2xp.wake_int_thread);

 	}	

-

+	*/

 	enable_irq_wake(g_xp2xp.eint_irq);

 /*jb.q add for dtr on 20231204 start*/

 	/* gpio request */