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