2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2021 Adrian Chadd <adrian@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include "opt_platform.h"
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/reboot.h>
37 #include <sys/devmap.h>
38 #include <sys/physmem.h>
43 #include <machine/bus.h>
44 #include <machine/fdt.h>
45 #include <machine/intr.h>
46 #include <machine/machdep.h>
47 #include <machine/platformvar.h>
49 #include <dev/fdt/fdt_common.h>
50 #include <dev/ofw/openfirm.h>
52 #include <arm/qualcomm/ipq4018_machdep.h>
53 #include <arm/qualcomm/ipq4018_reg.h>
55 #include "platform_if.h"
58 ipq4018_attach(platform_t plat)
64 ipq4018_late_init(platform_t plat)
67 * XXX FIXME This is needed because we're not parsing
68 * the fdt reserved memory regions in a consistent way
69 * between arm/arm64. Once the reserved region parsing
70 * is fixed up this will become unneccessary.
72 * These cover the SRAM/TZ regions that are not fully
73 * accessible from the OS. They're in the ipq4018.dtsi
76 * Without these, the system fails to boot because we
77 * aren't parsing the regions correctly.
79 * These will be unnecessary once the parser and setup
82 physmem_exclude_region(IPQ4018_MEM_SMEM_START,
83 IPQ4018_MEM_SMEM_SIZE,
84 EXFLAG_NODUMP | EXFLAG_NOALLOC);
85 physmem_exclude_region(IPQ4018_MEM_TZ_START,
87 EXFLAG_NODUMP | EXFLAG_NOALLOC);
91 ipq4018_devmap_init(platform_t plat)
94 * This covers the boot UART. Without it we can't boot successfully:
95 * there's a mutex uninit panic in subr_vmem.c that occurs when doing
96 * a call to pmap_mapdev() when the bus space code is doing its thing.
98 devmap_add_entry(IPQ4018_MEM_UART1_START, IPQ4018_MEM_UART1_SIZE);
101 * This covers a bunch of the reset block, which includes the PS-HOLD
102 * register for dropping power.
104 devmap_add_entry(IPQ4018_MEM_PSHOLD_START, IPQ4018_MEM_PSHOLD_SIZE);
110 * This toggles the PS-HOLD register which on most IPQ devices will toggle
111 * the power control block and reset the SoC.
113 * However, there are apparently some units out there where this is not
114 * appropriate and instead the watchdog needs to be used.
116 * For now since there's only going to be one or two initial supported boards
117 * this will be fine. But if this doesn't reboot cleanly, now you know.
120 ipq4018_cpu_reset_pshold(void)
122 bus_space_handle_t pshold;
124 printf("%s: called\n", __func__);
126 bus_space_map(fdtbus_bs_tag, IPQ4018_MEM_PSHOLD_START,
127 IPQ4018_MEM_PSHOLD_SIZE, 0, &pshold);
128 bus_space_write_4(fdtbus_bs_tag, pshold, 0, 0);
129 bus_space_barrier(fdtbus_bs_tag, pshold, 0, 0x4,
130 BUS_SPACE_BARRIER_WRITE);
134 ipq4018_cpu_reset(platform_t plat)
139 ipq4018_cpu_reset_pshold();
142 printf("%s: spinning\n", __func__);
148 * Early putc routine for EARLY_PRINTF support. To use, add to kernel config:
149 * option SOCDEV_PA=0x07800000
150 * option SOCDEV_VA=0x07800000
151 * option EARLY_PRINTF
152 * Resist the temptation to change the #if 0 to #ifdef EARLY_PRINTF here. It
153 * makes sense now, but if multiple SOCs do that it will make early_putc another
154 * duplicate symbol to be eliminated on the path to a generic kernel.
158 qca_msm_early_putc(int c)
160 static int is_init = 0;
164 * This must match what's put into SOCDEV_VA. You have to change them
167 * XXX TODO I should really go and just make UART_BASE here depend upon
168 * SOCDEV_VA so they move together.
170 #define UART_BASE IPQ4018_MEM_UART1_START
171 volatile uint32_t * UART_DM_TF0 = (uint32_t *)(UART_BASE + 0x70);
172 volatile uint32_t * UART_DM_SR = (uint32_t *)(UART_BASE + 0x08);
173 #define UART_DM_SR_TXEMT (1 << 3)
174 #define UART_DM_SR_TXRDY (1 << 2)
175 volatile uint32_t * UART_DM_ISR = (uint32_t *)(UART_BASE + 0x14);
176 volatile uint32_t * UART_DM_CR = (uint32_t *)(UART_BASE + 0x10);
177 #define UART_DM_TX_READY (1 << 7)
178 #define UART_DM_CLEAR_TX_READY 0x300
179 volatile uint32_t * UART_DM_NO_CHARS_FOR_TX = (uint32_t *)(UART_BASE + 0x40);
180 volatile uint32_t * UART_DM_TFWR = (uint32_t *)(UART_BASE + 0x1c);
181 #define UART_DM_TFW_VALUE 0
182 volatile uint32_t * UART_DM_IPR = (uint32_t *)(UART_BASE + 0x18);
183 #define UART_DM_STALE_TIMEOUT_LSB 0xf
187 *UART_DM_TFWR = UART_DM_TFW_VALUE;
189 *UART_DM_IPR = UART_DM_STALE_TIMEOUT_LSB;
193 /* Wait until TXFIFO is empty via ISR */
195 if ((*UART_DM_SR & UART_DM_SR_TXEMT) == 0) {
196 while (((*UART_DM_ISR & UART_DM_TX_READY) == 0) && --limit) {
197 /* Note - can't use DELAY here yet, too early */
200 *UART_DM_CR = UART_DM_CLEAR_TX_READY;
204 /* FIFO is ready. Say we're going to write one byte */
205 *UART_DM_NO_CHARS_FOR_TX = 1;
209 while (((*UART_DM_SR & UART_DM_SR_TXRDY) == 0) && --limit) {
210 /* Note - can't use DELAY here yet, too early */
214 /* Put character in first fifo slot */
218 early_putc_t *early_putc = qca_msm_early_putc;
221 static platform_method_t ipq4018_methods[] = {
222 PLATFORMMETHOD(platform_attach, ipq4018_attach),
223 PLATFORMMETHOD(platform_devmap_init, ipq4018_devmap_init),
224 PLATFORMMETHOD(platform_late_init, ipq4018_late_init),
225 PLATFORMMETHOD(platform_cpu_reset, ipq4018_cpu_reset),
228 PLATFORMMETHOD(platform_mp_start_ap, ipq4018_mp_start_ap),
229 PLATFORMMETHOD(platform_mp_setmaxid, ipq4018_mp_setmaxid),
235 FDT_PLATFORM_DEF2(ipq4018, ipq4018_ac58u, "ASUS RT-AC58U", 0,
236 "asus,rt-ac58u", 80);