git: cf0876820717 - main - starfive: add a syscon driver

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Tue, 07 May 2024 16:04:28 UTC
The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=cf0876820717192b4900b56c027b01dad35bc837

commit cf0876820717192b4900b56c027b01dad35bc837
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2024-03-05 23:57:30 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2024-05-07 16:02:57 +0000

    starfive: add a syscon driver
    
    It serves the purpose of attaching syscon devices as early as possible;
    this is required for early attachment of the PLL clock driver.
    
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D44270
---
 sys/riscv/starfive/files.starfive    |  1 +
 sys/riscv/starfive/starfive_syscon.c | 87 ++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+)

diff --git a/sys/riscv/starfive/files.starfive b/sys/riscv/starfive/files.starfive
index e69de29bb2d1..48ca738936da 100644
--- a/sys/riscv/starfive/files.starfive
+++ b/sys/riscv/starfive/files.starfive
@@ -0,0 +1 @@
+riscv/starfive/starfive_syscon.c	standard
diff --git a/sys/riscv/starfive/starfive_syscon.c b/sys/riscv/starfive/starfive_syscon.c
new file mode 100644
index 000000000000..dfc8fa8ba5d9
--- /dev/null
+++ b/sys/riscv/starfive/starfive_syscon.c
@@ -0,0 +1,87 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * This software was developed by Mitchell Horne <mhorne@FreeBSD.org> under
+ * sponsorship from the FreeBSD Foundation.
+ */
+
+/*
+ * StarFive syscon driver.
+ *
+ * On the JH7110, the PLL clock driver is a child of the sys-syscon device.
+ * This needs to probe very early (BUS_PASS_BUS + BUS_PASS_ORDER_EARLY).
+ */
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+
+#include <machine/bus.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include <dev/syscon/syscon.h>
+#include <dev/syscon/syscon_generic.h>
+
+#include <dev/fdt/simple_mfd.h>
+
+enum starfive_syscon_type {
+	JH7110_SYSCON_SYS = 1,
+	JH7110_SYSCON_AON,
+	JH7110_SYSCON_STG,
+};
+
+static struct ofw_compat_data compat_data[] = {
+	{ "starfive,jh7110-sys-syscon",	JH7110_SYSCON_SYS },
+	{ "starfive,jh7110-aon-syscon",	JH7110_SYSCON_AON },
+	{ "starfive,jh7110-stg-syscon",	JH7110_SYSCON_STG },
+
+	{ NULL, 0 }
+};
+
+static int
+starfive_syscon_probe(device_t dev)
+{
+	enum starfive_syscon_type type;
+
+	if (!ofw_bus_status_okay(dev))
+		return (ENXIO);
+
+	type = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
+	if (type == 0)
+		return (ENXIO);
+
+	switch (type) {
+	case JH7110_SYSCON_SYS:
+		device_set_desc(dev, "JH7110 SYS syscon");
+		break;
+	case JH7110_SYSCON_AON:
+		device_set_desc(dev, "JH7110 AON syscon");
+		break;
+	case JH7110_SYSCON_STG:
+		device_set_desc(dev, "JH7110 STG syscon");
+		break;
+	}
+
+	return (BUS_PROBE_DEFAULT);
+}
+
+
+static device_method_t starfive_syscon_methods[] = {
+	DEVMETHOD(device_probe, starfive_syscon_probe),
+
+	DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(starfive_syscon, starfive_syscon_driver, starfive_syscon_methods,
+    sizeof(struct syscon_generic_softc), simple_mfd_driver);
+
+EARLY_DRIVER_MODULE(starfive_syscon, simplebus, starfive_syscon_driver, 0, 0,
+    BUS_PASS_BUS + BUS_PASS_ORDER_EARLY);
+MODULE_VERSION(starfive_syscon, 1);