[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241101173228.1db50f7c@jic23-huawei>
Date: Fri, 1 Nov 2024 17:32:28 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: Uwe Kleine-König <u.kleine-koenig@...libre.com>
Cc: David Lechner <dlechner@...libre.com>, Guillaume Stols
<gstols@...libre.com>, Michael Hennerich <Michael.Hennerich@...log.com>,
linux-pwm@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-iio@...r.kernel.org
Subject: Re: [PATCH v2 2/2] iio: adc: ad7606: finish pwm_get_state_hw() TODO
On Wed, 30 Oct 2024 09:28:01 +0100
Uwe Kleine-König <u.kleine-koenig@...libre.com> wrote:
> On Tue, Oct 29, 2024 at 04:18:50PM -0500, David Lechner wrote:
> > Replace the call to pwm_get_state() with a call to pwm_get_state_hw() in
> > the ad7606 driver. This allows reading the sampling_frequency attribute
> > to return the rate the hardware is actually running at rather than the
> > rate that was requested. These may differ when the hardware isn't
> > capable of running at exactly the requested frequency.
> >
> > Signed-off-by: David Lechner <dlechner@...libre.com>
> > ---
> >
> > I went ahead and made this patch since it is trivial, but it would be
> > nice to get a Tested-by from Guillaume to make sure it actually works
> > as expected.
> > ---
> > drivers/iio/adc/ad7606.c | 8 +++-----
> > 1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> > index 8b2046baaa3e..1581eb31b8f9 100644
> > --- a/drivers/iio/adc/ad7606.c
> > +++ b/drivers/iio/adc/ad7606.c
> > @@ -762,11 +762,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
> > *val = st->oversampling;
> > return IIO_VAL_INT;
> > case IIO_CHAN_INFO_SAMP_FREQ:
> > - /*
> > - * TODO: return the real frequency intead of the requested one once
> > - * pwm_get_state_hw comes upstream.
> > - */
> > - pwm_get_state(st->cnvst_pwm, &cnvst_pwm_state);
> > + ret = pwm_get_state_hw(st->cnvst_pwm, &cnvst_pwm_state);
> > + if (ret < 0)
> > + return ret;
> > *val = DIV_ROUND_CLOSEST_ULL(NSEC_PER_SEC, cnvst_pwm_state.period);
> > return IIO_VAL_INT;
> > }
>
> Acked-by: Uwe Kleine-König <u.kleine-koenig@...libre.com>
Probably not something we need to hurry so assuming it is fine, please
send again after the merge window.
>
> There is a slight inconsistency compared to ad7606_set_sampling_freq():
>
> ad7606_set_sampling_freq uses
>
> cnvst_pwm_state.period = DIV_ROUND_UP_ULL(NSEC_PER_SEC, freq);
>
> . So if cnvst_pwm_state.period happens to be 3 ns then reading
> the freq value yields 333333333, but if you feed freq=333333333 into
> ad7606_set_sampling_freq() it sets period = 4.
>
> To fix that you'd better use a plain / here in ad7606_read_raw().
> (Note that with using round-closest for both there are still corner
> cases, e.g. period = 31796 ns yields freq = 31450.496917851302 but
> setting freq = 31450 yields 31796.50238473768 and so 31797.)
Ouch.
>
> Best regards
> Uwe
Powered by blists - more mailing lists