Using spinlock to protect interrupt flag
authorYan Zhang <zhangy26@motorola.com>
Tue, 21 May 2019 05:36:11 +0000 (13:36 +0800)
committerxiest1 <xiest1@lenovo.com>
Tue, 5 Nov 2019 09:32:04 +0000 (17:32 +0800)
Using spinlock to protect interrupt flag in critical section.

Change-Id: Ia9cf2ba638763bb1a87954deefe8a65083058439
Signed-off-by: Yan Zhang <zhangy26@motorola.com>
Reviewed-on: https://gerrit.mot.com/1357136
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

drivers/input/egistec/et320-int.c

index 350b40d198249d67d1d682acc344570486848537..9b50e87b602491cea025431a3f3780efbb65733f 100755 (executable)
 #define        LEVEL_TRIGGER_HIGH      0x3\r
 #define EGIS_NAVI_INPUT 1  /* 1:open ; 0:close */\r
 struct wake_lock et320_wake_lock;\r
-\r
+/*\r
+ * spinlock for protecting interrupt flag\r
+ */\r
+static DEFINE_SPINLOCK(interrupt_lock);\r
 /*\r
  * FPS interrupt table\r
  */\r
@@ -240,13 +243,20 @@ static irqreturn_t fp_eint_func(int irq, void *dev_id)
 static irqreturn_t fp_eint_func_ll(int irq , void *dev_id)\r
 {\r
        pr_debug("etspi: fp_eint_func_ll\n");\r
+       spin_lock(&interrupt_lock);\r
        fps_ints.finger_on = 1;\r
-       /* fps_ints.int_count = 0; */\r
-       disable_irq_nosync(gpio_irq);\r
-       fps_ints.drdy_irq_flag = DRDY_IRQ_DISABLE;\r
+       if(fps_ints.drdy_irq_flag == DRDY_IRQ_DISABLE) {\r
+               DEBUG_PRINT("irq_flag is disabled\n");\r
+       } else {\r
+               /* fps_ints.int_count = 0; */\r
+               fps_ints.drdy_irq_flag = DRDY_IRQ_DISABLE;\r
+               disable_irq_nosync(gpio_irq);\r
+       }\r
+       spin_unlock(&interrupt_lock);\r
        wake_up_interruptible(&interrupt_waitq);\r
        /* printk_ratelimited(KERN_WARNING "-----------   zq fp fp_eint_func  ,fps_ints.int_count=%d",fps_ints.int_count);*/\r
        wake_lock_timeout(&et320_wake_lock, msecs_to_jiffies(1500));\r
+\r
        return IRQ_RETVAL(IRQ_HANDLED);\r
 }\r
 \r
@@ -274,6 +284,7 @@ int Interrupt_Init(struct etspi_data *etspi, int int_mode, int detect_period, in
        int err = 0;\r
        int status = 0;\r
        static unsigned long jt;\r
+       unsigned long flags;\r
 \r
        pr_debug("etspi: --  %s mode = %d period = %d threshold = %d\n",\\r
                __func__, int_mode, detect_period, detect_threshold);\r
@@ -284,7 +295,7 @@ int Interrupt_Init(struct etspi_data *etspi, int int_mode, int detect_period, in
        fps_ints.detect_period = detect_period;\r
        fps_ints.detect_threshold = detect_threshold;\r
        fps_ints.int_count = 0;\r
-       fps_ints.finger_on = 0;\r
+\r
 \r
 \r
        if (request_irq_done == 0)      {\r
@@ -332,21 +343,25 @@ int Interrupt_Init(struct etspi_data *etspi, int int_mode, int detect_period, in
                DEBUG_PRINT("etspi:Interrupt_Init:gpio_to_irq return: %d\n", gpio_irq);\r
                DEBUG_PRINT("etspi:Interrupt_Init:request_irq return: %d\n", err);\r
                /* disable_irq_nosync(gpio_irq); */\r
+               spin_lock_irqsave(&interrupt_lock, flags);\r
                fps_ints.drdy_irq_flag = DRDY_IRQ_ENABLE;\r
                enable_irq_wake(gpio_irq);\r
                request_irq_done = 1;\r
+               spin_unlock_irqrestore(&interrupt_lock, flags);\r
        }\r
 \r
 \r
+       spin_lock_irqsave(&interrupt_lock, flags);\r
+       fps_ints.finger_on = 0;\r
        if (fps_ints.drdy_irq_flag == DRDY_IRQ_DISABLE) {\r
                fps_ints.drdy_irq_flag = DRDY_IRQ_ENABLE;\r
-               enable_irq_wake(gpio_irq);\r
                enable_irq(gpio_irq);\r
                if (printk_timed_ratelimit(&jt, 500))\r
                        DEBUG_PRINT("etspi: Interrupt_Init: %s irq/done:%d %d mode:%d\\r
                        period:%d \threshold:%d \n", __func__, gpio_irq, request_irq_done,\\r
                        int_mode, detect_period, detect_threshold);\r
        }\r
+       spin_unlock_irqrestore(&interrupt_lock, flags);\r
 done:\r
        return 0;\r
 }\r
@@ -364,15 +379,19 @@ done:
 \r
 int Interrupt_Free(struct etspi_data *etspi)\r
 {\r
+       unsigned long flags;\r
        pr_debug("etspi: %s\n", __func__);\r
+       spin_lock_irqsave(&interrupt_lock, flags);\r
        fps_ints.finger_on = 0;\r
-\r
        if (fps_ints.drdy_irq_flag == DRDY_IRQ_ENABLE) {\r
                DEBUG_PRINT("etspi: %s (DISABLE IRQ)\n", __func__);\r
                disable_irq_nosync(gpio_irq);\r
+               fps_ints.drdy_irq_flag = DRDY_IRQ_DISABLE;\r
+               spin_unlock_irqrestore(&interrupt_lock, flags);\r
                /* disable_irq(gpio_irq); */\r
                del_timer_sync(&fps_ints.timer);\r
-               fps_ints.drdy_irq_flag = DRDY_IRQ_DISABLE;\r
+       } else {\r
+               spin_unlock_irqrestore(&interrupt_lock, flags);\r
        }\r
        return 0;\r
 }\r
@@ -1072,7 +1091,7 @@ static int etspi_probe(struct platform_device *pdev)
                pr_err("%s platforminit failed\n", __func__);\r
                goto etspi_probe_platformInit_failed;\r
        }\r
-\r
+       //intialize irq flag to disable during probe\r
        fps_ints.drdy_irq_flag = DRDY_IRQ_DISABLE;\r
 \r
 #ifdef ETSPI_NORMAL_MODE\r
@@ -1128,8 +1147,6 @@ static int etspi_probe(struct platform_device *pdev)
        }\r
        etspi_reset(etspi);\r
 \r
-       fps_ints.drdy_irq_flag = DRDY_IRQ_DISABLE;\r
-\r
        /* the timer is for ET310 */\r
        setup_timer(&fps_ints.timer, interrupt_timer_routine, (unsigned long)&fps_ints);\r
        add_timer(&fps_ints.timer);\r