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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
v3:
 * New patch.
---
 drivers/input/misc/da9063_onkey.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

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");
 	}
 
-- 
2.25.1





[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux