summaryrefslogtreecommitdiff
path: root/payloads/libpayload/drivers
diff options
context:
space:
mode:
authorPatrick Rudolph <siro@das-labor.org>2018-02-03 11:50:56 +0100
committerPatrick Georgi <pgeorgi@google.com>2020-03-23 08:35:31 +0000
commit77e0baa6e99761462af4c69c7beda0af9571525e (patch)
tree734a29e0d1e681ad1d1fa251e9cdbb7862e7e5bc /payloads/libpayload/drivers
parent0beddb5e237f23c59399b1c93f25230a6eab3372 (diff)
downloadcoreboot-77e0baa6e99761462af4c69c7beda0af9571525e.tar.xz
libpayload/drivers/nvram: Add function to write RTC
Add a function to set the RTC to provided struct tm. Change-Id: I17b4c1ee0dcc649738ac6a7400b087d07213eaf0 Signed-off-by: Patrick Rudolph <siro@das-labor.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/23585 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'payloads/libpayload/drivers')
-rw-r--r--payloads/libpayload/drivers/nvram.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/payloads/libpayload/drivers/nvram.c b/payloads/libpayload/drivers/nvram.c
index 34ee0331e1..0196bb5c7c 100644
--- a/payloads/libpayload/drivers/nvram.c
+++ b/payloads/libpayload/drivers/nvram.c
@@ -160,3 +160,55 @@ void rtc_read_clock(struct tm *time)
if (time->tm_year < 80)
time->tm_year += 100;
}
+
+/**
+ * Write the current time and date to the RTC
+ *
+ * @param time A pointer to a broken-down time structure
+ */
+void rtc_write_clock(const struct tm *time)
+{
+ u16 timeout = 10000;
+ u8 statusB;
+ u8 reg8, year;
+
+ while (nvram_updating())
+ if (!timeout--)
+ return;
+
+ statusB = nvram_read(NVRAM_RTC_STATUSB);
+
+ year = time->tm_year;
+ if (year > 100)
+ year -= 100;
+
+ if (!(statusB & NVRAM_RTC_FORMAT_BINARY)) {
+ nvram_write(dec2bcd(time->tm_mon + 1), NVRAM_RTC_MONTH);
+ nvram_write(dec2bcd(time->tm_sec), NVRAM_RTC_SECONDS);
+ nvram_write(dec2bcd(time->tm_min), NVRAM_RTC_MINUTES);
+ nvram_write(dec2bcd(time->tm_mday), NVRAM_RTC_DAY);
+ if (!(statusB & NVRAM_RTC_FORMAT_24HOUR)) {
+ if (time->tm_hour > 12)
+ reg8 = dec2bcd(time->tm_hour - 12) | 0x80;
+ else
+ reg8 = dec2bcd(time->tm_hour);
+ } else
+ reg8 = dec2bcd(time->tm_hour);
+ nvram_write(reg8, NVRAM_RTC_HOURS);
+ nvram_write(dec2bcd(year), NVRAM_RTC_YEAR);
+ } else {
+ nvram_write(time->tm_mon + 1, NVRAM_RTC_MONTH);
+ nvram_write(time->tm_sec, NVRAM_RTC_SECONDS);
+ nvram_write(time->tm_min, NVRAM_RTC_MINUTES);
+ nvram_write(time->tm_mday, NVRAM_RTC_DAY);
+ if (!(statusB & NVRAM_RTC_FORMAT_24HOUR)) {
+ if (time->tm_hour > 12)
+ reg8 = (time->tm_hour - 12) | 0x80;
+ else
+ reg8 = time->tm_hour;
+ } else
+ reg8 = time->tm_hour;
+ nvram_write(reg8, NVRAM_RTC_HOURS);
+ nvram_write(year, NVRAM_RTC_YEAR);
+ }
+}