bootcount_at91.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * See file CREDITS for list of people who contributed to this
  3. * project.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <common.h>
  17. #include <asm/io.h>
  18. #include <asm/arch/hardware.h>
  19. #include <asm/arch/at91_gpbr.h>
  20. /*
  21. * We combine the BOOTCOUNT_MAGIC and bootcount in one 32-bit register.
  22. * This is done so we need to use only one of the four GPBR registers.
  23. */
  24. void bootcount_store(ulong a)
  25. {
  26. at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
  27. writel((BOOTCOUNT_MAGIC & 0xffff0000) | (a & 0x0000ffff),
  28. &gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
  29. }
  30. ulong bootcount_load(void)
  31. {
  32. at91_gpbr_t *gpbr = (at91_gpbr_t *) ATMEL_BASE_GPBR;
  33. ulong val = readl(&gpbr->reg[AT91_GPBR_INDEX_BOOTCOUNT]);
  34. if ((val & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
  35. return 0;
  36. else
  37. return val & 0x0000ffff;
  38. }