aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm
diff options
context:
space:
mode:
authorPaul Walmsley <paul@pwsan.com>2009-01-28 14:08:41 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2009-02-08 12:50:34 -0500
commit85a5f78d2b15a2e73b6486a24b77bb3ab67d5bbc (patch)
tree6ea454fb3e0a26ede82ea2c3e0d881758b41c0fc /arch/arm
parentb32450409847dddf060a468707212d3493df4f63 (diff)
[ARM] OMAP3 clock: optimize DPLL rate rounding algorithm
The previous DPLL rate rounding algorithm counted the divider (N) down from the maximum to 1. Since we currently use a broad DPLL rate tolerance, and lower N values are more power-efficient, we can often bypass several iterations through the loop by counting N upwards from 1. Peter de Schrijver <peter.de-schrijver@nokia.com> put up with several test cycles of this patch - thanks Peter. linux-omap source commit is 6f6d82bb2f80fa20a841ac3e95a6f44a5a156188. Signed-off-by: Paul Walmsley <paul@pwsan.com> Cc: Peter de Schrijver <peter.de-schrijver@nokia.com> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm')
-rw-r--r--arch/arm/mach-omap2/clock.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/arch/arm/mach-omap2/clock.c b/arch/arm/mach-omap2/clock.c
index 2f0eaaad4819..76e20bcc4e8a 100644
--- a/arch/arm/mach-omap2/clock.c
+++ b/arch/arm/mach-omap2/clock.c
@@ -45,7 +45,7 @@
45#define DPLL_MIN_DIVIDER 1 45#define DPLL_MIN_DIVIDER 1
46 46
47/* Possible error results from _dpll_test_mult */ 47/* Possible error results from _dpll_test_mult */
48#define DPLL_MULT_UNDERFLOW (1 << 0) 48#define DPLL_MULT_UNDERFLOW -1
49 49
50/* 50/*
51 * Scale factor to mitigate roundoff errors in DPLL rate rounding. 51 * Scale factor to mitigate roundoff errors in DPLL rate rounding.
@@ -826,7 +826,7 @@ static int _dpll_test_mult(int *m, int n, unsigned long *new_rate,
826 unsigned long target_rate, 826 unsigned long target_rate,
827 unsigned long parent_rate) 827 unsigned long parent_rate)
828{ 828{
829 int flags = 0, carry = 0; 829 int r = 0, carry = 0;
830 830
831 /* Unscale m and round if necessary */ 831 /* Unscale m and round if necessary */
832 if (*m % DPLL_SCALE_FACTOR >= DPLL_ROUNDING_VAL) 832 if (*m % DPLL_SCALE_FACTOR >= DPLL_ROUNDING_VAL)
@@ -847,13 +847,13 @@ static int _dpll_test_mult(int *m, int n, unsigned long *new_rate,
847 if (*m < DPLL_MIN_MULTIPLIER) { 847 if (*m < DPLL_MIN_MULTIPLIER) {
848 *m = DPLL_MIN_MULTIPLIER; 848 *m = DPLL_MIN_MULTIPLIER;
849 *new_rate = 0; 849 *new_rate = 0;
850 flags = DPLL_MULT_UNDERFLOW; 850 r = DPLL_MULT_UNDERFLOW;
851 } 851 }
852 852
853 if (*new_rate == 0) 853 if (*new_rate == 0)
854 *new_rate = _dpll_compute_new_rate(parent_rate, *m, n); 854 *new_rate = _dpll_compute_new_rate(parent_rate, *m, n);
855 855
856 return flags; 856 return r;
857} 857}
858 858
859/** 859/**
@@ -892,21 +892,27 @@ long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate)
892 892
893 dd->last_rounded_rate = 0; 893 dd->last_rounded_rate = 0;
894 894
895 for (n = dd->max_divider; n >= DPLL_MIN_DIVIDER; n--) { 895 for (n = DPLL_MIN_DIVIDER; n <= dd->max_divider; n++) {
896 896
897 /* Compute the scaled DPLL multiplier, based on the divider */ 897 /* Compute the scaled DPLL multiplier, based on the divider */
898 m = scaled_rt_rp * n; 898 m = scaled_rt_rp * n;
899 899
900 /* 900 /*
901 * Since we're counting n down, a m overflow means we can 901 * Since we're counting n up, a m overflow means we
902 * can immediately skip to the next n 902 * can bail out completely (since as n increases in
903 * the next iteration, there's no way that m can
904 * increase beyond the current m)
903 */ 905 */
904 if (m > scaled_max_m) 906 if (m > scaled_max_m)
905 continue; 907 break;
906 908
907 r = _dpll_test_mult(&m, n, &new_rate, target_rate, 909 r = _dpll_test_mult(&m, n, &new_rate, target_rate,
908 clk->parent->rate); 910 clk->parent->rate);
909 911
912 /* m can't be set low enough for this n - try with a larger n */
913 if (r == DPLL_MULT_UNDERFLOW)
914 continue;
915
910 e = target_rate - new_rate; 916 e = target_rate - new_rate;
911 pr_debug("clock: n = %d: m = %d: rate error is %d " 917 pr_debug("clock: n = %d: m = %d: rate error is %d "
912 "(new_rate = %ld)\n", n, m, e, new_rate); 918 "(new_rate = %ld)\n", n, m, e, new_rate);
@@ -918,16 +924,11 @@ long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate)
918 min_e_n = n; 924 min_e_n = n;
919 925
920 pr_debug("clock: found new least error %d\n", min_e); 926 pr_debug("clock: found new least error %d\n", min_e);
921 }
922 927
923 /* 928 /* We found good settings -- bail out now */
924 * Since we're counting n down, a m underflow means we 929 if (min_e <= clk->dpll_data->rate_tolerance)
925 * can bail out completely (since as n decreases in 930 break;
926 * the next iteration, there's no way that m can 931 }
927 * increase beyond the current m)
928 */
929 if (r & DPLL_MULT_UNDERFLOW)
930 break;
931 } 932 }
932 933
933 if (min_e < 0) { 934 if (min_e < 0) {