exynos_soc.c revision 1.23 1 1.23 reinoud /* $NetBSD: exynos_soc.c,v 1.23 2014/09/30 14:23:41 reinoud 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.23 reinoud __KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.23 2014/09/30 14:23:41 reinoud 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
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.16 reinoud /* cpu frequencies */
71 1.16 reinoud struct cpu_freq {
72 1.16 reinoud uint64_t freq;
73 1.16 reinoud int P;
74 1.16 reinoud int M;
75 1.16 reinoud int S;
76 1.16 reinoud };
77 1.16 reinoud
78 1.16 reinoud
79 1.16 reinoud #ifdef EXYNOS4
80 1.16 reinoud const struct cpu_freq cpu_freq_settings_exynos4[] = {
81 1.16 reinoud { 200, 3, 100, 2},
82 1.16 reinoud { 300, 4, 200, 2},
83 1.16 reinoud { 400, 3, 100, 1},
84 1.16 reinoud { 500, 3, 125, 1},
85 1.16 reinoud { 600, 4, 200, 1},
86 1.16 reinoud { 700, 3, 175, 1},
87 1.16 reinoud { 800, 3, 100, 0},
88 1.16 reinoud { 900, 4, 150, 0},
89 1.16 reinoud {1000, 3, 125, 0},
90 1.16 reinoud {1100, 6, 275, 0},
91 1.16 reinoud {1200, 4, 200, 0},
92 1.16 reinoud {1300, 6, 325, 0},
93 1.16 reinoud {1400, 3, 175, 0},
94 1.16 reinoud {1600, 3, 200, 0},
95 1.16 reinoud };
96 1.16 reinoud #endif
97 1.16 reinoud
98 1.16 reinoud
99 1.16 reinoud #ifdef EXYNOS5
100 1.16 reinoud const struct cpu_freq cpu_freq_settings_exynos5[] = {
101 1.16 reinoud { 200, 3, 100, 2},
102 1.16 reinoud { 333, 4, 222, 2},
103 1.16 reinoud { 400, 3, 100, 1},
104 1.16 reinoud { 533, 12, 533, 1},
105 1.16 reinoud { 600, 4, 200, 1},
106 1.16 reinoud { 667, 7, 389, 1},
107 1.16 reinoud { 800, 3, 100, 0},
108 1.16 reinoud {1000, 3, 125, 0},
109 1.16 reinoud {1066, 12, 533, 0},
110 1.16 reinoud {1200, 3, 150, 0},
111 1.16 reinoud {1400, 3, 175, 0},
112 1.16 reinoud {1600, 3, 200, 0},
113 1.16 reinoud };
114 1.16 reinoud #endif
115 1.16 reinoud
116 1.16 reinoud static struct cpu_freq const *cpu_freq_settings = NULL;
117 1.16 reinoud static int ncpu_freq_settings = 0;
118 1.16 reinoud
119 1.16 reinoud static int cpu_freq_target = 0;
120 1.16 reinoud #define NFRQS 15
121 1.16 reinoud static char sysctl_cpu_freqs_txt[NFRQS*5];
122 1.16 reinoud
123 1.21 reinoud bus_space_handle_t exynos_core_bsh;
124 1.21 reinoud bus_space_handle_t exynos_audiocore_bsh;
125 1.21 reinoud
126 1.21 reinoud bus_space_handle_t exynos_wdt_bsh;
127 1.21 reinoud bus_space_handle_t exynos_pmu_bsh;
128 1.21 reinoud bus_space_handle_t exynos_cmu_bsh;
129 1.21 reinoud bus_space_handle_t exynos_cmu_apll_bsh;
130 1.22 reinoud bus_space_handle_t exynos_sysreg_bsh;
131 1.21 reinoud
132 1.21 reinoud
133 1.16 reinoud static int sysctl_cpufreq_target(SYSCTLFN_ARGS);
134 1.16 reinoud static int sysctl_cpufreq_current(SYSCTLFN_ARGS);
135 1.16 reinoud
136 1.1 matt /*
137 1.1 matt * the early serial console
138 1.1 matt */
139 1.1 matt #ifdef EXYNOS_CONSOLE_EARLY
140 1.1 matt
141 1.1 matt #include "opt_sscom.h"
142 1.1 matt #include <arm/samsung/sscom_reg.h>
143 1.1 matt #include <arm/samsung/sscom_var.h>
144 1.1 matt #include <dev/cons.h>
145 1.1 matt
146 1.1 matt static volatile uint8_t *uart_base;
147 1.1 matt
148 1.1 matt #define CON_REG(a) (*((volatile uint32_t *)(uart_base + (a))))
149 1.1 matt
150 1.1 matt static int
151 1.1 matt exynos_cngetc(dev_t dv)
152 1.1 matt {
153 1.1 matt if ((CON_REG(SSCOM_UTRSTAT) & UTRSTAT_RXREADY) == 0)
154 1.1 matt return -1;
155 1.1 matt
156 1.1 matt return CON_REG(SSCOM_URXH);
157 1.1 matt }
158 1.1 matt
159 1.1 matt static void
160 1.1 matt exynos_cnputc(dev_t dv, int c)
161 1.1 matt {
162 1.1 matt int timo = 150000;
163 1.1 matt
164 1.1 matt while ((CON_REG(SSCOM_UFSTAT) & UFSTAT_TXFULL) && --timo > 0);
165 1.1 matt
166 1.1 matt CON_REG(SSCOM_UTXH) = c & 0xff;
167 1.1 matt }
168 1.1 matt
169 1.1 matt static struct consdev exynos_earlycons = {
170 1.1 matt .cn_putc = exynos_cnputc,
171 1.1 matt .cn_getc = exynos_cngetc,
172 1.1 matt .cn_pollc = nullcnpollc,
173 1.1 matt };
174 1.1 matt #endif /* EXYNOS_CONSOLE_EARLY */
175 1.1 matt
176 1.1 matt
177 1.1 matt #ifdef ARM_TRUSTZONE_FIRMWARE
178 1.2 reinoud int
179 1.1 matt exynos_do_idle(void)
180 1.1 matt {
181 1.1 matt exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
182 1.1 matt
183 1.1 matt return 0;
184 1.1 matt }
185 1.1 matt
186 1.1 matt
187 1.2 reinoud int
188 1.1 matt exynos_set_cpu_boot_addr(int cpu, vaddr_t boot_addr)
189 1.1 matt {
190 1.2 reinoud /* XXX we need to map in iRAM space for this XXX */
191 1.1 matt return 0;
192 1.1 matt }
193 1.1 matt
194 1.1 matt
195 1.2 reinoud int
196 1.1 matt exynos_cpu_boot(int cpu)
197 1.1 matt {
198 1.1 matt exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0);
199 1.1 matt
200 1.1 matt return 0;
201 1.1 matt }
202 1.1 matt
203 1.1 matt
204 1.23 reinoud #ifdef EXYNOS4
205 1.1 matt /*
206 1.17 snj * The latency values used below are `magic' and probably chosen empirically.
207 1.1 matt * For the 4210 variant the data latency is lower, a 0x110. This is currently
208 1.1 matt * not enforced.
209 1.1 matt *
210 1.1 matt * The prefetch values are also different for the revision 0 of the
211 1.1 matt * Exynos4412, but why?
212 1.1 matt */
213 1.1 matt
214 1.2 reinoud int
215 1.23 reinoud exynos4_l2cc_init(void)
216 1.1 matt {
217 1.1 matt const uint32_t tag_latency = 0x110;
218 1.2 reinoud const uint32_t data_latency = IS_EXYNOS4410_P() ? 0x110 : 0x120;
219 1.1 matt const uint32_t prefetch4412 = /* 0111 0001 0000 0000 0000 0000 0000 0111 */
220 1.1 matt PREFETCHCTL_DBLLINEF_EN |
221 1.1 matt PREFETCHCTL_INSTRPREF_EN |
222 1.1 matt PREFETCHCTL_DATAPREF_EN |
223 1.1 matt PREFETCHCTL_PREF_DROP_EN |
224 1.1 matt PREFETCHCTL_PREFETCH_OFFSET_7;
225 1.1 matt const uint32_t prefetch4412_r0 = /* 0011 0000 0000 0000 0000 0000 0000 0111 */
226 1.1 matt PREFETCHCTL_INSTRPREF_EN |
227 1.1 matt PREFETCHCTL_DATAPREF_EN |
228 1.1 matt PREFETCHCTL_PREFETCH_OFFSET_7;
229 1.1 matt const uint32_t aux_val = /* 0111 1100 0100 0111 0000 0000 0000 0001 */
230 1.1 matt AUXCTL_EARLY_BRESP_EN |
231 1.1 matt AUXCTL_I_PREFETCH |
232 1.1 matt AUXCTL_D_PREFETCH |
233 1.1 matt AUXCTL_NS_INT_ACC_CTL |
234 1.1 matt AUXCTL_NS_INT_LOCK_EN |
235 1.1 matt AUXCTL_SHARED_ATT_OVR |
236 1.1 matt AUXCTL_WAY_SIZE_RSVD7 << 16 | /* why rsvd7 ??? */
237 1.1 matt AUXCTL_FULL_LINE_WR0;
238 1.1 matt const uint32_t aux_keepmask = /* 1100 0010 0000 0000 1111 1111 1111 1111 */
239 1.1 matt AUXCTL_RSVD31 |
240 1.1 matt AUXCTL_EARLY_BRESP_EN |
241 1.1 matt AUXCTL_CACHE_REPL_RR |
242 1.1 matt
243 1.1 matt AUXCTL_SH_ATTR_INV_ENA|
244 1.1 matt AUXCTL_EXCL_CACHE_CFG |
245 1.1 matt AUXCTL_ST_BUF_DEV_LIM_EN |
246 1.1 matt AUXCTL_HIPRO_SO_DEV_EN |
247 1.1 matt AUXCTL_FULL_LINE_WR0 |
248 1.1 matt 0xffff;
249 1.1 matt uint32_t prefetch;
250 1.1 matt
251 1.1 matt /* check the bitmaps are the same as the linux implementation uses */
252 1.1 matt KASSERT(prefetch4412 == 0x71000007);
253 1.1 matt KASSERT(prefetch4412_r0 == 0x30000007);
254 1.1 matt KASSERT(aux_val == 0x7C470001);
255 1.1 matt KASSERT(aux_keepmask == 0xC200FFFF);
256 1.1 matt
257 1.2 reinoud if (IS_EXYNOS4412_R0_P())
258 1.1 matt prefetch = prefetch4412_r0;
259 1.1 matt else
260 1.1 matt prefetch = prefetch4412; /* newer than >= r1_0 */
261 1.1 matt ;
262 1.1 matt
263 1.1 matt exynos_smc(SMC_CMD_L2X0SETUP1, tag_latency, data_latency, prefetch);
264 1.1 matt exynos_smc(SMC_CMD_L2X0SETUP2,
265 1.1 matt POWERCTL_DYNCLKGATE | POWERCTL_STANDBY,
266 1.1 matt aux_val, aux_keepmask);
267 1.1 matt exynos_smc(SMC_CMD_L2X0INVALL, 0, 0, 0);
268 1.1 matt exynos_smc(SMC_CMD_L2X0CTRL, 1, 0, 0);
269 1.1 matt
270 1.1 matt return 0;
271 1.1 matt }
272 1.23 reinoud #endif
273 1.2 reinoud #endif /* ARM_TRUSTZONE_FIRMWARE */
274 1.1 matt
275 1.1 matt
276 1.1 matt void
277 1.16 reinoud exynos_sysctl_cpufreq_init(void)
278 1.16 reinoud {
279 1.16 reinoud const struct sysctlnode *node, *cpunode, *freqnode;
280 1.16 reinoud char *cpos;
281 1.16 reinoud int i, val;
282 1.16 reinoud int error;
283 1.16 reinoud
284 1.16 reinoud memset(sysctl_cpu_freqs_txt, (int) ' ', sizeof(sysctl_cpu_freqs_txt));
285 1.16 reinoud cpos = sysctl_cpu_freqs_txt;
286 1.16 reinoud for (i = 0; i < ncpu_freq_settings; i++) {
287 1.16 reinoud val = cpu_freq_settings[i].freq;
288 1.16 reinoud snprintf(cpos, 6, "%d ", val);
289 1.16 reinoud cpos += (val < 1000) ? 4 : 5;
290 1.16 reinoud }
291 1.16 reinoud *cpos = 0;
292 1.16 reinoud
293 1.16 reinoud error = sysctl_createv(NULL, 0, NULL, &node,
294 1.16 reinoud CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
295 1.16 reinoud NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
296 1.16 reinoud if (error)
297 1.16 reinoud printf("couldn't create `machdep' node\n");
298 1.16 reinoud
299 1.16 reinoud error = sysctl_createv(NULL, 0, &node, &cpunode,
300 1.16 reinoud 0, CTLTYPE_NODE, "cpu", NULL,
301 1.16 reinoud NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
302 1.16 reinoud if (error)
303 1.16 reinoud printf("couldn't create `cpu' node\n");
304 1.16 reinoud
305 1.16 reinoud error = sysctl_createv(NULL, 0, &cpunode, &freqnode,
306 1.16 reinoud 0, CTLTYPE_NODE, "frequency", NULL,
307 1.16 reinoud NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
308 1.16 reinoud if (error)
309 1.16 reinoud printf("couldn't create `frequency' node\n");
310 1.16 reinoud
311 1.16 reinoud error = sysctl_createv(NULL, 0, &freqnode, &node,
312 1.16 reinoud CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
313 1.16 reinoud sysctl_cpufreq_target, 0, &cpu_freq_target, 0,
314 1.16 reinoud CTL_CREATE, CTL_EOL);
315 1.16 reinoud if (error)
316 1.16 reinoud printf("couldn't create `target' node\n");
317 1.16 reinoud
318 1.16 reinoud error = sysctl_createv(NULL, 0, &freqnode, &node,
319 1.16 reinoud 0, CTLTYPE_INT, "current", NULL,
320 1.16 reinoud sysctl_cpufreq_current, 0, NULL, 0,
321 1.16 reinoud CTL_CREATE, CTL_EOL);
322 1.16 reinoud if (error)
323 1.16 reinoud printf("couldn't create `current' node\n");
324 1.16 reinoud
325 1.16 reinoud error = sysctl_createv(NULL, 0, &freqnode, &node,
326 1.16 reinoud CTLFLAG_READONLY, CTLTYPE_STRING, "available", NULL,
327 1.16 reinoud NULL, 0, sysctl_cpu_freqs_txt, 0,
328 1.16 reinoud CTL_CREATE, CTL_EOL);
329 1.16 reinoud if (error)
330 1.16 reinoud printf("couldn't create `available' node\b");
331 1.16 reinoud }
332 1.16 reinoud
333 1.16 reinoud
334 1.16 reinoud uint64_t
335 1.16 reinoud exynos_get_cpufreq(void)
336 1.16 reinoud {
337 1.16 reinoud uint32_t regval;
338 1.16 reinoud uint32_t freq;
339 1.16 reinoud
340 1.21 reinoud regval = bus_space_read_4(&exynos_bs_tag, exynos_cmu_apll_bsh,
341 1.21 reinoud PLL_CON0_OFFSET);
342 1.16 reinoud freq = PLL_FREQ(EXYNOS_F_IN_FREQ, regval);
343 1.16 reinoud
344 1.16 reinoud return freq;
345 1.16 reinoud }
346 1.16 reinoud
347 1.16 reinoud
348 1.16 reinoud static void
349 1.16 reinoud exynos_set_cpufreq(const struct cpu_freq *freqreq)
350 1.16 reinoud {
351 1.18 reinoud struct cpu_info *ci;
352 1.16 reinoud uint32_t regval;
353 1.16 reinoud int M, P, S;
354 1.18 reinoud int cii;
355 1.16 reinoud
356 1.16 reinoud M = freqreq->M;
357 1.16 reinoud P = freqreq->P;
358 1.16 reinoud S = freqreq->S;
359 1.16 reinoud
360 1.16 reinoud regval = __SHIFTIN(M, PLL_CON0_M) |
361 1.16 reinoud __SHIFTIN(P, PLL_CON0_P) |
362 1.16 reinoud __SHIFTIN(S, PLL_CON0_S);
363 1.16 reinoud
364 1.16 reinoud /* enable PPL and write config */
365 1.16 reinoud regval |= PLL_CON0_ENABLE;
366 1.21 reinoud bus_space_write_4(&exynos_bs_tag, exynos_cmu_apll_bsh, PLL_CON0_OFFSET,
367 1.21 reinoud regval);
368 1.18 reinoud
369 1.18 reinoud /* update our cycle counter i.e. our CPU frequency for all CPUs */
370 1.18 reinoud for (CPU_INFO_FOREACH(cii, ci)) {
371 1.18 reinoud ci->ci_data.cpu_cc_freq = exynos_get_cpufreq();
372 1.18 reinoud }
373 1.16 reinoud }
374 1.16 reinoud
375 1.16 reinoud
376 1.16 reinoud static int
377 1.16 reinoud sysctl_cpufreq_target(SYSCTLFN_ARGS)
378 1.16 reinoud {
379 1.16 reinoud struct sysctlnode node;
380 1.16 reinoud uint32_t t, curfreq, minfreq, maxfreq;
381 1.16 reinoud int i, best_i, diff;
382 1.16 reinoud int error;
383 1.16 reinoud
384 1.16 reinoud curfreq = exynos_get_cpufreq() / (1000*1000);
385 1.16 reinoud t = *(int *)rnode->sysctl_data;
386 1.16 reinoud if (t == 0)
387 1.16 reinoud t = curfreq;
388 1.16 reinoud
389 1.16 reinoud node = *rnode;
390 1.16 reinoud node.sysctl_data = &t;
391 1.16 reinoud error = sysctl_lookup(SYSCTLFN_CALL(&node));
392 1.16 reinoud if (error || newp == NULL)
393 1.16 reinoud return error;
394 1.16 reinoud
395 1.16 reinoud minfreq = cpu_freq_settings[0].freq;
396 1.16 reinoud maxfreq = cpu_freq_settings[ncpu_freq_settings-1].freq;
397 1.16 reinoud
398 1.16 reinoud if ((t < minfreq) || (t > maxfreq))
399 1.16 reinoud return EINVAL;
400 1.16 reinoud
401 1.16 reinoud if (t == curfreq) {
402 1.16 reinoud *(int *)rnode->sysctl_data = t;
403 1.16 reinoud return 0;
404 1.16 reinoud }
405 1.16 reinoud
406 1.16 reinoud diff = maxfreq;
407 1.16 reinoud best_i = -1;
408 1.16 reinoud for (i = 0; i < ncpu_freq_settings; i++) {
409 1.16 reinoud if (abs(t - cpu_freq_settings[i].freq) <= diff) {
410 1.16 reinoud diff = labs(t - cpu_freq_settings[i].freq);
411 1.16 reinoud best_i = i;
412 1.16 reinoud }
413 1.16 reinoud }
414 1.16 reinoud if (best_i < 0)
415 1.16 reinoud return EINVAL;
416 1.16 reinoud
417 1.16 reinoud exynos_set_cpufreq(&cpu_freq_settings[best_i]);
418 1.16 reinoud
419 1.16 reinoud *(int *)rnode->sysctl_data = t;
420 1.16 reinoud return 0;
421 1.16 reinoud }
422 1.16 reinoud
423 1.16 reinoud
424 1.16 reinoud static int
425 1.16 reinoud sysctl_cpufreq_current(SYSCTLFN_ARGS)
426 1.16 reinoud {
427 1.16 reinoud struct sysctlnode node = *rnode;
428 1.16 reinoud uint32_t freq;
429 1.16 reinoud
430 1.16 reinoud freq = exynos_get_cpufreq() / (1000*1000);
431 1.16 reinoud node.sysctl_data = &freq;
432 1.16 reinoud
433 1.16 reinoud return sysctl_lookup(SYSCTLFN_CALL(&node));
434 1.16 reinoud }
435 1.16 reinoud
436 1.16 reinoud
437 1.19 reinoud #ifdef VERBOSE_INIT_ARM
438 1.19 reinoud #define DUMP_PLL(v, var) \
439 1.19 reinoud reg = EXYNOS##v##_CMU_##var + PLL_CON0_OFFSET;\
440 1.21 reinoud regval = bus_space_read_4(&exynos_bs_tag, exynos_cmu_bsh, reg); \
441 1.19 reinoud freq = PLL_FREQ(EXYNOS_F_IN_FREQ, regval); \
442 1.19 reinoud printf("%8s at %d Mhz\n", #var, freq/(1000*1000));
443 1.19 reinoud
444 1.19 reinoud
445 1.19 reinoud static void
446 1.19 reinoud exynos_dump_clocks(void)
447 1.19 reinoud {
448 1.19 reinoud uint32_t reg = 0;
449 1.19 reinoud uint32_t regval;
450 1.19 reinoud uint32_t freq;
451 1.19 reinoud
452 1.19 reinoud printf("Initial PLL settings\n");
453 1.19 reinoud #ifdef EXYNOS4
454 1.21 reinoud DUMP_PLL(4, APLL);
455 1.21 reinoud DUMP_PLL(4, MPLL);
456 1.21 reinoud DUMP_PLL(4, EPLL);
457 1.21 reinoud DUMP_PLL(4, VPLL);
458 1.19 reinoud #endif
459 1.19 reinoud #ifdef EXYNOS5
460 1.21 reinoud DUMP_PLL(5, APLL);
461 1.21 reinoud DUMP_PLL(5, MPLL);
462 1.21 reinoud DUMP_PLL(5, EPLL);
463 1.21 reinoud DUMP_PLL(5, VPLL);
464 1.21 reinoud DUMP_PLL(5, CPLL);
465 1.21 reinoud DUMP_PLL(5, GPLL);
466 1.21 reinoud DUMP_PLL(5, BPLL);
467 1.19 reinoud #endif
468 1.19 reinoud }
469 1.19 reinoud #undef DUMP_PLL
470 1.19 reinoud #endif
471 1.19 reinoud
472 1.19 reinoud
473 1.21 reinoud /* XXX clock stuff needs major work XXX */
474 1.21 reinoud
475 1.21 reinoud void
476 1.21 reinoud exynos_clocks_bootstrap(void)
477 1.21 reinoud {
478 1.16 reinoud KASSERT(ncpu_freq_settings != 0);
479 1.16 reinoud KASSERT(ncpu_freq_settings < NFRQS);
480 1.16 reinoud
481 1.19 reinoud #ifdef VERBOSE_INIT_ARM
482 1.19 reinoud exynos_dump_clocks();
483 1.19 reinoud #endif
484 1.19 reinoud
485 1.16 reinoud /* set max cpufreq */
486 1.16 reinoud exynos_set_cpufreq(&cpu_freq_settings[ncpu_freq_settings-1]);
487 1.21 reinoud
488 1.21 reinoud /* set external USB frequency to XCLKOUT */
489 1.21 reinoud exynos_init_clkout_for_usb();
490 1.16 reinoud }
491 1.16 reinoud
492 1.16 reinoud
493 1.16 reinoud void
494 1.1 matt exynos_bootstrap(vaddr_t iobase, vaddr_t uartbase)
495 1.1 matt {
496 1.5 reinoud int error;
497 1.11 reinoud size_t core_size, audiocore_size;
498 1.21 reinoud bus_addr_t audiocore_pbase;
499 1.21 reinoud bus_addr_t audiocore_vbase __diagused;
500 1.21 reinoud bus_addr_t exynos_wdt_offset;
501 1.21 reinoud bus_addr_t exynos_pmu_offset;
502 1.22 reinoud bus_addr_t exynos_sysreg_offset;
503 1.21 reinoud bus_addr_t exynos_cmu_apll_offset;
504 1.21 reinoud
505 1.21 reinoud /* set up early console so we can use printf() and friends */
506 1.21 reinoud #ifdef EXYNOS_CONSOLE_EARLY
507 1.21 reinoud uart_base = (volatile uint8_t *) uartbase;
508 1.21 reinoud cn_tab = &exynos_earlycons;
509 1.21 reinoud printf("Exynos early console operational\n\n");
510 1.21 reinoud #endif
511 1.11 reinoud
512 1.11 reinoud #ifdef EXYNOS4
513 1.21 reinoud core_size = EXYNOS4_CORE_SIZE;
514 1.21 reinoud audiocore_size = EXYNOS4_AUDIOCORE_SIZE;
515 1.21 reinoud audiocore_pbase = EXYNOS4_AUDIOCORE_PBASE;
516 1.21 reinoud audiocore_vbase = EXYNOS4_AUDIOCORE_VBASE;
517 1.21 reinoud exynos_wdt_offset = EXYNOS4_WDT_OFFSET;
518 1.21 reinoud exynos_pmu_offset = EXYNOS4_PMU_OFFSET;
519 1.22 reinoud exynos_sysreg_offset = EXYNOS4_SYSREG_OFFSET;
520 1.21 reinoud exynos_cmu_apll_offset = EXYNOS4_CMU_APLL;
521 1.21 reinoud
522 1.21 reinoud cpu_freq_settings = cpu_freq_settings_exynos4;
523 1.21 reinoud ncpu_freq_settings = __arraycount(cpu_freq_settings_exynos4);
524 1.11 reinoud #endif
525 1.11 reinoud
526 1.11 reinoud #ifdef EXYNOS5
527 1.21 reinoud core_size = EXYNOS5_CORE_SIZE;
528 1.21 reinoud audiocore_size = EXYNOS5_AUDIOCORE_SIZE;
529 1.21 reinoud audiocore_pbase = EXYNOS5_AUDIOCORE_PBASE;
530 1.21 reinoud audiocore_vbase = EXYNOS5_AUDIOCORE_VBASE;
531 1.21 reinoud exynos_wdt_offset = EXYNOS5_WDT_OFFSET;
532 1.21 reinoud exynos_pmu_offset = EXYNOS5_PMU_OFFSET;
533 1.22 reinoud exynos_sysreg_offset = EXYNOS5_SYSREG_OFFSET;
534 1.21 reinoud exynos_cmu_apll_offset = EXYNOS5_CMU_APLL;
535 1.21 reinoud
536 1.21 reinoud cpu_freq_settings = cpu_freq_settings_exynos5;
537 1.21 reinoud ncpu_freq_settings = __arraycount(cpu_freq_settings_exynos5);
538 1.11 reinoud #endif
539 1.1 matt
540 1.1 matt /* map in the exynos io registers */
541 1.1 matt error = bus_space_map(&exynos_bs_tag, EXYNOS_CORE_PBASE,
542 1.5 reinoud core_size, 0, &exynos_core_bsh);
543 1.1 matt if (error)
544 1.11 reinoud panic("%s: failed to map in Exynos SFR registers: %d",
545 1.1 matt __func__, error);
546 1.1 matt KASSERT(exynos_core_bsh == iobase);
547 1.7 reinoud
548 1.11 reinoud error = bus_space_map(&exynos_bs_tag, audiocore_pbase,
549 1.11 reinoud audiocore_size, 0, &exynos_audiocore_bsh);
550 1.11 reinoud if (error)
551 1.11 reinoud panic("%s: failed to map in Exynos audio SFR registers: %d",
552 1.11 reinoud __func__, error);
553 1.12 reinoud KASSERT(exynos_audiocore_bsh == audiocore_vbase);
554 1.11 reinoud
555 1.21 reinoud /* map in commonly used subregions and common used register banks */
556 1.21 reinoud error = bus_space_subregion(&exynos_bs_tag, exynos_core_bsh,
557 1.21 reinoud exynos_wdt_offset, EXYNOS_BLOCK_SIZE, &exynos_wdt_bsh);
558 1.21 reinoud if (error)
559 1.21 reinoud panic("%s: failed to subregion wdt registers: %d",
560 1.21 reinoud __func__, error);
561 1.21 reinoud
562 1.21 reinoud error = bus_space_subregion(&exynos_bs_tag, exynos_core_bsh,
563 1.21 reinoud exynos_pmu_offset, EXYNOS_BLOCK_SIZE, &exynos_pmu_bsh);
564 1.21 reinoud if (error)
565 1.21 reinoud panic("%s: failed to subregion pmu registers: %d",
566 1.21 reinoud __func__, error);
567 1.21 reinoud
568 1.21 reinoud exynos_cmu_bsh = exynos_core_bsh;
569 1.22 reinoud bus_space_subregion(&exynos_bs_tag, exynos_core_bsh,
570 1.22 reinoud exynos_sysreg_offset, EXYNOS_BLOCK_SIZE,
571 1.22 reinoud &exynos_sysreg_bsh);
572 1.22 reinoud if (error)
573 1.22 reinoud panic("%s: failed to subregion sysreg registers: %d",
574 1.22 reinoud __func__, error);
575 1.22 reinoud
576 1.21 reinoud error = bus_space_subregion(&exynos_bs_tag, exynos_cmu_bsh,
577 1.21 reinoud exynos_cmu_apll_offset, 0xfff, &exynos_cmu_apll_bsh);
578 1.21 reinoud if (error)
579 1.21 reinoud panic("%s: failed to subregion cmu apll registers: %d",
580 1.21 reinoud __func__, error);
581 1.21 reinoud
582 1.7 reinoud /* init bus dma tags */
583 1.7 reinoud exynos_dma_bootstrap(physmem * PAGE_SIZE);
584 1.8 reinoud
585 1.11 reinoud /* gpio bootstrapping delayed */
586 1.1 matt }
587 1.1 matt
588 1.1 matt
589 1.1 matt void
590 1.1 matt exynos_device_register(device_t self, void *aux)
591 1.1 matt {
592 1.1 matt if (device_is_a(self, "armperiph")
593 1.1 matt && device_is_a(device_parent(self), "mainbus")) {
594 1.1 matt /*
595 1.1 matt * XXX KLUDGE ALERT XXX
596 1.1 matt * The iot mainbus supplies is completely wrong since it scales
597 1.17 snj * addresses by 2. The simplest remedy is to replace with our
598 1.23 reinoud * bus space used for the armcore registers (which armperiph uses).
599 1.1 matt */
600 1.1 matt struct mainbus_attach_args * const mb = aux;
601 1.1 matt mb->mb_iot = &exynos_bs_tag;
602 1.1 matt return;
603 1.1 matt }
604 1.1 matt if (device_is_a(self, "armgic")
605 1.1 matt && device_is_a(device_parent(self), "armperiph")) {
606 1.1 matt /*
607 1.1 matt * The Exynos4420 armgic is located at a different location!
608 1.1 matt */
609 1.1 matt
610 1.1 matt extern uint32_t exynos_soc_id;
611 1.6 reinoud
612 1.1 matt switch (EXYNOS_PRODUCT_ID(exynos_soc_id)) {
613 1.21 reinoud #ifdef EXYNOS5
614 1.1 matt case 0xe5410:
615 1.6 reinoud /* offsets not changed on matt's request */
616 1.1 matt #if 0
617 1.6 reinoud mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
618 1.1 matt mpcaa->mpcaa_off1 = EXYNOS5_GIC_IOP_DISTRIBUTOR_OFFSET;
619 1.1 matt mpcaa->mpcaa_off2 = EXYNOS5_GIC_IOP_CONTROLLER_OFFSET;
620 1.1 matt #endif
621 1.1 matt break;
622 1.1 matt #endif
623 1.21 reinoud #ifdef EXYNOS4
624 1.1 matt case 0xe4410:
625 1.12 reinoud case 0xe4412: {
626 1.12 reinoud struct mpcore_attach_args * const mpcaa = aux;
627 1.12 reinoud
628 1.1 matt mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
629 1.1 matt mpcaa->mpcaa_off1 = EXYNOS4_GIC_DISTRIBUTOR_OFFSET;
630 1.1 matt mpcaa->mpcaa_off2 = EXYNOS4_GIC_CNTR_OFFSET;
631 1.1 matt break;
632 1.12 reinoud }
633 1.1 matt #endif
634 1.1 matt default:
635 1.1 matt panic("%s: unknown SoC product id %#x", __func__,
636 1.1 matt (u_int)EXYNOS_PRODUCT_ID(exynos_soc_id));
637 1.1 matt }
638 1.1 matt return;
639 1.1 matt }
640 1.10 reinoud if (device_is_a(self, "armgtmr") || device_is_a(self, "mct")) {
641 1.14 matt #ifdef EXYNOS5
642 1.13 matt /*
643 1.13 matt * The global timer is dependent on the MCT running.
644 1.13 matt */
645 1.13 matt bus_size_t o = EXYNOS5_MCT_OFFSET + MCT_G_TCON;
646 1.13 matt uint32_t v = bus_space_read_4(&exynos_bs_tag, exynos_core_bsh,
647 1.14 matt o);
648 1.13 matt v |= G_TCON_START;
649 1.13 matt bus_space_write_4(&exynos_bs_tag, exynos_core_bsh, o, v);
650 1.13 matt #endif
651 1.1 matt /*
652 1.10 reinoud * The frequencies of the timers are the reference
653 1.1 matt * frequency.
654 1.1 matt */
655 1.1 matt prop_dictionary_set_uint32(device_properties(self),
656 1.10 reinoud "frequency", EXYNOS_F_IN_FREQ);
657 1.1 matt return;
658 1.1 matt }
659 1.1 matt
660 1.1 matt exyo_device_register(self, aux);
661 1.1 matt }
662 1.1 matt
663 1.9 reinoud
664 1.9 reinoud void
665 1.9 reinoud exynos_device_register_post_config(device_t self, void *aux)
666 1.9 reinoud {
667 1.9 reinoud exyo_device_register_post_config(self, aux);
668 1.9 reinoud }
669 1.9 reinoud
670 1.23 reinoud
671 1.23 reinoud /*
672 1.23 reinoud * USB power SoC dependent handling
673 1.23 reinoud */
674 1.23 reinoud
675 1.23 reinoud #ifdef EXYNOS4
676 1.23 reinoud static struct exynos_gpio_pinset e4_uhost_pwr_pinset = {
677 1.23 reinoud .pinset_group = "ETC6",
678 1.23 reinoud .pinset_func = 0,
679 1.23 reinoud .pinset_mask = __BIT(6) | __BIT(7),
680 1.23 reinoud };
681 1.23 reinoud #endif
682 1.23 reinoud
683 1.23 reinoud
684 1.23 reinoud #ifdef EXYNOS5
685 1.23 reinoud static struct exynos_gpio_pinset e5_uhost_pwr_pinset = {
686 1.23 reinoud .pinset_group = "ETC6",
687 1.23 reinoud .pinset_func = 0,
688 1.23 reinoud .pinset_mask = __BIT(5) | __BIT(6),
689 1.23 reinoud };
690 1.23 reinoud static struct exynos_gpio_pinset e5_usb3_bus0_pinset = {
691 1.23 reinoud .pinset_group = "GPK3",
692 1.23 reinoud .pinset_func = 2,
693 1.23 reinoud .pinset_mask = __BIT(0) | __BIT(1) | __BIT(3),
694 1.23 reinoud };
695 1.23 reinoud static struct exynos_gpio_pinset e5_usb3_bus1_pinset = {
696 1.23 reinoud .pinset_group = "GPK2",
697 1.23 reinoud .pinset_func = 2,
698 1.23 reinoud .pinset_mask = __BIT(4) | __BIT(5) | __BIT(7),
699 1.23 reinoud };
700 1.23 reinoud #endif
701 1.23 reinoud
702 1.23 reinoud
703 1.23 reinoud void
704 1.23 reinoud exynos_usb_soc_powerup(void)
705 1.23 reinoud {
706 1.23 reinoud struct exynos_gpio_pindata XuhostOVERCUR;
707 1.23 reinoud struct exynos_gpio_pindata XuhostPWREN;
708 1.23 reinoud
709 1.23 reinoud #ifdef EXYNOS4
710 1.23 reinoud exynos_gpio_pinset_acquire(&e4_uhost_pwr_pinset);
711 1.23 reinoud exynos_gpio_pinset_to_pindata(&e4_uhost_pwr_pinset, 6, &XuhostPWREN);
712 1.23 reinoud exynos_gpio_pinset_to_pindata(&e4_uhost_pwr_pinset, 7, &XuhostOVERCUR);
713 1.23 reinoud
714 1.23 reinoud /* enable power and set Xuhost OVERCUR to inactive by pulling it up */
715 1.23 reinoud exynos_gpio_pindata_ctl(&XuhostPWREN, GPIO_PIN_PULLUP);
716 1.23 reinoud exynos_gpio_pindata_ctl(&XuhostOVERCUR, GPIO_PIN_PULLUP);
717 1.23 reinoud DELAY(80000);
718 1.23 reinoud #endif
719 1.23 reinoud #ifdef EXYNOS5
720 1.23 reinoud if (IS_EXYNOS5410_P()) {
721 1.23 reinoud struct exynos_gpio_pindata Xovercur2, Xovercur3;
722 1.23 reinoud struct exynos_gpio_pindata Xvbus;
723 1.23 reinoud
724 1.23 reinoud /* BUS 0 */
725 1.23 reinoud exynos_gpio_pinset_acquire(&e5_usb3_bus0_pinset);
726 1.23 reinoud exynos_gpio_pinset_to_pindata(&e5_usb3_bus0_pinset, 0, &Xovercur2);
727 1.23 reinoud exynos_gpio_pinset_to_pindata(&e5_usb3_bus0_pinset, 1, &Xovercur3);
728 1.23 reinoud exynos_gpio_pinset_to_pindata(&e5_usb3_bus0_pinset, 3, &Xvbus);
729 1.23 reinoud
730 1.23 reinoud /* enable power and set overcur inactive by pulling them up */
731 1.23 reinoud exynos_gpio_pindata_ctl(&Xvbus, GPIO_PIN_PULLUP);
732 1.23 reinoud exynos_gpio_pindata_ctl(&Xovercur2, GPIO_PIN_PULLUP);
733 1.23 reinoud exynos_gpio_pindata_ctl(&Xovercur3, GPIO_PIN_PULLUP);
734 1.23 reinoud
735 1.23 reinoud /* BUS 1 */
736 1.23 reinoud exynos_gpio_pinset_acquire(&e5_usb3_bus1_pinset);
737 1.23 reinoud exynos_gpio_pinset_to_pindata(&e5_usb3_bus1_pinset, 4, &Xovercur2);
738 1.23 reinoud exynos_gpio_pinset_to_pindata(&e5_usb3_bus1_pinset, 5, &Xovercur3);
739 1.23 reinoud exynos_gpio_pinset_to_pindata(&e5_usb3_bus1_pinset, 7, &Xvbus);
740 1.23 reinoud
741 1.23 reinoud /* enable power and set overcur inactive by pulling them up */
742 1.23 reinoud exynos_gpio_pindata_ctl(&Xvbus, GPIO_PIN_PULLUP);
743 1.23 reinoud exynos_gpio_pindata_ctl(&Xovercur2, GPIO_PIN_PULLUP);
744 1.23 reinoud exynos_gpio_pindata_ctl(&Xovercur3, GPIO_PIN_PULLUP);
745 1.23 reinoud
746 1.23 reinoud /* enable power to the hub */
747 1.23 reinoud exynos_gpio_pinset_acquire(&e5_uhost_pwr_pinset);
748 1.23 reinoud exynos_gpio_pinset_to_pindata(&e5_uhost_pwr_pinset, 5, &XuhostPWREN);
749 1.23 reinoud exynos_gpio_pinset_to_pindata(&e5_uhost_pwr_pinset, 6, &XuhostOVERCUR);
750 1.23 reinoud
751 1.23 reinoud /* enable power and set Xuhost OVERCUR to inactive by pulling it up */
752 1.23 reinoud exynos_gpio_pindata_ctl(&XuhostPWREN, GPIO_PIN_PULLUP);
753 1.23 reinoud exynos_gpio_pindata_ctl(&XuhostOVERCUR, GPIO_PIN_PULLUP);
754 1.23 reinoud DELAY(80000);
755 1.23 reinoud }
756 1.23 reinoud /* XXX 5422 XXX */
757 1.23 reinoud #endif
758 1.23 reinoud }
759 1.23 reinoud
760 1.23 reinoud
761 1.23 reinoud /*
762 1.23 reinoud * USB Phy SoC dependent handling
763 1.23 reinoud */
764 1.23 reinoud
765 1.23 reinoud /* XXX 5422 not handled since its unknown how it handles this XXX*/
766 1.23 reinoud static void
767 1.23 reinoud exynos_usb2_set_isolation(bool on)
768 1.23 reinoud {
769 1.23 reinoud uint32_t en_mask, regval;
770 1.23 reinoud bus_addr_t reg;
771 1.23 reinoud
772 1.23 reinoud /* enable PHY */
773 1.23 reinoud reg = EXYNOS_PMU_USB_PHY_CTRL;
774 1.23 reinoud
775 1.23 reinoud if (IS_EXYNOS5_P() || IS_EXYNOS4410_P()) {
776 1.23 reinoud /* set usbhost mode */
777 1.23 reinoud regval = on ? 0 : USB20_PHY_HOST_LINK_EN;
778 1.23 reinoud bus_space_write_4(&exynos_bs_tag, exynos_sysreg_bsh,
779 1.23 reinoud EXYNOS5_SYSREG_USB20_PHY_TYPE, regval);
780 1.23 reinoud reg = EXYNOS_PMU_USBHOST_PHY_CTRL;
781 1.23 reinoud }
782 1.23 reinoud
783 1.23 reinoud /* do enable PHY */
784 1.23 reinoud en_mask = PMU_PHY_ENABLE;
785 1.23 reinoud regval = bus_space_read_4(&exynos_bs_tag, exynos_pmu_bsh, reg);
786 1.23 reinoud regval = on ? regval & ~en_mask : regval | en_mask;
787 1.23 reinoud
788 1.23 reinoud bus_space_write_4(&exynos_bs_tag, exynos_pmu_bsh,
789 1.23 reinoud reg, regval);
790 1.23 reinoud
791 1.23 reinoud if (IS_EXYNOS4X12_P()) {
792 1.23 reinoud bus_space_write_4(&exynos_bs_tag, exynos_pmu_bsh,
793 1.23 reinoud EXYNOS_PMU_USB_HSIC_1_PHY_CTRL, regval);
794 1.23 reinoud bus_space_write_4(&exynos_bs_tag, exynos_pmu_bsh,
795 1.23 reinoud EXYNOS_PMU_USB_HSIC_2_PHY_CTRL, regval);
796 1.23 reinoud }
797 1.23 reinoud }
798 1.23 reinoud
799 1.23 reinoud
800 1.23 reinoud #ifdef EXYNOS4
801 1.23 reinoud static void
802 1.23 reinoud exynos4_usb2phy_enable(bus_space_handle_t usb2phy_bsh)
803 1.23 reinoud {
804 1.23 reinoud uint32_t phypwr, rstcon, clkreg;
805 1.23 reinoud
806 1.23 reinoud /* write clock value */
807 1.23 reinoud clkreg = FSEL_CLKSEL_24M;
808 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
809 1.23 reinoud USB_PHYCLK, clkreg);
810 1.23 reinoud
811 1.23 reinoud /* set device and host to normal */
812 1.23 reinoud phypwr = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
813 1.23 reinoud USB_PHYPWR);
814 1.23 reinoud
815 1.23 reinoud /* enable analog, enable otg, unsleep phy0 (host) */
816 1.23 reinoud phypwr &= ~PHYPWR_NORMAL_MASK_PHY0;
817 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
818 1.23 reinoud USB_PHYPWR, phypwr);
819 1.23 reinoud
820 1.23 reinoud if (IS_EXYNOS4X12_P()) {
821 1.23 reinoud /* enable hsic0 (host), enable hsic1 and phy1 (otg) */
822 1.23 reinoud phypwr = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
823 1.23 reinoud USB_PHYPWR);
824 1.23 reinoud phypwr &= ~(PHYPWR_NORMAL_MASK_HSIC0 |
825 1.23 reinoud PHYPWR_NORMAL_MASK_HSIC1 |
826 1.23 reinoud PHYPWR_NORMAL_MASK_PHY1);
827 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
828 1.23 reinoud USB_PHYPWR, phypwr);
829 1.23 reinoud }
830 1.23 reinoud
831 1.23 reinoud /* reset both phy and link of device */
832 1.23 reinoud rstcon = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
833 1.23 reinoud USB_RSTCON);
834 1.23 reinoud rstcon |= RSTCON_DEVPHY_SWRST;
835 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
836 1.23 reinoud USB_RSTCON, rstcon);
837 1.23 reinoud DELAY(10000);
838 1.23 reinoud rstcon &= ~RSTCON_DEVPHY_SWRST;
839 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
840 1.23 reinoud USB_RSTCON, rstcon);
841 1.23 reinoud
842 1.23 reinoud if (IS_EXYNOS4X12_P()) {
843 1.23 reinoud /* reset both phy and link of host */
844 1.23 reinoud rstcon = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
845 1.23 reinoud USB_RSTCON);
846 1.23 reinoud rstcon |= RSTCON_HOSTPHY_SWRST | RSTCON_HOSTPHYLINK_SWRST;
847 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
848 1.23 reinoud USB_RSTCON, rstcon);
849 1.23 reinoud DELAY(10000);
850 1.23 reinoud rstcon &= ~(RSTCON_HOSTPHY_SWRST | RSTCON_HOSTPHYLINK_SWRST);
851 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
852 1.23 reinoud USB_RSTCON, rstcon);
853 1.23 reinoud }
854 1.23 reinoud
855 1.23 reinoud /* wait for everything to be initialized */
856 1.23 reinoud DELAY(80000);
857 1.23 reinoud }
858 1.23 reinoud #endif
859 1.23 reinoud
860 1.23 reinoud
861 1.23 reinoud #ifdef EXYNOS5
862 1.23 reinoud static void
863 1.23 reinoud exynos5410_usb2phy_enable(bus_space_handle_t usb2phy_bsh)
864 1.23 reinoud {
865 1.23 reinoud uint32_t phyhost; //, phyotg;
866 1.23 reinoud uint32_t phyhsic1, phyhsic2, hsic_ctrl;
867 1.23 reinoud uint32_t ehcictrl; //, ohcictrl;
868 1.23 reinoud
869 1.23 reinoud /* host configuration: */
870 1.23 reinoud phyhost = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
871 1.23 reinoud USB_PHY_HOST_CTRL0);
872 1.23 reinoud
873 1.23 reinoud /* host phy reference clock; assumption its 24 MHz now */
874 1.23 reinoud phyhost &= ~HOST_CTRL0_FSEL_MASK;
875 1.23 reinoud phyhost |= __SHIFTIN(HOST_CTRL0_FSEL_MASK, FSEL_CLKSEL_24M);
876 1.23 reinoud
877 1.23 reinoud /* enable normal mode of operation */
878 1.23 reinoud phyhost &= ~(HOST_CTRL0_FORCESUSPEND | HOST_CTRL0_FORCESLEEP);
879 1.23 reinoud
880 1.23 reinoud /* host phy reset */
881 1.23 reinoud phyhost &= ~(HOST_CTRL0_PHY_SWRST | HOST_CTRL0_PHY_SWRST_ALL |
882 1.23 reinoud HOST_CTRL0_SIDDQ | HOST_CTRL0_COMMONON_N);
883 1.23 reinoud
884 1.23 reinoud /* host link reset */
885 1.23 reinoud phyhost |= HOST_CTRL0_LINK_SWRST | HOST_CTRL0_UTMI_SWRST;
886 1.23 reinoud
887 1.23 reinoud /* do the reset */
888 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
889 1.23 reinoud USB_PHY_HOST_CTRL0, phyhost);
890 1.23 reinoud DELAY(10000);
891 1.23 reinoud phyhost &= ~(HOST_CTRL0_LINK_SWRST | HOST_CTRL0_UTMI_SWRST);
892 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
893 1.23 reinoud USB_PHY_HOST_CTRL0, phyhost);
894 1.23 reinoud
895 1.23 reinoud #if 0
896 1.23 reinoud /* otg configuration: */
897 1.23 reinoud phyotg = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
898 1.23 reinoud USB_PHY_OTG_SYS);
899 1.23 reinoud
900 1.23 reinoud /* otg phy refrence clock: assumption its 24 Mhz now */
901 1.23 reinoud phyotg &= ~OTG_SYS_FSEL_MASK;
902 1.23 reinoud phyotg |= __SHIFTIN(OTG_SYS_FSEL_MASK, FSEL_CLKSEL_24M);
903 1.23 reinoud
904 1.23 reinoud /* enable normal mode of operation */
905 1.23 reinoud phyotg &= ~(OTG_SYS_FORCESUSPEND | OTG_SYS_FORCESLEEP |
906 1.23 reinoud OTG_SYS_SIDDQ_UOTG | OTG_SYS_REFCLKSEL_MASK |
907 1.23 reinoud OTG_SYS_COMMON_ON);
908 1.23 reinoud
909 1.23 reinoud /* OTG phy and link reset */
910 1.23 reinoud phyotg |= OTG_SYS_PHY0_SWRST | OTG_SYS_PHYLINK_SWRST |
911 1.23 reinoud OTG_SYS_OTGDISABLE | OTG_SYS_REFCLKSEL_MASK;
912 1.23 reinoud
913 1.23 reinoud /* do the reset */
914 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
915 1.23 reinoud USB_PHY_OTG_SYS, phyotg);
916 1.23 reinoud DELAY(10000);
917 1.23 reinoud phyotg &= ~(OTG_SYS_PHY0_SWRST | OTG_SYS_LINK_SWRST_UOTG |
918 1.23 reinoud OTG_SYS_PHYLINK_SWRST);
919 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
920 1.23 reinoud USB_PHY_OTG_SYS, phyotg);
921 1.23 reinoud #endif
922 1.23 reinoud
923 1.23 reinoud /* HSIC phy configuration: */
924 1.23 reinoud hsic_ctrl = HSIC_CTRL_FORCESUSPEND | HSIC_CTRL_FORCESLEEP |
925 1.23 reinoud HSIC_CTRL_SIDDQ;
926 1.23 reinoud
927 1.23 reinoud phyhsic1 = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
928 1.23 reinoud USB_PHY_HSIC_CTRL1);
929 1.23 reinoud phyhsic2 = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
930 1.23 reinoud USB_PHY_HSIC_CTRL1);
931 1.23 reinoud
932 1.23 reinoud phyhsic1 &= ~hsic_ctrl;
933 1.23 reinoud phyhsic2 &= ~hsic_ctrl;
934 1.23 reinoud
935 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
936 1.23 reinoud USB_PHY_HSIC_CTRL1, phyhsic1);
937 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
938 1.23 reinoud USB_PHY_HSIC_CTRL2, phyhsic2);
939 1.23 reinoud DELAY(10000);
940 1.23 reinoud
941 1.23 reinoud hsic_ctrl = REFCLKDIV_12 | REFCLKSEL_HSIC_DEFAULT |
942 1.23 reinoud HSIC_CTRL_UTMI_SWRST;
943 1.23 reinoud
944 1.23 reinoud phyhsic1 |= hsic_ctrl;
945 1.23 reinoud phyhsic2 |= hsic_ctrl;
946 1.23 reinoud
947 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
948 1.23 reinoud USB_PHY_HSIC_CTRL1, phyhsic1);
949 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
950 1.23 reinoud USB_PHY_HSIC_CTRL2, phyhsic2);
951 1.23 reinoud
952 1.23 reinoud DELAY(10000);
953 1.23 reinoud
954 1.23 reinoud hsic_ctrl = HSIC_CTRL_PHY_SWRST | HSIC_CTRL_UTMI_SWRST;
955 1.23 reinoud
956 1.23 reinoud phyhsic1 &= ~hsic_ctrl;
957 1.23 reinoud phyhsic2 &= ~hsic_ctrl;
958 1.23 reinoud
959 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
960 1.23 reinoud USB_PHY_HSIC_CTRL1, phyhsic1);
961 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
962 1.23 reinoud USB_PHY_HSIC_CTRL2, phyhsic2);
963 1.23 reinoud DELAY(20000);
964 1.23 reinoud
965 1.23 reinoud /* enable EHCI DMA burst: */
966 1.23 reinoud ehcictrl = bus_space_read_4(&exynos_bs_tag, usb2phy_bsh,
967 1.23 reinoud USB_PHY_HOST_EHCICTRL);
968 1.23 reinoud ehcictrl |= HOST_EHCICTRL_ENA_INCRXALIGN |
969 1.23 reinoud HOST_EHCICTRL_ENA_INCR4 | HOST_EHCICTRL_ENA_INCR8 |
970 1.23 reinoud HOST_EHCICTRL_ENA_INCR16;
971 1.23 reinoud bus_space_write_4(&exynos_bs_tag, usb2phy_bsh,
972 1.23 reinoud USB_PHY_HOST_EHCICTRL, ehcictrl);
973 1.23 reinoud DELAY(10000);
974 1.23 reinoud }
975 1.23 reinoud
976 1.23 reinoud
977 1.23 reinoud static void
978 1.23 reinoud exynos5422_usb2phy_enable(bus_space_handle_t usb2phy_bsh)
979 1.23 reinoud {
980 1.23 reinoud aprint_error("%s not implemented\n", __func__);
981 1.23 reinoud }
982 1.23 reinoud #endif
983 1.23 reinoud
984 1.23 reinoud
985 1.23 reinoud void
986 1.23 reinoud exynos_usb_phy_init(bus_space_handle_t usb2phy_bsh)
987 1.23 reinoud {
988 1.23 reinoud /* disable phy isolation */
989 1.23 reinoud exynos_usb2_set_isolation(false);
990 1.23 reinoud
991 1.23 reinoud #ifdef EXYNOS4
992 1.23 reinoud exynos4_usb2phy_enable(usb2phy_bsh);
993 1.23 reinoud #endif
994 1.23 reinoud #ifdef EXYNOS5
995 1.23 reinoud if (IS_EXYNOS5410_P()) {
996 1.23 reinoud exynos5410_usb2phy_enable(usb2phy_bsh);
997 1.23 reinoud /* TBD: USB3 phy init */
998 1.23 reinoud } else if (IS_EXYNOS5422_P()) {
999 1.23 reinoud exynos5422_usb2phy_enable(usb2phy_bsh);
1000 1.23 reinoud /* TBD: USB3 phy init */
1001 1.23 reinoud }
1002 1.23 reinoud #endif
1003 1.23 reinoud }
1004 1.23 reinoud
1005 1.23 reinoud
1006