rk3188-board-spl.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2015 Google, Inc
  4. */
  5. #include <clk.h>
  6. #include <common.h>
  7. #include <debug_uart.h>
  8. #include <dm.h>
  9. #include <fdtdec.h>
  10. #include <led.h>
  11. #include <malloc.h>
  12. #include <ram.h>
  13. #include <spl.h>
  14. #include <asm/gpio.h>
  15. #include <asm/io.h>
  16. #include <asm/arch/bootrom.h>
  17. #include <asm/arch/clock.h>
  18. #include <asm/arch/hardware.h>
  19. #include <asm/arch/periph.h>
  20. #include <asm/arch/pmu_rk3188.h>
  21. #include <asm/arch/sdram.h>
  22. #include <asm/arch/timer.h>
  23. #include <dm/pinctrl.h>
  24. #include <dm/root.h>
  25. #include <dm/test.h>
  26. #include <dm/util.h>
  27. #include <power/regulator.h>
  28. #include <syscon.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. u32 spl_boot_device(void)
  31. {
  32. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  33. const void *blob = gd->fdt_blob;
  34. struct udevice *dev;
  35. const char *bootdev;
  36. int node;
  37. int ret;
  38. bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
  39. debug("Boot device %s\n", bootdev);
  40. if (!bootdev)
  41. goto fallback;
  42. node = fdt_path_offset(blob, bootdev);
  43. if (node < 0) {
  44. debug("node=%d\n", node);
  45. goto fallback;
  46. }
  47. ret = device_get_global_by_of_offset(node, &dev);
  48. if (ret) {
  49. debug("device at node %s/%d not found: %d\n", bootdev, node,
  50. ret);
  51. goto fallback;
  52. }
  53. debug("Found device %s\n", dev->name);
  54. switch (device_get_uclass_id(dev)) {
  55. case UCLASS_SPI_FLASH:
  56. return BOOT_DEVICE_SPI;
  57. case UCLASS_MMC:
  58. return BOOT_DEVICE_MMC1;
  59. default:
  60. debug("Booting from device uclass '%s' not supported\n",
  61. dev_get_uclass_name(dev));
  62. }
  63. fallback:
  64. #endif
  65. return BOOT_DEVICE_MMC1;
  66. }
  67. static int setup_arm_clock(void)
  68. {
  69. struct udevice *dev;
  70. struct clk clk;
  71. int ret;
  72. ret = rockchip_get_clk(&dev);
  73. if (ret)
  74. return ret;
  75. clk.id = CLK_ARM;
  76. ret = clk_request(dev, &clk);
  77. if (ret < 0)
  78. return ret;
  79. ret = clk_set_rate(&clk, 600000000);
  80. clk_free(&clk);
  81. return ret;
  82. }
  83. void board_init_f(ulong dummy)
  84. {
  85. struct udevice *pinctrl, *dev;
  86. int ret;
  87. /* Example code showing how to enable the debug UART on RK3188 */
  88. #ifdef EARLY_UART
  89. #include <asm/arch/grf_rk3188.h>
  90. /* Enable early UART on the RK3188 */
  91. #define GRF_BASE 0x20008000
  92. struct rk3188_grf * const grf = (void *)GRF_BASE;
  93. rk_clrsetreg(&grf->gpio1b_iomux,
  94. GPIO1B1_MASK << GPIO1B1_SHIFT |
  95. GPIO1B0_MASK << GPIO1B0_SHIFT,
  96. GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT |
  97. GPIO1B0_UART2_SIN << GPIO1B0_SHIFT);
  98. /*
  99. * Debug UART can be used from here if required:
  100. *
  101. * debug_uart_init();
  102. * printch('a');
  103. * printhex8(0x1234);
  104. * printascii("string");
  105. */
  106. debug_uart_init();
  107. printch('s');
  108. printch('p');
  109. printch('l');
  110. printch('\n');
  111. #endif
  112. ret = spl_early_init();
  113. if (ret) {
  114. debug("spl_early_init() failed: %d\n", ret);
  115. hang();
  116. }
  117. ret = rockchip_get_clk(&dev);
  118. if (ret) {
  119. debug("CLK init failed: %d\n", ret);
  120. return;
  121. }
  122. ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
  123. if (ret) {
  124. debug("Pinctrl init failed: %d\n", ret);
  125. return;
  126. }
  127. ret = uclass_get_device(UCLASS_RAM, 0, &dev);
  128. if (ret) {
  129. debug("DRAM init failed: %d\n", ret);
  130. return;
  131. }
  132. setup_arm_clock();
  133. #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
  134. back_to_bootrom(BROM_BOOT_NEXTSTAGE);
  135. #endif
  136. }
  137. static int setup_led(void)
  138. {
  139. #ifdef CONFIG_SPL_LED
  140. struct udevice *dev;
  141. char *led_name;
  142. int ret;
  143. led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
  144. if (!led_name)
  145. return 0;
  146. ret = led_get_by_label(led_name, &dev);
  147. if (ret) {
  148. debug("%s: get=%d\n", __func__, ret);
  149. return ret;
  150. }
  151. ret = led_set_on(dev, 1);
  152. if (ret)
  153. return ret;
  154. #endif
  155. return 0;
  156. }
  157. void spl_board_init(void)
  158. {
  159. struct udevice *pinctrl;
  160. int ret;
  161. ret = setup_led();
  162. if (ret) {
  163. debug("LED ret=%d\n", ret);
  164. hang();
  165. }
  166. ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
  167. if (ret) {
  168. debug("%s: Cannot find pinctrl device\n", __func__);
  169. goto err;
  170. }
  171. #ifdef CONFIG_SPL_MMC_SUPPORT
  172. ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
  173. if (ret) {
  174. debug("%s: Failed to set up SD card\n", __func__);
  175. goto err;
  176. }
  177. #endif
  178. /* Enable debug UART */
  179. ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
  180. if (ret) {
  181. debug("%s: Failed to set up console UART\n", __func__);
  182. goto err;
  183. }
  184. preloader_console_init();
  185. #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
  186. back_to_bootrom(BROM_BOOT_NEXTSTAGE);
  187. #endif
  188. return;
  189. err:
  190. printf("spl_board_init: Error %d\n", ret);
  191. /* No way to report error here */
  192. hang();
  193. }