From: Jonathan Cameron <jic23@kernel.org>
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Cc: David Lechner <dlechner@baylibre.com>,
Guillaume Stols <gstols@baylibre.com>,
Michael Hennerich <Michael.Hennerich@analog.com>,
linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 2/2] iio: adc: ad7606: finish pwm_get_state_hw() TODO
Date: Fri, 1 Nov 2024 17:32:28 +0000 [thread overview]
Message-ID: <20241101173228.1db50f7c@jic23-huawei> (raw)
In-Reply-To: <iajs2rk7odutqwoih4h6besd4b4nnksap6om5r7i2cw5arqcip@rvztnliokuk3>
On Wed, 30 Oct 2024 09:28:01 +0100
Uwe Kleine-König <u.kleine-koenig@baylibre.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@baylibre.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@baylibre.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
next prev parent reply other threads:[~2024-11-01 17:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 21:18 [PATCH v2 0/2] pwm: export pwm_get_state_hw() David Lechner
2024-10-29 21:18 ` [PATCH v2 1/2] pwm: core: " David Lechner
2024-10-30 8:05 ` Uwe Kleine-König
2024-10-29 21:18 ` [PATCH v2 2/2] iio: adc: ad7606: finish pwm_get_state_hw() TODO David Lechner
2024-10-30 8:28 ` Uwe Kleine-König
2024-11-01 17:32 ` Jonathan Cameron [this message]
2024-11-01 17:50 ` kernel test robot
2024-11-03 14:00 ` Uwe Kleine-König
2024-11-03 20:20 ` Uwe Kleine-König
2024-11-03 22:10 ` David Lechner
2024-11-01 20:24 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241101173228.1db50f7c@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=dlechner@baylibre.com \
--cc=gstols@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=u.kleine-koenig@baylibre.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox