Revert "Revert "MALI: midgard: avoid GPU voltage domain keeping the initial voltage""
authorchenzhen <chenzhen@rock-chips.com>
Thu, 23 Feb 2017 02:01:42 +0000 (10:01 +0800)
committerchenzhen <chenzhen@rock-chips.com>
Wed, 15 Mar 2017 01:45:49 +0000 (09:45 +0800)
This reverts commit e7db50b51268386fd0e9f88a95c45a4ef3454c4e.

Change-Id: I47f9c1d114b06264d6dd4098bc0e00228fd8f187
Signed-off-by: chenzhen <chenzhen@rock-chips.com>
drivers/gpu/arm/midgard/backend/gpu/mali_kbase_devfreq.c

index 2306c757735ce6a4ffc1987eedaeabed1f3860ae..22f67916b54900d229f8efe3517471bf17d188b6 100644 (file)
@@ -54,6 +54,7 @@ kbase_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags)
        struct kbase_device *kbdev = dev_get_drvdata(dev);
        struct dev_pm_opp *opp;
        unsigned long freq = 0;
+       unsigned long old_freq = kbdev->current_freq;
        unsigned long voltage;
        int err;
 
@@ -71,14 +72,24 @@ kbase_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags)
        /*
         * Only update if there is a change of frequency
         */
-       if (kbdev->current_freq == freq) {
+       if (old_freq == freq) {
                *target_freq = freq;
+#ifdef CONFIG_REGULATOR
+               if (kbdev->current_voltage == voltage)
+                       return 0;
+               err = regulator_set_voltage(kbdev->regulator, voltage, voltage);
+               if (err) {
+                       dev_err(dev, "Failed to set voltage (%d)\n", err);
+                       return err;
+               }
+#else
                return 0;
+#endif
        }
 
 #ifdef CONFIG_REGULATOR
-       if (kbdev->regulator && kbdev->current_voltage != voltage
-                       && kbdev->current_freq < freq) {
+       if (kbdev->regulator && kbdev->current_voltage != voltage &&
+           old_freq < freq) {
                err = regulator_set_voltage(kbdev->regulator, voltage, voltage);
                if (err) {
                        dev_err(dev, "Failed to increase voltage (%d)\n", err);
@@ -93,10 +104,12 @@ kbase_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags)
                                freq, *target_freq);
                return err;
        }
+       *target_freq = freq;
+       kbdev->current_freq = freq;
 
 #ifdef CONFIG_REGULATOR
-       if (kbdev->regulator && kbdev->current_voltage != voltage
-                       && kbdev->current_freq > freq) {
+       if (kbdev->regulator && kbdev->current_voltage != voltage &&
+           old_freq > freq) {
                err = regulator_set_voltage(kbdev->regulator, voltage, voltage);
                if (err) {
                        dev_err(dev, "Failed to decrease voltage (%d)\n", err);
@@ -105,9 +118,7 @@ kbase_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags)
        }
 #endif
 
-       *target_freq = freq;
        kbdev->current_voltage = voltage;
-       kbdev->current_freq = freq;
 
        kbase_tlstream_aux_devfreq_target((u64)freq);
 
@@ -212,6 +223,11 @@ int kbase_devfreq_init(struct kbase_device *kbdev)
                return -ENODEV;
 
        kbdev->current_freq = clk_get_rate(kbdev->clock);
+#ifdef CONFIG_REGULATOR
+       if (kbdev->regulator)
+               kbdev->current_voltage =
+                       regulator_get_voltage(kbdev->regulator);
+#endif
 
        dp = &kbdev->devfreq_profile;