xref: /aosp_15_r20/external/coreboot/src/southbridge/intel/common/rtc.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #define __SIMPLE_DEVICE__
4 
5 #include <console/console.h>
6 #include <device/pci_ops.h>
7 #include <device/pci_type.h>
8 #include <elog.h>
9 #include <pc80/mc146818rtc.h>
10 #include <security/vboot/vbnv.h>
11 
12 #include "pmutil.h"
13 #include "rtc.h"
14 
15 #define PCH_LPC_DEV	PCI_DEV(0, 0x1f, 0)
16 
rtc_failure(void)17 int rtc_failure(void)
18 {
19 	return !!(pci_read_config8(PCH_LPC_DEV, D31F0_GEN_PMCON_3) & RTC_BATTERY_DEAD);
20 }
21 
sb_rtc_init(void)22 void sb_rtc_init(void)
23 {
24 	int rtc_failed = rtc_failure();
25 
26 	if (rtc_failed) {
27 		if (CONFIG(ELOG))
28 			elog_add_event(ELOG_TYPE_RTC_RESET);
29 		pci_update_config8(PCH_LPC_DEV, D31F0_GEN_PMCON_3,
30 				   ~RTC_BATTERY_DEAD, 0);
31 	}
32 
33 	printk(BIOS_DEBUG, "RTC: failed = 0x%x\n", rtc_failed);
34 
35 	cmos_init(rtc_failed);
36 }
37 
vbnv_cmos_failed(void)38 int vbnv_cmos_failed(void)
39 {
40 	return rtc_failure();
41 }
42