Skip to content

Commit c14ddd0

Browse files
committed
Use system timer for udelay, so unaffected by cpufreq
1 parent 965b922 commit c14ddd0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

arch/arm/mach-bcm2708/bcm2708.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,36 @@ static inline void bcm2708_init_led(void)
859859
}
860860
#endif
861861

862+
863+
/* The assembly versions in delay.S don't account for core freq changing in cpufreq driver */
864+
/* Use 1MHz system timer for busy waiting */
865+
void __udelay(unsigned long usecs)
866+
{
867+
unsigned long start = readl(__io_address(ST_BASE + 0x04));
868+
unsigned long now;
869+
do {
870+
now = readl(__io_address(ST_BASE + 0x04));
871+
} while ((long)(now - start) <= usecs);
872+
}
873+
874+
875+
void __const_udelay(unsigned long scaled_usecs)
876+
{
877+
/* want /107374, this is about 3% bigger. We know usecs is less than 2000, so shouldn't overflow */
878+
const unsigned long usecs = scaled_usecs * 10 >> 20;
879+
unsigned long start = readl(__io_address(ST_BASE + 0x04));
880+
unsigned long now;
881+
do {
882+
now = readl(__io_address(ST_BASE + 0x04));
883+
} while ((long)(now - start) <= usecs);
884+
}
885+
886+
void __delay(int loops)
887+
{
888+
while (--loops > 0)
889+
nop();
890+
}
891+
862892
MACHINE_START(BCM2708, "BCM2708")
863893
/* Maintainer: Broadcom Europe Ltd. */
864894
.map_io = bcm2708_map_io,.init_irq = bcm2708_init_irq,.timer =

0 commit comments

Comments
 (0)