[PATCH] rtc: Fix hwclock write fail problem in x86 arch

From: Sang Yan
Date: Wed May 19 2021 - 05:21:28 EST


From: Jingxian He <hejingxian@xxxxxxxxxx>

When RTC_ALWAYS_BCD is set as 1, the function mc146818_set_time
ignores the reading value of RTC_CONTROL register,
and assumes that RTC always operates in binary mode.

However, the mc146818 development manual says that:
if !(CMOS_READ(RTC_CONTROL) & 0x04), then
the rtc time is in binary mode;
if (CMOS_READ(RTC_CONTROL) & 0x04), then
the rtc time is in bcd mode.

We use 'hwclock -w' to set the RTC from the system time
at our x86 machines, and we find that when
(CMOS_READ(RTC_CONTROL) & 0x04) is equal to 1,
'hwclock -w' will fail to set the RTC.

We change the RTC_ALWAYS_BCD to 0 to parse the rtc
time according to the read value of RTC_CONTROL register.

Signed-off-by: Jingxian He <hejingxian@xxxxxxxxxx>
Signed-off-by: Jie He <hejie3@xxxxxxxxxx>
---
arch/x86/include/asm/mc146818rtc.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/mc146818rtc.h b/arch/x86/include/asm/mc146818rtc.h
index 9719800..63cf0d5 100644
--- a/arch/x86/include/asm/mc146818rtc.h
+++ b/arch/x86/include/asm/mc146818rtc.h
@@ -10,7 +10,7 @@

#ifndef RTC_PORT
#define RTC_PORT(x) (0x70 + (x))
-#define RTC_ALWAYS_BCD 1 /* RTC operates in binary mode */
+#define RTC_ALWAYS_BCD 0
#endif

#if defined(CONFIG_X86_32)
--
2.9.5