Hello, On Mon, Dec 10, 2018 at 05:09:31AM +0000, Yoshihiro Shimoda wrote: > Thank you very much for your patches! > I tested patches and both codes work correctly. \o/, that's actually better than I expected :-) > > > The value of div should be calculatable without a loop. Something like: > > > > > > divider = NSEC_PER_SEC * RCAR_PWM_MAX_CYCLE; > > > tmp = (unsigned long long)period_ns * clk_rate + (divider - 1); > > > do_div(tmp, divider); > > This should be do_div64_u64() because the divider is 1,023,000,000,000 (over 32-bits). Yes, I think Laurent did this part right. > > > div = ilog2(tmp - 1) + 1; > > > > > > You might want to check if my maths are right, I didn't test. > > > > I've noticed the same, and wrote the following patch last week, also untested. > > I was planning to give it a try before sending it out, but as you've noticed > > the same issue, here's the code if anyone wants to give it a try before I can. > > Our calculations are similar, the main difference is the last line, and I > > think yours read better. > > So, I'd like to apply Uwe's code to mainline. Uwe, may I send such a patch > with your author and Singed-off-by? Please no, I cannot sing good enough for this :-) Honestly: If you take the authorship and write something like "Algorithm suggested by Uwe Kleine-König and Laurent Pinchart" that's IMHO fine. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |