git: 9ddd516b8862 - main - riscv: enable allwinner RTC
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 16 Nov 2024 19:04:28 UTC
The branch main has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=9ddd516b886218af809dbf40eeda1ed388e2879c
commit 9ddd516b886218af809dbf40eeda1ed388e2879c
Author: Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2024-11-15 17:20:35 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2024-11-16 19:04:04 +0000
riscv: enable allwinner RTC
For the Allwinner D1 (Nehza) SBC.
This RTC driver is also a clock provider, which registers two fixed
clocks. In all the devices we currently support, the names of the clocks
are present in the "clock-output-names" property of the device tree.
This is not the case for the D1 DTS, as this property does not appear in
upstream. Therefore the clock definitions are statically assigned a
name, which is overridden when specified.
Reviewed by: manu
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47514
---
sys/arm/allwinner/aw_rtc.c | 24 ++++++++++++++++--------
sys/riscv/allwinner/files.allwinner | 1 +
sys/riscv/conf/std.allwinner | 1 +
3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/sys/arm/allwinner/aw_rtc.c b/sys/arm/allwinner/aw_rtc.c
index 9938601f17ce..a13c0e7d926e 100644
--- a/sys/arm/allwinner/aw_rtc.c
+++ b/sys/arm/allwinner/aw_rtc.c
@@ -134,6 +134,7 @@ static struct ofw_compat_data compat_data[] = {
{ "allwinner,sun7i-a20-rtc", (uintptr_t) &a20_conf },
{ "allwinner,sun6i-a31-rtc", (uintptr_t) &a31_conf },
{ "allwinner,sun8i-h3-rtc", (uintptr_t) &h3_conf },
+ { "allwinner,sun20i-d1-rtc", (uintptr_t) &h3_conf },
{ "allwinner,sun50i-h5-rtc", (uintptr_t) &h3_conf },
{ "allwinner,sun50i-h6-rtc", (uintptr_t) &h3_conf },
{ NULL, 0 }
@@ -147,11 +148,13 @@ struct aw_rtc_softc {
static struct clk_fixed_def aw_rtc_osc32k = {
.clkdef.id = 0,
+ .clkdef.name = "osc32k",
.freq = 32768,
};
static struct clk_fixed_def aw_rtc_iosc = {
.clkdef.id = 2,
+ .clkdef.name = "iosc",
};
static void aw_rtc_install_clocks(struct aw_rtc_softc *sc, device_t dev);
@@ -249,24 +252,29 @@ aw_rtc_install_clocks(struct aw_rtc_softc *sc, device_t dev) {
phandle_t node;
int nclocks;
+ /*
+ * If the device tree gives us specific output names for the clocks,
+ * use them.
+ */
node = ofw_bus_get_node(dev);
nclocks = ofw_bus_string_list_to_array(node, "clock-output-names", &clknames);
- /* No clocks to export */
- if (nclocks <= 0)
- return;
+ if (nclocks > 0) {
+ if (nclocks != 3) {
+ device_printf(dev,
+ "Found %d clocks instead of 3, aborting\n",
+ nclocks);
+ return;
+ }
- if (nclocks != 3) {
- device_printf(dev, "Having only %d clocks instead of 3, aborting\n", nclocks);
- return;
+ aw_rtc_osc32k.clkdef.name = clknames[0];
+ aw_rtc_iosc.clkdef.name = clknames[2];
}
clkdom = clkdom_create(dev);
- aw_rtc_osc32k.clkdef.name = clknames[0];
if (clknode_fixed_register(clkdom, &aw_rtc_osc32k) != 0)
device_printf(dev, "Cannot register osc32k clock\n");
- aw_rtc_iosc.clkdef.name = clknames[2];
aw_rtc_iosc.freq = sc->conf->iosc_freq;
if (clknode_fixed_register(clkdom, &aw_rtc_iosc) != 0)
device_printf(dev, "Cannot register iosc clock\n");
diff --git a/sys/riscv/allwinner/files.allwinner b/sys/riscv/allwinner/files.allwinner
index ee7ad9be1e70..e4849e53e339 100644
--- a/sys/riscv/allwinner/files.allwinner
+++ b/sys/riscv/allwinner/files.allwinner
@@ -1,2 +1,3 @@
+arm/allwinner/aw_rtc.c optional aw_rtc fdt
arm/allwinner/aw_wdog.c optional aw_wdog
diff --git a/sys/riscv/conf/std.allwinner b/sys/riscv/conf/std.allwinner
index a781164d0632..2071d15c3b24 100644
--- a/sys/riscv/conf/std.allwinner
+++ b/sys/riscv/conf/std.allwinner
@@ -2,6 +2,7 @@
# Allwinner SoC support
#
+device aw_rtc # Allwinner Real-time Clock
device aw_wdog # Allwinner Watchdog
files "../allwinner/files.allwinner"