blob: 3092ba56c04f2a69280217a1843d88ef74028e7a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese0044c422012-08-16 17:55:41 +00002
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 BOOTCOUNT_MAGIC and bootcount in one 32-bit register.
10 * This is done so we need to use only one of the four GPBR registers.
11 */
12void bootcount_store(ulong a)
13{
14 at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
15
16 writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
17 &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
18}
19
20ulong bootcount_load(void)
21{
22 at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
23
24 ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
25 if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
26 return 0;
27 else
28 return val & 0x0000ffff;
29}