/*-1* Copyright 2016 Michal Meloun <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include <sys/param.h>27#include <sys/systm.h>28#include <sys/kernel.h>29#include <sys/module.h>30#include <sys/bus.h>3132#include <dev/fdt/simplebus.h>3334#include <dev/ofw/openfirm.h>35#include <dev/ofw/ofw_bus_subr.h>3637struct ofw_clkbus_softc {38struct simplebus_softc simplebus_sc;39};4041static int42ofw_clkbus_probe(device_t dev)43{44const char *name;4546name = ofw_bus_get_name(dev);4748if (name == NULL || strcmp(name, "clocks") != 0)49return (ENXIO);5051device_set_desc(dev, "OFW clocks bus");5253return (BUS_PROBE_GENERIC);54}5556static int57ofw_clkbus_attach(device_t dev)58{59phandle_t node, child;60device_t cdev;6162node = ofw_bus_get_node(dev);63simplebus_init(dev, node);6465for (child = OF_child(node); child > 0; child = OF_peer(child)) {66cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);67if (cdev != NULL)68device_probe_and_attach(cdev);69}7071bus_attach_children(dev);72return (0);73}7475static device_method_t ofw_clkbus_methods[] = {76/* Device interface */77DEVMETHOD(device_probe, ofw_clkbus_probe),78DEVMETHOD(device_attach, ofw_clkbus_attach),7980DEVMETHOD_END81};8283DEFINE_CLASS_1(ofw_clkbus, ofw_clkbus_driver, ofw_clkbus_methods,84sizeof(struct ofw_clkbus_softc), simplebus_driver);85EARLY_DRIVER_MODULE(ofw_clkbus, simplebus, ofw_clkbus_driver, 0, 0,86BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);87MODULE_VERSION(ofw_clkbus, 1);888990