bootcount_at91.c 774 B

123456789101112131415161718192021222324252627282930
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <asm/io.h>
  4. #include <asm/arch/hardware.h>
  5. #include <asm/arch/at91_gpbr.h>
  6. /*
  7. * We combine the CONFIG_SYS_BOOTCOUNT_MAGIC and bootcount in one 32-bit
  8. * register. This is done so we need to use only one of the four GPBR
  9. * registers.
  10. */
  11. void bootcount_store(ulong a)
  12. {
  13. at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
  14. writel((CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
  15. &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
  16. }
  17. ulong bootcount_load(void)
  18. {
  19. at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
  20. ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
  21. if ((val & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000))
  22. return 0;
  23. else
  24. return val & 0x0000ffff;
  25. }