bootcount_davinci.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2011
  4. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  5. *
  6. * A bootcount driver for the RTC IP block found on many TI platforms.
  7. * This requires the RTC clocks, etc, to be enabled prior to use and
  8. * not all boards with this IP block on it will have the RTC in use.
  9. */
  10. #include <bootcount.h>
  11. #include <asm/davinci_rtc.h>
  12. void bootcount_store(ulong a)
  13. {
  14. struct davinci_rtc *reg =
  15. (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
  16. /*
  17. * write RTC kick registers to enable write
  18. * for RTC Scratch registers. Scratch register 2 is
  19. * used for bootcount value.
  20. */
  21. writel(RTC_KICK0R_WE, &reg->kick0r);
  22. writel(RTC_KICK1R_WE, &reg->kick1r);
  23. raw_bootcount_store(&reg->scratch2,
  24. (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff));
  25. }
  26. ulong bootcount_load(void)
  27. {
  28. unsigned long val;
  29. struct davinci_rtc *reg =
  30. (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
  31. val = raw_bootcount_load(&reg->scratch2);
  32. if ((val & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000))
  33. return 0;
  34. else
  35. return val & 0x0000ffff;
  36. }