From 6fa17b6920fde0287303d029472e697ebdbcbb00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ADra=20Canal?= <mcanal@igalia.com>
Date: Mon, 25 May 2026 16:53:06 -0300
Subject: [PATCH] [BACKPORT] drm/v3d: Introduce Runtime Power Management
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Make the downstream version match the upstream commit
458f2a712ab4 ("drm/v3d: Introduce Runtime Power Management").

Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 drivers/gpu/drm/v3d/v3d_power.c | 38 ++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 17 deletions(-)

--- a/drivers/gpu/drm/v3d/v3d_power.c
+++ b/drivers/gpu/drm/v3d/v3d_power.c
@@ -2,53 +2,61 @@
 /* Copyright (C) 2026 Raspberry Pi */
 
 #include <linux/clk.h>
-#include <linux/reset.h>
 
 #include <drm/drm_print.h>
 
 #include "v3d_drv.h"
 #include "v3d_regs.h"
 
-static void
+static int
 v3d_resume_sms(struct v3d_dev *v3d)
 {
 	if (v3d->ver < V3D_GEN_71)
-		return;
+		return 0;
 
 	V3D_SMS_WRITE(V3D_SMS_TEE_CS, V3D_SMS_CLEAR_POWER_OFF);
 
 	if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
 				    V3D_SMS_STATE) == V3D_SMS_IDLE), 100)) {
 		drm_err(&v3d->drm, "Failed to power up SMS\n");
+		return -ETIMEDOUT;
 	}
 
 	v3d_reset_sms(v3d);
+
+	return 0;
 }
 
-static void
+static int
 v3d_suspend_sms(struct v3d_dev *v3d)
 {
 	if (v3d->ver < V3D_GEN_71)
-		return;
+		return 0;
 
 	V3D_SMS_WRITE(V3D_SMS_TEE_CS, V3D_SMS_POWER_OFF);
 
 	if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
 				    V3D_SMS_STATE) == V3D_SMS_POWER_OFF_STATE), 100)) {
 		drm_err(&v3d->drm, "Failed to power off SMS\n");
+		return -ETIMEDOUT;
 	}
+
+	return 0;
 }
 
 int v3d_power_suspend(struct device *dev)
 {
 	struct drm_device *drm = dev_get_drvdata(dev);
 	struct v3d_dev *v3d = to_v3d_dev(drm);
+	int ret;
 
 	v3d_irq_disable(v3d);
-	v3d_suspend_sms(v3d);
 
-	if (v3d->reset)
-		reset_control_assert(v3d->reset);
+	ret = v3d_suspend_sms(v3d);
+	if (ret) {
+		v3d_irq_enable(v3d);
+		return ret;
+	}
 
 	clk_disable_unprepare(v3d->clk);
 
@@ -65,19 +73,15 @@ int v3d_power_resume(struct device *dev)
 	if (ret)
 		return ret;
 
-	if (v3d->reset) {
-		ret = reset_control_deassert(v3d->reset);
-		if (ret)
-			goto clk_disable;
+	ret = v3d_resume_sms(v3d);
+	if (ret) {
+		clk_disable_unprepare(v3d->clk);
+		return ret;
 	}
 
-	v3d_resume_sms(v3d);
+	v3d_init_hw_state(v3d);
 	v3d_mmu_set_page_table(v3d);
 	v3d_irq_enable(v3d);
 
 	return 0;
-
-clk_disable:
-	clk_disable_unprepare(v3d->clk);
-	return ret;
 }
