xref: /openbsd-src/sys/arch/armv7/omap/omap.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /* $OpenBSD: omap.c,v 1.19 2016/08/11 04:33:06 jsg Exp $ */
2 /*
3  * Copyright (c) 2005,2008 Dale Rahn <drahn@openbsd.com>
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();
30 void	omap4_init();
31 void	am335x_init();
32 
33 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 	{ "sitaracm",	0 },
51 	{ "edma",	0 },
52 	{ "dmtimer",	0 },
53 	{ "dmtimer",	1 },
54 	{ NULL,		0 }
55 };
56 
57 struct board_dev omap4_dev[] = {
58 	{ "omapid",	0 },
59 	{ "prcm",	0 },
60 	{ NULL,		0 }
61 };
62 
63 struct omap_soc {
64 	char			*compatible;
65 	struct board_dev	*devs;
66 	void			(*init)(void);
67 };
68 
69 struct omap_soc omap_socs[] = {
70 	{
71 		"ti,omap3",
72 		omap3_dev,
73 		omap3_init,
74 	},
75 	{
76 		"ti,am33xx",
77 		am33xx_dev,
78 		am335x_init,
79 	},
80 	{
81 		"ti,omap4",
82 		omap4_dev,
83 		omap4_init,
84 	},
85 	{ NULL, NULL, NULL },
86 };
87 
88 struct board_dev *
89 omap_board_devs(void)
90 {
91 	void *node;
92 	int i;
93 
94 	node = fdt_find_node("/");
95 	if (node == NULL)
96 		return NULL;
97 
98 	for (i = 0; omap_socs[i].compatible != NULL; i++) {
99 		if (fdt_is_compatible(node, omap_socs[i].compatible))
100 			return omap_socs[i].devs;
101 	}
102 	return NULL;
103 }
104 
105 void
106 omap_board_init(void)
107 {
108 	void *node;
109 	int i;
110 
111 	node = fdt_find_node("/");
112 	if (node == NULL)
113 		return;
114 
115 	for (i = 0; omap_socs[i].compatible != NULL; i++) {
116 		if (fdt_is_compatible(node, omap_socs[i].compatible)) {
117 			omap_socs[i].init();
118 			break;
119 		}
120 	}
121 }
122 
123 int
124 omap_match(struct device *parent, void *cfdata, void *aux)
125 {
126 	union mainbus_attach_args *ma = (union mainbus_attach_args *)aux;
127 	struct cfdata *cf = (struct cfdata *)cfdata;
128 
129 	if (ma->ma_name == NULL)
130 		return (0);
131 
132 	if (strcmp(cf->cf_driver->cd_name, ma->ma_name) != 0)
133 		return (0);
134 
135 	return (omap_board_devs() != NULL);
136 }
137