static int sandbox_i2c_rtc_set(struct udevice *dev, const 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; } plat->offset = rtc_mktime(time) - now; 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); }
static void reset_time(struct udevice *dev) { struct sandbox_i2c_rtc_plat_data *plat = dev_get_platdata(dev); struct rtc_time now; os_localtime(&now); plat->base_time = rtc_mktime(&now); plat->offset = 0; plat->use_system_time = true; }
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_set(struct rtc_time *rtc) { u32 time, day; struct pmic *p = pmic_get("FSL_PMIC"); if (!p) return -1; time = rtc_mktime(rtc); day = time / 86400; time %= 86400; pmic_reg_write(p, REG_RTC_DAY, day); pmic_reg_write(p, REG_RTC_TIME, time); return 0; }
int rtc_set (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; tim = rtc_mktime(tmp); /* clear alarm, set prescaler to 32768, clear counter */ writel(32768+AT91_RTT_RTTRST, &rtt->mr); writel(~0, &rtt->ar); writel(tim, &gpbr->reg[AT91_GPBR_INDEX_TIMEOFF]); /* wait for counter clear to happen, takes less than a 1/32768th second */ while (readl(&rtt->vr) != 0) ; return 0; }
/* * Set the RTC */ static int pl031_set(struct udevice *dev, const struct rtc_time *tm) { unsigned long tim; if (!tm) return -EINVAL; debug("Set 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); /* Calculate number of seconds this incoming time represents */ tim = rtc_mktime(tm); pl031_write_reg(dev, RTC_LR, tim); return 0; }
/* * Set the RTC */ int rtc_set(struct rtc_time *tmp) { unsigned long tim; if(!pl031_initted) rtc_init(); if (tmp == NULL) { puts("Error setting the date/time\n"); return -1; } /* Calculate number of seconds this incoming time represents */ tim = rtc_mktime(tmp); RTC_WRITE_REG(RTC_LR, tim); return -1; }
int rtc_set(struct rtc_time *tmp) { unsigned long now; int rc; if (!data.init_done) { rc = di_init(); if (rc) goto err; } now = rtc_mktime(tmp); /* zero the fractional part first */ rc = DI_WRITE_WAIT(0, dtclr); if (rc == 0) rc = DI_WRITE_WAIT(now, dtcmr); err: return rc; }
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; }