1
2
3
4
5
6
7
8
9
10#include <common.h>
11#include <ns16550.h>
12#include <asm/io.h>
13#include <asm/arch/msmc.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/hardware.h>
16#include <asm/arch/psc_defs.h>
17
18#define MAX_PCI_PORTS 2
19enum pci_mode {
20 ENDPOINT,
21 LEGACY_ENDPOINT,
22 ROOTCOMPLEX,
23};
24
25#define DEVCFG_MODE_MASK (BIT(2) | BIT(1))
26#define DEVCFG_MODE_SHIFT 1
27
28void chip_configuration_unlock(void)
29{
30 __raw_writel(KS2_KICK0_MAGIC, KS2_KICK0);
31 __raw_writel(KS2_KICK1_MAGIC, KS2_KICK1);
32}
33
34#ifdef CONFIG_SOC_K2L
35void osr_init(void)
36{
37 u32 i;
38 u32 j;
39 u32 val;
40 u32 base = KS2_OSR_CFG_BASE;
41 u32 ecc_ctrl[KS2_OSR_NUM_RAM_BANKS];
42
43
44 psc_enable_module(KS2_LPSC_OSR);
45
46
47 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++) {
48 val = i | KS2_OSR_ECC_VEC_TRIG_RD |
49 (KS2_OSR_ECC_CTRL << KS2_OSR_ECC_VEC_RD_ADDR_SH);
50
51 writel(val , base + KS2_OSR_ECC_VEC);
52
53
54
55
56
57 for (j = 0; j < 10000; j++) {
58 val = readl(base + KS2_OSR_ECC_VEC);
59 if (val & KS2_OSR_ECC_VEC_RD_DONE)
60 break;
61 }
62
63 ecc_ctrl[i] = readl(base + KS2_OSR_ECC_CTRL) ^
64 KS2_OSR_ECC_CTRL_CHK;
65
66 writel(ecc_ctrl[i], KS2_MSMC_DATA_BASE + i * 4);
67 writel(ecc_ctrl[i], base + KS2_OSR_ECC_CTRL);
68 }
69
70
71 for (i = 0; i < KS2_OSR_SIZE; i += 4)
72 writel(0, KS2_OSR_DATA_BASE + i);
73
74
75 for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++)
76 writel(ecc_ctrl[i] |
77 KS2_OSR_ECC_CTRL_CHK, base + KS2_OSR_ECC_CTRL);
78}
79#endif
80
81
82static void config_pcie_mode(int pcie_port, enum pci_mode mode)
83{
84 u32 val = __raw_readl(KS2_DEVCFG);
85
86 if (pcie_port >= MAX_PCI_PORTS)
87 return;
88
89
90
91
92
93 pcie_port <<= 1;
94 val &= ~(DEVCFG_MODE_MASK << pcie_port);
95 val |= ((mode << DEVCFG_MODE_SHIFT) << pcie_port);
96 __raw_writel(val, KS2_DEVCFG);
97}
98
99static void msmc_k2hkle_common_setup(void)
100{
101 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
102 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_ARM);
103 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_NETCP);
104#ifdef KS2_MSMC_SEGMENT_QM_PDSP
105 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_QM_PDSP);
106#endif
107 msmc_share_all_segments(K2HKLE_MSMC_SEGMENT_PCIE0);
108 msmc_share_all_segments(KS2_MSMC_SEGMENT_DEBUG);
109}
110
111static 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
123static inline void msmc_k2l_setup(void)
124{
125 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);
128 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);
134 msmc_share_all_segments(K2HKE_MSMC_SEGMENT_HYPERLINK);
135 msmc_share_all_segments(K2E_MSMC_SEGMENT_TSIP);
136}
137
138static void msmc_k2g_setup(void)
139{
140 msmc_share_all_segments(KS2_MSMC_SEGMENT_C6X_0);
141 msmc_share_all_segments(K2G_MSMC_SEGMENT_ARM);
142 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS0);
143 msmc_share_all_segments(K2G_MSMC_SEGMENT_ICSS1);
144 msmc_share_all_segments(K2G_MSMC_SEGMENT_NSS);
145 msmc_share_all_segments(K2G_MSMC_SEGMENT_PCIE);
146 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);
152}
153
154int arch_cpu_init(void)
155{
156 chip_configuration_unlock();
157 icache_enable();
158
159 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();
167 else
168 msmc_k2hk_setup();
169 }
170
171
172 config_pcie_mode(0, ROOTCOMPLEX);
173#if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L)
174
175 config_pcie_mode(1, ROOTCOMPLEX);
176#endif
177#ifdef CONFIG_SOC_K2L
178 osr_init();
179#endif
180
181
182
183
184
185
186#ifndef CONFIG_DM_SERIAL
187 NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2),
188 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
189#endif
190
191 return 0;
192}
193
194void reset_cpu(ulong addr)
195{
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{
210#ifndef CONFIG_SYS_DCACHE_OFF
211
212 dcache_enable();
213#endif
214}
215
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;
233 case CPU_66AK2Gx:
234 puts("66AK2Gx SR");
235 break;
236 default:
237 puts("Unknown\n");
238 }
239
240 if (rev == 2)
241 puts("2.0\n");
242 else if (rev == 1)
243 puts("1.1\n");
244 else if (rev == 0)
245 puts("1.0\n");
246
247 return 0;
248}
249#endif
250