kernel_optimize_test/arch/m68k/sun3/intersil.c
Finn Thain b65769fc01 m68k: Fix off-by-one calendar month
This fixes a bug in read_persistent_clock() which causes the system
clock to lag the Real Time Clock by one month. The problem was noticed
on a Mac, but theoretically it must also affect Atari, BVME6000 and Q40.

The tm_mon value in the struct rtc_time passed to mach_hwclk() is
zero-based, and atari_mste_hwclk(), atari_tt_hwclk(), bvme6000_hwclk(),
mac_hwclk() and q40_hwclk() all make this adjustment. Unfortunately,
dn_dummy_hwclk(), mvme147_hwclk(), mvme16x_hwclk(), sun3_hwclk() and
sun3x_hwclk() fail to decrement tm_mon.  Also m68328_hwclk() assumes
a one-based tm_mon.

Bring these platforms into line and fix read_persistent_clock() so it
works correctly on all m68k platforms.

The datasheets for the RTC devices found on the affected platforms
all confirm that the year is stored as a value in the range 0-99 and
the month is stored as a value in the range 1-12. Please refer to the
datasheets for MC146818 (Apollo), DS1643 (MVME), ICM7170 (Sun 3)
and M48T02 (Sun 3x).

Reported-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2018-05-22 10:31:50 +02:00

77 lines
1.7 KiB
C

/*
* arch/m68k/sun3/intersil.c
*
* basic routines for accessing the intersil clock within the sun3 machines
*
* started 11/12/1999 Sam Creasey
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*/
#include <linux/kernel.h>
#include <linux/rtc.h>
#include <asm/errno.h>
#include <asm/intersil.h>
#include <asm/machdep.h>
/* bits to set for start/run of the intersil */
#define STOP_VAL (INTERSIL_STOP | INTERSIL_INT_ENABLE | INTERSIL_24H_MODE)
#define START_VAL (INTERSIL_RUN | INTERSIL_INT_ENABLE | INTERSIL_24H_MODE)
/* does this need to be implemented? */
u32 sun3_gettimeoffset(void)
{
return 1000;
}
/* get/set hwclock */
int sun3_hwclk(int set, struct rtc_time *t)
{
volatile struct intersil_dt *todintersil;
unsigned long flags;
todintersil = (struct intersil_dt *) &intersil_clock->counter;
local_irq_save(flags);
intersil_clock->cmd_reg = STOP_VAL;
/* set or read the clock */
if(set) {
todintersil->csec = 0;
todintersil->hour = t->tm_hour;
todintersil->minute = t->tm_min;
todintersil->second = t->tm_sec;
todintersil->month = t->tm_mon + 1;
todintersil->day = t->tm_mday;
todintersil->year = (t->tm_year - 68) % 100;
todintersil->weekday = t->tm_wday;
} else {
/* read clock */
t->tm_sec = todintersil->csec;
t->tm_hour = todintersil->hour;
t->tm_min = todintersil->minute;
t->tm_sec = todintersil->second;
t->tm_mon = todintersil->month - 1;
t->tm_mday = todintersil->day;
t->tm_year = todintersil->year + 68;
t->tm_wday = todintersil->weekday;
if (t->tm_year < 70)
t->tm_year += 100;
}
intersil_clock->cmd_reg = START_VAL;
local_irq_restore(flags);
return 0;
}