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