From 490db740a14b99fc6201b5ecdf5c22546047d9d2 Mon Sep 17 00:00:00 2001 From: Marcin Bukat Date: Fri, 12 Apr 2013 10:08:45 +0200 Subject: rk27xx: avoid one multiply in udelay() as pointed by kugel Change-Id: Ie33a393b0d4c4b45975ca53ced91dd9f03369db1 --- firmware/target/arm/rk27xx/system-rk27xx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'firmware') diff --git a/firmware/target/arm/rk27xx/system-rk27xx.c b/firmware/target/arm/rk27xx/system-rk27xx.c index a36b4e9581..77a2d120aa 100644 --- a/firmware/target/arm/rk27xx/system-rk27xx.c +++ b/firmware/target/arm/rk27xx/system-rk27xx.c @@ -177,9 +177,16 @@ int system_memory_guard(int newmode) /* usecs may be at most 2^32/200 (~21 seconds) for 200MHz max cpu freq */ void udelay(unsigned usecs) { + unsigned cycles_per_usec; unsigned delay; - delay = (usecs * (cpu_frequency/1000000)) / 5; + if (cpu_frequency == CPUFREQ_MAX) { + cycles_per_usec = (CPUFREQ_MAX + 999999) / 1000000; + } else { + cycles_per_usec = (CPUFREQ_NORMAL + 999999) / 1000000; + } + + delay = (usecs * cycles_per_usec) / 5; asm volatile( "1: subs %0, %0, #1 \n" /* 1 cycle */ -- cgit v1.2.3