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