1 // SPDX-License-Identifier: GPL-2.0+ 2 3 #include <common.h> 4 #include <asm/io.h> 5 #include <asm/arch/hardware.h> 6 #include <asm/arch/at91_gpbr.h> 7 8 /* 9 * We combine the CONFIG_SYS_BOOTCOUNT_MAGIC and bootcount in one 32-bit 10 * register. This is done so we need to use only one of the four GPBR 11 * registers. 12 */ bootcount_store(ulong a)13void bootcount_store(ulong a) 14 { 15 at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR; 16 17 writel((CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff), 18 &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]); 19 } 20 bootcount_load(void)21ulong bootcount_load(void) 22 { 23 at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR; 24 25 ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]); 26 if ((val & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000)) 27 return 0; 28 else 29 return val & 0x0000ffff; 30 } 31