exynos_soc.c revision 1.3 1 /* $NetBSD: exynos_soc.c,v 1.3 2014/04/13 20:49:36 reinoud Exp $ */
2 /*-
3 * Copyright (c) 2014 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Reinoud Zandijk.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "opt_exynos.h"
32
33 #define _ARM32_BUS_DMA_PRIVATE
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.3 2014/04/13 20:49:36 reinoud Exp $");
37
38 #include <sys/param.h>
39 #include <sys/bus.h>
40 #include <sys/cpu.h>
41 #include <sys/device.h>
42
43 #include <prop/proplib.h>
44
45 #include <net/if.h>
46 #include <net/if_ether.h>
47
48 #include <arm/locore.h>
49
50 #include <arm/mainbus/mainbus.h>
51 #include <arm/cortex/mpcore_var.h>
52
53 #include <arm/samsung/exynos_reg.h>
54 #include <arm/samsung/exynos_var.h>
55 #include <arm/samsung/smc.h>
56
57 #include <arm/cortex/pl310_var.h>
58 #include <arm/cortex/pl310_reg.h>
59
60 /* XXXNH */
61 #include <evbarm/odroid/platform.h>
62
63 bus_space_handle_t exynos_core_bsh;
64
65 /* these variables are retrieved in start.S and stored in .data */
66 uint32_t exynos_soc_id = 0;
67 uint32_t exynos_pop_id = 0;
68
69
70 /*
71 * the early serial console
72 */
73 #ifdef EXYNOS_CONSOLE_EARLY
74
75 #include "opt_sscom.h"
76 #include <arm/samsung/sscom_reg.h>
77 #include <arm/samsung/sscom_var.h>
78 #include <dev/cons.h>
79
80 static volatile uint8_t *uart_base;
81
82 #define CON_REG(a) (*((volatile uint32_t *)(uart_base + (a))))
83
84 static int
85 exynos_cngetc(dev_t dv)
86 {
87 if ((CON_REG(SSCOM_UTRSTAT) & UTRSTAT_RXREADY) == 0)
88 return -1;
89
90 return CON_REG(SSCOM_URXH);
91 }
92
93 static void
94 exynos_cnputc(dev_t dv, int c)
95 {
96 int timo = 150000;
97
98 while ((CON_REG(SSCOM_UFSTAT) & UFSTAT_TXFULL) && --timo > 0);
99
100 CON_REG(SSCOM_UTXH) = c & 0xff;
101 }
102
103 static struct consdev exynos_earlycons = {
104 .cn_putc = exynos_cnputc,
105 .cn_getc = exynos_cngetc,
106 .cn_pollc = nullcnpollc,
107 };
108 #endif /* EXYNOS_CONSOLE_EARLY */
109
110
111 #ifdef ARM_TRUSTZONE_FIRMWARE
112 int
113 exynos_do_idle(void)
114 {
115 exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
116
117 return 0;
118 }
119
120
121 int
122 exynos_set_cpu_boot_addr(int cpu, vaddr_t boot_addr)
123 {
124 #if 0
125 /* XXX we need to map in iRAM space for this XXX */
126 void __iomem *boot_reg = S5P_VA_SYSRAM_NS + 0x1c;
127
128 if (!soc_is_exynos5420())
129 boot_reg += 4 * cpu;
130
131 writel_relaxed(boot_addr, boot_reg);
132 return 0;
133 #endif
134 return 0;
135 }
136
137
138 int
139 exynos_cpu_boot(int cpu)
140 {
141 exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0);
142
143 return 0;
144 }
145
146
147 /*
148 * The latency values used below are `magic' and probably chosen empiricaly.
149 * For the 4210 variant the data latency is lower, a 0x110. This is currently
150 * not enforced.
151 *
152 * The prefetch values are also different for the revision 0 of the
153 * Exynos4412, but why?
154 */
155
156 int
157 exynos_l2cc_init(void)
158 {
159 const uint32_t tag_latency = 0x110;
160 const uint32_t data_latency = IS_EXYNOS4410_P() ? 0x110 : 0x120;
161 const uint32_t prefetch4412 = /* 0111 0001 0000 0000 0000 0000 0000 0111 */
162 PREFETCHCTL_DBLLINEF_EN |
163 PREFETCHCTL_INSTRPREF_EN |
164 PREFETCHCTL_DATAPREF_EN |
165 PREFETCHCTL_PREF_DROP_EN |
166 PREFETCHCTL_PREFETCH_OFFSET_7;
167 const uint32_t prefetch4412_r0 = /* 0011 0000 0000 0000 0000 0000 0000 0111 */
168 PREFETCHCTL_INSTRPREF_EN |
169 PREFETCHCTL_DATAPREF_EN |
170 PREFETCHCTL_PREFETCH_OFFSET_7;
171 const uint32_t aux_val = /* 0111 1100 0100 0111 0000 0000 0000 0001 */
172 AUXCTL_EARLY_BRESP_EN |
173 AUXCTL_I_PREFETCH |
174 AUXCTL_D_PREFETCH |
175 AUXCTL_NS_INT_ACC_CTL |
176 AUXCTL_NS_INT_LOCK_EN |
177 AUXCTL_SHARED_ATT_OVR |
178 AUXCTL_WAY_SIZE_RSVD7 << 16 | /* why rsvd7 ??? */
179 AUXCTL_FULL_LINE_WR0;
180 const uint32_t aux_keepmask = /* 1100 0010 0000 0000 1111 1111 1111 1111 */
181 AUXCTL_RSVD31 |
182 AUXCTL_EARLY_BRESP_EN |
183 AUXCTL_CACHE_REPL_RR |
184
185 AUXCTL_SH_ATTR_INV_ENA|
186 AUXCTL_EXCL_CACHE_CFG |
187 AUXCTL_ST_BUF_DEV_LIM_EN |
188 AUXCTL_HIPRO_SO_DEV_EN |
189 AUXCTL_FULL_LINE_WR0 |
190 0xffff;
191 uint32_t prefetch;
192
193 /* check the bitmaps are the same as the linux implementation uses */
194 KASSERT(prefetch4412 == 0x71000007);
195 KASSERT(prefetch4412_r0 == 0x30000007);
196 KASSERT(aux_val == 0x7C470001);
197 KASSERT(aux_keepmask == 0xC200FFFF);
198
199 if (IS_EXYNOS4412_R0_P())
200 prefetch = prefetch4412_r0;
201 else
202 prefetch = prefetch4412; /* newer than >= r1_0 */
203 ;
204
205 exynos_smc(SMC_CMD_L2X0SETUP1, tag_latency, data_latency, prefetch);
206 exynos_smc(SMC_CMD_L2X0SETUP2,
207 POWERCTL_DYNCLKGATE | POWERCTL_STANDBY,
208 aux_val, aux_keepmask);
209 exynos_smc(SMC_CMD_L2X0INVALL, 0, 0, 0);
210 exynos_smc(SMC_CMD_L2X0CTRL, 1, 0, 0);
211
212 return 0;
213 }
214 #endif /* ARM_TRUSTZONE_FIRMWARE */
215
216
217 void
218 exynos_bootstrap(vaddr_t iobase, vaddr_t uartbase)
219 {
220 // int error;
221
222 /* set up early console so we can use printf() and friends */
223 #ifdef EXYNOS_CONSOLE_EARLY
224 uart_base = (volatile uint8_t *) uartbase;
225 cn_tab = &exynos_earlycons;
226 printf("Exynos early console operational\n\n");
227 #endif
228 #if 0
229 /* map in the exynos io registers */
230 error = bus_space_map(&exynos_bs_tag, EXYNOS_CORE_PBASE,
231 0x04000000 /*EXYNOS_CORE_SIZE*/, 0, &exynos_core_bsh);
232 if (error)
233 panic("%s: failed to map in Exynos io registers: %d",
234 __func__, error);
235 KASSERT(exynos_core_bsh == iobase);
236 #endif
237 }
238
239
240 void
241 exynos_device_register(device_t self, void *aux)
242 {
243 if (device_is_a(self, "armperiph")
244 && device_is_a(device_parent(self), "mainbus")) {
245 /*
246 * XXX KLUDGE ALERT XXX
247 * The iot mainbus supplies is completely wrong since it scales
248 * addresses by 2. The simpliest remedy is to replace with our
249 * bus space used for the armcore regisers (which armperiph uses).
250 */
251 struct mainbus_attach_args * const mb = aux;
252 mb->mb_iot = &exynos_bs_tag;
253 return;
254 }
255 if (device_is_a(self, "armgic")
256 && device_is_a(device_parent(self), "armperiph")) {
257 /*
258 * The Exynos4420 armgic is located at a different location!
259 */
260
261 extern uint32_t exynos_soc_id;
262 switch (EXYNOS_PRODUCT_ID(exynos_soc_id)) {
263 #if defined(EXYNOS5)
264 case 0xe5410:
265 #if 0
266 mpcaa->mpcaa_off1 = EXYNOS5_GIC_IOP_DISTRIBUTOR_OFFSET;
267 mpcaa->mpcaa_off2 = EXYNOS5_GIC_IOP_CONTROLLER_OFFSET;
268 #endif
269 break;
270 #endif
271 #if defined(EXYNOS4)
272 case 0xe4410:
273 case 0xe4412: {
274 struct mpcore_attach_args * const mpcaa = aux;
275 mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
276 mpcaa->mpcaa_off1 = EXYNOS4_GIC_DISTRIBUTOR_OFFSET;
277 mpcaa->mpcaa_off2 = EXYNOS4_GIC_CNTR_OFFSET;
278 break;
279 }
280 #endif
281 default:
282 panic("%s: unknown SoC product id %#x", __func__,
283 (u_int)EXYNOS_PRODUCT_ID(exynos_soc_id));
284 }
285 return;
286 }
287 #if defined(CPU_CORTEXA7) || defined(CPU_CORTEXA15)
288 if (device_is_a(self, "armgtmr")) {
289 /*
290 * The frequency of the generic timer is the reference
291 * frequency.
292 */
293 prop_dictionary_set_uint32(device_properties(self),
294 "frequency", 24000000);
295 return;
296 }
297 #endif
298
299 exyo_device_register(self, aux);
300 }
301
302