tegra_platform.c revision 1.8.2.2 1 1.8.2.2 jdolecek /* $NetBSD: tegra_platform.c,v 1.8.2.2 2017/12/03 11:35:54 jdolecek Exp $ */
2 1.8.2.2 jdolecek
3 1.8.2.2 jdolecek /*-
4 1.8.2.2 jdolecek * Copyright (c) 2017 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.8.2.2 jdolecek * All rights reserved.
6 1.8.2.2 jdolecek *
7 1.8.2.2 jdolecek * Redistribution and use in source and binary forms, with or without
8 1.8.2.2 jdolecek * modification, are permitted provided that the following conditions
9 1.8.2.2 jdolecek * are met:
10 1.8.2.2 jdolecek * 1. Redistributions of source code must retain the above copyright
11 1.8.2.2 jdolecek * notice, this list of conditions and the following disclaimer.
12 1.8.2.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
13 1.8.2.2 jdolecek * notice, this list of conditions and the following disclaimer in the
14 1.8.2.2 jdolecek * documentation and/or other materials provided with the distribution.
15 1.8.2.2 jdolecek *
16 1.8.2.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.8.2.2 jdolecek * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.8.2.2 jdolecek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.8.2.2 jdolecek * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.8.2.2 jdolecek * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.8.2.2 jdolecek * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.8.2.2 jdolecek * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.8.2.2 jdolecek * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.8.2.2 jdolecek * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.8.2.2 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.8.2.2 jdolecek * SUCH DAMAGE.
27 1.8.2.2 jdolecek */
28 1.8.2.2 jdolecek
29 1.8.2.2 jdolecek #include "opt_tegra.h"
30 1.8.2.2 jdolecek #include "opt_multiprocessor.h"
31 1.8.2.2 jdolecek #include "opt_fdt_arm.h"
32 1.8.2.2 jdolecek
33 1.8.2.2 jdolecek #include "ukbd.h"
34 1.8.2.2 jdolecek
35 1.8.2.2 jdolecek #include <sys/cdefs.h>
36 1.8.2.2 jdolecek __KERNEL_RCSID(0, "$NetBSD: tegra_platform.c,v 1.8.2.2 2017/12/03 11:35:54 jdolecek Exp $");
37 1.8.2.2 jdolecek
38 1.8.2.2 jdolecek #include <sys/param.h>
39 1.8.2.2 jdolecek #include <sys/bus.h>
40 1.8.2.2 jdolecek #include <sys/cpu.h>
41 1.8.2.2 jdolecek #include <sys/device.h>
42 1.8.2.2 jdolecek #include <sys/termios.h>
43 1.8.2.2 jdolecek
44 1.8.2.2 jdolecek #include <dev/fdt/fdtvar.h>
45 1.8.2.2 jdolecek
46 1.8.2.2 jdolecek #include <uvm/uvm_extern.h>
47 1.8.2.2 jdolecek
48 1.8.2.2 jdolecek #include <machine/bootconfig.h>
49 1.8.2.2 jdolecek #include <arm/cpufunc.h>
50 1.8.2.2 jdolecek
51 1.8.2.2 jdolecek #include <arm/nvidia/tegra_reg.h>
52 1.8.2.2 jdolecek #include <arm/nvidia/tegra_var.h>
53 1.8.2.2 jdolecek
54 1.8.2.2 jdolecek #include <arm/fdt/arm_fdtvar.h>
55 1.8.2.2 jdolecek
56 1.8.2.2 jdolecek #if NUKBD > 0
57 1.8.2.2 jdolecek #include <dev/usb/ukbdvar.h>
58 1.8.2.2 jdolecek #endif
59 1.8.2.2 jdolecek
60 1.8.2.2 jdolecek #include <dev/ic/ns16550reg.h>
61 1.8.2.2 jdolecek #include <dev/ic/comreg.h>
62 1.8.2.2 jdolecek
63 1.8.2.2 jdolecek #define PLLP_OUT0_FREQ 408000000
64 1.8.2.2 jdolecek
65 1.8.2.2 jdolecek static const struct pmap_devmap *
66 1.8.2.2 jdolecek tegra_platform_devmap(void)
67 1.8.2.2 jdolecek {
68 1.8.2.2 jdolecek static const struct pmap_devmap devmap[] = {
69 1.8.2.2 jdolecek DEVMAP_ENTRY(TEGRA_HOST1X_VBASE,
70 1.8.2.2 jdolecek TEGRA_HOST1X_BASE,
71 1.8.2.2 jdolecek TEGRA_HOST1X_SIZE),
72 1.8.2.2 jdolecek DEVMAP_ENTRY(TEGRA_PPSB_VBASE,
73 1.8.2.2 jdolecek TEGRA_PPSB_BASE,
74 1.8.2.2 jdolecek TEGRA_PPSB_SIZE),
75 1.8.2.2 jdolecek DEVMAP_ENTRY(TEGRA_APB_VBASE,
76 1.8.2.2 jdolecek TEGRA_APB_BASE,
77 1.8.2.2 jdolecek TEGRA_APB_SIZE),
78 1.8.2.2 jdolecek DEVMAP_ENTRY(TEGRA_AHB_A2_VBASE,
79 1.8.2.2 jdolecek TEGRA_AHB_A2_BASE,
80 1.8.2.2 jdolecek TEGRA_AHB_A2_SIZE),
81 1.8.2.2 jdolecek DEVMAP_ENTRY_END
82 1.8.2.2 jdolecek };
83 1.8.2.2 jdolecek
84 1.8.2.2 jdolecek return devmap;
85 1.8.2.2 jdolecek }
86 1.8.2.2 jdolecek
87 1.8.2.2 jdolecek static void
88 1.8.2.2 jdolecek tegra124_platform_bootstrap(void)
89 1.8.2.2 jdolecek {
90 1.8.2.2 jdolecek tegra_bootstrap();
91 1.8.2.2 jdolecek
92 1.8.2.2 jdolecek tegra124_mpinit();
93 1.8.2.2 jdolecek }
94 1.8.2.2 jdolecek
95 1.8.2.2 jdolecek static void
96 1.8.2.2 jdolecek tegra210_platform_bootstrap(void)
97 1.8.2.2 jdolecek {
98 1.8.2.2 jdolecek tegra_bootstrap();
99 1.8.2.2 jdolecek
100 1.8.2.2 jdolecek tegra210_mpinit();
101 1.8.2.2 jdolecek }
102 1.8.2.2 jdolecek
103 1.8.2.2 jdolecek static void
104 1.8.2.2 jdolecek tegra_platform_init_attach_args(struct fdt_attach_args *faa)
105 1.8.2.2 jdolecek {
106 1.8.2.2 jdolecek extern struct bus_space armv7_generic_bs_tag;
107 1.8.2.2 jdolecek extern struct bus_space armv7_generic_a4x_bs_tag;
108 1.8.2.2 jdolecek extern struct arm32_bus_dma_tag armv7_generic_dma_tag;
109 1.8.2.2 jdolecek
110 1.8.2.2 jdolecek faa->faa_bst = &armv7_generic_bs_tag;
111 1.8.2.2 jdolecek faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag;
112 1.8.2.2 jdolecek faa->faa_dmat = &armv7_generic_dma_tag;
113 1.8.2.2 jdolecek }
114 1.8.2.2 jdolecek
115 1.8.2.2 jdolecek static void
116 1.8.2.2 jdolecek tegra_platform_early_putchar(char c)
117 1.8.2.2 jdolecek {
118 1.8.2.2 jdolecek #ifdef CONSADDR
119 1.8.2.2 jdolecek #define CONSADDR_VA (CONSADDR - TEGRA_APB_BASE + TEGRA_APB_VBASE)
120 1.8.2.2 jdolecek volatile uint32_t *uartaddr = (volatile uint32_t *)CONSADDR_VA;
121 1.8.2.2 jdolecek
122 1.8.2.2 jdolecek while ((uartaddr[com_lsr] & LSR_TXRDY) == 0)
123 1.8.2.2 jdolecek ;
124 1.8.2.2 jdolecek
125 1.8.2.2 jdolecek uartaddr[com_data] = c;
126 1.8.2.2 jdolecek #endif
127 1.8.2.2 jdolecek }
128 1.8.2.2 jdolecek
129 1.8.2.2 jdolecek static void
130 1.8.2.2 jdolecek tegra_platform_device_register(device_t self, void *aux)
131 1.8.2.2 jdolecek {
132 1.8.2.2 jdolecek prop_dictionary_t dict = device_properties(self);
133 1.8.2.2 jdolecek
134 1.8.2.2 jdolecek if (device_is_a(self, "tegrafb") &&
135 1.8.2.2 jdolecek match_bootconf_option(boot_args, "console", "fb")) {
136 1.8.2.2 jdolecek prop_dictionary_set_bool(dict, "is_console", true);
137 1.8.2.2 jdolecek #if NUKBD > 0
138 1.8.2.2 jdolecek ukbd_cnattach();
139 1.8.2.2 jdolecek #endif
140 1.8.2.2 jdolecek }
141 1.8.2.2 jdolecek
142 1.8.2.2 jdolecek if (device_is_a(self, "tegradrm")) {
143 1.8.2.2 jdolecek const char *video = get_bootconf_string(boot_args, "video");
144 1.8.2.2 jdolecek if (video)
145 1.8.2.2 jdolecek prop_dictionary_set_cstring(dict, "HDMI-A-1", video);
146 1.8.2.2 jdolecek if (match_bootconf_option(boot_args, "hdmi.forcemode", "dvi"))
147 1.8.2.2 jdolecek prop_dictionary_set_bool(dict, "force-dvi", true);
148 1.8.2.2 jdolecek }
149 1.8.2.2 jdolecek
150 1.8.2.2 jdolecek if (device_is_a(self, "tegracec"))
151 1.8.2.2 jdolecek prop_dictionary_set_cstring(dict, "hdmi-device", "tegradrm0");
152 1.8.2.2 jdolecek
153 1.8.2.2 jdolecek if (device_is_a(self, "nouveau")) {
154 1.8.2.2 jdolecek const char *config = get_bootconf_string(boot_args,
155 1.8.2.2 jdolecek "nouveau.config");
156 1.8.2.2 jdolecek if (config)
157 1.8.2.2 jdolecek prop_dictionary_set_cstring(dict, "config", config);
158 1.8.2.2 jdolecek const char *debug = get_bootconf_string(boot_args,
159 1.8.2.2 jdolecek "nouveau.debug");
160 1.8.2.2 jdolecek if (debug)
161 1.8.2.2 jdolecek prop_dictionary_set_cstring(dict, "debug", debug);
162 1.8.2.2 jdolecek }
163 1.8.2.2 jdolecek
164 1.8.2.2 jdolecek if (device_is_a(self, "tegrapcie")) {
165 1.8.2.2 jdolecek const char * const jetsontk1_compat[] = {
166 1.8.2.2 jdolecek "nvidia,jetson-tk1", NULL
167 1.8.2.2 jdolecek };
168 1.8.2.2 jdolecek const int phandle = OF_peer(0);
169 1.8.2.2 jdolecek if (of_match_compatible(phandle, jetsontk1_compat)) {
170 1.8.2.2 jdolecek /* rfkill GPIO at GPIO X7 */
171 1.8.2.2 jdolecek struct tegra_gpio_pin *pin =
172 1.8.2.2 jdolecek tegra_gpio_acquire("X7", GPIO_PIN_OUTPUT);
173 1.8.2.2 jdolecek if (pin)
174 1.8.2.2 jdolecek tegra_gpio_write(pin, 1);
175 1.8.2.2 jdolecek }
176 1.8.2.2 jdolecek }
177 1.8.2.2 jdolecek }
178 1.8.2.2 jdolecek
179 1.8.2.2 jdolecek static void
180 1.8.2.2 jdolecek tegra_platform_reset(void)
181 1.8.2.2 jdolecek {
182 1.8.2.2 jdolecek tegra_pmc_reset();
183 1.8.2.2 jdolecek }
184 1.8.2.2 jdolecek
185 1.8.2.2 jdolecek static void
186 1.8.2.2 jdolecek tegra_platform_delay(u_int us)
187 1.8.2.2 jdolecek {
188 1.8.2.2 jdolecek tegra_timer_delay(us);
189 1.8.2.2 jdolecek }
190 1.8.2.2 jdolecek
191 1.8.2.2 jdolecek static u_int
192 1.8.2.2 jdolecek tegra_platform_uart_freq(void)
193 1.8.2.2 jdolecek {
194 1.8.2.2 jdolecek return PLLP_OUT0_FREQ;
195 1.8.2.2 jdolecek }
196 1.8.2.2 jdolecek
197 1.8.2.2 jdolecek static const struct arm_platform tegra124_platform = {
198 1.8.2.2 jdolecek .devmap = tegra_platform_devmap,
199 1.8.2.2 jdolecek .bootstrap = tegra124_platform_bootstrap,
200 1.8.2.2 jdolecek .init_attach_args = tegra_platform_init_attach_args,
201 1.8.2.2 jdolecek .early_putchar = tegra_platform_early_putchar,
202 1.8.2.2 jdolecek .device_register = tegra_platform_device_register,
203 1.8.2.2 jdolecek .reset = tegra_platform_reset,
204 1.8.2.2 jdolecek .delay = tegra_platform_delay,
205 1.8.2.2 jdolecek .uart_freq = tegra_platform_uart_freq,
206 1.8.2.2 jdolecek };
207 1.8.2.2 jdolecek
208 1.8.2.2 jdolecek ARM_PLATFORM(tegra124, "nvidia,tegra124", &tegra124_platform);
209 1.8.2.2 jdolecek
210 1.8.2.2 jdolecek static const struct arm_platform tegra210_platform = {
211 1.8.2.2 jdolecek .devmap = tegra_platform_devmap,
212 1.8.2.2 jdolecek .bootstrap = tegra210_platform_bootstrap,
213 1.8.2.2 jdolecek .init_attach_args = tegra_platform_init_attach_args,
214 1.8.2.2 jdolecek .early_putchar = tegra_platform_early_putchar,
215 1.8.2.2 jdolecek .device_register = tegra_platform_device_register,
216 1.8.2.2 jdolecek .reset = tegra_platform_reset,
217 1.8.2.2 jdolecek .delay = tegra_platform_delay,
218 1.8.2.2 jdolecek .uart_freq = tegra_platform_uart_freq,
219 1.8.2.2 jdolecek };
220 1.8.2.2 jdolecek
221 1.8.2.2 jdolecek ARM_PLATFORM(tegra210, "nvidia,tegra210", &tegra210_platform);
222