4
4
*/
5
5
#include <linux/platform_device.h>
6
6
#include <linux/mc146818rtc.h>
7
- #include <linux/acpi.h>
8
- #include <linux/bcd.h>
9
7
#include <linux/export.h>
10
8
#include <linux/pnp.h>
11
- #include <linux/of.h>
12
9
13
10
#include <asm/vsyscall.h>
14
11
#include <asm/x86_init.h>
20
17
/*
21
18
* This is a special lock that is owned by the CPU and holds the index
22
19
* register we are working with. It is required for NMI access to the
23
- * CMOS/RTC registers. See include/asm-i386 /mc146818rtc.h for details.
20
+ * CMOS/RTC registers. See arch/x86/ include/asm/mc146818rtc.h for details.
24
21
*/
25
22
volatile unsigned long cmos_lock ;
26
23
EXPORT_SYMBOL (cmos_lock );
27
24
#endif /* CONFIG_X86_32 */
28
25
29
- /* For two digit years assume time is always after that */
30
- #define CMOS_YEARS_OFFS 2000
31
-
32
26
DEFINE_SPINLOCK (rtc_lock );
33
27
EXPORT_SYMBOL (rtc_lock );
34
28
35
29
/*
36
- * In order to set the CMOS clock precisely, set_rtc_mmss has to be
30
+ * In order to set the CMOS clock precisely, mach_set_cmos_time has to be
37
31
* called 500 ms after the second nowtime has started, because when
38
32
* nowtime is written into the registers of the CMOS clock, it will
39
33
* jump to the next second precisely 500 ms later. Check the Motorola
40
34
* MC146818A or Dallas DS12887 data sheet for details.
41
35
*/
42
- int mach_set_rtc_mmss (const struct timespec64 * now )
36
+ int mach_set_cmos_time (const struct timespec64 * now )
43
37
{
44
38
unsigned long long nowtime = now -> tv_sec ;
45
39
struct rtc_time tm ;
@@ -62,8 +56,7 @@ int mach_set_rtc_mmss(const struct timespec64 *now)
62
56
63
57
void mach_get_cmos_time (struct timespec64 * now )
64
58
{
65
- unsigned int status , year , mon , day , hour , min , sec , century = 0 ;
66
- unsigned long flags ;
59
+ struct rtc_time tm ;
67
60
68
61
/*
69
62
* If pm_trace abused the RTC as storage, set the timespec to 0,
@@ -74,51 +67,13 @@ void mach_get_cmos_time(struct timespec64 *now)
74
67
return ;
75
68
}
76
69
77
- spin_lock_irqsave (& rtc_lock , flags );
78
-
79
- /*
80
- * If UIP is clear, then we have >= 244 microseconds before
81
- * RTC registers will be updated. Spec sheet says that this
82
- * is the reliable way to read RTC - registers. If UIP is set
83
- * then the register access might be invalid.
84
- */
85
- while ((CMOS_READ (RTC_FREQ_SELECT ) & RTC_UIP ))
86
- cpu_relax ();
87
-
88
- sec = CMOS_READ (RTC_SECONDS );
89
- min = CMOS_READ (RTC_MINUTES );
90
- hour = CMOS_READ (RTC_HOURS );
91
- day = CMOS_READ (RTC_DAY_OF_MONTH );
92
- mon = CMOS_READ (RTC_MONTH );
93
- year = CMOS_READ (RTC_YEAR );
94
-
95
- #ifdef CONFIG_ACPI
96
- if (acpi_gbl_FADT .header .revision >= FADT2_REVISION_ID &&
97
- acpi_gbl_FADT .century )
98
- century = CMOS_READ (acpi_gbl_FADT .century );
99
- #endif
100
-
101
- status = CMOS_READ (RTC_CONTROL );
102
- WARN_ON_ONCE (RTC_ALWAYS_BCD && (status & RTC_DM_BINARY ));
103
-
104
- spin_unlock_irqrestore (& rtc_lock , flags );
105
-
106
- if (RTC_ALWAYS_BCD || !(status & RTC_DM_BINARY )) {
107
- sec = bcd2bin (sec );
108
- min = bcd2bin (min );
109
- hour = bcd2bin (hour );
110
- day = bcd2bin (day );
111
- mon = bcd2bin (mon );
112
- year = bcd2bin (year );
70
+ if (mc146818_get_time (& tm )) {
71
+ pr_err ("Unable to read current time from RTC\n" );
72
+ now -> tv_sec = now -> tv_nsec = 0 ;
73
+ return ;
113
74
}
114
75
115
- if (century ) {
116
- century = bcd2bin (century );
117
- year += century * 100 ;
118
- } else
119
- year += CMOS_YEARS_OFFS ;
120
-
121
- now -> tv_sec = mktime64 (year , mon , day , hour , min , sec );
76
+ now -> tv_sec = rtc_tm_to_time64 (& tm );
122
77
now -> tv_nsec = 0 ;
123
78
}
124
79
0 commit comments