Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F148826780
D31311.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D31311.diff
View Options
diff --git a/sys/conf/files b/sys/conf/files
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1770,6 +1770,7 @@
dev/fdt/fdt_static_dtb.S optional fdt fdt_dtb_static \
dependency "${FDT_DTS_FILE:T:R}.dtb"
dev/fdt/simplebus.c optional fdt
+dev/fdt/simplepmbus.c optional fdt
dev/fdt/simple_mfd.c optional syscon fdt
dev/filemon/filemon.c optional filemon
dev/firewire/firewire.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,140 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2021 Oskar Holmlund <oskar.holmlund@ohdata.se>
+ *
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/rman.h>
+
+#include <dev/extres/clk/clk.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include <dev/fdt/simplebus.h>
+
+
+struct simple_pm_bus_softc {
+ struct simplebus_softc simplebus;
+ device_t dev;
+ clk_t clk_fck;
+};
+
+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 void
+simple_pm_bus_delayed_attach(void *xsc)
+{
+ int err;
+ struct simple_pm_bus_softc *sc;
+
+ sc = (struct simple_pm_bus_softc *)xsc;
+
+ /* Enable the clock */
+ err = clk_enable(sc->clk_fck);
+ if (err != 0)
+ device_printf(sc->dev, "Failed to enable clk\n");
+}
+
+static int
+simple_pm_bus_attach(device_t dev)
+{
+ struct simple_pm_bus_softc *sc;
+ sc = device_get_softc(dev);
+ sc->dev = dev;
+
+ if (ofw_bus_has_prop(dev, "power-domains"))
+ device_printf(dev,
+ "Note power-domains are currently unsupported\n");
+
+ if (ofw_bus_has_prop(dev, "clock")) {
+ /* expect one clock */
+ int err;
+ err = clk_get_by_ofw_index(dev, 0, 0, &sc->clk_fck);
+ if (err != 0) {
+ device_printf(dev, "Cant find clock (err %d)\n",
+ err);
+ return (ENXIO);
+ }
+ config_intrhook_oneshot(simple_pm_bus_delayed_attach, sc);
+ }
+
+ return (simplebus_attach(dev));
+}
+
+static int
+simple_pm_bus_detach(device_t dev)
+{
+ return (simplebus_detach(dev));
+}
+
+static device_method_t simple_pm_bus_methods[] = {
+ DEVMETHOD(device_probe, simple_pm_bus_probe),
+ DEVMETHOD(device_attach, simple_pm_bus_attach),
+ DEVMETHOD(device_detach, simple_pm_bus_detach),
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(simple_pm_bus, simple_pm_bus_driver, simple_pm_bus_methods,
+ sizeof(struct simple_pm_bus_softc), simplebus_driver);
+
+static devclass_t simple_pm_bus_devclass;
+EARLY_DRIVER_MODULE(simple_pm_bus, simplebus, simple_pm_bus_driver,
+ simple_pm_bus_devclass, 0, 0,
+ BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
+
+MODULE_VERSION(simple_pm_bus, 1);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 21, 10:15 AM (3 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30049571
Default Alt Text
D31311.diff (4 KB)
Attached To
Mode
D31311: simple-pm-bus driver
Attached
Detach File
Event Timeline
Log In to Comment