2 * arch/sh/boards/landisk/rtc.c -- RTC support
4 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
5 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/time.h>
15 #include <linux/delay.h>
16 #include <linux/spinlock.h>
17 #include <linux/bcd.h>
20 extern spinlock_t rtc_lock
;
23 rs5c313_set_cmos_time(unsigned int BCD_yr
, unsigned int BCD_mon
,
24 unsigned int BCD_day
, unsigned int BCD_hr
,
25 unsigned int BCD_min
, unsigned int BCD_sec
);
28 rs5c313_get_cmos_time(unsigned int *BCD_yr
, unsigned int *BCD_mon
,
29 unsigned int *BCD_day
, unsigned int *BCD_hr
,
30 unsigned int *BCD_min
, unsigned int *BCD_sec
);
32 void landisk_rtc_gettimeofday(struct timespec
*tv
)
34 unsigned int BCD_yr
, BCD_mon
, BCD_day
, BCD_hr
, BCD_min
, BCD_sec
;
37 spin_lock_irqsave(&rtc_lock
, flags
);
38 tv
->tv_sec
= rs5c313_get_cmos_time
39 (&BCD_yr
, &BCD_mon
, &BCD_day
, &BCD_hr
, &BCD_min
, &BCD_sec
);
41 spin_unlock_irqrestore(&rtc_lock
, flags
);
44 int landisk_rtc_settimeofday(const time_t secs
)
47 int real_seconds
, real_minutes
, cmos_minutes
;
49 unsigned long nowtime
= secs
;
50 unsigned int BCD_yr
, BCD_mon
, BCD_day
, BCD_hr
, BCD_min
, BCD_sec
;
52 spin_lock_irqsave(&rtc_lock
, flags
);
55 (&BCD_yr
, &BCD_mon
, &BCD_day
, &BCD_hr
, &BCD_min
, &BCD_sec
);
56 cmos_minutes
= BCD_min
;
57 BCD_TO_BIN(cmos_minutes
);
60 * since we're only adjusting minutes and seconds,
61 * don't interfere with hour overflow. This avoids
62 * messing with unknown time zones but requires your
63 * RTC not to be off by more than 15 minutes
65 real_seconds
= nowtime
% 60;
66 real_minutes
= nowtime
/ 60;
67 if (((abs(real_minutes
- cmos_minutes
) + 15) / 30) & 1)
68 real_minutes
+= 30; /* correct for half hour time zone */
71 if (abs(real_minutes
- cmos_minutes
) < 30) {
72 BIN_TO_BCD(real_seconds
);
73 BIN_TO_BCD(real_minutes
);
74 rs5c313_set_cmos_time(BCD_yr
, BCD_mon
, BCD_day
, BCD_hr
,
75 real_minutes
, real_seconds
);
78 "set_rtc_time: can't update from %d to %d\n",
79 cmos_minutes
, real_minutes
);
83 spin_unlock_irqrestore(&rtc_lock
, flags
);
87 void landisk_time_init(void)
89 rtc_sh_get_time
= landisk_rtc_gettimeofday
;
90 rtc_sh_set_time
= landisk_rtc_settimeofday
;