1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2019 Emmanuel Vadot <manu@FreeBSD.org> 5 * Copyright (c) 2020 Oskar Holmlund <oskar.holmlund@ohdata.se> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. 15 * 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 26 * SUCH DAMAGE. 27 * 28 * Based on sys/arm/ti/ti_sysc.c 29 */ 30 31 #include <sys/cdefs.h> 32 __FBSDID("$FreeBSD$"); 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/bus.h> 37 #include <sys/fbio.h> 38 #include <sys/kernel.h> 39 #include <sys/module.h> 40 #include <sys/rman.h> 41 #include <sys/resource.h> 42 #include <machine/bus.h> 43 #include <vm/vm.h> 44 #include <vm/vm_extern.h> 45 #include <vm/vm_kern.h> 46 #include <vm/pmap.h> 47 48 #include <dev/fdt/simplebus.h> 49 50 #include <dev/ofw/ofw_bus.h> 51 #include <dev/ofw/ofw_bus_subr.h> 52 53 #include <arm/ti/ti_omap4_cm.h> 54 55 static struct ofw_compat_data compat_data[] = { 56 { "ti,omap4-cm", 1 }, 57 { NULL, 0 } 58 }; 59 60 struct ti_omap4_cm_softc { 61 struct simplebus_softc sc; 62 device_t dev; 63 }; 64 65 uint64_t 66 ti_omap4_cm_get_simplebus_base_host(device_t dev) { 67 struct ti_omap4_cm_softc *sc; 68 69 sc = device_get_softc(dev); 70 if (sc->sc.nranges == 0) 71 return (0); 72 73 return (sc->sc.ranges[0].host); 74 } 75 76 static int ti_omap4_cm_probe(device_t dev); 77 static int ti_omap4_cm_attach(device_t dev); 78 static int ti_omap4_cm_detach(device_t dev); 79 80 static int 81 ti_omap4_cm_probe(device_t dev) 82 { 83 if (!ofw_bus_status_okay(dev)) 84 return (ENXIO); 85 86 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) 87 return (ENXIO); 88 89 device_set_desc(dev, "TI OMAP4-CM"); 90 if (!bootverbose) 91 device_quiet(dev); 92 93 return (BUS_PROBE_DEFAULT); 94 } 95 96 static int 97 ti_omap4_cm_attach(device_t dev) 98 { 99 struct ti_omap4_cm_softc *sc; 100 device_t cdev; 101 phandle_t node, child; 102 103 sc = device_get_softc(dev); 104 sc->dev = dev; 105 node = ofw_bus_get_node(dev); 106 107 simplebus_init(dev, node); 108 if (simplebus_fill_ranges(node, &sc->sc) < 0) { 109 device_printf(dev, "could not get ranges\n"); 110 return (ENXIO); 111 } 112 113 bus_generic_probe(sc->dev); 114 115 for (child = OF_child(node); child > 0; child = OF_peer(child)) { 116 cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL); 117 if (cdev != NULL) 118 device_probe_and_attach(cdev); 119 } 120 121 return (bus_generic_attach(dev)); 122 } 123 124 static int 125 ti_omap4_cm_detach(device_t dev) 126 { 127 return (EBUSY); 128 } 129 130 static device_method_t ti_omap4_cm_methods[] = { 131 /* Device interface */ 132 DEVMETHOD(device_probe, ti_omap4_cm_probe), 133 DEVMETHOD(device_attach, ti_omap4_cm_attach), 134 DEVMETHOD(device_detach, ti_omap4_cm_detach), 135 136 DEVMETHOD_END 137 }; 138 139 DEFINE_CLASS_1(ti_omap4_cm, ti_omap4_cm_driver, ti_omap4_cm_methods, 140 sizeof(struct ti_omap4_cm_softc), simplebus_driver); 141 142 EARLY_DRIVER_MODULE(ti_omap4_cm, simplebus, ti_omap4_cm_driver, 0, 0, 143 BUS_PASS_BUS + BUS_PASS_ORDER_FIRST); 144 145 EARLY_DRIVER_MODULE(ti_omap4_cm, ofwbus, ti_omap4_cm_driver, 0, 0, 146 BUS_PASS_BUS + BUS_PASS_ORDER_FIRST); 147