summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2020-05-25 13:16:07 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2020-05-25 13:16:07 +0000
commitd70921a9eac1db381b557c545e92dc8721303c8a (patch)
tree39d654b87b54f6d644fd09387850b9604a36128a /sys/arch
parentdb5e25f07373ee9ae29220edb8ff42bb1e1690c3 (diff)
Use <dev/clock_subr.h> in mcclock(4).
Tested on Yeeloong. Looks good to miod@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/loongson/dev/mcclock.c76
-rw-r--r--sys/arch/loongson/dev/mcclock_isa.c7
-rw-r--r--sys/arch/loongson/dev/mcclockvar.h3
3 files changed, 45 insertions, 41 deletions
diff --git a/sys/arch/loongson/dev/mcclock.c b/sys/arch/loongson/dev/mcclock.c
index ef03151a186..34eee094293 100644
--- a/sys/arch/loongson/dev/mcclock.c
+++ b/sys/arch/loongson/dev/mcclock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mcclock.c,v 1.3 2010/01/22 21:44:00 miod Exp $ */
+/* $OpenBSD: mcclock.c,v 1.4 2020/05/25 13:16:06 visa Exp $ */
/* $NetBSD: mcclock.c,v 1.4 1996/10/13 02:59:41 christos Exp $ */
/*
@@ -33,20 +33,17 @@
#include <sys/systm.h>
#include <sys/device.h>
-#include <mips64/dev/clockvar.h>
-#include <loongson/dev/mcclockvar.h>
+#include <dev/clock_subr.h>
#include <dev/ic/mc146818reg.h>
+#include <loongson/dev/mcclockvar.h>
+
struct cfdriver mcclock_cd = {
NULL, "mcclock", DV_DULL,
};
-void mcclock_get(void *, time_t, struct tod_time *);
-void mcclock_set(void *, struct tod_time *);
-
-struct tod_desc mcclock_clockfns = {
- NULL, mcclock_get, mcclock_set,
-};
+int mcclock_gettime(struct todr_chip_handle *, struct timeval *);
+int mcclock_settime(struct todr_chip_handle *, struct timeval *);
#define mc146818_write(dev, reg, datum) \
(*(dev)->sc_busfns->mc_bf_write)(dev, reg, datum)
@@ -67,21 +64,20 @@ mcclock_attach(sc, busfns)
mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
mc146818_write(sc, MC_REGA, MC_BASE_32_KHz | MC_RATE_NONE);
- sys_tod.tod_cookie = sc;
- sys_tod.tod_get = mcclock_get;
- sys_tod.tod_set = mcclock_set;
+ sc->sc_todr.cookie = sc;
+ sc->sc_todr.todr_gettime = mcclock_gettime;
+ sc->sc_todr.todr_settime = mcclock_settime;
+ todr_attach(&sc->sc_todr);
}
/*
* Get the time of day, based on the clock's value and/or the base value.
*/
-void
-mcclock_get(dev, base, ct)
- void *dev;
- time_t base;
- struct tod_time *ct;
+int
+mcclock_gettime(struct todr_chip_handle *handle, struct timeval *tv)
{
- struct mcclock_softc *sc = (struct mcclock_softc *)dev;
+ struct clock_ymdhms dt;
+ struct mcclock_softc *sc = handle->cookie;
mc_todregs regs;
int s;
@@ -89,40 +85,46 @@ mcclock_get(dev, base, ct)
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] + 100;
+ dt.dt_sec = regs[MC_SEC];
+ dt.dt_min = regs[MC_MIN];
+ dt.dt_hour = regs[MC_HOUR];
+ dt.dt_day = regs[MC_DOM];
+ dt.dt_mon = regs[MC_MONTH];
+ dt.dt_year = regs[MC_YEAR] + 2000;
+
+ tv->tv_sec = clock_ymdhms_to_secs(&dt);
+ tv->tv_usec = 0;
+ return 0;
}
/*
* Reset the TODR based on the time value.
*/
-void
-mcclock_set(dev, ct)
- void *dev;
- struct tod_time *ct;
+int
+mcclock_settime(struct todr_chip_handle *handle, struct timeval *tv)
{
- struct mcclock_softc *sc = (struct mcclock_softc *)dev;
+ struct clock_ymdhms dt;
+ struct mcclock_softc *sc = handle->cookie;
mc_todregs regs;
int s;
+ clock_secs_to_ymdhms(tv->tv_sec, &dt);
+
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 - 100;
+ regs[MC_SEC] = dt.dt_sec;
+ regs[MC_MIN] = dt.dt_min;
+ regs[MC_HOUR] = dt.dt_hour;
+ regs[MC_DOW] = dt.dt_wday + 1;
+ regs[MC_DOM] = dt.dt_day;
+ regs[MC_MONTH] = dt.dt_mon;
+ regs[MC_YEAR] = dt.dt_year % 100;
s = splclock();
MC146818_PUTTOD(sc, &regs);
splx(s);
+
+ return 0;
}
diff --git a/sys/arch/loongson/dev/mcclock_isa.c b/sys/arch/loongson/dev/mcclock_isa.c
index ecda221bc14..b69a0a446ea 100644
--- a/sys/arch/loongson/dev/mcclock_isa.c
+++ b/sys/arch/loongson/dev/mcclock_isa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mcclock_isa.c,v 1.1 2009/12/25 21:04:32 miod Exp $ */
+/* $OpenBSD: mcclock_isa.c,v 1.2 2020/05/25 13:16:06 visa Exp $ */
/* $NetBSD: mcclock_isa.c,v 1.5 1996/12/05 01:39:29 cgd Exp $ */
/*
@@ -35,11 +35,12 @@
#include <machine/bus.h>
-#include <mips64/dev/clockvar.h>
-#include <loongson/dev/mcclockvar.h>
+#include <dev/clock_subr.h>
#include <dev/ic/mc146818reg.h>
#include <dev/isa/isavar.h>
+#include <loongson/dev/mcclockvar.h>
+
struct mcclock_isa_softc {
struct mcclock_softc sc_mcclock;
diff --git a/sys/arch/loongson/dev/mcclockvar.h b/sys/arch/loongson/dev/mcclockvar.h
index 3e4a6dd0781..97a89a607f0 100644
--- a/sys/arch/loongson/dev/mcclockvar.h
+++ b/sys/arch/loongson/dev/mcclockvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mcclockvar.h,v 1.1 2009/11/26 12:14:01 miod Exp $ */
+/* $OpenBSD: mcclockvar.h,v 1.2 2020/05/25 13:16:06 visa Exp $ */
/* $NetBSD: mcclockvar.h,v 1.2 1996/04/17 22:22:38 cgd Exp $ */
/*
@@ -30,6 +30,7 @@
struct mcclock_softc {
struct device sc_dev;
+ struct todr_chip_handle sc_todr;
const struct mcclock_busfns *sc_busfns;
};