diff --git a/sys/conf/files b/sys/conf/files --- a/sys/conf/files +++ b/sys/conf/files @@ -1709,6 +1709,7 @@ dependency "${FDT_DTS_FILE:T:R}.dtb" dev/fdt/simplebus.c optional fdt dev/fdt/simple_mfd.c optional syscon fdt +dev/fdt/simplepmbus.c optional clk fdt dev/filemon/filemon.c optional filemon dev/firewire/firewire.c optional firewire dev/firewire/fwcrom.c optional firewire diff --git a/sys/dev/fdt/simplepmbus.c b/sys/dev/fdt/simplepmbus.c new file mode 100644 --- /dev/null +++ b/sys/dev/fdt/simplepmbus.c @@ -0,0 +1,83 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Oskar Holmlund + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* + * Bindings + * sys/contrib/device-tree/Bindings/bus/simple-pm-bus.yaml + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +static int +simple_pm_bus_probe(device_t dev) +{ + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + /* + * for now: require "ranges" + * later require "clock" or "power-domains" aswell. + */ + if (!(ofw_bus_is_compatible(dev, "simple-pm-bus") && + ofw_bus_has_prop(dev, "ranges"))) + { + return (ENXIO); + } + + device_set_desc(dev, "Simple Power-Managed Bus"); + + return (BUS_PROBE_GENERIC); +} + +static device_method_t simple_pm_bus_methods[] = { + DEVMETHOD(device_probe, simple_pm_bus_probe), + DEVMETHOD(device_attach, simplebus_attach), + DEVMETHOD(device_detach, simplebus_detach), + DEVMETHOD_END +}; + +DEFINE_CLASS_1(simple_pm_bus, simple_pm_bus_driver, simple_pm_bus_methods, + sizeof(struct simplebus_softc), simplebus_driver); + +EARLY_DRIVER_MODULE(simple_pm_bus, simplebus, simple_pm_bus_driver, 0, 0, + BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); + +MODULE_VERSION(simple_pm_bus, 1);