diff options
author | Aneesh V <aneesh@ti.com> | 2011-11-21 23:38:57 (GMT) |
---|---|---|
committer | Albert ARIBAUD <albert.u.boot@aribaud.net> | 2011-12-06 22:59:34 (GMT) |
commit | 28a181ff81826bfa53f42c9790cc7397ef9a2dc9 (patch) | |
tree | 016d0b15baf0bb7b31b6f42ead09744257000f87 /tools | |
parent | e4fce34e7a5f484de2ca557fd43a198fd14894b7 (diff) | |
download | u-boot-fsl-qoriq-28a181ff81826bfa53f42c9790cc7397ef9a2dc9.tar.xz |
omap: Improve PLL parameter calculation tool
Improve the tool that finds multiplier and divider for PLLs:
The previous algorithm could get stuck on local maxima
and required the user to specify the tolerance. Improve
the algorithm to go through the entire search space and find
the optimal solution.
Signed-off-by: Aneesh V <aneesh@ti.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/omap/clocks_get_m_n.c | 187 |
1 files changed, 96 insertions, 91 deletions
diff --git a/tools/omap/clocks_get_m_n.c b/tools/omap/clocks_get_m_n.c index cfc1760..c27577b 100644 --- a/tools/omap/clocks_get_m_n.c +++ b/tools/omap/clocks_get_m_n.c @@ -63,45 +63,41 @@ typedef unsigned int u32; * $ gcc clocks_get_m_n.c * $ ./a.out */ -int get_m_n_optimized(u32 target_freq_khz, u32 ref_freq_khz, u32 *m, u32 *n, - u32 tolerance_khz) +int get_m_n_optimized(u32 target_freq_khz, u32 ref_freq_khz, u32 *M, u32 *N) { - u32 min_freq = target_freq_khz - tolerance_khz; - u32 max_freq = target_freq_khz; - u32 freq, freq_old; - *n = 1; + u32 freq = target_freq_khz; + u32 m_optimal, n_optimal, freq_optimal = 0, freq_old; + u32 m, n; + n = 1; while (1) { - *m = min_freq / ref_freq_khz / 2 * (*n) ; + m = target_freq_khz / ref_freq_khz / 2 * n; freq_old = 0; while (1) { - freq = ref_freq_khz * 2 * (*m) / (*n); - if (abs(target_freq_khz - freq_old) <= - abs(target_freq_khz - freq)) { + freq = ref_freq_khz * 2 * m / n; + if (freq > target_freq_khz) { freq = freq_old; - (*m)--; + m--; break; } - (*m)++; + m++; freq_old = freq; } - if (freq >= min_freq && freq <= max_freq) + if (freq > freq_optimal) { + freq_optimal = freq; + m_optimal = m; + n_optimal = n; + } + n++; + if ((freq_optimal == target_freq_khz) || + ((ref_freq_khz / n) < 1000)) { break; - (*n)++; - if ((*n) > MAX_N + 1) { - printf("ref %d m %d n %d target %d : ", - ref_freq_khz, *m, *n, target_freq_khz); - printf("can not find m & n - please consider" - " increasing tolerance\n"); - return -1; } } - (*n)--; - printf("ref %d m %d n %d target %d locked %d\n", - ref_freq_khz, *m, *n, target_freq_khz, freq); - if ((ref_freq_khz / (*n + 1)) < 1000) { - printf("\tREFCLK - CLKINP/(N+1) is less than 1 MHz - less than" - " ideal, locking time will be high!\n"); - } + n--; + *M = m_optimal; + *N = n_optimal - 1; + printf("ref %d m %d n %d target %d locked %d\n", ref_freq_khz, + m_optimal, n_optimal - 1, target_freq_khz, freq_optimal); return 0; } @@ -109,89 +105,98 @@ void main(void) { u32 m, n; printf("\nMPU - 2000000\n"); - get_m_n_optimized(2000000, 12000, &m, &n, 0); - get_m_n_optimized(2000000, 13000, &m, &n, 0); - get_m_n_optimized(2000000, 16800, &m, &n, 800); - get_m_n_optimized(2000000, 19200, &m, &n, 0); - get_m_n_optimized(2000000, 26000, &m, &n, 0); - get_m_n_optimized(2000000, 27000, &m, &n, 0); - get_m_n_optimized(2000000, 38400, &m, &n, 0); + get_m_n_optimized(2000000, 12000, &m, &n); + get_m_n_optimized(2000000, 13000, &m, &n); + get_m_n_optimized(2000000, 16800, &m, &n); + get_m_n_optimized(2000000, 19200, &m, &n); + get_m_n_optimized(2000000, 26000, &m, &n); + get_m_n_optimized(2000000, 27000, &m, &n); + get_m_n_optimized(2000000, 38400, &m, &n); printf("\nMPU - 1200000\n"); - get_m_n_optimized(1200000, 12000, &m, &n, 0); - get_m_n_optimized(1200000, 13000, &m, &n, 0); - get_m_n_optimized(1200000, 16800, &m, &n, 800); - get_m_n_optimized(1200000, 19200, &m, &n, 0); - get_m_n_optimized(1200000, 26000, &m, &n, 0); - get_m_n_optimized(1200000, 27000, &m, &n, 0); - get_m_n_optimized(1200000, 38400, &m, &n, 0); + get_m_n_optimized(1200000, 12000, &m, &n); + get_m_n_optimized(1200000, 13000, &m, &n); + get_m_n_optimized(1200000, 16800, &m, &n); + get_m_n_optimized(1200000, 19200, &m, &n); + get_m_n_optimized(1200000, 26000, &m, &n); + get_m_n_optimized(1200000, 27000, &m, &n); + get_m_n_optimized(1200000, 38400, &m, &n); printf("\nMPU - 1584000\n"); - get_m_n_optimized(1584000, 12000, &m, &n, 0); - get_m_n_optimized(1584000, 13000, &m, &n, 0); - get_m_n_optimized(1584000, 16800, &m, &n, 400); - get_m_n_optimized(1584000, 19200, &m, &n, 0); - get_m_n_optimized(1584000, 26000, &m, &n, 0); - get_m_n_optimized(1584000, 27000, &m, &n, 0); - get_m_n_optimized(1584000, 38400, &m, &n, 0); + get_m_n_optimized(1584000, 12000, &m, &n); + get_m_n_optimized(1584000, 13000, &m, &n); + get_m_n_optimized(1584000, 16800, &m, &n); + get_m_n_optimized(1584000, 19200, &m, &n); + get_m_n_optimized(1584000, 26000, &m, &n); + get_m_n_optimized(1584000, 27000, &m, &n); + get_m_n_optimized(1584000, 38400, &m, &n); printf("\nCore 1600000\n"); - get_m_n_optimized(1600000, 12000, &m, &n, 0); - get_m_n_optimized(1600000, 13000, &m, &n, 0); - get_m_n_optimized(1600000, 16800, &m, &n, 200); - get_m_n_optimized(1600000, 19200, &m, &n, 0); - get_m_n_optimized(1600000, 26000, &m, &n, 0); - get_m_n_optimized(1600000, 27000, &m, &n, 0); - get_m_n_optimized(1600000, 38400, &m, &n, 0); + get_m_n_optimized(1600000, 12000, &m, &n); + get_m_n_optimized(1600000, 13000, &m, &n); + get_m_n_optimized(1600000, 16800, &m, &n); + get_m_n_optimized(1600000, 19200, &m, &n); + get_m_n_optimized(1600000, 26000, &m, &n); + get_m_n_optimized(1600000, 27000, &m, &n); + get_m_n_optimized(1600000, 38400, &m, &n); printf("\nPER 1536000\n"); - get_m_n_optimized(1536000, 12000, &m, &n, 0); - get_m_n_optimized(1536000, 13000, &m, &n, 0); - get_m_n_optimized(1536000, 16800, &m, &n, 0); - get_m_n_optimized(1536000, 19200, &m, &n, 0); - get_m_n_optimized(1536000, 26000, &m, &n, 0); - get_m_n_optimized(1536000, 27000, &m, &n, 0); - get_m_n_optimized(1536000, 38400, &m, &n, 0); + get_m_n_optimized(1536000, 12000, &m, &n); + get_m_n_optimized(1536000, 13000, &m, &n); + get_m_n_optimized(1536000, 16800, &m, &n); + get_m_n_optimized(1536000, 19200, &m, &n); + get_m_n_optimized(1536000, 26000, &m, &n); + get_m_n_optimized(1536000, 27000, &m, &n); + get_m_n_optimized(1536000, 38400, &m, &n); printf("\nIVA 1862000\n"); - get_m_n_optimized(1862000, 12000, &m, &n, 0); - get_m_n_optimized(1862000, 13000, &m, &n, 0); - get_m_n_optimized(1862000, 16800, &m, &n, 0); - get_m_n_optimized(1862000, 19200, &m, &n, 900); - get_m_n_optimized(1862000, 26000, &m, &n, 0); - get_m_n_optimized(1862000, 27000, &m, &n, 0); - get_m_n_optimized(1862000, 38400, &m, &n, 800); + get_m_n_optimized(1862000, 12000, &m, &n); + get_m_n_optimized(1862000, 13000, &m, &n); + get_m_n_optimized(1862000, 16800, &m, &n); + get_m_n_optimized(1862000, 19200, &m, &n); + get_m_n_optimized(1862000, 26000, &m, &n); + get_m_n_optimized(1862000, 27000, &m, &n); + get_m_n_optimized(1862000, 38400, &m, &n); + + printf("\nIVA Nitro - 1290000\n"); + get_m_n_optimized(1290000, 12000, &m, &n); + get_m_n_optimized(1290000, 13000, &m, &n); + get_m_n_optimized(1290000, 16800, &m, &n); + get_m_n_optimized(1290000, 19200, &m, &n); + get_m_n_optimized(1290000, 26000, &m, &n); + get_m_n_optimized(1290000, 27000, &m, &n); + get_m_n_optimized(1290000, 38400, &m, &n); printf("\nABE 196608 sys clk\n"); - get_m_n_optimized(196608, 12000, &m, &n, 700); - get_m_n_optimized(196608, 13000, &m, &n, 200); - get_m_n_optimized(196608, 16800, &m, &n, 700); - get_m_n_optimized(196608, 19200, &m, &n, 400); - get_m_n_optimized(196608, 26000, &m, &n, 200); - get_m_n_optimized(196608, 27000, &m, &n, 900); - get_m_n_optimized(196608, 38400, &m, &n, 0); + get_m_n_optimized(196608, 12000, &m, &n); + get_m_n_optimized(196608, 13000, &m, &n); + get_m_n_optimized(196608, 16800, &m, &n); + get_m_n_optimized(196608, 19200, &m, &n); + get_m_n_optimized(196608, 26000, &m, &n); + get_m_n_optimized(196608, 27000, &m, &n); + get_m_n_optimized(196608, 38400, &m, &n); printf("\nABE 196608 32K\n"); - get_m_n_optimized(196608000/4, 32768, &m, &n, 0); + get_m_n_optimized(196608000/4, 32768, &m, &n); printf("\nUSB 1920000\n"); - get_m_n_optimized(1920000, 12000, &m, &n, 0); - get_m_n_optimized(1920000, 13000, &m, &n, 0); - get_m_n_optimized(1920000, 16800, &m, &n, 0); - get_m_n_optimized(1920000, 19200, &m, &n, 0); - get_m_n_optimized(1920000, 26000, &m, &n, 0); - get_m_n_optimized(1920000, 27000, &m, &n, 0); - get_m_n_optimized(1920000, 38400, &m, &n, 0); + get_m_n_optimized(1920000, 12000, &m, &n); + get_m_n_optimized(1920000, 13000, &m, &n); + get_m_n_optimized(1920000, 16800, &m, &n); + get_m_n_optimized(1920000, 19200, &m, &n); + get_m_n_optimized(1920000, 26000, &m, &n); + get_m_n_optimized(1920000, 27000, &m, &n); + get_m_n_optimized(1920000, 38400, &m, &n); printf("\nCore ES1 1523712\n"); - get_m_n_optimized(1524000, 12000, &m, &n, 100); - get_m_n_optimized(1524000, 13000, &m, &n, 0); - get_m_n_optimized(1524000, 16800, &m, &n, 0); - get_m_n_optimized(1524000, 19200, &m, &n, 0); - get_m_n_optimized(1524000, 26000, &m, &n, 0); - get_m_n_optimized(1524000, 27000, &m, &n, 0); + get_m_n_optimized(1524000, 12000, &m, &n); + get_m_n_optimized(1524000, 13000, &m, &n); + get_m_n_optimized(1524000, 16800, &m, &n); + get_m_n_optimized(1524000, 19200, &m, &n); + get_m_n_optimized(1524000, 26000, &m, &n); + get_m_n_optimized(1524000, 27000, &m, &n); /* exact recommendation for SDPs */ - get_m_n_optimized(1523712, 38400, &m, &n, 0); + get_m_n_optimized(1523712, 38400, &m, &n); } |