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