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 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 = mktime(rtc->tm_year, rtc->tm_mon, rtc->tm_mday, 55 rtc->tm_hour, rtc->tm_min, rtc->tm_sec); 56 day = time / 86400; 57 time %= 86400; 58 59 pmic_reg_write(p, REG_RTC_DAY, day); 60 pmic_reg_write(p, REG_RTC_TIME, time); 61 62 return 0; 63 } 64 65 void rtc_reset(void) 66 { 67 } 68