1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2019 Michal Meloun <mmel@FreeBSD.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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. 14 * 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 25 * SUCH DAMAGE. 26 */ 27 28 #include "opt_platform.h" 29 30 #include <sys/cdefs.h> 31 __FBSDID("$FreeBSD$"); 32 33 #include <sys/param.h> 34 #include <sys/systm.h> 35 #include <sys/bus.h> 36 #include <sys/devmap.h> 37 #include <sys/lock.h> 38 #include <sys/reboot.h> 39 40 #include <vm/vm.h> 41 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> 47 48 #include <dev/ofw/openfirm.h> 49 50 #include <arm/rockchip/rk32xx_mp.h> 51 52 #include "platform_if.h" 53 #define CRU_PHYSBASE 0xFF760000 54 #define CRU_SIZE 0x00010000 55 #define CRU_GLB_SRST_FST_VALUE 0x1B0 56 57 static platform_def_t rk3288w_platform; 58 59 static void 60 rk32xx_late_init(platform_t plat) 61 { 62 63 } 64 65 /* 66 * Set up static device mappings. 67 */ 68 static int 69 rk32xx_devmap_init(platform_t plat) 70 { 71 72 devmap_add_entry(0xFF000000, 0x00E00000); 73 return (0); 74 } 75 76 static void 77 rk32xx_cpu_reset(platform_t plat) 78 { 79 bus_space_handle_t cru; 80 81 printf("Resetting...\n"); 82 bus_space_map(fdtbus_bs_tag, CRU_PHYSBASE, CRU_SIZE, 0, &cru); 83 84 spinlock_enter(); 85 dsb(); 86 /* Generate 'first global software reset' */ 87 bus_space_write_4(fdtbus_bs_tag, cru, CRU_GLB_SRST_FST_VALUE, 0xfdb9); 88 while(1) 89 ; 90 } 91 92 /* 93 * Early putc routine for EARLY_PRINTF support. To use, add to kernel config: 94 * option SOCDEV_PA=0xFF600000 95 * option SOCDEV_VA=0x70000000 96 * option EARLY_PRINTF 97 */ 98 #if 0 99 #ifdef EARLY_PRINTF 100 static void 101 rk32xx_early_putc(int c) 102 { 103 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) 108 continue; 109 *UART_TX_REG = c; 110 } 111 early_putc_t *early_putc = rk32xx_early_putc; 112 #endif 113 #endif 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), 118 119 #ifdef SMP 120 PLATFORMMETHOD(platform_mp_start_ap, rk32xx_mp_start_ap), 121 PLATFORMMETHOD(platform_mp_setmaxid, rk32xx_mp_setmaxid), 122 #endif 123 PLATFORMMETHOD_END, 124 }; 125 FDT_PLATFORM_DEF2(rk32xx, rk3288, "RK3288", 0, "rockchip,rk3288", 200); 126 FDT_PLATFORM_DEF2(rk32xx, rk3288w, "RK3288W", 0, "rockchip,rk3288w", 200); 127