]> www.infradead.org Git - users/hch/misc.git/commitdiff
clk: spacemit: introduce pre-div for ddn clock
authorTroy Mitchell <troy.mitchell@linux.spacemit.com>
Thu, 11 Sep 2025 03:34:04 +0000 (11:34 +0800)
committerStephen Boyd <sboyd@kernel.org>
Sat, 20 Sep 2025 05:54:44 +0000 (22:54 -0700)
The original DDN operations applied an implicit divide-by-2, which should
not be a default behavior.

This patch removes that assumption, letting each clock define its
actual behavior explicitly.

Reviewed-by: Haylen Chu <heylenay@4d2.org>
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/spacemit/ccu-k1.c
drivers/clk/spacemit/ccu_ddn.c
drivers/clk/spacemit/ccu_ddn.h

index 62cdba516a29f960e15e04642470f55e3d85bfad..14a88d0372dde922a451b337897147e02a1db5aa 100644 (file)
@@ -136,8 +136,8 @@ CCU_GATE_DEFINE(pll1_d3_819p2, CCU_PARENT_HW(pll1_d3), MPMU_ACGR, BIT(14), 0);
 CCU_GATE_DEFINE(pll1_d2_1228p8, CCU_PARENT_HW(pll1_d2), MPMU_ACGR, BIT(16), 0);
 
 CCU_GATE_DEFINE(slow_uart, CCU_PARENT_NAME(osc), MPMU_ACGR, BIT(1), CLK_IGNORE_UNUSED);
-CCU_DDN_DEFINE(slow_uart1_14p74, pll1_d16_153p6, MPMU_SUCCR, 16, 13, 0, 13, 0);
-CCU_DDN_DEFINE(slow_uart2_48, pll1_d4_614p4, MPMU_SUCCR_1, 16, 13, 0, 13, 0);
+CCU_DDN_DEFINE(slow_uart1_14p74, pll1_d16_153p6, MPMU_SUCCR, 16, 13, 0, 13, 2, 0);
+CCU_DDN_DEFINE(slow_uart2_48, pll1_d4_614p4, MPMU_SUCCR_1, 16, 13, 0, 13, 2, 0);
 
 CCU_GATE_DEFINE(wdt_clk, CCU_PARENT_HW(pll1_d96_25p6), MPMU_WDTPCR, BIT(1), 0);
 
index 02b68ea84db9bd3ecdde41f8013c48263edbd917..5b16e273bee5b1085626f4aea4e41235874a16c0 100644 (file)
 
 #include "ccu_ddn.h"
 
-static unsigned long ccu_ddn_calc_rate(unsigned long prate,
-                                      unsigned long num, unsigned long den)
+static unsigned long ccu_ddn_calc_rate(unsigned long prate, unsigned long num,
+                                      unsigned long den, unsigned int pre_div)
 {
-       return prate * den / 2 / num;
+       return prate * den / pre_div / num;
 }
 
 static unsigned long ccu_ddn_calc_best_rate(struct ccu_ddn *ddn,
                                            unsigned long rate, unsigned long prate,
                                            unsigned long *num, unsigned long *den)
 {
-       rational_best_approximation(rate, prate / 2,
+       rational_best_approximation(rate, prate / ddn->pre_div,
                                    ddn->den_mask >> ddn->den_shift,
                                    ddn->num_mask >> ddn->num_shift,
                                    den, num);
-       return ccu_ddn_calc_rate(prate, *num, *den);
+       return ccu_ddn_calc_rate(prate, *num, *den, ddn->pre_div);
 }
 
 static int ccu_ddn_determine_rate(struct clk_hw *hw,
@@ -61,7 +61,7 @@ static unsigned long ccu_ddn_recalc_rate(struct clk_hw *hw, unsigned long prate)
        num = (val & ddn->num_mask) >> ddn->num_shift;
        den = (val & ddn->den_mask) >> ddn->den_shift;
 
-       return ccu_ddn_calc_rate(prate, num, den);
+       return ccu_ddn_calc_rate(prate, num, den, ddn->pre_div);
 }
 
 static int ccu_ddn_set_rate(struct clk_hw *hw, unsigned long rate,
index a52fabe77d62eba16426867a9c13481e72f025c0..4838414a8e8dc04af49d3b8d39280efedbd75616 100644 (file)
@@ -18,13 +18,14 @@ struct ccu_ddn {
        unsigned int num_shift;
        unsigned int den_mask;
        unsigned int den_shift;
+       unsigned int pre_div;
 };
 
 #define CCU_DDN_INIT(_name, _parent, _flags) \
        CLK_HW_INIT_HW(#_name, &_parent.common.hw, &spacemit_ccu_ddn_ops, _flags)
 
 #define CCU_DDN_DEFINE(_name, _parent, _reg_ctrl, _num_shift, _num_width,      \
-                      _den_shift, _den_width, _flags)                          \
+                      _den_shift, _den_width, _pre_div, _flags)                \
 static struct ccu_ddn _name = {                                                        \
        .common = {                                                             \
                .reg_ctrl       = _reg_ctrl,                                    \
@@ -33,7 +34,8 @@ static struct ccu_ddn _name = {                                                       \
        .num_mask       = GENMASK(_num_shift + _num_width - 1, _num_shift),     \
        .num_shift      = _num_shift,                                           \
        .den_mask       = GENMASK(_den_shift + _den_width - 1, _den_shift),     \
-       .den_shift      = _den_shift,                                   \
+       .den_shift      = _den_shift,                                           \
+       .pre_div        = _pre_div,                                             \
 }
 
 static inline struct ccu_ddn *hw_to_ccu_ddn(struct clk_hw *hw)