2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2019 Michal Meloun <mmel@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/devmap.h>
38 #include <sys/reboot.h>
42 #include <machine/bus.h>
43 #include <machine/fdt.h>
44 #include <machine/intr.h>
45 #include <machine/machdep.h>
46 #include <machine/platformvar.h>
48 #include <dev/ofw/openfirm.h>
50 #include <arm/rockchip/rk32xx_mp.h>
52 #include "platform_if.h"
53 #define CRU_PHYSBASE 0xFF760000
54 #define CRU_SIZE 0x00010000
55 #define CRU_GLB_SRST_FST_VALUE 0x1B0
57 static platform_def_t rk3288w_platform;
60 rk32xx_late_init(platform_t plat)
66 * Set up static device mappings.
69 rk32xx_devmap_init(platform_t plat)
72 devmap_add_entry(0xFF000000, 0x00E00000);
77 rk32xx_cpu_reset(platform_t plat)
79 bus_space_handle_t cru;
81 printf("Resetting...\n");
82 bus_space_map(fdtbus_bs_tag, CRU_PHYSBASE, CRU_SIZE, 0, &cru);
86 /* Generate 'first global software reset' */
87 bus_space_write_4(fdtbus_bs_tag, cru, CRU_GLB_SRST_FST_VALUE, 0xfdb9);
93 * Early putc routine for EARLY_PRINTF support. To use, add to kernel config:
94 * option SOCDEV_PA=0xFF600000
95 * option SOCDEV_VA=0x70000000
101 rk32xx_early_putc(int c)
104 volatile uint32_t * UART_STAT_REG = (uint32_t *)(0x7009007C);
105 volatile uint32_t * UART_TX_REG = (uint32_t *)(0x70090000);
106 const uint32_t UART_TXRDY = (1 << 2);
107 while ((*UART_STAT_REG & UART_TXRDY) == 0)
111 early_putc_t *early_putc = rk32xx_early_putc;
114 static platform_method_t rk32xx_methods[] = {
115 PLATFORMMETHOD(platform_devmap_init, rk32xx_devmap_init),
116 PLATFORMMETHOD(platform_late_init, rk32xx_late_init),
117 PLATFORMMETHOD(platform_cpu_reset, rk32xx_cpu_reset),
120 PLATFORMMETHOD(platform_mp_start_ap, rk32xx_mp_start_ap),
121 PLATFORMMETHOD(platform_mp_setmaxid, rk32xx_mp_setmaxid),
125 FDT_PLATFORM_DEF2(rk32xx, rk3288, "RK3288", 0, "rockchip,rk3288", 200);
126 FDT_PLATFORM_DEF2(rk32xx, rk3288w, "RK3288W", 0, "rockchip,rk3288w", 200);