Skip to content

Commit 74246a8

Browse files
TroyMitchell911bebarino
authored andcommitted
clk: spacemit: introduce pre-div for ddn clock
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>
1 parent 8be1f29 commit 74246a8

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

drivers/clk/spacemit/ccu-k1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ CCU_GATE_DEFINE(pll1_d3_819p2, CCU_PARENT_HW(pll1_d3), MPMU_ACGR, BIT(14), 0);
136136
CCU_GATE_DEFINE(pll1_d2_1228p8, CCU_PARENT_HW(pll1_d2), MPMU_ACGR, BIT(16), 0);
137137

138138
CCU_GATE_DEFINE(slow_uart, CCU_PARENT_NAME(osc), MPMU_ACGR, BIT(1), CLK_IGNORE_UNUSED);
139-
CCU_DDN_DEFINE(slow_uart1_14p74, pll1_d16_153p6, MPMU_SUCCR, 16, 13, 0, 13, 0);
140-
CCU_DDN_DEFINE(slow_uart2_48, pll1_d4_614p4, MPMU_SUCCR_1, 16, 13, 0, 13, 0);
139+
CCU_DDN_DEFINE(slow_uart1_14p74, pll1_d16_153p6, MPMU_SUCCR, 16, 13, 0, 13, 2, 0);
140+
CCU_DDN_DEFINE(slow_uart2_48, pll1_d4_614p4, MPMU_SUCCR_1, 16, 13, 0, 13, 2, 0);
141141

142142
CCU_GATE_DEFINE(wdt_clk, CCU_PARENT_HW(pll1_d96_25p6), MPMU_WDTPCR, BIT(1), 0);
143143

drivers/clk/spacemit/ccu_ddn.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222

2323
#include "ccu_ddn.h"
2424

25-
static unsigned long ccu_ddn_calc_rate(unsigned long prate,
26-
unsigned long num, unsigned long den)
25+
static unsigned long ccu_ddn_calc_rate(unsigned long prate, unsigned long num,
26+
unsigned long den, unsigned int pre_div)
2727
{
28-
return prate * den / 2 / num;
28+
return prate * den / pre_div / num;
2929
}
3030

3131
static unsigned long ccu_ddn_calc_best_rate(struct ccu_ddn *ddn,
3232
unsigned long rate, unsigned long prate,
3333
unsigned long *num, unsigned long *den)
3434
{
35-
rational_best_approximation(rate, prate / 2,
35+
rational_best_approximation(rate, prate / ddn->pre_div,
3636
ddn->den_mask >> ddn->den_shift,
3737
ddn->num_mask >> ddn->num_shift,
3838
den, num);
39-
return ccu_ddn_calc_rate(prate, *num, *den);
39+
return ccu_ddn_calc_rate(prate, *num, *den, ddn->pre_div);
4040
}
4141

4242
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)
6161
num = (val & ddn->num_mask) >> ddn->num_shift;
6262
den = (val & ddn->den_mask) >> ddn->den_shift;
6363

64-
return ccu_ddn_calc_rate(prate, num, den);
64+
return ccu_ddn_calc_rate(prate, num, den, ddn->pre_div);
6565
}
6666

6767
static int ccu_ddn_set_rate(struct clk_hw *hw, unsigned long rate,

drivers/clk/spacemit/ccu_ddn.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ struct ccu_ddn {
1818
unsigned int num_shift;
1919
unsigned int den_mask;
2020
unsigned int den_shift;
21+
unsigned int pre_div;
2122
};
2223

2324
#define CCU_DDN_INIT(_name, _parent, _flags) \
2425
CLK_HW_INIT_HW(#_name, &_parent.common.hw, &spacemit_ccu_ddn_ops, _flags)
2526

2627
#define CCU_DDN_DEFINE(_name, _parent, _reg_ctrl, _num_shift, _num_width, \
27-
_den_shift, _den_width, _flags) \
28+
_den_shift, _den_width, _pre_div, _flags) \
2829
static struct ccu_ddn _name = { \
2930
.common = { \
3031
.reg_ctrl = _reg_ctrl, \
@@ -33,7 +34,8 @@ static struct ccu_ddn _name = { \
3334
.num_mask = GENMASK(_num_shift + _num_width - 1, _num_shift), \
3435
.num_shift = _num_shift, \
3536
.den_mask = GENMASK(_den_shift + _den_width - 1, _den_shift), \
36-
.den_shift = _den_shift, \
37+
.den_shift = _den_shift, \
38+
.pre_div = _pre_div, \
3739
}
3840

3941
static inline struct ccu_ddn *hw_to_ccu_ddn(struct clk_hw *hw)

0 commit comments

Comments
 (0)