]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/sh/boards/landisk/rtc.c
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
12 #include <linux/config.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/time.h>
17 #include <linux/delay.h>
18 #include <linux/spinlock.h>
19 #include <linux/bcd.h>
22 extern spinlock_t rtc_lock
;
25 rs5c313_set_cmos_time(unsigned int BCD_yr
, unsigned int BCD_mon
,
26 unsigned int BCD_day
, unsigned int BCD_hr
,
27 unsigned int BCD_min
, unsigned int BCD_sec
);
30 rs5c313_get_cmos_time(unsigned int *BCD_yr
, unsigned int *BCD_mon
,
31 unsigned int *BCD_day
, unsigned int *BCD_hr
,
32 unsigned int *BCD_min
, unsigned int *BCD_sec
);
34 void landisk_rtc_gettimeofday(struct timespec
*tv
)
36 unsigned int BCD_yr
, BCD_mon
, BCD_day
, BCD_hr
, BCD_min
, BCD_sec
;
39 spin_lock_irqsave(&rtc_lock
, flags
);
40 tv
->tv_sec
= rs5c313_get_cmos_time
41 (&BCD_yr
, &BCD_mon
, &BCD_day
, &BCD_hr
, &BCD_min
, &BCD_sec
);
43 spin_unlock_irqrestore(&rtc_lock
, flags
);
46 int landisk_rtc_settimeofday(const time_t secs
)
49 int real_seconds
, real_minutes
, cmos_minutes
;
51 unsigned long nowtime
= secs
;
52 unsigned int BCD_yr
, BCD_mon
, BCD_day
, BCD_hr
, BCD_min
, BCD_sec
;
54 spin_lock_irqsave(&rtc_lock
, flags
);
57 (&BCD_yr
, &BCD_mon
, &BCD_day
, &BCD_hr
, &BCD_min
, &BCD_sec
);
58 cmos_minutes
= BCD_min
;
59 BCD_TO_BIN(cmos_minutes
);
62 * since we're only adjusting minutes and seconds,
63 * don't interfere with hour overflow. This avoids
64 * messing with unknown time zones but requires your
65 * RTC not to be off by more than 15 minutes
67 real_seconds
= nowtime
% 60;
68 real_minutes
= nowtime
/ 60;
69 if (((abs(real_minutes
- cmos_minutes
) + 15) / 30) & 1)
70 real_minutes
+= 30; /* correct for half hour time zone */
73 if (abs(real_minutes
- cmos_minutes
) < 30) {
74 BIN_TO_BCD(real_seconds
);
75 BIN_TO_BCD(real_minutes
);
76 rs5c313_set_cmos_time(BCD_yr
, BCD_mon
, BCD_day
, BCD_hr
,
77 real_minutes
, real_seconds
);
80 "set_rtc_time: can't update from %d to %d\n",
81 cmos_minutes
, real_minutes
);
85 spin_unlock_irqrestore(&rtc_lock
, flags
);
89 void landisk_time_init(void)
91 rtc_sh_get_time
= landisk_rtc_gettimeofday
;
92 rtc_sh_set_time
= landisk_rtc_settimeofday
;