blob: 88e8912959fa83f14cd09144498624dc6ce3f910 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianovef509b92014-04-04 13:16:53 -04002/*
3 * Keystone2: Architecture initialization
4 *
5 * (C) Copyright 2012-2014
6 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianovef509b92014-04-04 13:16:53 -04007 */
8
9#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -070010#include <cpu_func.h>
Simon Glass691d7192020-05-10 11:40:02 -060011#include <init.h>
Murali Karicheriafee59c2014-05-29 18:57:12 +030012#include <ns16550.h>
Simon Glass90526e92020-05-10 11:39:56 -060013#include <asm/cache.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040014#include <asm/io.h>
Hao Zhang20187fd2014-07-16 00:59:24 +030015#include <asm/arch/msmc.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040016#include <asm/arch/clock.h>
17#include <asm/arch/hardware.h>
Hao Zhangb66604f2014-10-22 16:32:32 +030018#include <asm/arch/psc_defs.h>
Simon Glasscd93d622020-05-10 11:40:13 -060019#include <linux/bitops.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040020
Karicheri, Muralidharan58927a92014-12-09 14:32:26 -050021#define MAX_PCI_PORTS 2
22enum pci_mode {
23 ENDPOINT,
24 LEGACY_ENDPOINT,
25 ROOTCOMPLEX,
26};
27
28#define DEVCFG_MODE_MASK (BIT(2) | BIT(1))
29#define DEVCFG_MODE_SHIFT 1
30
Vitaly Andrianovef509b92014-04-04 13:16:53 -040031void chip_configuration_unlock(void)
32{
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030033 __raw_writel(KS2_KICK0_MAGIC, KS2_KICK0);
34 __raw_writel(KS2_KICK1_MAGIC, KS2_KICK1);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040035}
36
Hao Zhangb66604f2014-10-22 16:32:32 +030037#ifdef CONFIG_SOC_K2L
38void osr_init(void)
39{
40 u32 i;
41 u32 j;
42 u32 val;
43 u32 base = KS2_OSR_CFG_BASE;
44 u32 ecc_ctrl[KS2_OSR_NUM_RAM_BANKS];
45
46 /* Enable the OSR clock domain */
47 psc_enable_module(KS2_LPSC_OSR);
48
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);
53
54 writel(val , base + KS2_OSR_ECC_VEC);
55
56 /**
57 * wait till read is done.
58 * Print should be added after earlyprintk support is added.
59 */
60 for (j = 0; j < 10000; j++) {
61 val = readl(base + KS2_OSR_ECC_VEC);
62 if (val & KS2_OSR_ECC_VEC_RD_DONE)
63 break;
64 }
65
66 ecc_ctrl[i] = readl(base + KS2_OSR_ECC_CTRL) ^
67 KS2_OSR_ECC_CTRL_CHK;
68
69 writel(ecc_ctrl[i], KS2_MSMC_DATA_BASE + i * 4);
70 writel(ecc_ctrl[i], base + KS2_OSR_ECC_CTRL);
71 }
72
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);
76
77 /* Enable OSR ECC check for all the ram banks */
78 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++)
79 writel(ecc_ctrl[i] |
80 KS2_OSR_ECC_CTRL_CHK, base + KS2_OSR_ECC_CTRL);
81}
82#endif
83
Karicheri, Muralidharan58927a92014-12-09 14:32:26 -050084/* Function to set up PCIe mode */
85static void config_pcie_mode(int pcie_port, enum pci_mode mode)
86{
87 u32 val = __raw_readl(KS2_DEVCFG);
88
89 if (pcie_port >= MAX_PCI_PORTS)
90 return;
91
92 /**
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.
95 */
96 pcie_port <<= 1;
97 val &= ~(DEVCFG_MODE_MASK << pcie_port);
98 val |= ((mode << DEVCFG_MODE_SHIFT) << pcie_port);
99 __raw_writel(val, KS2_DEVCFG);
100}
101
Nishanth Menon1f807a92016-03-23 10:14:18 -0500102static void msmc_k2hkle_common_setup(void)
103{
Nishanth Menon22832842016-03-23 10:14:19 -0500104 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500105 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_ARM);
106 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_NETCP);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500107 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_QM_PDSP);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500108 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_PCIE0);
Nishanth Menon22832842016-03-23 10:14:19 -0500109 msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
110}
111
112static void msmc_k2hk_setup(void)
113{
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);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500122}
123
124static inline void msmc_k2l_setup(void)
125{
Nishanth Menon22832842016-03-23 10:14:19 -0500126 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);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500129 msmc_share_all_segments(K2L_MSMC_SEGMENT_PCIE1);
130}
131
132static inline void msmc_k2e_setup(void)
133{
134 msmc_share_all_segments(K2E_MSMC_SEGMENT_PCIE1);
Nishanth Menon22832842016-03-23 10:14:19 -0500135 msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
136 msmc_share_all_segments(K2E_MSMC_SEGMENT_TSIP);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500137}
138
Nishanth Menon22832842016-03-23 10:14:19 -0500139static void msmc_k2g_setup(void)
Nishanth Menon1f807a92016-03-23 10:14:18 -0500140{
Nishanth Menon22832842016-03-23 10:14:19 -0500141 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500142 msmc_share_all_segments(K2G_MSMC_SEGMENT_ARM);
Nishanth Menon22832842016-03-23 10:14:19 -0500143 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS0);
144 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS1);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500145 msmc_share_all_segments(K2G_MSMC_SEGMENT_NSS);
146 msmc_share_all_segments(K2G_MSMC_SEGMENT_PCIE);
Nishanth Menon22832842016-03-23 10:14:19 -0500147 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);
Nishanth Menon1f807a92016-03-23 10:14:18 -0500153}
154
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400155int arch_cpu_init(void)
156{
157 chip_configuration_unlock();
158 icache_enable();
159
Nishanth Menon1f807a92016-03-23 10:14:18 -0500160 if (cpu_is_k2g()) {
161 msmc_k2g_setup();
162 } else {
163 msmc_k2hkle_common_setup();
164 if (cpu_is_k2e())
165 msmc_k2e_setup();
166 else if (cpu_is_k2l())
167 msmc_k2l_setup();
Nishanth Menon22832842016-03-23 10:14:19 -0500168 else
169 msmc_k2hk_setup();
Nishanth Menon1f807a92016-03-23 10:14:18 -0500170 }
Karicheri, Muralidharan58927a92014-12-09 14:32:26 -0500171
172 /* Initialize the PCIe-0 to work as Root Complex */
173 config_pcie_mode(0, ROOTCOMPLEX);
Hao Zhangbc45d572014-10-22 16:32:30 +0300174#if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
Karicheri, Muralidharan58927a92014-12-09 14:32:26 -0500175 /* Initialize the PCIe-1 to work as Root Complex */
176 config_pcie_mode(1, ROOTCOMPLEX);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400177#endif
Hao Zhangb66604f2014-10-22 16:32:32 +0300178#ifdef CONFIG_SOC_K2L
179 osr_init();
180#endif
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400181
Murali Karicheriafee59c2014-05-29 18:57:12 +0300182 /*
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.
186 */
Lokesh Vutla8c80b192015-09-19 15:00:16 +0530187#ifndef CONFIG_DM_SERIAL
Murali Karicheriafee59c2014-05-29 18:57:12 +0300188 NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2),
189 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
Lokesh Vutla8c80b192015-09-19 15:00:16 +0530190#endif
Murali Karicheriafee59c2014-05-29 18:57:12 +0300191
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400192 return 0;
193}
194
195void reset_cpu(ulong addr)
196{
197 volatile u32 *rstctrl = (volatile u32 *)(KS2_RSTCTRL);
198 u32 tmp;
199
200 tmp = *rstctrl & KS2_RSTCTRL_MASK;
201 *rstctrl = tmp | KS2_RSTCTRL_KEY;
202
203 *rstctrl &= KS2_RSTCTRL_SWRST;
204
205 for (;;)
206 ;
207}
208
209void enable_caches(void)
210{
Trevor Woerner10015022019-05-03 09:41:00 -0400211#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400212 /* Enable D-cache. I-cache is already enabled in start.S */
213 dcache_enable();
214#endif
215}
Lokesh Vutlaaeabe652015-07-28 14:16:42 +0530216
217#if defined(CONFIG_DISPLAY_CPUINFO)
218int print_cpuinfo(void)
219{
220 u16 cpu = get_part_number();
221 u8 rev = cpu_revision();
222
223 puts("CPU: ");
224 switch (cpu) {
225 case CPU_66AK2Hx:
226 puts("66AK2Hx SR");
227 break;
228 case CPU_66AK2Lx:
229 puts("66AK2Lx SR");
230 break;
231 case CPU_66AK2Ex:
232 puts("66AK2Ex SR");
233 break;
Lokesh Vutlaf11a3282015-09-19 16:26:38 +0530234 case CPU_66AK2Gx:
Rex Chang4849d952017-12-28 20:39:59 +0530235 puts("66AK2Gx");
236#ifdef CONFIG_SOC_K2G
237 {
238 int speed = get_max_arm_speed(speeds);
239 if (speed == SPD1000)
240 puts("-100 ");
241 else if (speed == SPD600)
242 puts("-60 ");
243 else
244 puts("-xx ");
245 }
246#endif
247 puts("SR");
Lokesh Vutlaf11a3282015-09-19 16:26:38 +0530248 break;
Lokesh Vutlaaeabe652015-07-28 14:16:42 +0530249 default:
250 puts("Unknown\n");
251 }
252
253 if (rev == 2)
254 puts("2.0\n");
255 else if (rev == 1)
256 puts("1.1\n");
257 else if (rev == 0)
258 puts("1.0\n");
Rex Chang4849d952017-12-28 20:39:59 +0530259 else if (rev == 8)
260 puts("1.0\n");
Lokesh Vutlaaeabe652015-07-28 14:16:42 +0530261 return 0;
262}
263#endif