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