summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2018-04-10 22:49:09 +0200
committerMarcin Bukat <marcin.bukat@gmail.com>2018-06-12 10:31:16 +0200
commita81391b62330e18c82ecb8b277528828d7e0e516 (patch)
tree1c38a033eeb7a257cadb3c42942a4365d491d76c
parent1af78b99d90629cfc90805b18270afaa486ddb50 (diff)
downloadrockbox-a81391b62330e18c82ecb8b277528828d7e0e516.tar.gz
rockbox-a81391b62330e18c82ecb8b277528828d7e0e516.zip
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
-rw-r--r--firmware/target/hosted/rtc.c23
1 files changed, 22 insertions, 1 deletions
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 @@
22 ****************************************************************************/ 22 ****************************************************************************/
23#include <time.h> 23#include <time.h>
24#include <sys/time.h> 24#include <sys/time.h>
25#include <sys/ioctl.h>
26#include <linux/rtc.h>
27#include <fcntl.h>
28#include <unistd.h>
25 29
26void rtc_init(void) 30void rtc_init(void)
27{ 31{
@@ -37,10 +41,27 @@ int rtc_read_datetime(struct tm *tm)
37 41
38int rtc_write_datetime(const struct tm *tm) 42int rtc_write_datetime(const struct tm *tm)
39{ 43{
44#if defined(AGPTEK_ROCKER)
40 struct timeval tv; 45 struct timeval tv;
46 struct tm *tm_time;
47
48 int rtc = open("/dev/rtc0", O_WRONLY);
41 49
42 tv.tv_sec = mktime((struct tm *)tm); 50 tv.tv_sec = mktime((struct tm *)tm);
43 tv.tv_usec = 0; 51 tv.tv_usec = 0;
44 52
45 return settimeofday(&tv, NULL); 53 /* set system clock */
54 settimeofday(&tv, NULL);
55
56 /* hw clock stores time in UTC */
57 time_t now = time(NULL);
58 tm_time = gmtime(&now);
59
60 ioctl(rtc, RTC_SET_TIME, (struct rtc_time *)tm_time);
61 close(rtc);
62
63 return 0;
64#else
65 return -1;
66#endif
46} 67}