Re: [PATCH v7 2/2] pwm: Add support for RZ/G2L GPT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Biju,

On Thu, Sep 29, 2022 at 05:36:38PM +0000, Biju Das wrote:
> > +static u8 rzg2l_calculate_prescale(struct rzg2l_gpt_chip *rzg2l_gpt,
> > +				   u64 period_cycles)
> > +{
> > +	u32 prescaled_period_cycles;
> > +	u8 prescale;
> > +
> > +	prescaled_period_cycles = period_cycles >> 32;
> > +
> > +	if (prescaled_period_cycles >= 256)
> > +		prescale = 5;
> > +	else
> > +		prescale = (roundup_pow_of_two(prescaled_period_cycles + 1)
> > + 1) / 2;
> 
> 
> This algorithm won't give desired result.
> 
> prescaled_period_cycles		Expected result
> 0					->0
> 1..3					->1
> 4..15					->2
> 16..63				->3
> 64..255				->4
> 256 >					->5

Oh, indeed, it fails for prescaled_period_cycles ∈ { 0, 3, 15, 63, 255 }.

The correct formula is:

	if (prescaled_period_cycles >= 256)
		prescale = 5;
	else
		prescale = (roundup_pow_of_two(prescaled_period_cycles) + 1) / 2;

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux