dram_helpers.c 955 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * DRAM init helper functions
  4. *
  5. * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
  6. */
  7. #include <common.h>
  8. #include <asm/barriers.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/dram.h>
  11. /*
  12. * Wait up to 1s for value to be set in given part of reg.
  13. */
  14. void mctl_await_completion(u32 *reg, u32 mask, u32 val)
  15. {
  16. unsigned long tmo = timer_get_us() + 1000000;
  17. while ((readl(reg) & mask) != val) {
  18. if (timer_get_us() > tmo)
  19. panic("Timeout initialising DRAM\n");
  20. }
  21. }
  22. /*
  23. * Test if memory at offset offset matches memory at begin of DRAM
  24. */
  25. bool mctl_mem_matches(u32 offset)
  26. {
  27. /* Try to write different values to RAM at two addresses */
  28. writel(0, CONFIG_SYS_SDRAM_BASE);
  29. writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset);
  30. dsb();
  31. /* Check if the same value is actually observed when reading back */
  32. return readl(CONFIG_SYS_SDRAM_BASE) ==
  33. readl((ulong)CONFIG_SYS_SDRAM_BASE + offset);
  34. }