/*
* Copyright (c) 2001 Erik Reid
* Copyright (c) 2001 Rafal K. Boni
* Copyright (c) 2001 Christopher Sekiya
* Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Portions of this code are derived from software contributed to The
* NetBSD Foundation by Jason R. Thorpe of the Numerical Aerospace
* Simulation Facility, NASA Ames Research Center.
*
* 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.
*/
sc->sc_rtct = normal_memt;
/*
* All machines have one byte register per word. IP6/IP10 use
* the MSB, others the LSB.
*/
if (mach_type == MACH_SGI_IP12 || mach_type == MACH_SGI_IP20)
sc->sc_offset = 3;
else
sc->sc_offset = 0;
/*
* Get the time of day, based on the clock's value and/or the base value.
*/
static int
dpclock_gettime_ymdhms(struct todr_chip_handle *todrch, struct clock_ymdhms *dt)
{
struct dpclock_softc *sc = (struct dpclock_softc *)todrch->cookie;
int s;
u_int8_t i, j;
u_int8_t regs[32];
s = splhigh();
i = readreg(sc, DP8573A_TIMESAVE_CTL);
j = i | DP8573A_TIMESAVE_CTL_EN;
writereg(sc, DP8573A_TIMESAVE_CTL, j);
writereg(sc, DP8573A_TIMESAVE_CTL, i);
splx(s);
for (i = 0; i < 32; i++)
regs[i] = readreg(sc, i);
dt->dt_wday = bcdtobin(regs[DP8573A_DOW]); /* Not from time saved */
dt->dt_day = bcdtobin(regs[DP8573A_SAVE_DOM]);
dt->dt_mon = bcdtobin(regs[DP8573A_SAVE_MONTH]);
dt->dt_year = FROM_IRIX_YEAR(bcdtobin(regs[DP8573A_YEAR]));
return (0);
}
/*
* Reset the TODR based on the time value.
*/
static int
dpclock_settime_ymdhms(struct todr_chip_handle *todrch, struct clock_ymdhms *dt)
{
struct dpclock_softc *sc = (struct dpclock_softc *)todrch->cookie;
int s;
u_int8_t i, j;
u_int8_t regs[32];
s = splhigh();
i = readreg(sc, DP8573A_TIMESAVE_CTL);
j = i | DP8573A_TIMESAVE_CTL_EN;
writereg(sc, DP8573A_TIMESAVE_CTL, j);
writereg(sc, DP8573A_TIMESAVE_CTL, i);
splx(s);
for (i = 0; i < 32; i++)
regs[i] = readreg(sc, i);