Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 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 | /* |
Marek Vasut | 6ae0ded | 2018-10-11 00:13:54 +0200 | [diff] [blame] | 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. |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 12 | */ |
| 13 | void bootcount_store(ulong a) |
| 14 | { |
| 15 | at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR; |
| 16 | |
Marek Vasut | 6ae0ded | 2018-10-11 00:13:54 +0200 | [diff] [blame] | 17 | writel((CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff), |
| 18 | &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]); |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | ulong 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]); |
Marek Vasut | 6ae0ded | 2018-10-11 00:13:54 +0200 | [diff] [blame] | 26 | if ((val & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000)) |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 27 | return 0; |
| 28 | else |
| 29 | return val & 0x0000ffff; |
| 30 | } |