int rtc_get(struct rtc_time *rtc) { u32 day1, day2, time; int tim, i = 0; struct pmic *p = pmic_get("FSL_PMIC"); int ret; if (!p) return -1; do { ret = pmic_reg_read(p, REG_RTC_DAY, &day1); if (ret < 0) return -1; ret = pmic_reg_read(p, REG_RTC_TIME, &time); if (ret < 0) return -1; ret = pmic_reg_read(p, REG_RTC_DAY, &day2); if (ret < 0) return -1; } while (day1 != day2 && i++ < 3); tim = day1 * 86400 + time; rtc_to_tm(tim, rtc); rtc->tm_yday = 0; rtc->tm_isdst = 0; return 0; }
static void rtc_post_restore (struct rtc_time *tm, unsigned int sec) { time_t t = rtc_mktime(tm) + sec; struct rtc_time ntm; rtc_to_tm(t, &ntm); rtc_set (&ntm); }
void genimg_print_time(time_t timestamp) { #ifndef USE_HOSTCC struct rtc_time tm; rtc_to_tm(timestamp, &tm); printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); #else printf("%s", ctime(×tamp)); #endif }
static int sandbox_i2c_rtc_get(struct udevice *dev, struct rtc_time *time) { struct sandbox_i2c_rtc_plat_data *plat = dev_get_platdata(dev); struct rtc_time tm_now; long now; if (plat->use_system_time) { os_localtime(&tm_now); now = rtc_mktime(&tm_now); } else { now = plat->base_time; } return rtc_to_tm(now + plat->offset, time); }
int rtc_get(struct rtc_time *tmp) { unsigned long now; int rc = 0; if (!data.init_done) { rc = di_init(); if (rc) goto err; } now = __raw_readl(&data.regs->dtcmr); rtc_to_tm(now, tmp); err: return rc; }
int rtc_get(struct rtc_time *time) { struct chromeec_command cmd; struct ec_response_rtc r; cmd.cmd_code = EC_CMD_RTC_GET_VALUE; cmd.cmd_version = 0; cmd.cmd_size_in = 0; cmd.cmd_data_out = &r; cmd.cmd_size_out = sizeof(r); cmd.cmd_dev_index = 0; if (google_chromeec_command(&cmd) != 0) return -1; return rtc_to_tm(r.time, time); }
/* * Get the current time from the RTC */ static int pl031_get(struct udevice *dev, struct rtc_time *tm) { unsigned long tim; if (!tm) return -EINVAL; tim = pl031_read_reg(dev, RTC_DR); rtc_to_tm(tim, tm); debug("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec); return 0; }
int rtc_get (struct rtc_time *tmp) { at91_rtt_t *rtt = (at91_rtt_t *) ATMEL_BASE_RTT; at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR; ulong tim; ulong tim2; ulong off; do { tim = readl(&rtt->vr); tim2 = readl(&rtt->vr); } while (tim!=tim2); off = readl(&gpbr->reg[AT91_GPBR_INDEX_TIMEOFF]); /* off==0 means time is invalid, but we ignore that */ rtc_to_tm(tim+off, tmp); return 0; }
/* * Get the current time from the RTC */ int rtc_get(struct rtc_time *tmp) { ulong tim; if(!pl031_initted) rtc_init(); if (tmp == NULL) { puts("Error getting the date/time\n"); return -1; } tim = RTC_READ_REG(RTC_DR); rtc_to_tm(tim, tmp); debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); return 0; }
int rtc_post_test (int flags) { ulong diff; unsigned int i; struct rtc_time svtm; static unsigned int daysnl[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static unsigned int daysl[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; unsigned int ynl = 1999; unsigned int yl = 2000; unsigned int skipped = 0; int reliable; /* Time reliability */ reliable = rtc_get (&svtm); /* Time uniformity */ if (rtc_post_skip (&diff) != 0) { post_log ("Timeout while waiting for a new second !\n"); return -1; } for (i = 0; i < 5; i++) { if (rtc_post_skip (&diff) != 0) { post_log ("Timeout while waiting for a new second !\n"); return -1; } if (diff < 950 || diff > 1050) { post_log ("Invalid second duration !\n"); return -1; } } /* Passing month boundaries */ if (rtc_post_skip (&diff) != 0) { post_log ("Timeout while waiting for a new second !\n"); return -1; } rtc_get (&svtm); for (i = 0; i < 12; i++) { time_t t; struct rtc_time tm; tm.tm_year = ynl; tm.tm_mon = i + 1; tm.tm_mday = daysnl[i]; tm.tm_hour = 23; tm.tm_min = 59; tm.tm_sec = 59; t = rtc_mktime(&tm); rtc_to_tm(t, &tm); rtc_set (&tm); skipped++; if (rtc_post_skip (&diff) != 0) { rtc_post_restore (&svtm, skipped); post_log ("Timeout while waiting for a new second !\n"); return -1; } rtc_get (&tm); if (tm.tm_mon == i + 1) { rtc_post_restore (&svtm, skipped); post_log ("Month %d boundary is not passed !\n", i + 1); return -1; } } for (i = 0; i < 12; i++) { time_t t; struct rtc_time tm; tm.tm_year = yl; tm.tm_mon = i + 1; tm.tm_mday = daysl[i]; tm.tm_hour = 23; tm.tm_min = 59; tm.tm_sec = 59; t = rtc_mktime(&tm); rtc_to_tm(t, &tm); rtc_set (&tm); skipped++; if (rtc_post_skip (&diff) != 0) { rtc_post_restore (&svtm, skipped); post_log ("Timeout while waiting for a new second !\n"); return -1; } rtc_get (&tm); if (tm.tm_mon == i + 1) { rtc_post_restore (&svtm, skipped); post_log ("Month %d boundary is not passed !\n", i + 1); return -1; } } rtc_post_restore (&svtm, skipped); /* If come here, then RTC operates correcty, check the correctness * of the time it reports. */ if (reliable < 0) { post_log ("RTC Time is not reliable! Power fault? \n"); return -1; } return 0; }