ARM: tegra12: clock: Round emc rate up/down
Kaz Fukuoka [Wed, 28 Aug 2013 01:18:56 +0000 (18:18 -0700)]
Added support for bidirectional up/down rounding of emc rate.

Ported from Tegra14 Change-Id: I9c83db11478fab1894b694d34ce9025fe6ce2ee7

Change-Id: Ifc8a33257b2063f13377d9a2bffeb2dde38d12d0
Signed-off-by: Kaz Fukuoka <kfukuoka@nvidia.com>
Reviewed-on: http://git-master/r/267575
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>

arch/arm/mach-tegra/tegra12_clocks.c
arch/arm/mach-tegra/tegra12_emc.c

index f35dc40..bbb1990 100644 (file)
@@ -4653,8 +4653,7 @@ static long tegra12_emc_clk_round_updown(struct clk *c, unsigned long rate,
 {
        unsigned long new_rate = max(rate, c->min_rate);
 
-       /* FIXME: emc updown rounding */
-       new_rate = tegra_emc_round_rate(new_rate);
+       new_rate = tegra_emc_round_rate_updown(new_rate, up);
        if (IS_ERR_VALUE(new_rate))
                new_rate = c->max_rate;
 
index f65dae3..5b062a6 100644 (file)
@@ -781,9 +781,10 @@ int tegra_emc_set_rate(unsigned long rate)
        return 0;
 }
 
-long tegra_emc_round_rate(unsigned long rate)
+long tegra_emc_round_rate_updown(unsigned long rate, bool up)
 {
        int i;
+       unsigned long table_rate;
 
        if (!tegra_emc_table)
                return clk_get_rate_locked(emc); /* no table - no rate change */
@@ -801,11 +802,15 @@ long tegra_emc_round_rate(unsigned long rate)
                if (tegra_emc_clk_sel[i].input == NULL)
                        continue;       /* invalid entry */
 
-               if (tegra_emc_table[i].rate >= rate) {
-                       pr_debug("%s: using %lu\n",
-                                __func__, tegra_emc_table[i].rate);
+               table_rate = tegra_emc_table[i].rate;
+               if (table_rate >= rate) {
+                       if (!up && i && (table_rate > rate)) {
+                               i--;
+                               table_rate = tegra_emc_table[i].rate;
+                       }
+                       pr_debug("%s: using %lu\n", __func__, table_rate);
                        last_round_idx = i;
-                       return tegra_emc_table[i].rate * 1000;
+                       return table_rate * 1000;
                }
        }