init.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. static void msmc_k2hkle_common_setup(void)
  83. {
  84. msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_ARM);
  85. msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_NETCP);
  86. #ifdef KS2_MSMC_SEGMENT_QM_PDSP
  87. msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_QM_PDSP);
  88. #endif
  89. msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_PCIE0);
  90. }
  91. static inline void msmc_k2l_setup(void)
  92. {
  93. msmc_share_all_segments(K2L_MSMC_SEGMENT_PCIE1);
  94. }
  95. static inline void msmc_k2e_setup(void)
  96. {
  97. msmc_share_all_segments(K2E_MSMC_SEGMENT_PCIE1);
  98. }
  99. static inline void msmc_k2g_setup(void)
  100. {
  101. msmc_share_all_segments(K2G_MSMC_SEGMENT_ARM);
  102. msmc_share_all_segments(K2G_MSMC_SEGMENT_NSS);
  103. msmc_share_all_segments(K2G_MSMC_SEGMENT_PCIE);
  104. }
  105. int arch_cpu_init(void)
  106. {
  107. chip_configuration_unlock();
  108. icache_enable();
  109. if (cpu_is_k2g()) {
  110. msmc_k2g_setup();
  111. } else {
  112. msmc_k2hkle_common_setup();
  113. if (cpu_is_k2e())
  114. msmc_k2e_setup();
  115. else if (cpu_is_k2l())
  116. msmc_k2l_setup();
  117. }
  118. /* Initialize the PCIe-0 to work as Root Complex */
  119. config_pcie_mode(0, ROOTCOMPLEX);
  120. #if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
  121. /* Initialize the PCIe-1 to work as Root Complex */
  122. config_pcie_mode(1, ROOTCOMPLEX);
  123. #endif
  124. #ifdef CONFIG_SOC_K2L
  125. osr_init();
  126. #endif
  127. /*
  128. * just initialise the COM2 port so that TI specific
  129. * UART register PWREMU_MGMT is initialized. Linux UART
  130. * driver doesn't handle this.
  131. */
  132. #ifndef CONFIG_DM_SERIAL
  133. NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2),
  134. CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
  135. #endif
  136. return 0;
  137. }
  138. void reset_cpu(ulong addr)
  139. {
  140. volatile u32 *rstctrl = (volatile u32 *)(KS2_RSTCTRL);
  141. u32 tmp;
  142. tmp = *rstctrl & KS2_RSTCTRL_MASK;
  143. *rstctrl = tmp | KS2_RSTCTRL_KEY;
  144. *rstctrl &= KS2_RSTCTRL_SWRST;
  145. for (;;)
  146. ;
  147. }
  148. void enable_caches(void)
  149. {
  150. #ifndef CONFIG_SYS_DCACHE_OFF
  151. /* Enable D-cache. I-cache is already enabled in start.S */
  152. dcache_enable();
  153. #endif
  154. }
  155. #if defined(CONFIG_DISPLAY_CPUINFO)
  156. int print_cpuinfo(void)
  157. {
  158. u16 cpu = get_part_number();
  159. u8 rev = cpu_revision();
  160. puts("CPU: ");
  161. switch (cpu) {
  162. case CPU_66AK2Hx:
  163. puts("66AK2Hx SR");
  164. break;
  165. case CPU_66AK2Lx:
  166. puts("66AK2Lx SR");
  167. break;
  168. case CPU_66AK2Ex:
  169. puts("66AK2Ex SR");
  170. break;
  171. case CPU_66AK2Gx:
  172. puts("66AK2Gx SR");
  173. break;
  174. default:
  175. puts("Unknown\n");
  176. }
  177. if (rev == 2)
  178. puts("2.0\n");
  179. else if (rev == 1)
  180. puts("1.1\n");
  181. else if (rev == 0)
  182. puts("1.0\n");
  183. return 0;
  184. }
  185. #endif