]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
clk: thead: th1520-ap: Correctly handle flags for dividers
authorYao Zi <ziyao@disroot.org>
Thu, 10 Jul 2025 03:41:57 +0000 (03:41 +0000)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Thu, 17 Jul 2025 06:37:40 +0000 (14:37 +0800)
Unlike the gate clocks which make no use of flags, most dividers in
TH1520 SoC are one-based, thus are applied with CLK_DIVIDER_ONE_BASED
flag. We couldn't simply ignore the flag, which causes wrong results
when calculating the clock rates.

Add a member to ccu_div_internal for defining the flags, and pass it to
divider_recalc_rate(). With this fix, frequency of all the clocks match
the Linux kernel's calculation.

Fixes: e6bfa6fc94f ("clk: thead: Port clock controller driver of TH1520 SoC")
Signed-off-by: Yao Zi <ziyao@disroot.org>
Acked-by: Leo Yu-Chi Liang <ycliang@andestech.com>
drivers/clk/thead/clk-th1520-ap.c

index b80ad05b8adf618def2f63e5203ff2abb13a7d16..822cf0809d57748d7712ce4eda221f0787194906 100644 (file)
@@ -32,6 +32,7 @@ struct ccu_internal {
 struct ccu_div_internal {
        u8 shift;
        u8 width;
+       unsigned long flags;
 };
 
 struct ccu_common {
@@ -79,6 +80,7 @@ struct ccu_pll {
        {                                                               \
                .shift  = _shift,                                       \
                .width  = _width,                                       \
+               .flags  = _flags,                                       \
        }
 
 #define CCU_GATE(_clkid, _struct, _name, _parent, _reg, _gate, _flags) \
@@ -182,7 +184,7 @@ static unsigned long ccu_div_get_rate(struct clk *clk)
        val = val >> cd->div.shift;
        val &= GENMASK(cd->div.width - 1, 0);
        rate = divider_recalc_rate(clk, clk_get_parent_rate(clk), val, NULL,
-                                  0, cd->div.width);
+                                  cd->div.flags, cd->div.width);
 
        return rate;
 }