1 // SPDX-License-Identifier: GPL-2.0+
4 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
5 * (C) Copyright 2018 Robert Bosch Power Tools GmbH.
7 * A bootcount driver for the RTC IP block found on many TI platforms.
8 * This requires the RTC clocks, etc, to be enabled prior to use and
9 * not all boards with this IP block on it will have the RTC in use.
12 #include <bootcount.h>
13 #include <asm/davinci_rtc.h>
17 void bootcount_store(ulong bootcount)
19 u8 upgrade_available = 0;
21 struct davinci_rtc *reg =
22 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
24 val = raw_bootcount_load(®->scratch2);
25 upgrade_available = (val >> 8) & 0x000000ff;
27 /* Only update bootcount during upgrade process */
28 if (!upgrade_available)
31 val = (bootcount & 0x000000ff) |
32 (upgrade_available << 8) |
34 (CONFIG_SYS_BOOTCOUNT_MAGIC << 24);
37 * write RTC kick registers to enable write
38 * for RTC Scratch registers. Scratch register 2 is
39 * used for bootcount value.
41 writel(RTC_KICK0R_WE, ®->kick0r);
42 writel(RTC_KICK1R_WE, ®->kick1r);
43 raw_bootcount_store(®->scratch2, val);
46 ulong bootcount_load(void)
48 unsigned long val = 0;
49 struct davinci_rtc *reg =
50 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
52 val = raw_bootcount_load(®->scratch2);
53 if ((val >> 24) != CONFIG_SYS_BOOTCOUNT_MAGIC)
56 return val & 0x000000ff;