Switch to use MI mk48txx(4) and todr(9) for MK48T02 todclocks on newsmips.

This commit is contained in:
tsutsui 2003-10-25 04:07:28 +00:00
parent b9e3ec284d
commit 62c9f07679
15 changed files with 361 additions and 580 deletions

View File

@ -1,150 +0,0 @@
/* $NetBSD: clock_ap.c,v 1.5 2003/07/15 02:59:28 lukem Exp $ */
/*-
* Copyright (C) 1999 Tsubai Masanari. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clock_ap.c,v 1.5 2003/07/15 02:59:28 lukem Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <dev/clock_subr.h>
#include <machine/adrsmap.h>
#include <newsmips/apbus/apbusvar.h>
#include <newsmips/newsmips/clockvar.h>
#include <newsmips/newsmips/clockreg.h>
struct clock_ap_softc {
struct device sc_dev;
u_int32_t *sc_addr;
};
int clock_ap_match __P((struct device *, struct cfdata *, void *));
void clock_ap_attach __P((struct device *, struct device *, void *));
CFATTACH_DECL(mkclock_ap, sizeof(struct clock_ap_softc),
clock_ap_match, clock_ap_attach, NULL, NULL);
static void clockinit __P((struct device *));
static void clockget __P((struct device *, struct clock_ymdhms *));
static void clockset __P((struct device *, struct clock_ymdhms *));
struct clockfns clockfns_ap = {
clockinit, clockget, clockset
};
int
clock_ap_match(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
{
struct apbus_attach_args *apa = aux;
if (strcmp("clock", apa->apa_name) != 0)
return 0;
return 1;
}
void
clock_ap_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct clock_ap_softc *sc = (void *)self;
struct apbus_attach_args *apa = aux;
printf(" slot%d addr 0x%lx\n", apa->apa_slotno, apa->apa_hwbase);
sc->sc_addr = (void *)apa->apa_hwbase;
clockattach(&sc->sc_dev, &clockfns_ap);
}
/*
* Enable the real-time clock.
*/
void
clockinit(dev)
struct device *dev;
{
*(volatile u_int *)NEWS5000_INTEN2 = NEWS5000_INT2_TIMER0;
}
void
clockget(dev, dt)
struct device *dev;
struct clock_ymdhms *dt;
{
struct clock_ap_softc *sc = (void *)dev;
volatile u_int *rtc_port = sc->sc_addr;
volatile u_int *rtc_data = rtc_port + 1;
u_int8_t x;
int s;
s = splclock();
*rtc_port = READ_CLOCK;
x = *rtc_data++; dt->dt_sec = FROMBCD(x);
x = *rtc_data++; dt->dt_min = FROMBCD(x);
x = *rtc_data++; dt->dt_hour = FROMBCD(x);
x = *rtc_data++; dt->dt_wday = x - 1;
x = *rtc_data++; dt->dt_day = FROMBCD(x);
x = *rtc_data++; dt->dt_mon = FROMBCD(x);
x = *rtc_data++; dt->dt_year = FROMBCD(x);
*rtc_port = 0;
splx(s);
dt->dt_year = dt->dt_year + (dt->dt_year >= 70 ? 1900 : 2000);
}
void
clockset(dev, dt)
struct device *dev;
struct clock_ymdhms *dt;
{
struct clock_ap_softc *sc = (void *)dev;
volatile u_int *rtc_port = sc->sc_addr;
volatile u_int *rtc_data = rtc_port + 1;
int year, s;
year = dt->dt_year % 100;
s = splclock();
*rtc_port = SET_CLOCK;
*rtc_data++ = TOBCD(dt->dt_sec);
*rtc_data++ = TOBCD(dt->dt_min);
*rtc_data++ = TOBCD(dt->dt_hour);
*rtc_data++ = dt->dt_wday + 1;
*rtc_data++ = TOBCD(dt->dt_day);
*rtc_data++ = TOBCD(dt->dt_mon);
*rtc_data++ = TOBCD(year);
*rtc_port = 0;
splx(s);
}

View File

@ -0,0 +1,132 @@
/* $NetBSD: mkclock_ap.c,v 1.1 2003/10/25 04:07:28 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mkclock_ap.c,v 1.1 2003/10/25 04:07:28 tsutsui Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/cpu.h>
#include <machine/bus.h>
#include <dev/clock_subr.h>
#include <dev/ic/mk48txxreg.h>
#include <newsmips/apbus/apbusvar.h>
#define MKCLOCK_AP_STRIDE 2
#define MKCLOCK_AP_OFFSET \
((MK48T02_CLKOFF + MK48TXX_ICSR) << MKCLOCK_AP_STRIDE)
int mkclock_ap_match(struct device *, struct cfdata *, void *);
void mkclock_ap_attach(struct device *, struct device *, void *);
static u_int8_t mkclock_ap_nvrd(bus_space_tag_t bt, bus_space_handle_t, int);
static void mkclock_ap_nvwr(bus_space_tag_t, bus_space_handle_t, int, u_int8_t);
CFATTACH_DECL(mkclock_ap, sizeof(struct device),
mkclock_ap_match, mkclock_ap_attach, NULL, NULL);
extern struct cfdriver mkclock_cd;
int
mkclock_ap_match(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct apbus_attach_args *apa = aux;
if (strcmp("clock", apa->apa_name) != 0)
return 0;
return 1;
}
void
mkclock_ap_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct apbus_attach_args *apa = aux;
bus_space_tag_t bst;
bus_space_handle_t bsh;
todr_chip_handle_t handle;
printf(" slot%d addr 0x%lx", apa->apa_slotno, apa->apa_hwbase);
if (bus_space_map(bst, apa->apa_hwbase - MKCLOCK_AP_OFFSET,
MK48T02_CLKSZ, 0, &bsh) != 0)
printf("can't map device space\n");
handle = mk48txx_attach(bst, bsh, "mk48t02", 1900,
mkclock_ap_nvrd, mkclock_ap_nvwr);
if (handle == NULL)
panic("can't attach tod clock");
printf("\n");
handle->bus_cookie = NULL;
handle->todr_setwen = NULL;
todr_attach(handle);
}
static u_int8_t
mkclock_ap_nvrd(bt, bh, off)
bus_space_tag_t bt;
bus_space_handle_t bh;
int off;
{
u_int8_t rv;
rv = bus_space_read_4(bt, bh, off << MKCLOCK_AP_STRIDE);
return rv;
}
static void
mkclock_ap_nvwr(bt, bh, off, v)
bus_space_tag_t bt;
bus_space_handle_t bh;
int off;
u_int8_t v;
{
bus_space_write_4(bt, bh, off << MKCLOCK_AP_STRIDE, v);
}

View File

@ -1,4 +1,4 @@
# $NetBSD: GENERIC,v 1.61 2003/10/24 15:58:31 tsutsui Exp $
# $NetBSD: GENERIC,v 1.62 2003/10/25 04:07:28 tsutsui Exp $
#
# GENERIC machine description file
#
@ -22,7 +22,7 @@ include "arch/newsmips/conf/std.newsmips"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
#ident "GENERIC-$Revision: 1.61 $"
#ident "GENERIC-$Revision: 1.62 $"
maxusers 16
@ -128,7 +128,7 @@ cpu0 at mainbus0
hb0 at mainbus0 # Hyper-bus on news3400
ap0 at mainbus0 # APbus on news5000
mkclock0 at hb0 addr 0xbff407f8 # MK48T02 realtime clock
mkclock0 at hb0 addr 0xbff40000 # MK48T02 realtime clock
mkclock0 at ap? #
le0 at hb0 addr 0xbff80000 level 1 # on-board LANCE Ethernet

View File

@ -1,4 +1,4 @@
# $NetBSD: INSTALL,v 1.19 2003/10/24 15:58:31 tsutsui Exp $
# $NetBSD: INSTALL,v 1.20 2003/10/25 04:07:28 tsutsui Exp $
#
# INSTALL kernel for RISC-NEWS
@ -61,7 +61,7 @@ cpu0 at mainbus0
hb0 at mainbus0 # Hyper-bus
ap0 at mainbus0 # APbus
mkclock0 at hb0 addr 0xbff407f8 # MK48T02 realtime clock
mkclock0 at hb0 addr 0xbff40000 # MK48T02 realtime clock
mkclock0 at ap?
le0 at hb0 addr 0xbff80000 level 1 # built-in LANCE ethernet

View File

@ -1,7 +1,7 @@
#
# NEWS3400 config file
#
# $NetBSD: WAPIKO,v 1.20 2003/04/10 22:07:01 christos Exp $
# $NetBSD: WAPIKO,v 1.21 2003/10/25 04:07:28 tsutsui Exp $
#
include "arch/newsmips/conf/std.newsmips"
@ -52,7 +52,7 @@ mainbus0 at root
cpu0 at mainbus0
hb0 at mainbus0
mkclock0 at hb0 addr 0xbff407f8 # MK48T02 realtime clock
mkclock0 at hb0 addr 0xbff40000 # MK48T02 realtime clock
le0 at hb0 addr 0xbff80000 level 1 # built-in LANCE ethernet
le1 at hb0 addr 0xb8c30000 level 0

View File

@ -1,4 +1,4 @@
# $NetBSD: files.newsmips,v 1.23 2003/07/27 01:19:29 thorpej Exp $
# $NetBSD: files.newsmips,v 1.24 2003/10/25 04:07:28 tsutsui Exp $
# NEWSMIPS-specific configuration info
@ -27,14 +27,12 @@ attach ap at mainbus
file arch/newsmips/apbus/apbus.c ap
file arch/newsmips/apbus/apbus_subr.c ap
device mkclock
file arch/newsmips/newsmips/clock.c mkclock
# MK48T02 TOD clock and NVRAM
device mkclock: mk48txx
attach mkclock at hb with mkclock_hb
file arch/newsmips/dev/clock_hb.c mkclock_hb
file arch/newsmips/dev/mkclock_hb.c mkclock_hb
attach mkclock at ap with mkclock_ap
file arch/newsmips/apbus/clock_ap.c mkclock_ap
file arch/newsmips/apbus/mkclock_ap.c mkclock_ap
attach le at hb: le24
file arch/newsmips/dev/if_le.c le needs-count
@ -89,6 +87,7 @@ file arch/newsmips/apbus/if_tlp_ap.c tlp_ap
file arch/newsmips/newsmips/autoconf.c
file arch/newsmips/newsmips/bus.c
file arch/newsmips/newsmips/clock.c
file arch/newsmips/newsmips/machdep.c
file arch/newsmips/newsmips/news3400.c hb
file arch/newsmips/newsmips/news5000.c ap

View File

@ -1,150 +0,0 @@
/* $NetBSD: clock_hb.c,v 1.5 2003/07/15 02:59:29 lukem Exp $ */
/*-
* Copyright (C) 1999 Tsubai Masanari. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clock_hb.c,v 1.5 2003/07/15 02:59:29 lukem Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <dev/clock_subr.h>
#include <machine/adrsmap.h>
#include <newsmips/newsmips/clockvar.h>
#include <newsmips/newsmips/clockreg.h>
#include <newsmips/dev/hbvar.h>
struct clock_hb_softc {
struct device sc_dev;
u_int32_t *sc_addr;
};
int clock_hb_match __P((struct device *, struct cfdata *, void *));
void clock_hb_attach __P((struct device *, struct device *, void *));
CFATTACH_DECL(mkclock_hb, sizeof(struct clock_hb_softc),
clock_hb_match, clock_hb_attach, NULL, NULL);
static void clockinit __P((struct device *));
static void clockget __P((struct device *, struct clock_ymdhms *));
static void clockset __P((struct device *, struct clock_ymdhms *));
struct clockfns clockfns_hb = {
clockinit, clockget, clockset
};
int
clock_hb_match(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
{
struct hb_attach_args *ha = aux;
if (strcmp(ha->ha_name, "mkclock") != 0)
return 0;
return 1;
}
void
clock_hb_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct clock_hb_softc *sc = (void *)self;
printf("\n");
clockattach(&sc->sc_dev, &clockfns_hb);
}
void
clockinit(dev)
struct device *dev;
{
/*
* Start the real-time clock.
*/
*(char *)ITIMER = IOCLOCK / 6144 / 100 - 1;
/*
* Enable the real-time clock.
*/
*(char *)INTEN0 |= (char)INTEN0_TIMINT;
}
void
clockget(dev, dt)
struct device *dev;
struct clock_ymdhms *dt;
{
volatile u_char *rtc_port = (u_char *)RTC_PORT;
volatile u_char *rtc_data = (u_char *)DATA_PORT;
u_int8_t x;
int s;
s = splclock();
*rtc_port = READ_CLOCK;
x = *rtc_data++; dt->dt_sec = FROMBCD(x);
x = *rtc_data++; dt->dt_min = FROMBCD(x);
x = *rtc_data++; dt->dt_hour = FROMBCD(x);
x = *rtc_data++; dt->dt_wday = x - 1;
x = *rtc_data++; dt->dt_day = FROMBCD(x);
x = *rtc_data++; dt->dt_mon = FROMBCD(x);
x = *rtc_data++; dt->dt_year = FROMBCD(x);
*rtc_port = 0;
splx(s);
dt->dt_year = dt->dt_year + (dt->dt_year >= 70 ? 1900 : 2000);
}
void
clockset(dev, dt)
struct device *dev;
struct clock_ymdhms *dt;
{
volatile u_char *rtc_port = (u_char *)RTC_PORT;
volatile u_char *rtc_data = (u_char *)DATA_PORT;
int year, s;
year = dt->dt_year % 100;
s = splclock();
*rtc_port = SET_CLOCK;
*rtc_data++ = TOBCD(dt->dt_sec);
*rtc_data++ = TOBCD(dt->dt_min);
*rtc_data++ = TOBCD(dt->dt_hour);
*rtc_data++ = dt->dt_wday + 1;
*rtc_data++ = TOBCD(dt->dt_day);
*rtc_data++ = TOBCD(dt->dt_mon);
*rtc_data++ = TOBCD(year);
*rtc_port = 0;
splx(s);
}

View File

@ -0,0 +1,108 @@
/* $NetBSD: mkclock_hb.c,v 1.1 2003/10/25 04:10:12 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mkclock_hb.c,v 1.1 2003/10/25 04:10:12 tsutsui Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/cpu.h>
#include <machine/bus.h>
#include <dev/clock_subr.h>
#include <dev/ic/mk48txxreg.h>
#include <newsmips/dev/hbvar.h>
int mkclock_hb_match(struct device *, struct cfdata *, void *);
void mkclock_hb_attach(struct device *, struct device *, void *);
CFATTACH_DECL(mkclock_hb, sizeof(struct device),
mkclock_hb_match, mkclock_hb_attach, NULL, NULL);
extern struct cfdriver mkclock_cd;
int
mkclock_hb_match(parent, cf, aux)
struct device *parent;
struct cfdata *cf;
void *aux;
{
struct hb_attach_args *ha = aux;
static int mkclock_hb_matched;
/* Only one clock, please. */
if (mkclock_hb_matched)
return (0);
if (strcmp(ha->ha_name, mkclock_cd.cd_name))
return (0);
mkclock_hb_matched = 1;
return 1;
}
void
mkclock_hb_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct hb_attach_args *ha = aux;
bus_space_tag_t bst;
bus_space_handle_t bsh;
todr_chip_handle_t handle;
if (bus_space_map(bst, (bus_addr_t)ha->ha_addr, MK48T02_CLKSZ,
0, &bsh) != 0)
printf("can't map device space\n");
handle = mk48txx_attach(bst, bsh, "mk48t02", 1900, NULL, NULL);
if (handle == NULL)
panic("can't attach tod clock");
printf("\n");
handle->bus_cookie = NULL;
handle->todr_setwen = NULL;
todr_attach(handle);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: intr.h,v 1.13 2003/05/25 14:02:48 tsutsui Exp $ */
/* $NetBSD: intr.h,v 1.14 2003/10/25 04:07:28 tsutsui Exp $ */
/*-
* Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@ -148,10 +148,11 @@ void news3400_intr __P((u_int, u_int, u_int, u_int));
#ifdef news5000
void news5000_intr __P((u_int, u_int, u_int, u_int));
#endif
void (*hardware_intr) __P((u_int, u_int, u_int, u_int));
extern void (*hardware_intr) __P((u_int, u_int, u_int, u_int));
void (*enable_intr) __P((void));
void (*disable_intr) __P((void));
extern void (*enable_intr) __P((void));
extern void (*disable_intr) __P((void));
extern void (*enable_timer) __P((void));
#endif /* !_LOCORE */
#endif /* _KERNEL */

View File

@ -1,13 +1,17 @@
/* $NetBSD: clock.c,v 1.9 2003/08/07 16:28:54 agc Exp $ */
/* $NetBSD: clock.c,v 1.10 2003/10/25 04:07:28 tsutsui Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department, Ralph Campbell, and Kazumasa Utashiro of
* Software Research Associates, Inc.
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Lawrence Berkeley Laboratory.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -33,163 +37,108 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Utah $Hdr: clock.c 1.18 91/01/21$
*
* @(#)clock.c 8.1 (Berkeley) 6/11/93
*/
/*
* Copyright (c) 1988 University of Utah.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department, Ralph Campbell, and Kazumasa Utashiro of
* Software Research Associates, Inc.
*
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* from: Utah $Hdr: clock.c 1.18 91/01/21$
*
* @(#)clock.c 8.1 (Berkeley) 6/11/93
* @(#)clock.c 8.1 (Berkeley) 6/11/93
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.9 2003/08/07 16:28:54 agc Exp $");
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.10 2003/10/25 04:07:28 tsutsui Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <dev/clock_subr.h>
#include <newsmips/newsmips/clockvar.h>
#include <machine/cpu.h>
#include <machine/intr.h>
static struct clockfns *clockfns;
static struct device *clockdev;
static int clockinitted;
static todr_chip_handle_t todr_handle;
/*
* Common parts of todclock autoconfiguration.
*/
void
clockattach(dev, fns)
struct device *dev;
struct clockfns *fns;
todr_attach(handle)
todr_chip_handle_t handle;
{
if (clockfns != NULL)
panic("clockattach: multiple clocks");
clockdev = dev;
clockfns = fns;
if (todr_handle)
panic("todr_attach: too many todclocks configured");
todr_handle = handle;
}
/*
* Machine-dependent clock routines.
* Set up the real-time and statistics clocks. Leave stathz 0 only
* if no alternative timer is available.
*
* Startrtclock restarts the real-time clock, which provides
* hardclock interrupts to kern_clock.c.
*
* Inittodr initializes the time of day hardware which provides
* date functions. Its primary function is to use some file
* system information in case the hardare clock lost state.
*
* Resettodr restores the time of day hardware after a time change.
* The frequencies of these clocks must be an even number of microseconds.
*/
void
cpu_initclocks()
{
if (todr_handle == NULL)
panic("no todclock device configured");
/* Call the machine-specific initclocks hook. */
(*enable_timer)();
}
/*
* We assume newhz is either stathz or profhz, and that neither will
* change after being set up above. Could recalculate intervals here
* but that would be a drag.
* This does not need to do anything, as we have only one timer and
* profhz == stathz == hz.
*/
void
setstatclockrate(newhz)
int newhz;
{
/* KU:XXX do something! */
/* nothing to do */
}
/*
* Set up the real-time and statistics clocks. Leave stathz 0 only if
* no alternative timer is available.
*/
void
cpu_initclocks()
{
(*clockfns->cf_init)(clockdev);
}
/*
* Initialze the time of day register, based on the time base which is, e.g.
* from a filesystem. Base provides the time to within six months,
* and the time of year clock (if any) provides the rest.
* Set up the system's time, given a `reasonable' time value.
*/
void
inittodr(base)
time_t base;
{
int deltat, badbase = 0;
struct clock_ymdhms dt;
int badbase, waszero;
if (base < 5*SECYR) {
printf("WARNING: preposterous time in file system\n");
/* read the system clock anyway */
base = 6*SECYR + 186*SECDAY + SECDAY/2;
badbase = 0;
waszero = (base == 0);
if (base < 5 * SECYR) {
/*
* If base is 0, assume filesystem time is just unknown
* in stead of preposterous. Don't bark.
*/
if (base != 0)
printf("WARNING: preposterous time in file system\n");
/* not going to use it anyway, if the chip is readable */
/* 1991/07/01 12:00:00 */
base = 21*SECYR + 186*SECDAY + SECDAY/2;
badbase = 1;
}
(*clockfns->cf_get)(clockdev, &dt);
clockinitted = 1;
/* simple sanity checks */
if (dt.dt_mon < 1 || dt.dt_mon > 12 ||
dt.dt_day < 1 || dt.dt_day > 31 ||
dt.dt_hour > 23 || dt.dt_min > 59 || dt.dt_sec > 59) {
printf("WARNING: preposterous clock chip time\n");
if (todr_gettime(todr_handle, (struct timeval *)&time) != 0 ||
time.tv_sec == 0) {
printf("WARNING: bad date in battery clock");
/*
* Believe the time in the file system for lack of
* anything better, resetting the TODR.
* anything better, resetting the clock.
*/
time.tv_sec = base;
if (!badbase)
resettodr();
return;
}
} else {
int deltat = time.tv_sec - base;
time.tv_sec = clock_ymdhms_to_secs(&dt);
if (!badbase) {
/*
* See if we gained/lost two or more days;
* if so, assume something is amiss.
*/
deltat = time.tv_sec - base;
if (deltat < 0)
deltat = -deltat;
if (deltat < 2 * SECDAY)
if (waszero || deltat < 2 * SECDAY)
return;
printf("WARNING: clock %s %d days",
time.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
@ -198,20 +147,18 @@ inittodr(base)
}
/*
* Reset the TODR based on the time value; used when the TODR
* has a preposterous value and also when the time is reset
* by the stime system call. Also called when the TODR goes past
* TODRZERO + 100*(SECYEAR+2*SECDAY) (e.g. on Jan 2 just after midnight)
* to wrap the TODR around.
* Reset the clock based on the current time.
* Used when the current clock is preposterous, when the time is changed,
* and when rebooting. Do nothing if the time is not yet known, e.g.,
* when crashing during autoconfig.
*/
void
resettodr()
{
struct clock_ymdhms dt;
if (! clockinitted)
if (time.tv_sec == 0)
return;
clock_secs_to_ymdhms(time.tv_sec, &dt);
(*clockfns->cf_set)(clockdev, &dt);
if (todr_settime(todr_handle, (struct timeval *)&time) != 0)
printf("resettodr: cannot set time in time-of-day clock\n");
}

View File

@ -1,97 +0,0 @@
/* $NetBSD: clockreg.h,v 1.4 2003/08/07 16:28:54 agc Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department, Ralph Campbell, Sony Corp. and Kazumasa
* Utashiro of Software Research Associates, Inc.
*
* 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. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* from: Utah $Hdr: clockreg.h 1.14 91/01/18$
*
* @(#)clockreg.h 8.1 (Berkeley) 6/11/93
*/
/*
* Copyright (c) 1988 University of Utah.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department, Ralph Campbell, Sony Corp. and Kazumasa
* Utashiro of Software Research Associates, Inc.
*
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* from: Utah $Hdr: clockreg.h 1.14 91/01/18$
*
* @(#)clockreg.h 8.1 (Berkeley) 6/11/93
*/
#define MK48T02
#define SET_CLOCK 0x80
#define READ_CLOCK 0x40
/*
* Mostek MK48T02 clock.
*/
struct clockreg {
volatile u_char cl_csr; /* control register */
volatile u_char cl_sec; /* seconds (0..59; BCD) */
volatile u_char cl_min; /* minutes (0..59; BCD) */
volatile u_char cl_hour; /* hour (0..23; BCD) */
volatile u_char cl_wday; /* weekday (1..7) */
volatile u_char cl_mday; /* day in month (1..31; BCD) */
volatile u_char cl_month; /* month (1..12; BCD) */
volatile u_char cl_year; /* year (0..99; BCD) */
};

View File

@ -1,35 +0,0 @@
/* $NetBSD: clockvar.h,v 1.1 1999/12/22 05:55:26 tsubai Exp $ */
/*-
* Copyright (C) 1999 Tsubai Masanari. All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
struct clockfns {
void (*cf_init) __P((struct device *));
void (*cf_get) __P((struct device *, struct clock_ymdhms *));
void (*cf_set) __P((struct device *, struct clock_ymdhms *));
};
void clockattach __P((struct device *, struct clockfns *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.71 2003/08/07 16:28:54 agc Exp $ */
/* $NetBSD: machdep.c,v 1.72 2003/10/25 04:07:28 tsutsui Exp $ */
/*
* Copyright (c) 1992, 1993
@ -76,7 +76,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.71 2003/08/07 16:28:54 agc Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.72 2003/10/25 04:07:28 tsutsui Exp $");
/* from: Utah Hdr: machdep.c 1.63 91/04/24 */
@ -136,7 +136,6 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.71 2003/08/07 16:28:54 agc Exp $");
#include <machine/adrsmap.h>
#include <machine/machConst.h>
#include <machine/intr.h>
#include <newsmips/newsmips/clockreg.h>
#include <newsmips/newsmips/machid.h>
#include <dev/cons.h>
@ -164,6 +163,10 @@ int mem_cluster_cnt;
struct idrom idrom;
void (*readmicrotime) __P((struct timeval *tvp));
void (*hardware_intr) __P((u_int, u_int, u_int, u_int));
void (*enable_intr) __P((void));
void (*disable_intr) __P((void));
void (*enable_timer) __P((void));
/*
* Local functions.

View File

@ -1,4 +1,4 @@
/* $NetBSD: news3400.c,v 1.12 2003/07/15 02:59:31 lukem Exp $ */
/* $NetBSD: news3400.c,v 1.13 2003/10/25 04:07:28 tsutsui Exp $ */
/*-
* Copyright (C) 1999 Tsubai Masanari. All rights reserved.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: news3400.c,v 1.12 2003/07/15 02:59:31 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: news3400.c,v 1.13 2003/10/25 04:07:28 tsutsui Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -52,6 +52,7 @@ static void news3400_level0_intr(void);
static void news3400_level1_intr(void);
static void news3400_enable_intr(void);
static void news3400_disable_intr(void);
static void news3400_enable_timer(void);
static void news3400_readidrom(u_char *);
static int badaddr_flag;
@ -246,6 +247,17 @@ news3400_disable_intr(void)
*inten1 = 0;
}
static void
news3400_enable_timer(void)
{
/* initialize interval timer */
*(volatile u_int8_t *)ITIMER = IOCLOCK / 6144 / 100 - 1;
/* enable timer interrupt */
*(volatile u_int8_t *)INTEN0 |= (u_int8_t)INTEN0_TIMINT;
}
static void
news3400_readidrom(rom)
u_char *rom;
@ -265,6 +277,7 @@ news3400_init()
enable_intr = news3400_enable_intr;
disable_intr = news3400_disable_intr;
enable_timer = news3400_enable_timer;
news3400_readidrom((u_char *)&idrom);
hostid = idrom.id_serial;

View File

@ -1,4 +1,4 @@
/* $NetBSD: news5000.c,v 1.11 2003/07/15 02:59:31 lukem Exp $ */
/* $NetBSD: news5000.c,v 1.12 2003/10/25 04:07:28 tsutsui Exp $ */
/*-
* Copyright (C) 1999 SHIMIZU Ryo. All rights reserved.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: news5000.c,v 1.11 2003/07/15 02:59:31 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: news5000.c,v 1.12 2003/10/25 04:07:28 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -47,6 +47,7 @@ static void news5000_level0_intr(void);
static void news5000_enable_intr(void);
static void news5000_disable_intr(void);
static void news5000_enable_timer(void);
static void news5000_readmicrotime(struct timeval *);
static void news5000_readidrom(u_char *);
@ -213,6 +214,14 @@ news5000_disable_intr(void)
*(volatile u_int *)NEWS5000_INTEN5 = 0;
}
static void
news5000_enable_timer(void)
{
/* enable timer interrpt */
*(volatile u_int32_t *)NEWS5000_INTEN2 = NEWS5000_INT2_TIMER0;
}
static void
news5000_readmicrotime(tvp)
struct timeval *tvp;
@ -250,6 +259,7 @@ news5000_init(void)
enable_intr = news5000_enable_intr;
disable_intr = news5000_disable_intr;
enable_timer = news5000_enable_timer;
news5000_readidrom((u_char *)&idrom);
readmicrotime = news5000_readmicrotime;