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