bootcount_davinci.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * (C) Copyright 2011
  3. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #include <bootcount.h>
  20. #include <asm/arch/da850_lowlevel.h>
  21. #include <asm/arch/davinci_misc.h>
  22. void bootcount_store(ulong a)
  23. {
  24. struct davinci_rtc *reg =
  25. (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
  26. /*
  27. * write RTC kick register to enable write
  28. * for RTC Scratch registers. Scratch0 and 1 are
  29. * used for bootcount values.
  30. */
  31. writel(RTC_KICK0R_WE, &reg->kick0r);
  32. writel(RTC_KICK1R_WE, &reg->kick1r);
  33. raw_bootcount_store(&reg->scratch0, a);
  34. raw_bootcount_store(&reg->scratch1, BOOTCOUNT_MAGIC);
  35. }
  36. ulong bootcount_load(void)
  37. {
  38. struct davinci_rtc *reg =
  39. (struct davinci_rtc *)CONFIG_SYS_BOOTCOUNT_ADDR;
  40. if (raw_bootcount_load(&reg->scratch1) != BOOTCOUNT_MAGIC)
  41. return 0;
  42. else
  43. return raw_bootcount_load(&reg->scratch0);
  44. }