xref: /freebsd/sys/arm/ti/ti_sysc.c (revision 38effe887ee979f91ad5abf42a2291558e7ff8d1)
1 /*-
2  * Copyright (c) 2019 Emmanuel Vadot <manu@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
20  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/fbio.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/rman.h>
38 #include <sys/resource.h>
39 #include <machine/bus.h>
40 #include <vm/vm.h>
41 #include <vm/vm_extern.h>
42 #include <vm/vm_kern.h>
43 #include <vm/pmap.h>
44 
45 #include <dev/fdt/simplebus.h>
46 
47 #include <dev/ofw/ofw_bus.h>
48 #include <dev/ofw/ofw_bus_subr.h>
49 
50 static struct ofw_compat_data compat_data[] = {
51 	{ "ti,sysc",	1 },
52 	{ NULL,				0 }
53 };
54 
55 struct ti_sysc_softc {
56 	struct simplebus_softc	sc;
57 	device_t		dev;
58 };
59 
60 static int ti_sysc_probe(device_t dev);
61 static int ti_sysc_attach(device_t dev);
62 static int ti_sysc_detach(device_t dev);
63 
64 static int
65 ti_sysc_probe(device_t dev)
66 {
67 	if (!ofw_bus_status_okay(dev))
68 		return (ENXIO);
69 
70 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
71 		return (ENXIO);
72 
73 	device_set_desc(dev, "TI SYSC Interconnect");
74 	if (!bootverbose)
75 		device_quiet(dev);
76 
77 	return (BUS_PROBE_DEFAULT);
78 }
79 
80 static int
81 ti_sysc_attach(device_t dev)
82 {
83 	struct ti_sysc_softc *sc;
84 	device_t cdev;
85 	phandle_t node, child;
86 
87 	sc = device_get_softc(dev);
88 	sc->dev = dev;
89 	node = ofw_bus_get_node(dev);
90 
91 	simplebus_init(dev, node);
92 	if (simplebus_fill_ranges(node, &sc->sc) < 0) {
93 		device_printf(dev, "could not get ranges\n");
94 		return (ENXIO);
95 	}
96 
97 	for (child = OF_child(node); child > 0; child = OF_peer(child)) {
98 		cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
99 		if (cdev != NULL)
100 			device_probe_and_attach(cdev);
101 	}
102 
103 	return (bus_generic_attach(dev));
104 }
105 
106 static int
107 ti_sysc_detach(device_t dev)
108 {
109 
110 	return (EBUSY);
111 }
112 
113 static device_method_t ti_sysc_methods[] = {
114 	/* Device interface */
115 	DEVMETHOD(device_probe,		ti_sysc_probe),
116 	DEVMETHOD(device_attach,	ti_sysc_attach),
117 	DEVMETHOD(device_detach,	ti_sysc_detach),
118 
119 	DEVMETHOD_END
120 };
121 
122 DEFINE_CLASS_1(ti_sysc, ti_sysc_driver, ti_sysc_methods,
123     sizeof(struct ti_sysc_softc), simplebus_driver);
124 
125 static devclass_t ti_sysc_devclass;
126 
127 EARLY_DRIVER_MODULE(ti_sysc, simplebus, ti_sysc_driver,
128 ti_sysc_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
129