[PATCH 4/7] pwm: rzg2l-gpt: Add calculate_prescale() callback to struct rzg2l_gpt_info

Biju posted 7 patches 1 month, 2 weeks ago
[PATCH 4/7] pwm: rzg2l-gpt: Add calculate_prescale() callback to struct rzg2l_gpt_info
Posted by Biju 1 month, 2 weeks ago
From: Biju Das <biju.das.jz@bp.renesas.com>

RZ/G2L GPT the prescale factors are continuous power of 4 whereas on RZ/G3E
it is power of 2 but discontinuous. Add calculate_prescale() callback to
struct rzg2l_gpt_info for handling this difference.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/pwm/pwm-rzg2l-gpt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c
index 74bb0cca4ab4..b247a6c181d5 100644
--- a/drivers/pwm/pwm-rzg2l-gpt.c
+++ b/drivers/pwm/pwm-rzg2l-gpt.c
@@ -90,6 +90,7 @@
 #define RZG2L_MAX_TICKS		((u64)U32_MAX * RZG2L_MAX_SCALE_FACTOR)
 
 struct rzg2l_gpt_info {
+	u8 (*calculate_prescale)(u64 period);
 	u32 gtcr_tpcs_mask;
 	u8 prescale_pow_of_two_mult_factor;
 };
@@ -138,8 +139,7 @@ static void rzg2l_gpt_modify(struct rzg2l_gpt_chip *rzg2l_gpt, u32 reg, u32 clr,
 			(rzg2l_gpt_read(rzg2l_gpt, reg) & ~clr) | set);
 }
 
-static u8 rzg2l_gpt_calculate_prescale(struct rzg2l_gpt_chip *rzg2l_gpt,
-				       u64 period_ticks)
+static u8 rzg2l_gpt_calculate_prescale(u64 period_ticks)
 {
 	u32 prescaled_period_ticks;
 	u8 prescale;
@@ -292,7 +292,7 @@ static int rzg2l_gpt_round_waveform_tohw(struct pwm_chip *chip,
 			period_ticks = rzg2l_gpt->period_ticks[ch];
 	}
 
-	wfhw->prescale = rzg2l_gpt_calculate_prescale(rzg2l_gpt, period_ticks);
+	wfhw->prescale = info->calculate_prescale(period_ticks);
 	pv = rzg2l_gpt_calculate_pv_or_dc(info, period_ticks, wfhw->prescale);
 	wfhw->gtpr = pv;
 	duty_ticks = mul_u64_u64_div_u64(wf->duty_length_ns, rzg2l_gpt->rate_khz, USEC_PER_SEC);
@@ -482,6 +482,7 @@ static int rzg2l_gpt_probe(struct platform_device *pdev)
 }
 
 static const struct rzg2l_gpt_info rzg2l_data = {
+	.calculate_prescale = rzg2l_gpt_calculate_prescale,
 	.gtcr_tpcs_mask = GENMASK(26, 24),
 	.prescale_pow_of_two_mult_factor = 2,
 };
-- 
2.43.0
Re: [PATCH 4/7] pwm: rzg2l-gpt: Add calculate_prescale() callback to struct rzg2l_gpt_info
Posted by Tommaso Merciai 1 month, 2 weeks ago
Hi Biju,
Thank you for your patch.

On Thu, Aug 14, 2025 at 07:41:08PM +0100, Biju wrote:
> From: Biju Das <biju.das.jz@bp.renesas.com>
> 
> RZ/G2L GPT the prescale factors are continuous power of 4 whereas on RZ/G3E
> it is power of 2 but discontinuous. Add calculate_prescale() callback to
> struct rzg2l_gpt_info for handling this difference.
> 

Reviewed-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>

> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>

Thanks & Regards,
Tommaso

> ---
>  drivers/pwm/pwm-rzg2l-gpt.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-rzg2l-gpt.c b/drivers/pwm/pwm-rzg2l-gpt.c
> index 74bb0cca4ab4..b247a6c181d5 100644
> --- a/drivers/pwm/pwm-rzg2l-gpt.c
> +++ b/drivers/pwm/pwm-rzg2l-gpt.c
> @@ -90,6 +90,7 @@
>  #define RZG2L_MAX_TICKS		((u64)U32_MAX * RZG2L_MAX_SCALE_FACTOR)
>  
>  struct rzg2l_gpt_info {
> +	u8 (*calculate_prescale)(u64 period);
>  	u32 gtcr_tpcs_mask;
>  	u8 prescale_pow_of_two_mult_factor;
>  };
> @@ -138,8 +139,7 @@ static void rzg2l_gpt_modify(struct rzg2l_gpt_chip *rzg2l_gpt, u32 reg, u32 clr,
>  			(rzg2l_gpt_read(rzg2l_gpt, reg) & ~clr) | set);
>  }
>  
> -static u8 rzg2l_gpt_calculate_prescale(struct rzg2l_gpt_chip *rzg2l_gpt,
> -				       u64 period_ticks)
> +static u8 rzg2l_gpt_calculate_prescale(u64 period_ticks)
>  {
>  	u32 prescaled_period_ticks;
>  	u8 prescale;
> @@ -292,7 +292,7 @@ static int rzg2l_gpt_round_waveform_tohw(struct pwm_chip *chip,
>  			period_ticks = rzg2l_gpt->period_ticks[ch];
>  	}
>  
> -	wfhw->prescale = rzg2l_gpt_calculate_prescale(rzg2l_gpt, period_ticks);
> +	wfhw->prescale = info->calculate_prescale(period_ticks);
>  	pv = rzg2l_gpt_calculate_pv_or_dc(info, period_ticks, wfhw->prescale);
>  	wfhw->gtpr = pv;
>  	duty_ticks = mul_u64_u64_div_u64(wf->duty_length_ns, rzg2l_gpt->rate_khz, USEC_PER_SEC);
> @@ -482,6 +482,7 @@ static int rzg2l_gpt_probe(struct platform_device *pdev)
>  }
>  
>  static const struct rzg2l_gpt_info rzg2l_data = {
> +	.calculate_prescale = rzg2l_gpt_calculate_prescale,
>  	.gtcr_tpcs_mask = GENMASK(26, 24),
>  	.prescale_pow_of_two_mult_factor = 2,
>  };
> -- 
> 2.43.0
>