The branch main has been updated by mhorne:

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

commit deaae83da0571af7c97acf8f1444a00350e21e3a
Author:     Mitchell Horne <mho...@freebsd.org>
AuthorDate: 2025-07-04 15:54:48 +0000
Commit:     Mitchell Horne <mho...@freebsd.org>
CommitDate: 2025-07-04 15:55:55 +0000

    riscv: enable allwinner RTC
    
    (Second attempt.)
    
    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.
    
    The driver also supports the older A10/A20 models, which don't export
    any clocks. Ensure this case is handled properly.
    
    Reviewed by:    mmel
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D50369
---
 sys/arm/allwinner/aw_rtc.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/sys/arm/allwinner/aw_rtc.c b/sys/arm/allwinner/aw_rtc.c
index 9938601f17ce..4af57ab879e8 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);
@@ -250,23 +253,33 @@ aw_rtc_install_clocks(struct aw_rtc_softc *sc, device_t 
dev) {
        int nclocks;
 
        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 != 3) {
-               device_printf(dev, "Having only %d clocks instead of 3, 
aborting\n", nclocks);
+       /* Nothing to do. */
+       if (!OF_hasprop(node, "clocks"))
                return;
+
+       /*
+        * If the device tree gives us specific output names for the clocks,
+        * use them.
+        */
+       nclocks = ofw_bus_string_list_to_array(node, "clock-output-names", 
&clknames);
+       if (nclocks > 0) {
+               if (nclocks != 3) {
+                       device_printf(dev,
+                           "Found %d clocks names 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");

Reply via email to