2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2019 Emmanuel Vadot <manu@FreeBSD.org>
5 * Copyright (c) 2020 Oskar Holmlund <oskar.holmlund@ohdata.se>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Based on sys/arm/ti/ti_sysc.c
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
43 #include <sys/resource.h>
44 #include <machine/bus.h>
46 #include <vm/vm_extern.h>
47 #include <vm/vm_kern.h>
50 #include <dev/fdt/simplebus.h>
52 #include <dev/ofw/ofw_bus.h>
53 #include <dev/ofw/ofw_bus_subr.h>
55 #include <arm/ti/ti_omap4_cm.h>
57 static struct ofw_compat_data compat_data[] = {
62 struct ti_omap4_cm_softc {
63 struct simplebus_softc sc;
68 ti_omap4_cm_get_simplebus_base_host(device_t dev) {
69 struct ti_omap4_cm_softc *sc;
71 sc = device_get_softc(dev);
72 if (sc->sc.nranges == 0)
75 return (sc->sc.ranges[0].host);
78 static int ti_omap4_cm_probe(device_t dev);
79 static int ti_omap4_cm_attach(device_t dev);
80 static int ti_omap4_cm_detach(device_t dev);
83 ti_omap4_cm_probe(device_t dev)
85 if (!ofw_bus_status_okay(dev))
88 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
91 device_set_desc(dev, "TI OMAP4-CM");
95 return (BUS_PROBE_DEFAULT);
99 ti_omap4_cm_attach(device_t dev)
101 struct ti_omap4_cm_softc *sc;
103 phandle_t node, child;
105 sc = device_get_softc(dev);
107 node = ofw_bus_get_node(dev);
109 simplebus_init(dev, node);
110 if (simplebus_fill_ranges(node, &sc->sc) < 0) {
111 device_printf(dev, "could not get ranges\n");
115 bus_generic_probe(sc->dev);
117 for (child = OF_child(node); child > 0; child = OF_peer(child)) {
118 cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
120 device_probe_and_attach(cdev);
123 return (bus_generic_attach(dev));
127 ti_omap4_cm_detach(device_t dev)
132 static device_method_t ti_omap4_cm_methods[] = {
133 /* Device interface */
134 DEVMETHOD(device_probe, ti_omap4_cm_probe),
135 DEVMETHOD(device_attach, ti_omap4_cm_attach),
136 DEVMETHOD(device_detach, ti_omap4_cm_detach),
141 DEFINE_CLASS_1(ti_omap4_cm, ti_omap4_cm_driver, ti_omap4_cm_methods,
142 sizeof(struct ti_omap4_cm_softc), simplebus_driver);
144 EARLY_DRIVER_MODULE(ti_omap4_cm, simplebus, ti_omap4_cm_driver, 0, 0,
145 BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
147 EARLY_DRIVER_MODULE(ti_omap4_cm, ofwbus, ti_omap4_cm_driver, 0, 0,
148 BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);