bootcount_at91.c 732 B

1234567891011121314151617181920212223242526272829
  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 BOOTCOUNT_MAGIC and bootcount in one 32-bit register.
  8. * This is done so we need to use only one of the four GPBR registers.
  9. */
  10. void bootcount_store(ulong a)
  11. {
  12. at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
  13. writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
  14. &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
  15. }
  16. ulong bootcount_load(void)
  17. {
  18. at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
  19. ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
  20. if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
  21. return 0;
  22. else
  23. return val & 0x0000ffff;
  24. }