]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
rtc: goldfish: Support platform data for non-DT probing
authorKuan-Wei Chiu <visitorckw@gmail.com>
Wed, 7 Jan 2026 20:18:32 +0000 (20:18 +0000)
committerTom Rini <trini@konsulko.com>
Mon, 2 Feb 2026 20:24:40 +0000 (14:24 -0600)
Currently, the Goldfish RTC driver exclusively relies on device tree
to retrieve the base address, failing immediately if dev_read_addr()
returns FDT_ADDR_T_NONE. This restriction prevents the driver from
being used on platforms that instantiate devices via U_BOOT_DRVINFO()
instead of device tree, such as the QEMU m68k virt machine.

Add support for platform data to address this limitation. Introduce a
new .of_to_plat hook to handle device tree parsing and populate the
platform data. Update the probe function to rely exclusively on this
platform data, enabling support for both Device Tree and manual
instantiation.

Introduce a new header file include/goldfish_rtc.h to define the
platform data structure.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
drivers/rtc/goldfish_rtc.c
include/goldfish_rtc.h [new file with mode: 0644]

index e63a2766c7603cb99531cc44ffbea5e1b49d8837..d2991ca67192faf30c0d601c8172157212a5c06c 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <div64.h>
 #include <dm.h>
+#include <goldfish_rtc.h>
 #include <mapmem.h>
 #include <rtc.h>
 #include <linux/io.h>
@@ -74,15 +75,27 @@ static int goldfish_rtc_set(struct udevice *dev, const struct rtc_time *time)
        return 0;
 }
 
-static int goldfish_rtc_probe(struct udevice *dev)
+static int goldfish_rtc_of_to_plat(struct udevice *dev)
 {
-       struct goldfish_rtc *priv = dev_get_priv(dev);
+       struct goldfish_rtc_plat *plat = dev_get_plat(dev);
        fdt_addr_t addr;
 
        addr = dev_read_addr(dev);
-       if (addr == FDT_ADDR_T_NONE)
+       if (addr != FDT_ADDR_T_NONE)
+               plat->reg = addr;
+
+       return 0;
+}
+
+static int goldfish_rtc_probe(struct udevice *dev)
+{
+       struct goldfish_rtc_plat *plat = dev_get_plat(dev);
+       struct goldfish_rtc *priv = dev_get_priv(dev);
+
+       if (!plat->reg)
                return -EINVAL;
-       priv->base = map_sysmem(addr, 0x20);
+
+       priv->base = map_sysmem(plat->reg, 0x20);
 
        return 0;
 }
@@ -103,5 +116,7 @@ U_BOOT_DRIVER(rtc_goldfish) = {
        .ops            = &goldfish_rtc_ops,
        .probe          = goldfish_rtc_probe,
        .of_match       = goldfish_rtc_of_match,
+       .of_to_plat = goldfish_rtc_of_to_plat,
+       .plat_auto  = sizeof(struct goldfish_rtc_plat),
        .priv_auto      = sizeof(struct goldfish_rtc),
 };
diff --git a/include/goldfish_rtc.h b/include/goldfish_rtc.h
new file mode 100644 (file)
index 0000000..f0e6ba3
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2025, Kuan-Wei Chiu <visitorckw@gmail.com>
+ */
+
+#ifndef _GOLDFISH_RTC_H_
+#define _GOLDFISH_RTC_H_
+
+#include <linux/types.h>
+
+struct goldfish_rtc_plat {
+       phys_addr_t reg;
+};
+
+#endif /* _GOLDFISH_RTC_H_ */