exynos_platform.c revision 1.8 1 /* $NetBSD: exynos_platform.c,v 1.8 2017/12/19 09:04:19 skrll Exp $ */
2
3 /*-
4 * Copyright (c) 2017 Jared D. McNeill <jmcneill (at) invisible.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include "opt_exynos.h"
30 #include "opt_multiprocessor.h"
31 #include "opt_fdt_arm.h"
32
33 #include "ukbd.h"
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: exynos_platform.c,v 1.8 2017/12/19 09:04:19 skrll Exp $");
37
38 #include <sys/param.h>
39 #include <sys/bus.h>
40 #include <sys/cpu.h>
41 #include <sys/device.h>
42 #include <sys/termios.h>
43
44 #include <dev/fdt/fdtvar.h>
45
46 #include <uvm/uvm_extern.h>
47
48 #include <machine/bootconfig.h>
49 #include <arm/cpufunc.h>
50
51 #include <arm/samsung/exynos_reg.h>
52 #include <arm/samsung/exynos_var.h>
53
54 #include <evbarm/exynos/platform.h>
55
56 #include <arm/cortex/gtmr_var.h>
57
58 #include <arm/fdt/arm_fdtvar.h>
59
60 #define EXYNOS5_SWRESET_REG 0x10040400
61
62 static const struct pmap_devmap *
63 exynos_platform_devmap(void)
64 {
65 static const struct pmap_devmap devmap[] = {
66 DEVMAP_ENTRY(EXYNOS_CORE_VBASE,
67 EXYNOS_CORE_PBASE,
68 EXYNOS5_CORE_SIZE),
69 DEVMAP_ENTRY(EXYNOS5_AUDIOCORE_VBASE,
70 EXYNOS5_AUDIOCORE_PBASE,
71 EXYNOS5_AUDIOCORE_SIZE),
72 DEVMAP_ENTRY_END
73 };
74
75 return devmap;
76 }
77
78 #define EXYNOS_IOPHYSTOVIRT(a) \
79 ((vaddr_t)(((a) - EXYNOS_CORE_PBASE) + EXYNOS_CORE_VBASE))
80
81 static void
82 exynos_platform_bootstrap(void)
83 {
84 paddr_t uart_address = armreg_tpidruro_read(); /* XXX */
85 exynos_bootstrap(EXYNOS_CORE_VBASE, EXYNOS_IOPHYSTOVIRT(uart_address));
86 }
87
88 static void
89 exynos_platform_init_attach_args(struct fdt_attach_args *faa)
90 {
91 extern struct bus_space armv7_generic_bs_tag;
92 extern struct bus_space armv7_generic_a4x_bs_tag;
93 extern struct arm32_bus_dma_tag armv7_generic_dma_tag;
94
95 faa->faa_bst = &armv7_generic_bs_tag;
96 faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag;
97 faa->faa_dmat = &armv7_generic_dma_tag;
98 }
99
100 static void
101 exynos_platform_early_putchar(char c)
102 {
103 #if defined(VERBOSE_INIT_ARM)
104 extern void exynos_putchar(int); /* XXX from exynos_start.S */
105
106 exynos_putchar(c);
107 #endif
108 }
109
110 static void
111 exynos_platform_device_register(device_t self, void *aux)
112 {
113 exynos_device_register(self, aux);
114 }
115
116 static void
117 exynos5_platform_reset(void)
118 {
119 bus_space_tag_t bst = &armv7_generic_bs_tag;
120 bus_space_handle_t bsh;
121
122 bus_space_map(bst, EXYNOS5_SWRESET_REG, 4, 0, &bsh);
123 bus_space_write_4(bst, bsh, 0, 1);
124 }
125
126 static void
127 exynos_platform_delay(u_int us)
128 {
129 gtmr_delay(us);
130 }
131
132 static u_int
133 exynos_platform_uart_freq(void)
134 {
135 return EXYNOS_UART_FREQ;
136 }
137
138 static const struct arm_platform exynos5_platform = {
139 .devmap = exynos_platform_devmap,
140 .bootstrap = exynos_platform_bootstrap,
141 .init_attach_args = exynos_platform_init_attach_args,
142 .early_putchar = exynos_platform_early_putchar,
143 .device_register = exynos_platform_device_register,
144 .reset = exynos5_platform_reset,
145 .delay = exynos_platform_delay,
146 .uart_freq = exynos_platform_uart_freq,
147 };
148
149 ARM_PLATFORM(exynos5, "samsung,exynos5", &exynos5_platform);
150