|
8 | 8 | #ifndef __ASM_MC146818_TIME_H
|
9 | 9 | #define __ASM_MC146818_TIME_H
|
10 | 10 |
|
11 |
| -#include <linux/bcd.h> |
12 | 11 | #include <linux/mc146818rtc.h>
|
13 | 12 | #include <linux/time.h>
|
14 | 13 |
|
| 14 | +#ifdef CONFIG_RTC_MC146818_LIB |
15 | 15 | static inline time64_t mc146818_get_cmos_time(void)
|
16 | 16 | {
|
17 |
| - unsigned int year, mon, day, hour, min, sec; |
18 |
| - unsigned long flags; |
| 17 | + struct rtc_time tm; |
19 | 18 |
|
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; |
38 | 22 | }
|
39 |
| - spin_unlock_irqrestore(&rtc_lock, flags); |
40 |
| - if (year < 70) |
41 |
| - year += 2000; |
42 |
| - else |
43 |
| - year += 1900; |
44 | 23 |
|
45 |
| - return mktime64(year, mon, day, hour, min, sec); |
| 24 | + return rtc_tm_to_time64(&tm); |
46 | 25 | }
|
| 26 | +#endif /* CONFIG_RTC_MC146818_LIB */ |
47 | 27 |
|
48 | 28 | #endif /* __ASM_MC146818_TIME_H */
|
0 commit comments