1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 31 */ 32 33 #include <sys/cdefs.h> 34 __FBSDID("$FreeBSD$"); 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 #include <arm/ti/ti_omap4_cm.h> 56 57 static struct ofw_compat_data compat_data[] = { 58 { "ti,omap4-cm", 1 }, 59 { NULL, 0 } 60 }; 61 62 struct ti_omap4_cm_softc { 63 struct simplebus_softc sc; 64 device_t dev; 65 }; 66 67 uint64_t 68 ti_omap4_cm_get_simplebus_base_host(device_t dev) { 69 struct ti_omap4_cm_softc *sc; 70 71 sc = device_get_softc(dev); 72 if (sc->sc.nranges == 0) 73 return (0); 74 75 return (sc->sc.ranges[0].host); 76 } 77 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); 81 82 static int 83 ti_omap4_cm_probe(device_t dev) 84 { 85 if (!ofw_bus_status_okay(dev)) 86 return (ENXIO); 87 88 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) 89 return (ENXIO); 90 91 device_set_desc(dev, "TI OMAP4-CM"); 92 if (!bootverbose) 93 device_quiet(dev); 94 95 return (BUS_PROBE_DEFAULT); 96 } 97 98 static int 99 ti_omap4_cm_attach(device_t dev) 100 { 101 struct ti_omap4_cm_softc *sc; 102 device_t cdev; 103 phandle_t node, child; 104 105 sc = device_get_softc(dev); 106 sc->dev = dev; 107 node = ofw_bus_get_node(dev); 108 109 simplebus_init(dev, node); 110 if (simplebus_fill_ranges(node, &sc->sc) < 0) { 111 device_printf(dev, "could not get ranges\n"); 112 return (ENXIO); 113 } 114 115 bus_generic_probe(sc->dev); 116 117 for (child = OF_child(node); child > 0; child = OF_peer(child)) { 118 cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL); 119 if (cdev != NULL) 120 device_probe_and_attach(cdev); 121 } 122 123 return (bus_generic_attach(dev)); 124 } 125 126 static int 127 ti_omap4_cm_detach(device_t dev) 128 { 129 return (EBUSY); 130 } 131 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), 137 138 DEVMETHOD_END 139 }; 140 141 DEFINE_CLASS_1(ti_omap4_cm, ti_omap4_cm_driver, ti_omap4_cm_methods, 142 sizeof(struct ti_omap4_cm_softc), simplebus_driver); 143 144 static devclass_t ti_omap4_cm_devclass; 145 146 EARLY_DRIVER_MODULE(ti_omap4_cm, simplebus, ti_omap4_cm_driver, 147 ti_omap4_cm_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_FIRST); 148 149 EARLY_DRIVER_MODULE(ti_omap4_cm, ofwbus, ti_omap4_cm_driver, 150 ti_omap4_cm_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_FIRST); 151 152