Skip to content

Commit faddad5

Browse files
Dzmitry Sankouskiandersson
authored andcommitted
clk: qcom: clk-rcg2: split __clk_rcg2_configure function
__clk_rcg2_configure function does 2 things - configures parent and mnd values. In order to be able to add new clock options, we should split. Move __clk_rcg2_configure logic on 2 functions: - __clk_rcg2_configure_parent which configures clock parent - __clk_rcg2_configure_mnd which configures mnd values __clk_rcg2_configure delegates to mentioned functions. Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com> Link: https://lore.kernel.org/r/20241118-starqltechn_integration_upstream-v8-2-ac8e36a3aa65@gmail.com Signed-off-by: Bjorn Andersson <andersson@kernel.org>
1 parent cef0523 commit faddad5

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

drivers/clk/qcom/clk-rcg2.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,16 +402,26 @@ static int clk_rcg2_fm_determine_rate(struct clk_hw *hw,
402402
return _freq_tbl_fm_determine_rate(hw, rcg->freq_multi_tbl, req);
403403
}
404404

405-
static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
406-
u32 *_cfg)
405+
static int __clk_rcg2_configure_parent(struct clk_rcg2 *rcg, u8 src, u32 *_cfg)
407406
{
408-
u32 cfg, mask, d_val, not2d_val, n_minus_m;
409407
struct clk_hw *hw = &rcg->clkr.hw;
410-
int ret, index = qcom_find_src_index(hw, rcg->parent_map, f->src);
408+
int index = qcom_find_src_index(hw, rcg->parent_map, src);
411409

412410
if (index < 0)
413411
return index;
414412

413+
*_cfg &= ~CFG_SRC_SEL_MASK;
414+
*_cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
415+
416+
return 0;
417+
}
418+
419+
static int __clk_rcg2_configure_mnd(struct clk_rcg2 *rcg, const struct freq_tbl *f,
420+
u32 *_cfg)
421+
{
422+
u32 cfg, mask, d_val, not2d_val, n_minus_m;
423+
int ret;
424+
415425
if (rcg->mnd_width && f->n) {
416426
mask = BIT(rcg->mnd_width) - 1;
417427
ret = regmap_update_bits(rcg->clkr.regmap,
@@ -440,9 +450,8 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
440450
}
441451

442452
mask = BIT(rcg->hid_width) - 1;
443-
mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
453+
mask |= CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
444454
cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
445-
cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
446455
if (rcg->mnd_width && f->n && (f->m != f->n))
447456
cfg |= CFG_MODE_DUAL_EDGE;
448457
if (rcg->hw_clk_ctrl)
@@ -454,6 +463,22 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
454463
return 0;
455464
}
456465

466+
static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
467+
u32 *_cfg)
468+
{
469+
int ret;
470+
471+
ret = __clk_rcg2_configure_parent(rcg, f->src, _cfg);
472+
if (ret)
473+
return ret;
474+
475+
ret = __clk_rcg2_configure_mnd(rcg, f, _cfg);
476+
if (ret)
477+
return ret;
478+
479+
return 0;
480+
}
481+
457482
static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
458483
{
459484
u32 cfg;

0 commit comments

Comments
 (0)