Switch arc to use MI mc146818 tod driver.

This commit is contained in:
tsutsui 2003-10-29 18:17:49 +00:00
parent 21ebbd9f3e
commit 18b32ac5ba
11 changed files with 168 additions and 479 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: c_jazz_eisa.c,v 1.7 2003/07/15 00:04:41 lukem Exp $ */
/* $NetBSD: c_jazz_eisa.c,v 1.8 2003/10/29 18:17:49 tsutsui Exp $ */
/*
* Copyright (c) 1998
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: c_jazz_eisa.c,v 1.7 2003/07/15 00:04:41 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: c_jazz_eisa.c,v 1.8 2003/10/29 18:17:49 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -44,10 +44,12 @@ __KERNEL_RCSID(0, "$NetBSD: c_jazz_eisa.c,v 1.7 2003/07/15 00:04:41 lukem Exp $"
#include <machine/pio.h>
#include <machine/platform.h>
#include <dev/clock_subr.h>
#include <dev/ic/mc146818var.h>
#include <arc/arc/arcbios.h>
#include <arc/jazz/pica.h>
#include <arc/jazz/jazziovar.h>
#include <arc/dev/mcclockvar.h>
#include <arc/jazz/mcclock_jazziovar.h>
#include "pc.h"
@ -92,37 +94,39 @@ char *c_jazz_eisa_mainbusdevs[] = {
/*
* chipset-dependent mcclock routines.
*/
u_int mc_jazz_eisa_read __P((struct mcclock_softc *, u_int));
void mc_jazz_eisa_write __P((struct mcclock_softc *, u_int, u_int));
static u_int mc_jazz_eisa_read(struct mc146818_softc *, u_int);
static void mc_jazz_eisa_write(struct mc146818_softc *, u_int, u_int);
struct mcclock_jazzio_config mcclock_jazz_eisa_conf = {
0x80004000, 1,
{ mc_jazz_eisa_read, mc_jazz_eisa_write }
0x80004000, /* I/O base */
1, /* I/O size */
mc_jazz_eisa_read, /* read function */
mc_jazz_eisa_write /* write function */
};
u_int
static u_int
mc_jazz_eisa_read(sc, reg)
struct mcclock_softc *sc;
struct mc146818_softc *sc;
u_int reg;
{
int i, as;
u_int i, as;
as = in32(arc_bus_io.bs_vbase + C_JAZZ_EISA_TODCLOCK_AS) & 0x80;
out32(arc_bus_io.bs_vbase + C_JAZZ_EISA_TODCLOCK_AS, as | reg);
i = bus_space_read_1(sc->sc_iot, sc->sc_ioh, 0);
i = bus_space_read_1(sc->sc_bst, sc->sc_bsh, 0);
return i;
}
void
static void
mc_jazz_eisa_write(sc, reg, datum)
struct mcclock_softc *sc;
struct mc146818_softc *sc;
u_int reg, datum;
{
int as;
u_int as;
as = in32(arc_bus_io.bs_vbase + C_JAZZ_EISA_TODCLOCK_AS) & 0x80;
out32(arc_bus_io.bs_vbase + C_JAZZ_EISA_TODCLOCK_AS, as | reg);
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, datum);
bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, datum);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: c_nec_pci.c,v 1.7 2003/07/15 00:04:41 lukem Exp $ */
/* $NetBSD: c_nec_pci.c,v 1.8 2003/10/29 18:17:49 tsutsui Exp $ */
/*-
* Copyright (C) 2000 Shuichiro URATA. All rights reserved.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: c_nec_pci.c,v 1.7 2003/07/15 00:04:41 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: c_nec_pci.c,v 1.8 2003/10/29 18:17:49 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -40,10 +40,14 @@ __KERNEL_RCSID(0, "$NetBSD: c_nec_pci.c,v 1.7 2003/07/15 00:04:41 lukem Exp $");
#include <uvm/uvm_extern.h>
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/pio.h>
#include <machine/platform.h>
#include <mips/pte.h>
#include <dev/clock_subr.h>
#include <dev/ic/mc146818var.h>
#include <dev/pci/pcivar.h>
#include <arc/arc/arcbios.h>
@ -51,7 +55,6 @@ __KERNEL_RCSID(0, "$NetBSD: c_nec_pci.c,v 1.7 2003/07/15 00:04:41 lukem Exp $");
#include <arc/jazz/pica.h>
#include <arc/jazz/rd94.h>
#include <arc/jazz/jazziovar.h>
#include <arc/dev/mcclockvar.h>
#include <arc/jazz/mcclock_jazziovar.h>
#include <arc/pci/necpbvar.h>
@ -93,12 +96,14 @@ char *c_nec_pci_mainbusdevs[] = {
* chipset-dependent mcclock routines.
*/
u_int mc_nec_pci_read __P((struct mcclock_softc *, u_int));
void mc_nec_pci_write __P((struct mcclock_softc *, u_int, u_int));
static u_int mc_nec_pci_read(struct mc146818_softc *, u_int);
static void mc_nec_pci_write(struct mc146818_softc *, u_int, u_int);
struct mcclock_jazzio_config mcclock_nec_pci_conf = {
0x80004000, 2,
{ mc_nec_pci_read, mc_nec_pci_write }
0x80004000, /* I/O base */
2, /* I/O size */
mc_nec_pci_read, /* read function */
mc_nec_pci_write /* write function */
};
/*
@ -146,29 +151,29 @@ static const u_int32_t nec_pci_ipl_sr_bits[_IPL_N] = {
MIPS_INT_MASK_5, /* IPL_{CLOCK,HIGH} */
};
u_int
static u_int
mc_nec_pci_read(sc, reg)
struct mcclock_softc *sc;
struct mc146818_softc *sc;
u_int reg;
{
int i, as;
u_int i, as;
as = bus_space_read_1(sc->sc_iot, sc->sc_ioh, 1) & 0x80;
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 1, as | reg);
i = bus_space_read_1(sc->sc_iot, sc->sc_ioh, 0);
return (i);
as = bus_space_read_1(sc->sc_bst, sc->sc_bsh, 1) & 0x80;
bus_space_write_1(sc->sc_bst, sc->sc_bsh, 1, as | reg);
i = bus_space_read_1(sc->sc_bst, sc->sc_bsh, 0);
return i;
}
void
static void
mc_nec_pci_write(sc, reg, datum)
struct mcclock_softc *sc;
struct mc146818_softc *sc;
u_int reg, datum;
{
int as;
u_int as;
as = bus_space_read_1(sc->sc_iot, sc->sc_ioh, 1) & 0x80;
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 1, as | reg);
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, datum);
as = bus_space_read_1(sc->sc_bst, sc->sc_bsh, 1) & 0x80;
bus_space_write_1(sc->sc_bst, sc->sc_bsh, 1, as | reg);
bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, datum);
}
/*

View File

@ -1,13 +1,17 @@
/* $NetBSD: todclock.c,v 1.4 2003/08/07 16:26:48 agc Exp $ */
/* NetBSD: clock.c,v 1.31 2001/05/27 13:53:24 sommerfeld Exp */
/* $NetBSD: todclock.c,v 1.5 2003/10/29 18:17:49 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 and Ralph Campbell.
* 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,209 +37,96 @@
* 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/10/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 and Ralph Campbell.
*
* 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/10/93
* @(#)clock.c 8.1 (Berkeley) 6/11/93
*/
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: todclock.c,v 1.4 2003/08/07 16:26:48 agc Exp $");
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: todclock.c,v 1.5 2003/10/29 18:17:49 tsutsui Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <dev/clock_subr.h>
#include <arc/arc/todclockvar.h>
#define MINYEAR 2002 /* "today" */
struct device *todclockdev;
const struct todclockfns *todclockfns;
int todclock_year_offset;
int todclockinitted;
static todr_chip_handle_t todr_handle;
/*
* Common parts of todclock autoconfiguration.
*/
void
todclockattach(dev, fns, year_offset)
struct device *dev;
const struct todclockfns *fns;
int year_offset;
todr_attach(handle)
todr_chip_handle_t handle;
{
/*
* Just bookkeeping.
*/
if (todclockfns != NULL)
panic("todclockattach: multiple todclocks");
if (todr_handle)
panic("todr_attach: too many todclocks configured");
todclockdev = dev;
todclockfns = fns;
todclock_year_offset = year_offset;
todr_handle = handle;
}
/*
* Machine-dependent real-time clock routines.
*
* 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.
*/
/*
* 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;
{
struct todclocktime ct;
int year;
struct clock_ymdhms dt;
time_t deltat;
int badbase;
int badbase, waszero;
if (todclockfns == NULL)
panic("inittodr: no real time clock attached");
badbase = 0;
waszero = (base == 0);
if (base < (MINYEAR - POSIX_BASE_YEAR) * SECYR) {
printf("WARNING: preposterous time in file system");
/* read the system clock anyway */
base = (MINYEAR - POSIX_BASE_YEAR) * SECYR;
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 */
/* 2002/7/1 12:00:00 */
base = 32*SECYR + 186*SECDAY + SECDAY/2;
badbase = 1;
} else
badbase = 0;
}
(*todclockfns->tcf_get)(todclockdev, base, &ct);
#ifdef DEBUG
printf("readclock: %02d/%02d/%02d/%02d/%02d/%02d",
ct.year, ct.mon, ct.day, ct.hour, ct.min, ct.sec);
#endif
todclockinitted = 1;
year = 1900 + todclock_year_offset + ct.year;
if (year < POSIX_BASE_YEAR)
year += 100;
/* simple sanity checks (2037 = time_t overflow) */
if (year < MINYEAR || year > 2037 ||
ct.mon < 1 || ct.mon > 12 || ct.day < 1 || ct.day > 31 ||
ct.hour >= 24 || ct.min >= 60 || ct.sec >= 60) {
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) {
printf("WARNING: preposterous clock chip time\n");
if (!badbase)
resettodr();
}
goto bad;
}
} else {
int deltat = time.tv_sec - base;
dt.dt_year = year;
dt.dt_mon = ct.mon;
dt.dt_day = ct.day;
dt.dt_hour = ct.hour;
dt.dt_min = ct.min;
dt.dt_sec = ct.sec;
time.tv_sec = clock_ymdhms_to_secs(&dt);
#ifdef DEBUG
printf("=>%ld (%ld)\n", time.tv_sec, base);
#endif
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 %ld days",
time.tv_sec < base ? "lost" : "gained",
(long)deltat / SECDAY);
printf("WARNING: clock %s %d days",
time.tv_sec < base ? "lost" : "gained", deltat / SECDAY);
}
bad:
printf(" -- CHECK AND RESET THE DATE!\n");
}
/*
* 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;
struct todclocktime ct;
if (!todclockinitted)
if (time.tv_sec == 0)
return;
clock_secs_to_ymdhms(time.tv_sec, &dt);
/* rt clock wants 2 digits */
ct.year = (dt.dt_year - todclock_year_offset) % 100;
ct.mon = dt.dt_mon;
ct.day = dt.dt_day;
ct.hour = dt.dt_hour;
ct.min = dt.dt_min;
ct.sec = dt.dt_sec;
ct.dow = dt.dt_wday;
#ifdef DEBUG
printf("setclock: %02d/%02d/%02d/%02d/%02d/%02d\n",
ct.year, ct.mon, ct.day,
ct.hour, ct.min, ct.sec);
#endif
(*todclockfns->tcf_set)(todclockdev, &ct);
if (todr_settime(todr_handle, (struct timeval *)&time) != 0)
printf("resettodr: cannot set time in time-of-day clock\n");
}

View File

@ -1,62 +0,0 @@
/* $NetBSD: todclockvar.h,v 1.1 2001/06/13 15:00:27 soda Exp $ */
/* NetBSD: clockvar.h,v 1.4 1997/06/22 08:02:18 jonathan Exp */
/*
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
/*
* Definitions for cpu-independent todclock handling for the arc.
*/
/*
* todclocktime structure:
*
* structure passed to TOY clocks when setting them. broken out this
* way, so that the time_t -> field conversion can be shared.
*/
struct todclocktime {
int year; /* year - 1900 */
int mon; /* month (1 - 12) */
int day; /* day (1 - 31) */
int hour; /* hour (0 - 23) */
int min; /* minute (0 - 59) */
int sec; /* second (0 - 59) */
int dow; /* day of week (0 - 6; 0 = Sunday) */
};
/*
* todclockfns structure:
*
* function switch used by chip-independent todclock code, to access
* chip-dependent routines.
*/
struct todclockfns {
void (*tcf_get) __P((struct device *, time_t, struct todclocktime *));
void (*tcf_set) __P((struct device *, struct todclocktime *));
};
void todclockattach __P((struct device *, const struct todclockfns *, int));

View File

@ -1,4 +1,4 @@
# $NetBSD: files.arc,v 1.47 2003/07/27 01:17:40 thorpej Exp $
# $NetBSD: files.arc,v 1.48 2003/10/29 18:17:49 tsutsui Exp $
# $OpenBSD: files.arc,v 1.21 1999/09/11 10:20:20 niklas Exp $
#
# maxpartitions must be first item in files.${ARCH}
@ -217,10 +217,9 @@ file arch/arc/jazz/timer_jazzio.c timer & timer_jazzio needs-flag
file arch/arc/isa/timer_isa.c timer & timer_isa needs-flag
# Real time clock, must have one..
device mcclock
device mcclock: mc146818
attach mcclock at jazzio with mcclock_jazzio
attach mcclock at isa with mcclock_isa
file arch/arc/dev/mcclock.c mcclock needs-flag
file arch/arc/jazz/mcclock_jazzio.c mcclock & mcclock_jazzio needs-flag
file arch/arc/isa/mcclock_isa.c mcclock & mcclock_isa needs-flag

View File

@ -1,120 +0,0 @@
/* $NetBSD: mcclock.c,v 1.1 2001/06/13 15:02:12 soda Exp $ */
/* NetBSD: mcclock.c,v 1.12 1999/01/15 23:29:55 thorpej Exp */
/*
* Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: mcclock.c,v 1.1 2001/06/13 15:02:12 soda Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/bus.h>
#include <dev/ic/mc146818reg.h>
#include <arc/arc/todclockvar.h>
#include <arc/dev/mcclockvar.h>
void mcclock_get __P((struct device *, time_t, struct todclocktime *));
void mcclock_set __P((struct device *, struct todclocktime *));
const struct todclockfns mcclock_todclockfns = {
mcclock_get, mcclock_set,
};
void
mcclock_attach(sc, busfns, year_offset)
struct mcclock_softc *sc;
const struct mcclock_busfns *busfns;
int year_offset;
{
printf(": mc146818 or compatible\n");
sc->sc_busfns = busfns;
todclockattach(&sc->sc_dev, &mcclock_todclockfns, year_offset);
}
/*
* Get the time of day, based on the clock's value and/or the base value.
*/
void
mcclock_get(dev, base, ct)
struct device *dev;
time_t base;
struct todclocktime *ct;
{
struct mcclock_softc *sc = (struct mcclock_softc *)dev;
mc_todregs regs;
int s;
s = splclock();
MC146818_GETTOD(sc, &regs)
splx(s);
ct->sec = regs[MC_SEC];
ct->min = regs[MC_MIN];
ct->hour = regs[MC_HOUR];
ct->dow = regs[MC_DOW];
ct->day = regs[MC_DOM];
ct->mon = regs[MC_MONTH];
ct->year = regs[MC_YEAR];
}
/*
* Reset the TODR based on the time value.
*/
void
mcclock_set(dev, ct)
struct device *dev;
struct todclocktime *ct;
{
struct mcclock_softc *sc = (struct mcclock_softc *)dev;
mc_todregs regs;
int s;
s = splclock();
MC146818_GETTOD(sc, &regs);
splx(s);
regs[MC_SEC] = ct->sec;
regs[MC_MIN] = ct->min;
regs[MC_HOUR] = ct->hour;
regs[MC_DOW] = ct->dow;
regs[MC_DOM] = ct->day;
regs[MC_MONTH] = ct->mon;
regs[MC_YEAR] = ct->year;
s = splclock();
MC146818_PUTTOD(sc, &regs);
splx(s);
}

View File

@ -1,51 +0,0 @@
/* $NetBSD: mcclockvar.h,v 1.2 2003/10/23 02:31:03 simonb Exp $ */
/*
* Copyright (c) 1996 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
struct mcclock_softc {
struct device sc_dev;
const struct mcclock_busfns *sc_busfns;
/* the followings may be used by bus-dependent frontend */
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
};
struct mcclock_busfns {
u_int (*mc_bf_read) __P((struct mcclock_softc *, u_int));
void (*mc_bf_write) __P((struct mcclock_softc *, u_int, u_int));
};
#define mc146818_read(dev, reg) \
(*(sc)->sc_busfns->mc_bf_read)(sc, reg)
#define mc146818_write(sc, reg, datum) \
(*(sc)->sc_busfns->mc_bf_write)(sc, reg, datum)
void mcclock_attach(struct mcclock_softc *, const struct mcclock_busfns *,
int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcclock_isa.c,v 1.6 2003/08/07 16:26:50 agc Exp $ */
/* $NetBSD: mcclock_isa.c,v 1.7 2003/10/29 18:17:50 tsutsui Exp $ */
/* $OpenBSD: clock_mc.c,v 1.9 1998/03/16 09:38:26 pefo Exp $ */
/* NetBSD: clock_mc.c,v 1.2 1995/06/28 04:30:30 cgd Exp */
@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.6 2003/08/07 16:26:50 agc Exp $");
__KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.7 2003/10/29 18:17:50 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -90,24 +90,22 @@ __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.6 2003/08/07 16:26:50 agc Exp $");
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <dev/ic/mc146818reg.h>
#include <dev/clock_subr.h>
#include <dev/ic/mc146818reg.h>
#include <dev/ic/mc146818var.h>
#include <arc/dev/mcclockvar.h>
#include <arc/isa/mcclock_isavar.h>
int mcclock_isa_match __P((struct device *, struct cfdata *, void *));
void mcclock_isa_attach __P((struct device *, struct device *, void *));
int mcclock_isa_match(struct device *, struct cfdata *, void *);
void mcclock_isa_attach(struct device *, struct device *, void *);
CFATTACH_DECL(mcclock_isa, sizeof(struct mcclock_softc),
CFATTACH_DECL(mcclock_isa, sizeof(struct mc146818_softc),
mcclock_isa_match, mcclock_isa_attach, NULL, NULL);
/* Deskstation clock access code */
u_int mc_isa_read __P((struct mcclock_softc *, u_int));
void mc_isa_write __P((struct mcclock_softc *, u_int, u_int));
struct mcclock_busfns mcclock_isa_busfns = {
mc_isa_read, mc_isa_write
};
static u_int mc_isa_read(struct mc146818_softc *, u_int);
static void mc_isa_write(struct mc146818_softc *, u_int, u_int);
int mcclock_isa_conf = 0;
@ -162,37 +160,45 @@ mcclock_isa_attach(parent, self, aux)
struct device *self;
void *aux;
{
struct mcclock_softc *sc = (struct mcclock_softc *)self;
struct mc146818_softc *sc = (void *)self;
struct isa_attach_args *ia = aux;
sc->sc_iot = ia->ia_iot;
if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
ia->ia_io[0].ir_size, 0, &sc->sc_ioh))
sc->sc_bst = ia->ia_iot;
if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
panic("mcclock_isa_attach: couldn't map clock I/O space");
mcclock_attach(sc, &mcclock_isa_busfns, 80);
sc->sc_year0 = 1980;
sc->sc_mcread = mc_isa_read;
sc->sc_mcwrite = mc_isa_write;
mc146818_attach(sc);
printf("\n");
/* Turn interrupts off, just in case. */
mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
mc_isa_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
todr_attach(&sc->sc_handle);
}
u_int
mc_isa_read(sc, reg)
struct mcclock_softc *sc;
struct mc146818_softc *sc;
u_int reg;
{
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, reg);
return (bus_space_read_1(sc->sc_iot, sc->sc_ioh, 1));
bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, reg);
return bus_space_read_1(sc->sc_bst, sc->sc_bsh, 1);
}
void
mc_isa_write(sc, reg, datum)
struct mcclock_softc *sc;
struct mc146818_softc *sc;
u_int reg, datum;
{
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, reg);
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 1, datum);
bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, reg);
bus_space_write_1(sc->sc_bst, sc->sc_bsh, 1, datum);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcclock_jazzio.c,v 1.5 2003/08/07 16:26:51 agc Exp $ */
/* $NetBSD: mcclock_jazzio.c,v 1.6 2003/10/29 18:17:50 tsutsui Exp $ */
/* $OpenBSD: clock_mc.c,v 1.9 1998/03/16 09:38:26 pefo Exp $ */
/* NetBSD: clock_mc.c,v 1.2 1995/06/28 04:30:30 cgd Exp */
@ -79,7 +79,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mcclock_jazzio.c,v 1.5 2003/08/07 16:26:51 agc Exp $");
__KERNEL_RCSID(0, "$NetBSD: mcclock_jazzio.c,v 1.6 2003/10/29 18:17:50 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -88,20 +88,22 @@ __KERNEL_RCSID(0, "$NetBSD: mcclock_jazzio.c,v 1.5 2003/08/07 16:26:51 agc Exp $
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <dev/ic/mc146818reg.h>
#include <dev/clock_subr.h>
#include <dev/ic/mc146818reg.h>
#include <dev/ic/mc146818var.h>
#include <arc/dev/mcclockvar.h>
#include <arc/jazz/jazziovar.h>
#include <arc/jazz/mcclock_jazziovar.h>
int mcclock_jazzio_match __P((struct device *, struct cfdata *, void *));
void mcclock_jazzio_attach __P((struct device *, struct device *, void *));
int mcclock_jazzio_match(struct device *, struct cfdata *, void *);
void mcclock_jazzio_attach(struct device *, struct device *, void *);
CFATTACH_DECL(mcclock_jazzio, sizeof(struct mcclock_softc),
CFATTACH_DECL(mcclock_jazzio, sizeof(struct mc146818_softc),
mcclock_jazzio_match, mcclock_jazzio_attach, NULL, NULL);
struct mcclock_jazzio_config *mcclock_jazzio_conf = NULL;
int mcclock_jazzio_found = 0;
static int mcclock_jazzio_found = 0;
int
mcclock_jazzio_match(parent, match, aux)
@ -127,23 +129,31 @@ mcclock_jazzio_attach(parent, self, aux)
struct device *self;
void *aux;
{
struct mcclock_softc *sc = (struct mcclock_softc *)self;
struct mc146818_softc *sc = (void *)self;
struct jazzio_attach_args *ja = aux;
if (mcclock_jazzio_conf == NULL)
panic("mcclock_jazzio_conf isn't initialized");
sc->sc_iot = ja->ja_bust;
if (bus_space_map(sc->sc_iot,
ja->ja_addr, mcclock_jazzio_conf->mjc_iosize, 0, &sc->sc_ioh)) {
sc->sc_bst = ja->ja_bust;
if (bus_space_map(sc->sc_bst,
ja->ja_addr, mcclock_jazzio_conf->mjc_iosize, 0, &sc->sc_bsh)) {
printf(": unable to map I/O space\n");
return;
}
mcclock_attach(sc, &mcclock_jazzio_conf->mjc_mcbusfns, 80);
sc->sc_year0 = 1980;
sc->sc_mcread = mcclock_jazzio_conf->mjc_mc_read;
sc->sc_mcwrite = mcclock_jazzio_conf->mjc_mc_write;
mc146818_attach(sc);
printf("\n");
/* Turn interrupts off, just in case. */
mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
(*sc->sc_mcwrite)(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
mcclock_jazzio_found = 1;
todr_attach(&sc->sc_handle);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcclock_jazziovar.h,v 1.1 2001/06/13 15:02:15 soda Exp $ */
/* $NetBSD: mcclock_jazziovar.h,v 1.2 2003/10/29 18:17:50 tsutsui Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -39,7 +39,8 @@
struct mcclock_jazzio_config {
bus_addr_t mjc_iobase;
bus_size_t mjc_iosize;
struct mcclock_busfns mjc_mcbusfns;
u_int (*mjc_mc_read)(struct mc146818_softc *, u_int);
void (*mjc_mc_write)(struct mc146818_softc *, u_int, u_int);
};
struct mcclock_jazzio_config *mcclock_jazzio_conf;
extern struct mcclock_jazzio_config *mcclock_jazzio_conf;

View File

@ -1,4 +1,4 @@
/* $NetBSD: mc146818reg.h,v 1.3 2003/07/08 10:06:31 itojun Exp $ */
/* $NetBSD: mc146818reg.h,v 1.4 2003/10/29 18:17:50 tsutsui Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
@ -61,6 +61,11 @@
* automatically reset; they must be reprogrammed with correct values.
*/
/* XXX not yet all port switch to MI mc146818(4) with todr(9) support */
#if defined(arc)
#define USE_TODR_MCCLOCK
#endif
/*
* The registers, and the bits within each register.
*/
@ -142,7 +147,7 @@
#define MC_BASE_NONE 0x60 /* actually, both of these reset */
#define MC_BASE_RESET 0x70
#ifndef USE_TODR_MCCLOCK
/*
* RTC register/NVRAM read and write functions -- machine-dependent.
* Appropriately manipulate RTC registers to get/put data values.
@ -192,3 +197,4 @@ typedef u_int mc_todregs[MC_NTODREGS];
mc146818_write(sc, MC_REGB, \
mc146818_read(sc, MC_REGB) & ~MC_REGB_SET); \
} while (0);
#endif /* USE_TODR_MCCLOCK */