bootcount_davinci.c 1.1 KB

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