summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2013-04-12 10:08:45 +0200
committerMarcin Bukat <marcin.bukat@gmail.com>2013-04-12 10:08:45 +0200
commit490db740a14b99fc6201b5ecdf5c22546047d9d2 (patch)
treea65358f674ef00346d81e130448a962ef7f8569d /firmware
parent3c802a95eda109adf16b28386c636697e6836fae (diff)
rk27xx: avoid one multiply in udelay() as pointed by kugel
Change-Id: Ie33a393b0d4c4b45975ca53ced91dd9f03369db1
Diffstat (limited to 'firmware')
-rw-r--r--firmware/target/arm/rk27xx/system-rk27xx.c9
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 */