init.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Keystone2: Architecture initialization
  4. *
  5. * (C) Copyright 2012-2014
  6. * Texas Instruments Incorporated, <www.ti.com>
  7. */
  8. #include <common.h>
  9. #include <ns16550.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/msmc.h>
  12. #include <asm/arch/clock.h>
  13. #include <asm/arch/hardware.h>
  14. #include <asm/arch/psc_defs.h>
  15. #define MAX_PCI_PORTS 2
  16. enum pci_mode {
  17. ENDPOINT,
  18. LEGACY_ENDPOINT,
  19. ROOTCOMPLEX,
  20. };
  21. #define DEVCFG_MODE_MASK (BIT(2) | BIT(1))
  22. #define DEVCFG_MODE_SHIFT 1
  23. void chip_configuration_unlock(void)
  24. {
  25. __raw_writel(KS2_KICK0_MAGIC, KS2_KICK0);
  26. __raw_writel(KS2_KICK1_MAGIC, KS2_KICK1);
  27. }
  28. #ifdef CONFIG_SOC_K2L
  29. void osr_init(void)
  30. {
  31. u32 i;
  32. u32 j;
  33. u32 val;
  34. u32 base = KS2_OSR_CFG_BASE;
  35. u32 ecc_ctrl[KS2_OSR_NUM_RAM_BANKS];
  36. /* Enable the OSR clock domain */
  37. psc_enable_module(KS2_LPSC_OSR);
  38. /* Disable OSR ECC check for all the ram banks */
  39. for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++) {
  40. val = i | KS2_OSR_ECC_VEC_TRIG_RD |
  41. (KS2_OSR_ECC_CTRL << KS2_OSR_ECC_VEC_RD_ADDR_SH);
  42. writel(val , base + KS2_OSR_ECC_VEC);
  43. /**
  44. * wait till read is done.
  45. * Print should be added after earlyprintk support is added.
  46. */
  47. for (j = 0; j < 10000; j++) {
  48. val = readl(base + KS2_OSR_ECC_VEC);
  49. if (val & KS2_OSR_ECC_VEC_RD_DONE)
  50. break;
  51. }
  52. ecc_ctrl[i] = readl(base + KS2_OSR_ECC_CTRL) ^
  53. KS2_OSR_ECC_CTRL_CHK;
  54. writel(ecc_ctrl[i], KS2_MSMC_DATA_BASE + i * 4);
  55. writel(ecc_ctrl[i], base + KS2_OSR_ECC_CTRL);
  56. }
  57. /* Reset OSR memory to all zeros */
  58. for (i = 0; i < KS2_OSR_SIZE; i += 4)
  59. writel(0, KS2_OSR_DATA_BASE + i);
  60. /* Enable OSR ECC check for all the ram banks */
  61. for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++)
  62. writel(ecc_ctrl[i] |
  63. KS2_OSR_ECC_CTRL_CHK, base + KS2_OSR_ECC_CTRL);
  64. }
  65. #endif
  66. /* Function to set up PCIe mode */
  67. static void config_pcie_mode(int pcie_port, enum pci_mode mode)
  68. {
  69. u32 val = __raw_readl(KS2_DEVCFG);
  70. if (pcie_port >= MAX_PCI_PORTS)
  71. return;
  72. /**
  73. * each pci port has two bits for mode and it starts at
  74. * bit 1. So use port number to get the right bit position.
  75. */
  76. pcie_port <<= 1;
  77. val &= ~(DEVCFG_MODE_MASK << pcie_port);
  78. val |= ((mode << DEVCFG_MODE_SHIFT) << pcie_port);
  79. __raw_writel(val, KS2_DEVCFG);
  80. }
  81. static void msmc_k2hkle_common_setup(void)
  82. {
  83. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
  84. msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_ARM);
  85. msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_NETCP);
  86. msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_QM_PDSP);
  87. msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_PCIE0);
  88. msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
  89. }
  90. static void msmc_k2hk_setup(void)
  91. {
  92. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_1);
  93. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_2);
  94. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_3);
  95. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_4);
  96. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_5);
  97. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_6);
  98. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_7);
  99. msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
  100. }
  101. static inline void msmc_k2l_setup(void)
  102. {
  103. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_1);
  104. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_2);
  105. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_3);
  106. msmc_share_all_segments(K2L_MSMC_SEGMENT_PCIE1);
  107. }
  108. static inline void msmc_k2e_setup(void)
  109. {
  110. msmc_share_all_segments(K2E_MSMC_SEGMENT_PCIE1);
  111. msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
  112. msmc_share_all_segments(K2E_MSMC_SEGMENT_TSIP);
  113. }
  114. static void msmc_k2g_setup(void)
  115. {
  116. msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
  117. msmc_share_all_segments(K2G_MSMC_SEGMENT_ARM);
  118. msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS0);
  119. msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS1);
  120. msmc_share_all_segments(K2G_MSMC_SEGMENT_NSS);
  121. msmc_share_all_segments(K2G_MSMC_SEGMENT_PCIE);
  122. msmc_share_all_segments(K2G_MSMC_SEGMENT_USB);
  123. msmc_share_all_segments(K2G_MSMC_SEGMENT_MLB);
  124. msmc_share_all_segments(K2G_MSMC_SEGMENT_PMMC);
  125. msmc_share_all_segments(K2G_MSMC_SEGMENT_DSS);
  126. msmc_share_all_segments(K2G_MSMC_SEGMENT_MMC);
  127. msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
  128. }
  129. int arch_cpu_init(void)
  130. {
  131. chip_configuration_unlock();
  132. icache_enable();
  133. if (cpu_is_k2g()) {
  134. msmc_k2g_setup();
  135. } else {
  136. msmc_k2hkle_common_setup();
  137. if (cpu_is_k2e())
  138. msmc_k2e_setup();
  139. else if (cpu_is_k2l())
  140. msmc_k2l_setup();
  141. else
  142. msmc_k2hk_setup();
  143. }
  144. /* Initialize the PCIe-0 to work as Root Complex */
  145. config_pcie_mode(0, ROOTCOMPLEX);
  146. #if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
  147. /* Initialize the PCIe-1 to work as Root Complex */
  148. config_pcie_mode(1, ROOTCOMPLEX);
  149. #endif
  150. #ifdef CONFIG_SOC_K2L
  151. osr_init();
  152. #endif
  153. /*
  154. * just initialise the COM2 port so that TI specific
  155. * UART register PWREMU_MGMT is initialized. Linux UART
  156. * driver doesn't handle this.
  157. */
  158. #ifndef CONFIG_DM_SERIAL
  159. NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2),
  160. CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
  161. #endif
  162. return 0;
  163. }
  164. void reset_cpu(ulong addr)
  165. {
  166. volatile u32 *rstctrl = (volatile u32 *)(KS2_RSTCTRL);
  167. u32 tmp;
  168. tmp = *rstctrl & KS2_RSTCTRL_MASK;
  169. *rstctrl = tmp | KS2_RSTCTRL_KEY;
  170. *rstctrl &= KS2_RSTCTRL_SWRST;
  171. for (;;)
  172. ;
  173. }
  174. void enable_caches(void)
  175. {
  176. #ifndef CONFIG_SYS_DCACHE_OFF
  177. /* Enable D-cache. I-cache is already enabled in start.S */
  178. dcache_enable();
  179. #endif
  180. }
  181. #if defined(CONFIG_DISPLAY_CPUINFO)
  182. int print_cpuinfo(void)
  183. {
  184. u16 cpu = get_part_number();
  185. u8 rev = cpu_revision();
  186. puts("CPU: ");
  187. switch (cpu) {
  188. case CPU_66AK2Hx:
  189. puts("66AK2Hx SR");
  190. break;
  191. case CPU_66AK2Lx:
  192. puts("66AK2Lx SR");
  193. break;
  194. case CPU_66AK2Ex:
  195. puts("66AK2Ex SR");
  196. break;
  197. case CPU_66AK2Gx:
  198. puts("66AK2Gx");
  199. #ifdef CONFIG_SOC_K2G
  200. {
  201. int speed = get_max_arm_speed(speeds);
  202. if (speed == SPD1000)
  203. puts("-100 ");
  204. else if (speed == SPD600)
  205. puts("-60 ");
  206. else
  207. puts("-xx ");
  208. }
  209. #endif
  210. puts("SR");
  211. break;
  212. default:
  213. puts("Unknown\n");
  214. }
  215. if (rev == 2)
  216. puts("2.0\n");
  217. else if (rev == 1)
  218. puts("1.1\n");
  219. else if (rev == 0)
  220. puts("1.0\n");
  221. else if (rev == 8)
  222. puts("1.0\n");
  223. return 0;
  224. }
  225. #endif