Re: [PATCH 7/9] net: ethernet: ti: cpts: calc mult and shift from refclk freq

From: Richard Cochran
Date: Thu Sep 15 2016 - 07:58:29 EST


On Wed, Sep 14, 2016 at 10:26:19PM +0200, Richard Cochran wrote:
> On Wed, Sep 14, 2016 at 04:02:29PM +0300, Grygorii Strashko wrote:
> > + clocks_calc_mult_shift(&mult, &shift, freq, NSEC_PER_SEC, maxsec);
> > +
> > + cpts->cc_mult = mult;
> > + cpts->cc.mult = mult;
>
> In order to get good resolution on the frequency adjustment, we want
> to keep 'mult' as large as possible. I don't see your code doing
> this. We can rely on the watchdog reader (work queue) to prevent
> overflows.

I took a closer look, and assuming cc.mask = 2^32 - 1, then using
clocks_calc_mult_shift() produces good results for a reasonable range
of input frequencies. Keeping 'maxsec' constant at 4 we have:

| Freq. MHz | mult | shift |
|-----------+------------+-------|
| 100 | 0xa0000000 | 28 |
| 250 | 0x80000000 | 29 |
| 500 | 0x80000000 | 30 |
| 1000 | 0x80000000 | 31 |

Can the input clock be higher than 1 GHz? If not, I suggest using
clocks_calc_mult_shift() with maxsec=4 and a setting the watchdog also
to 4*HZ.

Thanks,
Richard