From 1b1e4bd3d14da4640b4d584c075d913e695e64e9 Mon Sep 17 00:00:00 2001 From: simonb Date: Fri, 23 Nov 2001 01:04:11 +0000 Subject: [PATCH] Remove hardcoded values for HZ (under different names!) from mcclock.c and clock_machdep.h, so that now HZ can be any supported frequency of the mc146818a/ds1287a RTCs. Tested at 256Hz and 2048Hz. --- sys/arch/pmax/include/clock_machdep.h | 57 --------------------------- sys/arch/pmax/pmax/clock.c | 37 ++++++++--------- sys/dev/dec/mcclock.c | 57 ++++++++++++++++++++++++--- 3 files changed, 70 insertions(+), 81 deletions(-) delete mode 100644 sys/arch/pmax/include/clock_machdep.h diff --git a/sys/arch/pmax/include/clock_machdep.h b/sys/arch/pmax/include/clock_machdep.h deleted file mode 100644 index c597bfe4087a..000000000000 --- a/sys/arch/pmax/include/clock_machdep.h +++ /dev/null @@ -1,57 +0,0 @@ -/* $NetBSD: clock_machdep.h,v 1.5 2000/01/09 15:34:42 ad Exp $ */ - -/*- - * Copyright (c) 1997 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jonathan Stone. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * System-dependent clock declarations for the ``cpu-independent'' - * clock interface. - * - * This file must prototype or define the following functions or - * macros (one or more of which may be no-ops): - * - * CLOCK_RATE default rate at which clock runs. Some platforms - * run the RTC at a fixed rate, independent of - * the acutal RTC hardware in use. clock - */ - -#ifndef _PMAX_CLOCK_MACHDEP_H_ -#define _PMAX_CLOCK_MACHDEP_H_ - -/* The default clock rate on a pmax is 256 Hz. */ -#define CLOCK_RATE 256 - -#endif /* !_PMAX_CLOCK_MACHDEP_H_ */ diff --git a/sys/arch/pmax/pmax/clock.c b/sys/arch/pmax/pmax/clock.c index d2c585ec957d..3c8ec7d7cd59 100644 --- a/sys/arch/pmax/pmax/clock.c +++ b/sys/arch/pmax/pmax/clock.c @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.31 2000/06/04 19:14:54 cgd Exp $ */ +/* $NetBSD: clock.c,v 1.32 2001/11/23 01:04:11 simonb Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -44,7 +44,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.31 2000/06/04 19:14:54 cgd Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.32 2001/11/23 01:04:11 simonb Exp $"); #include #include @@ -52,8 +52,6 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.31 2000/06/04 19:14:54 cgd Exp $"); #include -#include - #include #include "opt_ntp.h" @@ -113,20 +111,6 @@ cpu_initclocks() if (clockfns == NULL) panic("cpu_initclocks: no clock attached"); - hz = CLOCK_RATE; /* 256 Hz clock */ - tick = 1000000 / hz; /* number of microseconds between interrupts */ - tickfix = 1000000 - (hz * tick); -#ifdef NTP - fixtick = tickfix; -#endif - if (tickfix) { - int ftp; - - ftp = min(ffs(tickfix), ffs(hz)); - tickfix >>= (ftp - 1); - tickfixinterval = hz >> (ftp - 1); - } - /* * Establish the clock interrupt; it's a special case. * @@ -144,6 +128,23 @@ cpu_initclocks() * Get the clock started. */ (*clockfns->cf_init)(clockdev); + + /* + * Set hz-related variables after the clock is initialised in + * case the initialisation routines adjusted hz. + */ + tick = 1000000 / hz; /* number of microseconds between interrupts */ + tickfix = 1000000 - (hz * tick); +#ifdef NTP + fixtick = tickfix; +#endif + if (tickfix) { + int ftp; + + ftp = min(ffs(tickfix), ffs(hz)); + tickfix >>= (ftp - 1); + tickfixinterval = hz >> (ftp - 1); + } } /* diff --git a/sys/dev/dec/mcclock.c b/sys/dev/dec/mcclock.c index 64b0fe77f680..8a5420ddcec0 100644 --- a/sys/dev/dec/mcclock.c +++ b/sys/dev/dec/mcclock.c @@ -1,4 +1,4 @@ -/* $NetBSD: mcclock.c,v 1.13 2001/11/13 12:49:45 lukem Exp $ */ +/* $NetBSD: mcclock.c,v 1.14 2001/11/23 01:04:11 simonb Exp $ */ /* * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mcclock.c,v 1.13 2001/11/13 12:49:45 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mcclock.c,v 1.14 2001/11/23 01:04:11 simonb Exp $"); #include #include @@ -40,13 +40,13 @@ __KERNEL_RCSID(0, "$NetBSD: mcclock.c,v 1.13 2001/11/13 12:49:45 lukem Exp $"); #include /* - * XXX rate is machine-dependent. + * XXX default rate is machine-dependent. */ #ifdef __alpha__ -#define MC_DFEAULTRATE MC_RATE_1024_Hz +#define MC_DFEAULTHZ 1024 #endif #ifdef pmax -#define MC_DEFAULTRATE MC_RATE_256_Hz +#define MC_DEFAULTHZ 256 #endif @@ -84,10 +84,55 @@ mcclock_init(dev) struct device *dev; { struct mcclock_softc *sc = (struct mcclock_softc *)dev; + int rate; - mc146818_write(sc, MC_REGA, MC_BASE_32_KHz | MC_DEFAULTRATE); +printf("%s: try to set hz to %d\n", sc->sc_dev.dv_xname, hz); + +again: + switch (hz) { + case 32: + rate = MC_BASE_32_KHz | MC_RATE_32_Hz; + break; + case 64: + rate = MC_BASE_32_KHz | MC_RATE_64_Hz; + break; + case 128: + rate = MC_BASE_32_KHz | MC_RATE_128_Hz; + break; + case 256: + rate = MC_BASE_32_KHz | MC_RATE_256_Hz; + break; + case 512: + rate = MC_BASE_32_KHz | MC_RATE_512_Hz; + break; + case 1024: + rate = MC_BASE_32_KHz | MC_RATE_1024_Hz; + break; + case 2048: + rate = MC_BASE_32_KHz | MC_RATE_2048_Hz; + break; + case 4096: + rate = MC_BASE_32_KHz | MC_RATE_4096_Hz; + break; + case 8192: + rate = MC_BASE_32_KHz | MC_RATE_8192_Hz; + break; + case 16384: + rate = MC_BASE_4_MHz | MC_RATE_1; + break; + case 32768: + rate = MC_BASE_4_MHz | MC_RATE_2; + break; + default: + printf("%s: Cannot get %d Hz clock; using %d Hz\n", + sc->sc_dev.dv_xname, hz, MC_DEFAULTHZ); + hz = MC_DEFAULTHZ; + goto again; + } + mc146818_write(sc, MC_REGA, rate); mc146818_write(sc, MC_REGB, MC_REGB_PIE | MC_REGB_SQWE | MC_REGB_BINARY | MC_REGB_24HR); +printf("%s: hz set to %d\n", sc->sc_dev.dv_xname, hz); } /*