blob: 59fd029e4c9f8517176ad47bb232eee178ed3494 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04002/*
3 * Keystone2: Architecture initialization
4 *
5 * (C) Copyright 2012-2014
6 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04007 */
8
9#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070010#include <cpu_func.h>
Murali Karicherif90901c2014-05-29 18:57:12 +030011#include <ns16550.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <asm/cache.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040013#include <asm/io.h>
Hao Zhangbccf0b72014-07-16 00:59:24 +030014#include <asm/arch/msmc.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040015#include <asm/arch/clock.h>
16#include <asm/arch/hardware.h>
Hao Zhangd5dff712014-10-22 16:32:32 +030017#include <asm/arch/psc_defs.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040018
Karicheri, Muralidharan54a55122014-12-09 14:32:26 -050019#define MAX_PCI_PORTS 2
20enum pci_mode {
21 ENDPOINT,
22 LEGACY_ENDPOINT,
23 ROOTCOMPLEX,
24};
25
26#define DEVCFG_MODE_MASK (BIT(2) | BIT(1))
27#define DEVCFG_MODE_SHIFT 1
28
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040029void chip_configuration_unlock(void)
30{
Khoronzhuk, Ivand5cb1bb2014-07-09 23:44:44 +030031 __raw_writel(KS2_KICK0_MAGIC, KS2_KICK0);
32 __raw_writel(KS2_KICK1_MAGIC, KS2_KICK1);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040033}
34
Hao Zhangd5dff712014-10-22 16:32:32 +030035#ifdef CONFIG_SOC_K2L
36void osr_init(void)
37{
38 u32 i;
39 u32 j;
40 u32 val;
41 u32 base = KS2_OSR_CFG_BASE;
42 u32 ecc_ctrl[KS2_OSR_NUM_RAM_BANKS];
43
44 /* Enable the OSR clock domain */
45 psc_enable_module(KS2_LPSC_OSR);
46
47 /* Disable OSR ECC check for all the ram banks */
48 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++) {
49 val = i | KS2_OSR_ECC_VEC_TRIG_RD |
50 (KS2_OSR_ECC_CTRL << KS2_OSR_ECC_VEC_RD_ADDR_SH);
51
52 writel(val , base + KS2_OSR_ECC_VEC);
53
54 /**
55 * wait till read is done.
56 * Print should be added after earlyprintk support is added.
57 */
58 for (j = 0; j < 10000; j++) {
59 val = readl(base + KS2_OSR_ECC_VEC);
60 if (val & KS2_OSR_ECC_VEC_RD_DONE)
61 break;
62 }
63
64 ecc_ctrl[i] = readl(base + KS2_OSR_ECC_CTRL) ^
65 KS2_OSR_ECC_CTRL_CHK;
66
67 writel(ecc_ctrl[i], KS2_MSMC_DATA_BASE + i * 4);
68 writel(ecc_ctrl[i], base + KS2_OSR_ECC_CTRL);
69 }
70
71 /* Reset OSR memory to all zeros */
72 for (i = 0; i < KS2_OSR_SIZE; i += 4)
73 writel(0, KS2_OSR_DATA_BASE + i);
74
75 /* Enable OSR ECC check for all the ram banks */
76 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++)
77 writel(ecc_ctrl[i] |
78 KS2_OSR_ECC_CTRL_CHK, base + KS2_OSR_ECC_CTRL);
79}
80#endif
81
Karicheri, Muralidharan54a55122014-12-09 14:32:26 -050082/* Function to set up PCIe mode */
83static void config_pcie_mode(int pcie_port, enum pci_mode mode)
84{
85 u32 val = __raw_readl(KS2_DEVCFG);
86
87 if (pcie_port >= MAX_PCI_PORTS)
88 return;
89
90 /**
91 * each pci port has two bits for mode and it starts at
92 * bit 1. So use port number to get the right bit position.
93 */
94 pcie_port <<= 1;
95 val &= ~(DEVCFG_MODE_MASK << pcie_port);
96 val |= ((mode << DEVCFG_MODE_SHIFT) << pcie_port);
97 __raw_writel(val, KS2_DEVCFG);
98}
99
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500100static void msmc_k2hkle_common_setup(void)
101{
Nishanth Menona96497d2016-03-23 10:14:19 -0500102 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500103 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_ARM);
104 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_NETCP);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500105 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_QM_PDSP);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500106 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_PCIE0);
Nishanth Menona96497d2016-03-23 10:14:19 -0500107 msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500108}
109
Nishanth Menona96497d2016-03-23 10:14:19 -0500110static void msmc_k2hk_setup(void)
111{
112 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_1);
113 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_2);
114 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_3);
115 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_4);
116 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_5);
117 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_6);
118 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_7);
119 msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
120}
121
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500122static inline void msmc_k2l_setup(void)
123{
Nishanth Menona96497d2016-03-23 10:14:19 -0500124 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_1);
125 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_2);
126 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_3);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500127 msmc_share_all_segments(K2L_MSMC_SEGMENT_PCIE1);
128}
129
130static inline void msmc_k2e_setup(void)
131{
132 msmc_share_all_segments(K2E_MSMC_SEGMENT_PCIE1);
Nishanth Menona96497d2016-03-23 10:14:19 -0500133 msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
134 msmc_share_all_segments(K2E_MSMC_SEGMENT_TSIP);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500135}
136
Nishanth Menona96497d2016-03-23 10:14:19 -0500137static void msmc_k2g_setup(void)
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500138{
Nishanth Menona96497d2016-03-23 10:14:19 -0500139 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500140 msmc_share_all_segments(K2G_MSMC_SEGMENT_ARM);
Nishanth Menona96497d2016-03-23 10:14:19 -0500141 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS0);
142 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS1);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500143 msmc_share_all_segments(K2G_MSMC_SEGMENT_NSS);
144 msmc_share_all_segments(K2G_MSMC_SEGMENT_PCIE);
Nishanth Menona96497d2016-03-23 10:14:19 -0500145 msmc_share_all_segments(K2G_MSMC_SEGMENT_USB);
146 msmc_share_all_segments(K2G_MSMC_SEGMENT_MLB);
147 msmc_share_all_segments(K2G_MSMC_SEGMENT_PMMC);
148 msmc_share_all_segments(K2G_MSMC_SEGMENT_DSS);
149 msmc_share_all_segments(K2G_MSMC_SEGMENT_MMC);
150 msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500151}
152
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400153int arch_cpu_init(void)
154{
155 chip_configuration_unlock();
156 icache_enable();
157
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500158 if (cpu_is_k2g()) {
159 msmc_k2g_setup();
160 } else {
161 msmc_k2hkle_common_setup();
162 if (cpu_is_k2e())
163 msmc_k2e_setup();
164 else if (cpu_is_k2l())
165 msmc_k2l_setup();
Nishanth Menona96497d2016-03-23 10:14:19 -0500166 else
167 msmc_k2hk_setup();
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500168 }
Karicheri, Muralidharan54a55122014-12-09 14:32:26 -0500169
170 /* Initialize the PCIe-0 to work as Root Complex */
171 config_pcie_mode(0, ROOTCOMPLEX);
Hao Zhang9000ea92014-10-22 16:32:30 +0300172#if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
Karicheri, Muralidharan54a55122014-12-09 14:32:26 -0500173 /* Initialize the PCIe-1 to work as Root Complex */
174 config_pcie_mode(1, ROOTCOMPLEX);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400175#endif
Hao Zhangd5dff712014-10-22 16:32:32 +0300176#ifdef CONFIG_SOC_K2L
177 osr_init();
178#endif
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400179
Murali Karicherif90901c2014-05-29 18:57:12 +0300180 /*
181 * just initialise the COM2 port so that TI specific
182 * UART register PWREMU_MGMT is initialized. Linux UART
183 * driver doesn't handle this.
184 */
Lokesh Vutla2c06c3f2015-09-19 15:00:16 +0530185#ifndef CONFIG_DM_SERIAL
Murali Karicherif90901c2014-05-29 18:57:12 +0300186 NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2),
187 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
Lokesh Vutla2c06c3f2015-09-19 15:00:16 +0530188#endif
Murali Karicherif90901c2014-05-29 18:57:12 +0300189
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400190 return 0;
191}
192
193void reset_cpu(ulong addr)
194{
195 volatile u32 *rstctrl = (volatile u32 *)(KS2_RSTCTRL);
196 u32 tmp;
197
198 tmp = *rstctrl & KS2_RSTCTRL_MASK;
199 *rstctrl = tmp | KS2_RSTCTRL_KEY;
200
201 *rstctrl &= KS2_RSTCTRL_SWRST;
202
203 for (;;)
204 ;
205}
206
207void enable_caches(void)
208{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400209#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400210 /* Enable D-cache. I-cache is already enabled in start.S */
211 dcache_enable();
212#endif
213}
Lokesh Vutla16451062015-07-28 14:16:42 +0530214
215#if defined(CONFIG_DISPLAY_CPUINFO)
216int print_cpuinfo(void)
217{
218 u16 cpu = get_part_number();
219 u8 rev = cpu_revision();
220
221 puts("CPU: ");
222 switch (cpu) {
223 case CPU_66AK2Hx:
224 puts("66AK2Hx SR");
225 break;
226 case CPU_66AK2Lx:
227 puts("66AK2Lx SR");
228 break;
229 case CPU_66AK2Ex:
230 puts("66AK2Ex SR");
231 break;
Lokesh Vutla05b8e492015-09-19 16:26:38 +0530232 case CPU_66AK2Gx:
Rex Chang4df43d42017-12-28 20:39:59 +0530233 puts("66AK2Gx");
234#ifdef CONFIG_SOC_K2G
235 {
236 int speed = get_max_arm_speed(speeds);
237 if (speed == SPD1000)
238 puts("-100 ");
239 else if (speed == SPD600)
240 puts("-60 ");
241 else
242 puts("-xx ");
243 }
244#endif
245 puts("SR");
Lokesh Vutla05b8e492015-09-19 16:26:38 +0530246 break;
Lokesh Vutla16451062015-07-28 14:16:42 +0530247 default:
248 puts("Unknown\n");
249 }
250
251 if (rev == 2)
252 puts("2.0\n");
253 else if (rev == 1)
254 puts("1.1\n");
255 else if (rev == 0)
256 puts("1.0\n");
Rex Chang4df43d42017-12-28 20:39:59 +0530257 else if (rev == 8)
258 puts("1.0\n");
Lokesh Vutla16451062015-07-28 14:16:42 +0530259 return 0;
260}
261#endif