1*3dd15d69Stsutsui /* $NetBSD: getsecs.c,v 1.3 2019/06/30 05:04:49 tsutsui Exp $ */
247bef335Stsutsui
347bef335Stsutsui /*-
447bef335Stsutsui * Copyright (c) 2004 The NetBSD Foundation, Inc.
547bef335Stsutsui * All rights reserved.
647bef335Stsutsui *
747bef335Stsutsui * This code is derived from software contributed to The NetBSD Foundation
847bef335Stsutsui * by UCHIYAMA Yasushi.
947bef335Stsutsui *
1047bef335Stsutsui * Redistribution and use in source and binary forms, with or without
1147bef335Stsutsui * modification, are permitted provided that the following conditions
1247bef335Stsutsui * are met:
1347bef335Stsutsui * 1. Redistributions of source code must retain the above copyright
1447bef335Stsutsui * notice, this list of conditions and the following disclaimer.
1547bef335Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
1647bef335Stsutsui * notice, this list of conditions and the following disclaimer in the
1747bef335Stsutsui * documentation and/or other materials provided with the distribution.
1847bef335Stsutsui *
1947bef335Stsutsui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2047bef335Stsutsui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2147bef335Stsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2247bef335Stsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2347bef335Stsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2447bef335Stsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2547bef335Stsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2647bef335Stsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2747bef335Stsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2847bef335Stsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2947bef335Stsutsui * POSSIBILITY OF SUCH DAMAGE.
3047bef335Stsutsui */
3147bef335Stsutsui
3247bef335Stsutsui #include <machine/cpu.h>
33*3dd15d69Stsutsui #include <machine/board.h>
3447bef335Stsutsui
3547bef335Stsutsui #include <lib/libkern/libkern.h>
3647bef335Stsutsui #include <lib/libsa/stand.h>
3747bef335Stsutsui #include <lib/libsa/net.h>
3847bef335Stsutsui
3949b79589Schristos #include <dev/clock_subr.h>
4049b79589Schristos
4147bef335Stsutsui #include <luna68k/dev/timekeeper.h>
4247bef335Stsutsui #include <luna68k/stand/boot/samachdep.h>
4347bef335Stsutsui
4447bef335Stsutsui satime_t
getsecs(void)4547bef335Stsutsui getsecs(void)
4647bef335Stsutsui {
4747bef335Stsutsui volatile uint8_t *mclock;
4847bef335Stsutsui u_int t;
4947bef335Stsutsui
50*3dd15d69Stsutsui mclock = (volatile uint8_t *)OBIO_CLOCK_BASE;
5147bef335Stsutsui
5247bef335Stsutsui if (machtype == LUNA_I) {
5347bef335Stsutsui mclock += 2040;
5447bef335Stsutsui mclock[MK_CSR] |= MK_CSR_READ;
5547bef335Stsutsui t = bcdtobin(mclock[MK_SEC]);
5647bef335Stsutsui t += bcdtobin(mclock[MK_MIN]) * 60;
5747bef335Stsutsui t += bcdtobin(mclock[MK_HOUR]) * 60 * 60;
5847bef335Stsutsui mclock[MK_CSR] &= ~MK_CSR_READ;
5947bef335Stsutsui } else {
6047bef335Stsutsui while (mclock[MC_REGA] & MC_REGA_UIP)
6147bef335Stsutsui continue;
6247bef335Stsutsui t = mclock[MC_SEC];
6347bef335Stsutsui t += mclock[MC_MIN] * 60;
6447bef335Stsutsui t += mclock[MC_HOUR] * 60 * 60;
6547bef335Stsutsui }
6647bef335Stsutsui
6747bef335Stsutsui return (satime_t)t;
6847bef335Stsutsui }
69