![Finn Thain](/assets/img/avatar_default.png)
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>
106 lines
2.1 KiB
C
106 lines
2.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* linux/arch/m68k/sun3x/time.c
|
|
*
|
|
* Sun3x-specific time handling
|
|
*/
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/kd.h>
|
|
#include <linux/init.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/kernel_stat.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/rtc.h>
|
|
#include <linux/bcd.h>
|
|
|
|
#include <asm/irq.h>
|
|
#include <asm/io.h>
|
|
#include <asm/machdep.h>
|
|
#include <asm/traps.h>
|
|
#include <asm/sun3x.h>
|
|
#include <asm/sun3ints.h>
|
|
|
|
#include "time.h"
|
|
|
|
#define M_CONTROL 0xf8
|
|
#define M_SEC 0xf9
|
|
#define M_MIN 0xfa
|
|
#define M_HOUR 0xfb
|
|
#define M_DAY 0xfc
|
|
#define M_DATE 0xfd
|
|
#define M_MONTH 0xfe
|
|
#define M_YEAR 0xff
|
|
|
|
#define C_WRITE 0x80
|
|
#define C_READ 0x40
|
|
#define C_SIGN 0x20
|
|
#define C_CALIB 0x1f
|
|
|
|
int sun3x_hwclk(int set, struct rtc_time *t)
|
|
{
|
|
volatile struct mostek_dt *h =
|
|
(struct mostek_dt *)(SUN3X_EEPROM+M_CONTROL);
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
|
|
if(set) {
|
|
h->csr |= C_WRITE;
|
|
h->sec = bin2bcd(t->tm_sec);
|
|
h->min = bin2bcd(t->tm_min);
|
|
h->hour = bin2bcd(t->tm_hour);
|
|
h->wday = bin2bcd(t->tm_wday);
|
|
h->mday = bin2bcd(t->tm_mday);
|
|
h->month = bin2bcd(t->tm_mon + 1);
|
|
h->year = bin2bcd(t->tm_year % 100);
|
|
h->csr &= ~C_WRITE;
|
|
} else {
|
|
h->csr |= C_READ;
|
|
t->tm_sec = bcd2bin(h->sec);
|
|
t->tm_min = bcd2bin(h->min);
|
|
t->tm_hour = bcd2bin(h->hour);
|
|
t->tm_wday = bcd2bin(h->wday);
|
|
t->tm_mday = bcd2bin(h->mday);
|
|
t->tm_mon = bcd2bin(h->month) - 1;
|
|
t->tm_year = bcd2bin(h->year);
|
|
h->csr &= ~C_READ;
|
|
if (t->tm_year < 70)
|
|
t->tm_year += 100;
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return 0;
|
|
}
|
|
/* Not much we can do here */
|
|
u32 sun3x_gettimeoffset(void)
|
|
{
|
|
return 0L;
|
|
}
|
|
|
|
#if 0
|
|
static void sun3x_timer_tick(int irq, void *dev_id, struct pt_regs *regs)
|
|
{
|
|
void (*vector)(int, void *, struct pt_regs *) = dev_id;
|
|
|
|
/* Clear the pending interrupt - pulse the enable line low */
|
|
disable_irq(5);
|
|
enable_irq(5);
|
|
|
|
vector(irq, NULL, regs);
|
|
}
|
|
#endif
|
|
|
|
void __init sun3x_sched_init(irq_handler_t vector)
|
|
{
|
|
|
|
sun3_disable_interrupts();
|
|
|
|
|
|
/* Pulse enable low to get the clock started */
|
|
sun3_disable_irq(5);
|
|
sun3_enable_irq(5);
|
|
sun3_enable_interrupts();
|
|
}
|