]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
serial: ns16550: Try get serial clock rate from DT before CLK
authorJonas Karlman <jonas@kwiboo.se>
Sun, 4 Aug 2024 15:09:52 +0000 (15:09 +0000)
committerTom Rini <trini@konsulko.com>
Mon, 7 Oct 2024 21:10:05 +0000 (15:10 -0600)
Initializing a clock driver to read a known static clock rate can take
some time at U-Boot proper pre-reloc phase.

Change to first try and read clock rate from DT to speed up boot time,
fall back to getting the clock rate from clock driver.

This help reduce boot time by around:
- ~35ms on a Radxa ROCK Pi 4 (RK3399)
- ~15ms on a Radxa ZERO 3W (RK3566)
Time that is wasted getting a static rate known at compile time.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/serial/ns16550.c

index 6fcb5b523acbf8e924b951625d1479d0454c266b..07f9ac00e113072522992054aaaf05829e6d52cb 100644 (file)
@@ -565,19 +565,19 @@ int ns16550_serial_of_to_plat(struct udevice *dev)
        plat->reg_shift = dev_read_u32_default(dev, "reg-shift", 0);
        plat->reg_width = dev_read_u32_default(dev, "reg-io-width", 1);
 
-       err = clk_get_by_index(dev, 0, &clk);
-       if (!err) {
-               err = clk_get_rate(&clk);
-               if (!IS_ERR_VALUE(err))
-                       plat->clock = err;
-       } else if (err != -ENOENT && err != -ENODEV && err != -ENOSYS) {
-               debug("ns16550 failed to get clock\n");
-               return err;
-       }
-
        if (!plat->clock)
-               plat->clock = dev_read_u32_default(dev, "clock-frequency",
-                                                  CFG_SYS_NS16550_CLK);
+               plat->clock = dev_read_u32_default(dev, "clock-frequency", 0);
+       if (!plat->clock) {
+               err = clk_get_by_index(dev, 0, &clk);
+               if (!err) {
+                       err = clk_get_rate(&clk);
+                       if (!IS_ERR_VALUE(err))
+                               plat->clock = err;
+               } else if (err != -ENOENT && err != -ENODEV && err != -ENOSYS) {
+                       debug("ns16550 failed to get clock\n");
+                       return err;
+               }
+       }
        if (!plat->clock)
                plat->clock = CFG_SYS_NS16550_CLK;
        if (!plat->clock) {