devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: Alexandru Ardelean <aardelean@baylibre.com>,
	David Lechner <dlechner@baylibre.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 devicetree@vger.kernel.org, jic23@kernel.org,
	krzk+dt@kernel.org, robh@kernel.org, 	lars@metafoo.de,
	michael.hennerich@analog.com, gstols@baylibre.com
Subject: Re: [PATCH 4/6] iio: adc: ad7606: rework scale-available to be static
Date: Tue, 22 Oct 2024 10:28:40 +0200	[thread overview]
Message-ID: <9083e7ff5471e9f8c478a10a67a7c606b81c6287.camel@gmail.com> (raw)
In-Reply-To: <CA+GgBR_tT5J8Lq7DmSw9GdETiRScXzPzcf5UkDk32GLP8tSrQw@mail.gmail.com>

On Tue, 2024-10-22 at 09:59 +0300, Alexandru Ardelean wrote:
> On Mon, Oct 21, 2024 at 9:17 PM David Lechner <dlechner@baylibre.com> wrote:
> > 
> > On 10/21/24 8:02 AM, Alexandru Ardelean wrote:
> > > The main driver for this change is the AD7607 part, which has a scale of
> > > "1.220703" for the ±10V range. The AD7607 has a resolution of 14-bits.
> > > 
> > > So, just adding the scale-available list for that part would require some
> > > quirks to handle just that scale value.
> > > But to do it more neatly, the best approach is to rework the scale
> > > available lists to have the same format as it is returned to userspace.
> > > That way, we can also get rid of the allocation for the 'scale_avail_show'
> > > array.
> > > 
> > > Signed-off-by: Alexandru Ardelean <aardelean@baylibre.com>
> > > ---
> > 
> > ...
> > 
> > 
> > >  static ssize_t in_voltage_scale_available_show(struct device *dev,
> > >                                              struct device_attribute
> > > *attr,
> > >                                              char *buf)
> > > @@ -703,8 +690,16 @@ static ssize_t in_voltage_scale_available_show(struct
> > > device *dev,
> > >       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> > >       struct ad7606_state *st = iio_priv(indio_dev);
> > >       struct ad7606_chan_scale *cs = &st->chan_scales[0];
> > > +     const unsigned int (*vals)[2] = cs->scale_avail;
> > > +     unsigned int i;
> > > +     size_t len = 0;
> > > 
> > > -     return ad7606_show_avail(buf, cs->scale_avail, cs->num_scales,
> > > true);
> > > +     for (i = 0; i < cs->num_scales; i++)
> > > +             len += scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ",
> > > +                              vals[i][0], vals[i][1]);
> > > +     buf[len - 1] = '\n';
> > > +
> > > +     return len;
> > >  }
> > > 
> > >  static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
> > 
> > Probably a reason for this that I forgot, but why is this handled in a
> > custom attribute instead of ad7606_read_avail()?
> 
> [1]
> So, this is a quirk of this driver that would require a bigger cleanup.
> It could be done as a different series.
> Or (otherwise said) I would do it in a different series (unless
> requested otherwise).

Agreed...

> 
> These device-level attributes are attached in the probe() of this
> driver, based on the GPIO configurations provided via DT.
> There's that bit of code
> 
>         if (st->gpio_os) {
>                 if (st->gpio_range)
>                         indio_dev->info = &ad7606_info_os_and_range;
>                 else
>                         indio_dev->info = &ad7606_info_os;
>         } else {
>                 if (st->gpio_range)
>                         indio_dev->info = &ad7606_info_range;
>                 else
>                         indio_dev->info = &ad7606_info_no_os_or_range;
>         }
> 
> The "range" there refers to "scale_available", which is only attached
> like this, for HW mode.
> A rework of HW-mode would be a good idea.
> 

Maybe it's also due to .read_avail() not being around when the driver was first
added (but not sure about that).

- Nuno Sá

> 

  reply	other threads:[~2024-10-22  8:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21 13:02 [PATCH 0/6] iio: adc: ad7606: add support for AD760{7,8,9} parts Alexandru Ardelean
2024-10-21 13:02 ` [PATCH 1/6] iio: adc: ad7606: fix/persist oversampling_ratio setting Alexandru Ardelean
2024-10-21 13:02 ` [PATCH 2/6] iio: adc: ad7606: fix issue/quirk with find_closest() for oversampling Alexandru Ardelean
2024-10-21 19:03   ` David Lechner
2024-10-21 19:31     ` David Lechner
2024-10-22  6:31       ` Alexandru Ardelean
2024-10-22  8:24         ` Nuno Sá
2024-10-21 13:02 ` [PATCH 3/6] iio: adc: ad7606: use realbits for sign-extending in scan_direct Alexandru Ardelean
2024-10-21 17:19   ` David Lechner
2024-10-22  6:09     ` Alexandru Ardelean
2024-10-21 13:02 ` [PATCH 4/6] iio: adc: ad7606: rework scale-available to be static Alexandru Ardelean
2024-10-21 18:17   ` David Lechner
2024-10-22  6:59     ` Alexandru Ardelean
2024-10-22  8:28       ` Nuno Sá [this message]
2024-10-21 13:02 ` [PATCH 5/6] dt-bindings: iio: adc: adi,ad7606: document AD760{7,8,9} parts Alexandru Ardelean
2024-10-21 16:52   ` Conor Dooley
2024-10-21 13:02 ` [PATCH 6/6] iio: adc: ad7606: add support for " Alexandru Ardelean

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=9083e7ff5471e9f8c478a10a67a7c606b81c6287.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=aardelean@baylibre.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gstols@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=robh@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).