poplar.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2017 Linaro
  4. * Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
  5. */
  6. #include <dm.h>
  7. #include <common.h>
  8. #include <asm/io.h>
  9. #include <dm/platform_data/serial_pl01x.h>
  10. #include <asm/arch/hi3798cv200.h>
  11. #include <asm/arch/dwmmc.h>
  12. #include <asm/armv8/mmu.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. static struct mm_region poplar_mem_map[] = {
  15. {
  16. .virt = 0x0UL,
  17. .phys = 0x0UL,
  18. .size = 0x80000000UL,
  19. .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  20. PTE_BLOCK_INNER_SHARE
  21. }, {
  22. .virt = 0x80000000UL,
  23. .phys = 0x80000000UL,
  24. .size = 0x80000000UL,
  25. .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
  26. PTE_BLOCK_NON_SHARE |
  27. PTE_BLOCK_PXN | PTE_BLOCK_UXN
  28. }, {
  29. 0,
  30. }
  31. };
  32. struct mm_region *mem_map = poplar_mem_map;
  33. static const struct pl01x_serial_platdata serial_platdata = {
  34. .base = REG_BASE_UART0,
  35. .type = TYPE_PL010,
  36. .clock = 75000000,
  37. };
  38. U_BOOT_DEVICE(poplar_serial) = {
  39. .name = "serial_pl01x",
  40. .platdata = &serial_platdata,
  41. };
  42. int checkboard(void)
  43. {
  44. puts("BOARD: Hisilicon HI3798cv200 Poplar\n");
  45. return 0;
  46. }
  47. void reset_cpu(ulong addr)
  48. {
  49. psci_system_reset();
  50. }
  51. int dram_init(void)
  52. {
  53. gd->ram_size = get_ram_size(NULL, 0x80000000);
  54. return 0;
  55. }
  56. /*
  57. * Some linux kernel versions don't use memory before its load address, so to
  58. * be generic we just pretend it isn't there. In previous uboot versions we
  59. * carved the space used by BL31 (runs in DDR on this platfomr) so the PSCI code
  60. * could persist in memory and be left alone by the kernel.
  61. *
  62. * That led to a problem when mapping memory in older kernels. That PSCI code
  63. * now lies in memory below the kernel load offset; it therefore won't be
  64. * touched by the kernel, and by not specially reserving it we avoid the mapping
  65. * problem as well.
  66. *
  67. */
  68. #define KERNEL_TEXT_OFFSET 0x00080000
  69. int dram_init_banksize(void)
  70. {
  71. gd->bd->bi_dram[0].start = KERNEL_TEXT_OFFSET;
  72. gd->bd->bi_dram[0].size = gd->ram_size - gd->bd->bi_dram[0].start;
  73. return 0;
  74. }
  75. static void usb2_phy_config(void)
  76. {
  77. const u32 config[] = {
  78. /* close EOP pre-emphasis. open data pre-emphasis */
  79. 0xa1001c,
  80. /* Rcomp = 150mW, increase DC level */
  81. 0xa00607,
  82. /* keep Rcomp working */
  83. 0xa10700,
  84. /* Icomp = 212mW, increase current drive */
  85. 0xa00aab,
  86. /* EMI fix: rx_active not stay 1 when error packets received */
  87. 0xa11140,
  88. /* Comp mode select */
  89. 0xa11041,
  90. /* adjust eye diagram */
  91. 0xa0098c,
  92. /* adjust eye diagram */
  93. 0xa10a0a,
  94. };
  95. int i;
  96. for (i = 0; i < ARRAY_SIZE(config); i++) {
  97. writel(config[i], PERI_CTRL_USB0);
  98. clrsetbits_le32(PERI_CTRL_USB0, BIT(21), BIT(20) | BIT(22));
  99. udelay(20);
  100. }
  101. }
  102. static void usb2_phy_init(void)
  103. {
  104. /* reset usb2 controller bus/utmi/roothub */
  105. setbits_le32(PERI_CRG46, USB2_BUS_SRST_REQ | USB2_UTMI0_SRST_REQ |
  106. USB2_HST_PHY_SYST_REQ | USB2_OTG_PHY_SYST_REQ);
  107. udelay(200);
  108. /* reset usb2 phy por/utmi */
  109. setbits_le32(PERI_CRG47, USB2_PHY01_SRST_REQ | USB2_PHY01_SRST_TREQ1);
  110. udelay(200);
  111. /* open usb2 ref clk */
  112. setbits_le32(PERI_CRG47, USB2_PHY01_REF_CKEN);
  113. udelay(300);
  114. /* cancel usb2 power on reset */
  115. clrbits_le32(PERI_CRG47, USB2_PHY01_SRST_REQ);
  116. udelay(500);
  117. usb2_phy_config();
  118. /* cancel usb2 port reset, wait comp circuit stable */
  119. clrbits_le32(PERI_CRG47, USB2_PHY01_SRST_TREQ1);
  120. mdelay(10);
  121. /* open usb2 controller clk */
  122. setbits_le32(PERI_CRG46, USB2_BUS_CKEN | USB2_OHCI48M_CKEN |
  123. USB2_OHCI12M_CKEN | USB2_OTG_UTMI_CKEN |
  124. USB2_HST_PHY_CKEN | USB2_UTMI0_CKEN);
  125. udelay(200);
  126. /* cancel usb2 control reset */
  127. clrbits_le32(PERI_CRG46, USB2_BUS_SRST_REQ | USB2_UTMI0_SRST_REQ |
  128. USB2_HST_PHY_SYST_REQ | USB2_OTG_PHY_SYST_REQ);
  129. udelay(200);
  130. }
  131. int board_mmc_init(bd_t *bis)
  132. {
  133. int ret;
  134. ret = hi6220_dwmci_add_port(0, REG_BASE_MCI, 8);
  135. if (ret)
  136. printf("mmc init error (%d)\n", ret);
  137. return ret;
  138. }
  139. int board_init(void)
  140. {
  141. usb2_phy_init();
  142. return 0;
  143. }