xref: /rk3399_rockchip-uboot/drivers/bootcount/bootcount_davinci.c (revision 155d424a9a0228e2f38ce21a92b20c31896d61d2)
10044c42eSStefan Roese /*
20044c42eSStefan Roese  * (C) Copyright 2011
30044c42eSStefan Roese  * Heiko Schocher, DENX Software Engineering, hs@denx.de.
40044c42eSStefan Roese  *
51a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
60044c42eSStefan Roese  */
70044c42eSStefan Roese 
80044c42eSStefan Roese #include <bootcount.h>
9*155d424aSTom Rini #include <asm/davinci_rtc.h>
100044c42eSStefan Roese 
110044c42eSStefan Roese void bootcount_store(ulong a)
120044c42eSStefan Roese {
130044c42eSStefan Roese 	struct davinci_rtc *reg =
140044c42eSStefan Roese 		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
150044c42eSStefan Roese 
160044c42eSStefan Roese 	/*
170044c42eSStefan Roese 	 * write RTC kick register to enable write
180044c42eSStefan Roese 	 * for RTC Scratch registers. Scratch0 and 1 are
190044c42eSStefan Roese 	 * used for bootcount values.
200044c42eSStefan Roese 	 */
210044c42eSStefan Roese 	writel(RTC_KICK0R_WE, &reg->kick0r);
220044c42eSStefan Roese 	writel(RTC_KICK1R_WE, &reg->kick1r);
230044c42eSStefan Roese 	raw_bootcount_store(&reg->scratch0, a);
240044c42eSStefan Roese 	raw_bootcount_store(&reg->scratch1, BOOTCOUNT_MAGIC);
250044c42eSStefan Roese }
260044c42eSStefan Roese 
270044c42eSStefan Roese ulong bootcount_load(void)
280044c42eSStefan Roese {
290044c42eSStefan Roese 	struct davinci_rtc *reg =
300044c42eSStefan Roese 		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
310044c42eSStefan Roese 
320044c42eSStefan Roese 	if (raw_bootcount_load(&reg->scratch1) != BOOTCOUNT_MAGIC)
330044c42eSStefan Roese 		return 0;
340044c42eSStefan Roese 	else
350044c42eSStefan Roese 		return raw_bootcount_load(&reg->scratch0);
360044c42eSStefan Roese }
37