2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-11-08 15:59:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 General Electric Company
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2020-01-31 13:07:54 +00:00
|
|
|
#include <dm/uclass.h>
|
2017-11-08 15:59:35 +00:00
|
|
|
#include <rtc.h>
|
|
|
|
|
|
|
|
void check_time(void)
|
|
|
|
{
|
2020-01-31 13:07:54 +00:00
|
|
|
struct udevice *dev;
|
2017-11-08 15:59:35 +00:00
|
|
|
int ret, i;
|
|
|
|
struct rtc_time tm;
|
|
|
|
u8 retry = 3;
|
|
|
|
|
2020-01-31 13:07:54 +00:00
|
|
|
ret = uclass_get_device(UCLASS_RTC, 0, &dev);
|
|
|
|
if (ret) {
|
2019-11-12 19:15:18 +00:00
|
|
|
env_set("rtc_status", "FAIL");
|
2017-11-08 15:59:35 +00:00
|
|
|
return;
|
2019-11-12 19:15:18 +00:00
|
|
|
}
|
2017-11-08 15:59:35 +00:00
|
|
|
|
|
|
|
for (i = 0; i < retry; i++) {
|
2020-01-31 13:07:54 +00:00
|
|
|
ret = dm_rtc_get(dev, &tm);
|
2017-11-08 15:59:35 +00:00
|
|
|
if (!ret || ret == -EINVAL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-12 19:15:18 +00:00
|
|
|
if (!ret && tm.tm_year > 2037) {
|
2017-11-08 15:59:35 +00:00
|
|
|
tm.tm_sec = 0;
|
|
|
|
tm.tm_min = 0;
|
|
|
|
tm.tm_hour = 0;
|
|
|
|
tm.tm_mday = 1;
|
|
|
|
tm.tm_wday = 2;
|
|
|
|
tm.tm_mon = 1;
|
|
|
|
tm.tm_year = 2036;
|
|
|
|
|
|
|
|
for (i = 0; i < retry; i++) {
|
2020-01-31 13:07:54 +00:00
|
|
|
ret = dm_rtc_set(dev, &tm);
|
2017-11-08 15:59:35 +00:00
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-12 19:15:18 +00:00
|
|
|
if (ret >= 0)
|
|
|
|
ret = 2038;
|
2017-11-08 15:59:35 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 19:15:18 +00:00
|
|
|
if (ret < 0)
|
|
|
|
env_set("rtc_status", "FAIL");
|
|
|
|
else if (ret == 2038)
|
|
|
|
env_set("rtc_status", "2038");
|
|
|
|
else
|
|
|
|
env_set("rtc_status", "OK");
|
2017-11-08 15:59:35 +00:00
|
|
|
}
|