Merge branch 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[~shefty/rdma-dev.git] / arch / x86 / platform / efi / efi.c
index 012b3f6a9bd692f1af5a9258e47ca70b9a486ec4..6b85db0a7ccc3a9070ab4eeafce2db2abd58c08e 100644 (file)
@@ -49,6 +49,7 @@
 #include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
 #include <asm/x86_init.h>
+#include <asm/rtc.h>
 
 #define EFI_DEBUG      1
 
@@ -352,10 +353,10 @@ static efi_status_t __init phys_efi_get_time(efi_time_t *tm,
 
 int efi_set_rtc_mmss(unsigned long nowtime)
 {
-       int real_seconds, real_minutes;
        efi_status_t    status;
        efi_time_t      eft;
        efi_time_cap_t  cap;
+       struct rtc_time tm;
 
        status = efi.get_time(&eft, &cap);
        if (status != EFI_SUCCESS) {
@@ -363,13 +364,20 @@ int efi_set_rtc_mmss(unsigned long nowtime)
                return -1;
        }
 
-       real_seconds = nowtime % 60;
-       real_minutes = nowtime / 60;
-       if (((abs(real_minutes - eft.minute) + 15)/30) & 1)
-               real_minutes += 30;
-       real_minutes %= 60;
-       eft.minute = real_minutes;
-       eft.second = real_seconds;
+       rtc_time_to_tm(nowtime, &tm);
+       if (!rtc_valid_tm(&tm)) {
+               eft.year = tm.tm_year + 1900;
+               eft.month = tm.tm_mon + 1;
+               eft.day = tm.tm_mday;
+               eft.minute = tm.tm_min;
+               eft.second = tm.tm_sec;
+               eft.nanosecond = 0;
+       } else {
+               printk(KERN_ERR
+                      "%s: Invalid EFI RTC value: write of %lx to EFI RTC failed\n",
+                      __FUNCTION__, nowtime);
+               return -1;
+       }
 
        status = efi.set_time(&eft);
        if (status != EFI_SUCCESS) {