blob: 933ac6349ff1e0a016187513a30ce93b931893d7 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Rudolph6b931122018-11-01 17:48:37 +01002
Angel Pons4dc85f12021-02-08 00:24:32 +01003#define __SIMPLE_DEVICE__
4
Patrick Rudolph6b931122018-11-01 17:48:37 +01005#include <console/console.h>
Patrick Rudolph6b931122018-11-01 17:48:37 +01006#include <device/pci_ops.h>
Elyes Haouasddd43de2022-10-02 20:02:23 +02007#include <device/pci_type.h>
Patrick Rudolph6b931122018-11-01 17:48:37 +01008#include <elog.h>
Elyes Haouasddd43de2022-10-02 20:02:23 +02009#include <pc80/mc146818rtc.h>
10#include <security/vboot/vbnv.h>
11
Patrick Rudolph6b931122018-11-01 17:48:37 +010012#include "pmutil.h"
13#include "rtc.h"
14
Patrick Rudolph6b931122018-11-01 17:48:37 +010015#define PCH_LPC_DEV PCI_DEV(0, 0x1f, 0)
Patrick Rudolph6b931122018-11-01 17:48:37 +010016
17int rtc_failure(void)
18{
Angel Pons4dc85f12021-02-08 00:24:32 +010019 return !!(pci_read_config8(PCH_LPC_DEV, D31F0_GEN_PMCON_3) & RTC_BATTERY_DEAD);
Patrick Rudolph6b931122018-11-01 17:48:37 +010020}
21
22void sb_rtc_init(void)
23{
24 int rtc_failed = rtc_failure();
25
26 if (rtc_failed) {
Julius Wernercd49cce2019-03-05 16:53:33 -080027 if (CONFIG(ELOG))
Patrick Rudolph6b931122018-11-01 17:48:37 +010028 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
38int vbnv_cmos_failed(void)
39{
40 return rtc_failure();
41}