exynos_soc.c revision 1.2 1 1.2 reinoud /* $NetBSD: exynos_soc.c,v 1.2 2014/04/13 20:45:25 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.2 reinoud __KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.2 2014/04/13 20:45:25 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 #ifdef ARM_TRUSTZONE_FIRMWARE
53 1.1 matt #include <arm/trustzone/firmware.h>
54 1.1 matt #endif
55 1.1 matt
56 1.1 matt #include <arm/samsung/exynos_reg.h>
57 1.1 matt #include <arm/samsung/exynos_var.h>
58 1.1 matt #include <arm/samsung/smc.h>
59 1.1 matt
60 1.1 matt #include <arm/cortex/pl310_var.h>
61 1.1 matt #include <arm/cortex/pl310_reg.h>
62 1.1 matt
63 1.1 matt /* XXXNH */
64 1.1 matt #include <evbarm/odroid/platform.h>
65 1.1 matt
66 1.1 matt bus_space_handle_t exynos_core_bsh;
67 1.1 matt
68 1.1 matt /* these variables are retrieved in start.S and stored in .data */
69 1.1 matt uint32_t exynos_soc_id = 0;
70 1.1 matt uint32_t exynos_pop_id = 0;
71 1.1 matt
72 1.1 matt
73 1.1 matt /*
74 1.1 matt * the early serial console
75 1.1 matt */
76 1.1 matt #ifdef EXYNOS_CONSOLE_EARLY
77 1.1 matt
78 1.1 matt #include "opt_sscom.h"
79 1.1 matt #include <arm/samsung/sscom_reg.h>
80 1.1 matt #include <arm/samsung/sscom_var.h>
81 1.1 matt #include <dev/cons.h>
82 1.1 matt
83 1.1 matt static volatile uint8_t *uart_base;
84 1.1 matt
85 1.1 matt #define CON_REG(a) (*((volatile uint32_t *)(uart_base + (a))))
86 1.1 matt
87 1.1 matt static int
88 1.1 matt exynos_cngetc(dev_t dv)
89 1.1 matt {
90 1.1 matt if ((CON_REG(SSCOM_UTRSTAT) & UTRSTAT_RXREADY) == 0)
91 1.1 matt return -1;
92 1.1 matt
93 1.1 matt return CON_REG(SSCOM_URXH);
94 1.1 matt }
95 1.1 matt
96 1.1 matt static void
97 1.1 matt exynos_cnputc(dev_t dv, int c)
98 1.1 matt {
99 1.1 matt int timo = 150000;
100 1.1 matt
101 1.1 matt while ((CON_REG(SSCOM_UFSTAT) & UFSTAT_TXFULL) && --timo > 0);
102 1.1 matt
103 1.1 matt CON_REG(SSCOM_UTXH) = c & 0xff;
104 1.1 matt }
105 1.1 matt
106 1.1 matt static struct consdev exynos_earlycons = {
107 1.1 matt .cn_putc = exynos_cnputc,
108 1.1 matt .cn_getc = exynos_cngetc,
109 1.1 matt .cn_pollc = nullcnpollc,
110 1.1 matt };
111 1.1 matt #endif /* EXYNOS_CONSOLE_EARLY */
112 1.1 matt
113 1.1 matt
114 1.1 matt #ifdef ARM_TRUSTZONE_FIRMWARE
115 1.2 reinoud int
116 1.1 matt exynos_do_idle(void)
117 1.1 matt {
118 1.1 matt exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
119 1.1 matt
120 1.1 matt return 0;
121 1.1 matt }
122 1.1 matt
123 1.1 matt
124 1.2 reinoud int
125 1.1 matt exynos_set_cpu_boot_addr(int cpu, vaddr_t boot_addr)
126 1.1 matt {
127 1.1 matt #if 0
128 1.2 reinoud /* XXX we need to map in iRAM space for this XXX */
129 1.1 matt void __iomem *boot_reg = S5P_VA_SYSRAM_NS + 0x1c;
130 1.1 matt
131 1.1 matt if (!soc_is_exynos5420())
132 1.1 matt boot_reg += 4 * cpu;
133 1.1 matt
134 1.1 matt writel_relaxed(boot_addr, boot_reg);
135 1.1 matt return 0;
136 1.1 matt #endif
137 1.1 matt return 0;
138 1.1 matt }
139 1.1 matt
140 1.1 matt
141 1.2 reinoud int
142 1.1 matt exynos_cpu_boot(int cpu)
143 1.1 matt {
144 1.1 matt exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0);
145 1.1 matt
146 1.1 matt return 0;
147 1.1 matt }
148 1.1 matt
149 1.1 matt
150 1.1 matt /*
151 1.1 matt * The latency values used below are `magic' and probably chosen empiricaly.
152 1.1 matt * For the 4210 variant the data latency is lower, a 0x110. This is currently
153 1.1 matt * not enforced.
154 1.1 matt *
155 1.1 matt * The prefetch values are also different for the revision 0 of the
156 1.1 matt * Exynos4412, but why?
157 1.1 matt */
158 1.1 matt
159 1.2 reinoud int
160 1.1 matt exynos_l2cc_init(void)
161 1.1 matt {
162 1.1 matt const uint32_t tag_latency = 0x110;
163 1.2 reinoud const uint32_t data_latency = IS_EXYNOS4410_P() ? 0x110 : 0x120;
164 1.1 matt const uint32_t prefetch4412 = /* 0111 0001 0000 0000 0000 0000 0000 0111 */
165 1.1 matt PREFETCHCTL_DBLLINEF_EN |
166 1.1 matt PREFETCHCTL_INSTRPREF_EN |
167 1.1 matt PREFETCHCTL_DATAPREF_EN |
168 1.1 matt PREFETCHCTL_PREF_DROP_EN |
169 1.1 matt PREFETCHCTL_PREFETCH_OFFSET_7;
170 1.1 matt const uint32_t prefetch4412_r0 = /* 0011 0000 0000 0000 0000 0000 0000 0111 */
171 1.1 matt PREFETCHCTL_INSTRPREF_EN |
172 1.1 matt PREFETCHCTL_DATAPREF_EN |
173 1.1 matt PREFETCHCTL_PREFETCH_OFFSET_7;
174 1.1 matt const uint32_t aux_val = /* 0111 1100 0100 0111 0000 0000 0000 0001 */
175 1.1 matt AUXCTL_EARLY_BRESP_EN |
176 1.1 matt AUXCTL_I_PREFETCH |
177 1.1 matt AUXCTL_D_PREFETCH |
178 1.1 matt AUXCTL_NS_INT_ACC_CTL |
179 1.1 matt AUXCTL_NS_INT_LOCK_EN |
180 1.1 matt AUXCTL_SHARED_ATT_OVR |
181 1.1 matt AUXCTL_WAY_SIZE_RSVD7 << 16 | /* why rsvd7 ??? */
182 1.1 matt AUXCTL_FULL_LINE_WR0;
183 1.1 matt const uint32_t aux_keepmask = /* 1100 0010 0000 0000 1111 1111 1111 1111 */
184 1.1 matt AUXCTL_RSVD31 |
185 1.1 matt AUXCTL_EARLY_BRESP_EN |
186 1.1 matt AUXCTL_CACHE_REPL_RR |
187 1.1 matt
188 1.1 matt AUXCTL_SH_ATTR_INV_ENA|
189 1.1 matt AUXCTL_EXCL_CACHE_CFG |
190 1.1 matt AUXCTL_ST_BUF_DEV_LIM_EN |
191 1.1 matt AUXCTL_HIPRO_SO_DEV_EN |
192 1.1 matt AUXCTL_FULL_LINE_WR0 |
193 1.1 matt 0xffff;
194 1.1 matt uint32_t prefetch;
195 1.1 matt
196 1.1 matt /* check the bitmaps are the same as the linux implementation uses */
197 1.1 matt KASSERT(prefetch4412 == 0x71000007);
198 1.1 matt KASSERT(prefetch4412_r0 == 0x30000007);
199 1.1 matt KASSERT(aux_val == 0x7C470001);
200 1.1 matt KASSERT(aux_keepmask == 0xC200FFFF);
201 1.1 matt
202 1.2 reinoud if (IS_EXYNOS4412_R0_P())
203 1.1 matt prefetch = prefetch4412_r0;
204 1.1 matt else
205 1.1 matt prefetch = prefetch4412; /* newer than >= r1_0 */
206 1.1 matt ;
207 1.1 matt
208 1.1 matt exynos_smc(SMC_CMD_L2X0SETUP1, tag_latency, data_latency, prefetch);
209 1.1 matt exynos_smc(SMC_CMD_L2X0SETUP2,
210 1.1 matt POWERCTL_DYNCLKGATE | POWERCTL_STANDBY,
211 1.1 matt aux_val, aux_keepmask);
212 1.1 matt exynos_smc(SMC_CMD_L2X0INVALL, 0, 0, 0);
213 1.1 matt exynos_smc(SMC_CMD_L2X0CTRL, 1, 0, 0);
214 1.1 matt
215 1.1 matt return 0;
216 1.1 matt }
217 1.2 reinoud #endif /* ARM_TRUSTZONE_FIRMWARE */
218 1.1 matt
219 1.1 matt
220 1.1 matt void
221 1.1 matt exynos_bootstrap(vaddr_t iobase, vaddr_t uartbase)
222 1.1 matt {
223 1.1 matt // int error;
224 1.1 matt
225 1.1 matt /* set up early console so we can use printf() and friends */
226 1.1 matt #ifdef EXYNOS_CONSOLE_EARLY
227 1.1 matt uart_base = (volatile uint8_t *) uartbase;
228 1.1 matt cn_tab = &exynos_earlycons;
229 1.1 matt printf("Exynos early console operational\n\n");
230 1.1 matt #endif
231 1.1 matt #if 0
232 1.1 matt /* map in the exynos io registers */
233 1.1 matt error = bus_space_map(&exynos_bs_tag, EXYNOS_CORE_PBASE,
234 1.1 matt 0x04000000 /*EXYNOS_CORE_SIZE*/, 0, &exynos_core_bsh);
235 1.1 matt if (error)
236 1.1 matt panic("%s: failed to map in Exynos io registers: %d",
237 1.1 matt __func__, error);
238 1.1 matt KASSERT(exynos_core_bsh == iobase);
239 1.1 matt #endif
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.1 matt extern uint32_t exynos_soc_id;
265 1.1 matt switch (EXYNOS_PRODUCT_ID(exynos_soc_id)) {
266 1.1 matt #if defined(EXYNOS5)
267 1.1 matt case 0xe5410:
268 1.1 matt #if 0
269 1.1 matt mpcaa->mpcaa_off1 = EXYNOS5_GIC_IOP_DISTRIBUTOR_OFFSET;
270 1.1 matt mpcaa->mpcaa_off2 = EXYNOS5_GIC_IOP_CONTROLLER_OFFSET;
271 1.1 matt #endif
272 1.1 matt break;
273 1.1 matt #endif
274 1.1 matt #if defined(EXYNOS4)
275 1.1 matt case 0xe4410:
276 1.1 matt case 0xe4412: {
277 1.1 matt struct mpcore_attach_args * const mpcaa = aux;
278 1.1 matt mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
279 1.1 matt mpcaa->mpcaa_off1 = EXYNOS4_GIC_DISTRIBUTOR_OFFSET;
280 1.1 matt mpcaa->mpcaa_off2 = EXYNOS4_GIC_CNTR_OFFSET;
281 1.1 matt break;
282 1.1 matt }
283 1.1 matt #endif
284 1.1 matt default:
285 1.1 matt panic("%s: unknown SoC product id %#x", __func__,
286 1.1 matt (u_int)EXYNOS_PRODUCT_ID(exynos_soc_id));
287 1.1 matt }
288 1.1 matt return;
289 1.1 matt }
290 1.1 matt #if defined(CPU_CORTEXA7) || defined(CPU_CORTEXA15)
291 1.1 matt if (device_is_a(self, "armgtmr")) {
292 1.1 matt /*
293 1.1 matt * The frequency of the generic timer is the reference
294 1.1 matt * frequency.
295 1.1 matt */
296 1.1 matt prop_dictionary_set_uint32(device_properties(self),
297 1.1 matt "frequency", 24000000);
298 1.1 matt return;
299 1.1 matt }
300 1.1 matt #endif
301 1.1 matt
302 1.1 matt exyo_device_register(self, aux);
303 1.1 matt }
304 1.1 matt
305