blob: 1a06db1fb7406792d6519695a2b404326070246f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese033848e2012-08-16 17:55:41 +00002
Stefan Roese033848e2012-08-16 17:55:41 +00003#include <asm/io.h>
4#include <asm/arch/hardware.h>
5#include <asm/arch/at91_gpbr.h>
6
7/*
Marek Vasut6ae0ded2018-10-11 00:13:54 +02008 * We combine the CONFIG_SYS_BOOTCOUNT_MAGIC and bootcount in one 32-bit
9 * register. This is done so we need to use only one of the four GPBR
10 * registers.
Stefan Roese033848e2012-08-16 17:55:41 +000011 */
12void bootcount_store(ulong a)
13{
14 at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
15
Marek Vasut6ae0ded2018-10-11 00:13:54 +020016 writel((CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
17 &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
Stefan Roese033848e2012-08-16 17:55:41 +000018}
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]);
Marek Vasut6ae0ded2018-10-11 00:13:54 +020025 if ((val & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000))
Stefan Roese033848e2012-08-16 17:55:41 +000026 return 0;
27 else
28 return val & 0x0000ffff;
29}