1 /* $NetBSD: exynos_platform.c,v 1.10 2018/07/02 12:49:37 jmcneill Exp $ */ 2 3 /*- 4 * Copyright (c) 2017 Jared D. McNeill <jmcneill@invisible.ca> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include "opt_exynos.h" 30 #include "opt_multiprocessor.h" 31 #include "opt_fdt_arm.h" 32 33 #include "ukbd.h" 34 35 #include <sys/cdefs.h> 36 __KERNEL_RCSID(0, "$NetBSD: exynos_platform.c,v 1.10 2018/07/02 12:49:37 jmcneill Exp $"); 37 38 #include <sys/param.h> 39 #include <sys/bus.h> 40 #include <sys/cpu.h> 41 #include <sys/device.h> 42 #include <sys/termios.h> 43 44 #include <dev/fdt/fdtvar.h> 45 46 #include <uvm/uvm_extern.h> 47 48 #include <machine/bootconfig.h> 49 #include <arm/cpufunc.h> 50 51 #include <arm/samsung/exynos_reg.h> 52 #include <arm/samsung/exynos_var.h> 53 #include <arm/samsung/mct_var.h> 54 55 #include <evbarm/exynos/platform.h> 56 57 #include <arm/fdt/arm_fdtvar.h> 58 59 #define EXYNOS5_SWRESET_REG 0x10040400 60 61 static const struct pmap_devmap * 62 exynos_platform_devmap(void) 63 { 64 static const struct pmap_devmap devmap[] = { 65 DEVMAP_ENTRY(EXYNOS_CORE_VBASE, 66 EXYNOS_CORE_PBASE, 67 EXYNOS5_CORE_SIZE), 68 DEVMAP_ENTRY(EXYNOS5_AUDIOCORE_VBASE, 69 EXYNOS5_AUDIOCORE_PBASE, 70 EXYNOS5_AUDIOCORE_SIZE), 71 DEVMAP_ENTRY_END 72 }; 73 74 return devmap; 75 } 76 77 #define EXYNOS_IOPHYSTOVIRT(a) \ 78 ((vaddr_t)(((a) - EXYNOS_CORE_PBASE) + EXYNOS_CORE_VBASE)) 79 80 static void 81 exynos_platform_bootstrap(void) 82 { 83 paddr_t uart_address = armreg_tpidruro_read(); /* XXX */ 84 exynos_bootstrap(EXYNOS_CORE_VBASE, EXYNOS_IOPHYSTOVIRT(uart_address)); 85 } 86 87 static void 88 exynos_platform_init_attach_args(struct fdt_attach_args *faa) 89 { 90 extern struct bus_space armv7_generic_bs_tag; 91 extern struct bus_space armv7_generic_a4x_bs_tag; 92 extern struct arm32_bus_dma_tag arm_generic_dma_tag; 93 94 faa->faa_bst = &armv7_generic_bs_tag; 95 faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag; 96 faa->faa_dmat = &arm_generic_dma_tag; 97 } 98 99 static void 100 exynos_platform_early_putchar(char c) 101 { 102 #if defined(VERBOSE_INIT_ARM) 103 extern void exynos_putchar(int); /* XXX from exynos_start.S */ 104 105 exynos_putchar(c); 106 #endif 107 } 108 109 static void 110 exynos_platform_device_register(device_t self, void *aux) 111 { 112 exynos_device_register(self, aux); 113 } 114 115 static void 116 exynos5_platform_reset(void) 117 { 118 bus_space_tag_t bst = &armv7_generic_bs_tag; 119 bus_space_handle_t bsh; 120 121 bus_space_map(bst, EXYNOS5_SWRESET_REG, 4, 0, &bsh); 122 bus_space_write_4(bst, bsh, 0, 1); 123 } 124 125 static u_int 126 exynos_platform_uart_freq(void) 127 { 128 return EXYNOS_UART_FREQ; 129 } 130 131 static const struct arm_platform exynos5_platform = { 132 .devmap = exynos_platform_devmap, 133 .bootstrap = exynos_platform_bootstrap, 134 .init_attach_args = exynos_platform_init_attach_args, 135 .early_putchar = exynos_platform_early_putchar, 136 .device_register = exynos_platform_device_register, 137 .reset = exynos5_platform_reset, 138 .delay = mct_delay, 139 .uart_freq = exynos_platform_uart_freq, 140 }; 141 142 ARM_PLATFORM(exynos5, "samsung,exynos5", &exynos5_platform); 143