bootcount_at91.c 739 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * SPDX-License-Identifier: GPL-2.0+
  3. */
  4. #include <common.h>
  5. #include <asm/io.h>
  6. #include <asm/arch/hardware.h>
  7. #include <asm/arch/at91_gpbr.h>
  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. */
  12. void bootcount_store(ulong a)
  13. {
  14. at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
  15. writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
  16. &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
  17. }
  18. ulong bootcount_load(void)
  19. {
  20. at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
  21. ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
  22. if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
  23. return 0;
  24. else
  25. return val & 0x0000ffff;
  26. }