ARM: tegra: edp: Fix tegra_edp_find_maxf edge case
Sai Gurrappadi [Wed, 23 Oct 2013 20:28:06 +0000 (13:28 -0700)]
Fixed an edge case where the lowest frequency could exceed
the given voltage. Just return the lowest frequency in that case
instead of crashing.

Bug 1349095

Change-Id: If89a5ebf4a3ef8fc0f3a2d2d8512f048630be14c
Signed-off-by: Sai Gurrappadi <sgurrappadi@nvidia.com>
Reviewed-on: http://git-master/r/302977
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Tested-by: Diwakar Tundlam <dtundlam@nvidia.com>

arch/arm/mach-tegra/edp.c

index 416b8f6..e646cdc 100644 (file)
@@ -279,15 +279,22 @@ static int edp_relate_freq_voltage(struct clk *clk_cpu_g,
        return 0;
 }
 
+/*
+ * Finds the maximum frequency whose corresponding voltage is <= volt
+ * If no such frequency is found, the least possible frequency is returned
+ */
 unsigned int tegra_edp_find_maxf(int volt)
 {
        unsigned int i;
 
        for (i = 0; i < freq_voltage_lut_size_saved; i++) {
-               if (freq_voltage_lut_saved[i].voltage_mV > volt)
+               if (freq_voltage_lut_saved[i].voltage_mV > volt) {
+                       if (!i)
+                               return freq_voltage_lut_saved[i].freq;
                        break;
+               }
        }
-       return freq_voltage_lut[i - 1].freq;
+       return freq_voltage_lut_saved[i - 1].freq;
 }