1b2f0caf1SEmmanuel Vadot /*-
2b2f0caf1SEmmanuel Vadot * Copyright 2016 Michal Meloun <mmel@FreeBSD.org>
3b2f0caf1SEmmanuel Vadot * All rights reserved.
4b2f0caf1SEmmanuel Vadot *
5b2f0caf1SEmmanuel Vadot * Redistribution and use in source and binary forms, with or without
6b2f0caf1SEmmanuel Vadot * modification, are permitted provided that the following conditions
7b2f0caf1SEmmanuel Vadot * are met:
8b2f0caf1SEmmanuel Vadot * 1. Redistributions of source code must retain the above copyright
9b2f0caf1SEmmanuel Vadot * notice, this list of conditions and the following disclaimer.
10b2f0caf1SEmmanuel Vadot * 2. Redistributions in binary form must reproduce the above copyright
11b2f0caf1SEmmanuel Vadot * notice, this list of conditions and the following disclaimer in the
12b2f0caf1SEmmanuel Vadot * documentation and/or other materials provided with the distribution.
13b2f0caf1SEmmanuel Vadot *
14b2f0caf1SEmmanuel Vadot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15b2f0caf1SEmmanuel Vadot * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16b2f0caf1SEmmanuel Vadot * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17b2f0caf1SEmmanuel Vadot * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18b2f0caf1SEmmanuel Vadot * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19b2f0caf1SEmmanuel Vadot * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20b2f0caf1SEmmanuel Vadot * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21b2f0caf1SEmmanuel Vadot * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22b2f0caf1SEmmanuel Vadot * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23b2f0caf1SEmmanuel Vadot * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24b2f0caf1SEmmanuel Vadot * SUCH DAMAGE.
25b2f0caf1SEmmanuel Vadot */
26b2f0caf1SEmmanuel Vadot
27b2f0caf1SEmmanuel Vadot #include <sys/param.h>
28b2f0caf1SEmmanuel Vadot #include <sys/systm.h>
29b2f0caf1SEmmanuel Vadot #include <sys/kernel.h>
30b2f0caf1SEmmanuel Vadot #include <sys/module.h>
31b2f0caf1SEmmanuel Vadot #include <sys/bus.h>
32b2f0caf1SEmmanuel Vadot
33b2f0caf1SEmmanuel Vadot #include <dev/fdt/simplebus.h>
34b2f0caf1SEmmanuel Vadot
35b2f0caf1SEmmanuel Vadot #include <dev/ofw/openfirm.h>
36b2f0caf1SEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h>
37b2f0caf1SEmmanuel Vadot
38b2f0caf1SEmmanuel Vadot struct ofw_regulator_bus_softc {
39b2f0caf1SEmmanuel Vadot struct simplebus_softc simplebus_sc;
40b2f0caf1SEmmanuel Vadot };
41b2f0caf1SEmmanuel Vadot
42b2f0caf1SEmmanuel Vadot static int
ofw_regulator_bus_probe(device_t dev)43b2f0caf1SEmmanuel Vadot ofw_regulator_bus_probe(device_t dev)
44b2f0caf1SEmmanuel Vadot {
45b2f0caf1SEmmanuel Vadot const char *name;
46b2f0caf1SEmmanuel Vadot
47b2f0caf1SEmmanuel Vadot name = ofw_bus_get_name(dev);
48b2f0caf1SEmmanuel Vadot if (name == NULL || strcmp(name, "regulators") != 0)
49b2f0caf1SEmmanuel Vadot return (ENXIO);
50b2f0caf1SEmmanuel Vadot device_set_desc(dev, "OFW regulators bus");
51b2f0caf1SEmmanuel Vadot
52b2f0caf1SEmmanuel Vadot return (0);
53b2f0caf1SEmmanuel Vadot }
54b2f0caf1SEmmanuel Vadot
55b2f0caf1SEmmanuel Vadot static int
ofw_regulator_bus_attach(device_t dev)56b2f0caf1SEmmanuel Vadot ofw_regulator_bus_attach(device_t dev)
57b2f0caf1SEmmanuel Vadot {
58b2f0caf1SEmmanuel Vadot phandle_t node, child;
59b2f0caf1SEmmanuel Vadot
60b2f0caf1SEmmanuel Vadot node = ofw_bus_get_node(dev);
61b2f0caf1SEmmanuel Vadot simplebus_init(dev, node);
62b2f0caf1SEmmanuel Vadot
63b2f0caf1SEmmanuel Vadot for (child = OF_child(node); child > 0; child = OF_peer(child)) {
64b2f0caf1SEmmanuel Vadot simplebus_add_device(dev, child, 0, NULL, -1, NULL);
65b2f0caf1SEmmanuel Vadot }
66b2f0caf1SEmmanuel Vadot
67*18250ec6SJohn Baldwin bus_attach_children(dev);
68*18250ec6SJohn Baldwin return (0);
69b2f0caf1SEmmanuel Vadot }
70b2f0caf1SEmmanuel Vadot
71b2f0caf1SEmmanuel Vadot static device_method_t ofw_regulator_bus_methods[] = {
72b2f0caf1SEmmanuel Vadot /* Device interface */
73b2f0caf1SEmmanuel Vadot DEVMETHOD(device_probe, ofw_regulator_bus_probe),
74b2f0caf1SEmmanuel Vadot DEVMETHOD(device_attach, ofw_regulator_bus_attach),
75b2f0caf1SEmmanuel Vadot
76b2f0caf1SEmmanuel Vadot DEVMETHOD_END
77b2f0caf1SEmmanuel Vadot };
78b2f0caf1SEmmanuel Vadot
79b2f0caf1SEmmanuel Vadot DEFINE_CLASS_1(ofw_regulator_bus, ofw_regulator_bus_driver,
80b2f0caf1SEmmanuel Vadot ofw_regulator_bus_methods, sizeof(struct ofw_regulator_bus_softc),
81b2f0caf1SEmmanuel Vadot simplebus_driver);
82b2f0caf1SEmmanuel Vadot EARLY_DRIVER_MODULE(ofw_regulator_bus, simplebus, ofw_regulator_bus_driver,
83b2f0caf1SEmmanuel Vadot 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
84b2f0caf1SEmmanuel Vadot MODULE_VERSION(ofw_regulator_bus, 1);
85