Home | History | Annotate | Line # | Download | only in sunxi
sunxi_platform.c revision 1.47
      1  1.47     skrll /* $NetBSD: sunxi_platform.c,v 1.47 2023/04/07 08:55:30 skrll Exp $ */
      2   1.1  jmcneill 
      3   1.1  jmcneill /*-
      4   1.1  jmcneill  * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
      5   1.1  jmcneill  * All rights reserved.
      6   1.1  jmcneill  *
      7   1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8   1.1  jmcneill  * modification, are permitted provided that the following conditions
      9   1.1  jmcneill  * are met:
     10   1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12   1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15   1.1  jmcneill  *
     16   1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18   1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19   1.1  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20   1.1  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21   1.1  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22   1.1  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23   1.1  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24   1.1  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25   1.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26   1.1  jmcneill  * SUCH DAMAGE.
     27   1.1  jmcneill  */
     28   1.1  jmcneill 
     29   1.1  jmcneill #include "opt_soc.h"
     30   1.1  jmcneill #include "opt_multiprocessor.h"
     31  1.28     skrll #include "opt_console.h"
     32   1.1  jmcneill 
     33   1.1  jmcneill #include <sys/cdefs.h>
     34  1.47     skrll __KERNEL_RCSID(0, "$NetBSD: sunxi_platform.c,v 1.47 2023/04/07 08:55:30 skrll Exp $");
     35   1.1  jmcneill 
     36   1.1  jmcneill #include <sys/param.h>
     37   1.1  jmcneill #include <sys/bus.h>
     38   1.1  jmcneill #include <sys/cpu.h>
     39   1.1  jmcneill #include <sys/device.h>
     40   1.1  jmcneill #include <sys/termios.h>
     41   1.1  jmcneill 
     42   1.1  jmcneill #include <dev/fdt/fdtvar.h>
     43  1.47     skrll 
     44   1.1  jmcneill #include <arm/fdt/arm_fdtvar.h>
     45   1.1  jmcneill 
     46   1.1  jmcneill #include <uvm/uvm_extern.h>
     47   1.1  jmcneill 
     48   1.1  jmcneill #include <machine/bootconfig.h>
     49   1.1  jmcneill #include <arm/cpufunc.h>
     50   1.1  jmcneill 
     51   1.1  jmcneill #include <arm/cortex/gtmr_var.h>
     52   1.1  jmcneill #include <arm/cortex/gic_reg.h>
     53   1.1  jmcneill 
     54   1.1  jmcneill #include <dev/ic/ns16550reg.h>
     55   1.1  jmcneill #include <dev/ic/comreg.h>
     56   1.1  jmcneill 
     57   1.1  jmcneill #include <arm/arm/psci.h>
     58  1.26       ryo #include <arm/fdt/psci_fdtvar.h>
     59   1.1  jmcneill 
     60   1.1  jmcneill #include <arm/sunxi/sunxi_platform.h>
     61   1.1  jmcneill 
     62  1.32  jmcneill #if defined(SOC_SUNXI_MC)
     63  1.32  jmcneill #include <arm/sunxi/sunxi_mc_smp.h>
     64  1.32  jmcneill #endif
     65  1.32  jmcneill 
     66   1.8  jmcneill #include <libfdt.h>
     67   1.8  jmcneill 
     68   1.1  jmcneill #define	SUNXI_REF_FREQ	24000000
     69   1.1  jmcneill 
     70   1.7  jmcneill #define	SUN4I_TIMER_BASE	0x01c20c00
     71   1.7  jmcneill #define	SUN4I_TIMER_SIZE	0x90
     72  1.15  jmcneill #define	SUN4I_TIMER_1_CTRL	0x20
     73  1.15  jmcneill #define	 SUN4I_TIMER_1_CTRL_CLK_SRC	__BITS(3,2)
     74  1.15  jmcneill #define	 SUN4I_TIMER_1_CTRL_CLK_SRC_OSC24M	1
     75  1.15  jmcneill #define	 SUN4I_TIMER_1_CTRL_RELOAD	__BIT(1)
     76  1.15  jmcneill #define	 SUN4I_TIMER_1_CTRL_EN		__BIT(0)
     77  1.15  jmcneill #define	SUN4I_TIMER_1_INTV_VALUE 0x24
     78  1.15  jmcneill #define	SUN4I_TIMER_1_VAL	0x28
     79   1.7  jmcneill 
     80   1.7  jmcneill #define	SUN4I_WDT_BASE		0x01c20c90
     81   1.7  jmcneill #define	SUN4I_WDT_SIZE		0x10
     82   1.7  jmcneill #define	SUN4I_WDT_CTRL		0x00
     83   1.7  jmcneill #define	 SUN4I_WDT_CTRL_KEY	(0x333 << 1)
     84   1.7  jmcneill #define	 SUN4I_WDT_CTRL_RESTART	__BIT(0)
     85   1.7  jmcneill #define	SUN4I_WDT_MODE		0x04
     86   1.7  jmcneill #define	 SUN4I_WDT_MODE_RST_EN	__BIT(1)
     87   1.7  jmcneill #define	 SUN4I_WDT_MODE_EN	__BIT(0)
     88   1.7  jmcneill 
     89   1.3  jmcneill #define	SUN6I_WDT_BASE		0x01c20ca0
     90   1.3  jmcneill #define	SUN6I_WDT_SIZE		0x20
     91   1.3  jmcneill #define	SUN6I_WDT_CFG		0x14
     92   1.7  jmcneill #define	 SUN6I_WDT_CFG_SYS	__BIT(0)
     93   1.3  jmcneill #define	SUN6I_WDT_MODE		0x18
     94   1.7  jmcneill #define	 SUN6I_WDT_MODE_EN	__BIT(0)
     95   1.1  jmcneill 
     96  1.10  jmcneill #define	SUN9I_WDT_BASE		0x06000ca0
     97  1.10  jmcneill #define	SUN9I_WDT_SIZE		0x20
     98  1.10  jmcneill #define	SUN9I_WDT_CFG		0x14
     99  1.10  jmcneill #define	 SUN9I_WDT_CFG_SYS	__BIT(0)
    100  1.10  jmcneill #define	SUN9I_WDT_MODE		0x18
    101  1.10  jmcneill #define	 SUN9I_WDT_MODE_EN	__BIT(0)
    102  1.10  jmcneill 
    103  1.20  jmcneill #define	SUN50I_H6_WDT_BASE	0x01c20ca0
    104  1.20  jmcneill #define	SUN50I_H6_WDT_SIZE	0x20
    105  1.20  jmcneill #define	SUN50I_H6_WDT_CFG	0x14
    106  1.20  jmcneill #define	 SUN50I_H6_WDT_CFG_SYS	__BIT(0)
    107  1.20  jmcneill #define	SUN50I_H6_WDT_MODE	0x18
    108  1.20  jmcneill #define	 SUN50I_H6_WDT_MODE_EN	__BIT(0)
    109  1.20  jmcneill 
    110  1.21       ryo extern struct arm32_bus_dma_tag arm_generic_dma_tag;
    111  1.22       ryo extern struct bus_space arm_generic_bs_tag;
    112  1.22       ryo 
    113  1.22       ryo #define	sunxi_dma_tag		arm_generic_dma_tag
    114  1.22       ryo #define	sunxi_bs_tag		arm_generic_bs_tag
    115   1.1  jmcneill 
    116  1.37       mrg static bus_space_handle_t reset_bsh;
    117  1.37       mrg 
    118   1.1  jmcneill static const struct pmap_devmap *
    119   1.1  jmcneill sunxi_platform_devmap(void)
    120   1.1  jmcneill {
    121   1.1  jmcneill 	static const struct pmap_devmap devmap[] = {
    122   1.1  jmcneill 		DEVMAP_ENTRY(SUNXI_CORE_VBASE,
    123   1.1  jmcneill 			     SUNXI_CORE_PBASE,
    124   1.1  jmcneill 			     SUNXI_CORE_SIZE),
    125   1.1  jmcneill 		DEVMAP_ENTRY_END
    126  1.17     skrll 	};
    127   1.1  jmcneill 
    128   1.1  jmcneill 	return devmap;
    129   1.1  jmcneill }
    130   1.1  jmcneill 
    131  1.34  jmcneill #define	SUNXI_MC_CPU_VBASE	(SUNXI_CORE_VBASE + SUNXI_CORE_SIZE)
    132  1.34  jmcneill #define	SUNXI_MC_CPU_PBASE	0x01700000
    133  1.34  jmcneill #define	SUNXI_MC_CPU_SIZE	0x00100000
    134  1.32  jmcneill 
    135  1.32  jmcneill static const struct pmap_devmap *
    136  1.32  jmcneill sun8i_a83t_platform_devmap(void)
    137  1.32  jmcneill {
    138  1.32  jmcneill 	static const struct pmap_devmap devmap[] = {
    139  1.32  jmcneill 		DEVMAP_ENTRY(SUNXI_CORE_VBASE,
    140  1.32  jmcneill 			     SUNXI_CORE_PBASE,
    141  1.32  jmcneill 			     SUNXI_CORE_SIZE),
    142  1.34  jmcneill 		DEVMAP_ENTRY(SUNXI_MC_CPU_VBASE,
    143  1.34  jmcneill 			     SUNXI_MC_CPU_PBASE,
    144  1.34  jmcneill 			     SUNXI_MC_CPU_SIZE),
    145  1.32  jmcneill 		DEVMAP_ENTRY_END
    146  1.32  jmcneill 	};
    147  1.32  jmcneill 
    148  1.32  jmcneill 	return devmap;
    149  1.32  jmcneill }
    150  1.32  jmcneill 
    151  1.34  jmcneill #define	SUN9I_A80_PRCM_VBASE	(SUNXI_MC_CPU_VBASE + SUNXI_MC_CPU_PBASE)
    152  1.34  jmcneill #define	SUN9I_A80_PRCM_PBASE	0x08000000
    153  1.34  jmcneill #define	SUN9I_A80_PRCM_SIZE	0x00100000
    154  1.34  jmcneill 
    155  1.34  jmcneill static const struct pmap_devmap *
    156  1.34  jmcneill sun9i_a80_platform_devmap(void)
    157  1.34  jmcneill {
    158  1.34  jmcneill 	static const struct pmap_devmap devmap[] = {
    159  1.34  jmcneill 		DEVMAP_ENTRY(SUNXI_CORE_VBASE,
    160  1.34  jmcneill 			     SUNXI_CORE_PBASE,
    161  1.34  jmcneill 			     SUNXI_CORE_SIZE),
    162  1.34  jmcneill 		DEVMAP_ENTRY(SUNXI_MC_CPU_VBASE,
    163  1.34  jmcneill 			     SUNXI_MC_CPU_PBASE,
    164  1.34  jmcneill 			     SUNXI_MC_CPU_SIZE),
    165  1.34  jmcneill 		DEVMAP_ENTRY(SUN9I_A80_PRCM_VBASE,
    166  1.34  jmcneill 			     SUN9I_A80_PRCM_PBASE,
    167  1.34  jmcneill 			     SUN9I_A80_PRCM_SIZE),
    168  1.34  jmcneill 		DEVMAP_ENTRY_END
    169  1.34  jmcneill 	};
    170  1.34  jmcneill 
    171  1.34  jmcneill 	return devmap;
    172  1.34  jmcneill }
    173  1.34  jmcneill 
    174  1.34  jmcneill 
    175   1.1  jmcneill static void
    176   1.1  jmcneill sunxi_platform_init_attach_args(struct fdt_attach_args *faa)
    177   1.1  jmcneill {
    178  1.22       ryo 	faa->faa_bst = &sunxi_bs_tag;
    179  1.22       ryo 	faa->faa_dmat = &sunxi_dma_tag;
    180   1.1  jmcneill }
    181   1.1  jmcneill 
    182  1.22       ryo void sunxi_platform_early_putchar(char);
    183  1.22       ryo 
    184  1.39     skrll void __noasan
    185   1.1  jmcneill sunxi_platform_early_putchar(char c)
    186   1.1  jmcneill {
    187   1.1  jmcneill #ifdef CONSADDR
    188  1.22       ryo #define CONSADDR_VA	((CONSADDR - SUNXI_CORE_PBASE) + SUNXI_CORE_VBASE)
    189  1.22       ryo 	volatile uint32_t *uartaddr = cpu_earlydevice_va_p() ?
    190  1.22       ryo 	    (volatile uint32_t *)CONSADDR_VA :
    191  1.22       ryo 	    (volatile uint32_t *)CONSADDR;
    192   1.1  jmcneill 
    193  1.14  jakllsch 	while ((le32toh(uartaddr[com_lsr]) & LSR_TXRDY) == 0)
    194   1.1  jmcneill 		;
    195   1.1  jmcneill 
    196  1.14  jakllsch 	uartaddr[com_data] = htole32(c);
    197   1.1  jmcneill #endif
    198   1.1  jmcneill }
    199   1.1  jmcneill 
    200   1.1  jmcneill static void
    201   1.1  jmcneill sunxi_platform_device_register(device_t self, void *aux)
    202   1.1  jmcneill {
    203  1.18  jmcneill 	prop_dictionary_t prop = device_properties(self);
    204  1.35  jmcneill 	int val;
    205  1.18  jmcneill 
    206  1.18  jmcneill 	if (device_is_a(self, "rgephy")) {
    207  1.19  jmcneill 		/* Pine64+ and NanoPi NEO Plus2 gigabit ethernet workaround */
    208  1.41   thorpej 		static const struct device_compatible_entry compat_data[] = {
    209  1.41   thorpej 			{ .compat = "pine64,pine64-plus" },
    210  1.41   thorpej 			{ .compat = "friendlyarm,nanopi-neo-plus2" },
    211  1.41   thorpej 			DEVICE_COMPAT_EOL
    212  1.19  jmcneill 		};
    213  1.41   thorpej 		if (of_compatible_match(OF_finddevice("/"), compat_data)) {
    214  1.18  jmcneill 			prop_dictionary_set_bool(prop, "no-rx-delay", true);
    215  1.18  jmcneill 		}
    216  1.18  jmcneill 	}
    217  1.27  jmcneill 
    218  1.27  jmcneill 	if (device_is_a(self, "armgtmr")) {
    219  1.27  jmcneill 		/* Allwinner A64 has an unstable architectural timer */
    220  1.41   thorpej 		static const struct device_compatible_entry compat_data[] = {
    221  1.41   thorpej 			{ .compat = "allwinner,sun50i-a64" },
    222  1.36       mrg 			/* Cubietruck Plus triggers this problem as well. */
    223  1.41   thorpej 			{ .compat = "allwinner,sun8i-a83t" },
    224  1.41   thorpej 			DEVICE_COMPAT_EOL
    225  1.27  jmcneill 		};
    226  1.41   thorpej 		if (of_compatible_match(OF_finddevice("/"), compat_data)) {
    227  1.27  jmcneill 			prop_dictionary_set_bool(prop, "sun50i-a64-unstable-timer", true);
    228  1.27  jmcneill 		}
    229  1.27  jmcneill 	}
    230  1.35  jmcneill 
    231  1.38  jmcneill 	if (device_is_a(self, "sunxidrm") || device_is_a(self, "dwhdmi")) {
    232  1.35  jmcneill 		if (get_bootconf_option(boot_args, "nomodeset", BOOTOPT_TYPE_BOOLEAN, &val))
    233  1.35  jmcneill 			if (val)
    234  1.35  jmcneill 				prop_dictionary_set_bool(prop, "disabled", true);
    235  1.35  jmcneill 	}
    236  1.38  jmcneill 
    237  1.38  jmcneill 	if (device_is_a(self, "sun50ia64ccu0")) {
    238  1.38  jmcneill 		if (get_bootconf_option(boot_args, "nomodeset", BOOTOPT_TYPE_BOOLEAN, &val))
    239  1.38  jmcneill 			if (val)
    240  1.38  jmcneill 				prop_dictionary_set_bool(prop, "nomodeset", true);
    241  1.38  jmcneill 	}
    242  1.44       tnn 
    243  1.44       tnn 	if (device_is_a(self, "com")) {
    244  1.44       tnn 		static const struct device_compatible_entry compat_data[] = {
    245  1.45       tnn 			{ .compat = "allwinner,sun4i-a10",	.value = 64 },
    246  1.45       tnn 			{ .compat = "allwinner,sun5i-a13",	.value = 64 },
    247  1.45       tnn 			{ .compat = "allwinner,sun6i-a31",	.value = 64 },
    248  1.45       tnn 			{ .compat = "allwinner,sun7i-a20",	.value = 64 },
    249  1.45       tnn 			{ .compat = "allwinner,sun8i-h2-plus",	.value = 64 },
    250  1.45       tnn 			{ .compat = "allwinner,sun8i-h3",	.value = 64 },
    251  1.45       tnn 			{ .compat = "allwinner,sun8i-a83t",	.value = 64 },
    252  1.45       tnn 			{ .compat = "allwinner,sun9i-a80",	.value = 64 },
    253  1.45       tnn 			{ .compat = "allwinner,sun50i-a64",	.value = 64 },
    254  1.45       tnn 			{ .compat = "allwinner,sun50i-h5",	.value = 64 },
    255  1.45       tnn 			{ .compat = "allwinner,sun50i-h6",	.value = 256 },
    256  1.44       tnn 			DEVICE_COMPAT_EOL
    257  1.44       tnn 		};
    258  1.45       tnn 		const struct device_compatible_entry *dce =
    259  1.45       tnn 		    of_compatible_lookup(OF_finddevice("/"), compat_data);
    260  1.45       tnn 		if (dce != NULL)
    261  1.45       tnn 			prop_dictionary_set_uint(prop, "fifolen", dce->value);
    262  1.44       tnn 	}
    263   1.1  jmcneill }
    264   1.1  jmcneill 
    265   1.3  jmcneill static u_int
    266   1.3  jmcneill sunxi_platform_uart_freq(void)
    267   1.3  jmcneill {
    268   1.3  jmcneill 	return SUNXI_REF_FREQ;
    269   1.3  jmcneill }
    270   1.3  jmcneill 
    271   1.1  jmcneill static void
    272   1.8  jmcneill sunxi_platform_bootstrap(void)
    273   1.8  jmcneill {
    274  1.30     skrll 	arm_fdt_cpu_bootstrap();
    275  1.30     skrll 
    276  1.23    bouyer 	void *fdt_data = __UNCONST(fdtbus_get_data());
    277  1.23    bouyer 	const int chosen_off = fdt_path_offset(fdt_data, "/chosen");
    278  1.23    bouyer 	if (chosen_off < 0)
    279  1.23    bouyer 		return;
    280  1.23    bouyer 
    281   1.8  jmcneill 	if (match_bootconf_option(boot_args, "console", "fb")) {
    282   1.8  jmcneill 		const int framebuffer_off =
    283   1.8  jmcneill 		    fdt_path_offset(fdt_data, "/chosen/framebuffer");
    284  1.23    bouyer 		if (framebuffer_off >= 0) {
    285  1.22       ryo 			const char *status = fdt_getprop(fdt_data,
    286  1.22       ryo 			    framebuffer_off, "status", NULL);
    287  1.22       ryo 			if (status == NULL || strncmp(status, "ok", 2) == 0) {
    288  1.22       ryo 				fdt_setprop_string(fdt_data, chosen_off,
    289  1.22       ryo 				    "stdout-path", "/chosen/framebuffer");
    290  1.22       ryo 			}
    291  1.22       ryo 		}
    292  1.23    bouyer 	} else if (match_bootconf_option(boot_args, "console", "serial")) {
    293  1.23    bouyer 		fdt_setprop_string(fdt_data, chosen_off,
    294  1.23    bouyer 		    "stdout-path", "serial0:115200n8");
    295   1.8  jmcneill 	}
    296   1.7  jmcneill }
    297   1.7  jmcneill 
    298  1.37       mrg static void
    299  1.37       mrg sun4i_platform_bootstrap(void)
    300  1.37       mrg {
    301  1.37       mrg 	bus_space_tag_t bst = &sunxi_bs_tag;
    302  1.37       mrg 
    303  1.37       mrg 	sunxi_platform_bootstrap();
    304  1.37       mrg 	bus_space_map(bst, SUN4I_WDT_BASE, SUN4I_WDT_SIZE, 0, &reset_bsh);
    305  1.37       mrg }
    306  1.37       mrg 
    307  1.37       mrg static void
    308  1.37       mrg sun6i_platform_bootstrap(void)
    309  1.37       mrg {
    310  1.37       mrg 	bus_space_tag_t bst = &sunxi_bs_tag;
    311  1.37       mrg 
    312  1.37       mrg 	sunxi_platform_bootstrap();
    313  1.37       mrg 	bus_space_map(bst, SUN6I_WDT_BASE, SUN6I_WDT_SIZE, 0, &reset_bsh);
    314  1.37       mrg }
    315  1.37       mrg 
    316  1.37       mrg static void
    317  1.37       mrg sun9i_platform_bootstrap(void)
    318  1.37       mrg {
    319  1.37       mrg 	bus_space_tag_t bst = &sunxi_bs_tag;
    320  1.37       mrg 
    321  1.37       mrg 	sunxi_platform_bootstrap();
    322  1.37       mrg 	bus_space_map(bst, SUN9I_WDT_BASE, SUN9I_WDT_SIZE, 0, &reset_bsh);
    323  1.37       mrg }
    324  1.37       mrg 
    325  1.37       mrg static void
    326  1.37       mrg sun50i_h6_platform_bootstrap(void)
    327  1.37       mrg {
    328  1.37       mrg 	bus_space_tag_t bst = &sunxi_bs_tag;
    329  1.37       mrg 
    330  1.37       mrg 	sunxi_platform_bootstrap();
    331  1.37       mrg 	bus_space_map(bst, SUN50I_H6_WDT_BASE, SUN50I_H6_WDT_SIZE, 0, &reset_bsh);
    332  1.37       mrg }
    333  1.37       mrg 
    334  1.33  jmcneill #if defined(SOC_SUNXI_MC)
    335  1.33  jmcneill static int
    336  1.34  jmcneill cpu_enable_sun8i_a83t(int phandle)
    337  1.32  jmcneill {
    338  1.33  jmcneill 	uint64_t mpidr;
    339  1.32  jmcneill 
    340  1.33  jmcneill 	fdtbus_get_reg64(phandle, 0, &mpidr, NULL);
    341  1.32  jmcneill 
    342  1.34  jmcneill 	return sun8i_a83t_smp_enable(mpidr);
    343  1.33  jmcneill }
    344  1.34  jmcneill ARM_CPU_METHOD(sun8i_a83t, "allwinner,sun8i-a83t-smp", cpu_enable_sun8i_a83t);
    345  1.34  jmcneill 
    346  1.34  jmcneill static int
    347  1.34  jmcneill cpu_enable_sun9i_a80(int phandle)
    348  1.34  jmcneill {
    349  1.34  jmcneill 	uint64_t mpidr;
    350  1.34  jmcneill 
    351  1.34  jmcneill 	fdtbus_get_reg64(phandle, 0, &mpidr, NULL);
    352  1.34  jmcneill 
    353  1.34  jmcneill 	return sun9i_a80_smp_enable(mpidr);
    354  1.34  jmcneill }
    355  1.34  jmcneill ARM_CPU_METHOD(sun9i_a80, "allwinner,sun9i-a80-smp", cpu_enable_sun9i_a80);
    356  1.32  jmcneill #endif
    357  1.32  jmcneill 
    358   1.7  jmcneill static void
    359   1.7  jmcneill sun4i_platform_reset(void)
    360   1.7  jmcneill {
    361  1.22       ryo 	bus_space_tag_t bst = &sunxi_bs_tag;
    362   1.7  jmcneill 
    363  1.37       mrg 	bus_space_write_4(bst, reset_bsh, SUN4I_WDT_CTRL,
    364   1.7  jmcneill 	    SUN4I_WDT_CTRL_KEY | SUN4I_WDT_CTRL_RESTART);
    365   1.7  jmcneill 	for (;;) {
    366  1.37       mrg 		bus_space_write_4(bst, reset_bsh, SUN4I_WDT_MODE,
    367   1.7  jmcneill 		    SUN4I_WDT_MODE_EN | SUN4I_WDT_MODE_RST_EN);
    368   1.7  jmcneill 	}
    369   1.7  jmcneill }
    370   1.7  jmcneill 
    371   1.7  jmcneill static void
    372   1.7  jmcneill sun4i_platform_delay(u_int n)
    373   1.7  jmcneill {
    374  1.22       ryo 	static bus_space_tag_t bst = &sunxi_bs_tag;
    375   1.7  jmcneill 	static bus_space_handle_t bsh = 0;
    376  1.12  jmcneill 	const long incs_per_us = SUNXI_REF_FREQ / 1000000;
    377  1.12  jmcneill 	long ticks = n * incs_per_us;
    378   1.7  jmcneill 	uint32_t cur, prev;
    379   1.7  jmcneill 
    380  1.15  jmcneill 	if (bsh == 0) {
    381   1.7  jmcneill 		bus_space_map(bst, SUN4I_TIMER_BASE, SUN4I_TIMER_SIZE, 0, &bsh);
    382   1.7  jmcneill 
    383  1.15  jmcneill 		/* Enable Timer 1 */
    384  1.15  jmcneill 		bus_space_write_4(bst, bsh, SUN4I_TIMER_1_INTV_VALUE, ~0U);
    385  1.15  jmcneill 		bus_space_write_4(bst, bsh, SUN4I_TIMER_1_CTRL,
    386  1.15  jmcneill 		    SUN4I_TIMER_1_CTRL_EN |
    387  1.15  jmcneill 		    SUN4I_TIMER_1_CTRL_RELOAD |
    388  1.15  jmcneill 		    __SHIFTIN(SUN4I_TIMER_1_CTRL_CLK_SRC_OSC24M,
    389  1.15  jmcneill 			      SUN4I_TIMER_1_CTRL_CLK_SRC));
    390  1.15  jmcneill 	}
    391  1.15  jmcneill 
    392  1.15  jmcneill 	prev = ~bus_space_read_4(bst, bsh, SUN4I_TIMER_1_VAL);
    393   1.7  jmcneill 	while (ticks > 0) {
    394  1.15  jmcneill 		cur = ~bus_space_read_4(bst, bsh, SUN4I_TIMER_1_VAL);
    395   1.7  jmcneill 		if (cur > prev)
    396   1.7  jmcneill 			ticks -= (cur - prev);
    397   1.7  jmcneill 		else
    398   1.7  jmcneill 			ticks -= (~0U - cur + prev);
    399   1.7  jmcneill 		prev = cur;
    400   1.7  jmcneill 	}
    401   1.7  jmcneill }
    402   1.7  jmcneill 
    403   1.7  jmcneill static void
    404   1.3  jmcneill sun6i_platform_reset(void)
    405   1.1  jmcneill {
    406  1.22       ryo 	bus_space_tag_t bst = &sunxi_bs_tag;
    407   1.1  jmcneill 
    408  1.37       mrg 	bus_space_write_4(bst, reset_bsh, SUN6I_WDT_CFG, SUN6I_WDT_CFG_SYS);
    409  1.37       mrg 	bus_space_write_4(bst, reset_bsh, SUN6I_WDT_MODE, SUN6I_WDT_MODE_EN);
    410   1.1  jmcneill }
    411   1.1  jmcneill 
    412  1.10  jmcneill static void
    413  1.10  jmcneill sun9i_platform_reset(void)
    414  1.10  jmcneill {
    415  1.22       ryo 	bus_space_tag_t bst = &sunxi_bs_tag;
    416  1.10  jmcneill 
    417  1.37       mrg 	bus_space_write_4(bst, reset_bsh, SUN9I_WDT_CFG, SUN9I_WDT_CFG_SYS);
    418  1.37       mrg 	bus_space_write_4(bst, reset_bsh, SUN9I_WDT_MODE, SUN9I_WDT_MODE_EN);
    419  1.10  jmcneill }
    420  1.10  jmcneill 
    421  1.20  jmcneill static void
    422  1.20  jmcneill sun50i_h6_platform_reset(void)
    423  1.20  jmcneill {
    424  1.22       ryo 	bus_space_tag_t bst = &sunxi_bs_tag;
    425  1.20  jmcneill 
    426  1.37       mrg 	bus_space_write_4(bst, reset_bsh, SUN50I_H6_WDT_CFG, SUN50I_H6_WDT_CFG_SYS);
    427  1.37       mrg 	bus_space_write_4(bst, reset_bsh, SUN50I_H6_WDT_MODE, SUN50I_H6_WDT_MODE_EN);
    428  1.20  jmcneill }
    429  1.20  jmcneill 
    430  1.47     skrll static const struct fdt_platform sun4i_platform = {
    431  1.47     skrll 	.fp_devmap = sunxi_platform_devmap,
    432  1.47     skrll 	.fp_bootstrap = sun4i_platform_bootstrap,
    433  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    434  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    435  1.47     skrll 	.fp_reset = sun4i_platform_reset,
    436  1.47     skrll 	.fp_delay = sun4i_platform_delay,
    437  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    438   1.9  jmcneill };
    439   1.9  jmcneill 
    440  1.47     skrll FDT_PLATFORM(sun4i_a10, "allwinner,sun4i-a10", &sun4i_platform);
    441   1.9  jmcneill 
    442  1.47     skrll static const struct fdt_platform sun5i_platform = {
    443  1.47     skrll 	.fp_devmap = sunxi_platform_devmap,
    444  1.47     skrll 	.fp_bootstrap = sun4i_platform_bootstrap,
    445  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    446  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    447  1.47     skrll 	.fp_reset = sun4i_platform_reset,
    448  1.47     skrll 	.fp_delay = sun4i_platform_delay,
    449  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    450   1.7  jmcneill };
    451   1.7  jmcneill 
    452  1.47     skrll FDT_PLATFORM(sun5i_a13, "allwinner,sun5i-a13", &sun5i_platform);
    453  1.47     skrll FDT_PLATFORM(sun5i_gr8, "nextthing,gr8", &sun5i_platform);
    454   1.6  jmcneill 
    455  1.47     skrll static const struct fdt_platform sun6i_platform = {
    456  1.47     skrll 	.fp_devmap = sunxi_platform_devmap,
    457  1.47     skrll 	.fp_bootstrap = sun6i_platform_bootstrap,
    458  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    459  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    460  1.47     skrll 	.fp_reset = sun6i_platform_reset,
    461  1.47     skrll 	.fp_delay = gtmr_delay,
    462  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    463  1.47     skrll 	.fp_mpstart = arm_fdt_cpu_mpstart,
    464   1.6  jmcneill };
    465   1.6  jmcneill 
    466  1.47     skrll FDT_PLATFORM(sun6i_a31, "allwinner,sun6i-a31", &sun6i_platform);
    467   1.6  jmcneill 
    468  1.47     skrll static const struct fdt_platform sun7i_platform = {
    469  1.47     skrll 	.fp_devmap = sunxi_platform_devmap,
    470  1.47     skrll 	.fp_bootstrap = sun4i_platform_bootstrap,
    471  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    472  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    473  1.47     skrll 	.fp_reset = sun4i_platform_reset,
    474  1.47     skrll 	.fp_delay = sun4i_platform_delay,
    475  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    476  1.47     skrll 	.fp_mpstart = arm_fdt_cpu_mpstart,
    477   1.9  jmcneill };
    478   1.9  jmcneill 
    479  1.47     skrll FDT_PLATFORM(sun7i_a20, "allwinner,sun7i-a20", &sun7i_platform);
    480   1.9  jmcneill 
    481  1.47     skrll static const struct fdt_platform sun8i_platform = {
    482  1.47     skrll 	.fp_devmap = sunxi_platform_devmap,
    483  1.47     skrll 	.fp_bootstrap = sun6i_platform_bootstrap,
    484  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    485  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    486  1.47     skrll 	.fp_reset = sun6i_platform_reset,
    487  1.47     skrll 	.fp_delay = gtmr_delay,
    488  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    489  1.47     skrll 	.fp_mpstart = arm_fdt_cpu_mpstart,
    490   1.3  jmcneill };
    491   1.3  jmcneill 
    492  1.47     skrll FDT_PLATFORM(sun8i_h2plus, "allwinner,sun8i-h2-plus", &sun8i_platform);
    493  1.47     skrll FDT_PLATFORM(sun8i_h3, "allwinner,sun8i-h3", &sun8i_platform);
    494  1.47     skrll FDT_PLATFORM(sun8i_v3s, "allwinner,sun8i-v3s", &sun8i_platform);
    495  1.47     skrll 
    496  1.47     skrll static const struct fdt_platform sun8i_a83t_platform = {
    497  1.47     skrll 	.fp_devmap = sun8i_a83t_platform_devmap,
    498  1.47     skrll 	.fp_bootstrap = sun6i_platform_bootstrap,
    499  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    500  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    501  1.47     skrll 	.fp_reset = sun6i_platform_reset,
    502  1.47     skrll 	.fp_delay = gtmr_delay,
    503  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    504  1.47     skrll 	.fp_mpstart = arm_fdt_cpu_mpstart,
    505  1.32  jmcneill };
    506  1.32  jmcneill 
    507  1.47     skrll FDT_PLATFORM(sun8i_a83t, "allwinner,sun8i-a83t", &sun8i_a83t_platform);
    508   1.1  jmcneill 
    509  1.47     skrll static const struct fdt_platform sun9i_platform = {
    510  1.47     skrll 	.fp_devmap = sun9i_a80_platform_devmap,
    511  1.47     skrll 	.fp_bootstrap = sun9i_platform_bootstrap,
    512  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    513  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    514  1.47     skrll 	.fp_reset = sun9i_platform_reset,
    515  1.47     skrll 	.fp_delay = gtmr_delay,
    516  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    517  1.47     skrll 	.fp_mpstart = arm_fdt_cpu_mpstart,
    518  1.10  jmcneill };
    519  1.10  jmcneill 
    520  1.47     skrll FDT_PLATFORM(sun9i_a80, "allwinner,sun9i-a80", &sun9i_platform);
    521  1.10  jmcneill 
    522  1.47     skrll static const struct fdt_platform sun50i_platform = {
    523  1.47     skrll 	.fp_devmap = sunxi_platform_devmap,
    524  1.47     skrll 	.fp_bootstrap = sun6i_platform_bootstrap,
    525  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    526  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    527  1.47     skrll 	.fp_reset = sun6i_platform_reset,
    528  1.47     skrll 	.fp_delay = gtmr_delay,
    529  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    530  1.47     skrll 	.fp_mpstart = arm_fdt_cpu_mpstart,
    531   1.1  jmcneill };
    532   1.1  jmcneill 
    533  1.47     skrll FDT_PLATFORM(sun50i_a64, "allwinner,sun50i-a64", &sun50i_platform);
    534  1.47     skrll FDT_PLATFORM(sun50i_h5, "allwinner,sun50i-h5", &sun50i_platform);
    535  1.20  jmcneill 
    536  1.47     skrll static const struct fdt_platform sun50i_h6_platform = {
    537  1.47     skrll 	.fp_devmap = sunxi_platform_devmap,
    538  1.47     skrll 	.fp_bootstrap = sun50i_h6_platform_bootstrap,
    539  1.47     skrll 	.fp_init_attach_args = sunxi_platform_init_attach_args,
    540  1.47     skrll 	.fp_device_register = sunxi_platform_device_register,
    541  1.47     skrll 	.fp_reset = sun50i_h6_platform_reset,
    542  1.47     skrll 	.fp_delay = gtmr_delay,
    543  1.47     skrll 	.fp_uart_freq = sunxi_platform_uart_freq,
    544  1.47     skrll 	.fp_mpstart = arm_fdt_cpu_mpstart,
    545  1.20  jmcneill };
    546  1.20  jmcneill 
    547  1.47     skrll FDT_PLATFORM(sun50i_h6, "allwinner,sun50i-h6", &sun50i_h6_platform);
    548