rk3036-board.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * (C) Copyright 2015 Rockchip Electronics Co., Ltd
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <clk.h>
  8. #include <dm.h>
  9. #include <ram.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/clock.h>
  12. #include <asm/arch/periph.h>
  13. #include <asm/arch/grf_rk3036.h>
  14. #include <asm/arch/boot_mode.h>
  15. #include <asm/arch/sdram_rk3036.h>
  16. #include <asm/gpio.h>
  17. #include <dm/pinctrl.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. #define GRF_BASE 0x20008000
  20. static void setup_boot_mode(void)
  21. {
  22. struct rk3036_grf *const grf = (void *)GRF_BASE;
  23. int boot_mode = readl(&grf->os_reg[4]);
  24. debug("boot mode %x.\n", boot_mode);
  25. /* Clear boot mode */
  26. writel(BOOT_NORMAL, &grf->os_reg[4]);
  27. switch (boot_mode) {
  28. case BOOT_FASTBOOT:
  29. printf("enter fastboot!\n");
  30. setenv("preboot", "setenv preboot; fastboot usb0");
  31. break;
  32. case BOOT_UMS:
  33. printf("enter UMS!\n");
  34. setenv("preboot", "setenv preboot; ums mmc 0");
  35. break;
  36. }
  37. }
  38. __weak int rk_board_late_init(void)
  39. {
  40. return 0;
  41. }
  42. int board_late_init(void)
  43. {
  44. setup_boot_mode();
  45. return rk_board_late_init();
  46. }
  47. int board_init(void)
  48. {
  49. return 0;
  50. }
  51. int dram_init(void)
  52. {
  53. gd->ram_size = sdram_size();
  54. return 0;
  55. }
  56. #ifndef CONFIG_SYS_DCACHE_OFF
  57. void enable_caches(void)
  58. {
  59. /* Enable D-cache. I-cache is already enabled in start.S */
  60. dcache_enable();
  61. }
  62. #endif
  63. #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
  64. #include <usb.h>
  65. #include <usb/dwc2_udc.h>
  66. static struct dwc2_plat_otg_data rk3036_otg_data = {
  67. .rx_fifo_sz = 512,
  68. .np_tx_fifo_sz = 16,
  69. .tx_fifo_sz = 128,
  70. };
  71. int board_usb_init(int index, enum usb_init_type init)
  72. {
  73. int node;
  74. const char *mode;
  75. bool matched = false;
  76. const void *blob = gd->fdt_blob;
  77. /* find the usb_otg node */
  78. node = fdt_node_offset_by_compatible(blob, -1,
  79. "rockchip,rk3288-usb");
  80. while (node > 0) {
  81. mode = fdt_getprop(blob, node, "dr_mode", NULL);
  82. if (mode && strcmp(mode, "otg") == 0) {
  83. matched = true;
  84. break;
  85. }
  86. node = fdt_node_offset_by_compatible(blob, node,
  87. "rockchip,rk3288-usb");
  88. }
  89. if (!matched) {
  90. debug("Not found usb_otg device\n");
  91. return -ENODEV;
  92. }
  93. rk3036_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
  94. return dwc2_udc_probe(&rk3036_otg_data);
  95. }
  96. int board_usb_cleanup(int index, enum usb_init_type init)
  97. {
  98. return 0;
  99. }
  100. #endif