make RTC year IRIX semantics adjustments a macro
This commit is contained in:
parent
c095bf1b6d
commit
53aa4de53f
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mcclock_mace.c,v 1.2 2001/11/25 15:13:53 soren Exp $ */
|
||||
/* $NetBSD: mcclock_mace.c,v 1.3 2002/01/14 16:23:28 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Antti Kantee. All Rights Reserved.
|
||||
|
@ -183,13 +183,7 @@ mcclock_mace_get(struct device *dev, struct clock_ymdhms *dt)
|
|||
dt->dt_wday = FROMBCD(regs[MC_DOW]);
|
||||
dt->dt_day = FROMBCD(regs[MC_DOM]);
|
||||
dt->dt_mon = FROMBCD(regs[MC_MONTH]);
|
||||
dt->dt_year = FROMBCD(regs[MC_YEAR]);
|
||||
|
||||
/* RTC base on IRIX is 1940, offsets < 45 are from 1970 */
|
||||
if (dt->dt_year < 45)
|
||||
dt->dt_year += 30;
|
||||
|
||||
dt->dt_year += IRIX_CLOCK_BASE; /* 1940 */
|
||||
dt->dt_year = FROM_IRIX_YEAR(FROMBCD(regs[MC_YEAR]));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -207,15 +201,7 @@ mcclock_mace_set(struct device *dev, struct clock_ymdhms *dt)
|
|||
regs[MC_DOW] = TOBCD(dt->dt_wday);
|
||||
regs[MC_DOM] = TOBCD(dt->dt_day);
|
||||
regs[MC_MONTH] = TOBCD(dt->dt_mon);
|
||||
|
||||
/*
|
||||
* If year < 1985, store (year - 1970), else (year - 1940). This
|
||||
* matches IRIX semantics.
|
||||
*/
|
||||
if (dt->dt_year < 1985)
|
||||
dt->dt_year -= 30;
|
||||
|
||||
regs[MC_YEAR] = TOBCD(dt->dt_year - IRIX_CLOCK_BASE); /* - 1940 */
|
||||
regs[MC_YEAR] = TOBSD(TO_IRIX_YEAR(dt->dt_year));
|
||||
|
||||
s = splhigh();
|
||||
MC146818_PUTTOD(sc, ®s);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: dsclock_hpc.c,v 1.1 2001/11/25 15:05:05 soren Exp $ */
|
||||
/* $NetBSD: dsclock_hpc.c,v 1.2 2002/01/14 16:23:28 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Rafal K. Boni
|
||||
|
@ -146,13 +146,7 @@ dsclock_get(struct device *dev, struct clock_ymdhms * dt)
|
|||
dt->dt_wday = FROMBCD(regs[DS_DOW]);
|
||||
dt->dt_day = FROMBCD(regs[DS_DOM]);
|
||||
dt->dt_mon = FROMBCD(regs[DS_MONTH] & DS_MONTH_MASK);
|
||||
dt->dt_year = FROMBCD(regs[DS_YEAR]);
|
||||
|
||||
/* RTC base on IRIX is 1940, offsets < 45 are from 1970 */
|
||||
if (dt->dt_year < 45)
|
||||
dt->dt_year += 30;
|
||||
|
||||
dt->dt_year += IRIX_CLOCK_BASE; /* 1940 */
|
||||
dt->dt_year = FROM_IRIX_YEAR(FROMBCD(regs[DS_YEAR]));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -180,14 +174,7 @@ dsclock_set(struct device *dev, struct clock_ymdhms * dt)
|
|||
regs[DS_MONTH] &= ~DS_MONTH_MASK;
|
||||
regs[DS_MONTH] |= TOBCD(dt->dt_mon) & DS_MONTH_MASK;
|
||||
|
||||
/*
|
||||
* If year < 1985, store (year - 1970), else (year - 1940). This
|
||||
* matches IRIX semantics.
|
||||
*/
|
||||
if (dt->dt_year < 1985)
|
||||
dt->dt_year -= 30;
|
||||
|
||||
regs[DS_YEAR] = TOBCD(dt->dt_year - IRIX_CLOCK_BASE); /* - 1940 */
|
||||
regs[DS_YEAR] = TOBCD(TO_IRIX_YEAR(dt->dt_year));
|
||||
|
||||
s = splhigh();
|
||||
DS1286_PUTTOD(sc, ®s);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: clockvar.h,v 1.2 2001/11/25 15:05:05 soren Exp $ */
|
||||
/* $NetBSD: clockvar.h,v 1.3 2002/01/14 16:23:27 pooka Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 1999 Tsubai Masanari. All rights reserved.
|
||||
|
@ -35,3 +35,14 @@ struct clockfns {
|
|||
void clockattach(struct device *, const struct clockfns *);
|
||||
|
||||
#define IRIX_CLOCK_BASE 1940
|
||||
|
||||
/*
|
||||
* If year < 1985, store (year - 1970), else (year - 1940). This
|
||||
* matches IRIX semantics.
|
||||
*/
|
||||
#define TO_IRIX_YEAR(a) ((a) < 1985) ? ((a) - (30 + IRIX_CLOCK_BASE)) \
|
||||
: ((a) - IRIX_CLOCK_BASE)
|
||||
|
||||
/* RTC base on IRIX is 1940, offsets < 45 are from 1970 */
|
||||
#define FROM_IRIX_YEAR(a) ((a) < 45) ? ((a) + 30 + IRIX_CLOCK_BASE) \
|
||||
: ((a) + IRIX_CLOCK_BASE)
|
||||
|
|
Loading…
Reference in New Issue