From a81391b62330e18c82ecb8b277528828d7e0e516 Mon Sep 17 00:00:00 2001 From: Marcin Bukat Date: Tue, 10 Apr 2018 22:49:09 +0200 Subject: Agptek Rocker: Fix saving time in hwclock Rocker is configured with CST (China Standard Time) timezone which is UTC+8. Time in RTC is stored in UTC. Change-Id: Ib9c03e0f0a1d3ea3a69f238cb083809ea9386e2a --- firmware/target/hosted/rtc.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'firmware/target/hosted') diff --git a/firmware/target/hosted/rtc.c b/firmware/target/hosted/rtc.c index cb11d3ca3c..c1a3f3cbcc 100644 --- a/firmware/target/hosted/rtc.c +++ b/firmware/target/hosted/rtc.c @@ -22,6 +22,10 @@ ****************************************************************************/ #include #include +#include +#include +#include +#include void rtc_init(void) { @@ -37,10 +41,27 @@ int rtc_read_datetime(struct tm *tm) int rtc_write_datetime(const struct tm *tm) { +#if defined(AGPTEK_ROCKER) struct timeval tv; + struct tm *tm_time; + + int rtc = open("/dev/rtc0", O_WRONLY); tv.tv_sec = mktime((struct tm *)tm); tv.tv_usec = 0; - return settimeofday(&tv, NULL); + /* set system clock */ + settimeofday(&tv, NULL); + + /* hw clock stores time in UTC */ + time_t now = time(NULL); + tm_time = gmtime(&now); + + ioctl(rtc, RTC_SET_TIME, (struct rtc_time *)tm_time); + close(rtc); + + return 0; +#else + return -1; +#endif } -- cgit