rk3288-board-spl.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * (C) Copyright 2015 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  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/clock.h>
  17. #include <asm/arch/hardware.h>
  18. #include <asm/arch/periph.h>
  19. #include <asm/arch/sdram.h>
  20. #include <asm/arch/timer.h>
  21. #include <dm/pinctrl.h>
  22. #include <dm/root.h>
  23. #include <dm/test.h>
  24. #include <dm/util.h>
  25. #include <power/regulator.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. u32 spl_boot_device(void)
  28. {
  29. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  30. const void *blob = gd->fdt_blob;
  31. struct udevice *dev;
  32. const char *bootdev;
  33. int node;
  34. int ret;
  35. bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
  36. debug("Boot device %s\n", bootdev);
  37. if (!bootdev)
  38. goto fallback;
  39. node = fdt_path_offset(blob, bootdev);
  40. if (node < 0) {
  41. debug("node=%d\n", node);
  42. goto fallback;
  43. }
  44. ret = device_get_global_by_of_offset(node, &dev);
  45. if (ret) {
  46. debug("device at node %s/%d not found: %d\n", bootdev, node,
  47. ret);
  48. goto fallback;
  49. }
  50. debug("Found device %s\n", dev->name);
  51. switch (device_get_uclass_id(dev)) {
  52. case UCLASS_SPI_FLASH:
  53. return BOOT_DEVICE_SPI;
  54. case UCLASS_MMC:
  55. return BOOT_DEVICE_MMC1;
  56. default:
  57. debug("Booting from device uclass '%s' not supported\n",
  58. dev_get_uclass_name(dev));
  59. }
  60. fallback:
  61. #elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
  62. defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
  63. defined(CONFIG_TARGET_CHROMEBOOK_MINNIE)
  64. return BOOT_DEVICE_SPI;
  65. #endif
  66. return BOOT_DEVICE_MMC1;
  67. }
  68. u32 spl_boot_mode(const u32 boot_device)
  69. {
  70. return MMCSD_MODE_RAW;
  71. }
  72. /* read L2 control register (L2CTLR) */
  73. static inline uint32_t read_l2ctlr(void)
  74. {
  75. uint32_t val = 0;
  76. asm volatile ("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
  77. return val;
  78. }
  79. /* write L2 control register (L2CTLR) */
  80. static inline void write_l2ctlr(uint32_t val)
  81. {
  82. /*
  83. * Note: L2CTLR can only be written when the L2 memory system
  84. * is idle, ie before the MMU is enabled.
  85. */
  86. asm volatile("mcr p15, 1, %0, c9, c0, 2" : : "r" (val) : "memory");
  87. isb();
  88. }
  89. static void configure_l2ctlr(void)
  90. {
  91. uint32_t l2ctlr;
  92. l2ctlr = read_l2ctlr();
  93. l2ctlr &= 0xfffc0000; /* clear bit0~bit17 */
  94. /*
  95. * Data RAM write latency: 2 cycles
  96. * Data RAM read latency: 2 cycles
  97. * Data RAM setup latency: 1 cycle
  98. * Tag RAM write latency: 1 cycle
  99. * Tag RAM read latency: 1 cycle
  100. * Tag RAM setup latency: 1 cycle
  101. */
  102. l2ctlr |= (1 << 3 | 1 << 0);
  103. write_l2ctlr(l2ctlr);
  104. }
  105. #ifdef CONFIG_SPL_MMC_SUPPORT
  106. static int configure_emmc(struct udevice *pinctrl)
  107. {
  108. #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY)
  109. struct gpio_desc desc;
  110. int ret;
  111. pinctrl_request_noflags(pinctrl, PERIPH_ID_EMMC);
  112. /*
  113. * TODO(sjg@chromium.org): Pick this up from device tree or perhaps
  114. * use the EMMC_PWREN setting.
  115. */
  116. ret = dm_gpio_lookup_name("D9", &desc);
  117. if (ret) {
  118. debug("gpio ret=%d\n", ret);
  119. return ret;
  120. }
  121. ret = dm_gpio_request(&desc, "emmc_pwren");
  122. if (ret) {
  123. debug("gpio_request ret=%d\n", ret);
  124. return ret;
  125. }
  126. ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
  127. if (ret) {
  128. debug("gpio dir ret=%d\n", ret);
  129. return ret;
  130. }
  131. ret = dm_gpio_set_value(&desc, 1);
  132. if (ret) {
  133. debug("gpio value ret=%d\n", ret);
  134. return ret;
  135. }
  136. #endif
  137. return 0;
  138. }
  139. #endif
  140. extern void back_to_bootrom(void);
  141. void board_init_f(ulong dummy)
  142. {
  143. struct udevice *pinctrl;
  144. struct udevice *dev;
  145. int ret;
  146. /* Example code showing how to enable the debug UART on RK3288 */
  147. #ifdef EARLY_UART
  148. #include <asm/arch/grf_rk3288.h>
  149. /* Enable early UART on the RK3288 */
  150. #define GRF_BASE 0xff770000
  151. struct rk3288_grf * const grf = (void *)GRF_BASE;
  152. rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT |
  153. GPIO7C6_MASK << GPIO7C6_SHIFT,
  154. GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT |
  155. GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT);
  156. /*
  157. * Debug UART can be used from here if required:
  158. *
  159. * debug_uart_init();
  160. * printch('a');
  161. * printhex8(0x1234);
  162. * printascii("string");
  163. */
  164. debug_uart_init();
  165. #endif
  166. ret = spl_init();
  167. if (ret) {
  168. debug("spl_init() failed: %d\n", ret);
  169. hang();
  170. }
  171. rockchip_timer_init();
  172. configure_l2ctlr();
  173. ret = rockchip_get_clk(&dev);
  174. if (ret) {
  175. debug("CLK init failed: %d\n", ret);
  176. return;
  177. }
  178. ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
  179. if (ret) {
  180. debug("Pinctrl init failed: %d\n", ret);
  181. return;
  182. }
  183. ret = uclass_get_device(UCLASS_RAM, 0, &dev);
  184. if (ret) {
  185. debug("DRAM init failed: %d\n", ret);
  186. return;
  187. }
  188. #if defined(CONFIG_ROCKCHIP_SPL_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
  189. back_to_bootrom();
  190. #endif
  191. }
  192. static int setup_led(void)
  193. {
  194. #ifdef CONFIG_SPL_LED
  195. struct udevice *dev;
  196. char *led_name;
  197. int ret;
  198. led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led");
  199. if (!led_name)
  200. return 0;
  201. ret = led_get_by_label(led_name, &dev);
  202. if (ret) {
  203. debug("%s: get=%d\n", __func__, ret);
  204. return ret;
  205. }
  206. ret = led_set_on(dev, 1);
  207. if (ret)
  208. return ret;
  209. #endif
  210. return 0;
  211. }
  212. void spl_board_init(void)
  213. {
  214. struct udevice *pinctrl;
  215. int ret;
  216. ret = setup_led();
  217. if (ret) {
  218. debug("LED ret=%d\n", ret);
  219. hang();
  220. }
  221. ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
  222. if (ret) {
  223. debug("%s: Cannot find pinctrl device\n", __func__);
  224. goto err;
  225. }
  226. #ifdef CONFIG_SPL_MMC_SUPPORT
  227. ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
  228. if (ret) {
  229. debug("%s: Failed to set up SD card\n", __func__);
  230. goto err;
  231. }
  232. ret = configure_emmc(pinctrl);
  233. if (ret) {
  234. debug("%s: Failed to set up eMMC\n", __func__);
  235. goto err;
  236. }
  237. #endif
  238. /* Enable debug UART */
  239. ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
  240. if (ret) {
  241. debug("%s: Failed to set up console UART\n", __func__);
  242. goto err;
  243. }
  244. preloader_console_init();
  245. #ifdef CONFIG_ROCKCHIP_SPL_BACK_TO_BROM
  246. back_to_bootrom();
  247. #endif
  248. return;
  249. err:
  250. printf("spl_board_init: Error %d\n", ret);
  251. /* No way to report error here */
  252. hang();
  253. }