/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2019 Michal Meloun <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include "opt_platform.h"2829#include <sys/param.h>30#include <sys/systm.h>31#include <sys/bus.h>32#include <sys/devmap.h>33#include <sys/lock.h>34#include <sys/reboot.h>3536#include <vm/vm.h>3738#include <machine/bus.h>39#include <machine/fdt.h>40#include <machine/intr.h>41#include <machine/machdep.h>42#include <machine/platformvar.h>4344#include <dev/ofw/openfirm.h>4546#include <arm/rockchip/rk32xx_mp.h>4748#include "platform_if.h"49#define CRU_PHYSBASE 0xFF76000050#define CRU_SIZE 0x0001000051#define CRU_GLB_SRST_FST_VALUE 0x1B05253static platform_def_t rk3288w_platform;5455static void56rk32xx_late_init(platform_t plat)57{5859}6061/*62* Set up static device mappings.63*/64static int65rk32xx_devmap_init(platform_t plat)66{6768devmap_add_entry(0xFF000000, 0x00E00000);69return (0);70}7172static void73rk32xx_cpu_reset(platform_t plat)74{75bus_space_handle_t cru;7677printf("Resetting...\n");78bus_space_map(fdtbus_bs_tag, CRU_PHYSBASE, CRU_SIZE, 0, &cru);7980spinlock_enter();81dsb();82/* Generate 'first global software reset' */83bus_space_write_4(fdtbus_bs_tag, cru, CRU_GLB_SRST_FST_VALUE, 0xfdb9);84while(1)85;86}8788/*89* Early putc routine for EARLY_PRINTF support. To use, add to kernel config:90* option SOCDEV_PA=0xFF60000091* option SOCDEV_VA=0x7000000092* option EARLY_PRINTF93*/94#if 095#ifdef EARLY_PRINTF96static void97rk32xx_early_putc(int c)98{99100volatile uint32_t * UART_STAT_REG = (uint32_t *)(0x7009007C);101volatile uint32_t * UART_TX_REG = (uint32_t *)(0x70090000);102const uint32_t UART_TXRDY = (1 << 2);103while ((*UART_STAT_REG & UART_TXRDY) == 0)104continue;105*UART_TX_REG = c;106}107early_putc_t *early_putc = rk32xx_early_putc;108#endif109#endif110static platform_method_t rk32xx_methods[] = {111PLATFORMMETHOD(platform_devmap_init, rk32xx_devmap_init),112PLATFORMMETHOD(platform_late_init, rk32xx_late_init),113PLATFORMMETHOD(platform_cpu_reset, rk32xx_cpu_reset),114115#ifdef SMP116PLATFORMMETHOD(platform_mp_start_ap, rk32xx_mp_start_ap),117PLATFORMMETHOD(platform_mp_setmaxid, rk32xx_mp_setmaxid),118#endif119PLATFORMMETHOD_END,120};121FDT_PLATFORM_DEF2(rk32xx, rk3288, "RK3288", 0, "rockchip,rk3288", 200);122FDT_PLATFORM_DEF2(rk32xx, rk3288w, "RK3288W", 0, "rockchip,rk3288w", 200);123124125