diff mbox series

mambo: add a mambo rtc_write

Message ID 20201221160837.943881-1-npiggin@gmail.com
State Accepted
Headers show
Series mambo: add a mambo rtc_write | expand

Commit Message

Nicholas Piggin Dec. 21, 2020, 4:08 p.m. UTC
This just keeps the requested delta and uses it to adjust subsequent
rtc_read calls.

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

Comments

Vasant Hegde Jan. 5, 2021, 9:13 a.m. UTC | #1
On 12/21/20 9:38 PM, Nicholas Piggin wrote:
> This just keeps the requested delta and uses it to adjust subsequent
> rtc_read calls.
> 

Thanks! Merged to master as 0f2c57df.

-Vasant
diff mbox series

Patch

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)