[PATCH] input: gpio-keys - optimize wakeup sequence.

From: Abhishek Kumar Singh
Date: Thu Oct 26 2023 - 01:53:29 EST


Dear Mr. Dmitry,
Greetings!


The patch removes unused many APIs call chain for every suspend/resume of the device 
if no key press event triggered.


There is a call back function gpio_keys_resume() called for
every suspend/resume of the device. and whenever this function called, it is
reading the status of the key. And gpio_keys_resume() API further calls the
below chain of API irrespective of key press event


APIs call chain:
static void gpio_keys_report_state(struct gpio_keys_drvdata *ddata)
static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
gpiod_get_value_cansleep(bdata->gpiod);
input_event(input, type, *bdata->code, state);
input_sync(input);


The patch avoid the above APIs call chain if there is no key press event triggered.
It will save the device computational resources, power resources and optimize the suspend/resume time


Signed-off-by: Abhishek Kumar Singh <abhi1.singh@xxxxxxxxxxx>


---
 linux-6.4.11/drivers/input/keyboard/gpio_keys.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)


diff --git a/linux-6.4.11/drivers/input/keyboard/gpio_keys.c b/linux-6.4.11/drivers/input/keyboard/gpio_keys.c
index 13a8ba5..cd1609e 100644
--- a/linux-6.4.11/drivers/input/keyboard/gpio_keys.c
+++ b/linux-6.4.11/drivers/input/keyboard/gpio_keys.c
@@ -687,8 +687,12 @@ static void gpio_keys_report_state(struct gpio_keys_drvdata *ddata)
 
   for (i = 0; i < ddata->pdata->nbuttons; i++) {
     struct gpio_button_data *bdata = &ddata->data[i];
-    if (bdata->gpiod)
-      gpio_keys_gpio_report_event(bdata);
+    if (bdata->gpiod) {
+      struct gpio_keys_button *button = bdata->button;
+      if(button->value) {
+        gpio_keys_gpio_report_event(bdata);
+      }
+    }
   }
   input_sync(input);
 }
---




Thanks and Regards,
Abhishek Kumar Singh
Sr. Chief Engineer, Samsung Electronics, Noida-India
 
  
 

Attachment: input_keys_optimized.zip
Description: Binary data