1 /* $OpenBSD: platform.c,v 1.14 2016/08/31 16:19:40 jsg Exp $ */ 2 /* 3 * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/param.h> 19 #include <sys/types.h> 20 #include <sys/systm.h> 21 22 #include <machine/bus.h> 23 24 #include <arm/mainbus/mainbus.h> 25 #include <armv7/armv7/armv7var.h> 26 #include <armv7/armv7/armv7_machdep.h> 27 #include <arm/cortex/smc.h> 28 29 #include "imx.h" 30 #include "omap.h" 31 #include "sunxi.h" 32 #include "exynos.h" 33 #include "vexpress.h" 34 35 static struct armv7_platform *platform; 36 37 void agtimer_init(void); 38 39 void exuart_init_cons(void); 40 void imxuart_init_cons(void); 41 void com_fdt_init_cons(void); 42 void pluart_init_cons(void); 43 44 struct armv7_platform *imx_platform_match(void); 45 struct armv7_platform *omap_platform_match(void); 46 struct armv7_platform *sunxi_platform_match(void); 47 struct armv7_platform *exynos_platform_match(void); 48 struct armv7_platform *vexpress_platform_match(void); 49 50 struct armv7_platform * (*plat_match[])(void) = { 51 #if NIMX > 0 52 imx_platform_match, 53 #endif 54 #if NOMAP > 0 55 omap_platform_match, 56 #endif 57 #if NSUNXI > 0 58 sunxi_platform_match, 59 #endif 60 #if NEXYNOS > 0 61 exynos_platform_match, 62 #endif 63 #if NVEXPRESS > 0 64 vexpress_platform_match, 65 #endif 66 }; 67 68 struct board_dev no_devs[] = { 69 { NULL, 0 } 70 }; 71 72 void 73 platform_init(void) 74 { 75 int i; 76 77 agtimer_init(); 78 79 for (i = 0; i < nitems(plat_match); i++) { 80 platform = plat_match[i](); 81 if (platform != NULL) 82 break; 83 } 84 if (platform && platform->board_init) 85 platform->board_init(); 86 } 87 88 void 89 platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off, 90 uint32_t op, uint32_t val) 91 { 92 if (platform && platform->smc_write) 93 platform->smc_write(iot, ioh, off, op, val); 94 else 95 bus_space_write_4(iot, ioh, off, val); 96 } 97 98 void 99 platform_init_cons(void) 100 { 101 if (platform && platform->init_cons) { 102 platform->init_cons(); 103 return; 104 } 105 exuart_init_cons(); 106 imxuart_init_cons(); 107 com_fdt_init_cons(); 108 pluart_init_cons(); 109 } 110 111 void 112 platform_init_mainbus(struct device *self) 113 { 114 if (platform && platform->init_mainbus) 115 platform->init_mainbus(self); 116 else 117 mainbus_legacy_found(self, "cortex"); 118 } 119 120 void 121 platform_watchdog_reset(void) 122 { 123 if (platform && platform->watchdog_reset) 124 platform->watchdog_reset(); 125 } 126 127 void 128 platform_powerdown(void) 129 { 130 if (platform && platform->powerdown) 131 platform->powerdown(); 132 } 133 134 void 135 platform_disable_l2_if_needed(void) 136 { 137 if (platform && platform->disable_l2_if_needed) 138 platform->disable_l2_if_needed(); 139 } 140 141 struct board_dev * 142 platform_board_devs() 143 { 144 if (platform && platform->devs) 145 return (platform->devs); 146 else 147 return (no_devs); 148 } 149