blob: eddd9400055fc47bca9512ae695311b9beddbae0 [file] [log] [blame]
Stefan Roese0044c422012-08-16 17:55:41 +00001/*
2 * (C) Copyright 2011
3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese0044c422012-08-16 17:55:41 +00006 */
7
8#include <bootcount.h>
Tom Rini155d4242013-08-28 09:00:28 -04009#include <asm/davinci_rtc.h>
Stefan Roese0044c422012-08-16 17:55:41 +000010
11void bootcount_store(ulong a)
12{
13 struct davinci_rtc *reg =
14 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
15
16 /*
17 * write RTC kick register to enable write
18 * for RTC Scratch registers. Scratch0 and 1 are
19 * used for bootcount values.
20 */
21 writel(RTC_KICK0R_WE, &reg->kick0r);
22 writel(RTC_KICK1R_WE, &reg->kick1r);
23 raw_bootcount_store(&reg->scratch0, a);
24 raw_bootcount_store(&reg->scratch1, BOOTCOUNT_MAGIC);
25}
26
27ulong bootcount_load(void)
28{
29 struct davinci_rtc *reg =
30 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
31
32 if (raw_bootcount_load(&reg->scratch1) != BOOTCOUNT_MAGIC)
33 return 0;
34 else
35 return raw_bootcount_load(&reg->scratch0);
36}