Devicetree
 help / color / mirror / Atom feed
From: Haylen Chu <heylenay@4d2.org>
To: Troy Mitchell <troy.mitchell@linux.spacemit.com>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>, Yixun Lan <dlan@gentoo.org>,
	Alex Elder <elder@riscstar.com>,
	Inochi Amaoto <inochiama@outlook.com>
Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
	linux-riscv@lists.infradead.org, spacemit@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Jinmei Wei <weijinmei@linux.spacemit.com>
Subject: Re: [PATCH v2 3/4] clk: spacemit: introduce factor for div clock
Date: Mon, 18 Aug 2025 02:20:03 +0000	[thread overview]
Message-ID: <aKKN05w88uKP_HY7@ketchup> (raw)
In-Reply-To: <20250811-k1-clk-i2s-generation-v2-3-e4d3ec268b7a@linux.spacemit.com>

On Mon, Aug 11, 2025 at 10:04:29PM +0800, Troy Mitchell wrote:
> From the definition of register, The i2s_bclk is a non-linear,
> discrete divider clock.
> 
> The following table shows the correspondence between index
> and frequency division coefficients:
> 
> | index |  div  |
> |-------|-------|
> |   0   |   2   |
> |   1   |   4   |
> |   2   |   6   |
> |   3   |   8   |
> 
> But from a software perspective and this table, dividing the
> actual div value by 2 is sufficient to obtain a continuous
> divider clock.
> 
> Rather than introducing a new clock type to handle this case,
> a factor parameter has been added to CCU_DIV_GATE_DEFINE.

Actually, I expected you to represent the factor simply with
CCU_FACTOR_DEFINE, introducing no new clock-calculation code...

> Suggested-by: Haylen Chu <heylenay@4d2.org>
> Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> ---
>  drivers/clk/spacemit/ccu_mix.c | 7 ++++++-
>  drivers/clk/spacemit/ccu_mix.h | 4 +++-
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/spacemit/ccu_mix.c b/drivers/clk/spacemit/ccu_mix.c
> index 9b852aa61f78aed5256bfe6fc3b01932d6db6256..dbd2cf234bf81d8e110b19868ff9af7373e2ab55 100644
> --- a/drivers/clk/spacemit/ccu_mix.c
> +++ b/drivers/clk/spacemit/ccu_mix.c
> @@ -56,7 +56,10 @@ static unsigned long ccu_div_recalc_rate(struct clk_hw *hw,
>  	val = ccu_read(&mix->common, ctrl) >> div->shift;
>  	val &= (1 << div->width) - 1;
>  
> -	return divider_recalc_rate(hw, parent_rate, val, NULL, 0, div->width);
> +	if (!div->factor)
> +		return divider_recalc_rate(hw, parent_rate, val, NULL, 0, div->width);

Please adapt all div-related macros to make them assign one to the
factor, which helps you get rid of this if and the one in
ccu_mix_calc_best_rate().

> +	return divider_recalc_rate(hw, parent_rate, val, NULL, 0, div->width) / div->factor;
>  }
>  
>  /*
> @@ -115,6 +118,8 @@ ccu_mix_calc_best_rate(struct clk_hw *hw, unsigned long rate,
>  
>  		for (int j = 1; j <= div_max; j++) {
>  			unsigned long tmp = DIV_ROUND_CLOSEST_ULL(parent_rate, j);
> +			if (mix->div.factor)
			---- this if ------

> +				tmp /= mix->div.factor;
>  
>  			if (abs(tmp - rate) < abs(best_rate - rate)) {
>  				best_rate = tmp;
> diff --git a/drivers/clk/spacemit/ccu_mix.h b/drivers/clk/spacemit/ccu_mix.h
> index 54d40cd39b2752260f57d2a96eb8d3eed8116ecd..7dd00d24ec4b1dab70663b9cb7b9ebb02abeaecb 100644
> --- a/drivers/clk/spacemit/ccu_mix.h
> +++ b/drivers/clk/spacemit/ccu_mix.h
> @@ -34,6 +34,7 @@ struct ccu_mux_config {
>  struct ccu_div_config {
>  	u8 shift;
>  	u8 width;
> +	unsigned int factor;
>  };
>  
>  struct ccu_mix {
> @@ -130,10 +131,11 @@ static struct ccu_mix _name = {							\
>  }
>  
>  #define CCU_DIV_GATE_DEFINE(_name, _parent, _reg_ctrl, _shift, _width,		\
> -			    _mask_gate,	_flags)					\
> +			    _mask_gate,	_factor, _flags)			\

This isn't that consistent: why could only divider-gate come with a
factor? This is another reason why I think representing the factor
separately with the CCU_FACTOR_DEFINE() macro is better.

>  static struct ccu_mix _name = {							\
>  	.gate	= CCU_GATE_INIT(_mask_gate),					\
>  	.div	= CCU_DIV_INIT(_shift, _width),					\
> +	.div.factor = _factor,						\
>  	.common = {								\
>  		.reg_ctrl	= _reg_ctrl,					\
>  		CCU_MIX_INITHW(_name, _parent, spacemit_ccu_div_gate_ops,	\
> 
> -- 
> 2.50.1
> 

Best regards,
Haylen Chu

  reply	other threads:[~2025-08-18  2:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 14:04 [PATCH v2 0/4] clk: spacemit: fix i2s clock Troy Mitchell
2025-08-11 14:04 ` [PATCH v2 1/4] dt-bindings: clock: spacemit: introduce i2s pre-clock to " Troy Mitchell
2025-08-14  8:58   ` Krzysztof Kozlowski
2025-08-11 14:04 ` [PATCH v2 2/4] clk: spacemit: introduce pre-div for ddn clock Troy Mitchell
2025-08-18  2:04   ` Haylen Chu
2025-08-18  7:32     ` Troy Mitchell
2025-08-11 14:04 ` [PATCH v2 3/4] clk: spacemit: introduce factor for div clock Troy Mitchell
2025-08-18  2:20   ` Haylen Chu [this message]
2025-08-18  7:33     ` Troy Mitchell
2025-08-11 14:04 ` [PATCH v2 4/4] clk: spacemit: fix i2s clock Troy Mitchell
2025-08-14  1:05   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aKKN05w88uKP_HY7@ketchup \
    --to=heylenay@4d2.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlan@gentoo.org \
    --cc=elder@riscstar.com \
    --cc=inochiama@outlook.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mturquette@baylibre.com \
    --cc=robh@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=spacemit@lists.linux.dev \
    --cc=troy.mitchell@linux.spacemit.com \
    --cc=weijinmei@linux.spacemit.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox