xref: /rk3399_rockchip-uboot/drivers/bootcount/bootcount_davinci.c (revision 0044c42e94ecc258728190919b4619508fb83089)
1*0044c42eSStefan Roese /*
2*0044c42eSStefan Roese  * (C) Copyright 2011
3*0044c42eSStefan Roese  * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4*0044c42eSStefan Roese  *
5*0044c42eSStefan Roese  * See file CREDITS for list of people who contributed to this
6*0044c42eSStefan Roese  * project.
7*0044c42eSStefan Roese  *
8*0044c42eSStefan Roese  * This program is free software; you can redistribute it and/or
9*0044c42eSStefan Roese  * modify it under the terms of the GNU General Public License as
10*0044c42eSStefan Roese  * published by the Free Software Foundation; either version 2 of
11*0044c42eSStefan Roese  * the License, or (at your option) any later version.
12*0044c42eSStefan Roese  *
13*0044c42eSStefan Roese  * This program is distributed in the hope that it will be useful,
14*0044c42eSStefan Roese  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15*0044c42eSStefan Roese  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*0044c42eSStefan Roese  * GNU General Public License for more details.
17*0044c42eSStefan Roese  *
18*0044c42eSStefan Roese  */
19*0044c42eSStefan Roese 
20*0044c42eSStefan Roese #include <bootcount.h>
21*0044c42eSStefan Roese #include <asm/arch/da850_lowlevel.h>
22*0044c42eSStefan Roese #include <asm/arch/davinci_misc.h>
23*0044c42eSStefan Roese 
24*0044c42eSStefan Roese void bootcount_store(ulong a)
25*0044c42eSStefan Roese {
26*0044c42eSStefan Roese 	struct davinci_rtc *reg =
27*0044c42eSStefan Roese 		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
28*0044c42eSStefan Roese 
29*0044c42eSStefan Roese 	/*
30*0044c42eSStefan Roese 	 * write RTC kick register to enable write
31*0044c42eSStefan Roese 	 * for RTC Scratch registers. Scratch0 and 1 are
32*0044c42eSStefan Roese 	 * used for bootcount values.
33*0044c42eSStefan Roese 	 */
34*0044c42eSStefan Roese 	writel(RTC_KICK0R_WE, &reg->kick0r);
35*0044c42eSStefan Roese 	writel(RTC_KICK1R_WE, &reg->kick1r);
36*0044c42eSStefan Roese 	raw_bootcount_store(&reg->scratch0, a);
37*0044c42eSStefan Roese 	raw_bootcount_store(&reg->scratch1, BOOTCOUNT_MAGIC);
38*0044c42eSStefan Roese }
39*0044c42eSStefan Roese 
40*0044c42eSStefan Roese ulong bootcount_load(void)
41*0044c42eSStefan Roese {
42*0044c42eSStefan Roese 	struct davinci_rtc *reg =
43*0044c42eSStefan Roese 		(struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
44*0044c42eSStefan Roese 
45*0044c42eSStefan Roese 	if (raw_bootcount_load(&reg->scratch1) != BOOTCOUNT_MAGIC)
46*0044c42eSStefan Roese 		return 0;
47*0044c42eSStefan Roese 	else
48*0044c42eSStefan Roese 		return raw_bootcount_load(&reg->scratch0);
49*0044c42eSStefan Roese }
50