exynos_soc.c revision 1.20 1 1.20 skrll /* $NetBSD: exynos_soc.c,v 1.20 2014/09/05 08:01:05 skrll Exp $ */
2 1.20 skrll
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Reinoud Zandijk.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt *
19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.1 matt */
31 1.1 matt
32 1.1 matt #include "opt_exynos.h"
33 1.1 matt
34 1.1 matt #define _ARM32_BUS_DMA_PRIVATE
35 1.1 matt
36 1.1 matt #include <sys/cdefs.h>
37 1.20 skrll __KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.20 2014/09/05 08:01:05 skrll Exp $");
38 1.1 matt
39 1.1 matt #include <sys/param.h>
40 1.1 matt #include <sys/bus.h>
41 1.1 matt #include <sys/cpu.h>
42 1.1 matt #include <sys/device.h>
43 1.1 matt
44 1.1 matt #include <prop/proplib.h>
45 1.1 matt
46 1.1 matt #include <net/if.h>
47 1.1 matt #include <net/if_ether.h>
48 1.1 matt
49 1.1 matt #include <arm/locore.h>
50 1.1 matt
51 1.1 matt #include <arm/mainbus/mainbus.h>
52 1.1 matt #include <arm/cortex/mpcore_var.h>
53 1.1 matt
54 1.1 matt #include <arm/samsung/exynos_reg.h>
55 1.1 matt #include <arm/samsung/exynos_var.h>
56 1.14 matt #include <arm/samsung/mct_reg.h>
57 1.1 matt #include <arm/samsung/smc.h>
58 1.1 matt
59 1.1 matt #include <arm/cortex/pl310_var.h>
60 1.1 matt #include <arm/cortex/pl310_reg.h>
61 1.1 matt
62 1.1 matt /* XXXNH */
63 1.1 matt #include <evbarm/odroid/platform.h>
64 1.1 matt
65 1.1 matt bus_space_handle_t exynos_core_bsh;
66 1.11 reinoud bus_space_handle_t exynos_audiocore_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.16 reinoud /* cpu frequencies */
74 1.16 reinoud struct cpu_freq {
75 1.16 reinoud uint64_t freq;
76 1.16 reinoud int P;
77 1.16 reinoud int M;
78 1.16 reinoud int S;
79 1.16 reinoud };
80 1.16 reinoud
81 1.16 reinoud
82 1.16 reinoud #ifdef EXYNOS4
83 1.16 reinoud const struct cpu_freq cpu_freq_settings_exynos4[] = {
84 1.16 reinoud { 200, 3, 100, 2},
85 1.16 reinoud { 300, 4, 200, 2},
86 1.16 reinoud { 400, 3, 100, 1},
87 1.16 reinoud { 500, 3, 125, 1},
88 1.16 reinoud { 600, 4, 200, 1},
89 1.16 reinoud { 700, 3, 175, 1},
90 1.16 reinoud { 800, 3, 100, 0},
91 1.16 reinoud { 900, 4, 150, 0},
92 1.16 reinoud {1000, 3, 125, 0},
93 1.16 reinoud {1100, 6, 275, 0},
94 1.16 reinoud {1200, 4, 200, 0},
95 1.16 reinoud {1300, 6, 325, 0},
96 1.16 reinoud {1400, 3, 175, 0},
97 1.16 reinoud {1600, 3, 200, 0},
98 1.16 reinoud };
99 1.16 reinoud #endif
100 1.16 reinoud
101 1.16 reinoud
102 1.16 reinoud #ifdef EXYNOS5
103 1.16 reinoud const struct cpu_freq cpu_freq_settings_exynos5[] = {
104 1.16 reinoud { 200, 3, 100, 2},
105 1.16 reinoud { 333, 4, 222, 2},
106 1.16 reinoud { 400, 3, 100, 1},
107 1.16 reinoud { 533, 12, 533, 1},
108 1.16 reinoud { 600, 4, 200, 1},
109 1.16 reinoud { 667, 7, 389, 1},
110 1.16 reinoud { 800, 3, 100, 0},
111 1.16 reinoud {1000, 3, 125, 0},
112 1.16 reinoud {1066, 12, 533, 0},
113 1.16 reinoud {1200, 3, 150, 0},
114 1.16 reinoud {1400, 3, 175, 0},
115 1.16 reinoud {1600, 3, 200, 0},
116 1.16 reinoud };
117 1.16 reinoud #endif
118 1.16 reinoud
119 1.16 reinoud static struct cpu_freq const *cpu_freq_settings = NULL;
120 1.16 reinoud static int ncpu_freq_settings = 0;
121 1.16 reinoud
122 1.16 reinoud static int cpu_freq_target = 0;
123 1.16 reinoud #define NFRQS 15
124 1.16 reinoud static char sysctl_cpu_freqs_txt[NFRQS*5];
125 1.16 reinoud
126 1.16 reinoud static int sysctl_cpufreq_target(SYSCTLFN_ARGS);
127 1.16 reinoud static int sysctl_cpufreq_current(SYSCTLFN_ARGS);
128 1.16 reinoud
129 1.16 reinoud
130 1.1 matt /*
131 1.1 matt * the early serial console
132 1.1 matt */
133 1.1 matt #ifdef EXYNOS_CONSOLE_EARLY
134 1.1 matt
135 1.1 matt #include "opt_sscom.h"
136 1.1 matt #include <arm/samsung/sscom_reg.h>
137 1.1 matt #include <arm/samsung/sscom_var.h>
138 1.1 matt #include <dev/cons.h>
139 1.1 matt
140 1.1 matt static volatile uint8_t *uart_base;
141 1.1 matt
142 1.1 matt #define CON_REG(a) (*((volatile uint32_t *)(uart_base + (a))))
143 1.1 matt
144 1.1 matt static int
145 1.1 matt exynos_cngetc(dev_t dv)
146 1.1 matt {
147 1.1 matt if ((CON_REG(SSCOM_UTRSTAT) & UTRSTAT_RXREADY) == 0)
148 1.1 matt return -1;
149 1.1 matt
150 1.1 matt return CON_REG(SSCOM_URXH);
151 1.1 matt }
152 1.1 matt
153 1.1 matt static void
154 1.1 matt exynos_cnputc(dev_t dv, int c)
155 1.1 matt {
156 1.1 matt int timo = 150000;
157 1.1 matt
158 1.1 matt while ((CON_REG(SSCOM_UFSTAT) & UFSTAT_TXFULL) && --timo > 0);
159 1.1 matt
160 1.1 matt CON_REG(SSCOM_UTXH) = c & 0xff;
161 1.1 matt }
162 1.1 matt
163 1.1 matt static struct consdev exynos_earlycons = {
164 1.1 matt .cn_putc = exynos_cnputc,
165 1.1 matt .cn_getc = exynos_cngetc,
166 1.1 matt .cn_pollc = nullcnpollc,
167 1.1 matt };
168 1.1 matt #endif /* EXYNOS_CONSOLE_EARLY */
169 1.1 matt
170 1.1 matt
171 1.1 matt #ifdef ARM_TRUSTZONE_FIRMWARE
172 1.2 reinoud int
173 1.1 matt exynos_do_idle(void)
174 1.1 matt {
175 1.1 matt exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
176 1.1 matt
177 1.1 matt return 0;
178 1.1 matt }
179 1.1 matt
180 1.1 matt
181 1.2 reinoud int
182 1.1 matt exynos_set_cpu_boot_addr(int cpu, vaddr_t boot_addr)
183 1.1 matt {
184 1.2 reinoud /* XXX we need to map in iRAM space for this XXX */
185 1.1 matt return 0;
186 1.1 matt }
187 1.1 matt
188 1.1 matt
189 1.2 reinoud int
190 1.1 matt exynos_cpu_boot(int cpu)
191 1.1 matt {
192 1.1 matt exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0);
193 1.1 matt
194 1.1 matt return 0;
195 1.1 matt }
196 1.1 matt
197 1.1 matt
198 1.1 matt /*
199 1.17 snj * The latency values used below are `magic' and probably chosen empirically.
200 1.1 matt * For the 4210 variant the data latency is lower, a 0x110. This is currently
201 1.1 matt * not enforced.
202 1.1 matt *
203 1.1 matt * The prefetch values are also different for the revision 0 of the
204 1.1 matt * Exynos4412, but why?
205 1.1 matt */
206 1.1 matt
207 1.2 reinoud int
208 1.1 matt exynos_l2cc_init(void)
209 1.1 matt {
210 1.1 matt const uint32_t tag_latency = 0x110;
211 1.2 reinoud const uint32_t data_latency = IS_EXYNOS4410_P() ? 0x110 : 0x120;
212 1.1 matt const uint32_t prefetch4412 = /* 0111 0001 0000 0000 0000 0000 0000 0111 */
213 1.1 matt PREFETCHCTL_DBLLINEF_EN |
214 1.1 matt PREFETCHCTL_INSTRPREF_EN |
215 1.1 matt PREFETCHCTL_DATAPREF_EN |
216 1.1 matt PREFETCHCTL_PREF_DROP_EN |
217 1.1 matt PREFETCHCTL_PREFETCH_OFFSET_7;
218 1.1 matt const uint32_t prefetch4412_r0 = /* 0011 0000 0000 0000 0000 0000 0000 0111 */
219 1.1 matt PREFETCHCTL_INSTRPREF_EN |
220 1.1 matt PREFETCHCTL_DATAPREF_EN |
221 1.1 matt PREFETCHCTL_PREFETCH_OFFSET_7;
222 1.1 matt const uint32_t aux_val = /* 0111 1100 0100 0111 0000 0000 0000 0001 */
223 1.1 matt AUXCTL_EARLY_BRESP_EN |
224 1.1 matt AUXCTL_I_PREFETCH |
225 1.1 matt AUXCTL_D_PREFETCH |
226 1.1 matt AUXCTL_NS_INT_ACC_CTL |
227 1.1 matt AUXCTL_NS_INT_LOCK_EN |
228 1.1 matt AUXCTL_SHARED_ATT_OVR |
229 1.1 matt AUXCTL_WAY_SIZE_RSVD7 << 16 | /* why rsvd7 ??? */
230 1.1 matt AUXCTL_FULL_LINE_WR0;
231 1.1 matt const uint32_t aux_keepmask = /* 1100 0010 0000 0000 1111 1111 1111 1111 */
232 1.1 matt AUXCTL_RSVD31 |
233 1.1 matt AUXCTL_EARLY_BRESP_EN |
234 1.1 matt AUXCTL_CACHE_REPL_RR |
235 1.1 matt
236 1.1 matt AUXCTL_SH_ATTR_INV_ENA|
237 1.1 matt AUXCTL_EXCL_CACHE_CFG |
238 1.1 matt AUXCTL_ST_BUF_DEV_LIM_EN |
239 1.1 matt AUXCTL_HIPRO_SO_DEV_EN |
240 1.1 matt AUXCTL_FULL_LINE_WR0 |
241 1.1 matt 0xffff;
242 1.1 matt uint32_t prefetch;
243 1.1 matt
244 1.1 matt /* check the bitmaps are the same as the linux implementation uses */
245 1.1 matt KASSERT(prefetch4412 == 0x71000007);
246 1.1 matt KASSERT(prefetch4412_r0 == 0x30000007);
247 1.1 matt KASSERT(aux_val == 0x7C470001);
248 1.1 matt KASSERT(aux_keepmask == 0xC200FFFF);
249 1.1 matt
250 1.2 reinoud if (IS_EXYNOS4412_R0_P())
251 1.1 matt prefetch = prefetch4412_r0;
252 1.1 matt else
253 1.1 matt prefetch = prefetch4412; /* newer than >= r1_0 */
254 1.1 matt ;
255 1.1 matt
256 1.1 matt exynos_smc(SMC_CMD_L2X0SETUP1, tag_latency, data_latency, prefetch);
257 1.1 matt exynos_smc(SMC_CMD_L2X0SETUP2,
258 1.1 matt POWERCTL_DYNCLKGATE | POWERCTL_STANDBY,
259 1.1 matt aux_val, aux_keepmask);
260 1.1 matt exynos_smc(SMC_CMD_L2X0INVALL, 0, 0, 0);
261 1.1 matt exynos_smc(SMC_CMD_L2X0CTRL, 1, 0, 0);
262 1.1 matt
263 1.1 matt return 0;
264 1.1 matt }
265 1.2 reinoud #endif /* ARM_TRUSTZONE_FIRMWARE */
266 1.1 matt
267 1.1 matt
268 1.1 matt void
269 1.16 reinoud exynos_sysctl_cpufreq_init(void)
270 1.16 reinoud {
271 1.16 reinoud const struct sysctlnode *node, *cpunode, *freqnode;
272 1.16 reinoud char *cpos;
273 1.16 reinoud int i, val;
274 1.16 reinoud int error;
275 1.16 reinoud
276 1.16 reinoud memset(sysctl_cpu_freqs_txt, (int) ' ', sizeof(sysctl_cpu_freqs_txt));
277 1.16 reinoud cpos = sysctl_cpu_freqs_txt;
278 1.16 reinoud for (i = 0; i < ncpu_freq_settings; i++) {
279 1.16 reinoud val = cpu_freq_settings[i].freq;
280 1.16 reinoud snprintf(cpos, 6, "%d ", val);
281 1.16 reinoud cpos += (val < 1000) ? 4 : 5;
282 1.16 reinoud }
283 1.16 reinoud *cpos = 0;
284 1.16 reinoud
285 1.16 reinoud error = sysctl_createv(NULL, 0, NULL, &node,
286 1.16 reinoud CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
287 1.16 reinoud NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
288 1.16 reinoud if (error)
289 1.16 reinoud printf("couldn't create `machdep' node\n");
290 1.16 reinoud
291 1.16 reinoud error = sysctl_createv(NULL, 0, &node, &cpunode,
292 1.16 reinoud 0, CTLTYPE_NODE, "cpu", NULL,
293 1.16 reinoud NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
294 1.16 reinoud if (error)
295 1.16 reinoud printf("couldn't create `cpu' node\n");
296 1.16 reinoud
297 1.16 reinoud error = sysctl_createv(NULL, 0, &cpunode, &freqnode,
298 1.16 reinoud 0, CTLTYPE_NODE, "frequency", NULL,
299 1.16 reinoud NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
300 1.16 reinoud if (error)
301 1.16 reinoud printf("couldn't create `frequency' node\n");
302 1.16 reinoud
303 1.16 reinoud error = sysctl_createv(NULL, 0, &freqnode, &node,
304 1.16 reinoud CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
305 1.16 reinoud sysctl_cpufreq_target, 0, &cpu_freq_target, 0,
306 1.16 reinoud CTL_CREATE, CTL_EOL);
307 1.16 reinoud if (error)
308 1.16 reinoud printf("couldn't create `target' node\n");
309 1.16 reinoud
310 1.16 reinoud error = sysctl_createv(NULL, 0, &freqnode, &node,
311 1.16 reinoud 0, CTLTYPE_INT, "current", NULL,
312 1.16 reinoud sysctl_cpufreq_current, 0, NULL, 0,
313 1.16 reinoud CTL_CREATE, CTL_EOL);
314 1.16 reinoud if (error)
315 1.16 reinoud printf("couldn't create `current' node\n");
316 1.16 reinoud
317 1.16 reinoud error = sysctl_createv(NULL, 0, &freqnode, &node,
318 1.16 reinoud CTLFLAG_READONLY, CTLTYPE_STRING, "available", NULL,
319 1.16 reinoud NULL, 0, sysctl_cpu_freqs_txt, 0,
320 1.16 reinoud CTL_CREATE, CTL_EOL);
321 1.16 reinoud if (error)
322 1.16 reinoud printf("couldn't create `available' node\b");
323 1.16 reinoud }
324 1.16 reinoud
325 1.16 reinoud
326 1.16 reinoud uint64_t
327 1.16 reinoud exynos_get_cpufreq(void)
328 1.16 reinoud {
329 1.16 reinoud uint32_t reg = 0;
330 1.16 reinoud uint32_t regval;
331 1.16 reinoud uint32_t freq;
332 1.16 reinoud
333 1.16 reinoud #ifdef EXYNOS4
334 1.16 reinoud if (IS_EXYNOS4_P())
335 1.16 reinoud reg = EXYNOS4_CMU_APLL + PLL_CON0_OFFSET;
336 1.16 reinoud #endif
337 1.16 reinoud #ifdef EXYNOS5
338 1.16 reinoud if (IS_EXYNOS5_P())
339 1.16 reinoud reg = EXYNOS5_CMU_APLL + PLL_CON0_OFFSET;
340 1.16 reinoud #endif
341 1.16 reinoud KASSERT(reg);
342 1.16 reinoud
343 1.16 reinoud regval = bus_space_read_4(&exynos_bs_tag, exynos_core_bsh, reg);
344 1.16 reinoud freq = PLL_FREQ(EXYNOS_F_IN_FREQ, regval);
345 1.16 reinoud
346 1.16 reinoud return freq;
347 1.16 reinoud }
348 1.16 reinoud
349 1.16 reinoud
350 1.16 reinoud static void
351 1.16 reinoud exynos_set_cpufreq(const struct cpu_freq *freqreq)
352 1.16 reinoud {
353 1.18 reinoud struct cpu_info *ci;
354 1.16 reinoud uint32_t reg = 0;
355 1.16 reinoud uint32_t regval;
356 1.16 reinoud int M, P, S;
357 1.18 reinoud int cii;
358 1.16 reinoud
359 1.16 reinoud M = freqreq->M;
360 1.16 reinoud P = freqreq->P;
361 1.16 reinoud S = freqreq->S;
362 1.16 reinoud
363 1.16 reinoud regval = __SHIFTIN(M, PLL_CON0_M) |
364 1.16 reinoud __SHIFTIN(P, PLL_CON0_P) |
365 1.16 reinoud __SHIFTIN(S, PLL_CON0_S);
366 1.16 reinoud
367 1.16 reinoud #ifdef EXYNOS4
368 1.16 reinoud if (IS_EXYNOS4_P())
369 1.16 reinoud reg = EXYNOS4_CMU_APLL + PLL_CON0_OFFSET;
370 1.16 reinoud #endif
371 1.16 reinoud #ifdef EXYNOS5
372 1.16 reinoud if (IS_EXYNOS5_P())
373 1.16 reinoud reg = EXYNOS5_CMU_APLL + PLL_CON0_OFFSET;
374 1.16 reinoud #endif
375 1.16 reinoud KASSERT(reg);
376 1.16 reinoud
377 1.16 reinoud /* enable PPL and write config */
378 1.16 reinoud regval |= PLL_CON0_ENABLE;
379 1.16 reinoud bus_space_write_4(&exynos_bs_tag, exynos_core_bsh, reg, regval);
380 1.18 reinoud
381 1.18 reinoud /* update our cycle counter i.e. our CPU frequency for all CPUs */
382 1.18 reinoud for (CPU_INFO_FOREACH(cii, ci)) {
383 1.18 reinoud ci->ci_data.cpu_cc_freq = exynos_get_cpufreq();
384 1.18 reinoud }
385 1.16 reinoud }
386 1.16 reinoud
387 1.16 reinoud
388 1.16 reinoud static int
389 1.16 reinoud sysctl_cpufreq_target(SYSCTLFN_ARGS)
390 1.16 reinoud {
391 1.16 reinoud struct sysctlnode node;
392 1.16 reinoud uint32_t t, curfreq, minfreq, maxfreq;
393 1.16 reinoud int i, best_i, diff;
394 1.16 reinoud int error;
395 1.16 reinoud
396 1.16 reinoud curfreq = exynos_get_cpufreq() / (1000*1000);
397 1.16 reinoud t = *(int *)rnode->sysctl_data;
398 1.16 reinoud if (t == 0)
399 1.16 reinoud t = curfreq;
400 1.16 reinoud
401 1.16 reinoud node = *rnode;
402 1.16 reinoud node.sysctl_data = &t;
403 1.16 reinoud error = sysctl_lookup(SYSCTLFN_CALL(&node));
404 1.16 reinoud if (error || newp == NULL)
405 1.16 reinoud return error;
406 1.16 reinoud
407 1.16 reinoud minfreq = cpu_freq_settings[0].freq;
408 1.16 reinoud maxfreq = cpu_freq_settings[ncpu_freq_settings-1].freq;
409 1.16 reinoud
410 1.16 reinoud if ((t < minfreq) || (t > maxfreq))
411 1.16 reinoud return EINVAL;
412 1.16 reinoud
413 1.16 reinoud if (t == curfreq) {
414 1.16 reinoud *(int *)rnode->sysctl_data = t;
415 1.16 reinoud return 0;
416 1.16 reinoud }
417 1.16 reinoud
418 1.16 reinoud diff = maxfreq;
419 1.16 reinoud best_i = -1;
420 1.16 reinoud for (i = 0; i < ncpu_freq_settings; i++) {
421 1.16 reinoud if (abs(t - cpu_freq_settings[i].freq) <= diff) {
422 1.16 reinoud diff = labs(t - cpu_freq_settings[i].freq);
423 1.16 reinoud best_i = i;
424 1.16 reinoud }
425 1.16 reinoud }
426 1.16 reinoud if (best_i < 0)
427 1.16 reinoud return EINVAL;
428 1.16 reinoud
429 1.16 reinoud exynos_set_cpufreq(&cpu_freq_settings[best_i]);
430 1.16 reinoud
431 1.16 reinoud *(int *)rnode->sysctl_data = t;
432 1.16 reinoud return 0;
433 1.16 reinoud }
434 1.16 reinoud
435 1.16 reinoud
436 1.16 reinoud static int
437 1.16 reinoud sysctl_cpufreq_current(SYSCTLFN_ARGS)
438 1.16 reinoud {
439 1.16 reinoud struct sysctlnode node = *rnode;
440 1.16 reinoud uint32_t freq;
441 1.16 reinoud
442 1.16 reinoud freq = exynos_get_cpufreq() / (1000*1000);
443 1.16 reinoud node.sysctl_data = &freq;
444 1.16 reinoud
445 1.16 reinoud return sysctl_lookup(SYSCTLFN_CALL(&node));
446 1.16 reinoud }
447 1.16 reinoud
448 1.16 reinoud
449 1.19 reinoud #ifdef VERBOSE_INIT_ARM
450 1.19 reinoud #define DUMP_PLL(v, var) \
451 1.19 reinoud reg = EXYNOS##v##_CMU_##var + PLL_CON0_OFFSET;\
452 1.19 reinoud regval = bus_space_read_4(&exynos_bs_tag, exynos_core_bsh, reg); \
453 1.19 reinoud freq = PLL_FREQ(EXYNOS_F_IN_FREQ, regval); \
454 1.19 reinoud printf("%8s at %d Mhz\n", #var, freq/(1000*1000));
455 1.19 reinoud
456 1.19 reinoud
457 1.19 reinoud static void
458 1.19 reinoud exynos_dump_clocks(void)
459 1.19 reinoud {
460 1.19 reinoud uint32_t reg = 0;
461 1.19 reinoud uint32_t regval;
462 1.19 reinoud uint32_t freq;
463 1.19 reinoud
464 1.19 reinoud printf("Initial PLL settings\n");
465 1.19 reinoud #ifdef EXYNOS4
466 1.19 reinoud if (IS_EXYNOS4_P()) {
467 1.19 reinoud DUMP_PLL(4, APLL);
468 1.19 reinoud DUMP_PLL(4, MPLL);
469 1.19 reinoud DUMP_PLL(4, EPLL);
470 1.19 reinoud DUMP_PLL(4, VPLL);
471 1.19 reinoud }
472 1.19 reinoud #endif
473 1.19 reinoud #ifdef EXYNOS5
474 1.19 reinoud if (IS_EXYNOS5_P()) {
475 1.19 reinoud DUMP_PLL(5, APLL);
476 1.19 reinoud DUMP_PLL(5, MPLL);
477 1.19 reinoud DUMP_PLL(5, EPLL);
478 1.19 reinoud DUMP_PLL(5, VPLL);
479 1.19 reinoud DUMP_PLL(5, CPLL);
480 1.19 reinoud DUMP_PLL(5, GPLL);
481 1.19 reinoud DUMP_PLL(5, BPLL);
482 1.19 reinoud }
483 1.19 reinoud #endif
484 1.19 reinoud }
485 1.19 reinoud #undef DUMP_PLL
486 1.19 reinoud #endif
487 1.19 reinoud
488 1.19 reinoud
489 1.16 reinoud void
490 1.16 reinoud exynos_clocks_bootstrap(void)
491 1.16 reinoud {
492 1.16 reinoud #ifdef EXYNOS4
493 1.16 reinoud if (IS_EXYNOS4_P()) {
494 1.16 reinoud cpu_freq_settings = cpu_freq_settings_exynos4;
495 1.16 reinoud ncpu_freq_settings = __arraycount(cpu_freq_settings_exynos4);
496 1.16 reinoud }
497 1.16 reinoud #endif
498 1.16 reinoud #ifdef EXYNOS5
499 1.16 reinoud if (IS_EXYNOS5_P()) {
500 1.16 reinoud cpu_freq_settings = cpu_freq_settings_exynos5;
501 1.16 reinoud ncpu_freq_settings = __arraycount(cpu_freq_settings_exynos5);
502 1.16 reinoud }
503 1.16 reinoud #endif
504 1.16 reinoud KASSERT(ncpu_freq_settings != 0);
505 1.16 reinoud KASSERT(ncpu_freq_settings < NFRQS);
506 1.16 reinoud
507 1.19 reinoud #ifdef VERBOSE_INIT_ARM
508 1.19 reinoud exynos_dump_clocks();
509 1.19 reinoud #endif
510 1.19 reinoud
511 1.16 reinoud /* set max cpufreq */
512 1.16 reinoud exynos_set_cpufreq(&cpu_freq_settings[ncpu_freq_settings-1]);
513 1.16 reinoud }
514 1.16 reinoud
515 1.16 reinoud
516 1.16 reinoud void
517 1.1 matt exynos_bootstrap(vaddr_t iobase, vaddr_t uartbase)
518 1.1 matt {
519 1.5 reinoud int error;
520 1.11 reinoud size_t core_size, audiocore_size;
521 1.15 reinoud size_t audiocore_pbase, audiocore_vbase __diagused;
522 1.11 reinoud
523 1.11 reinoud #ifdef EXYNOS4
524 1.11 reinoud if (IS_EXYNOS4_P()) {
525 1.11 reinoud core_size = EXYNOS4_CORE_SIZE;
526 1.11 reinoud audiocore_size = EXYNOS4_AUDIOCORE_SIZE;
527 1.11 reinoud audiocore_pbase = EXYNOS4_AUDIOCORE_PBASE;
528 1.12 reinoud audiocore_vbase = EXYNOS4_AUDIOCORE_VBASE;
529 1.11 reinoud }
530 1.11 reinoud #endif
531 1.11 reinoud
532 1.11 reinoud #ifdef EXYNOS5
533 1.11 reinoud if (IS_EXYNOS5_P()) {
534 1.11 reinoud core_size = EXYNOS5_CORE_SIZE;
535 1.11 reinoud audiocore_size = EXYNOS5_AUDIOCORE_SIZE;
536 1.11 reinoud audiocore_pbase = EXYNOS5_AUDIOCORE_PBASE;
537 1.12 reinoud audiocore_vbase = EXYNOS5_AUDIOCORE_VBASE;
538 1.11 reinoud }
539 1.11 reinoud #endif
540 1.1 matt
541 1.1 matt /* set up early console so we can use printf() and friends */
542 1.1 matt #ifdef EXYNOS_CONSOLE_EARLY
543 1.1 matt uart_base = (volatile uint8_t *) uartbase;
544 1.1 matt cn_tab = &exynos_earlycons;
545 1.1 matt printf("Exynos early console operational\n\n");
546 1.1 matt #endif
547 1.1 matt /* map in the exynos io registers */
548 1.1 matt error = bus_space_map(&exynos_bs_tag, EXYNOS_CORE_PBASE,
549 1.5 reinoud core_size, 0, &exynos_core_bsh);
550 1.1 matt if (error)
551 1.11 reinoud panic("%s: failed to map in Exynos SFR registers: %d",
552 1.1 matt __func__, error);
553 1.1 matt KASSERT(exynos_core_bsh == iobase);
554 1.7 reinoud
555 1.11 reinoud error = bus_space_map(&exynos_bs_tag, audiocore_pbase,
556 1.11 reinoud audiocore_size, 0, &exynos_audiocore_bsh);
557 1.11 reinoud if (error)
558 1.11 reinoud panic("%s: failed to map in Exynos audio SFR registers: %d",
559 1.11 reinoud __func__, error);
560 1.12 reinoud KASSERT(exynos_audiocore_bsh == audiocore_vbase);
561 1.11 reinoud
562 1.7 reinoud /* init bus dma tags */
563 1.7 reinoud exynos_dma_bootstrap(physmem * PAGE_SIZE);
564 1.8 reinoud
565 1.11 reinoud /* gpio bootstrapping delayed */
566 1.1 matt }
567 1.1 matt
568 1.1 matt
569 1.1 matt void
570 1.1 matt exynos_device_register(device_t self, void *aux)
571 1.1 matt {
572 1.1 matt if (device_is_a(self, "armperiph")
573 1.1 matt && device_is_a(device_parent(self), "mainbus")) {
574 1.1 matt /*
575 1.1 matt * XXX KLUDGE ALERT XXX
576 1.1 matt * The iot mainbus supplies is completely wrong since it scales
577 1.17 snj * addresses by 2. The simplest remedy is to replace with our
578 1.1 matt * bus space used for the armcore regisers (which armperiph uses).
579 1.1 matt */
580 1.1 matt struct mainbus_attach_args * const mb = aux;
581 1.1 matt mb->mb_iot = &exynos_bs_tag;
582 1.1 matt return;
583 1.1 matt }
584 1.1 matt if (device_is_a(self, "armgic")
585 1.1 matt && device_is_a(device_parent(self), "armperiph")) {
586 1.1 matt /*
587 1.1 matt * The Exynos4420 armgic is located at a different location!
588 1.1 matt */
589 1.1 matt
590 1.1 matt extern uint32_t exynos_soc_id;
591 1.6 reinoud
592 1.1 matt switch (EXYNOS_PRODUCT_ID(exynos_soc_id)) {
593 1.1 matt #if defined(EXYNOS5)
594 1.1 matt case 0xe5410:
595 1.6 reinoud /* offsets not changed on matt's request */
596 1.1 matt #if 0
597 1.6 reinoud mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
598 1.1 matt mpcaa->mpcaa_off1 = EXYNOS5_GIC_IOP_DISTRIBUTOR_OFFSET;
599 1.1 matt mpcaa->mpcaa_off2 = EXYNOS5_GIC_IOP_CONTROLLER_OFFSET;
600 1.1 matt #endif
601 1.1 matt break;
602 1.1 matt #endif
603 1.1 matt #if defined(EXYNOS4)
604 1.1 matt case 0xe4410:
605 1.12 reinoud case 0xe4412: {
606 1.12 reinoud struct mpcore_attach_args * const mpcaa = aux;
607 1.12 reinoud
608 1.1 matt mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
609 1.1 matt mpcaa->mpcaa_off1 = EXYNOS4_GIC_DISTRIBUTOR_OFFSET;
610 1.1 matt mpcaa->mpcaa_off2 = EXYNOS4_GIC_CNTR_OFFSET;
611 1.1 matt break;
612 1.12 reinoud }
613 1.1 matt #endif
614 1.1 matt default:
615 1.1 matt panic("%s: unknown SoC product id %#x", __func__,
616 1.1 matt (u_int)EXYNOS_PRODUCT_ID(exynos_soc_id));
617 1.1 matt }
618 1.1 matt return;
619 1.1 matt }
620 1.10 reinoud if (device_is_a(self, "armgtmr") || device_is_a(self, "mct")) {
621 1.14 matt #ifdef EXYNOS5
622 1.13 matt /*
623 1.13 matt * The global timer is dependent on the MCT running.
624 1.13 matt */
625 1.13 matt bus_size_t o = EXYNOS5_MCT_OFFSET + MCT_G_TCON;
626 1.13 matt uint32_t v = bus_space_read_4(&exynos_bs_tag, exynos_core_bsh,
627 1.14 matt o);
628 1.13 matt v |= G_TCON_START;
629 1.13 matt bus_space_write_4(&exynos_bs_tag, exynos_core_bsh, o, v);
630 1.13 matt #endif
631 1.1 matt /*
632 1.10 reinoud * The frequencies of the timers are the reference
633 1.1 matt * frequency.
634 1.1 matt */
635 1.1 matt prop_dictionary_set_uint32(device_properties(self),
636 1.10 reinoud "frequency", EXYNOS_F_IN_FREQ);
637 1.1 matt return;
638 1.1 matt }
639 1.1 matt
640 1.1 matt exyo_device_register(self, aux);
641 1.1 matt }
642 1.1 matt
643 1.9 reinoud
644 1.9 reinoud void
645 1.9 reinoud exynos_device_register_post_config(device_t self, void *aux)
646 1.9 reinoud {
647 1.9 reinoud exyo_device_register_post_config(self, aux);
648 1.9 reinoud }
649 1.9 reinoud
650