blob: c4ab5ceafabdf03828ecd53310a13cfd7a5376a7 [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
Tom Riniabb9a042024-05-18 20:20:43 -06003#include <common.h>
Stefan Roese033848e2012-08-16 17:55:41 +00004#include <asm/io.h>
5#include <asm/arch/hardware.h>
6#include <asm/arch/at91_gpbr.h>
7
8/*
Marek Vasut6ae0ded2018-10-11 00:13:54 +02009 * 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 Roese033848e2012-08-16 17:55:41 +000012 */
13void bootcount_store(ulong a)
14{
15 at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
16
Marek Vasut6ae0ded2018-10-11 00:13:54 +020017 writel((CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
18 &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
Stefan Roese033848e2012-08-16 17:55:41 +000019}
20
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]);
Marek Vasut6ae0ded2018-10-11 00:13:54 +020026 if ((val & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000))
Stefan Roese033848e2012-08-16 17:55:41 +000027 return 0;
28 else
29 return val & 0x0000ffff;
30}