]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/bootcount/bootcount_davinci.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[thirdparty/u-boot.git] / drivers / bootcount / bootcount_davinci.c
CommitLineData
0044c42e
SR
1/*
2 * (C) Copyright 2011
3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
0044c42e
SR
6 */
7
8#include <bootcount.h>
9#include <asm/arch/da850_lowlevel.h>
10#include <asm/arch/davinci_misc.h>
11
12void bootcount_store(ulong a)
13{
14 struct davinci_rtc *reg =
15 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
16
17 /*
18 * write RTC kick register to enable write
19 * for RTC Scratch registers. Scratch0 and 1 are
20 * used for bootcount values.
21 */
22 writel(RTC_KICK0R_WE, &reg->kick0r);
23 writel(RTC_KICK1R_WE, &reg->kick1r);
24 raw_bootcount_store(&reg->scratch0, a);
25 raw_bootcount_store(&reg->scratch1, BOOTCOUNT_MAGIC);
26}
27
28ulong bootcount_load(void)
29{
30 struct davinci_rtc *reg =
31 (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
32
33 if (raw_bootcount_load(&reg->scratch1) != BOOTCOUNT_MAGIC)
34 return 0;
35 else
36 return raw_bootcount_load(&reg->scratch0);
37}