exynos_soc.c revision 1.11 1 1.11 reinoud /* $NetBSD: exynos_soc.c,v 1.11 2014/05/14 09:03:09 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.11 reinoud __KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.11 2014/05/14 09:03:09 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.11 reinoud bus_space_handle_t exynos_audiocore_bsh;
65 1.1 matt
66 1.1 matt /* these variables are retrieved in start.S and stored in .data */
67 1.1 matt uint32_t exynos_soc_id = 0;
68 1.1 matt uint32_t exynos_pop_id = 0;
69 1.1 matt
70 1.1 matt
71 1.1 matt /*
72 1.1 matt * the early serial console
73 1.1 matt */
74 1.1 matt #ifdef EXYNOS_CONSOLE_EARLY
75 1.1 matt
76 1.1 matt #include "opt_sscom.h"
77 1.1 matt #include <arm/samsung/sscom_reg.h>
78 1.1 matt #include <arm/samsung/sscom_var.h>
79 1.1 matt #include <dev/cons.h>
80 1.1 matt
81 1.1 matt static volatile uint8_t *uart_base;
82 1.1 matt
83 1.1 matt #define CON_REG(a) (*((volatile uint32_t *)(uart_base + (a))))
84 1.1 matt
85 1.1 matt static int
86 1.1 matt exynos_cngetc(dev_t dv)
87 1.1 matt {
88 1.1 matt if ((CON_REG(SSCOM_UTRSTAT) & UTRSTAT_RXREADY) == 0)
89 1.1 matt return -1;
90 1.1 matt
91 1.1 matt return CON_REG(SSCOM_URXH);
92 1.1 matt }
93 1.1 matt
94 1.1 matt static void
95 1.1 matt exynos_cnputc(dev_t dv, int c)
96 1.1 matt {
97 1.1 matt int timo = 150000;
98 1.1 matt
99 1.1 matt while ((CON_REG(SSCOM_UFSTAT) & UFSTAT_TXFULL) && --timo > 0);
100 1.1 matt
101 1.1 matt CON_REG(SSCOM_UTXH) = c & 0xff;
102 1.1 matt }
103 1.1 matt
104 1.1 matt static struct consdev exynos_earlycons = {
105 1.1 matt .cn_putc = exynos_cnputc,
106 1.1 matt .cn_getc = exynos_cngetc,
107 1.1 matt .cn_pollc = nullcnpollc,
108 1.1 matt };
109 1.1 matt #endif /* EXYNOS_CONSOLE_EARLY */
110 1.1 matt
111 1.1 matt
112 1.1 matt #ifdef ARM_TRUSTZONE_FIRMWARE
113 1.2 reinoud int
114 1.1 matt exynos_do_idle(void)
115 1.1 matt {
116 1.1 matt exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
117 1.1 matt
118 1.1 matt return 0;
119 1.1 matt }
120 1.1 matt
121 1.1 matt
122 1.2 reinoud int
123 1.1 matt exynos_set_cpu_boot_addr(int cpu, vaddr_t boot_addr)
124 1.1 matt {
125 1.2 reinoud /* XXX we need to map in iRAM space for this XXX */
126 1.1 matt return 0;
127 1.1 matt }
128 1.1 matt
129 1.1 matt
130 1.2 reinoud int
131 1.1 matt exynos_cpu_boot(int cpu)
132 1.1 matt {
133 1.1 matt exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0);
134 1.1 matt
135 1.1 matt return 0;
136 1.1 matt }
137 1.1 matt
138 1.1 matt
139 1.1 matt /*
140 1.1 matt * The latency values used below are `magic' and probably chosen empiricaly.
141 1.1 matt * For the 4210 variant the data latency is lower, a 0x110. This is currently
142 1.1 matt * not enforced.
143 1.1 matt *
144 1.1 matt * The prefetch values are also different for the revision 0 of the
145 1.1 matt * Exynos4412, but why?
146 1.1 matt */
147 1.1 matt
148 1.2 reinoud int
149 1.1 matt exynos_l2cc_init(void)
150 1.1 matt {
151 1.1 matt const uint32_t tag_latency = 0x110;
152 1.2 reinoud const uint32_t data_latency = IS_EXYNOS4410_P() ? 0x110 : 0x120;
153 1.1 matt const uint32_t prefetch4412 = /* 0111 0001 0000 0000 0000 0000 0000 0111 */
154 1.1 matt PREFETCHCTL_DBLLINEF_EN |
155 1.1 matt PREFETCHCTL_INSTRPREF_EN |
156 1.1 matt PREFETCHCTL_DATAPREF_EN |
157 1.1 matt PREFETCHCTL_PREF_DROP_EN |
158 1.1 matt PREFETCHCTL_PREFETCH_OFFSET_7;
159 1.1 matt const uint32_t prefetch4412_r0 = /* 0011 0000 0000 0000 0000 0000 0000 0111 */
160 1.1 matt PREFETCHCTL_INSTRPREF_EN |
161 1.1 matt PREFETCHCTL_DATAPREF_EN |
162 1.1 matt PREFETCHCTL_PREFETCH_OFFSET_7;
163 1.1 matt const uint32_t aux_val = /* 0111 1100 0100 0111 0000 0000 0000 0001 */
164 1.1 matt AUXCTL_EARLY_BRESP_EN |
165 1.1 matt AUXCTL_I_PREFETCH |
166 1.1 matt AUXCTL_D_PREFETCH |
167 1.1 matt AUXCTL_NS_INT_ACC_CTL |
168 1.1 matt AUXCTL_NS_INT_LOCK_EN |
169 1.1 matt AUXCTL_SHARED_ATT_OVR |
170 1.1 matt AUXCTL_WAY_SIZE_RSVD7 << 16 | /* why rsvd7 ??? */
171 1.1 matt AUXCTL_FULL_LINE_WR0;
172 1.1 matt const uint32_t aux_keepmask = /* 1100 0010 0000 0000 1111 1111 1111 1111 */
173 1.1 matt AUXCTL_RSVD31 |
174 1.1 matt AUXCTL_EARLY_BRESP_EN |
175 1.1 matt AUXCTL_CACHE_REPL_RR |
176 1.1 matt
177 1.1 matt AUXCTL_SH_ATTR_INV_ENA|
178 1.1 matt AUXCTL_EXCL_CACHE_CFG |
179 1.1 matt AUXCTL_ST_BUF_DEV_LIM_EN |
180 1.1 matt AUXCTL_HIPRO_SO_DEV_EN |
181 1.1 matt AUXCTL_FULL_LINE_WR0 |
182 1.1 matt 0xffff;
183 1.1 matt uint32_t prefetch;
184 1.1 matt
185 1.1 matt /* check the bitmaps are the same as the linux implementation uses */
186 1.1 matt KASSERT(prefetch4412 == 0x71000007);
187 1.1 matt KASSERT(prefetch4412_r0 == 0x30000007);
188 1.1 matt KASSERT(aux_val == 0x7C470001);
189 1.1 matt KASSERT(aux_keepmask == 0xC200FFFF);
190 1.1 matt
191 1.2 reinoud if (IS_EXYNOS4412_R0_P())
192 1.1 matt prefetch = prefetch4412_r0;
193 1.1 matt else
194 1.1 matt prefetch = prefetch4412; /* newer than >= r1_0 */
195 1.1 matt ;
196 1.1 matt
197 1.1 matt exynos_smc(SMC_CMD_L2X0SETUP1, tag_latency, data_latency, prefetch);
198 1.1 matt exynos_smc(SMC_CMD_L2X0SETUP2,
199 1.1 matt POWERCTL_DYNCLKGATE | POWERCTL_STANDBY,
200 1.1 matt aux_val, aux_keepmask);
201 1.1 matt exynos_smc(SMC_CMD_L2X0INVALL, 0, 0, 0);
202 1.1 matt exynos_smc(SMC_CMD_L2X0CTRL, 1, 0, 0);
203 1.1 matt
204 1.1 matt return 0;
205 1.1 matt }
206 1.2 reinoud #endif /* ARM_TRUSTZONE_FIRMWARE */
207 1.1 matt
208 1.1 matt
209 1.1 matt void
210 1.1 matt exynos_bootstrap(vaddr_t iobase, vaddr_t uartbase)
211 1.1 matt {
212 1.5 reinoud int error;
213 1.11 reinoud size_t core_size, audiocore_size;
214 1.11 reinoud size_t audiocore_pbase;
215 1.11 reinoud
216 1.11 reinoud #ifdef EXYNOS4
217 1.11 reinoud if (IS_EXYNOS4_P()) {
218 1.11 reinoud core_size = EXYNOS4_CORE_SIZE;
219 1.11 reinoud audiocore_size = EXYNOS4_AUDIOCORE_SIZE;
220 1.11 reinoud audiocore_pbase = EXYNOS4_AUDIOCORE_PBASE;
221 1.11 reinoud }
222 1.11 reinoud #endif
223 1.11 reinoud
224 1.11 reinoud #ifdef EXYNOS5
225 1.11 reinoud if (IS_EXYNOS5_P()) {
226 1.11 reinoud core_size = EXYNOS5_CORE_SIZE;
227 1.11 reinoud audiocore_size = EXYNOS5_AUDIOCORE_SIZE;
228 1.11 reinoud audiocore_pbase = EXYNOS5_AUDIOCORE_PBASE;
229 1.11 reinoud }
230 1.11 reinoud #endif
231 1.1 matt
232 1.1 matt /* set up early console so we can use printf() and friends */
233 1.1 matt #ifdef EXYNOS_CONSOLE_EARLY
234 1.1 matt uart_base = (volatile uint8_t *) uartbase;
235 1.1 matt cn_tab = &exynos_earlycons;
236 1.1 matt printf("Exynos early console operational\n\n");
237 1.1 matt #endif
238 1.1 matt /* map in the exynos io registers */
239 1.1 matt error = bus_space_map(&exynos_bs_tag, EXYNOS_CORE_PBASE,
240 1.5 reinoud core_size, 0, &exynos_core_bsh);
241 1.1 matt if (error)
242 1.11 reinoud panic("%s: failed to map in Exynos SFR registers: %d",
243 1.1 matt __func__, error);
244 1.1 matt KASSERT(exynos_core_bsh == iobase);
245 1.7 reinoud
246 1.11 reinoud error = bus_space_map(&exynos_bs_tag, audiocore_pbase,
247 1.11 reinoud audiocore_size, 0, &exynos_audiocore_bsh);
248 1.11 reinoud if (error)
249 1.11 reinoud panic("%s: failed to map in Exynos audio SFR registers: %d",
250 1.11 reinoud __func__, error);
251 1.11 reinoud KASSERT(exynos_audiocore_bsh == EXYNOS4_AUDIOCORE_VBASE);
252 1.11 reinoud
253 1.7 reinoud /* init bus dma tags */
254 1.7 reinoud exynos_dma_bootstrap(physmem * PAGE_SIZE);
255 1.8 reinoud
256 1.11 reinoud /* gpio bootstrapping delayed */
257 1.1 matt }
258 1.1 matt
259 1.1 matt
260 1.1 matt void
261 1.1 matt exynos_device_register(device_t self, void *aux)
262 1.1 matt {
263 1.1 matt if (device_is_a(self, "armperiph")
264 1.1 matt && device_is_a(device_parent(self), "mainbus")) {
265 1.1 matt /*
266 1.1 matt * XXX KLUDGE ALERT XXX
267 1.1 matt * The iot mainbus supplies is completely wrong since it scales
268 1.1 matt * addresses by 2. The simpliest remedy is to replace with our
269 1.1 matt * bus space used for the armcore regisers (which armperiph uses).
270 1.1 matt */
271 1.1 matt struct mainbus_attach_args * const mb = aux;
272 1.1 matt mb->mb_iot = &exynos_bs_tag;
273 1.1 matt return;
274 1.1 matt }
275 1.1 matt if (device_is_a(self, "armgic")
276 1.1 matt && device_is_a(device_parent(self), "armperiph")) {
277 1.1 matt /*
278 1.1 matt * The Exynos4420 armgic is located at a different location!
279 1.1 matt */
280 1.1 matt
281 1.6 reinoud struct mpcore_attach_args * const mpcaa = aux;
282 1.1 matt extern uint32_t exynos_soc_id;
283 1.6 reinoud
284 1.1 matt switch (EXYNOS_PRODUCT_ID(exynos_soc_id)) {
285 1.1 matt #if defined(EXYNOS5)
286 1.1 matt case 0xe5410:
287 1.6 reinoud /* offsets not changed on matt's request */
288 1.1 matt #if 0
289 1.6 reinoud mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
290 1.1 matt mpcaa->mpcaa_off1 = EXYNOS5_GIC_IOP_DISTRIBUTOR_OFFSET;
291 1.1 matt mpcaa->mpcaa_off2 = EXYNOS5_GIC_IOP_CONTROLLER_OFFSET;
292 1.1 matt #endif
293 1.1 matt break;
294 1.1 matt #endif
295 1.1 matt #if defined(EXYNOS4)
296 1.1 matt case 0xe4410:
297 1.6 reinoud case 0xe4412:
298 1.1 matt mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
299 1.1 matt mpcaa->mpcaa_off1 = EXYNOS4_GIC_DISTRIBUTOR_OFFSET;
300 1.1 matt mpcaa->mpcaa_off2 = EXYNOS4_GIC_CNTR_OFFSET;
301 1.1 matt break;
302 1.1 matt #endif
303 1.1 matt default:
304 1.1 matt panic("%s: unknown SoC product id %#x", __func__,
305 1.1 matt (u_int)EXYNOS_PRODUCT_ID(exynos_soc_id));
306 1.1 matt }
307 1.1 matt return;
308 1.1 matt }
309 1.10 reinoud if (device_is_a(self, "armgtmr") || device_is_a(self, "mct")) {
310 1.1 matt /*
311 1.10 reinoud * The frequencies of the timers are the reference
312 1.1 matt * frequency.
313 1.1 matt */
314 1.1 matt prop_dictionary_set_uint32(device_properties(self),
315 1.10 reinoud "frequency", EXYNOS_F_IN_FREQ);
316 1.1 matt return;
317 1.1 matt }
318 1.1 matt
319 1.1 matt exyo_device_register(self, aux);
320 1.1 matt }
321 1.1 matt
322 1.9 reinoud
323 1.9 reinoud void
324 1.9 reinoud exynos_device_register_post_config(device_t self, void *aux)
325 1.9 reinoud {
326 1.9 reinoud exyo_device_register_post_config(self, aux);
327 1.9 reinoud }
328 1.9 reinoud
329