xref: /freebsd/sys/arm/ti/ti_scm.c (revision eda14cbc264d6969b02f2b1994cef11148e914f1)
1 /*-
2  * Copyright (c) 2019 Emmanuel Vadot <manu@FreeBSD.org>
3  *
4  * Copyright (c) 2020 Oskar Holmlund <oskar.holmlund@ohdata.se>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 
33 
34 /* Based on sys/arm/ti/ti_sysc.c */
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/bus.h>
39 #include <sys/fbio.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
42 #include <sys/rman.h>
43 #include <sys/resource.h>
44 #include <machine/bus.h>
45 #include <vm/vm.h>
46 #include <vm/vm_extern.h>
47 #include <vm/vm_kern.h>
48 #include <vm/pmap.h>
49 
50 #include <dev/fdt/simplebus.h>
51 
52 #include <dev/ofw/ofw_bus.h>
53 #include <dev/ofw/ofw_bus_subr.h>
54 
55 #define TI_AM3_SCM			14
56 #define TI_AM4_SCM			13
57 #define TI_DM814_SCRM			12
58 #define TI_DM816_SCRM			11
59 #define TI_OMAP2_SCM			10
60 #define TI_OMAP3_SCM			9
61 #define TI_OMAP4_SCM_CORE		8
62 #define TI_OMAP4_SCM_PADCONF_CORE	7
63 #define TI_OMAP4_SCM_WKUP		6
64 #define TI_OMAP4_SCM_PADCONF_WKUP	5
65 #define TI_OMAP5_SCM_CORE		4
66 #define TI_OMAP5_SCM_PADCONF_CORE	3
67 #define TI_OMAP5_SCM_WKUP_PAD_CONF	2
68 #define TI_DRA7_SCM_CORE		1
69 #define TI_SCM_END			0
70 
71 static struct ofw_compat_data compat_data[] = {
72 	{ "ti,am3-scm",			TI_AM3_SCM },
73 	{ "ti,am4-scm",			TI_AM4_SCM },
74 	{ "ti,dm814-scrm",		TI_DM814_SCRM },
75 	{ "ti,dm816-scrm",		TI_DM816_SCRM },
76 	{ "ti,omap2-scm",		TI_OMAP2_SCM },
77 	{ "ti,omap3-scm",		TI_OMAP3_SCM },
78 	{ "ti,omap4-scm-core",		TI_OMAP4_SCM_CORE },
79 	{ "ti,omap4-scm-padconf-core",	TI_OMAP4_SCM_PADCONF_CORE },
80 	{ "ti,omap4-scm-wkup",		TI_OMAP4_SCM_WKUP },
81 	{ "ti,omap4-scm-padconf-wkup",	TI_OMAP4_SCM_PADCONF_WKUP },
82 	{ "ti,omap5-scm-core",		TI_OMAP5_SCM_CORE },
83 	{ "ti,omap5-scm-padconf-core",	TI_OMAP5_SCM_PADCONF_CORE },
84 	{ "ti,omap5-scm-wkup-pad-conf",	TI_OMAP5_SCM_WKUP_PAD_CONF },
85 	{ "ti,dra7-scm-core",		TI_DRA7_SCM_CORE },
86 	{ NULL,				TI_SCM_END }
87 };
88 
89 struct ti_scm_softc {
90 	struct simplebus_softc	sc;
91 	device_t		dev;
92 };
93 
94 static int ti_scm_probe(device_t dev);
95 static int ti_scm_attach(device_t dev);
96 static int ti_scm_detach(device_t dev);
97 
98 static int
99 ti_scm_probe(device_t dev)
100 {
101 	if (!ofw_bus_status_okay(dev))
102 		return (ENXIO);
103 
104 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
105 		return (ENXIO);
106 
107 	device_set_desc(dev, "TI OMAP Control Module");
108 
109 	return (BUS_PROBE_DEFAULT);
110 }
111 
112 static int
113 ti_scm_attach(device_t dev)
114 {
115 	struct ti_scm_softc *sc;
116 	device_t cdev;
117 	phandle_t node, child;
118 
119 	sc = device_get_softc(dev);
120 	sc->dev = dev;
121 	node = ofw_bus_get_node(dev);
122 
123 	simplebus_init(dev, node);
124 	if (simplebus_fill_ranges(node, &sc->sc) < 0) {
125 		device_printf(dev, "could not get ranges\n");
126 		return (ENXIO);
127 	}
128 
129 	for (child = OF_child(node); child > 0; child = OF_peer(child)) {
130 		cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
131 		if (cdev != NULL)
132 			device_probe_and_attach(cdev);
133 	}
134 
135 	return (bus_generic_attach(dev));
136 }
137 
138 static int
139 ti_scm_detach(device_t dev)
140 {
141 	return (EBUSY);
142 }
143 
144 static device_method_t ti_scm_methods[] = {
145 	/* Device interface */
146 	DEVMETHOD(device_probe,		ti_scm_probe),
147 	DEVMETHOD(device_attach,	ti_scm_attach),
148 	DEVMETHOD(device_detach,	ti_scm_detach),
149 
150 	DEVMETHOD_END
151 };
152 
153 DEFINE_CLASS_1(ti_scm, ti_scm_driver, ti_scm_methods,
154     sizeof(struct ti_scm_softc), simplebus_driver);
155 
156 static devclass_t ti_scm_devclass;
157 
158 EARLY_DRIVER_MODULE(ti_scm, simplebus, ti_scm_driver,
159     ti_scm_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
160 MODULE_VERSION(ti_scm, 1);
161 MODULE_DEPEND(ti_scm, ti_sysc, 1, 1, 1);
162 
163