bcmstb.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2018 Cisco Systems, Inc.
  4. *
  5. * Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
  6. */
  7. #include <linux/types.h>
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <asm/bootm.h>
  11. #include <mach/sdhci.h>
  12. #include <mach/timer.h>
  13. #include <mmc.h>
  14. #include <fdtdec.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. #define BCMSTB_DATA_SECTION __attribute__((section(".data")))
  17. struct bcmstb_boot_parameters bcmstb_boot_parameters BCMSTB_DATA_SECTION;
  18. phys_addr_t prior_stage_fdt_address BCMSTB_DATA_SECTION;
  19. union reg_value_union {
  20. const char *data;
  21. const phys_addr_t *address;
  22. };
  23. int board_init(void)
  24. {
  25. return 0;
  26. }
  27. u32 get_board_rev(void)
  28. {
  29. return 0;
  30. }
  31. void reset_cpu(ulong ignored)
  32. {
  33. }
  34. int print_cpuinfo(void)
  35. {
  36. return 0;
  37. }
  38. int dram_init(void)
  39. {
  40. if (fdtdec_setup_mem_size_base() != 0)
  41. return -EINVAL;
  42. return 0;
  43. }
  44. int dram_init_banksize(void)
  45. {
  46. fdtdec_setup_memory_banksize();
  47. /*
  48. * On this SoC, U-Boot is running as an ELF file. Change the
  49. * relocation address to CONFIG_SYS_TEXT_BASE, so that in
  50. * setup_reloc, gd->reloc_off works out to 0, effectively
  51. * disabling relocation. Otherwise U-Boot hangs in the setup
  52. * instructions just before relocate_code in
  53. * arch/arm/lib/crt0.S.
  54. */
  55. gd->relocaddr = CONFIG_SYS_TEXT_BASE;
  56. return 0;
  57. }
  58. void enable_caches(void)
  59. {
  60. /*
  61. * This port assumes that the prior stage bootloader has
  62. * enabled I-cache and D-cache already. Implementing this
  63. * function silences the warning in the default function.
  64. */
  65. }
  66. static const phys_addr_t bcmstb_sdhci_address(u32 alias_index)
  67. {
  68. int node = 0;
  69. int ret = 0;
  70. char sdhci[16] = { 0 };
  71. const void *fdt = gd->fdt_blob;
  72. const char *path = NULL;
  73. struct fdt_resource resource = { 0 };
  74. if (!fdt) {
  75. printf("%s: Invalid gd->fdt_blob\n", __func__);
  76. return 0;
  77. }
  78. node = fdt_path_offset(fdt, "/aliases");
  79. if (node < 0) {
  80. printf("%s: Failed to find /aliases node\n", __func__);
  81. return 0;
  82. }
  83. sprintf(sdhci, "sdhci%d", alias_index);
  84. path = fdt_getprop(fdt, node, sdhci, NULL);
  85. if (!path) {
  86. printf("%s: Failed to find alias for %s\n", __func__, sdhci);
  87. return 0;
  88. }
  89. node = fdt_path_offset(fdt, path);
  90. if (node < 0) {
  91. printf("%s: Failed to resolve BCMSTB SDHCI alias\n", __func__);
  92. return 0;
  93. }
  94. ret = fdt_get_named_resource(fdt, node, "reg", "reg-names",
  95. "host", &resource);
  96. if (ret) {
  97. printf("%s: Failed to read BCMSTB SDHCI host resource\n",
  98. __func__);
  99. return 0;
  100. }
  101. return resource.start;
  102. }
  103. int board_mmc_init(bd_t *bis)
  104. {
  105. phys_addr_t sdhci_base_address = 0;
  106. sdhci_base_address = bcmstb_sdhci_address(CONFIG_BCMSTB_SDHCI_INDEX);
  107. if (!sdhci_base_address) {
  108. sdhci_base_address = BCMSTB_SDHCI_BASE;
  109. printf("%s: Assuming BCMSTB SDHCI address: 0x%p\n",
  110. __func__, (void *)sdhci_base_address);
  111. }
  112. debug("BCMSTB SDHCI base address: 0x%p\n", (void *)sdhci_base_address);
  113. bcmstb_sdhci_init(sdhci_base_address);
  114. return 0;
  115. }
  116. int timer_init(void)
  117. {
  118. gd->arch.timer_rate_hz = readl(BCMSTB_TIMER_FREQUENCY);
  119. return 0;
  120. }
  121. ulong get_tbclk(void)
  122. {
  123. return gd->arch.timer_rate_hz;
  124. }
  125. uint64_t get_ticks(void)
  126. {
  127. gd->timebase_h = readl(BCMSTB_TIMER_HIGH);
  128. gd->timebase_l = readl(BCMSTB_TIMER_LOW);
  129. return ((uint64_t)gd->timebase_h << 32) | gd->timebase_l;
  130. }
  131. int board_late_init(void)
  132. {
  133. debug("Arguments from prior stage bootloader:\n");
  134. debug("General Purpose Register 0: 0x%x\n", bcmstb_boot_parameters.r0);
  135. debug("General Purpose Register 1: 0x%x\n", bcmstb_boot_parameters.r1);
  136. debug("General Purpose Register 2: 0x%x\n", bcmstb_boot_parameters.r2);
  137. debug("General Purpose Register 3: 0x%x\n", bcmstb_boot_parameters.r3);
  138. debug("Stack Pointer Register: 0x%x\n", bcmstb_boot_parameters.sp);
  139. debug("Link Register: 0x%x\n", bcmstb_boot_parameters.lr);
  140. debug("Assuming timer frequency register at: 0x%p\n",
  141. (void *)BCMSTB_TIMER_FREQUENCY);
  142. debug("Read timer frequency (in Hz): %ld\n", gd->arch.timer_rate_hz);
  143. debug("Prior stage provided DTB at: 0x%p\n",
  144. (void *)prior_stage_fdt_address);
  145. /*
  146. * Set fdtcontroladdr in the environment so that scripts can
  147. * refer to it, for example, to reuse it for fdtaddr.
  148. */
  149. env_set_hex("fdtcontroladdr", prior_stage_fdt_address);
  150. /*
  151. * Do not set machid to the machine identifier value provided
  152. * by the prior stage bootloader (bcmstb_boot_parameters.r1)
  153. * because we're using a device tree to boot Linux.
  154. */
  155. return 0;
  156. }