[Skiboot] [PATCH] mambo: add a mambo rtc_write

Nicholas Piggin npiggin at gmail.com
Tue Dec 22 03:08:37 AEDT 2020


This just keeps the requested delta and uses it to adjust subsequent
rtc_read calls.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 platforms/mambo/mambo.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/platforms/mambo/mambo.c b/platforms/mambo/mambo.c
index 0c96100ed..a1e0488c8 100644
--- a/platforms/mambo/mambo.c
+++ b/platforms/mambo/mambo.c
@@ -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)
-- 
2.23.0



More information about the Skiboot mailing list