rk3288-board-spl.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2015 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <debug_uart.h>
  7. #include <dm.h>
  8. #include <fdtdec.h>
  9. #include <i2c.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_rk3288.h>
  21. #include <asm/arch/sdram.h>
  22. #include <asm/arch/sdram_common.h>
  23. #include <asm/arch/sys_proto.h>
  24. #include <asm/arch/timer.h>
  25. #include <dm/pinctrl.h>
  26. #include <dm/root.h>
  27. #include <dm/test.h>
  28. #include <dm/util.h>
  29. #include <power/regulator.h>
  30. #include <power/rk8xx_pmic.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. u32 spl_boot_device(void)
  33. {
  34. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  35. const void *blob = gd->fdt_blob;
  36. struct udevice *dev;
  37. const char *bootdev;
  38. int node;
  39. int ret;
  40. bootdev = fdtdec_get_config_string(blob, "u-boot,boot0");
  41. debug("Boot device %s\n", bootdev);
  42. if (!bootdev)
  43. goto fallback;
  44. node = fdt_path_offset(blob, bootdev);
  45. if (node < 0) {
  46. debug("node=%d\n", node);
  47. goto fallback;
  48. }
  49. ret = device_get_global_by_of_offset(node, &dev);
  50. if (ret) {
  51. debug("device at node %s/%d not found: %d\n", bootdev, node,
  52. ret);
  53. goto fallback;
  54. }
  55. debug("Found device %s\n", dev->name);
  56. switch (device_get_uclass_id(dev)) {
  57. case UCLASS_SPI_FLASH:
  58. return BOOT_DEVICE_SPI;
  59. case UCLASS_MMC:
  60. return BOOT_DEVICE_MMC1;
  61. default:
  62. debug("Booting from device uclass '%s' not supported\n",
  63. dev_get_uclass_name(dev));
  64. }
  65. fallback:
  66. #elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \
  67. defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \
  68. defined(CONFIG_TARGET_CHROMEBOOK_MINNIE)
  69. return BOOT_DEVICE_SPI;
  70. #endif
  71. return BOOT_DEVICE_MMC1;
  72. }
  73. #ifdef CONFIG_SPL_MMC_SUPPORT
  74. static int configure_emmc(struct udevice *pinctrl)
  75. {
  76. #if defined(CONFIG_TARGET_CHROMEBOOK_JERRY)
  77. struct gpio_desc desc;
  78. int ret;
  79. pinctrl_request_noflags(pinctrl, PERIPH_ID_EMMC);
  80. /*
  81. * TODO(sjg@chromium.org): Pick this up from device tree or perhaps
  82. * use the EMMC_PWREN setting.
  83. */
  84. ret = dm_gpio_lookup_name("D9", &desc);
  85. if (ret) {
  86. debug("gpio ret=%d\n", ret);
  87. return ret;
  88. }
  89. ret = dm_gpio_request(&desc, "emmc_pwren");
  90. if (ret) {
  91. debug("gpio_request ret=%d\n", ret);
  92. return ret;
  93. }
  94. ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_OUT);
  95. if (ret) {
  96. debug("gpio dir ret=%d\n", ret);
  97. return ret;
  98. }
  99. ret = dm_gpio_set_value(&desc, 1);
  100. if (ret) {
  101. debug("gpio value ret=%d\n", ret);
  102. return ret;
  103. }
  104. #endif
  105. return 0;
  106. }
  107. #endif
  108. #if !defined(CONFIG_SPL_OF_PLATDATA)
  109. static int phycore_init(void)
  110. {
  111. struct udevice *pmic;
  112. int ret;
  113. ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
  114. if (ret)
  115. return ret;
  116. #if defined(CONFIG_SPL_POWER_SUPPORT)
  117. /* Increase USB input current to 2A */
  118. ret = rk818_spl_configure_usb_input_current(pmic, 2000);
  119. if (ret)
  120. return ret;
  121. /* Close charger when USB lower then 3.26V */
  122. ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000);
  123. if (ret)
  124. return ret;
  125. #endif
  126. return 0;
  127. }
  128. #endif
  129. void board_init_f(ulong dummy)
  130. {
  131. struct udevice *pinctrl;
  132. struct udevice *dev;
  133. int ret;
  134. /* Example code showing how to enable the debug UART on RK3288 */
  135. #include <asm/arch/grf_rk3288.h>
  136. /* Enable early UART on the RK3288 */
  137. #define GRF_BASE 0xff770000
  138. struct rk3288_grf * const grf = (void *)GRF_BASE;
  139. rk_clrsetreg(&grf->gpio7ch_iomux, GPIO7C7_MASK << GPIO7C7_SHIFT |
  140. GPIO7C6_MASK << GPIO7C6_SHIFT,
  141. GPIO7C7_UART2DBG_SOUT << GPIO7C7_SHIFT |
  142. GPIO7C6_UART2DBG_SIN << GPIO7C6_SHIFT);
  143. /*
  144. * Debug UART can be used from here if required:
  145. *
  146. * debug_uart_init();
  147. * printch('a');
  148. * printhex8(0x1234);
  149. * printascii("string");
  150. */
  151. debug_uart_init();
  152. debug("\nspl:debug uart enabled in %s\n", __func__);
  153. ret = spl_early_init();
  154. if (ret) {
  155. debug("spl_early_init() failed: %d\n", ret);
  156. hang();
  157. }
  158. rockchip_timer_init();
  159. configure_l2ctlr();
  160. ret = rockchip_get_clk(&dev);
  161. if (ret) {
  162. debug("CLK init failed: %d\n", ret);
  163. return;
  164. }
  165. ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
  166. if (ret) {
  167. debug("Pinctrl init failed: %d\n", ret);
  168. return;
  169. }
  170. #if !defined(CONFIG_SPL_OF_PLATDATA)
  171. if (of_machine_is_compatible("phytec,rk3288-phycore-som")) {
  172. ret = phycore_init();
  173. if (ret) {
  174. debug("Failed to set up phycore power settings: %d\n",
  175. ret);
  176. return;
  177. }
  178. }
  179. #endif
  180. #if !defined(CONFIG_SUPPORT_TPL)
  181. debug("\nspl:init dram\n");
  182. ret = uclass_get_device(UCLASS_RAM, 0, &dev);
  183. if (ret) {
  184. debug("DRAM init failed: %d\n", ret);
  185. return;
  186. }
  187. #endif
  188. #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT)
  189. back_to_bootrom(BROM_BOOT_NEXTSTAGE);
  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. #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
  246. back_to_bootrom(BROM_BOOT_NEXTSTAGE);
  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. }
  254. #ifdef CONFIG_SPL_OS_BOOT
  255. #define PMU_BASE 0xff730000
  256. int dram_init_banksize(void)
  257. {
  258. struct rk3288_pmu *const pmu = (void *)PMU_BASE;
  259. size_t size = rockchip_sdram_size((phys_addr_t)&pmu->sys_reg[2]);
  260. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  261. gd->bd->bi_dram[0].size = size;
  262. return 0;
  263. }
  264. #endif