bootcount_davinci.c 834 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * (C) Copyright 2011
  3. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <bootcount.h>
  8. #include <asm/davinci_rtc.h>
  9. void bootcount_store(ulong a)
  10. {
  11. struct davinci_rtc *reg =
  12. (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
  13. /*
  14. * write RTC kick register to enable write
  15. * for RTC Scratch registers. Scratch0 and 1 are
  16. * used for bootcount values.
  17. */
  18. writel(RTC_KICK0R_WE, &reg->kick0r);
  19. writel(RTC_KICK1R_WE, &reg->kick1r);
  20. raw_bootcount_store(&reg->scratch0, a);
  21. raw_bootcount_store(&reg->scratch1, BOOTCOUNT_MAGIC);
  22. }
  23. ulong bootcount_load(void)
  24. {
  25. struct davinci_rtc *reg =
  26. (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
  27. if (raw_bootcount_load(&reg->scratch1) != BOOTCOUNT_MAGIC)
  28. return 0;
  29. else
  30. return raw_bootcount_load(&reg->scratch0);
  31. }