1 /*
2  * See file CREDITS for list of people who contributed to this
3  * project.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  */
16 
17 #include <common.h>
18 #include <asm/io.h>
19 #include <asm/arch/hardware.h>
20 #include <asm/arch/at91_gpbr.h>
21 
22 /*
23  * We combine the BOOTCOUNT_MAGIC and bootcount in one 32-bit register.
24  * This is done so we need to use only one of the four GPBR registers.
25  */
26 void bootcount_store(ulong a)
27 {
28 	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
29 
30 	writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
31 		&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
32 }
33 
34 ulong bootcount_load(void)
35 {
36 	at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
37 
38 	ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
39 	if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
40 		return 0;
41 	else
42 		return val & 0x0000ffff;
43 }
44