init.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Keystone2: Architecture initialization
  3. *
  4. * (C) Copyright 2012-2014
  5. * Texas Instruments Incorporated, <www.ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <ns16550.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/msmc.h>
  13. #include <asm/arch/clock.h>
  14. #include <asm/arch/hardware.h>
  15. #include <asm/arch/psc_defs.h>
  16. #define MAX_PCI_PORTS 2
  17. enum pci_mode {
  18. ENDPOINT,
  19. LEGACY_ENDPOINT,
  20. ROOTCOMPLEX,
  21. };
  22. #define DEVCFG_MODE_MASK (BIT(2) | BIT(1))
  23. #define DEVCFG_MODE_SHIFT 1
  24. void chip_configuration_unlock(void)
  25. {
  26. __raw_writel(KS2_KICK0_MAGIC, KS2_KICK0);
  27. __raw_writel(KS2_KICK1_MAGIC, KS2_KICK1);
  28. }
  29. #ifdef CONFIG_SOC_K2L
  30. void osr_init(void)
  31. {
  32. u32 i;
  33. u32 j;
  34. u32 val;
  35. u32 base = KS2_OSR_CFG_BASE;
  36. u32 ecc_ctrl[KS2_OSR_NUM_RAM_BANKS];
  37. /* Enable the OSR clock domain */
  38. psc_enable_module(KS2_LPSC_OSR);
  39. /* Disable OSR ECC check for all the ram banks */
  40. for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++) {
  41. val = i | KS2_OSR_ECC_VEC_TRIG_RD |
  42. (KS2_OSR_ECC_CTRL << KS2_OSR_ECC_VEC_RD_ADDR_SH);
  43. writel(val , base + KS2_OSR_ECC_VEC);
  44. /**
  45. * wait till read is done.
  46. * Print should be added after earlyprintk support is added.
  47. */
  48. for (j = 0; j < 10000; j++) {
  49. val = readl(base + KS2_OSR_ECC_VEC);
  50. if (val & KS2_OSR_ECC_VEC_RD_DONE)
  51. break;
  52. }
  53. ecc_ctrl[i] = readl(base + KS2_OSR_ECC_CTRL) ^
  54. KS2_OSR_ECC_CTRL_CHK;
  55. writel(ecc_ctrl[i], KS2_MSMC_DATA_BASE + i * 4);
  56. writel(ecc_ctrl[i], base + KS2_OSR_ECC_CTRL);
  57. }
  58. /* Reset OSR memory to all zeros */
  59. for (i = 0; i < KS2_OSR_SIZE; i += 4)
  60. writel(0, KS2_OSR_DATA_BASE + i);
  61. /* Enable OSR ECC check for all the ram banks */
  62. for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++)
  63. writel(ecc_ctrl[i] |
  64. KS2_OSR_ECC_CTRL_CHK, base + KS2_OSR_ECC_CTRL);
  65. }
  66. #endif
  67. /* Function to set up PCIe mode */
  68. static void config_pcie_mode(int pcie_port, enum pci_mode mode)
  69. {
  70. u32 val = __raw_readl(KS2_DEVCFG);
  71. if (pcie_port >= MAX_PCI_PORTS)
  72. return;
  73. /**
  74. * each pci port has two bits for mode and it starts at
  75. * bit 1. So use port number to get the right bit position.
  76. */
  77. pcie_port <<= 1;
  78. val &= ~(DEVCFG_MODE_MASK << pcie_port);
  79. val |= ((mode << DEVCFG_MODE_SHIFT) << pcie_port);
  80. __raw_writel(val, KS2_DEVCFG);
  81. }
  82. int arch_cpu_init(void)
  83. {
  84. chip_configuration_unlock();
  85. icache_enable();
  86. msmc_share_all_segments(KS2_MSMC_SEGMENT_TETRIS);
  87. msmc_share_all_segments(KS2_MSMC_SEGMENT_NETCP);
  88. msmc_share_all_segments(KS2_MSMC_SEGMENT_QM_PDSP);
  89. msmc_share_all_segments(KS2_MSMC_SEGMENT_PCIE0);
  90. /* Initialize the PCIe-0 to work as Root Complex */
  91. config_pcie_mode(0, ROOTCOMPLEX);
  92. #if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
  93. msmc_share_all_segments(KS2_MSMC_SEGMENT_PCIE1);
  94. /* Initialize the PCIe-1 to work as Root Complex */
  95. config_pcie_mode(1, ROOTCOMPLEX);
  96. #endif
  97. #ifdef CONFIG_SOC_K2L
  98. osr_init();
  99. #endif
  100. /*
  101. * just initialise the COM2 port so that TI specific
  102. * UART register PWREMU_MGMT is initialized. Linux UART
  103. * driver doesn't handle this.
  104. */
  105. NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2),
  106. CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
  107. return 0;
  108. }
  109. void reset_cpu(ulong addr)
  110. {
  111. volatile u32 *rstctrl = (volatile u32 *)(KS2_RSTCTRL);
  112. u32 tmp;
  113. tmp = *rstctrl & KS2_RSTCTRL_MASK;
  114. *rstctrl = tmp | KS2_RSTCTRL_KEY;
  115. *rstctrl &= KS2_RSTCTRL_SWRST;
  116. for (;;)
  117. ;
  118. }
  119. void enable_caches(void)
  120. {
  121. #ifndef CONFIG_SYS_DCACHE_OFF
  122. /* Enable D-cache. I-cache is already enabled in start.S */
  123. dcache_enable();
  124. #endif
  125. }
  126. #if defined(CONFIG_DISPLAY_CPUINFO)
  127. int print_cpuinfo(void)
  128. {
  129. u16 cpu = get_part_number();
  130. u8 rev = cpu_revision();
  131. puts("CPU: ");
  132. switch (cpu) {
  133. case CPU_66AK2Hx:
  134. puts("66AK2Hx SR");
  135. break;
  136. case CPU_66AK2Lx:
  137. puts("66AK2Lx SR");
  138. break;
  139. case CPU_66AK2Ex:
  140. puts("66AK2Ex SR");
  141. break;
  142. default:
  143. puts("Unknown\n");
  144. }
  145. if (rev == 2)
  146. puts("2.0\n");
  147. else if (rev == 1)
  148. puts("1.1\n");
  149. else if (rev == 0)
  150. puts("1.0\n");
  151. return 0;
  152. }
  153. #endif