diff options
author | Jordan Crouse <jordan.crouse@amd.com> | 2008-04-25 23:11:02 +0000 |
---|---|---|
committer | Jordan Crouse <jordan.crouse@amd.com> | 2008-04-25 23:11:02 +0000 |
commit | e2271430c53d24976ec3b0869dd8993cfba6d768 (patch) | |
tree | 4a5cf4555b8b535377e0f457b51c70c13ae08609 /payloads/libpayload/drivers | |
parent | d772e1e7feb3d782564fe7f46374d4ae8a5f4c36 (diff) |
libpayload: Add gettimeofday() and friends
Add a gettimeofday() implementation - it works pretty well, but it
drifts a little bit so its not very suitable for keeping time. It
works best to track changes in time over small periods of time.
Signed-off-by: Jordan Crouse <jordan.crouse@amd.com>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3272 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads/libpayload/drivers')
-rw-r--r-- | payloads/libpayload/drivers/nvram.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/payloads/libpayload/drivers/nvram.c b/payloads/libpayload/drivers/nvram.c index 9196d80b86..b28de92b78 100644 --- a/payloads/libpayload/drivers/nvram.c +++ b/payloads/libpayload/drivers/nvram.c @@ -93,3 +93,43 @@ void nvram_write(u8 val, u8 addr) outb(addr, rtc_port); outb(val, rtc_port + 1); } + +/** + * Return 1 if the NVRAM is currently updating and a 0 otherwise + * @return A 1 if the NVRAM is updating and 0 otherwise + */ + +int nvram_updating(void) +{ + return (nvram_read(NVRAM_RTC_FREQ_SELECT) & NVRAM_RTC_UIP) ? 1 : 0; +} + +/** + * Get the current time and date from the RTC + * + * @param time A pointer to a broken-down time structure + */ +void rtc_read_clock(struct tm *time) +{ + memset(time, 0, sizeof(*time)); + + while(nvram_updating()); + + time->tm_mon = bcd2dec(nvram_read(NVRAM_RTC_MONTH)) - 1; + time->tm_sec = bcd2dec(nvram_read(NVRAM_RTC_SECONDS)); + time->tm_min = bcd2dec(nvram_read(NVRAM_RTC_MINUTES)); + time->tm_mday = bcd2dec(nvram_read(NVRAM_RTC_DAY)); + time->tm_hour = bcd2dec(nvram_read(NVRAM_RTC_HOURS)); + + /* Instead of finding the century register, + we just make an assumption that if the year value is + less then 80, then it is 2000+ + */ + + time->tm_year = bcd2dec(nvram_read(NVRAM_RTC_YEAR)); + + if (time->tm_year < 80) + time->tm_year += 100; +} + + |