3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 * A bootcount driver for the RTC IP block found on many TI platforms.
6 * This requires the RTC clocks, etc, to be enabled prior to use and
7 * not all boards with this IP block on it will have the RTC in use.
9 * SPDX-License-Identifier: GPL-2.0+
12 #include <bootcount.h>
13 #include <asm/davinci_rtc.h>
15 void bootcount_store(ulong a)
17 struct davinci_rtc *reg =
18 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
21 * write RTC kick register to enable write
22 * for RTC Scratch registers. Scratch0 and 1 are
23 * used for bootcount values.
25 writel(RTC_KICK0R_WE, ®->kick0r);
26 writel(RTC_KICK1R_WE, ®->kick1r);
27 raw_bootcount_store(®->scratch2,
28 (BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff));
31 ulong bootcount_load(void)
34 struct davinci_rtc *reg =
35 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
37 val = raw_bootcount_load(®->scratch2);
38 if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
41 return val & 0x0000ffff;