From ef0f93264cc0624b2bd32fbdefa42274e58a2153 Mon Sep 17 00:00:00 2001
From: chenzhen <chenzhen@rock-chips.com>
Date: Thu, 29 Sep 2016 09:01:12 +0800
Subject: [PATCH] MALI: midgard: RK: not to power off all the pm cores

This is a workaround for the issue that
"400M, 500M and 600M of clk_gpu needs high vdd_gpu",
according to "6.1" of Mali Application Note
"Potential glitches on Power Domain interfaces".

Change-Id: I58daa3cf796802f073f67bacb62734516be76205
Signed-off-by: chenzhen <chenzhen@rock-chips.com>
---
 .../backend/gpu/mali_kbase_pm_driver.c        | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/gpu/arm/midgard/backend/gpu/mali_kbase_pm_driver.c b/drivers/gpu/arm/midgard/backend/gpu/mali_kbase_pm_driver.c
index 046ebcb7b508..03ba23d54365 100644
--- a/drivers/gpu/arm/midgard/backend/gpu/mali_kbase_pm_driver.c
+++ b/drivers/gpu/arm/midgard/backend/gpu/mali_kbase_pm_driver.c
@@ -21,6 +21,9 @@
  * Base kernel Power Management hardware control
  */
 
+// #define ENABLE_DEBUG_LOG
+#include "../../platform/rk/custom_log.h"
+
 #include <mali_kbase.h>
 #include <mali_kbase_config_defaults.h>
 #include <mali_midg_regmap.h>
@@ -71,6 +74,26 @@ enum kbasep_pm_action {
 	ACTION_PWRACTIVE = (SHADER_PWRACTIVE_LO - SHADER_PRESENT_LO)
 };
 
+/*---------------------------------------------------------------------------*/
+
+static bool is_action_of_powering_off_l2(enum kbase_pm_core_type core_type,
+					 enum kbasep_pm_action active)
+{
+	return (KBASE_PM_CORE_L2 == core_type) && (ACTION_PWROFF  == active);
+}
+
+static bool is_action_of_powering_off_shader(enum kbase_pm_core_type core_type,
+					     enum kbasep_pm_action active)
+{
+	return (KBASE_PM_CORE_SHADER == core_type) && (ACTION_PWROFF  == active);
+}
+
+static bool is_action_of_powering_off_tiler(enum kbase_pm_core_type core_type,
+					    enum kbasep_pm_action active)
+{
+	return (KBASE_PM_CORE_TILER == core_type) && (ACTION_PWROFF  == active);
+}
+
 static u64 kbase_pm_get_state(
 		struct kbase_device *kbdev,
 		enum kbase_pm_core_type core_type,
@@ -153,6 +176,25 @@ static void kbase_pm_invoke(struct kbase_device *kbdev,
 
 	lockdep_assert_held(&kbdev->pm.power_change_lock);
 
+	/*-------------------------------------------------------*/
+
+	if ( is_action_of_powering_off_l2(core_type, action) ) {
+		D("not to power off l2 actually.");
+		return;
+	}
+	if ( is_action_of_powering_off_shader(core_type, action) ) {
+		D("not to power off shader actually. cores_lo : 0x%x, hi : 0x%x.",
+		  lo,
+		  hi);
+		return;
+	}
+	if ( is_action_of_powering_off_tiler(core_type, action) ) {
+		D("not to power off tiler actually.");
+		return;
+	}
+
+	/*-------------------------------------------------------*/
+
 	reg = core_type_to_reg(core_type, action);
 
 	KBASE_DEBUG_ASSERT(reg);
-- 
2.34.1