Skip to content

Commit 7ad295d

Browse files
Jinke Fanalexandrebelloni
authored andcommitted
rtc: Fix the AltCentury value on AMD/Hygon platform
When using following operations: date -s "21190910 19:20:00" hwclock -w to change date from 2019 to 2119 for test, it will fail on Hygon Dhyana and AMD Zen CPUs, while the same operations run ok on Intel i7 platform. MC146818 driver use function mc146818_set_time() to set register RTC_FREQ_SELECT(RTC_REG_A)'s bit4-bit6 field which means divider stage reset value on Intel platform to 0x7. While AMD/Hygon RTC_REG_A(0Ah)'s bit4 is defined as DV0 [Reference]: DV0 = 0 selects Bank 0, DV0 = 1 selects Bank 1. Bit5-bit6 is defined as reserved. DV0 is set to 1, it will select Bank 1, which will disable AltCentury register(0x32) access. As UEFI pass acpi_gbl_FADT.century 0x32 (AltCentury), the CMOS write will be failed on code: CMOS_WRITE(century, acpi_gbl_FADT.century). Correct RTC_REG_A bank select bit(DV0) to 0 on AMD/Hygon CPUs, it will enable AltCentury(0x32) register writing and finally setup century as expected. Test results on Intel i7, AMD EPYC(17h) and Hygon machine show that it works as expected. Compiling for sparc64 and alpha architectures are passed. Reference: https://www.amd.com/system/files/TechDocs/51192_Bolton_FCH_RRG.pdf section: 3.13 Real Time Clock (RTC) Reported-by: kbuild test robot <[email protected]> Signed-off-by: Jinke Fan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent afe19a7 commit 7ad295d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/rtc/rtc-mc146818-lib.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,20 @@ int mc146818_set_time(struct rtc_time *time)
172172
save_control = CMOS_READ(RTC_CONTROL);
173173
CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
174174
save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
175-
CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT);
175+
176+
#ifdef CONFIG_X86
177+
if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
178+
boot_cpu_data.x86 == 0x17) ||
179+
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
180+
CMOS_WRITE((save_freq_select & (~RTC_DIV_RESET2)),
181+
RTC_FREQ_SELECT);
182+
save_freq_select &= ~RTC_DIV_RESET2;
183+
} else
184+
CMOS_WRITE((save_freq_select | RTC_DIV_RESET2),
185+
RTC_FREQ_SELECT);
186+
#else
187+
CMOS_WRITE((save_freq_select | RTC_DIV_RESET2), RTC_FREQ_SELECT);
188+
#endif
176189

177190
#ifdef CONFIG_MACH_DECSTATION
178191
CMOS_WRITE(real_yrs, RTC_DEC_YEAR);

0 commit comments

Comments
 (0)