All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Lyude Paul <lyude@redhat.com>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Subject: [PATCH 2/9] Input: synaptics-rmi4 - introduce rmi_f34v7_check_command_status() helper
Date: Wed,  8 Jun 2022 14:48:01 +0200	[thread overview]
Message-ID: <20220608124808.51402-3-matthias.schiffer@ew.tq-group.com> (raw)
In-Reply-To: <20220608124808.51402-1-matthias.schiffer@ew.tq-group.com>

Add a function that waits for the last command to complete and checks
the status, and use it where appropriate. This prepares for the subsequent
fix of the completion condition in rmi_f34_attention(), which would
previously lead to a timeout instead of a more detailed error message
whenever a command was unsuccessful with v7/v8 bootloaders.

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
---
 drivers/input/rmi4/rmi_f34v7.c | 36 +++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/drivers/input/rmi4/rmi_f34v7.c b/drivers/input/rmi4/rmi_f34v7.c
index 8d7ec9d89b18..9049acb3a994 100644
--- a/drivers/input/rmi4/rmi_f34v7.c
+++ b/drivers/input/rmi4/rmi_f34v7.c
@@ -72,6 +72,24 @@ static int rmi_f34v7_wait_for_idle(struct f34_data *f34, int timeout_ms)
 	return 0;
 }
 
+static int rmi_f34v7_check_command_status(struct f34_data *f34, int timeout_ms)
+{
+	int ret;
+
+	ret = rmi_f34v7_wait_for_idle(f34, timeout_ms);
+	if (ret < 0)
+		return ret;
+
+	ret = rmi_f34v7_read_flash_status(f34);
+	if (ret < 0)
+		return ret;
+
+	if (f34->v7.flash_status != 0x00)
+		return -EIO;
+
+	return 0;
+}
+
 static int rmi_f34v7_write_command_single_transaction(struct f34_data *f34,
 						      u8 cmd)
 {
@@ -318,6 +336,10 @@ static int rmi_f34v7_read_partition_table(struct f34_data *f34)
 		return ret;
 	}
 
+	/*
+	 * rmi_f34v7_check_command_status() can't be used here, as this
+	 * function is called before IRQs are available
+	 */
 	timeout = msecs_to_jiffies(F34_WRITE_WAIT_MS);
 	while (time_before(jiffies, timeout)) {
 		usleep_range(5000, 6000);
@@ -674,7 +696,7 @@ static int rmi_f34v7_erase_config(struct f34_data *f34)
 		break;
 	}
 
-	ret = rmi_f34v7_wait_for_idle(f34, F34_ERASE_WAIT_MS);
+	ret = rmi_f34v7_check_command_status(f34, F34_ERASE_WAIT_MS);
 	if (ret < 0)
 		return ret;
 
@@ -693,7 +715,7 @@ static int rmi_f34v7_erase_guest_code(struct f34_data *f34)
 	if (ret < 0)
 		return ret;
 
-	ret = rmi_f34v7_wait_for_idle(f34, F34_ERASE_WAIT_MS);
+	ret = rmi_f34v7_check_command_status(f34, F34_ERASE_WAIT_MS);
 	if (ret < 0)
 		return ret;
 
@@ -712,7 +734,7 @@ static int rmi_f34v7_erase_all(struct f34_data *f34)
 	if (ret < 0)
 		return ret;
 
-	ret = rmi_f34v7_wait_for_idle(f34, F34_ERASE_WAIT_MS);
+	ret = rmi_f34v7_check_command_status(f34, F34_ERASE_WAIT_MS);
 	if (ret < 0)
 		return ret;
 
@@ -787,7 +809,7 @@ static int rmi_f34v7_read_blocks(struct f34_data *f34,
 		if (ret < 0)
 			return ret;
 
-		ret = rmi_f34v7_wait_for_idle(f34, F34_ENABLE_WAIT_MS);
+		ret = rmi_f34v7_check_command_status(f34, F34_ENABLE_WAIT_MS);
 		if (ret < 0)
 			return ret;
 
@@ -871,7 +893,7 @@ static int rmi_f34v7_write_f34v7_blocks(struct f34_data *f34,
 			return ret;
 		}
 
-		ret = rmi_f34v7_wait_for_idle(f34, F34_ENABLE_WAIT_MS);
+		ret = rmi_f34v7_check_command_status(f34, F34_ENABLE_WAIT_MS);
 		if (ret < 0)
 			return ret;
 
@@ -944,7 +966,7 @@ static int rmi_f34v7_write_flash_config(struct f34_data *f34)
 	rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev,
 		"%s: Erase flash config command written\n", __func__);
 
-	ret = rmi_f34v7_wait_for_idle(f34, F34_WRITE_WAIT_MS);
+	ret = rmi_f34v7_check_command_status(f34, F34_WRITE_WAIT_MS);
 	if (ret < 0)
 		return ret;
 
@@ -1297,7 +1319,7 @@ static int rmi_f34v7_enter_flash_prog(struct f34_data *f34)
 	if (ret < 0)
 		return ret;
 
-	ret = rmi_f34v7_wait_for_idle(f34, F34_ENABLE_WAIT_MS);
+	ret = rmi_f34v7_check_command_status(f34, F34_ENABLE_WAIT_MS);
 	if (ret < 0)
 		return ret;
 
-- 
2.25.1


  parent reply	other threads:[~2022-06-08 12:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 12:47 [PATCH 0/9] Input: synaptics-rmi4 - Bootloader v7/v8 firmware update improvements Matthias Schiffer
2022-06-08 12:48 ` [PATCH 1/9] Input: synaptics-rmi4 - fix firmware update operations with bootloader v8 Matthias Schiffer
2022-09-22 20:06   ` Lyude Paul
2022-09-23  9:12     ` Matthias Schiffer
2022-09-23 19:13       ` Lyude Paul
2022-06-08 12:48 ` Matthias Schiffer [this message]
2022-06-08 12:48 ` [PATCH 3/9] Input: synaptics-rmi4 - fix command completion check for bootloader v7/v8 Matthias Schiffer
2022-06-08 12:48 ` [PATCH 4/9] Input: synaptics-rmi4 - rewrite partition table unconditionally Matthias Schiffer
2022-06-08 12:48 ` [PATCH 5/9] Input: synaptics-rmi4 - reset after writing partition table Matthias Schiffer
2022-06-08 12:48 ` [PATCH 6/9] Input: synaptics-rmi4 - make rmi_f34v7_erase_all() use the "erase all" command Matthias Schiffer
2022-06-08 12:48 ` [PATCH 7/9] Input: synaptics-rmi4 - remove unneeded struct register_offset Matthias Schiffer
2022-06-08 12:48 ` [PATCH 8/9] Input: synaptics-rmi4 - simplify rmi_f34v7_start_reflash() Matthias Schiffer
2022-06-08 12:48 ` [PATCH 9/9] Input: synaptics-rmi4 - drop useless gotos in rmi_f34v7_do_reflash() Matthias Schiffer
2022-06-27  8:31 ` [PATCH 0/9] Input: synaptics-rmi4 - Bootloader v7/v8 firmware update improvements Matthias Schiffer
2022-08-15  7:43   ` Matthias Schiffer
2022-09-15  8:02     ` Matthias Schiffer
2022-09-16 22:39       ` Lyude Paul
2022-09-16 22:50         ` Dmitry Torokhov
2022-09-16 22:51           ` Lyude Paul
2022-09-22 20:18 ` Lyude Paul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220608124808.51402-3-matthias.schiffer@ew.tq-group.com \
    --to=matthias.schiffer@ew.tq-group.com \
    --cc=Jason@zx2c4.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyude@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.