diff mbox series

[v3,1/3] Input: da9063_onkey - Add da9063_onkey_report_key()

Message ID 20240125133733.95081-2-biju.das.jz@bp.renesas.com
State New
Headers show
Series Add polling support for DA9063 onkey driver | expand

Commit Message

Biju Das Jan. 25, 2024, 1:37 p.m. UTC
Adding da9063_onkey_report_key() for reporting key events makes the code
simpler. So, simplify it.

While at it, update multiline code that can fit to single line.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v3:
 * New patch.
---
 drivers/input/misc/da9063_onkey.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/drivers/input/misc/da9063_onkey.c b/drivers/input/misc/da9063_onkey.c
index c338765e0ecd..06ad9d09ada8 100644
--- a/drivers/input/misc/da9063_onkey.c
+++ b/drivers/input/misc/da9063_onkey.c
@@ -75,6 +75,13 @@  static const struct da906x_chip_config da9062_regs = {
 	.name = "da9062-onkey",
 };
 
+static void da9063_onkey_report_key(struct da9063_onkey *onkey,
+				    unsigned int code, int value)
+{
+	input_report_key(onkey->input, code, value);
+	input_sync(onkey->input);
+}
+
 static void da9063_poll_on(struct work_struct *work)
 {
 	struct da9063_onkey *onkey = container_of(work,
@@ -87,12 +94,9 @@  static void da9063_poll_on(struct work_struct *work)
 	int error;
 
 	/* Poll to see when the pin is released */
-	error = regmap_read(onkey->regmap,
-			    config->onkey_status,
-			    &val);
+	error = regmap_read(onkey->regmap, config->onkey_status, &val);
 	if (error) {
-		dev_err(onkey->dev,
-			"Failed to read ON status: %d\n", error);
+		dev_err(onkey->dev, "Failed to read ON status: %d\n", error);
 		goto err_poll;
 	}
 
@@ -107,8 +111,7 @@  static void da9063_poll_on(struct work_struct *work)
 			goto err_poll;
 		}
 
-		input_report_key(onkey->input, KEY_POWER, 0);
-		input_sync(onkey->input);
+		da9063_onkey_report_key(onkey, KEY_POWER, 0);
 
 		poll = false;
 	}
@@ -159,19 +162,13 @@  static irqreturn_t da9063_onkey_irq_handler(int irq, void *data)
 	unsigned int val;
 	int error;
 
-	error = regmap_read(onkey->regmap,
-			    config->onkey_status,
-			    &val);
+	error = regmap_read(onkey->regmap, config->onkey_status, &val);
+	da9063_onkey_report_key(onkey, KEY_POWER, 1);
 	if (onkey->key_power && !error && (val & config->onkey_nonkey_mask)) {
-		input_report_key(onkey->input, KEY_POWER, 1);
-		input_sync(onkey->input);
 		schedule_delayed_work(&onkey->work, 0);
 		dev_dbg(onkey->dev, "KEY_POWER long press.\n");
 	} else {
-		input_report_key(onkey->input, KEY_POWER, 1);
-		input_sync(onkey->input);
-		input_report_key(onkey->input, KEY_POWER, 0);
-		input_sync(onkey->input);
+		da9063_onkey_report_key(onkey, KEY_POWER, 0);
 		dev_dbg(onkey->dev, "KEY_POWER short press.\n");
 	}