Make timebase frequency value adjustable.

This commit is contained in:
tsubai 2000-07-14 05:53:31 +00:00
parent 9bdf22f648
commit 500013914e
1 changed files with 32 additions and 20 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.c,v 1.10 2000/06/29 08:10:45 mrg Exp $ */
/* $NetBSD: clock.c,v 1.11 2000/07/14 05:53:31 tsubai Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@ -43,13 +43,19 @@
#include "adb.h"
/*
* Initially we assume a processor with a bus frequency of 12.5 MHz.
* Initially we assume a processor with a bus frequency of 50 MHz.
*/
static u_long ticks_per_sec = 12500000;
static u_long ticks_per_sec = 50*1000*1000/4;
static u_long ns_per_tick = 80;
static long ticks_per_intr;
static volatile u_long lasttb;
#ifdef TIMEBASE_FREQ
u_int timebase_freq = TIMEBASE_FREQ;
#else
u_int timebase_freq = 0;
#endif
#define SECDAY 86400
#define DIFF19041970 2082844800
@ -178,17 +184,35 @@ void
calc_delayconst()
{
int qhandle, phandle;
char name[32];
char type[32];
int msr, scratch;
/*
* Get this info during autoconf? XXX
*/
if (timebase_freq != 0) {
ticks_per_sec = timebase_freq;
goto found;
}
for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
if (OF_getprop(qhandle, "device_type", name, sizeof name) >= 0
&& !strcmp(name, "cpu")
if (OF_getprop(qhandle, "device_type", type, sizeof type) > 0
&& strcmp(type, "cpu") == 0
&& OF_getprop(qhandle, "timebase-frequency",
&ticks_per_sec, sizeof ticks_per_sec) >= 0) {
&ticks_per_sec, sizeof ticks_per_sec) > 0) {
goto found;
}
if ((phandle = OF_child(qhandle)))
continue;
while (qhandle) {
if ((phandle = OF_peer(qhandle)))
break;
qhandle = OF_parent(qhandle);
}
}
panic("no cpu node");
found:
/*
* Should check for correct CPU here? XXX
*/
@ -199,18 +223,6 @@ calc_delayconst()
asm volatile ("mftb %0" : "=r"(lasttb));
asm volatile ("mtdec %0" :: "r"(ticks_per_intr));
asm volatile ("mtmsr %0" :: "r"(msr));
break;
}
if ((phandle = OF_child(qhandle)))
continue;
while (qhandle) {
if ((phandle = OF_peer(qhandle)))
break;
qhandle = OF_parent(qhandle);
}
}
if (!phandle)
panic("no cpu node");
}
static inline u_quad_t