xref: /freebsd/sys/arm/ti/ti_sysc.c (revision ddc0daea20280c3a06a910b72b14ffe3f624df71)
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 	return (BUS_PROBE_DEFAULT);
75 }
76 
77 static int
78 ti_sysc_attach(device_t dev)
79 {
80 	struct ti_sysc_softc *sc;
81 	device_t cdev;
82 	phandle_t node, child;
83 
84 	sc = device_get_softc(dev);
85 	sc->dev = dev;
86 	node = ofw_bus_get_node(dev);
87 
88 	simplebus_init(dev, node);
89 	if (simplebus_fill_ranges(node, &sc->sc) < 0) {
90 		device_printf(dev, "could not get ranges\n");
91 		return (ENXIO);
92 	}
93 
94 	for (child = OF_child(node); child > 0; child = OF_peer(child)) {
95 		cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
96 		if (cdev != NULL)
97 			device_probe_and_attach(cdev);
98 	}
99 
100 	return (bus_generic_attach(dev));
101 }
102 
103 static int
104 ti_sysc_detach(device_t dev)
105 {
106 
107 	return (EBUSY);
108 }
109 
110 static device_method_t ti_sysc_methods[] = {
111 	/* Device interface */
112 	DEVMETHOD(device_probe,		ti_sysc_probe),
113 	DEVMETHOD(device_attach,	ti_sysc_attach),
114 	DEVMETHOD(device_detach,	ti_sysc_detach),
115 
116 	DEVMETHOD_END
117 };
118 
119 DEFINE_CLASS_1(ti_sysc, ti_sysc_driver, ti_sysc_methods,
120     sizeof(struct ti_sysc_softc), simplebus_driver);
121 
122 static devclass_t ti_sysc_devclass;
123 
124 EARLY_DRIVER_MODULE(ti_sysc, simplebus, ti_sysc_driver,
125 ti_sysc_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
126