MALI: rockchip: upgrade midgard DDK to r14p0-01rel0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / backend / gpu / mali_kbase_devfreq.c
index 3791457f605d9573a0acee082ad41b0a591d4a2a..2306c757735ce6a4ffc1987eedaeabed1f3860ae 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *
- * (C) COPYRIGHT 2014 ARM Limited. All rights reserved.
+ * (C) COPYRIGHT 2014-2016 ARM Limited. All rights reserved.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
  */
 
 
+#define ENABLE_DEBUG_LOG
+#include "../../platform/rk/custom_log.h"
+
 
 #include <mali_kbase.h>
+#include <mali_kbase_tlstream.h>
 #include <mali_kbase_config_defaults.h>
 #include <backend/gpu/mali_kbase_pm_internal.h>
+#ifdef CONFIG_DEVFREQ_THERMAL
+#include <backend/gpu/mali_kbase_power_model_simple.h>
+#endif
 
 #include <linux/clk.h>
 #include <linux/devfreq.h>
@@ -102,6 +109,8 @@ kbase_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags)
        kbdev->current_voltage = voltage;
        kbdev->current_freq = freq;
 
+       kbase_tlstream_aux_devfreq_target((u64)freq);
+
        kbase_pm_reset_dvfs_utilisation(kbdev);
 
        return err;
@@ -130,7 +139,11 @@ kbase_devfreq_status(struct device *dev, struct devfreq_dev_status *stat)
        stat->private_data = NULL;
 
 #ifdef CONFIG_DEVFREQ_THERMAL
-       memcpy(&kbdev->devfreq_cooling->last_status, stat, sizeof(*stat));
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
+       if (kbdev->devfreq_cooling)
+               memcpy(&kbdev->devfreq_cooling->last_status, stat,
+                               sizeof(*stat));
+#endif
 #endif
 
        return 0;
@@ -192,14 +205,9 @@ static void kbase_devfreq_exit(struct device *dev)
 
 int kbase_devfreq_init(struct kbase_device *kbdev)
 {
-#ifdef CONFIG_DEVFREQ_THERMAL
-       struct devfreq_cooling_ops *callbacks = POWER_MODEL_CALLBACKS;
-#endif
        struct devfreq_dev_profile *dp;
        int err;
 
-       dev_dbg(kbdev->dev, "Init Mali devfreq\n");
-
        if (!kbdev->clock)
                return -ENODEV;
 
@@ -208,7 +216,8 @@ int kbase_devfreq_init(struct kbase_device *kbdev)
        dp = &kbdev->devfreq_profile;
 
        dp->initial_freq = kbdev->current_freq;
-       dp->polling_ms = 100;
+       /* .KP : set devfreq_dvfs_interval_in_ms */
+       dp->polling_ms = 20;
        dp->target = kbase_devfreq_target;
        dp->get_dev_status = kbase_devfreq_status;
        dp->get_cur_freq = kbase_devfreq_cur_freq;
@@ -232,12 +241,20 @@ int kbase_devfreq_init(struct kbase_device *kbdev)
        }
 
 #ifdef CONFIG_DEVFREQ_THERMAL
-       if (callbacks) {
-
+       err = kbase_power_model_simple_init(kbdev);
+       if (err && err != -ENODEV && err != -EPROBE_DEFER) {
+               dev_err(kbdev->dev,
+                       "Failed to initialize simple power model (%d)\n",
+                       err);
+               goto cooling_failed;
+       }
+       if (err == -EPROBE_DEFER)
+               goto cooling_failed;
+       if (err != -ENODEV) {
                kbdev->devfreq_cooling = of_devfreq_cooling_register_power(
                                kbdev->dev->of_node,
                                kbdev->devfreq,
-                               callbacks);
+                               &power_model_simple_ops);
                if (IS_ERR_OR_NULL(kbdev->devfreq_cooling)) {
                        err = PTR_ERR(kbdev->devfreq_cooling);
                        dev_err(kbdev->dev,
@@ -245,7 +262,10 @@ int kbase_devfreq_init(struct kbase_device *kbdev)
                                err);
                        goto cooling_failed;
                }
+       } else {
+               err = 0;
        }
+       I("success initing power_model_simple.");
 #endif
 
        return 0;
@@ -255,8 +275,7 @@ cooling_failed:
        devfreq_unregister_opp_notifier(kbdev->dev, kbdev->devfreq);
 #endif /* CONFIG_DEVFREQ_THERMAL */
 opp_notifier_failed:
-       err = devfreq_remove_device(kbdev->devfreq);
-       if (err)
+       if (devfreq_remove_device(kbdev->devfreq))
                dev_err(kbdev->dev, "Failed to terminate devfreq (%d)\n", err);
        else
                kbdev->devfreq = NULL;
@@ -271,7 +290,8 @@ void kbase_devfreq_term(struct kbase_device *kbdev)
        dev_dbg(kbdev->dev, "Term Mali devfreq\n");
 
 #ifdef CONFIG_DEVFREQ_THERMAL
-       devfreq_cooling_unregister(kbdev->devfreq_cooling);
+       if (kbdev->devfreq_cooling)
+               devfreq_cooling_unregister(kbdev->devfreq_cooling);
 #endif
 
        devfreq_unregister_opp_notifier(kbdev->dev, kbdev->devfreq);