mambo: add a mambo rtc_write
This just keeps the requested delta and uses it to adjust subsequent
rtc_read calls.
@@ -173,6 +173,8 @@ static void bogus_disk_flash_init(void)
}
}
+static int64_t time_delta = 0;
+
static int64_t mambo_rtc_read(__be32 *ymd, __be64 *hmsm)
{
int64_t mambo_time;
@@ -186,6 +188,7 @@ static int64_t mambo_rtc_read(__be32 *ymd, __be64 *hmsm)
mambo_time = callthru0(SIM_GET_TIME_CODE);
mt = mambo_time >> 32;
+ mt += time_delta;
gmtime_r(&mt, &t);
tm_to_datetime(&t, &__ymd, &__hmsm);
@@ -195,12 +198,30 @@ static int64_t mambo_rtc_read(__be32 *ymd, __be64 *hmsm)
return OPAL_SUCCESS;
}
+static int64_t mambo_rtc_write(uint32_t ymd, uint64_t hmsm)
+{
+ int64_t mambo_time;
+ struct tm tm;
+ time_t mt, new_mt;
+
+ mambo_time = callthru0(SIM_GET_TIME_CODE);
+ mt = mambo_time >> 32;
+
+ datetime_to_tm(ymd, hmsm, &tm);
+ new_mt = mktime(&tm);
+
+ time_delta = new_mt - mt;
+
+ return OPAL_SUCCESS;
+}
+
static void mambo_rtc_init(void)
{
struct dt_node *np = dt_new(opal_node, "rtc");
dt_add_property_strings(np, "compatible", "ibm,opal-rtc");
opal_register(OPAL_RTC_READ, mambo_rtc_read, 2);
+ opal_register(OPAL_RTC_WRITE, mambo_rtc_write, 2);
}
static void mambo_system_reset_cpu(struct cpu_thread *cpu)
