Skip to content

Commit 01557e3

Browse files
matjontsbogend
authored andcommitted
mips/malta,loongson2ef: use generic mc146818_get_time function
mc146818_get_cmos_time() is now mostly equivalent to mc146818_get_time() from drivers/rtc/rtc-mc146818-lib.c, with the latter using a more advanced algorithm (which checks the UIP bit in the CMOS). The Malta and Loongson2ef platforms, the only users of mc146818_get_cmos_time() have RTC devices that should be MC146818 compatible. So, rewrite mc146818_get_cmos_time() in a way that uses mc146818_get_time() and add CONFIG_RTC_MC146818_LIB as a dependency of CONFIG_MIPS_MALTA and CONFIG_CPU_LOONGSON2EF. The should be safe as: - malta_defconfig already uses a standard RTC CMOS driver (CONFIG_RTC_DRV_CMOS=y). The Malta board has an Intel 82371EB (PIIX4E) south bridge with the CMOS RTC, so should work correctly with the modification, - Loongson2e and 2f apparently use the VIA686B south bridge and the AMD CS5536 south bridge respectively (at least according to Kconfig). I have checked datasheets of both and these appear to be MC146818 software compatible. Signed-off-by: Mateusz Jończyk <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent 6e68ee3 commit 01557e3

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

arch/mips/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ config MIPS_MALTA
563563
select MIPS_L1_CACHE_SHIFT_6
564564
select MIPS_MSC
565565
select PCI_GT64XXX_PCI0
566+
select RTC_MC146818_LIB
566567
select SMP_UP if SMP
567568
select SWAP_IO_SPACE
568569
select SYS_HAS_CPU_MIPS32_R1
@@ -1837,6 +1838,7 @@ config CPU_LOONGSON2EF
18371838
select CPU_SUPPORTS_64BIT_KERNEL
18381839
select CPU_SUPPORTS_HIGHMEM
18391840
select CPU_SUPPORTS_HUGEPAGES
1841+
select RTC_MC146818_LIB
18401842

18411843
config CPU_LOONGSON32
18421844
bool

arch/mips/include/asm/mc146818-time.h

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,21 @@
88
#ifndef __ASM_MC146818_TIME_H
99
#define __ASM_MC146818_TIME_H
1010

11-
#include <linux/bcd.h>
1211
#include <linux/mc146818rtc.h>
1312
#include <linux/time.h>
1413

14+
#ifdef CONFIG_RTC_MC146818_LIB
1515
static inline time64_t mc146818_get_cmos_time(void)
1616
{
17-
unsigned int year, mon, day, hour, min, sec;
18-
unsigned long flags;
17+
struct rtc_time tm;
1918

20-
spin_lock_irqsave(&rtc_lock, flags);
21-
22-
do {
23-
sec = CMOS_READ(RTC_SECONDS);
24-
min = CMOS_READ(RTC_MINUTES);
25-
hour = CMOS_READ(RTC_HOURS);
26-
day = CMOS_READ(RTC_DAY_OF_MONTH);
27-
mon = CMOS_READ(RTC_MONTH);
28-
year = CMOS_READ(RTC_YEAR);
29-
} while (sec != CMOS_READ(RTC_SECONDS));
30-
31-
if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
32-
sec = bcd2bin(sec);
33-
min = bcd2bin(min);
34-
hour = bcd2bin(hour);
35-
day = bcd2bin(day);
36-
mon = bcd2bin(mon);
37-
year = bcd2bin(year);
19+
if (mc146818_get_time(&tm, 1000)) {
20+
pr_err("Unable to read current time from RTC\n");
21+
return 0;
3822
}
39-
spin_unlock_irqrestore(&rtc_lock, flags);
40-
if (year < 70)
41-
year += 2000;
42-
else
43-
year += 1900;
4423

45-
return mktime64(year, mon, day, hour, min, sec);
24+
return rtc_tm_to_time64(&tm);
4625
}
26+
#endif /* CONFIG_RTC_MC146818_LIB */
4727

4828
#endif /* __ASM_MC146818_TIME_H */

0 commit comments

Comments
 (0)