1 /* $OpenBSD: platform.c,v 1.27 2021/05/16 03:39:28 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
20 #include <machine/bus.h>
21
22 #include <arm/mainbus/mainbus.h>
23 #include <armv7/armv7/armv7var.h>
24 #include <armv7/armv7/armv7_machdep.h>
25 #include <arm/cortex/smc.h>
26
27 #include "omap.h"
28
29 static struct armv7_platform *platform;
30
31 void agtimer_init(void);
32
33 extern void cduart_init_cons(void);
34 extern void exuart_init_cons(void);
35 extern void imxuart_init_cons(void);
36 extern void com_fdt_init_cons(void);
37 extern void pluart_init_cons(void);
38 extern void simplefb_init_cons(bus_space_tag_t);
39
40 struct armv7_platform *omap_platform_match(void);
41
42 struct armv7_platform * (*plat_match[])(void) = {
43 #if NOMAP > 0
44 omap_platform_match,
45 #endif
46 };
47
48 struct board_dev no_devs[] = {
49 { NULL, 0 }
50 };
51
52 void
platform_init(void)53 platform_init(void)
54 {
55 int i;
56
57 agtimer_init();
58
59 for (i = 0; i < nitems(plat_match); i++) {
60 platform = plat_match[i]();
61 if (platform != NULL)
62 break;
63 }
64
65 if (platform == NULL)
66 return;
67
68 cpuresetfn = platform_watchdog_reset;
69 powerdownfn = platform_powerdown;
70 if (platform->board_init)
71 platform->board_init();
72 }
73
74 void
platform_smc_write(bus_space_tag_t iot,bus_space_handle_t ioh,bus_size_t off,uint32_t op,uint32_t val)75 platform_smc_write(bus_space_tag_t iot, bus_space_handle_t ioh, bus_size_t off,
76 uint32_t op, uint32_t val)
77 {
78 if (platform && platform->smc_write)
79 platform->smc_write(iot, ioh, off, op, val);
80 else
81 bus_space_write_4(iot, ioh, off, val);
82 }
83
84 void
platform_init_cons(void)85 platform_init_cons(void)
86 {
87 if (platform && platform->init_cons) {
88 platform->init_cons();
89 return;
90 }
91 cduart_init_cons();
92 exuart_init_cons();
93 imxuart_init_cons();
94 com_fdt_init_cons();
95 pluart_init_cons();
96 simplefb_init_cons(&armv7_bs_tag);
97 }
98
99 void
platform_init_mainbus(struct device * self)100 platform_init_mainbus(struct device *self)
101 {
102 if (platform && platform->init_mainbus)
103 platform->init_mainbus(self);
104 else
105 mainbus_legacy_found(self, "cortex");
106 }
107
108 void
platform_watchdog_reset(void)109 platform_watchdog_reset(void)
110 {
111 if (platform && platform->watchdog_reset)
112 platform->watchdog_reset();
113 }
114
115 void
platform_powerdown(void)116 platform_powerdown(void)
117 {
118 if (platform && platform->powerdown)
119 platform->powerdown();
120 }
121
122 struct board_dev *
platform_board_devs(void)123 platform_board_devs(void)
124 {
125 if (platform && platform->devs)
126 return (platform->devs);
127 else
128 return (no_devs);
129 }
130