From 647155bcd549edae57f027e08add4c9ac090f05e Mon Sep 17 00:00:00 2001 From: Martyn Welch Date: Wed, 8 Nov 2017 15:59:35 +0000 Subject: board: ge: mx53ppd: Move check_time() to common location We are going to be using check_time() on more than the mx53ppd, move this function to a common location. Signed-off-by: Martyn Welch --- board/ge/common/Makefile | 2 +- board/ge/common/ge_common.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ board/ge/common/ge_common.h | 7 ++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 board/ge/common/ge_common.c create mode 100644 board/ge/common/ge_common.h (limited to 'board/ge/common') diff --git a/board/ge/common/Makefile b/board/ge/common/Makefile index 93e6c0182b..f5be11bcef 100644 --- a/board/ge/common/Makefile +++ b/board/ge/common/Makefile @@ -4,4 +4,4 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-y := vpd_reader.o +obj-y := vpd_reader.o ge_common.o diff --git a/board/ge/common/ge_common.c b/board/ge/common/ge_common.c new file mode 100644 index 0000000000..c8260960cf --- /dev/null +++ b/board/ge/common/ge_common.c @@ -0,0 +1,55 @@ +/* + * Copyright 2017 General Electric Company + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +void check_time(void) +{ + int ret, i; + struct rtc_time tm; + u8 retry = 3; + + unsigned int current_i2c_bus = i2c_get_bus_num(); + + ret = i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM); + if (ret < 0) + return; + + rtc_init(); + + for (i = 0; i < retry; i++) { + ret = rtc_get(&tm); + if (!ret || ret == -EINVAL) + break; + } + + if (ret < 0) + env_set("rtc_status", "RTC_ERROR"); + + if (tm.tm_year > 2037) { + 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++) { + ret = rtc_set(&tm); + if (!ret) + break; + } + + if (ret < 0) + env_set("rtc_status", "RTC_ERROR"); + } + + i2c_set_bus_num(current_i2c_bus); +} + diff --git a/board/ge/common/ge_common.h b/board/ge/common/ge_common.h new file mode 100644 index 0000000000..b28aada8dd --- /dev/null +++ b/board/ge/common/ge_common.h @@ -0,0 +1,7 @@ +/* + * Copyright 2017 General Electric Company + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +void check_time(void); -- cgit