blob: 39afaaa63d613fe4a157cc63a53dcb030f3f0c35 [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
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.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>
Simon Glass4dcacfc2020-05-10 11:40:13 -060018#include <linux/bitops.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040019
Karicheri, Muralidharan54a55122014-12-09 14:32:26 -050020#define MAX_PCI_PORTS 2
21enum pci_mode {
22 ENDPOINT,
23 LEGACY_ENDPOINT,
24 ROOTCOMPLEX,
25};
26
27#define DEVCFG_MODE_MASK (BIT(2) | BIT(1))
28#define DEVCFG_MODE_SHIFT 1
29
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040030void chip_configuration_unlock(void)
31{
Khoronzhuk, Ivand5cb1bb2014-07-09 23:44:44 +030032 __raw_writel(KS2_KICK0_MAGIC, KS2_KICK0);
33 __raw_writel(KS2_KICK1_MAGIC, KS2_KICK1);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040034}
35
Hao Zhangd5dff712014-10-22 16:32:32 +030036#ifdef CONFIG_SOC_K2L
37void osr_init(void)
38{
39 u32 i;
40 u32 j;
41 u32 val;
42 u32 base = KS2_OSR_CFG_BASE;
43 u32 ecc_ctrl[KS2_OSR_NUM_RAM_BANKS];
44
45 /* Enable the OSR clock domain */
46 psc_enable_module(KS2_LPSC_OSR);
47
48 /* Disable OSR ECC check for all the ram banks */
49 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++) {
50 val = i | KS2_OSR_ECC_VEC_TRIG_RD |
51 (KS2_OSR_ECC_CTRL << KS2_OSR_ECC_VEC_RD_ADDR_SH);
52
53 writel(val , base + KS2_OSR_ECC_VEC);
54
55 /**
56 * wait till read is done.
57 * Print should be added after earlyprintk support is added.
58 */
59 for (j = 0; j < 10000; j++) {
60 val = readl(base + KS2_OSR_ECC_VEC);
61 if (val & KS2_OSR_ECC_VEC_RD_DONE)
62 break;
63 }
64
65 ecc_ctrl[i] = readl(base + KS2_OSR_ECC_CTRL) ^
66 KS2_OSR_ECC_CTRL_CHK;
67
68 writel(ecc_ctrl[i], KS2_MSMC_DATA_BASE + i * 4);
69 writel(ecc_ctrl[i], base + KS2_OSR_ECC_CTRL);
70 }
71
72 /* Reset OSR memory to all zeros */
73 for (i = 0; i < KS2_OSR_SIZE; i += 4)
74 writel(0, KS2_OSR_DATA_BASE + i);
75
76 /* Enable OSR ECC check for all the ram banks */
77 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++)
78 writel(ecc_ctrl[i] |
79 KS2_OSR_ECC_CTRL_CHK, base + KS2_OSR_ECC_CTRL);
80}
81#endif
82
Karicheri, Muralidharan54a55122014-12-09 14:32:26 -050083/* Function to set up PCIe mode */
84static void config_pcie_mode(int pcie_port, enum pci_mode mode)
85{
86 u32 val = __raw_readl(KS2_DEVCFG);
87
88 if (pcie_port >= MAX_PCI_PORTS)
89 return;
90
91 /**
92 * each pci port has two bits for mode and it starts at
93 * bit 1. So use port number to get the right bit position.
94 */
95 pcie_port <<= 1;
96 val &= ~(DEVCFG_MODE_MASK << pcie_port);
97 val |= ((mode << DEVCFG_MODE_SHIFT) << pcie_port);
98 __raw_writel(val, KS2_DEVCFG);
99}
100
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500101static void msmc_k2hkle_common_setup(void)
102{
Nishanth Menona96497d2016-03-23 10:14:19 -0500103 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500104 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_ARM);
105 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_NETCP);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500106 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_QM_PDSP);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500107 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_PCIE0);
Nishanth Menona96497d2016-03-23 10:14:19 -0500108 msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500109}
110
Nishanth Menona96497d2016-03-23 10:14:19 -0500111static void msmc_k2hk_setup(void)
112{
113 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_1);
114 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_2);
115 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_3);
116 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_4);
117 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_5);
118 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_6);
119 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_7);
120 msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
121}
122
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500123static inline void msmc_k2l_setup(void)
124{
Nishanth Menona96497d2016-03-23 10:14:19 -0500125 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_1);
126 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_2);
127 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_3);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500128 msmc_share_all_segments(K2L_MSMC_SEGMENT_PCIE1);
129}
130
131static inline void msmc_k2e_setup(void)
132{
133 msmc_share_all_segments(K2E_MSMC_SEGMENT_PCIE1);
Nishanth Menona96497d2016-03-23 10:14:19 -0500134 msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
135 msmc_share_all_segments(K2E_MSMC_SEGMENT_TSIP);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500136}
137
Nishanth Menona96497d2016-03-23 10:14:19 -0500138static void msmc_k2g_setup(void)
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500139{
Nishanth Menona96497d2016-03-23 10:14:19 -0500140 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500141 msmc_share_all_segments(K2G_MSMC_SEGMENT_ARM);
Nishanth Menona96497d2016-03-23 10:14:19 -0500142 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS0);
143 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS1);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500144 msmc_share_all_segments(K2G_MSMC_SEGMENT_NSS);
145 msmc_share_all_segments(K2G_MSMC_SEGMENT_PCIE);
Nishanth Menona96497d2016-03-23 10:14:19 -0500146 msmc_share_all_segments(K2G_MSMC_SEGMENT_USB);
147 msmc_share_all_segments(K2G_MSMC_SEGMENT_MLB);
148 msmc_share_all_segments(K2G_MSMC_SEGMENT_PMMC);
149 msmc_share_all_segments(K2G_MSMC_SEGMENT_DSS);
150 msmc_share_all_segments(K2G_MSMC_SEGMENT_MMC);
151 msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500152}
153
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400154int arch_cpu_init(void)
155{
156 chip_configuration_unlock();
157 icache_enable();
158
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500159 if (cpu_is_k2g()) {
160 msmc_k2g_setup();
161 } else {
162 msmc_k2hkle_common_setup();
163 if (cpu_is_k2e())
164 msmc_k2e_setup();
165 else if (cpu_is_k2l())
166 msmc_k2l_setup();
Nishanth Menona96497d2016-03-23 10:14:19 -0500167 else
168 msmc_k2hk_setup();
Nishanth Menon1c6686d2016-03-23 10:14:18 -0500169 }
Karicheri, Muralidharan54a55122014-12-09 14:32:26 -0500170
171 /* Initialize the PCIe-0 to work as Root Complex */
172 config_pcie_mode(0, ROOTCOMPLEX);
Hao Zhang9000ea92014-10-22 16:32:30 +0300173#if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
Karicheri, Muralidharan54a55122014-12-09 14:32:26 -0500174 /* Initialize the PCIe-1 to work as Root Complex */
175 config_pcie_mode(1, ROOTCOMPLEX);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400176#endif
Hao Zhangd5dff712014-10-22 16:32:32 +0300177#ifdef CONFIG_SOC_K2L
178 osr_init();
179#endif
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400180
Murali Karicherif90901c2014-05-29 18:57:12 +0300181 /*
182 * just initialise the COM2 port so that TI specific
183 * UART register PWREMU_MGMT is initialized. Linux UART
184 * driver doesn't handle this.
185 */
Lokesh Vutla2c06c3f2015-09-19 15:00:16 +0530186#ifndef CONFIG_DM_SERIAL
Tom Rinidf6a2152022-11-16 13:10:28 -0500187 ns16550_init((struct ns16550 *)(CFG_SYS_NS16550_COM2),
188 CFG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
Lokesh Vutla2c06c3f2015-09-19 15:00:16 +0530189#endif
Murali Karicherif90901c2014-05-29 18:57:12 +0300190
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400191 return 0;
192}
193
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100194void reset_cpu(void)
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400195{
196 volatile u32 *rstctrl = (volatile u32 *)(KS2_RSTCTRL);
197 u32 tmp;
198
199 tmp = *rstctrl & KS2_RSTCTRL_MASK;
200 *rstctrl = tmp | KS2_RSTCTRL_KEY;
201
202 *rstctrl &= KS2_RSTCTRL_SWRST;
203
204 for (;;)
205 ;
206}
207
208void enable_caches(void)
209{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400210#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -0400211 /* Enable D-cache. I-cache is already enabled in start.S */
212 dcache_enable();
213#endif
214}
Lokesh Vutla16451062015-07-28 14:16:42 +0530215
216#if defined(CONFIG_DISPLAY_CPUINFO)
217int print_cpuinfo(void)
218{
219 u16 cpu = get_part_number();
220 u8 rev = cpu_revision();
221
222 puts("CPU: ");
223 switch (cpu) {
224 case CPU_66AK2Hx:
225 puts("66AK2Hx SR");
226 break;
227 case CPU_66AK2Lx:
228 puts("66AK2Lx SR");
229 break;
230 case CPU_66AK2Ex:
231 puts("66AK2Ex SR");
232 break;
Lokesh Vutla05b8e492015-09-19 16:26:38 +0530233 case CPU_66AK2Gx:
Rex Chang4df43d42017-12-28 20:39:59 +0530234 puts("66AK2Gx");
235#ifdef CONFIG_SOC_K2G
236 {
237 int speed = get_max_arm_speed(speeds);
238 if (speed == SPD1000)
239 puts("-100 ");
240 else if (speed == SPD600)
241 puts("-60 ");
242 else
243 puts("-xx ");
244 }
245#endif
246 puts("SR");
Lokesh Vutla05b8e492015-09-19 16:26:38 +0530247 break;
Lokesh Vutla16451062015-07-28 14:16:42 +0530248 default:
249 puts("Unknown\n");
250 }
251
252 if (rev == 2)
253 puts("2.0\n");
254 else if (rev == 1)
255 puts("1.1\n");
256 else if (rev == 0)
257 puts("1.0\n");
Rex Chang4df43d42017-12-28 20:39:59 +0530258 else if (rev == 8)
259 puts("1.0\n");
Lokesh Vutla16451062015-07-28 14:16:42 +0530260 return 0;
261}
262#endif