Convert evbarm to __HAVE_GENERIC_TODR.
This commit is contained in:
parent
fc7b39db52
commit
370a7a67ca
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pl030_rtc.c,v 1.7 2005/12/11 12:17:09 christos Exp $ */
|
||||
/* $NetBSD: pl030_rtc.c,v 1.8 2007/02/19 02:08:12 briggs Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 ARM Ltd
|
||||
|
@ -32,7 +32,7 @@
|
|||
/* Include header files */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: pl030_rtc.c,v 1.7 2005/12/11 12:17:09 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pl030_rtc.c,v 1.8 2007/02/19 02:08:12 briggs Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
@ -41,6 +41,8 @@ __KERNEL_RCSID(0, "$NetBSD: pl030_rtc.c,v 1.7 2005/12/11 12:17:09 christos Exp $
|
|||
#include <sys/time.h>
|
||||
#include <sys/device.h>
|
||||
|
||||
#include <dev/clock_subr.h>
|
||||
|
||||
#include <arm/cpufunc.h>
|
||||
#include <machine/intr.h>
|
||||
#include <evbarm/ifpga/ifpgavar.h>
|
||||
|
@ -53,6 +55,7 @@ struct plrtc_softc {
|
|||
struct device sc_dev;
|
||||
bus_space_tag_t sc_iot;
|
||||
bus_space_handle_t sc_ioh;
|
||||
struct todr_chip_handle sc_todr;
|
||||
};
|
||||
|
||||
static int plrtc_probe (struct device *, struct cfdata *, void *);
|
||||
|
@ -61,11 +64,26 @@ static void plrtc_attach (struct device *, struct device *, void *);
|
|||
CFATTACH_DECL(plrtc, sizeof(struct plrtc_softc),
|
||||
plrtc_probe, plrtc_attach, NULL, NULL);
|
||||
|
||||
/* Remember our handle, since it isn't passed in by inittodr and
|
||||
resettodr. */
|
||||
static struct plrtc_softc *plrtc_sc;
|
||||
static int
|
||||
plrtc_gettime(todr_chip_handle_t todr, volatile struct timeval *tv)
|
||||
{
|
||||
struct plrtc_softc *sc;
|
||||
|
||||
static int timeset = 0;
|
||||
sc = (struct plrtc_softc *)todr->cookie;
|
||||
tv->tv_sec = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IFPGA_RTC_DR);
|
||||
/* initialize tv_usec? */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
plrtc_settime(todr_chip_handle_t todr, volatile struct timeval *tv)
|
||||
{
|
||||
struct plrtc_softc *sc;
|
||||
|
||||
sc = (struct plrtc_softc *)todr->cookie;
|
||||
bus_space_write_4(sc->sc_iot, sc->sc_ioh, IFPGA_RTC_LR, tv->tv_sec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
plrtc_probe(struct device *parent, struct cfdata *cf, void *aux)
|
||||
|
@ -86,46 +104,12 @@ plrtc_attach(struct device *parent, struct device *self, void *aux)
|
|||
return;
|
||||
}
|
||||
|
||||
plrtc_sc = sc;
|
||||
memset(&sc->sc_todr, 0, sizeof(struct todr_chip_handle));
|
||||
sc->sc_todr.cookie = sc;
|
||||
sc->sc_todr.todr_gettime = plrtc_gettime;
|
||||
sc->sc_todr.todr_settime = plrtc_settime;
|
||||
|
||||
todr_attach( &sc->sc_todr );
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void
|
||||
inittodr(time_t base)
|
||||
{
|
||||
time_t rtc_time;
|
||||
struct plrtc_softc *sc = plrtc_sc;
|
||||
|
||||
if (sc == NULL)
|
||||
panic("RTC not attached");
|
||||
|
||||
/* Default to the suggested time, but replace that with one from the
|
||||
RTC if it seems more sensible. */
|
||||
rtc_time = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IFPGA_RTC_DR);
|
||||
|
||||
time.tv_usec = 0;
|
||||
time.tv_sec = rtc_time;
|
||||
|
||||
timeset = 1;
|
||||
|
||||
if (base > rtc_time) {
|
||||
printf("inittodr: rtc value suspect, ignoring it.\n");
|
||||
time.tv_usec = 0;
|
||||
time.tv_sec = base;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
resettodr()
|
||||
{
|
||||
struct plrtc_softc *sc = plrtc_sc;
|
||||
|
||||
/* The time hasn't been set yet, so avoid writing a dubious value
|
||||
to the RTC. */
|
||||
if (!timeset)
|
||||
return;
|
||||
|
||||
bus_space_write_4(sc->sc_iot, sc->sc_ioh, IFPGA_RTC_LR, time.tv_sec);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: types.h,v 1.6 2006/09/03 13:51:23 bjh21 Exp $ */
|
||||
/* $NetBSD: types.h,v 1.7 2007/02/19 02:08:12 briggs Exp $ */
|
||||
|
||||
#ifndef _EVBARM_TYPES_H_
|
||||
#define _EVBARM_TYPES_H_
|
||||
|
@ -10,4 +10,6 @@
|
|||
#endif
|
||||
#define __HAVE_DEVICE_REGISTER
|
||||
|
||||
#define __HAVE_GENERIC_TODR
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: iq80310_timer.c,v 1.19 2005/12/24 20:06:59 perry Exp $ */
|
||||
/* $NetBSD: iq80310_timer.c,v 1.20 2007/02/19 02:08:12 briggs Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001, 2002 Wasabi Systems, Inc.
|
||||
|
@ -47,7 +47,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: iq80310_timer.c,v 1.19 2005/12/24 20:06:59 perry Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: iq80310_timer.c,v 1.20 2007/02/19 02:08:12 briggs Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -319,93 +319,6 @@ delay(u_int n)
|
|||
}
|
||||
}
|
||||
|
||||
todr_chip_handle_t todr_handle;
|
||||
|
||||
/*
|
||||
* todr_attach:
|
||||
*
|
||||
* Set the specified time-of-day register as the system real-time clock.
|
||||
*/
|
||||
void
|
||||
todr_attach(todr_chip_handle_t todr)
|
||||
{
|
||||
|
||||
if (todr_handle)
|
||||
panic("todr_attach: rtc already configured");
|
||||
todr_handle = todr;
|
||||
}
|
||||
|
||||
/*
|
||||
* inittodr:
|
||||
*
|
||||
* Initialize time from the time-of-day register.
|
||||
*/
|
||||
#define MINYEAR 2003 /* minimum plausible year */
|
||||
void
|
||||
inittodr(time_t base)
|
||||
{
|
||||
time_t deltat;
|
||||
int badbase;
|
||||
|
||||
if (base < (MINYEAR - 1970) * SECYR) {
|
||||
printf("WARNING: preposterous time in file system");
|
||||
/* read the system clock anyway */
|
||||
base = (MINYEAR - 1970) * SECYR;
|
||||
badbase = 1;
|
||||
} else
|
||||
badbase = 0;
|
||||
|
||||
if (todr_handle == NULL ||
|
||||
todr_gettime(todr_handle, &time) != 0 ||
|
||||
time.tv_sec == 0) {
|
||||
/*
|
||||
* Believe the time in the file system for lack of
|
||||
* anything better, resetting the TODR.
|
||||
*/
|
||||
time.tv_sec = base;
|
||||
time.tv_usec = 0;
|
||||
if (todr_handle != NULL && !badbase) {
|
||||
printf("WARNING: preposterous clock chip time\n");
|
||||
resettodr();
|
||||
}
|
||||
goto bad;
|
||||
}
|
||||
|
||||
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)
|
||||
return; /* all is well */
|
||||
printf("WARNING: clock %s %ld days\n",
|
||||
time.tv_sec < base ? "lost" : "gained",
|
||||
(long)deltat / SECDAY);
|
||||
}
|
||||
bad:
|
||||
printf("WARNING: CHECK AND RESET THE DATE!\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* resettodr:
|
||||
*
|
||||
* Reset the time-of-day register with the current time.
|
||||
*/
|
||||
void
|
||||
resettodr(void)
|
||||
{
|
||||
|
||||
if (time.tv_sec == 0)
|
||||
return;
|
||||
|
||||
if (todr_handle != NULL &&
|
||||
todr_settime(todr_handle, &time) != 0)
|
||||
printf("resettodr: failed to set time\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* clockhandler:
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue