coreboot-kgpe-d16/util/flashrom/udelay.c
Stefan Reinauer 03cafbfdfe Trivial (cosmetic) cleanup:
* Only open /dev/mem once and do it early.
* Drop extern for function prototypes.
* Minimize ts5300 impact in probe_flash()

This cleanup will making ICH7 SPI support quite some easier.

Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Stefan Reinauer <stepan@coresystems.de>



git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2585 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
2007-04-06 11:58:03 +00:00

40 lines
828 B
C

#include <sys/time.h>
#include <stdio.h>
#include "debug.h"
// count to a billion. Time it. If it's < 1 sec, count to 10B, etc.
unsigned long micro = 1;
void myusec_delay(int time)
{
volatile unsigned long i;
for (i = 0; i < time * micro; i++) ;
}
void myusec_calibrate_delay()
{
int count = 1000;
unsigned long timeusec;
struct timeval start, end;
int ok = 0;
printf("Calibrating delay loop... ");
while (!ok) {
gettimeofday(&start, 0);
myusec_delay(count);
gettimeofday(&end, 0);
timeusec = 1000000 * (end.tv_sec - start.tv_sec) +
(end.tv_usec - start.tv_usec);
count *= 2;
if (timeusec < 1000000 / 4)
continue;
ok = 1;
}
// compute one microsecond. That will be count / time
micro = count / timeusec;
printf_debug("%ldM loops per second. ", (unsigned long)micro);
printf("ok\n");
}