static int sprd_rtc_read_time(struct device *dev, struct rtc_time *tm) { unsigned long secs = sprd_rtc_get_sec(); int n =2; if(secs > 0x7f000000){ while(sprd_rtc_set_sec(0)!=0&&(n--)>0); secs = 0; } secs = secs + secs_start_year_to_1970; if(secs > 0x7f000000){ secs = secs_start_year_to_1970; n =2; while(sprd_rtc_set_sec(0)!=0&&(n--)>0); } #if(CONFIG_RTC_START_YEAR==1999) if(secs < RTC_START_YEAR_2000) { secs = RTC_START_YEAR_2012; sprd_rtc_set_sec(secs - secs_start_year_to_1970); } #endif rtc_time_to_tm(secs, tm); return 0; }
int alarm_flag_check(void) { int ret = -1,ret1 = -1; long time = 0; long time1 = 0; unsigned long time_rtc= 0; unsigned long time_rtc1= 0; unsigned long now_rtc = 0; int time_lead = 0; ret = alarm_file_check(time_buf); if(ret > 0){ printf("file: alarm_flag exist\n"); printf("time get %s", time_buf); time = simple_strtol(time_buf, NULL, 10); time_rtc = time; } ret1 = poweron_file_check(time_buf1); if(ret1 > 0){ printf("file: poweron_timeinmillis exist\n"); printf("time get %s", time_buf1); time1 = simple_strtol(time_buf1, NULL, 10); time_rtc1 = time1; } sprd_rtc_init(); now_rtc = sprd_rtc_get_sec(); printf("now rtc %lu\n", now_rtc); time_lead = get_alarm_lead_set(); time = time - now_rtc; time1 = time1 - now_rtc; if((time < time_lead +180) && (time > time_lead -10)) { if((time1 < time_lead +180) && (time1 > time_lead -10)&& (time -time1>50)) ret = 2; else ret = 1; } else if((time1 < time_lead +180) && (time1 > time_lead -10)) ret =2; else{ if (ret == -1&& ret1== -1) { printf("file: all not found\n"); }else if(ret1== -1){ uboot_rtc_set_alarm_sec(time_rtc); }else if(ret== -1){ uboot_rtc_set_alarm_sec(time_rtc1); }else{ if(time_rtc1 > time_rtc){ uboot_rtc_set_alarm_sec(time_rtc); }else{ uboot_rtc_set_alarm_sec(time_rtc1); } } ret = 0; } return ret; }
int sprd_clean_rtc(void) { int err; ANA_REG_AND(ANA_RTC_INT_EN, ~(RTC_INT_ALL_MSK)); // disable all interrupt ANA_REG_OR(ANA_APB_CLK_EN, AGEN_RTC_EN | AGEN_RTC_RTC_EN); //enable rtc device CLEAR_RTC_INT(RTC_INT_ALL_MSK); sprd_rtc_set_sec(0); sprd_rtc_set_alarm_sec(0); printf("now time sec %lu\n", sprd_rtc_get_sec()); printf("now alarm sec %lu\n", sprd_rtc_get_alarm_sec()); return 0; }
static int sprd_rtc_read_time(struct device *dev, struct rtc_time *tm) { unsigned long secs = sprd_rtc_get_sec(); int n =2; if(secs > 0x7f000000){ while(sprd_rtc_set_sec(0)!=0&&(n--)>0); secs = 0; } secs = secs + secs_start_year_to_1970; if(secs > 0x7f000000){ secs = secs_start_year_to_1970; n =2; while(sprd_rtc_set_sec(0)!=0&&(n--)>0); } rtc_time_to_tm(secs, tm); return 0; }