[PATCH 2/5] clk: spacemit: make MIX rate selection consistent

Troy Mitchell troy.mitchell at linux.spacemit.com
Thu Sep 10 07:19:54 PDT 2026


On Thu, Sep 10, 2026 at 01:01:30PM +0000, Yao Zi wrote:
> [...]
>
> > @@ -107,22 +107,27 @@ ccu_mix_calc_best_rate(struct clk_hw *hw, unsigned long rate,
> >  	struct ccu_mix *mix = hw_to_ccu_mix(hw);
> >  	unsigned int parent_num = clk_hw_get_num_parents(hw);
> >  	struct ccu_div_config *div = &mix->div;
> > -	u32 div_max = 1 << div->width;
> >  	unsigned long best_rate = 0;
> > +	unsigned long best_delta = ULONG_MAX;
> >  
> >  	for (int i = 0; i < parent_num; i++) {
> >  		struct clk_hw *parent = clk_hw_get_parent_by_index(hw, i);
> >  		unsigned long parent_rate;
> > +		u32 div_max = 1 << div->width;
>
> div_max should be invariant across iterations. Is there a reason moving
> it inside the loop?

It is invariant in this patch. Moving the declaration was preparation
for patch 3, which makes the limit depend on the parent being considered:

    u32 div_max = div->bypass & BIT(i) ? 1 : 1 << div->width;

K3 bypasses the divider for some parents, so those parents must only be
considered with a divisor of one.

I will keep the declaration outside the loop in patch 2 and move it
inside when introducing the bypass handling in patch 3. This does not
change the final code.

                                            - Troy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 248 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-riscv/attachments/20260910/9c175a7f/attachment.sig>


More information about the linux-riscv mailing list