diff options
-rw-r--r-- | firmware/target/arm/rk27xx/system-rk27xx.c | 9 |
1 files changed, 8 insertions, 1 deletions
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 */ |