xref: /freebsd/sys/arm/rockchip/rk32xx_machdep.c (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/devmap.h>
35 #include <sys/lock.h>
36 #include <sys/reboot.h>
37 
38 #include <vm/vm.h>
39 
40 #include <machine/bus.h>
41 #include <machine/fdt.h>
42 #include <machine/intr.h>
43 #include <machine/machdep.h>
44 #include <machine/platformvar.h>
45 
46 #include <dev/ofw/openfirm.h>
47 
48 #include <arm/rockchip/rk32xx_mp.h>
49 
50 #include "platform_if.h"
51 #define CRU_PHYSBASE		0xFF760000
52 #define CRU_SIZE		0x00010000
53 #define	 CRU_GLB_SRST_FST_VALUE	 0x1B0
54 
55 static platform_def_t rk3288w_platform;
56 
57 static void
58 rk32xx_late_init(platform_t plat)
59 {
60 
61 }
62 
63 /*
64  * Set up static device mappings.
65  */
66 static int
67 rk32xx_devmap_init(platform_t plat)
68 {
69 
70 	devmap_add_entry(0xFF000000, 0x00E00000);
71 	return (0);
72 }
73 
74 static void
75 rk32xx_cpu_reset(platform_t plat)
76 {
77 	bus_space_handle_t cru;
78 
79 	printf("Resetting...\n");
80 	bus_space_map(fdtbus_bs_tag, CRU_PHYSBASE, CRU_SIZE, 0, &cru);
81 
82 	spinlock_enter();
83 	dsb();
84 	/* Generate 'first global software reset' */
85 	bus_space_write_4(fdtbus_bs_tag, cru, CRU_GLB_SRST_FST_VALUE, 0xfdb9);
86 	while(1)
87 		;
88 }
89 
90 /*
91  * Early putc routine for EARLY_PRINTF support.  To use, add to kernel config:
92  *   option SOCDEV_PA=0xFF600000
93  *   option SOCDEV_VA=0x70000000
94  *   option EARLY_PRINTF
95  */
96 #if 0
97 #ifdef EARLY_PRINTF
98 static void
99 rk32xx_early_putc(int c)
100 {
101 
102 	volatile uint32_t * UART_STAT_REG = (uint32_t *)(0x7009007C);
103 	volatile uint32_t * UART_TX_REG   = (uint32_t *)(0x70090000);
104 	const uint32_t      UART_TXRDY    = (1 << 2);
105 	while ((*UART_STAT_REG & UART_TXRDY) == 0)
106 		continue;
107 	*UART_TX_REG = c;
108 }
109 early_putc_t *early_putc = rk32xx_early_putc;
110 #endif
111 #endif
112 static platform_method_t rk32xx_methods[] = {
113 	PLATFORMMETHOD(platform_devmap_init,	rk32xx_devmap_init),
114 	PLATFORMMETHOD(platform_late_init,	rk32xx_late_init),
115 	PLATFORMMETHOD(platform_cpu_reset,	rk32xx_cpu_reset),
116 
117 #ifdef SMP
118 	PLATFORMMETHOD(platform_mp_start_ap,	rk32xx_mp_start_ap),
119 	PLATFORMMETHOD(platform_mp_setmaxid,	rk32xx_mp_setmaxid),
120 #endif
121 	PLATFORMMETHOD_END,
122 };
123 FDT_PLATFORM_DEF2(rk32xx, rk3288,  "RK3288",  0, "rockchip,rk3288",  200);
124 FDT_PLATFORM_DEF2(rk32xx, rk3288w, "RK3288W", 0, "rockchip,rk3288w", 200);
125