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