From 596bcc11787df53ee133403bc2088479276dbc4c Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Tue, 25 Mar 2025 16:02:24 +0000
Subject: [PATCH] drm/vc4: plane: Correct SAND30 word sizing for cropping on
 BCM2712

BCM2712/vc6 uses 256bit words when reading in P030/SAND128,
increased from 128bit on BCM2711/vc5.

Update the code for cropping the read area to handle the correct
word length.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 drivers/gpu/drm/vc4/vc4_plane.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

--- a/drivers/gpu/drm/vc4/vc4_plane.c
+++ b/drivers/gpu/drm/vc4/vc4_plane.c
@@ -1973,18 +1973,18 @@ static int vc6_plane_mode_set(struct drm
 
 			if (fb->format->format == DRM_FORMAT_P030) {
 				/*
-				 * Spec says: bits [31:4] of the given address
-				 * should point to the 128-bit word containing
-				 * the desired starting pixel, and bits[3:0]
-				 * should be between 0 and 11, indicating which
-				 * of the 12-pixels in that 128-bit word is the
+				 * Spec says: bits [31:5] of the given address
+				 * should point to the 256-bit word containing
+				 * the desired starting pixel, and bits[4:0]
+				 * should be between 0 and 23, indicating which
+				 * of the 24-pixels in that 256-bit word is the
 				 * first pixel to be used
 				 */
 				u32 remaining_pixels = src_x % 96;
-				u32 aligned = remaining_pixels / 12;
-				u32 last_bits = remaining_pixels % 12;
+				u32 aligned = remaining_pixels / 24;
+				u32 last_bits = remaining_pixels % 24;
 
-				x_off = aligned * 16 + last_bits;
+				x_off = aligned * 32 + last_bits;
 				pix_per_tile = 96;
 			} else {
 				pix_per_tile = tile_width / fb->format->cpp[0];
