From e0958c306679d65070c65bf82893dd51eca1b944 Mon Sep 17 00:00:00 2001
From: chenzhen <chenzhen@rock-chips.com>
Date: Fri, 4 Mar 2016 21:49:35 +0800
Subject: [PATCH] MALI: rockchip: modify to build in kernel 4.4.

Change-Id: Ib462c42337e655607b2e222d7d97064dfc1c76c4
Signed-off-by: chenzhen <chenzhen@rock-chips.com>
---
 drivers/gpu/arm/midgard/Kconfig                |  2 +-
 drivers/gpu/arm/midgard/mali_kbase_config.h    | 10 ++++------
 .../gpu/arm/midgard/mali_kbase_core_linux.c    | 18 +++++++-----------
 drivers/gpu/arm/midgard/mali_kbase_defs.h      |  3 +--
 .../midgard/mali_kbase_gpu_memory_debugfs.c    |  4 ++--
 .../midgard/mali_kbase_mem_profile_debugfs.c   |  2 +-
 6 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/arm/midgard/Kconfig b/drivers/gpu/arm/midgard/Kconfig
index a6780dc83bee..b45420da8282 100644
--- a/drivers/gpu/arm/midgard/Kconfig
+++ b/drivers/gpu/arm/midgard/Kconfig
@@ -66,7 +66,7 @@ config MALI_MIDGARD_DVFS
 config MALI_MIDGARD_RT_PM
 	bool "Enable Runtime power management"
 	depends on MALI_MIDGARD
-	depends on PM_RUNTIME
+	depends on PM
 	default y
 	help
 	  Choose this option to enable runtime power management in the Mali Midgard DDK.
diff --git a/drivers/gpu/arm/midgard/mali_kbase_config.h b/drivers/gpu/arm/midgard/mali_kbase_config.h
index 41c885691a65..816e45c4d02d 100644
--- a/drivers/gpu/arm/midgard/mali_kbase_config.h
+++ b/drivers/gpu/arm/midgard/mali_kbase_config.h
@@ -66,20 +66,18 @@ struct kbase_device;
  */
 struct kbase_platform_funcs_conf {
 	/**
-	 * platform_init_func 
-         *      - platform specific init function pointer
+	 * platform_init_func - platform specific init function pointer
 	 * @kbdev - kbase_device pointer
 	 *
-	 * Returns 0 on success,
-         * negative error code otherwise.
+	 * Returns 0 on success, negative error code otherwise.
 	 *
 	 * Function pointer for platform specific initialization or NULL if no
 	 * initialization function is required. At the point this the GPU is
 	 * not active and its power and clocks are in unknown (platform specific
 	 * state) as kbase doesn't yet have control of power and clocks.
 	 *
-	 * The platform specific private pointer kbase_device::platform_context 
-         * can be accessed (and possibly initialized) in here.
+	 * The platform specific private pointer kbase_device::platform_context
+	 * can be accessed (and possibly initialized) in here.
 	 */
 	int (*platform_init_func)(struct kbase_device *kbdev);
 	/**
diff --git a/drivers/gpu/arm/midgard/mali_kbase_core_linux.c b/drivers/gpu/arm/midgard/mali_kbase_core_linux.c
index 09688219d5f3..426947fd76a2 100644
--- a/drivers/gpu/arm/midgard/mali_kbase_core_linux.c
+++ b/drivers/gpu/arm/midgard/mali_kbase_core_linux.c
@@ -14,7 +14,8 @@
  *
  */
 
-
+#define ENABLE_DEBUG_LOG
+#include "platform/rk/custom_log.h"
 
 #include <mali_kbase.h>
 #include <mali_kbase_hwaccess_gpuprops.h>
@@ -48,6 +49,7 @@
 #include <linux/syscalls.h>
 #endif /* CONFIG_KDS */
 
+#include <linux/pm_runtime.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/poll.h>
@@ -1293,7 +1295,7 @@ static int kbase_open(struct inode *inode, struct file *filp)
 	  */
 #else
 	debugfs_create_bool("infinite_cache", 0644, kctx->kctx_dentry,
-			&kctx->infinite_cache_active);
+			(bool*)&(kctx->infinite_cache_active));
 #endif /* CONFIG_MALI_COH_USER */
 
 	mutex_init(&kctx->mem_profile_lock);
@@ -3158,7 +3160,7 @@ static int kbase_device_debugfs_init(struct kbase_device *kbdev)
 #ifndef CONFIG_MALI_COH_USER
 	debugfs_create_bool("infinite_cache", 0644,
 			debugfs_ctx_defaults_directory,
-			&kbdev->infinite_cache_active_default);
+			(bool*)&(kbdev->infinite_cache_active_default));
 #endif /* CONFIG_MALI_COH_USER */
 
 	debugfs_create_size_t("mem_pool_max_size", 0644,
@@ -3533,12 +3535,6 @@ static int kbase_platform_device_probe(struct platform_device *pdev)
 	int err = 0;
 	int i;
 
-	printk(KERN_INFO "arm_release_ver of this mali_ko is '%s', rk_ko_ver is '%d', built at '%s', on '%s'.",
-           MALI_RELEASE_NAME,
-           ROCKCHIP_VERSION,
-           __TIME__,
-           __DATE__);
-
 #ifdef CONFIG_OF
 	err = kbase_platform_early_init();
 	if (err) {
@@ -3648,7 +3644,7 @@ static int kbase_platform_device_probe(struct platform_device *pdev)
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)) && defined(CONFIG_OF) \
 			&& defined(CONFIG_PM_OPP)
 	/* Register the OPPs if they are available in device tree */
-	if (of_init_opp_table(kbdev->dev) < 0)
+	if (dev_pm_opp_of_add_table(kbdev->dev) < 0)
 		dev_dbg(kbdev->dev, "OPP table not found\n");
 #endif
 
@@ -3688,7 +3684,7 @@ out_sysfs:
 	kbase_common_device_remove(kbdev);
 out_common_init:
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
-	of_free_opp_table(kbdev->dev);
+	dev_pm_opp_of_remove_table(kbdev->dev);
 #endif
 	clk_disable_unprepare(kbdev->clock);
 out_clock_prepare:
diff --git a/drivers/gpu/arm/midgard/mali_kbase_defs.h b/drivers/gpu/arm/midgard/mali_kbase_defs.h
index b4e5809a3d54..7d8590af031e 100644
--- a/drivers/gpu/arm/midgard/mali_kbase_defs.h
+++ b/drivers/gpu/arm/midgard/mali_kbase_defs.h
@@ -64,8 +64,7 @@
 #include <linux/clk.h>
 #include <linux/regulator/consumer.h>
 
-#if defined(CONFIG_PM_RUNTIME) || \
-	(defined(CONFIG_PM) && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
+#if defined(CONFIG_PM)
 #define KBASE_PM_RUNTIME 1
 #endif
 
diff --git a/drivers/gpu/arm/midgard/mali_kbase_gpu_memory_debugfs.c b/drivers/gpu/arm/midgard/mali_kbase_gpu_memory_debugfs.c
index ca264049653c..5aff522e594a 100644
--- a/drivers/gpu/arm/midgard/mali_kbase_gpu_memory_debugfs.c
+++ b/drivers/gpu/arm/midgard/mali_kbase_gpu_memory_debugfs.c
@@ -43,14 +43,14 @@ static int kbasep_gpu_memory_seq_show(struct seq_file *sfile, void *data)
 
 		kbdev = list_entry(entry, struct kbase_device, entry);
 		/* output the total memory usage and cap for this device */
-		ret = seq_printf(sfile, "%-16s  %10u\n",
+		seq_printf(sfile, "%-16s  %10u\n",
 				kbdev->devname,
 				atomic_read(&(kbdev->memdev.used_pages)));
 		mutex_lock(&kbdev->kctx_list_lock);
 		list_for_each_entry(element, &kbdev->kctx_list, link) {
 			/* output the memory usage and cap for each kctx
 			* opened on this device */
-			ret = seq_printf(sfile, "  %s-0x%p %10u\n",
+			seq_printf(sfile, "  %s-0x%p %10u\n",
 				"kctx",
 				element->kctx,
 				atomic_read(&(element->kctx->used_pages)));
diff --git a/drivers/gpu/arm/midgard/mali_kbase_mem_profile_debugfs.c b/drivers/gpu/arm/midgard/mali_kbase_mem_profile_debugfs.c
index a443d002a1ac..bfa0bbeaa186 100644
--- a/drivers/gpu/arm/midgard/mali_kbase_mem_profile_debugfs.c
+++ b/drivers/gpu/arm/midgard/mali_kbase_mem_profile_debugfs.c
@@ -39,7 +39,7 @@ static int kbasep_mem_profile_seq_show(struct seq_file *sfile, void *data)
 	err = seq_write(sfile, kctx->mem_profile_data, kctx->mem_profile_size);
 
 	if (!err)
-		err = seq_putc(sfile, '\n');
+		seq_putc(sfile, '\n');
 
 	mutex_unlock(&kctx->mem_profile_lock);
 
-- 
2.34.1