From 002c83bd47e147593d9544f6ebc680be1a11b6bc Mon Sep 17 00:00:00 2001 From: Finley Xiao Date: Thu, 7 Sep 2017 12:37:19 +0800 Subject: [PATCH] MALI: utgard: Avoid GPU voltage domain keeping the initial voltage If there is only one opp whose frequency is equal to the initial value in opp table list, the GPU voltage domain will keep the initial voltage, it may be too large. Change-Id: I3dd97fe252a15b789f218f44b8fbc7d4143f7085 Signed-off-by: Finley Xiao --- .../gpu/arm/mali400/mali/linux/mali_devfreq.c | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.c b/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.c index b28f489e2cbf..92a5707d55d7 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.c @@ -42,6 +42,7 @@ mali_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags) struct mali_device *mdev = dev_get_drvdata(dev); struct dev_pm_opp *opp; unsigned long freq = 0; + unsigned long old_freq = mdev->current_freq; unsigned long voltage; int err; @@ -60,15 +61,25 @@ mali_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags) /* * Only update if there is a change of frequency */ - if (mdev->current_freq == freq) { + if (old_freq == freq) { *target_freq = freq; mali_pm_reset_dvfs_utilisation(mdev); +#ifdef CONFIG_REGULATOR + if (mdev->current_voltage == voltage) + return 0; + err = regulator_set_voltage(mdev->regulator, voltage, voltage); + if (err) { + dev_err(dev, "Failed to set voltage (%d)\n", err); + return err; + } + mdev->current_voltage = voltage; +#endif return 0; } #ifdef CONFIG_REGULATOR - if (mdev->regulator && mdev->current_voltage != voltage - && mdev->current_freq < freq) { + if (mdev->regulator && mdev->current_voltage != voltage && + old_freq < freq) { err = regulator_set_voltage(mdev->regulator, voltage, voltage); if (err) { MALI_PRINT_ERROR(("Failed to increase voltage (%d)\n", err)); @@ -82,10 +93,12 @@ mali_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags) MALI_PRINT_ERROR(("Failed to set clock %lu (target %lu)\n", freq, *target_freq)); return err; } + *target_freq = freq; + mdev->current_freq = freq; #ifdef CONFIG_REGULATOR - if (mdev->regulator && mdev->current_voltage != voltage - && mdev->current_freq > freq) { + if (mdev->regulator && mdev->current_voltage != voltage && + old_freq > freq) { err = regulator_set_voltage(mdev->regulator, voltage, voltage); if (err) { MALI_PRINT_ERROR(("Failed to decrease voltage (%d)\n", err)); @@ -94,9 +107,7 @@ mali_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags) } #endif - *target_freq = freq; mdev->current_voltage = voltage; - mdev->current_freq = freq; mali_pm_reset_dvfs_utilisation(mdev); @@ -222,6 +233,8 @@ int mali_devfreq_init(struct mali_device *mdev) return -ENODEV; mdev->current_freq = clk_get_rate(mdev->clock); + if (mdev->regulator) + mdev->current_voltage = regulator_get_voltage(mdev->regulator); dp = &mdev->devfreq_profile;