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