Patrick Rudolph | 6b93112 | 2018-11-01 17:48:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2013 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/pci_def.h> |
| 19 | #include <device/pci_ops.h> |
| 20 | #include <security/vboot/vbnv.h> |
| 21 | #include <pc80/mc146818rtc.h> |
| 22 | #include <elog.h> |
| 23 | #include "pmutil.h" |
| 24 | #include "rtc.h" |
| 25 | |
| 26 | /* PCI Configuration Space (D31:F0): LPC */ |
| 27 | #if defined(__SIMPLE_DEVICE__) |
| 28 | #define PCH_LPC_DEV PCI_DEV(0, 0x1f, 0) |
| 29 | #else |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 30 | #define PCH_LPC_DEV pcidev_on_root(0x1f, 0) |
Patrick Rudolph | 6b93112 | 2018-11-01 17:48:37 +0100 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | int rtc_failure(void) |
| 34 | { |
| 35 | return !!(pci_read_config8(PCH_LPC_DEV, D31F0_GEN_PMCON_3) |
| 36 | & RTC_BATTERY_DEAD); |
| 37 | } |
| 38 | |
| 39 | void sb_rtc_init(void) |
| 40 | { |
| 41 | int rtc_failed = rtc_failure(); |
| 42 | |
| 43 | if (rtc_failed) { |
| 44 | if (IS_ENABLED(CONFIG_ELOG)) |
| 45 | elog_add_event(ELOG_TYPE_RTC_RESET); |
| 46 | pci_update_config8(PCH_LPC_DEV, D31F0_GEN_PMCON_3, |
| 47 | ~RTC_BATTERY_DEAD, 0); |
| 48 | } |
| 49 | |
| 50 | printk(BIOS_DEBUG, "RTC: failed = 0x%x\n", rtc_failed); |
| 51 | |
| 52 | cmos_init(rtc_failed); |
| 53 | } |
| 54 | |
| 55 | int vbnv_cmos_failed(void) |
| 56 | { |
| 57 | return rtc_failure(); |
| 58 | } |