stemmy.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2019 Stephan Gerhold <stephan@gerhold.net>
  4. */
  5. #include <common.h>
  6. #include <init.h>
  7. #include <log.h>
  8. #include <asm/global_data.h>
  9. #include <asm/setup.h>
  10. #include <asm/system.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. /* Parse atags provided by Samsung bootloader to get available memory */
  13. static ulong fw_mach __section(".data");
  14. static ulong fw_atags __section(".data");
  15. void save_boot_params(ulong r0, ulong r1, ulong r2, ulong r3)
  16. {
  17. fw_mach = r1;
  18. fw_atags = r2;
  19. save_boot_params_ret();
  20. }
  21. static const struct tag *fw_atags_get(void)
  22. {
  23. const struct tag *tags = (const struct tag *)fw_atags;
  24. if (tags->hdr.tag != ATAG_CORE) {
  25. log_err("Invalid atags: tag 0x%x at %p\n", tags->hdr.tag, tags);
  26. return NULL;
  27. }
  28. return tags;
  29. }
  30. int dram_init(void)
  31. {
  32. const struct tag *t, *tags = fw_atags_get();
  33. if (!tags)
  34. return -EINVAL;
  35. for_each_tag(t, tags) {
  36. if (t->hdr.tag != ATAG_MEM)
  37. continue;
  38. debug("Memory: %#x-%#x (size %#x)\n", t->u.mem.start,
  39. t->u.mem.start + t->u.mem.size, t->u.mem.size);
  40. gd->ram_size += t->u.mem.size;
  41. }
  42. return 0;
  43. }
  44. int dram_init_banksize(void)
  45. {
  46. const struct tag *t, *tags = fw_atags_get();
  47. unsigned int bank = 0;
  48. if (!tags)
  49. return -EINVAL;
  50. for_each_tag(t, tags) {
  51. if (t->hdr.tag != ATAG_MEM)
  52. continue;
  53. gd->bd->bi_dram[bank].start = t->u.mem.start;
  54. gd->bd->bi_dram[bank].size = t->u.mem.size;
  55. if (++bank == CONFIG_NR_DRAM_BANKS)
  56. break;
  57. }
  58. return 0;
  59. }
  60. int board_init(void)
  61. {
  62. gd->bd->bi_arch_number = fw_mach;
  63. gd->bd->bi_boot_params = fw_atags;
  64. return 0;
  65. }