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