10050ea24SMichal Meloun /*- 20050ea24SMichal Meloun * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 30050ea24SMichal Meloun * 40050ea24SMichal Meloun * Copyright (c) 2019 Emmanuel Vadot <manu@FreeBSD.org> 50050ea24SMichal Meloun * Copyright (c) 2020 Oskar Holmlund <oskar.holmlund@ohdata.se> 60050ea24SMichal Meloun * 70050ea24SMichal Meloun * Redistribution and use in source and binary forms, with or without 80050ea24SMichal Meloun * modification, are permitted provided that the following conditions 90050ea24SMichal Meloun * are met: 100050ea24SMichal Meloun * 1. Redistributions of source code must retain the above copyright 110050ea24SMichal Meloun * notice, this list of conditions and the following disclaimer. 120050ea24SMichal Meloun * 2. Redistributions in binary form must reproduce the above copyright 130050ea24SMichal Meloun * notice, this list of conditions and the following disclaimer in the 140050ea24SMichal Meloun * documentation and/or other materials provided with the distribution. 150050ea24SMichal Meloun * 160050ea24SMichal Meloun * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 170050ea24SMichal Meloun * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 180050ea24SMichal Meloun * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 190050ea24SMichal Meloun * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 200050ea24SMichal Meloun * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 210050ea24SMichal Meloun * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 220050ea24SMichal Meloun * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 230050ea24SMichal Meloun * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 240050ea24SMichal Meloun * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 250050ea24SMichal Meloun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 260050ea24SMichal Meloun * SUCH DAMAGE. 270050ea24SMichal Meloun * 280050ea24SMichal Meloun * Based on sys/arm/ti/ti_sysc.c 290050ea24SMichal Meloun * 300050ea24SMichal Meloun * $FreeBSD$ 310050ea24SMichal Meloun */ 320050ea24SMichal Meloun 330050ea24SMichal Meloun #include <sys/cdefs.h> 340050ea24SMichal Meloun __FBSDID("$FreeBSD$"); 350050ea24SMichal Meloun 360050ea24SMichal Meloun #include <sys/param.h> 370050ea24SMichal Meloun #include <sys/systm.h> 380050ea24SMichal Meloun #include <sys/bus.h> 390050ea24SMichal Meloun #include <sys/fbio.h> 400050ea24SMichal Meloun #include <sys/kernel.h> 410050ea24SMichal Meloun #include <sys/module.h> 420050ea24SMichal Meloun #include <sys/rman.h> 430050ea24SMichal Meloun #include <sys/resource.h> 440050ea24SMichal Meloun #include <machine/bus.h> 450050ea24SMichal Meloun #include <vm/vm.h> 460050ea24SMichal Meloun #include <vm/vm_extern.h> 470050ea24SMichal Meloun #include <vm/vm_kern.h> 480050ea24SMichal Meloun #include <vm/pmap.h> 490050ea24SMichal Meloun 500050ea24SMichal Meloun #include <dev/fdt/simplebus.h> 510050ea24SMichal Meloun 520050ea24SMichal Meloun #include <dev/ofw/ofw_bus.h> 530050ea24SMichal Meloun #include <dev/ofw/ofw_bus_subr.h> 540050ea24SMichal Meloun 550050ea24SMichal Meloun #include <arm/ti/ti_omap4_cm.h> 560050ea24SMichal Meloun 570050ea24SMichal Meloun static struct ofw_compat_data compat_data[] = { 580050ea24SMichal Meloun { "ti,omap4-cm", 1 }, 590050ea24SMichal Meloun { NULL, 0 } 600050ea24SMichal Meloun }; 610050ea24SMichal Meloun 620050ea24SMichal Meloun struct ti_omap4_cm_softc { 630050ea24SMichal Meloun struct simplebus_softc sc; 640050ea24SMichal Meloun device_t dev; 650050ea24SMichal Meloun }; 660050ea24SMichal Meloun 670050ea24SMichal Meloun uint64_t 680050ea24SMichal Meloun ti_omap4_cm_get_simplebus_base_host(device_t dev) { 690050ea24SMichal Meloun struct ti_omap4_cm_softc *sc; 700050ea24SMichal Meloun 710050ea24SMichal Meloun sc = device_get_softc(dev); 720050ea24SMichal Meloun if (sc->sc.nranges == 0) 730050ea24SMichal Meloun return (0); 740050ea24SMichal Meloun 750050ea24SMichal Meloun return (sc->sc.ranges[0].host); 760050ea24SMichal Meloun } 770050ea24SMichal Meloun 780050ea24SMichal Meloun static int ti_omap4_cm_probe(device_t dev); 790050ea24SMichal Meloun static int ti_omap4_cm_attach(device_t dev); 800050ea24SMichal Meloun static int ti_omap4_cm_detach(device_t dev); 810050ea24SMichal Meloun 820050ea24SMichal Meloun static int 830050ea24SMichal Meloun ti_omap4_cm_probe(device_t dev) 840050ea24SMichal Meloun { 850050ea24SMichal Meloun if (!ofw_bus_status_okay(dev)) 860050ea24SMichal Meloun return (ENXIO); 870050ea24SMichal Meloun 880050ea24SMichal Meloun if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) 890050ea24SMichal Meloun return (ENXIO); 900050ea24SMichal Meloun 910050ea24SMichal Meloun device_set_desc(dev, "TI OMAP4-CM"); 920050ea24SMichal Meloun if (!bootverbose) 930050ea24SMichal Meloun device_quiet(dev); 940050ea24SMichal Meloun 950050ea24SMichal Meloun return (BUS_PROBE_DEFAULT); 960050ea24SMichal Meloun } 970050ea24SMichal Meloun 980050ea24SMichal Meloun static int 990050ea24SMichal Meloun ti_omap4_cm_attach(device_t dev) 1000050ea24SMichal Meloun { 1010050ea24SMichal Meloun struct ti_omap4_cm_softc *sc; 1020050ea24SMichal Meloun device_t cdev; 1030050ea24SMichal Meloun phandle_t node, child; 1040050ea24SMichal Meloun 1050050ea24SMichal Meloun sc = device_get_softc(dev); 1060050ea24SMichal Meloun sc->dev = dev; 1070050ea24SMichal Meloun node = ofw_bus_get_node(dev); 1080050ea24SMichal Meloun 1090050ea24SMichal Meloun simplebus_init(dev, node); 1100050ea24SMichal Meloun if (simplebus_fill_ranges(node, &sc->sc) < 0) { 1110050ea24SMichal Meloun device_printf(dev, "could not get ranges\n"); 1120050ea24SMichal Meloun return (ENXIO); 1130050ea24SMichal Meloun } 1140050ea24SMichal Meloun 1150050ea24SMichal Meloun bus_generic_probe(sc->dev); 1160050ea24SMichal Meloun 1170050ea24SMichal Meloun for (child = OF_child(node); child > 0; child = OF_peer(child)) { 1180050ea24SMichal Meloun cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL); 1190050ea24SMichal Meloun if (cdev != NULL) 1200050ea24SMichal Meloun device_probe_and_attach(cdev); 1210050ea24SMichal Meloun } 1220050ea24SMichal Meloun 1230050ea24SMichal Meloun return (bus_generic_attach(dev)); 1240050ea24SMichal Meloun } 1250050ea24SMichal Meloun 1260050ea24SMichal Meloun static int 1270050ea24SMichal Meloun ti_omap4_cm_detach(device_t dev) 1280050ea24SMichal Meloun { 1290050ea24SMichal Meloun return (EBUSY); 1300050ea24SMichal Meloun } 1310050ea24SMichal Meloun 1320050ea24SMichal Meloun static device_method_t ti_omap4_cm_methods[] = { 1330050ea24SMichal Meloun /* Device interface */ 1340050ea24SMichal Meloun DEVMETHOD(device_probe, ti_omap4_cm_probe), 1350050ea24SMichal Meloun DEVMETHOD(device_attach, ti_omap4_cm_attach), 1360050ea24SMichal Meloun DEVMETHOD(device_detach, ti_omap4_cm_detach), 1370050ea24SMichal Meloun 1380050ea24SMichal Meloun DEVMETHOD_END 1390050ea24SMichal Meloun }; 1400050ea24SMichal Meloun 1410050ea24SMichal Meloun DEFINE_CLASS_1(ti_omap4_cm, ti_omap4_cm_driver, ti_omap4_cm_methods, 1420050ea24SMichal Meloun sizeof(struct ti_omap4_cm_softc), simplebus_driver); 1430050ea24SMichal Meloun 144*8537e671SJohn Baldwin EARLY_DRIVER_MODULE(ti_omap4_cm, simplebus, ti_omap4_cm_driver, 0, 0, 145*8537e671SJohn Baldwin BUS_PASS_BUS + BUS_PASS_ORDER_FIRST); 1460050ea24SMichal Meloun 147*8537e671SJohn Baldwin EARLY_DRIVER_MODULE(ti_omap4_cm, ofwbus, ti_omap4_cm_driver, 0, 0, 148*8537e671SJohn Baldwin BUS_PASS_BUS + BUS_PASS_ORDER_FIRST); 149