From: Jonathan Cameron <jic23@kernel.org>
To: Guillaume Stols <gstols@baylibre.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Nuno Sa <nuno.sa@analog.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, dlechner@baylibre.com,
jstephan@baylibre.com, aardelean@baylibre.com,
adureghello@baylibre.com
Subject: Re: [PATCH v2 9/9] iio: adc: ad7606: Add support for writing registers when using backend
Date: Sun, 15 Dec 2024 12:12:39 +0000 [thread overview]
Message-ID: <20241215121239.10a29743@jic23-huawei> (raw)
In-Reply-To: <20241210-ad7606_add_iio_backend_software_mode-v2-9-6619c3e50d81@baylibre.com>
On Tue, 10 Dec 2024 10:46:49 +0000
Guillaume Stols <gstols@baylibre.com> wrote:
> Adds the logic for effectively enabling the software mode for the
> iio-backend, i.e enabling the software mode channel configuration and
> implementing the register writing functions.
>
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
Hi Guillaume,
Main thing in here is really about not adding more cases of
iio_device_claim_direct_scoped() given the problems we are having with it
and lack of a clean replacement.
My current thinking is that it's just not worth the pain of weird
compiler quirks etc and readability issues (even though I for one have
gotten used to that bit!)
Jonathan
> ---
> drivers/iio/adc/ad7606.h | 15 ++++++++++++
> drivers/iio/adc/ad7606_par.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 71 insertions(+)
>
> diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
> index ada8065fba4e..9da39c2d5d53 100644
> --- a/drivers/iio/adc/ad7606.h
> +++ b/drivers/iio/adc/ad7606.h
> @@ -96,6 +96,21 @@
> BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
> 0, 0, 16)
>
> +#define AD7606_BI_SW_CHANNEL(num) \
> + AD760X_CHANNEL(num, \
> + /* mask separate */ \
> + BIT(IIO_CHAN_INFO_SCALE), \
> + /* mask type */ \
> + 0, \
> + /* mask all */ \
> + BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
> + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
> + /* mask separate available */ \
> + BIT(IIO_CHAN_INFO_SCALE), \
> + /* mask all available */ \
> + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
> + 16)
> +
> struct ad7606_state;
>
> typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev,
> diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
> index 64733b607aa8..c159cd4f7802 100644
> --- a/drivers/iio/adc/ad7606_par.c
> +++ b/drivers/iio/adc/ad7606_par.c
> @@ -13,12 +13,14 @@
> #include <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/property.h>
> +#include <linux/pwm.h>
Why the addition of this? If it was simply missing previously spin a
separate patch.
> #include <linux/types.h>
>
> #include <linux/iio/backend.h>
> #include <linux/iio/iio.h>
>
> #include "ad7606.h"
> +#include "ad7606_bi.h"
>
> static const struct iio_chan_spec ad7606b_bi_channels[] = {
> AD7606_BI_CHANNEL(0),
> @@ -31,6 +33,17 @@ static const struct iio_chan_spec ad7606b_bi_channels[] = {
> AD7606_BI_CHANNEL(7),
> };
>
> +static const struct iio_chan_spec ad7606b_bi_sw_channels[] = {
> + AD7606_BI_SW_CHANNEL(0),
> + AD7606_BI_SW_CHANNEL(1),
> + AD7606_BI_SW_CHANNEL(2),
> + AD7606_BI_SW_CHANNEL(3),
> + AD7606_BI_SW_CHANNEL(4),
> + AD7606_BI_SW_CHANNEL(5),
> + AD7606_BI_SW_CHANNEL(6),
> + AD7606_BI_SW_CHANNEL(7),
> +};
> +
> static int ad7606_bi_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask)
> {
> struct ad7606_state *st = iio_priv(indio_dev);
> @@ -86,9 +99,52 @@ static int ad7606_bi_setup_iio_backend(struct device *dev, struct iio_dev *indio
> return 0;
> }
>
> +static int ad7606_bi_reg_read(struct iio_dev *indio_dev, unsigned int addr)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> + int val, ret;
> + struct ad7606_platform_data *pdata = st->dev->platform_data;
> +
> + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
As below. Let's go back to
ret = iio_device_claim_direct_mode(indio-dev)
if (ret)
return ret;
ret = ....
iio_device_release_direct_mode()
if (ret < 0)
return ret;
return val;
> + ret = pdata->bus_reg_read(st->back,
> + addr,
> + &val);
> + }
> + if (ret < 0)
> + return ret;
> +
> + return val;
> +}
> +
> +static int ad7606_bi_reg_write(struct iio_dev *indio_dev,
> + unsigned int addr,
> + unsigned int val)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> + struct ad7606_platform_data *pdata = st->dev->platform_data;
> + int ret;
> +
> + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
> + ret = pdata->bus_reg_write(st->back,
Quite a few things wrong with indentation here.
Also a small request. Don't use iio_device_claim_direct_scoped.
It's proved a PITA for all sorts of reasons so one of my possible projects
for when I get bored is to look at just how bad it would be to rip it out.
One of those things that seems cool and useful but turns out it's not worth it.
Jonathan
> + addr,
> + val);
> + }
> + return ret;
> +}
prev parent reply other threads:[~2024-12-15 12:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 10:46 [PATCH v2 0/9] Add support for Software mode on AD7606's iio backend driver Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 1/9] iio: adc: ad7606: Fix hardcoded offset in the ADC channels Guillaume Stols
2024-12-14 18:26 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 2/9] dt-bindings: iio: dac: adi-axi-adc: Add ad7606 variant Guillaume Stols
2024-12-10 12:31 ` Rob Herring (Arm)
2024-12-11 22:01 ` David Lechner
2024-12-10 10:46 ` [PATCH v2 3/9] iio:adc: ad7606: Move the software mode configuration Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 4/9] iio: adc: ad7606: Move software functions into common file Guillaume Stols
2024-12-15 11:51 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 5/9] iio: adc: adi-axi-adc: Add platform children support Guillaume Stols
2024-12-15 11:57 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 6/9] iio: adc: adi-axi-adc: Add support for AD7606 register writing Guillaume Stols
2024-12-15 12:05 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 7/9] iio: adc: ad7606: change r/w_register signature Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 8/9] iio: adc: ad7606: Change channel macros parameters Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 9/9] iio: adc: ad7606: Add support for writing registers when using backend Guillaume Stols
2024-12-15 12:12 ` Jonathan Cameron [this message]
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=20241215121239.10a29743@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=aardelean@baylibre.com \
--cc=adureghello@baylibre.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=gstols@baylibre.com \
--cc=jstephan@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@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