rk3128-board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
  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/periph.h>
  13. #include <asm/arch/grf_rk3128.h>
  14. #include <asm/arch/boot_mode.h>
  15. #include <asm/arch/timer.h>
  16. #include <power/regulator.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. __weak int rk_board_late_init(void)
  19. {
  20. return 0;
  21. }
  22. int board_late_init(void)
  23. {
  24. setup_boot_mode();
  25. return rk_board_late_init();
  26. }
  27. int board_init(void)
  28. {
  29. int ret = 0;
  30. rockchip_timer_init();
  31. ret = regulators_enable_boot_on(false);
  32. if (ret) {
  33. debug("%s: Cannot enable boot on regulator\n", __func__);
  34. return ret;
  35. }
  36. return 0;
  37. }
  38. int dram_init_banksize(void)
  39. {
  40. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  41. gd->bd->bi_dram[0].size = 0x8400000;
  42. /* Reserve 0xe00000(14MB) for OPTEE with TA enabled, otherwise 2MB */
  43. gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE
  44. + gd->bd->bi_dram[0].size + 0xe00000;
  45. gd->bd->bi_dram[1].size = gd->bd->bi_dram[0].start
  46. + gd->ram_size - gd->bd->bi_dram[1].start;
  47. return 0;
  48. }
  49. #ifndef CONFIG_SYS_DCACHE_OFF
  50. void enable_caches(void)
  51. {
  52. /* Enable D-cache. I-cache is already enabled in start.S */
  53. dcache_enable();
  54. }
  55. #endif
  56. #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
  57. #include <usb.h>
  58. #include <usb/dwc2_udc.h>
  59. static struct dwc2_plat_otg_data rk3128_otg_data = {
  60. .rx_fifo_sz = 512,
  61. .np_tx_fifo_sz = 16,
  62. .tx_fifo_sz = 128,
  63. };
  64. int board_usb_init(int index, enum usb_init_type init)
  65. {
  66. int node;
  67. const char *mode;
  68. bool matched = false;
  69. const void *blob = gd->fdt_blob;
  70. /* find the usb_otg node */
  71. node = fdt_node_offset_by_compatible(blob, -1,
  72. "rockchip,rk3128-usb");
  73. while (node > 0) {
  74. mode = fdt_getprop(blob, node, "dr_mode", NULL);
  75. if (mode && strcmp(mode, "otg") == 0) {
  76. matched = true;
  77. break;
  78. }
  79. node = fdt_node_offset_by_compatible(blob, node,
  80. "rockchip,rk3128-usb");
  81. }
  82. if (!matched) {
  83. debug("Not found usb_otg device\n");
  84. return -ENODEV;
  85. }
  86. rk3128_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
  87. return dwc2_udc_probe(&rk3128_otg_data);
  88. }
  89. int board_usb_cleanup(int index, enum usb_init_type init)
  90. {
  91. return 0;
  92. }
  93. #endif
  94. #if CONFIG_IS_ENABLED(FASTBOOT)
  95. int fastboot_set_reboot_flag(void)
  96. {
  97. struct rk3128_grf *grf;
  98. printf("Setting reboot to fastboot flag ...\n");
  99. grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
  100. /* Set boot mode to fastboot */
  101. writel(BOOT_FASTBOOT, &grf->os_reg[0]);
  102. return 0;
  103. }
  104. #endif