bootcount_davinci.c 878 B

1234567891011121314151617181920212223242526272829303132333435363738
  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->scratch2,
  21. (BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff));
  22. }
  23. ulong bootcount_load(void)
  24. {
  25. unsigned long val;
  26. struct davinci_rtc *reg =
  27. (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
  28. val = raw_bootcount_load(&reg->scratch2);
  29. if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
  30. return 0;
  31. else
  32. return val & 0x0000ffff;
  33. }