rk3288-board.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2015 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <clk.h>
  7. #include <dm.h>
  8. #include <ram.h>
  9. #include <syscon.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/clock.h>
  12. #include <asm/arch/cru_rk3288.h>
  13. #include <asm/arch/periph.h>
  14. #include <asm/arch/pmu_rk3288.h>
  15. #include <asm/arch/qos_rk3288.h>
  16. #include <asm/arch/boot_mode.h>
  17. #include <asm/gpio.h>
  18. #include <dm/pinctrl.h>
  19. #include <dt-bindings/clock/rk3288-cru.h>
  20. #include <power/regulator.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. __weak int rk_board_late_init(void)
  23. {
  24. return 0;
  25. }
  26. int rk3288_qos_init(void)
  27. {
  28. int val = 2 << PRIORITY_HIGH_SHIFT | 2 << PRIORITY_LOW_SHIFT;
  29. /* set vop qos to higher priority */
  30. writel(val, CPU_AXI_QOS_PRIORITY + VIO0_VOP_QOS);
  31. writel(val, CPU_AXI_QOS_PRIORITY + VIO1_VOP_QOS);
  32. if (!fdt_node_check_compatible(gd->fdt_blob, 0,
  33. "rockchip,rk3288-tinker"))
  34. {
  35. /* set isp qos to higher priority */
  36. writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_R_QOS);
  37. writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W0_QOS);
  38. writel(val, CPU_AXI_QOS_PRIORITY + VIO1_ISP_W1_QOS);
  39. }
  40. return 0;
  41. }
  42. static void rk3288_detect_reset_reason(void)
  43. {
  44. struct rk3288_cru *cru = rockchip_get_cru();
  45. const char *reason;
  46. if (IS_ERR(cru))
  47. return;
  48. switch (cru->cru_glb_rst_st) {
  49. case GLB_POR_RST:
  50. reason = "POR";
  51. break;
  52. case FST_GLB_RST_ST:
  53. case SND_GLB_RST_ST:
  54. reason = "RST";
  55. break;
  56. case FST_GLB_TSADC_RST_ST:
  57. case SND_GLB_TSADC_RST_ST:
  58. reason = "THERMAL";
  59. break;
  60. case FST_GLB_WDT_RST_ST:
  61. case SND_GLB_WDT_RST_ST:
  62. reason = "WDOG";
  63. break;
  64. default:
  65. reason = "unknown reset";
  66. }
  67. env_set("reset_reason", reason);
  68. /*
  69. * Clear cru_glb_rst_st, so we can determine the last reset cause
  70. * for following resets.
  71. */
  72. rk_clrreg(&cru->cru_glb_rst_st, GLB_RST_ST_MASK);
  73. }
  74. int board_late_init(void)
  75. {
  76. setup_boot_mode();
  77. rk3288_qos_init();
  78. rk3288_detect_reset_reason();
  79. return rk_board_late_init();
  80. }
  81. #if !CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
  82. static int veyron_init(void)
  83. {
  84. struct udevice *dev;
  85. struct clk clk;
  86. int ret;
  87. ret = regulator_get_by_platname("vdd_arm", &dev);
  88. if (ret) {
  89. debug("Cannot set regulator name\n");
  90. return ret;
  91. }
  92. /* Slowly raise to max CPU voltage to prevent overshoot */
  93. ret = regulator_set_value(dev, 1200000);
  94. if (ret)
  95. return ret;
  96. udelay(175); /* Must wait for voltage to stabilize, 2mV/us */
  97. ret = regulator_set_value(dev, 1400000);
  98. if (ret)
  99. return ret;
  100. udelay(100); /* Must wait for voltage to stabilize, 2mV/us */
  101. ret = rockchip_get_clk(&clk.dev);
  102. if (ret)
  103. return ret;
  104. clk.id = PLL_APLL;
  105. ret = clk_set_rate(&clk, 1800000000);
  106. if (IS_ERR_VALUE(ret))
  107. return ret;
  108. return 0;
  109. }
  110. #endif
  111. int board_init(void)
  112. {
  113. #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM)
  114. struct udevice *pinctrl;
  115. int ret;
  116. /*
  117. * We need to implement sdcard iomux here for the further
  118. * initlization, otherwise, it'll hit sdcard command sending
  119. * timeout exception.
  120. */
  121. ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
  122. if (ret) {
  123. debug("%s: Cannot find pinctrl device\n", __func__);
  124. goto err;
  125. }
  126. ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD);
  127. if (ret) {
  128. debug("%s: Failed to set up SD card\n", __func__);
  129. goto err;
  130. }
  131. return 0;
  132. err:
  133. printf("board_init: Error %d\n", ret);
  134. /* No way to report error here */
  135. hang();
  136. return -1;
  137. #else
  138. int ret;
  139. /* We do some SoC one time setting here */
  140. if (!fdt_node_check_compatible(gd->fdt_blob, 0, "google,veyron")) {
  141. ret = veyron_init();
  142. if (ret)
  143. return ret;
  144. }
  145. return 0;
  146. #endif
  147. }
  148. #ifndef CONFIG_SYS_DCACHE_OFF
  149. void enable_caches(void)
  150. {
  151. /* Enable D-cache. I-cache is already enabled in start.S */
  152. dcache_enable();
  153. }
  154. #endif
  155. #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
  156. #include <usb.h>
  157. #include <usb/dwc2_udc.h>
  158. static struct dwc2_plat_otg_data rk3288_otg_data = {
  159. .rx_fifo_sz = 512,
  160. .np_tx_fifo_sz = 16,
  161. .tx_fifo_sz = 128,
  162. };
  163. int board_usb_init(int index, enum usb_init_type init)
  164. {
  165. int node, phy_node;
  166. const char *mode;
  167. bool matched = false;
  168. const void *blob = gd->fdt_blob;
  169. u32 grf_phy_offset;
  170. /* find the usb_otg node */
  171. node = fdt_node_offset_by_compatible(blob, -1,
  172. "rockchip,rk3288-usb");
  173. while (node > 0) {
  174. mode = fdt_getprop(blob, node, "dr_mode", NULL);
  175. if (mode && strcmp(mode, "otg") == 0) {
  176. matched = true;
  177. break;
  178. }
  179. node = fdt_node_offset_by_compatible(blob, node,
  180. "rockchip,rk3288-usb");
  181. }
  182. if (!matched) {
  183. debug("Not found usb_otg device\n");
  184. return -ENODEV;
  185. }
  186. rk3288_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
  187. node = fdtdec_lookup_phandle(blob, node, "phys");
  188. if (node <= 0) {
  189. debug("Not found usb phy device\n");
  190. return -ENODEV;
  191. }
  192. phy_node = fdt_parent_offset(blob, node);
  193. if (phy_node <= 0) {
  194. debug("Not found usb phy device\n");
  195. return -ENODEV;
  196. }
  197. rk3288_otg_data.phy_of_node = phy_node;
  198. grf_phy_offset = fdtdec_get_addr(blob, node, "reg");
  199. /* find the grf node */
  200. node = fdt_node_offset_by_compatible(blob, -1,
  201. "rockchip,rk3288-grf");
  202. if (node <= 0) {
  203. debug("Not found grf device\n");
  204. return -ENODEV;
  205. }
  206. rk3288_otg_data.regs_phy = grf_phy_offset +
  207. fdtdec_get_addr(blob, node, "reg");
  208. return dwc2_udc_probe(&rk3288_otg_data);
  209. }
  210. int board_usb_cleanup(int index, enum usb_init_type init)
  211. {
  212. return 0;
  213. }
  214. #endif
  215. static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc,
  216. char * const argv[])
  217. {
  218. static const struct {
  219. char *name;
  220. int id;
  221. } clks[] = {
  222. { "osc", CLK_OSC },
  223. { "apll", CLK_ARM },
  224. { "dpll", CLK_DDR },
  225. { "cpll", CLK_CODEC },
  226. { "gpll", CLK_GENERAL },
  227. #ifdef CONFIG_ROCKCHIP_RK3036
  228. { "mpll", CLK_NEW },
  229. #else
  230. { "npll", CLK_NEW },
  231. #endif
  232. };
  233. int ret, i;
  234. struct udevice *dev;
  235. ret = rockchip_get_clk(&dev);
  236. if (ret) {
  237. printf("clk-uclass not found\n");
  238. return 0;
  239. }
  240. for (i = 0; i < ARRAY_SIZE(clks); i++) {
  241. struct clk clk;
  242. ulong rate;
  243. clk.id = clks[i].id;
  244. ret = clk_request(dev, &clk);
  245. if (ret < 0)
  246. continue;
  247. rate = clk_get_rate(&clk);
  248. printf("%s: %lu\n", clks[i].name, rate);
  249. clk_free(&clk);
  250. }
  251. return 0;
  252. }
  253. U_BOOT_CMD(
  254. clock, 2, 1, do_clock,
  255. "display information about clocks",
  256. ""
  257. );
  258. #define GRF_SOC_CON2 0xff77024c
  259. int board_early_init_f(void)
  260. {
  261. struct udevice *pinctrl;
  262. struct udevice *dev;
  263. int ret;
  264. /*
  265. * This init is done in SPL, but when chain-loading U-Boot SPL will
  266. * have been skipped. Allow the clock driver to check if it needs
  267. * setting up.
  268. */
  269. ret = rockchip_get_clk(&dev);
  270. if (ret) {
  271. debug("CLK init failed: %d\n", ret);
  272. return ret;
  273. }
  274. ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
  275. if (ret) {
  276. debug("%s: Cannot find pinctrl device\n", __func__);
  277. return ret;
  278. }
  279. /* Enable debug UART */
  280. ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_UART_DBG);
  281. if (ret) {
  282. debug("%s: Failed to set up console UART\n", __func__);
  283. return ret;
  284. }
  285. rk_setreg(GRF_SOC_CON2, 1 << 0);
  286. return 0;
  287. }