Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Mitja Špes" <mitja@lxnav.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Angelo Compagnucci <angelo.compagnucci@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] iio: adc: mcp3422: allow setting gain and sampling per channel
Date: Mon, 14 Nov 2022 20:18:40 +0000	[thread overview]
Message-ID: <20221114201840.71a1326c@jic23-huawei> (raw)
In-Reply-To: <CACbQKWfzbxS2SKzd3v=h8-3oQw3hRhZJr_fJMaiTKaFwLn-jJg@mail.gmail.com>

On Sun, 13 Nov 2022 14:39:03 +0100
Mitja Špes <mitja@lxnav.com> wrote:

> On Sun, Nov 13, 2022 at 12:53 PM Jonathan Cameron <jic23@kernel.org> wrote:
> > > On Sat, Nov 12, 2022 at 6:15 PM Jonathan Cameron <jic23@kernel.org> wrote:  
> > > > Was it possible for these scales to differ before this change?  
> > > Yes. The difference is that before this change you could only see and set
> > > available scales that were available for specified sampling rate. Now you're
> > > able to set gain and sampling rate via scale. So before the change you got
> > > these (@240sps):
> > >
> > > 0.001000000 0.000500000 0.000250000 0.000125000
> > >
> > > Now you get the complete set:
> > > /*                 gain x1     gain x2     gain x4     gain x8  */
> > > /* 240 sps    */ 0.001000000 0.000500000 0.000250000 0.000125000
> > > /*  60 sps    */ 0.000250000 0.000125000 0.000062500 0.000031250
> > > /*  15 sps    */ 0.000062500 0.000031250 0.000015625 0.000007812
> > > /*   3.75 sps */ 0.000015625 0.000007812 0.000003906 0.000001953  
> >
> > Ok. That doesn't work as a standard interface because userspace code wants to pick say
> > 0.00062500 which appears twice.  
> I don't know how I missed that. It's clear to me now that this patch is wrong.
> 
> 
> > > > If not, then why was the previous patch a fix rather than simply a precursor
> > > > to this change (where it now matters).  
> > > I wanted to separate a bug fix from improvements, if these were rejected for
> > > for some reason.  
> >
> > Is it a bug fix?  The way I read it is that, before this patch there is only
> > one scale that is applied to all channels.  As such, the current value == the
> > value set and the code works as expected.
> > So the previous patch is only necessary once this one is applied.  Hence no
> > bug, just a rework that is useful to enabling this feature.  
> I'll post the previous snippet here and write the comments inline:
> ----
> @@ -164,8 +164,9 @@ static int mcp3422_read_raw(struct iio_dev *iio,
>   struct mcp3422 *adc = iio_priv(iio);
>   int err;
> 
> + u8 req_channel = channel->channel;
>   u8 sample_rate = MCP3422_SAMPLE_RATE(adc->config);
> - u8 pga = MCP3422_PGA(adc->config);  /* <- this uses the "current" config
>       which changes depending on the last read channel */
> + u8 pga = adc->pga[req_channel];          /* this now returns the PGA for the
>       selected channel */
> 
>   switch (mask) {
>   case IIO_CHAN_INFO_RAW:
> ----
> I hope this clarifies the bugfix.

Ah I see. The bit that threw me off was the title of this patch.
"allow setting gain ... per channel" which made me think that before this patch
there was one gain for all channels.  I was too lazy to actually check and discover
that it has always been per channel on the write side of things.

Jonathan


> 
> 
> Thanks for in depth look at this and sorry for wasting your time with this
> flawed patch.
> 
> Kind regards,
> Mitja


  reply	other threads:[~2022-11-14 20:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 11:26 [PATCH 0/4] iio: adc: mcp3422 improvements Mitja Spes
2022-11-11 11:26 ` [PATCH 1/4] iio: adc: mcp3422: fix scale read bug Mitja Spes
2022-11-12 17:10   ` Jonathan Cameron
2022-11-12 20:06     ` Mitja Špes
2022-11-11 11:26 ` [PATCH 2/4] iio: adc: mcp3422: allow setting gain and sampling per channel Mitja Spes
2022-11-12 17:28   ` Jonathan Cameron
2022-11-12 20:51     ` Mitja Špes
2022-11-13 12:06       ` Jonathan Cameron
2022-11-13 13:39         ` Mitja Špes
2022-11-14 20:18           ` Jonathan Cameron [this message]
2022-11-11 11:26 ` [PATCH 3/4] iio: adc: mcp3422: add hardware gain attribute Mitja Spes
2022-11-12 17:32   ` Jonathan Cameron
2022-11-12 21:19     ` Mitja Špes
2022-11-13 12:33       ` Jonathan Cameron
2022-11-13 13:51         ` Mitja Špes
2022-11-11 11:26 ` [PATCH 4/4] iio: adc: mcp3422: reduce sleep for fast sampling rates Mitja Spes
2022-11-12 17:33   ` Jonathan Cameron

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=20221114201840.71a1326c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=angelo.compagnucci@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mitja@lxnav.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