From 8f44ced6b386bfb72963d73de2a39d91c06d5089 Mon Sep 17 00:00:00 2001
From: Richard Oliver <richard.oliver@raspberrypi.com>
Date: Tue, 16 Dec 2025 15:23:59 +0000
Subject: [PATCH] media: i2c: imx500: Allow larger SPI transfers

Remove the arbitrary 1 MiB transfer limit from imx500_spi_write() as
the 1 MiB chunk limitation for firmware / network transfers is already
upheld by imx500_state_transition(). This allows for larger input
tensors to be injected via imx500_inject_input_tensor() (where there is
no 1 MiB chunk limitation).

Increase the number of poll attempts whilst waiting for the injection
handshake register to be TRANS_COMP to allow more time for the checksum
of larger input tensors to be calculated.

Alter error messages in imx500_inject_input_tensor() so that
imx500_spi_write() and imx500_injection_wait_transfer_complete() errors
may be more easily differentiated.

Signed-off-by: Richard Oliver <richard.oliver@raspberrypi.com>
---
 drivers/media/i2c/imx500.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/media/i2c/imx500.c
+++ b/drivers/media/i2c/imx500.c
@@ -1937,7 +1937,7 @@ static void imx500_clear_fw_network(stru
 static int __must_check imx500_spi_write(struct imx500 *state, const u8 *data,
 					 size_t size)
 {
-	if (size % 4 || size > ONE_MIB)
+	if (size % 4)
 		return -EINVAL;
 
 	if (!state->spi_device)
@@ -1957,7 +1957,7 @@ static int imx500_injection_wait_transfe
 
 	/* Continue polling until we reach the final TRANS_COMP state */
 	while (hndsk_reg.val != IMX500_DD_DAT_INJECTION_HNDSK_TRANS_COMP) {
-		ret = imx500_poll_status_reg(imx500, &hndsk_reg, 5);
+		ret = imx500_poll_status_reg(imx500, &hndsk_reg, 10);
 		if (ret) {
 			dev_err(&client->dev,
 				"Handshake register did not update from state %llu\n",
@@ -2085,7 +2085,7 @@ static int imx500_inject_input_tensor(st
 
 	ret = imx500_injection_wait_transfer_complete(imx500);
 	if (ret) {
-		dev_err(&client->dev, "SPI transfer of input tensor failed\n");
+		dev_err(&client->dev, "Input tensor transfer failed to complete\n");
 		return ret;
 	}
 
