cpufreq: vexpress-spc: find and skip duplicates when merging frequencies
authorSudeep Holla <sudeep.holla@arm.com>
Wed, 23 Oct 2019 12:18:51 +0000 (13:18 +0100)
committerViresh Kumar <viresh.kumar@linaro.org>
Thu, 24 Oct 2019 03:07:47 +0000 (08:37 +0530)
Currently the cpufreq core aborts the validation and return error
immediately when it encounter duplicate frequency table entries.
This change was introduced long back since commit da0c6dc00c69
("cpufreq: Handle sorted frequency tables more efficiently").

However, this missed the testing with modified firmware for long time.
Inorder to make it work with default settings, we need to ensure the
merged table for bL switcher contains no duplicates. Find the duplicates
and skip them when merging the frequenct tables of A15 and A7 clusters.

Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/cpufreq/vexpress-spc-cpufreq.c

index 093ef8d3a8d408d7a9d4af7d2828e7b125b701b1..506e3f2bf53aca6c62242c0f38ab3ebe3350ddf8 100644 (file)
@@ -242,6 +242,19 @@ static inline u32 get_table_max(struct cpufreq_frequency_table *table)
        return max_freq;
 }
 
+static bool search_frequency(struct cpufreq_frequency_table *table, int size,
+                            unsigned int freq)
+{
+       int count;
+
+       for (count = 0; count < size; count++) {
+               if (table[count].frequency == freq)
+                       return true;
+       }
+
+       return false;
+}
+
 static int merge_cluster_tables(void)
 {
        int i, j, k = 0, count = 1;
@@ -257,10 +270,13 @@ static int merge_cluster_tables(void)
        freq_table[MAX_CLUSTERS] = table;
 
        /* Add in reverse order to get freqs in increasing order */
-       for (i = MAX_CLUSTERS - 1; i >= 0; i--) {
+       for (i = MAX_CLUSTERS - 1; i >= 0; i--, count = k) {
                for (j = 0; freq_table[i][j].frequency != CPUFREQ_TABLE_END;
-                    j++, k++) {
-                       table[k].frequency =
+                    j++) {
+                       if (i == A15_CLUSTER &&
+                           search_frequency(table, count, freq_table[i][j].frequency))
+                               continue; /* skip duplicates */
+                       table[k++].frequency =
                                VIRT_FREQ(i, freq_table[i][j].frequency);
                }
        }