1 // SPDX-License-Identifier: GPL-2.0+
3 * Keystone2: Architecture initialization
5 * (C) Copyright 2012-2014
6 * Texas Instruments Incorporated, <www.ti.com>
13 #include <asm/cache.h>
15 #include <asm/arch/msmc.h>
16 #include <asm/arch/clock.h>
17 #include <asm/arch/hardware.h>
18 #include <asm/arch/psc_defs.h>
19 #include <linux/bitops.h>
21 #define MAX_PCI_PORTS 2
28 #define DEVCFG_MODE_MASK (BIT(2) | BIT(1))
29 #define DEVCFG_MODE_SHIFT 1
31 void chip_configuration_unlock(void)
33 __raw_writel(KS2_KICK0_MAGIC, KS2_KICK0);
34 __raw_writel(KS2_KICK1_MAGIC, KS2_KICK1);
43 u32 base = KS2_OSR_CFG_BASE;
44 u32 ecc_ctrl[KS2_OSR_NUM_RAM_BANKS];
46 /* Enable the OSR clock domain */
47 psc_enable_module(KS2_LPSC_OSR);
49 /* Disable OSR ECC check for all the ram banks */
50 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++) {
51 val = i | KS2_OSR_ECC_VEC_TRIG_RD |
52 (KS2_OSR_ECC_CTRL << KS2_OSR_ECC_VEC_RD_ADDR_SH);
54 writel(val , base + KS2_OSR_ECC_VEC);
57 * wait till read is done.
58 * Print should be added after earlyprintk support is added.
60 for (j = 0; j < 10000; j++) {
61 val = readl(base + KS2_OSR_ECC_VEC);
62 if (val & KS2_OSR_ECC_VEC_RD_DONE)
66 ecc_ctrl[i] = readl(base + KS2_OSR_ECC_CTRL) ^
69 writel(ecc_ctrl[i], KS2_MSMC_DATA_BASE + i * 4);
70 writel(ecc_ctrl[i], base + KS2_OSR_ECC_CTRL);
73 /* Reset OSR memory to all zeros */
74 for (i = 0; i < KS2_OSR_SIZE; i += 4)
75 writel(0, KS2_OSR_DATA_BASE + i);
77 /* Enable OSR ECC check for all the ram banks */
78 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++)
80 KS2_OSR_ECC_CTRL_CHK, base + KS2_OSR_ECC_CTRL);
84 /* Function to set up PCIe mode */
85 static void config_pcie_mode(int pcie_port, enum pci_mode mode)
87 u32 val = __raw_readl(KS2_DEVCFG);
89 if (pcie_port >= MAX_PCI_PORTS)
93 * each pci port has two bits for mode and it starts at
94 * bit 1. So use port number to get the right bit position.
97 val &= ~(DEVCFG_MODE_MASK << pcie_port);
98 val |= ((mode << DEVCFG_MODE_SHIFT) << pcie_port);
99 __raw_writel(val, KS2_DEVCFG);
102 static void msmc_k2hkle_common_setup(void)
104 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
105 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_ARM);
106 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_NETCP);
107 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_QM_PDSP);
108 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_PCIE0);
109 msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
112 static void msmc_k2hk_setup(void)
114 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_1);
115 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_2);
116 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_3);
117 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_4);
118 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_5);
119 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_6);
120 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_7);
121 msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
124 static inline void msmc_k2l_setup(void)
126 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_1);
127 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_2);
128 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_3);
129 msmc_share_all_segments(K2L_MSMC_SEGMENT_PCIE1);
132 static inline void msmc_k2e_setup(void)
134 msmc_share_all_segments(K2E_MSMC_SEGMENT_PCIE1);
135 msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
136 msmc_share_all_segments(K2E_MSMC_SEGMENT_TSIP);
139 static void msmc_k2g_setup(void)
141 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
142 msmc_share_all_segments(K2G_MSMC_SEGMENT_ARM);
143 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS0);
144 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS1);
145 msmc_share_all_segments(K2G_MSMC_SEGMENT_NSS);
146 msmc_share_all_segments(K2G_MSMC_SEGMENT_PCIE);
147 msmc_share_all_segments(K2G_MSMC_SEGMENT_USB);
148 msmc_share_all_segments(K2G_MSMC_SEGMENT_MLB);
149 msmc_share_all_segments(K2G_MSMC_SEGMENT_PMMC);
150 msmc_share_all_segments(K2G_MSMC_SEGMENT_DSS);
151 msmc_share_all_segments(K2G_MSMC_SEGMENT_MMC);
152 msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
155 int arch_cpu_init(void)
157 chip_configuration_unlock();
163 msmc_k2hkle_common_setup();
166 else if (cpu_is_k2l())
172 /* Initialize the PCIe-0 to work as Root Complex */
173 config_pcie_mode(0, ROOTCOMPLEX);
174 #if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
175 /* Initialize the PCIe-1 to work as Root Complex */
176 config_pcie_mode(1, ROOTCOMPLEX);
178 #ifdef CONFIG_SOC_K2L
183 * just initialise the COM2 port so that TI specific
184 * UART register PWREMU_MGMT is initialized. Linux UART
185 * driver doesn't handle this.
187 #ifndef CONFIG_DM_SERIAL
188 NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2),
189 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
195 void reset_cpu(ulong addr)
197 volatile u32 *rstctrl = (volatile u32 *)(KS2_RSTCTRL);
200 tmp = *rstctrl & KS2_RSTCTRL_MASK;
201 *rstctrl = tmp | KS2_RSTCTRL_KEY;
203 *rstctrl &= KS2_RSTCTRL_SWRST;
209 void enable_caches(void)
211 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
212 /* Enable D-cache. I-cache is already enabled in start.S */
217 #if defined(CONFIG_DISPLAY_CPUINFO)
218 int print_cpuinfo(void)
220 u16 cpu = get_part_number();
221 u8 rev = cpu_revision();
236 #ifdef CONFIG_SOC_K2G
238 int speed = get_max_arm_speed(speeds);
239 if (speed == SPD1000)
241 else if (speed == SPD600)