1 /* $OpenBSD: omap.c,v 1.24 2021/10/24 17:52:27 mpi Exp $ */
2 /*
3 * Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.org>
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/systm.h>
20
21 #include <machine/bus.h>
22
23 #include <arm/mainbus/mainbus.h>
24 #include <armv7/armv7/armv7var.h>
25
26 #include <dev/ofw/fdt.h>
27
28 int omap_match(struct device *, void *, void *);
29 void omap3_init(void);
30 void omap4_init(void);
31 void am335x_init(void);
32
33 const struct cfattach omap_ca = {
34 sizeof(struct armv7_softc), omap_match, armv7_attach
35 };
36
37 struct cfdriver omap_cd = {
38 NULL, "omap", DV_DULL
39 };
40
41 struct board_dev omap3_dev[] = {
42 { "prcm", 0 },
43 { "gptimer", 0 },
44 { "gptimer", 1 },
45 { NULL, 0 }
46 };
47
48 struct board_dev am33xx_dev[] = {
49 { "prcm", 0 },
50 { "dmtimer", 0 },
51 { "dmtimer", 1 },
52 { NULL, 0 }
53 };
54
55 struct board_dev omap4_dev[] = {
56 { "omapid", 0 },
57 { "prcm", 0 },
58 { NULL, 0 }
59 };
60
61 struct omap_soc {
62 char *compatible;
63 struct board_dev *devs;
64 void (*init)(void);
65 };
66
67 struct omap_soc omap_socs[] = {
68 {
69 "ti,omap3",
70 omap3_dev,
71 omap3_init,
72 },
73 {
74 "ti,am33xx",
75 am33xx_dev,
76 am335x_init,
77 },
78 {
79 "ti,omap4",
80 omap4_dev,
81 omap4_init,
82 },
83 { NULL, NULL, NULL },
84 };
85
86 struct board_dev *
omap_board_devs(void)87 omap_board_devs(void)
88 {
89 void *node;
90 int i;
91
92 node = fdt_find_node("/");
93 if (node == NULL)
94 return NULL;
95
96 for (i = 0; omap_socs[i].compatible != NULL; i++) {
97 if (fdt_is_compatible(node, omap_socs[i].compatible))
98 return omap_socs[i].devs;
99 }
100 return NULL;
101 }
102
103 void
omap_board_init(void)104 omap_board_init(void)
105 {
106 void *node;
107 int i;
108
109 node = fdt_find_node("/");
110 if (node == NULL)
111 return;
112
113 for (i = 0; omap_socs[i].compatible != NULL; i++) {
114 if (fdt_is_compatible(node, omap_socs[i].compatible)) {
115 omap_socs[i].init();
116 break;
117 }
118 }
119 }
120
121 int
omap_match(struct device * parent,void * cfdata,void * aux)122 omap_match(struct device *parent, void *cfdata, void *aux)
123 {
124 union mainbus_attach_args *ma = (union mainbus_attach_args *)aux;
125 struct cfdata *cf = (struct cfdata *)cfdata;
126
127 if (ma->ma_name == NULL)
128 return (0);
129
130 if (strcmp(cf->cf_driver->cd_name, ma->ma_name) != 0)
131 return (0);
132
133 return (omap_board_devs() != NULL);
134 }
135