1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <common.h>
24#include <rtc.h>
25#include <spi.h>
26#include <pmic.h>
27#include <fsl_pmic.h>
28
29int rtc_get(struct rtc_time *rtc)
30{
31 u32 day1, day2, time;
32 int tim, i = 0;
33 struct pmic *p = get_pmic();
34 int ret;
35
36 do {
37 ret = pmic_reg_read(p, REG_RTC_DAY, &day1);
38 if (ret < 0)
39 return -1;
40
41 ret = pmic_reg_read(p, REG_RTC_TIME, &time);
42 if (ret < 0)
43 return -1;
44
45 ret = pmic_reg_read(p, REG_RTC_DAY, &day2);
46 if (ret < 0)
47 return -1;
48
49 } while (day1 != day2 && i++ < 3);
50
51 tim = day1 * 86400 + time;
52
53 to_tm(tim, rtc);
54
55 rtc->tm_yday = 0;
56 rtc->tm_isdst = 0;
57
58 return 0;
59}
60
61int rtc_set(struct rtc_time *rtc)
62{
63 u32 time, day;
64 struct pmic *p = get_pmic();
65
66 time = mktime(rtc->tm_year, rtc->tm_mon, rtc->tm_mday,
67 rtc->tm_hour, rtc->tm_min, rtc->tm_sec);
68 day = time / 86400;
69 time %= 86400;
70
71 pmic_reg_write(p, REG_RTC_DAY, day);
72 pmic_reg_write(p, REG_RTC_TIME, time);
73
74 return 0;
75}
76
77void rtc_reset(void)
78{
79}
80